Skip to content

Commit

Permalink
funding: extend lqt vote validation
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed Feb 5, 2025
1 parent 092d4cc commit b8e44eb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{anyhow, Context as _};
use anyhow::{anyhow, ensure, Context as _};
use async_trait::async_trait;
use cnidarium::{StateRead, StateWrite};
use cnidarium_component::ActionHandler;
Expand Down Expand Up @@ -131,17 +131,38 @@ impl ActionHandler for ActionLiquidityTournamentVote {
.get_current_source()
.expect("source transaction id should be set");
state.put_lqt_spent_nullifier(current_epoch.index, nullifier, tx_id);
// 3. Ok, actually tally.
// 3. Validate that the delegation asset is for a known validator.
let validator = state
.validator_by_delegation_asset(self.body.value.asset_id)
.await?;
// The ZK proof asserts that we own the delegation notes, so no further checks are needed
// for the IK.

// 4. Check that the validator state is not `Defined` or `Tombstoned`
let Some(validator_state) = state.get_validator_state(&validator).await? else {
anyhow::bail!("validator {} is unknown", validator)
};

use penumbra_sdk_stake::validator::State;
ensure!(
!matches!(validator_state, State::Defined | State::Tombstoned),
"validator {} is not in a valid state (Defined or Tombstoned)",
validator
);

// 5. Ok, actually tally.
let power = voting_power(unbonded_amount(&state, self.body.value).await?);
let incentivized = self
.body
.incentivized_id()
.ok_or_else(|| anyhow!("{:?} is not a base denom", self.body.incentivized))?;

state
.tally(
current_epoch.index,
incentivized,
power,
validator,
&self.body.rewards_recipient,
)
.await;
Expand Down
1 change: 1 addition & 0 deletions crates/core/component/stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub use self::undelegate_claim::{
pub use self::delegation_token::DelegationToken;
pub use self::governance_key::GovernanceKey;
pub use self::identity_key::IdentityKey;
pub use self::identity_key::IDENTITY_KEY_LEN_BYTES;
pub use self::penalty::Penalty;
pub use self::unbonding_token::UnbondingToken;

Expand Down

0 comments on commit b8e44eb

Please sign in to comment.