From bfcd34e508e8514b53456be245eb0171824d92ac Mon Sep 17 00:00:00 2001 From: brentstone Date: Mon, 14 Nov 2022 13:36:40 -0500 Subject: [PATCH] cleanup after rebase (updated #677) --- core/src/ledger/storage/merkle_tree.rs | 2 +- proof_of_stake/src/lib.rs | 16 ++++++++------- proof_of_stake/src/storage.rs | 6 ++---- proof_of_stake/src/types.rs | 26 +----------------------- shared/src/ledger/pos/mod.rs | 28 ++++++++++++++++++++++++++ shared/src/types/key/mod.rs | 2 +- tests/src/native_vp/pos.rs | 2 +- 7 files changed, 43 insertions(+), 39 deletions(-) diff --git a/core/src/ledger/storage/merkle_tree.rs b/core/src/ledger/storage/merkle_tree.rs index eb690356e54..9848462417d 100644 --- a/core/src/ledger/storage/merkle_tree.rs +++ b/core/src/ledger/storage/merkle_tree.rs @@ -874,4 +874,4 @@ mod test { ); assert!(basetree_verification_res); } -} +} \ No newline at end of file diff --git a/proof_of_stake/src/lib.rs b/proof_of_stake/src/lib.rs index 7e92fdf6fbb..ba57b659039 100644 --- a/proof_of_stake/src/lib.rs +++ b/proof_of_stake/src/lib.rs @@ -36,12 +36,12 @@ use parameters::PosParams; use rust_decimal::Decimal; use thiserror::Error; use types::{ - ActiveValidator, Bonds, CommissionRate, Epoch, GenesisValidator, GenesisValidator_NEW, + ActiveValidator, Bonds, CommissionRates, GenesisValidator, Slash, SlashType, Slashes, TotalDeltas, Unbond, Unbonds, ValidatorConsensusKeys, ValidatorConsensusKeys_NEW, ValidatorSet, ValidatorSetUpdate, ValidatorSets, ValidatorState, ValidatorStates, ValidatorDeltas, ValidatorStates_NEW, - ValidatorDeltas_NEW, ValidatorSets_NEW, BondId_NEW + ValidatorDeltas_NEW, ValidatorSets_NEW }; use crate::btree_set::BTreeSetShims; @@ -1703,7 +1703,7 @@ pub fn validator_state_handle( pub fn validator_deltas_handle( validator: &Address ) -> ValidatorDeltas_NEW { - let key = storage::validator_total_deltas_key(&validator); + let key = storage::validator_deltas_key(&validator); crate::epoched_new::EpochedDelta::open(key) } @@ -1712,7 +1712,7 @@ pub fn bond_handle( source: &Address, validator: &Address ) -> LazyMap { - let bond_id = BondId_NEW {source: source.clone(), validator: validator.clone()}; + let bond_id = BondId {source: source.clone(), validator: validator.clone()}; let key = storage::bond_key(&bond_id); LazyMap::open(key) } @@ -1721,7 +1721,7 @@ pub fn bond_handle( pub fn init_genesis_NEW( storage: &mut S, params: &PosParams, - validators: impl Iterator + Clone, + validators: impl Iterator + Clone, current_epoch: namada_core::types::storage::Epoch, ) -> storage_api::Result<()> where @@ -1732,6 +1732,8 @@ where address, tokens, consensus_key, + commission_rate, + max_commission_rate_change } in validators { validator_consensus_key_handle(&address).init_at_genesis( @@ -1761,7 +1763,7 @@ pub fn read_validator_consensus_key( params: &PosParams, validator: &Address, epoch: namada_core::types::storage::Epoch, -) -> storage_api::Result> +) -> storage_api::Result> where S: for<'iter> StorageRead<'iter>, { @@ -1774,7 +1776,7 @@ pub fn write_validator_consensus_key( storage: &mut S, params: &PosParams, validator: &Address, - consensus_key: key::common::PublicKey, + consensus_key: common::PublicKey, current_epoch: namada_core::types::storage::Epoch, ) -> storage_api::Result<()> where diff --git a/proof_of_stake/src/storage.rs b/proof_of_stake/src/storage.rs index e543bc46bb3..412ef679627 100644 --- a/proof_of_stake/src/storage.rs +++ b/proof_of_stake/src/storage.rs @@ -2,7 +2,7 @@ use namada_core::ledger::storage::types::{decode, encode}; use namada_core::ledger::storage::{self, Storage, StorageHasher}; -use namada_core::types::address::{self, Address}; +use namada_core::types::address::Address; use namada_core::types::storage::{DbKeySeg, Key, KeySeg}; use namada_core::types::{key, token}; use rust_decimal::Decimal; @@ -17,7 +17,7 @@ const VALIDATOR_STORAGE_PREFIX: &str = "validator_NEW"; const VALIDATOR_ADDRESS_RAW_HASH: &str = "address_raw_hash_NEW"; const VALIDATOR_CONSENSUS_KEY_STORAGE_KEY: &str = "consensus_key_NEW"; const VALIDATOR_STATE_STORAGE_KEY: &str = "state_NEW"; -const VALIDATOR_ELTAS_STORAGE_KEY: &str = "validator_deltas_NEW"; +const VALIDATOR_DELTAS_STORAGE_KEY: &str = "validator_deltas_NEW"; const VALIDATOR_COMMISSION_RATE_STORAGE_KEY: &str = "commission_rate_NEW"; const VALIDATOR_MAX_COMMISSION_CHANGE_STORAGE_KEY: &str = "max_commission_rate_change_NEW"; @@ -27,8 +27,6 @@ const UNBOND_STORAGE_KEY: &str = "unbond_NEW"; const VALIDATOR_SET_STORAGE_KEY: &str = "validator_set_NEW"; const TOTAL_DELTAS_STORAGE_KEY: &str = "total_deltas_NEW"; -const ADDRESS: Address = address::POS; - /// Is the given key a PoS storage key? pub fn is_pos_key(key: &Key) -> bool { match &key.segments.get(0) { diff --git a/proof_of_stake/src/types.rs b/proof_of_stake/src/types.rs index af4469a33ea..c70d4954419 100644 --- a/proof_of_stake/src/types.rs +++ b/proof_of_stake/src/types.rs @@ -37,7 +37,7 @@ pub type ValidatorStates_NEW = crate::epoched_new::Epoched< /// Epoched validator sets. pub type ValidatorSets_NEW = crate::epoched_new::Epoched< - ValidatorSet_NEW, + ValidatorSet, crate::epoched_new::OffsetPipelineLen, 0 >; @@ -100,8 +100,6 @@ pub struct GenesisValidator { /// Maximum change in commission rate permitted per epoch pub max_commission_rate_change: Decimal, } -pub type GenesisValidator_NEW = - GenesisValidator; /// An update of the active and inactive validator set. #[derive(Debug, Clone)] @@ -141,26 +139,6 @@ pub struct BondId { pub validator: Address, } -/// ID of a bond and/or an unbond. -#[derive( - Debug, - Clone, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - BorshDeserialize, - BorshSerialize, - BorshSchema, -)] -pub struct BondId_NEW { - /// (Un)bond's source address is the owner of the bonded tokens. - pub source: Address, - /// (Un)bond's validator address. - pub validator: Address, -} - /// Validator's address with its voting power. #[derive( Debug, @@ -213,8 +191,6 @@ pub struct ValidatorSet { pub inactive: BTreeSet, } -pub type ValidatorSet_NEW = ValidatorSet
; - /// Validator's state. #[derive( Debug, diff --git a/shared/src/ledger/pos/mod.rs b/shared/src/ledger/pos/mod.rs index 71402967da5..aef8b1b95a0 100644 --- a/shared/src/ledger/pos/mod.rs +++ b/shared/src/ledger/pos/mod.rs @@ -14,6 +14,11 @@ use crate::ledger::storage::{self as ledger_storage, Storage, StorageHasher}; use crate::types::address::{Address, InternalAddress}; use crate::types::storage::Epoch; +pub use namada_core::types::key::common; +pub use namada_core::types::token; +pub use namada_core::ledger::storage_api; + + /// Address of the PoS account implemented as a native VP pub const ADDRESS: Address = Address::Internal(InternalAddress::PoS); @@ -64,3 +69,26 @@ pub fn init_genesis_storage_NEW( ) .expect("Initialize PoS genesis storage"); } + +/// Alias for a PoS type with the same name with concrete type parameters +pub type ValidatorConsensusKeys = + namada_proof_of_stake::types::ValidatorConsensusKeys; + +/// Alias for a PoS type with the same name with concrete type parameters +pub type ValidatorDeltas = + namada_proof_of_stake::types::ValidatorDeltas; + +/// Alias for a PoS type with the same name with concrete type parameters +pub type Bonds = namada_proof_of_stake::types::Bonds; + +/// Alias for a PoS type with the same name with concrete type parameters +pub type Unbonds = namada_proof_of_stake::types::Unbonds; + +/// Alias for a PoS type with the same name with concrete type parameters +pub type ValidatorSets = namada_proof_of_stake::types::ValidatorSets; + +/// Alias for a PoS type with the same name with concrete type parameters +pub type BondId = namada_proof_of_stake::types::BondId; + +/// Alias for a PoS type with the same name with concrete type parameters +pub type GenesisValidator = namada_proof_of_stake::types::GenesisValidator; diff --git a/shared/src/types/key/mod.rs b/shared/src/types/key/mod.rs index 11a7af55335..f49f9f379c8 100644 --- a/shared/src/types/key/mod.rs +++ b/shared/src/types/key/mod.rs @@ -1,3 +1,3 @@ //! Cryptographic keys -pub use namada_core::types::key::*; +pub use namada_core::types::key::*; \ No newline at end of file diff --git a/tests/src/native_vp/pos.rs b/tests/src/native_vp/pos.rs index 69b7502a505..e556d684a2e 100644 --- a/tests/src/native_vp/pos.rs +++ b/tests/src/native_vp/pos.rs @@ -100,7 +100,7 @@ use namada::ledger::pos::namada_proof_of_stake::PosBase; use namada::proof_of_stake::storage::GenesisValidator; -use namada::proof_of_stake::PosParams; +use namada::proof_of_stake::parameters::PosParams; use namada::types::storage::Epoch; use crate::tx::tx_host_env;