Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoS SM fixes #2221

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions proof_of_stake/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ impl OwnedPosParams {
max_proposal_period: gov.max_proposal_period,
}
}

/// A test helper to add the default gov params to PoS params.
#[cfg(any(test, feature = "testing"))]
pub fn with_gov_params(self, gov: &GovernanceParameters) -> PosParams {
PosParams {
owned: self,
max_proposal_period: gov.max_proposal_period,
}
}
}

impl std::ops::Deref for PosParams {
Expand Down
8 changes: 7 additions & 1 deletion proof_of_stake/src/tests/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::ops::Deref;

use assert_matches::assert_matches;
use itertools::Itertools;
use namada_core::ledger::governance::parameters::GovernanceParameters;
use namada_core::ledger::storage::testing::TestWlStorage;
use namada_core::ledger::storage_api::collections::lazy_map::{
Collectable, NestedSubKey, SubKey,
Expand Down Expand Up @@ -104,6 +105,8 @@ struct AbstractPosState {
epoch: Epoch,
/// Parameters
params: PosParams,
/// Governance parameters used to construct `params`
gov_params: GovernanceParameters,
/// Genesis validators
genesis_validators: Vec<GenesisValidator>,
/// Bonds delta values. The outer key for Epoch is pipeline offset from
Expand Down Expand Up @@ -217,6 +220,7 @@ impl StateMachineTest for ConcretePosState {
.collect::<Vec<_>>()
);
let mut s = TestWlStorage::default();
initial_state.gov_params.init_storage(&mut s).unwrap();
crate::test_utils::test_init_genesis(
&mut s,
initial_state.params.owned.clone(),
Expand Down Expand Up @@ -1985,11 +1989,13 @@ impl ReferenceStateMachine for AbstractPosState {
tracing::debug!("\nInitializing abstract state machine");
arb_params_and_genesis_validators(Some(8), 8..10)
.prop_map(|(params, genesis_validators)| {
let params = params.with_default_gov_params();
let gov_params = GovernanceParameters::default();
let params = params.with_gov_params(&gov_params);
let epoch = Epoch::default();
let mut state = Self {
epoch,
params,
gov_params,
genesis_validators: genesis_validators
.into_iter()
// Sorted by stake to fill in the consensus set first
Expand Down
12 changes: 8 additions & 4 deletions proof_of_stake/src/tests/state_machine_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{cmp, mem};
use assert_matches::assert_matches;
use derivative::Derivative;
use itertools::Itertools;
use namada_core::ledger::governance::parameters::GovernanceParameters;
use namada_core::ledger::storage::testing::TestWlStorage;
use namada_core::ledger::storage_api::collections::lazy_map::{
NestedSubKey, SubKey,
Expand Down Expand Up @@ -66,6 +67,8 @@ struct AbstractPosState {
epoch: Epoch,
/// Parameters
params: PosParams,
/// Governance parameters used to construct `params`
gov_params: GovernanceParameters,
/// Genesis validators
#[derivative(Debug = "ignore")]
genesis_validators: Vec<GenesisValidator>,
Expand Down Expand Up @@ -1929,6 +1932,7 @@ impl StateMachineTest for ConcretePosState {
.collect::<Vec<_>>()
);
let mut s = TestWlStorage::default();
initial_state.gov_params.init_storage(&mut s).unwrap();
crate::test_utils::init_genesis_helper(
&mut s,
&initial_state.params,
Expand Down Expand Up @@ -3575,12 +3579,12 @@ impl ReferenceStateMachine for AbstractPosState {
arb_params_and_genesis_validators(Some(8), 8..10)
.prop_map(|(params, genesis_validators)| {
let epoch = Epoch::default();
let gov_params = GovernanceParameters::default();
let params = params.with_gov_params(&gov_params);
let mut state = Self {
epoch,
params: PosParams {
owned: params,
..Default::default()
},
params,
gov_params,
genesis_validators: genesis_validators
.into_iter()
// Sorted by stake to fill in the consensus set first
Expand Down
Loading