Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/unreleased/bug-fixes/1553-fix-is-validator-fn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- PoS: fixed a check for whether a given address belongs to a
validator account to work properly with newly created accounts.
([\#1553](https://github.com/anoma/namada/pull/1553))
16 changes: 5 additions & 11 deletions proof_of_stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,14 +808,12 @@ where
pub fn is_validator<S>(
storage: &S,
address: &Address,
params: &PosParams,
epoch: namada_core::types::storage::Epoch,
) -> storage_api::Result<bool>
where
S: StorageRead + StorageWrite,
{
let state = validator_state_handle(address).get(storage, epoch, params)?;
Ok(state.is_some())
let rate = read_validator_max_commission_rate_change(storage, address)?;
Ok(rate.is_some())
}

/// Check if the provided address is a delegator address, optionally at a
Expand Down Expand Up @@ -868,9 +866,7 @@ where
let params = read_pos_params(storage)?;
let pipeline_epoch = current_epoch + params.pipeline_len;
if let Some(source) = source {
if source != validator
&& is_validator(storage, source, &params, pipeline_epoch)?
{
if source != validator && is_validator(storage, source)? {
return Err(
BondError::SourceMustNotBeAValidator(source.clone()).into()
);
Expand Down Expand Up @@ -1534,16 +1530,14 @@ where

// Make sure source is not some other validator
if let Some(source) = source {
if source != validator
&& is_validator(storage, source, &params, pipeline_epoch)?
{
if source != validator && is_validator(storage, source)? {
return Err(
BondError::SourceMustNotBeAValidator(source.clone()).into()
);
}
}
// Make sure the target is actually a validator
if !is_validator(storage, validator, &params, pipeline_epoch)? {
if !is_validator(storage, validator)? {
return Err(BondError::NotAValidator(validator.clone()).into());
}
// Make sure the validator is not currently frozen
Expand Down
4 changes: 3 additions & 1 deletion proof_of_stake/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::{
bond_tokens, bonds_and_unbonds, consensus_validator_set_handle,
copy_validator_sets_and_positions, find_validator_by_raw_hash,
get_num_consensus_validators, init_genesis,
insert_validator_into_validator_set, process_slashes,
insert_validator_into_validator_set, is_validator, process_slashes,
read_below_capacity_validator_set_addresses_with_stake,
read_consensus_validator_set_addresses_with_stake, read_total_stake,
read_validator_delta_value, read_validator_stake, slash,
Expand Down Expand Up @@ -789,6 +789,7 @@ fn test_become_validator_aux(
min(validators.len() as u64, params.max_validator_slots),
num_consensus_before
);
assert!(!is_validator(&s, &new_validator).unwrap());

// Initialize the validator account
let consensus_key = new_validator_consensus_key.to_public();
Expand All @@ -802,6 +803,7 @@ fn test_become_validator_aux(
Decimal::new(5, 2),
)
.unwrap();
assert!(is_validator(&s, &new_validator).unwrap());

let num_consensus_after =
get_num_consensus_validators(&s, current_epoch + params.pipeline_len)
Expand Down
8 changes: 1 addition & 7 deletions proof_of_stake/src/tests/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,7 @@ impl StateMachineTest for ConcretePosState {
// This must be ensured by both transitions generator and
// pre-conditions!
assert!(
crate::is_validator(
&state.s,
&id.validator,
&params,
pipeline,
)
.unwrap(),
crate::is_validator(&state.s, &id.validator).unwrap(),
"{} is not a validator",
id.validator
);
Expand Down
8 changes: 1 addition & 7 deletions shared/src/ledger/queries/vp/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,7 @@ where
D: 'static + DB + for<'iter> DBIter<'iter> + Sync,
H: 'static + StorageHasher + Sync,
{
let params = namada_proof_of_stake::read_pos_params(ctx.wl_storage)?;
namada_proof_of_stake::is_validator(
ctx.wl_storage,
&addr,
&params,
ctx.wl_storage.storage.block.epoch,
)
namada_proof_of_stake::is_validator(ctx.wl_storage, &addr)
}

/// Find if the given address is a delegator
Expand Down
10 changes: 5 additions & 5 deletions wasm/checksums.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"tx_bond.wasm": "tx_bond.9d034041d7085d261e2d75e548b74e0635b7c87f14173aecddbd64d8a8646d58.wasm",
"tx_change_validator_commission.wasm": "tx_change_validator_commission.5d172f38a22a045902e83d10ebdcaef88f75a0511dc5c3e224ef89d7fc594b78.wasm",
"tx_bond.wasm": "tx_bond.4f5c6ca2ac0e933ab9d7370743de4950f95f5ad3ccb3d3a45ab42daa1e69506f.wasm",
"tx_change_validator_commission.wasm": "tx_change_validator_commission.9c8d8fe732a794bc00fe9247d5e28a6b4df6959018140a05161c27ac68aab853.wasm",
"tx_ibc.wasm": "tx_ibc.462075ed66348d74f60a7af04d5200acff673ddb1a1d16497fbc97ee846e1851.wasm",
"tx_init_account.wasm": "tx_init_account.7e827fb86331b0b62eb1162f917e522f6f426df9608d67c13caed089d63cd25f.wasm",
"tx_init_proposal.wasm": "tx_init_proposal.4fe5500d95d040ca3f2e51446bfb96cfc99596302e4e2368ee599f1a610f5968.wasm",
"tx_init_validator.wasm": "tx_init_validator.a6db44f07090f6c19dea71f1865f6acba1a4a946c29057231312188dfbfd1c9e.wasm",
"tx_reveal_pk.wasm": "tx_reveal_pk.3bb71bb884737ab184b4f543b503e512431d0e8cad24d202981c06063a11614c.wasm",
"tx_transfer.wasm": "tx_transfer.8c24cc4bb4e947a7fab4708039300cfa36b0513db55e6ca45b1d7276db1eb02c.wasm",
"tx_unbond.wasm": "tx_unbond.99aacaa049edea0704a147d2feb79702fbae8a014092f41b8483daeff5eee181.wasm",
"tx_unjail_validator.wasm": "tx_unjail_validator.d9fe28aadc5d21d9d0c8e89365e5e8e68420c8f5c15c5c12c8587120822b9ceb.wasm",
"tx_unbond.wasm": "tx_unbond.88b522ab08abe228d6deb2716060cfc1db9ebff016c3d97a8b94d80126b96aab.wasm",
"tx_unjail_validator.wasm": "tx_unjail_validator.4cad94633f701614c891c74a7d829dd44cd39ee0aebf6a6921ccea1bb9333214.wasm",
"tx_update_vp.wasm": "tx_update_vp.c5706b7f5223deb15f2fae1646ee487948dd0ac25450ca460d9dfa55f29ab2c5.wasm",
"tx_vote_proposal.wasm": "tx_vote_proposal.df21ee966e13f9c5731deea7c8a2ed62612d4706691b35564b058ed175b476ef.wasm",
"tx_withdraw.wasm": "tx_withdraw.cbb043216f2fc75b88a32bd3fbad8a05b48df4c3d6bdbc8284606a71b9be9d38.wasm",
"tx_withdraw.wasm": "tx_withdraw.0f4a54d0158937f50df7077baf78766bb2549361015f27d911810aea4228358a.wasm",
"vp_implicit.wasm": "vp_implicit.c3b78b8b0bb9072a9a4c9e2aa1e89e04db9fdc41eecd53850698bfea89631103.wasm",
"vp_masp.wasm": "vp_masp.8c4ea33db73f13ad9c6efd1634780fd872e7acadb5a615e96f4b2cbbf8626463.wasm",
"vp_testnet_faucet.wasm": "vp_testnet_faucet.403d3d09e582968305223e66a0c35c7b91fd62ac9bc07bab32250bc9120d2114.wasm",
Expand Down