Skip to content

Commit

Permalink
fixup! store total consensus stake; garbage collect validator sets
Browse files Browse the repository at this point in the history
  • Loading branch information
karbyshev committed Jul 6, 2023
1 parent c6c37a1 commit aa8da81
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
5 changes: 0 additions & 5 deletions apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,6 @@ pub mod genesis_config {
/// The minimum amount of bonded tokens that a validator needs to be in
/// either the `consensus` or `below_capacity` validator sets
pub validator_stake_threshold: token::Amount,
/// Number of epochs below the current epoch for which the full
/// validator set is stored
pub store_validator_set_len: u64,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -634,7 +631,6 @@ pub mod genesis_config {
light_client_attack_min_slash_rate,
cubic_slashing_window_length,
validator_stake_threshold,
store_validator_set_len,
} = pos_params;
let pos_params = PosParams {
max_validator_slots,
Expand All @@ -649,7 +645,6 @@ pub mod genesis_config {
light_client_attack_min_slash_rate,
cubic_slashing_window_length,
validator_stake_threshold,
store_validator_set_len,
};

let mut genesis = Genesis {
Expand Down
1 change: 0 additions & 1 deletion apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ where
namada_proof_of_stake::purge_validator_sets_for_old_epoch(
&mut self.wl_storage,
current_epoch,
&pos_params,
)?;
}

Expand Down
9 changes: 6 additions & 3 deletions proof_of_stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ pub fn staking_token_address(storage: &impl StorageRead) -> Address {
.expect("Must be able to read native token address")
}

/// Number of epochs below the current epoch for which full validator sets are
/// stored
const STORE_VALIDATOR_SETS_LEN: u64 = 2;

#[allow(missing_docs)]
#[derive(Error, Debug)]
pub enum GenesisError {
Expand Down Expand Up @@ -1660,13 +1664,12 @@ where
pub fn purge_validator_sets_for_old_epoch<S>(
storage: &mut S,
epoch: Epoch,
params: &PosParams,
) -> storage_api::Result<()>
where
S: StorageRead + StorageWrite,
{
if Epoch(params.store_validator_set_len) < epoch {
let old_epoch = epoch - params.store_validator_set_len - 1;
if Epoch(STORE_VALIDATOR_SETS_LEN) < epoch {
let old_epoch = epoch - STORE_VALIDATOR_SETS_LEN - 1;
consensus_validator_set_handle()
.get_data_handler()
.remove_all(storage, &old_epoch)?;
Expand Down
4 changes: 0 additions & 4 deletions proof_of_stake/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ pub struct PosParams {
/// The minimum amount of bonded tokens that a validator needs to be in
/// either the `consensus` or `below_capacity` validator sets
pub validator_stake_threshold: token::Amount,
/// Number of epochs below the current epoch for which the full validator
/// set is stored
pub store_validator_set_len: u64,
}

impl Default for PosParams {
Expand All @@ -73,7 +70,6 @@ impl Default for PosParams {
.expect("Test failed"),
cubic_slashing_window_length: 1,
validator_stake_threshold: token::Amount::native_whole(1_u64),
store_validator_set_len: 2,
}
}
}
Expand Down

0 comments on commit aa8da81

Please sign in to comment.