diff --git a/.changelog/unreleased/bug-fixes/1553-fix-is-validator-fn.md b/.changelog/unreleased/bug-fixes/1553-fix-is-validator-fn.md new file mode 100644 index 0000000000..c66e587913 --- /dev/null +++ b/.changelog/unreleased/bug-fixes/1553-fix-is-validator-fn.md @@ -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)) \ No newline at end of file diff --git a/proof_of_stake/src/lib.rs b/proof_of_stake/src/lib.rs index e98659b70f..1308d92e11 100644 --- a/proof_of_stake/src/lib.rs +++ b/proof_of_stake/src/lib.rs @@ -808,14 +808,12 @@ where pub fn is_validator( storage: &S, address: &Address, - params: &PosParams, - epoch: namada_core::types::storage::Epoch, ) -> storage_api::Result 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 @@ -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, ¶ms, pipeline_epoch)? - { + if source != validator && is_validator(storage, source)? { return Err( BondError::SourceMustNotBeAValidator(source.clone()).into() ); @@ -1533,16 +1529,14 @@ where // Make sure source is not some other validator if let Some(source) = source { - if source != validator - && is_validator(storage, source, ¶ms, 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, ¶ms, pipeline_epoch)? { + if !is_validator(storage, validator)? { return Err(BondError::NotAValidator(validator.clone()).into()); } // Make sure the validator is not currently frozen diff --git a/proof_of_stake/src/tests.rs b/proof_of_stake/src/tests.rs index c670160c7b..95b8d91fac 100644 --- a/proof_of_stake/src/tests.rs +++ b/proof_of_stake/src/tests.rs @@ -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, @@ -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(); @@ -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) diff --git a/proof_of_stake/src/tests/state_machine.rs b/proof_of_stake/src/tests/state_machine.rs index 85bcf093b4..df3c85be13 100644 --- a/proof_of_stake/src/tests/state_machine.rs +++ b/proof_of_stake/src/tests/state_machine.rs @@ -252,13 +252,7 @@ impl StateMachineTest for ConcretePosState { // This must be ensured by both transitions generator and // pre-conditions! assert!( - crate::is_validator( - &state.s, - &id.validator, - ¶ms, - pipeline, - ) - .unwrap(), + crate::is_validator(&state.s, &id.validator).unwrap(), "{} is not a validator", id.validator ); diff --git a/shared/src/ledger/queries/vp/pos.rs b/shared/src/ledger/queries/vp/pos.rs index 7e89e0293e..d4b4b6ad68 100644 --- a/shared/src/ledger/queries/vp/pos.rs +++ b/shared/src/ledger/queries/vp/pos.rs @@ -142,13 +142,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, - ¶ms, - ctx.wl_storage.storage.block.epoch, - ) + namada_proof_of_stake::is_validator(ctx.wl_storage, &addr) } /// Find if the given address is a delegator diff --git a/wasm/checksums.json b/wasm/checksums.json index 78aef0ade1..8e2e714b1b 100644 --- a/wasm/checksums.json +++ b/wasm/checksums.json @@ -1,21 +1,21 @@ { - "tx_bond.wasm": "tx_bond.e3a64e4026c81610b62d4b8fa5e8a5c24ac279d110eb402ccffce5d79db07b93.wasm", - "tx_change_validator_commission.wasm": "tx_change_validator_commission.c81cf8b64f13edce96fd6924c979c101c6199596101ce694f47b206b3673da06.wasm", - "tx_ibc.wasm": "tx_ibc.e8bee97364213334475df66e9a0e23dcf3154ea60294aac72642c3d74c942073.wasm", - "tx_init_account.wasm": "tx_init_account.c17afaeec08c6f90757980bd60fa0d77b4b36b9d0c68ecc71bda222b2f204a86.wasm", - "tx_init_proposal.wasm": "tx_init_proposal.4f10ec824404193f9fc37088aecc7f53564f535191fcd54ab6fbd0bf14a64b28.wasm", - "tx_init_validator.wasm": "tx_init_validator.55e3e1b8222d1b43a15a0ed1488fb2e9eacbaadf5513277a1d8003083b7c2af7.wasm", - "tx_reveal_pk.wasm": "tx_reveal_pk.f5ab2c096a8253c3db83c344724388811f925c884156e18a6c3a634d07ee7640.wasm", - "tx_transfer.wasm": "tx_transfer.1d98257dc00b851c616c1c9e8ab978a6eac0cedebdda22ae3270b47aaf5b164c.wasm", - "tx_unbond.wasm": "tx_unbond.64494eb5a012b5d9515329ff471efed49e6b0eefe6f281ef04a7dbbd344d6234.wasm", - "tx_unjail_validator.wasm": "tx_unjail_validator.624e2dd02883cc21f5738ec11542e1732eea4943ddf683b44d0644b3914c427d.wasm", - "tx_update_vp.wasm": "tx_update_vp.cefd67a267f34d8e93b207a39de9e920616f3d4e5e629086bbcb88b079ce6856.wasm", - "tx_vote_proposal.wasm": "tx_vote_proposal.71da34c54ece175129519120bd597b0226896827cfe0e1c76f435489cd899617.wasm", - "tx_withdraw.wasm": "tx_withdraw.37634f6111c4decc45901c20bd4640cceca68ddc51da70adb9bfdfb539c05259.wasm", - "vp_implicit.wasm": "vp_implicit.3acce29720aa7fedb75e7408c09b6bbd6e3a20e0afa7a0f20d58864d8fc3c111.wasm", - "vp_masp.wasm": "vp_masp.cd7fae1152e765ad4e3985fbdd0b8b2cb1cea13e2fff812291ebaf484f8676c9.wasm", - "vp_testnet_faucet.wasm": "vp_testnet_faucet.1dc87f66e7a378df435a20f97592e3a7746a3ccb322ca11889f11822d312ee22.wasm", - "vp_token.wasm": "vp_token.56c0f16a5c67e36a10716b10fe392271e205b9c095c7d9bf161dc646dd0644ff.wasm", - "vp_user.wasm": "vp_user.5cd6a74674f71d7b61ec6491cfb567028233e1844f3ee1b21d3cc573366dcc62.wasm", - "vp_validator.wasm": "vp_validator.aadb458e884c877afcf1c316da24ec529c946d0cb8f9f4e578ab3eec8efb4e16.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.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.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", + "vp_token.wasm": "vp_token.d1f3cbfd1fccc432e9070b3b94ce1fe21798dc41c557c9201d58d52a02c61337.wasm", + "vp_user.wasm": "vp_user.7514d52275b0d2cb403db04f62656148dbb8570c47d2ec5bd21bb53fa45987a7.wasm", + "vp_validator.wasm": "vp_validator.02eab5750ce4773c2bd350cc642f39aa5d50e58aaa2a2974313329a138335566.wasm" } \ No newline at end of file