Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoS crate refactors #1928

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
196bfec
SQUASHED redelegation
brentstone Jun 23, 2023
90f32b1
pos/SM: fix update_redelegated_bonds in v1
brentstone Sep 15, 2023
4d5a959
fixup! SQUASHED redelegation
tzemanovic Sep 18, 2023
59a6fd8
add redelegate to cli commands
tzemanovic Sep 18, 2023
63e47d5
test/e2e: add redelegation to `pos_bonds` ledger test
tzemanovic Sep 18, 2023
9fef2b6
fix redelegation tx code path
tzemanovic Sep 18, 2023
53b8e12
pos/SM: fix bug in updating map of validator slashed amounts
brentstone Sep 19, 2023
0665d40
test/ethereum_bridge: fix PS initializationin the affected test
tzemanovic Sep 19, 2023
200a27d
fix cli dest validator arg
tzemanovic Sep 19, 2023
c5eb4cd
test/e2e: simplify to only require single node
tzemanovic Sep 19, 2023
6fd0a48
tx_redelegate: refactor
tzemanovic Sep 19, 2023
e00abe3
prohibit redelegation with src == dest validator
tzemanovic Sep 19, 2023
3398066
update wasm tests
brentstone Sep 19, 2023
a9e3f68
fix buggy storage removal of empty unbonds
brentstone Sep 20, 2023
1099ae2
error handling in client redelegation submission
brentstone Sep 20, 2023
d4cff58
use token zero fns everywhere
brentstone Sep 20, 2023
1e57754
fixup! error handling in client redelegation submission
brentstone Sep 20, 2023
cb1abe1
update `bond` client errors and lib fn
brentstone Sep 20, 2023
80959c6
update `unbond` client
brentstone Sep 20, 2023
43734bd
WIP: polishing `unbond_tokens`
brentstone Sep 22, 2023
7475c44
benches: add redelegation tx
tzemanovic Sep 22, 2023
24639f4
wasm/tx_redelegate: update gas cost
tzemanovic Sep 22, 2023
fdfb1bc
fixup! benches: add redelegation tx
tzemanovic Sep 22, 2023
515ceba
PoS: rename mod storage to storage_key
tzemanovic Sep 22, 2023
b93df45
PoS: move storage lazy collection handles into sub-mod
tzemanovic Sep 22, 2023
16201a2
gov: use `fn is_delegator` avoid using PoS storage directly
tzemanovic Sep 22, 2023
b6fb0c9
eth: add higher-level functions to read validator ETH cold and hot key
tzemanovic Sep 22, 2023
4847921
PoS: remove `StorageWrite` trait bound on `fn is_delegator`
tzemanovic Sep 22, 2023
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
48 changes: 25 additions & 23 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ use namada::ledger::storage::EPOCH_SWITCH_BLOCKS_DELAY;
use namada::ledger::storage_api::token::credit_tokens;
use namada::ledger::storage_api::{pgf, StorageRead, StorageWrite};
use namada::ledger::{inflation, protocol, replay_protection};
use namada::proof_of_stake::{
delegator_rewards_products_handle, find_validator_by_raw_hash,
read_last_block_proposer_address, read_pos_params, read_total_stake,
read_validator_stake, rewards_accumulator_handle,
use namada::proof_of_stake::storage::{
delegator_rewards_products_handle, rewards_accumulator_handle,
validator_commission_rate_handle, validator_rewards_products_handle,
};
use namada::proof_of_stake::{
find_validator_by_raw_hash, read_last_block_proposer_address,
read_pos_params, read_total_stake, read_validator_stake,
write_last_block_proposer_address,
};
use namada::types::address::Address;
Expand Down Expand Up @@ -1084,17 +1086,20 @@ mod test_finalize_block {
use namada::ledger::storage_api;
use namada::ledger::storage_api::StorageWrite;
use namada::proof_of_stake::storage::{
enqueued_slashes_handle, rewards_accumulator_handle,
validator_consensus_key_handle, validator_rewards_products_handle,
validator_slashes_handle, validator_state_handle,
};
use namada::proof_of_stake::storage_key::{
is_validator_slashes_key, slashes_prefix,
};
use namada::proof_of_stake::types::{
BondId, SlashType, ValidatorState, WeightedValidator,
};
use namada::proof_of_stake::{
enqueued_slashes_handle, get_num_consensus_validators,
read_consensus_validator_set_addresses_with_stake,
rewards_accumulator_handle, unjail_validator,
validator_consensus_key_handle, validator_rewards_products_handle,
validator_slashes_handle, validator_state_handle, write_pos_params,
get_num_consensus_validators,
read_consensus_validator_set_addresses_with_stake, unjail_validator,
write_pos_params,
};
use namada::proto::{Code, Data, Section, Signature};
use namada::types::dec::POS_DECIMAL_PRECISION;
Expand Down Expand Up @@ -1946,11 +1951,10 @@ mod test_finalize_block {
let validator = shell.mode.get_validator_address().unwrap();
let pos_params =
namada_proof_of_stake::read_pos_params(&shell.wl_storage).unwrap();
let consensus_key =
namada_proof_of_stake::validator_consensus_key_handle(validator)
.get(&shell.wl_storage, Epoch::default(), &pos_params)
.unwrap()
.unwrap();
let consensus_key = validator_consensus_key_handle(validator)
.get(&shell.wl_storage, Epoch::default(), &pos_params)
.unwrap()
.unwrap();
let proposer_address = HEXUPPER
.decode(consensus_key.tm_raw_hash().as_bytes())
.unwrap();
Expand Down Expand Up @@ -2602,11 +2606,10 @@ mod test_finalize_block {
let validator = shell.mode.get_validator_address().unwrap().to_owned();
let pos_params =
namada_proof_of_stake::read_pos_params(&shell.wl_storage).unwrap();
let consensus_key =
namada_proof_of_stake::validator_consensus_key_handle(&validator)
.get(&shell.wl_storage, Epoch::default(), &pos_params)
.unwrap()
.unwrap();
let consensus_key = validator_consensus_key_handle(&validator)
.get(&shell.wl_storage, Epoch::default(), &pos_params)
.unwrap()
.unwrap();
let proposer_address = HEXUPPER
.decode(consensus_key.tm_raw_hash().as_bytes())
.unwrap();
Expand Down Expand Up @@ -3369,7 +3372,7 @@ mod test_finalize_block {
.unwrap();
assert_eq!(last_slash, Some(misbehavior_epoch));
assert!(
namada_proof_of_stake::validator_slashes_handle(&val1.address)
validator_slashes_handle(&val1.address)
.is_empty(&shell.wl_storage)
.unwrap()
);
Expand Down Expand Up @@ -3446,7 +3449,7 @@ mod test_finalize_block {
.unwrap()
);
assert!(
namada_proof_of_stake::validator_slashes_handle(&val1.address)
validator_slashes_handle(&val1.address)
.is_empty(&shell.wl_storage)
.unwrap()
);
Expand Down Expand Up @@ -3528,8 +3531,7 @@ mod test_finalize_block {

// There should be 2 slashes processed for the validator, each with rate
// equal to the cubic slashing rate
let val_slashes =
namada_proof_of_stake::validator_slashes_handle(&val1.address);
let val_slashes = validator_slashes_handle(&val1.address);
assert_eq!(val_slashes.len(&shell.wl_storage).unwrap(), 2u64);
let is_rate_good = val_slashes
.iter(&shell.wl_storage)
Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ mod test_utils {
};
use namada::ledger::storage_api::StorageWrite;
use namada::proof_of_stake::parameters::PosParams;
use namada::proof_of_stake::validator_consensus_key_handle;
use namada::proof_of_stake::storage::validator_consensus_key_handle;
use namada::proto::{Code, Data};
use namada::tendermint_proto::abci::VoteInfo;
use namada::types::address;
Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/node/ledger/shell/prepare_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,9 @@ mod test_prepare_proposal {
use namada::ledger::gas::Gas;
use namada::ledger::pos::PosQueries;
use namada::ledger::replay_protection;
use namada::proof_of_stake::storage::consensus_validator_set_handle;
use namada::proof_of_stake::types::WeightedValidator;
use namada::proof_of_stake::{
consensus_validator_set_handle,
read_consensus_validator_set_addresses_with_stake, Epoch,
};
#[cfg(feature = "abcipp")]
Expand Down
6 changes: 2 additions & 4 deletions apps/src/lib/node/ledger/shell/testing/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ use namada::ledger::storage::{
LastBlock, Sha256Hasher, EPOCH_SWITCH_BLOCKS_DELAY,
};
use namada::proof_of_stake::pos_queries::PosQueries;
use namada::proof_of_stake::read_consensus_validator_set_addresses_with_stake;
use namada::proof_of_stake::storage::validator_consensus_key_handle;
use namada::proof_of_stake::types::WeightedValidator;
use namada::proof_of_stake::{
read_consensus_validator_set_addresses_with_stake,
validator_consensus_key_handle,
};
use namada::tendermint_proto::abci::VoteInfo;
use namada::tendermint_rpc::endpoint::abci_info;
use namada::tendermint_rpc::SimpleRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,13 @@ mod test_bp_vote_extensions {
use namada::ledger::eth_bridge::EthBridgeQueries;
use namada::ledger::pos::PosQueries;
use namada::ledger::storage_api::StorageWrite;
use namada::proof_of_stake::storage::consensus_validator_set_handle;
use namada::proof_of_stake::types::{
Position as ValidatorPosition, WeightedValidator,
};
use namada::proof_of_stake::{
become_validator, consensus_validator_set_handle,
read_consensus_validator_set_addresses_with_stake, BecomeValidator,
Epoch,
become_validator, read_consensus_validator_set_addresses_with_stake,
BecomeValidator, Epoch,
};
use namada::proto::{SignableEthMessage, Signed};
use namada::tendermint_proto::abci::VoteInfo;
Expand Down
6 changes: 2 additions & 4 deletions apps/src/lib/node/ledger/shell/vote_extensions/eth_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,9 @@ mod test_vote_extensions {
};
use namada::eth_bridge::storage::bridge_pool;
use namada::ledger::pos::PosQueries;
use namada::proof_of_stake::read_consensus_validator_set_addresses_with_stake;
use namada::proof_of_stake::storage::consensus_validator_set_handle;
use namada::proof_of_stake::types::WeightedValidator;
use namada::proof_of_stake::{
consensus_validator_set_handle,
read_consensus_validator_set_addresses_with_stake,
};
#[cfg(feature = "abcipp")]
use namada::proto::{SignableEthMessage, Signed};
use namada::tendermint_proto::abci::VoteInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ mod test_vote_extensions {
};
use namada::ledger::eth_bridge::EthBridgeQueries;
use namada::ledger::pos::PosQueries;
use namada::proof_of_stake::storage::consensus_validator_set_handle;
use namada::proof_of_stake::types::WeightedValidator;
use namada::proof_of_stake::{
consensus_validator_set_handle,
read_consensus_validator_set_addresses_with_stake, Epoch,
};
#[cfg(feature = "abcipp")]
Expand Down
10 changes: 3 additions & 7 deletions ethereum_bridge/src/storage/eth_bridge_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use namada_core::types::voting_power::{
};
use namada_proof_of_stake::pos_queries::{ConsensusValidators, PosQueries};
use namada_proof_of_stake::{
validator_eth_cold_key_handle, validator_eth_hot_key_handle,
read_validator_eth_cold_key, read_validator_eth_hot_key,
};

use crate::storage::proof::BridgePoolRootProof;
Expand Down Expand Up @@ -293,9 +293,7 @@ where
) -> Option<EthAddress> {
let epoch = epoch
.unwrap_or_else(|| self.wl_storage.storage.get_current_epoch().0);
let params = self.wl_storage.pos_queries().get_pos_params();
validator_eth_hot_key_handle(validator)
.get(self.wl_storage, epoch, &params)
read_validator_eth_hot_key(self.wl_storage, validator, epoch)
.expect("Should be able to read eth hot key from storage")
.and_then(|ref pk| pk.try_into().ok())
}
Expand All @@ -310,9 +308,7 @@ where
) -> Option<EthAddress> {
let epoch = epoch
.unwrap_or_else(|| self.wl_storage.storage.get_current_epoch().0);
let params = self.wl_storage.pos_queries().get_pos_params();
validator_eth_cold_key_handle(validator)
.get(self.wl_storage, epoch, &params)
read_validator_eth_cold_key(self.wl_storage, validator, epoch)
.expect("Should be able to read eth cold key from storage")
.and_then(|ref pk| pk.try_into().ok())
}
Expand Down
Loading
Loading