From 8cc15c0ab9b175d2582ca365abc861dde44c5bb1 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 | 15 +-- core/src/types/transaction/governance.rs | 1 - 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 | 158 ++--------------------- shared/src/types/key/mod.rs | 3 +- shared/src/types/mod.rs | 1 - tests/src/native_vp/pos.rs | 2 +- tx_prelude/src/lib.rs | 2 +- 10 files changed, 29 insertions(+), 201 deletions(-) diff --git a/core/src/ledger/storage/merkle_tree.rs b/core/src/ledger/storage/merkle_tree.rs index 2124410c536..b28e1b9eb85 100644 --- a/core/src/ledger/storage/merkle_tree.rs +++ b/core/src/ledger/storage/merkle_tree.rs @@ -13,6 +13,7 @@ use ics23::{CommitmentProof, ExistenceProof, NonExistenceProof}; use thiserror::Error; use super::traits::{StorageHasher, SubTreeRead, SubTreeWrite}; +use crate::bytes::ByteBuf; use crate::ledger::storage::ics23_specs::{self, ibc_leaf_spec}; use crate::ledger::storage::types; use crate::types::address::{Address, InternalAddress}; @@ -873,16 +874,4 @@ mod test { ); assert!(basetree_verification_res); } -} - -/// Type of membership proof from a merkle tree -pub enum MembershipProof { - /// ICS23 compliant membership proof - ICS23(CommitmentProof), -} - -impl From for MembershipProof { - fn from(proof: CommitmentProof) -> Self { - Self::ICS23(proof) - } -} +} \ No newline at end of file diff --git a/core/src/types/transaction/governance.rs b/core/src/types/transaction/governance.rs index 4641b1eede8..ba2bd5f9336 100644 --- a/core/src/types/transaction/governance.rs +++ b/core/src/types/transaction/governance.rs @@ -1,5 +1,4 @@ use borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::governance::{Proposal, ProposalError}; use serde::{Deserialize, Serialize}; use crate::types::address::Address; diff --git a/proof_of_stake/src/lib.rs b/proof_of_stake/src/lib.rs index bffef8a26ed..7fe319b5b07 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 3e7b63c7922..fafb69c70b7 100644 --- a/proof_of_stake/src/storage.rs +++ b/proof_of_stake/src/storage.rs @@ -3,7 +3,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; @@ -18,7 +18,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"; @@ -28,8 +28,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 81ebde868d1..57f9edcc9ea 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 e74f7db857f..dd23d92356d 100644 --- a/shared/src/ledger/pos/mod.rs +++ b/shared/src/ledger/pos/mod.rs @@ -14,6 +14,10 @@ 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); @@ -69,161 +73,23 @@ pub fn init_genesis_storage_NEW( /// Alias for a PoS type with the same name with concrete type parameters pub type ValidatorConsensusKeys = - namada_proof_of_stake::types::ValidatorConsensusKeys< - key::common::PublicKey, - >; + namada_proof_of_stake::types::ValidatorConsensusKeys; /// Alias for a PoS type with the same name with concrete type parameters -pub type ValidatorTotalDeltas = - namada_proof_of_stake::types::ValidatorTotalDeltas; +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; +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; +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
; +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
; +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< - Address, - token::Amount, - key::common::PublicKey, ->; - -#[macro_use] -mod macros { - /// Implement `PosReadOnly` for a type that implements - /// [`trait@crate::ledger::storage_api::StorageRead`]. - /// - /// Excuse the horrible syntax - we haven't found a better way to use this - /// for native_vp `CtxPreStorageRead`/`CtxPostStorageRead`, which have - /// generics and explicit lifetimes. - /// - /// # Examples - /// - /// ```ignore - /// impl_pos_read_only! { impl PosReadOnly for X } - /// ``` - #[macro_export] - macro_rules! impl_pos_read_only { - ( - // Type error type has to be declared before the impl. - // This error type must `impl From for $error`. - type $error:tt = $err_ty:ty ; - // Matches anything, so that we can use lifetimes and generic types. - // This expects `impl(<.*>)? PoSReadOnly for $ty(<.*>)?`. - $( $any:tt )* ) - => { - $( $any )* - { - type Address = $crate::types::address::Address; - type $error = $err_ty; - type PublicKey = $crate::types::key::common::PublicKey; - type TokenAmount = $crate::types::token::Amount; - type TokenChange = $crate::types::token::Change; - - const POS_ADDRESS: Self::Address = $crate::ledger::pos::ADDRESS; - - fn staking_token_address() -> Self::Address { - $crate::ledger::pos::staking_token_address() - } - - fn read_pos_params(&self) -> std::result::Result { - let value = $crate::ledger::storage_api::StorageRead::read_bytes(self, ¶ms_key())?.unwrap(); - Ok($crate::ledger::storage::types::decode(value).unwrap()) - } - - fn read_validator_consensus_key( - &self, - key: &Self::Address, - ) -> std::result::Result, Self::Error> { - let value = - $crate::ledger::storage_api::StorageRead::read_bytes(self, &validator_consensus_key_key(key))?; - Ok(value.map(|value| $crate::ledger::storage::types::decode(value).unwrap())) - } - - fn read_validator_state( - &self, - key: &Self::Address, - ) -> std::result::Result, Self::Error> { - let value = $crate::ledger::storage_api::StorageRead::read_bytes(self, &validator_state_key(key))?; - Ok(value.map(|value| $crate::ledger::storage::types::decode(value).unwrap())) - } - - fn read_validator_total_deltas( - &self, - key: &Self::Address, - ) -> std::result::Result, Self::Error> { - let value = - $crate::ledger::storage_api::StorageRead::read_bytes(self, &validator_total_deltas_key(key))?; - Ok(value.map(|value| $crate::ledger::storage::types::decode(value).unwrap())) - } - - fn read_validator_voting_power( - &self, - key: &Self::Address, - ) -> std::result::Result, Self::Error> { - let value = - $crate::ledger::storage_api::StorageRead::read_bytes(self, &validator_voting_power_key(key))?; - Ok(value.map(|value| $crate::ledger::storage::types::decode(value).unwrap())) - } - - fn read_validator_slashes( - &self, - key: &Self::Address, - ) -> std::result::Result, Self::Error> { - let value = $crate::ledger::storage_api::StorageRead::read_bytes(self, &validator_slashes_key(key))?; - Ok(value - .map(|value| $crate::ledger::storage::types::decode(value).unwrap()) - .unwrap_or_default()) - } - - fn read_bond( - &self, - key: &BondId, - ) -> std::result::Result, Self::Error> { - let value = $crate::ledger::storage_api::StorageRead::read_bytes(self, &bond_key(key))?; - Ok(value.map(|value| $crate::ledger::storage::types::decode(value).unwrap())) - } - - fn read_unbond( - &self, - key: &BondId, - ) -> std::result::Result, Self::Error> { - let value = $crate::ledger::storage_api::StorageRead::read_bytes(self, &unbond_key(key))?; - Ok(value.map(|value| $crate::ledger::storage::types::decode(value).unwrap())) - } - - fn read_validator_set( - &self, - ) -> std::result::Result { - let value = - $crate::ledger::storage_api::StorageRead::read_bytes(self, &validator_set_key())?.unwrap(); - Ok($crate::ledger::storage::types::decode(value).unwrap()) - } - - fn read_total_voting_power( - &self, - ) -> std::result::Result { - let value = - $crate::ledger::storage_api::StorageRead::read_bytes(self, &total_voting_power_key())?.unwrap(); - Ok($crate::ledger::storage::types::decode(value).unwrap()) - } - } - } -} -} - -impl_pos_read_only! { - type Error = storage_api::Error; - impl PosReadOnly for Storage - where - DB: ledger_storage::DB + for<'iter> ledger_storage::DBIter<'iter> +'static, - H: StorageHasher +'static, -} +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 2a176d022e6..f49f9f379c8 100644 --- a/shared/src/types/key/mod.rs +++ b/shared/src/types/key/mod.rs @@ -1,4 +1,3 @@ //! Cryptographic keys -pub use namada_core::types::key::*; -pub mod dkg_session_keys; \ No newline at end of file +pub use namada_core::types::key::*; \ No newline at end of file diff --git a/shared/src/types/mod.rs b/shared/src/types/mod.rs index 4b9ea17d10c..7d3cdb105b7 100644 --- a/shared/src/types/mod.rs +++ b/shared/src/types/mod.rs @@ -2,7 +2,6 @@ pub mod ibc; pub mod key; -pub mod transaction; pub use namada_core::types::{ address, chain, governance, hash, internal, storage, time, token, 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; diff --git a/tx_prelude/src/lib.rs b/tx_prelude/src/lib.rs index b3be1ae9516..463073b9e54 100644 --- a/tx_prelude/src/lib.rs +++ b/tx_prelude/src/lib.rs @@ -237,7 +237,7 @@ impl StorageWrite for Ctx { } impl TxEnv<'_> for Ctx { - type IbcEvent = namada::types::ibc::IbcEvent; + type IbcEvent = namada_core::types::ibc::IbcEvent; fn get_block_time(&self) -> Result { let read_result = unsafe { anoma_tx_get_block_time() };