From 022c61adf8643009087c99f058a7930794014d13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 13 Jun 2023 10:06:48 +0200 Subject: [PATCH 1/4] pos: fix is_validator to be epoch agnostic --- proof_of_stake/src/lib.rs | 16 +++++----------- proof_of_stake/src/tests/state_machine.rs | 8 +------- shared/src/ledger/queries/vp/pos.rs | 8 +------- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/proof_of_stake/src/lib.rs b/proof_of_stake/src/lib.rs index b1fdb82bc0a..1c9e475ff93 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() ); @@ -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, ¶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/state_machine.rs b/proof_of_stake/src/tests/state_machine.rs index 85d1758e26c..2e8b0c4d252 100644 --- a/proof_of_stake/src/tests/state_machine.rs +++ b/proof_of_stake/src/tests/state_machine.rs @@ -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, - ¶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 81fc3f681b2..dd0e561514c 100644 --- a/shared/src/ledger/queries/vp/pos.rs +++ b/shared/src/ledger/queries/vp/pos.rs @@ -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, - ¶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 From 6cfee905a996569a7b0cadec3184c43549ea2216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 13 Jun 2023 10:07:10 +0200 Subject: [PATCH 2/4] test/pos: check is_validator for a new validator --- proof_of_stake/src/tests.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/proof_of_stake/src/tests.rs b/proof_of_stake/src/tests.rs index edc01d3c358..08dcde453f2 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) From 5ae25fb21edf96771522601cee04e85d68f8a5b2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 13 Jun 2023 08:45:52 +0000 Subject: [PATCH 3/4] [ci] wasm checksums update --- wasm/checksums.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/wasm/checksums.json b/wasm/checksums.json index 718af73ccad..8e2e714b1bf 100644 --- a/wasm/checksums.json +++ b/wasm/checksums.json @@ -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", From 3be1d72d6f521fbf625791fe74f0ead03162f1a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 13 Jun 2023 10:47:34 +0200 Subject: [PATCH 4/4] changelog: add #1553 --- .changelog/unreleased/bug-fixes/1553-fix-is-validator-fn.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/unreleased/bug-fixes/1553-fix-is-validator-fn.md 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 00000000000..c66e5879139 --- /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