Skip to content

Commit

Permalink
Merge branch 'brent/jailed-inactive-vals-no-voting' (#3004)
Browse files Browse the repository at this point in the history
* origin/brent/jailed-inactive-vals-no-voting:
  rename total_active_voting_power --> total_active_deltas
  • Loading branch information
tzemanovic committed Apr 8, 2024
2 parents 5ec9f90 + 28ddef6 commit 8ba327f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
16 changes: 8 additions & 8 deletions crates/proof_of_stake/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ pub fn liveness_sum_missed_votes_handle() -> LivenessSumMissedVotes {
LivenessSumMissedVotes::open(key)
}

/// Get the storage handle to the total active voting power
pub fn total_active_voting_power_handle() -> TotalDeltas {
let key = storage_key::total_active_voting_power_key();
/// Get the storage handle to the total active deltas
pub fn total_active_deltas_handle() -> TotalDeltas {
let key = storage_key::total_active_deltas_key();
TotalDeltas::open(key)
}

Expand Down Expand Up @@ -531,7 +531,7 @@ pub fn read_total_active_stake<S>(
where
S: StorageRead,
{
let handle = total_active_voting_power_handle();
let handle = total_active_deltas_handle();
let amnt = handle
.get_sum(storage, epoch, params)?
.map(|change| {
Expand Down Expand Up @@ -697,7 +697,7 @@ where
{
let offset = offset_opt.unwrap_or(params.pipeline_len);
let total_deltas = total_deltas_handle();
let total_active_voting_power = total_active_voting_power_handle();
let total_active_deltas = total_active_deltas_handle();

// Update total deltas
let total_deltas_val = total_deltas
Expand All @@ -714,12 +714,12 @@ where

// Update total active voting power
if update_active_voting_power {
let active_val = total_active_voting_power
let active_delta = total_active_deltas
.get_delta_val(storage, current_epoch + offset)?
.unwrap_or_default();
total_active_voting_power.set(
total_active_deltas.set(
storage,
active_val.checked_add(&delta).expect(
active_delta.checked_add(&delta).expect(
"Total active voting power updated amount should not overflow",
),
current_epoch,
Expand Down
14 changes: 7 additions & 7 deletions crates/proof_of_stake/src/storage_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const LIVENESS_MISSED_VOTES: &str = "missed_votes";
const LIVENESS_MISSED_VOTES_SUM: &str = "sum_missed_votes";
const LAST_STAKED_RATIO_KEY: &str = "last_staked_ratio";
const LAST_POS_INFLATION_AMOUNT_KEY: &str = "last_inflation_amount";
const TOTAL_ACTIVE_VOTING_POWER_KEY: &str = "total_active_voting_power";
const TOTAL_ACTIVE_DELTAS_KEY: &str = "total_active_deltas";

/// Is the given key a PoS storage key?
pub fn is_pos_key(key: &Key) -> bool {
Expand Down Expand Up @@ -1062,20 +1062,20 @@ pub fn last_pos_inflation_amount_key() -> Key {
.expect("Cannot obtain a storage key")
}

/// Storage key for total active voting power (Consensus, Below-Capacity, and
/// Storage key for total active deltas (Consensus, Below-Capacity, and
/// Below-threshold validators).
pub fn total_active_voting_power_key() -> Key {
pub fn total_active_deltas_key() -> Key {
Key::from(ADDRESS.to_db_key())
.push(&TOTAL_ACTIVE_VOTING_POWER_KEY.to_owned())
.push(&TOTAL_ACTIVE_DELTAS_KEY.to_owned())
.expect("Cannot obtain a storage key")
}

/// Is storage key for total active voting power?
pub fn is_total_active_voting_power_key(key: &Key) -> bool {
/// Is storage key for total active deltas?
pub fn is_total_active_deltas_key(key: &Key) -> bool {
if key.segments.len() >= 2 {
match &key.segments[..2] {
[DbKeySeg::AddressSeg(addr), DbKeySeg::StringSeg(prefix)] => {
addr == &ADDRESS && prefix == TOTAL_ACTIVE_VOTING_POWER_KEY
addr == &ADDRESS && prefix == TOTAL_ACTIVE_DELTAS_KEY
}
_ => false,
}
Expand Down
2 changes: 1 addition & 1 deletion wasm/wasm_source/src/vp_implicit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ fn validate_pos_changes(

let pos_state_changes = is_valid_bond_or_unbond_change().is_ok()
|| storage_key::is_total_deltas_key(key)
|| storage_key::is_total_active_voting_power_key(key)
|| storage_key::is_total_active_deltas_key(key)
|| storage_key::is_validator_deltas_key(key)
|| storage_key::is_validator_total_bond_or_unbond_key(key)
|| storage_key::is_validator_set_positions_key(key)
Expand Down
19 changes: 9 additions & 10 deletions wasm/wasm_source/src/vp_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ use proof_of_stake::parameters::MAX_VALIDATOR_METADATA_LEN;
use proof_of_stake::storage::{read_pos_params, validator_state_handle};
use proof_of_stake::storage_key::{
self, is_below_capacity_validator_set_key, is_consensus_keys_key,
is_consensus_validator_set_key, is_pos_key,
is_total_active_voting_power_key, is_total_consensus_stake_key,
is_total_deltas_key, is_validator_address_raw_hash_key,
is_validator_addresses_key, is_validator_commission_rate_key,
is_validator_deltas_key, is_validator_eth_cold_key_key,
is_validator_eth_hot_key_key, is_validator_max_commission_rate_change_key,
is_validator_metadata_key, is_validator_set_positions_key,
is_validator_state_epoched_meta_key, is_validator_state_key,
is_validator_total_bond_or_unbond_key,
is_consensus_validator_set_key, is_pos_key, is_total_active_deltas_key,
is_total_consensus_stake_key, is_total_deltas_key,
is_validator_address_raw_hash_key, is_validator_addresses_key,
is_validator_commission_rate_key, is_validator_deltas_key,
is_validator_eth_cold_key_key, is_validator_eth_hot_key_key,
is_validator_max_commission_rate_change_key, is_validator_metadata_key,
is_validator_set_positions_key, is_validator_state_epoched_meta_key,
is_validator_state_key, is_validator_total_bond_or_unbond_key,
};

enum KeyType<'a> {
Expand Down Expand Up @@ -399,7 +398,7 @@ fn validate_pos_changes(

let pos_state_changes = is_valid_bond_or_unbond_change().is_ok()
|| is_total_deltas_key(key)
|| is_total_active_voting_power_key(key)
|| is_total_active_deltas_key(key)
|| is_validator_deltas_key(key)
|| is_validator_total_bond_or_unbond_key(key)
|| is_validator_set_positions_key(key)
Expand Down

0 comments on commit 8ba327f

Please sign in to comment.