Skip to content

Commit

Permalink
cleanup after rebase (updated #677)
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone authored and tzemanovic committed Dec 5, 2022
1 parent e43fb43 commit bfcd34e
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 39 deletions.
2 changes: 1 addition & 1 deletion core/src/ledger/storage/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,4 +874,4 @@ mod test {
);
assert!(basetree_verification_res);
}
}
}
16 changes: 9 additions & 7 deletions proof_of_stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}

Expand All @@ -1712,7 +1712,7 @@ pub fn bond_handle(
source: &Address,
validator: &Address
) -> LazyMap<Epoch, token::Amount> {
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)
}
Expand All @@ -1721,7 +1721,7 @@ pub fn bond_handle(
pub fn init_genesis_NEW<S>(
storage: &mut S,
params: &PosParams,
validators: impl Iterator<Item = GenesisValidator_NEW> + Clone,
validators: impl Iterator<Item = GenesisValidator> + Clone,
current_epoch: namada_core::types::storage::Epoch,
) -> storage_api::Result<()>
where
Expand All @@ -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(
Expand Down Expand Up @@ -1761,7 +1763,7 @@ pub fn read_validator_consensus_key<S>(
params: &PosParams,
validator: &Address,
epoch: namada_core::types::storage::Epoch,
) -> storage_api::Result<Option<key::common::PublicKey>>
) -> storage_api::Result<Option<common::PublicKey>>
where
S: for<'iter> StorageRead<'iter>,
{
Expand All @@ -1774,7 +1776,7 @@ pub fn write_validator_consensus_key<S>(
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
Expand Down
6 changes: 2 additions & 4 deletions proof_of_stake/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -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) {
Expand Down
26 changes: 1 addition & 25 deletions proof_of_stake/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
>;
Expand Down Expand Up @@ -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<Address, token::Amount, key::common::PublicKey>;

/// An update of the active and inactive validator set.
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -213,8 +191,6 @@ pub struct ValidatorSet {
pub inactive: BTreeSet<WeightedValidator>,
}

pub type ValidatorSet_NEW = ValidatorSet<Address>;

/// Validator's state.
#[derive(
Debug,
Expand Down
28 changes: 28 additions & 0 deletions shared/src/ledger/pos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -64,3 +69,26 @@ pub fn init_genesis_storage_NEW<DB, H>(
)
.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;
2 changes: 1 addition & 1 deletion shared/src/types/key/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//! Cryptographic keys
pub use namada_core::types::key::*;
pub use namada_core::types::key::*;
2 changes: 1 addition & 1 deletion tests/src/native_vp/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bfcd34e

Please sign in to comment.