Skip to content

Commit

Permalink
governance: fetch delegation before governance proposal start epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraccaman committed Oct 3, 2024
1 parent 602d154 commit 49fc433
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions wasm/tx_vote_proposal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,23 @@ fn apply_tx(ctx: &mut Ctx, tx_data: BatchedTx) -> TxResult {

debug_log!("apply_tx called to vote a governance proposal");

let voting_start_epoch_key =
gov_storage::keys::get_voting_start_epoch_key(tx_data.id);
let start_epoch = if let Some(epoch) = ctx.read(&voting_start_epoch_key)? {
epoch
} else {
return Err(Error::new_alloc(format!(
"Proposal id {} doesn't exist.",
tx_data.id
)));
};

// Pass in all target validators to the proposal vote. Whether or not the
// vote will be counted based on the validator state will be determined
// when tallying the votes and executing the proposal.
let current_epoch = ctx.get_block_epoch()?;

let is_validator = is_validator(ctx, &tx_data.voter).unwrap_or(false);
let delegation_targets = if !is_validator {
find_delegation_validators(ctx, &tx_data.voter, &current_epoch)?
find_delegation_validators(ctx, &tx_data.voter, &start_epoch)?
} else {
[tx_data.voter.clone()].into()
};
Expand Down

0 comments on commit 49fc433

Please sign in to comment.