diff --git a/crates/apps/src/lib/node/ledger/shell/mod.rs b/crates/apps/src/lib/node/ledger/shell/mod.rs index 5d47fe8539..28a2cc006a 100644 --- a/crates/apps/src/lib/node/ledger/shell/mod.rs +++ b/crates/apps/src/lib/node/ledger/shell/mod.rs @@ -38,7 +38,6 @@ use namada::ethereum_bridge::protocol::validation::validator_set_update::validat use namada::ledger::events::log::EventLog; use namada::ledger::events::Event; use namada::ledger::gas::{Gas, TxGasMeter}; -use namada::ledger::pos::into_tm_voting_power; use namada::ledger::pos::namada_proof_of_stake::types::{ ConsensusValidator, ValidatorSetUpdate, }; @@ -1305,14 +1304,8 @@ where let (consensus_key, power) = match update { ValidatorSetUpdate::Consensus(ConsensusValidator { consensus_key, - bonded_stake, - }) => { - let power: i64 = into_tm_voting_power( - pos_params.tm_votes_per_token, - bonded_stake, - ); - (consensus_key, power) - } + bonded_stake: power, + }) => (consensus_key, power), ValidatorSetUpdate::Deactivated(consensus_key) => { // Any validators that have been dropped from the // consensus set must have voting power set to 0 to diff --git a/crates/proof_of_stake/src/lib.rs b/crates/proof_of_stake/src/lib.rs index 558c40e0ea..6fb618db4f 100644 --- a/crates/proof_of_stake/src/lib.rs +++ b/crates/proof_of_stake/src/lib.rs @@ -36,6 +36,7 @@ use namada_storage::collections::lazy_map::{self, Collectable, LazyMap}; use namada_storage::{StorageRead, StorageWrite}; pub use namada_trans_token as token; pub use parameters::{OwnedPosParams, PosParams}; +use types::into_tm_voting_power; use crate::queries::{find_bonds, has_bonds}; use crate::rewards::{ @@ -1843,9 +1844,11 @@ where let consensus_key = validator_consensus_key_handle(&address) .get(storage, current_epoch, params)? .unwrap(); + let new_tm_voting_power = + into_tm_voting_power(params.tm_votes_per_token, new_stake); let converted = f(ValidatorSetUpdate::Consensus(ConsensusValidator { consensus_key, - bonded_stake: new_stake, + bonded_stake: new_tm_voting_power, })); Ok(converted) }) diff --git a/crates/proof_of_stake/src/tests/test_validator.rs b/crates/proof_of_stake/src/tests/test_validator.rs index 7b5f8df40d..4ddb17c7c6 100644 --- a/crates/proof_of_stake/src/tests/test_validator.rs +++ b/crates/proof_of_stake/src/tests/test_validator.rs @@ -556,7 +556,10 @@ fn test_validator_sets() { tm_updates[0], ValidatorSetUpdate::Consensus(ConsensusValidator { consensus_key: pk3, - bonded_stake: stake3, + bonded_stake: into_tm_voting_power( + params.tm_votes_per_token, + stake3 + ), }) ); @@ -611,7 +614,10 @@ fn test_validator_sets() { tm_updates[0], ValidatorSetUpdate::Consensus(ConsensusValidator { consensus_key: pk5, - bonded_stake: stake5, + bonded_stake: into_tm_voting_power( + params.tm_votes_per_token, + stake5 + ), }) ); assert_eq!(tm_updates[1], ValidatorSetUpdate::Deactivated(pk2)); @@ -812,7 +818,10 @@ fn test_validator_sets() { tm_updates[0], ValidatorSetUpdate::Consensus(ConsensusValidator { consensus_key: pk4.clone(), - bonded_stake: stake4, + bonded_stake: into_tm_voting_power( + params.tm_votes_per_token, + stake4 + ), }) ); assert_eq!(tm_updates[1], ValidatorSetUpdate::Deactivated(pk1)); @@ -927,7 +936,10 @@ fn test_validator_sets() { tm_updates[0], ValidatorSetUpdate::Consensus(ConsensusValidator { consensus_key: pk6, - bonded_stake: stake6, + bonded_stake: into_tm_voting_power( + params.tm_votes_per_token, + stake6 + ), }) ); assert_eq!(tm_updates[1], ValidatorSetUpdate::Deactivated(pk4)); @@ -1187,7 +1199,10 @@ fn test_validator_sets_swap() { tm_updates[0], ValidatorSetUpdate::Consensus(ConsensusValidator { consensus_key: pk3.clone(), - bonded_stake: stake3, + bonded_stake: into_tm_voting_power( + params.tm_votes_per_token, + stake3 + ), }) ); @@ -1226,14 +1241,17 @@ fn test_validator_sets_swap() { assert_eq!(epoch, bonds_epoch_3); let tm_updates = get_tendermint_set_updates(&s, ¶ms, epoch); - dbg!(&tm_updates); + // dbg!(&tm_updates); assert_eq!(tm_updates.len(), 2); assert_eq!( tm_updates, vec![ ValidatorSetUpdate::Consensus(ConsensusValidator { consensus_key: new_ck2, - bonded_stake: stake2, + bonded_stake: into_tm_voting_power( + params.tm_votes_per_token, + stake2 + ), }), ValidatorSetUpdate::Deactivated(pk3), ] diff --git a/crates/proof_of_stake/src/types/mod.rs b/crates/proof_of_stake/src/types/mod.rs index 282ab6a6d4..b2a0d176ad 100644 --- a/crates/proof_of_stake/src/types/mod.rs +++ b/crates/proof_of_stake/src/types/mod.rs @@ -388,13 +388,13 @@ pub enum ValidatorSetUpdate { Deactivated(common::PublicKey), } -/// Consensus validator's consensus key and its bonded stake. +/// Newly updated consensus validator's consensus key and bonded stake. #[derive(Debug, Clone, PartialEq)] pub struct ConsensusValidator { /// A public key used for signing validator's consensus actions pub consensus_key: common::PublicKey, /// Total bonded stake of the validator - pub bonded_stake: token::Amount, + pub bonded_stake: i64, } /// ID of a bond and/or an unbond. diff --git a/crates/proof_of_stake/src/validator_set_update.rs b/crates/proof_of_stake/src/validator_set_update.rs index ed0d8fa1a5..474af4ddda 100644 --- a/crates/proof_of_stake/src/validator_set_update.rs +++ b/crates/proof_of_stake/src/validator_set_update.rs @@ -653,7 +653,7 @@ where return vec![ValidatorSetUpdate::Consensus( ConsensusValidator { consensus_key: new_consensus_key, - bonded_stake: new_stake, + bonded_stake: *new_tm_voting_power, }, )]; } @@ -667,7 +667,7 @@ where vec![ ValidatorSetUpdate::Consensus(ConsensusValidator { consensus_key: new_consensus_key, - bonded_stake: new_stake, + bonded_stake: *new_tm_voting_power, }), ValidatorSetUpdate::Deactivated( prev_consensus_key.unwrap(), @@ -682,7 +682,7 @@ where } else { vec![ValidatorSetUpdate::Consensus(ConsensusValidator { consensus_key: new_consensus_key, - bonded_stake: new_stake, + bonded_stake: *new_tm_voting_power, })] } });