Skip to content

Commit

Permalink
stake: unify unbonding token regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed Mar 11, 2024
1 parent 5811492 commit 1032224
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions crates/core/asset/src/asset/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,10 @@ pub static REGISTRY: Lazy<Registry> = Lazy::new(|| {
// Note: this regex must be in sync with UnbondingToken::try_from
// and VALIDATOR_IDENTITY_BECH32_PREFIX in the penumbra-stake crate
// TODO: this doesn't restrict the length of the bech32 encoding
"^uunbonding_(?P<data>epoch_(?P<start>[0-9]+)_until_(?P<end>[0-9]+)_(?P<validator>penumbravalid1[a-zA-HJ-NP-Z0-9]+))$",
"^uunbonding_(?P<data>start_at_(?P<start>[0-9]+)_(?P<validator>penumbravalid1[a-zA-HJ-NP-Z0-9]+))$",
&[
"^unbonding_(?P<data>epoch_(?P<start>[0-9]+)_until_(?P<end>[0-9]+)_(?P<validator>penumbravalid1[a-zA-HJ-NP-Z0-9]+))$",
"^munbonding_(?P<data>epoch_(?P<start>[0-9]+)_until_(?P<end>[0-9]+)_(?P<validator>penumbravalid1[a-zA-HJ-NP-Z0-9]+))$",
"^unbonding_(?P<data>start_at_(?P<start>[0-9]+)_(?P<validator>penumbravalid1[a-zA-HJ-NP-Z0-9]+))$",
"^munbonding_(?P<data>start_at_(?P<start>[0-9]+)_(?P<validator>penumbravalid1[a-zA-HJ-NP-Z0-9]+))$",
],
(|data: &str| {
assert!(!data.is_empty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ impl ActionHandler for UndelegateClaim {
}

async fn check_and_execute<S: StateWrite>(&self, state: S) -> Result<()> {
// These checks all formerly happened in the `check_historical` method,
// These checks all formerly happened in the `check_stateful` method,
// if profiling shows that they cause a bottleneck we could (CAREFULLY)
// move some of them back.

// If the validator delegation pool is bonded, or unbonding, check that enough epochs
// have elapsed to claim the unbonding tokens:
// If the validator delegation pool is bonded, or unbonding, we must
// check that the unbonding delay (measured in blocks) has elapsed.
let current_height = state.get_block_height().await?;

// Check if the unbonding height has been reached, it will always be the case if
// the validator delegation pool is unbonded.
let allowed_unbonding_height = state
.compute_unbonding_height(
&self.body.validator_identity,
Expand All @@ -58,18 +60,18 @@ impl ActionHandler for UndelegateClaim {
wait_blocks
);

let unbonding_epoch = state
let unbonding_epoch_start = state
.get_epoch_by_height(self.body.unbonding_start_height)
.await?;
let allowed_epoch = state.get_epoch_by_height(allowed_unbonding_height).await?;
let unbonding_epoch_end = state.get_epoch_by_height(allowed_unbonding_height).await?;

// Compute the penalty for the epoch range [start_epoch_index, unbonding_epoch], and check
// Compute the penalty for the epoch range [unbonding_epoch_start, unbonding_epoch_end], and check
// that it matches the penalty in the claim.
let expected_penalty = state
.compounded_penalty_over_range(
&self.body.validator_identity,
unbonding_epoch.index,
allowed_epoch.index,
unbonding_epoch_start.index,
unbonding_epoch_end.index,
)
.await?;

Expand All @@ -78,11 +80,9 @@ impl ActionHandler for UndelegateClaim {
"penalty does not match expected penalty"
);

// (end of former check_historical impl)

/* ---------- execution ----------- */
// No state changes here - this action just converts one token to another

// TODO: where should we be tracking token supply changes?
Ok(())
}
}
4 changes: 2 additions & 2 deletions crates/core/component/stake/src/unbonding_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl UnbondingToken {
let base_denom = asset::REGISTRY
.parse_denom(&format!(
// "uu" is not a typo, these are micro-unbonding tokens
"uunbonding_epoch_{unbonding_start_height}_{validator_identity}"
"uunbonding_start_at_{unbonding_start_height}_{validator_identity}"
))
.expect("base denom format is valid");
UnbondingToken {
Expand Down Expand Up @@ -68,7 +68,7 @@ impl TryFrom<asset::Metadata> for UnbondingToken {
// and VALIDATOR_IDENTITY_BECH32_PREFIX
// The data capture group is used by asset::REGISTRY
let captures =
Regex::new("^uunbonding_(?P<data>at_(?P<start>[0-9]+)_(?P<validator>penumbravalid1[a-zA-HJ-NP-Z0-9]+))$")
Regex::new("^uunbonding_(?P<data>start_at_(?P<start>[0-9]+)_(?P<validator>penumbravalid1[a-zA-HJ-NP-Z0-9]+))$")
.expect("regex is valid")
.captures(base_string.as_ref())
.ok_or_else(|| {
Expand Down

0 comments on commit 1032224

Please sign in to comment.