Skip to content

Commit

Permalink
goveranance: let validator vote even if it doesn't have a self-bond
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraccaman committed Oct 2, 2024
1 parent 394d4d9 commit 2895e48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion crates/tx_prelude/src/proof_of_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use namada_proof_of_stake::{
claim_reward_tokens, deactivate_validator, reactivate_validator,
redelegate_tokens, unbond_tokens, unjail_validator, withdraw_tokens,
};
pub use namada_proof_of_stake::{parameters, storage, storage_key, types};
pub use namada_proof_of_stake::{
is_validator, parameters, storage, storage_key, types,
};
use namada_tx::action::{
Action, ClaimRewards, PosAction, Redelegation, Unbond, Withdraw, Write,
};
Expand Down
13 changes: 10 additions & 3 deletions wasm/tx_vote_proposal/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! A tx to vote on a proposal

use namada_tx_prelude::action::{Action, GovAction, Write};
use namada_tx_prelude::proof_of_stake::find_delegation_validators;
use namada_tx_prelude::proof_of_stake::{
find_delegation_validators, is_validator,
};
use namada_tx_prelude::*;

#[transaction]
Expand All @@ -24,8 +26,13 @@ fn apply_tx(ctx: &mut Ctx, tx_data: BatchedTx) -> TxResult {
// 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 delegation_targets =
find_delegation_validators(ctx, &tx_data.voter, &current_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)?
} else {
[tx_data.voter.clone()].into()
};

governance::vote_proposal(ctx, tx_data, delegation_targets)
.wrap_err("Failed to vote on governance proposal")
Expand Down

0 comments on commit 2895e48

Please sign in to comment.