Skip to content

Commit

Permalink
Revert "fix: expire all previous epochs (#5279)"
Browse files Browse the repository at this point in the history
This reverts commit 5baa3dd.
  • Loading branch information
kylezs committed Oct 29, 2024
1 parent 5baa3dd commit b724f08
Show file tree
Hide file tree
Showing 21 changed files with 116 additions and 247 deletions.
22 changes: 11 additions & 11 deletions state-chain/cf-integration-tests/src/authorities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ pub fn fund_authorities_and_join_auction(
/// by going through the correct sequence in sync.
#[test]
fn authority_rotates_with_correct_sequence() {
const EPOCH_DURATION_BLOCKS: u32 = 1000;
const EPOCH_BLOCKS: u32 = 1000;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_DURATION_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand Down Expand Up @@ -162,7 +162,7 @@ fn authorities_earn_rewards_for_authoring_blocks() {
// set
const MAX_AUTHORITIES: AuthorityCount = 3;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand Down Expand Up @@ -206,7 +206,7 @@ fn genesis_nodes_rotated_out_accumulate_rewards_correctly() {
// set
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand Down Expand Up @@ -273,7 +273,7 @@ fn authority_rotation_can_succeed_after_aborted_by_safe_mode() {
const EPOCH_BLOCKS: u32 = 1000;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand Down Expand Up @@ -328,7 +328,7 @@ fn authority_rotation_cannot_be_aborted_after_key_handover_and_completes_even_on
const EPOCH_BLOCKS: u32 = 1000;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand Down Expand Up @@ -371,7 +371,7 @@ fn authority_rotation_can_recover_after_keygen_fails() {
const EPOCH_BLOCKS: u32 = 1000;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand Down Expand Up @@ -424,7 +424,7 @@ fn authority_rotation_can_recover_after_key_handover_fails() {
const EPOCH_BLOCKS: u32 = 1000;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand Down Expand Up @@ -502,7 +502,7 @@ fn can_move_through_multiple_epochs() {
const EPOCH_BLOCKS: u32 = 100;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand All @@ -524,7 +524,7 @@ fn cant_rotate_if_previous_rotation_is_pending() {
const EPOCH_BLOCKS: u32 = 100;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand Down Expand Up @@ -559,7 +559,7 @@ fn waits_for_governance_when_apicall_fails() {
const EPOCH_BLOCKS: u32 = 100;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand Down
4 changes: 2 additions & 2 deletions state-chain/cf-integration-tests/src/broadcasting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use state_chain_runtime::{

#[test]
fn bitcoin_broadcast_delay_works() {
const EPOCH_DURATION_BLOCKS: u32 = 200;
const EPOCH_BLOCKS: u32 = 200;
const MAX_AUTHORITIES: AuthorityCount = 150;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_DURATION_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand Down
16 changes: 8 additions & 8 deletions state-chain/cf-integration-tests/src/funding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ use state_chain_runtime::{
// We have a set of nodes that are funded and can redeem in the redeeming period and
// not redeem when out of the period
fn cannot_redeem_funds_out_of_redemption_period() {
const EPOCH_DURATION_BLOCKS: u32 = 100;
const EPOCH_BLOCKS: u32 = 100;
const MAX_AUTHORITIES: AuthorityCount = 3;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_DURATION_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand Down Expand Up @@ -68,7 +68,7 @@ fn cannot_redeem_funds_out_of_redemption_period() {
}

let end_of_redemption_period =
EPOCH_DURATION_BLOCKS * REDEMPTION_PERIOD_AS_PERCENTAGE as u32 / 100;
EPOCH_BLOCKS * REDEMPTION_PERIOD_AS_PERCENTAGE as u32 / 100;
// Move to end of the redemption period
System::set_block_number(end_of_redemption_period + 1);
// We will try to redeem
Expand Down Expand Up @@ -125,7 +125,7 @@ fn cannot_redeem_funds_out_of_redemption_period() {
fn funded_node_is_added_to_backups() {
const EPOCH_BLOCKS: u32 = 10_000_000;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
// As we run a rotation at genesis we will need accounts to support
// having 5 authorities as the default is 3 (Alice, Bob and Charlie)
.accounts(vec![
Expand All @@ -149,7 +149,7 @@ fn backup_reward_is_calculated_linearly() {
const MAX_AUTHORITIES: u32 = 10;
const NUM_BACKUPS: u32 = 20;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand Down Expand Up @@ -194,7 +194,7 @@ fn can_calculate_account_apy() {
const MAX_AUTHORITIES: u32 = 10;
const NUM_BACKUPS: u32 = 20;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand Down Expand Up @@ -246,7 +246,7 @@ fn apy_can_be_above_100_percent() {
const MAX_AUTHORITIES: u32 = 2;
const NUM_BACKUPS: u32 = 2;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand Down Expand Up @@ -282,7 +282,7 @@ fn backup_rewards_event_gets_emitted_on_heartbeat_interval() {
const NUM_BACKUPS: u32 = 20;
const MAX_AUTHORITIES: u32 = 100;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.accounts(
(0..MAX_AUTHORITIES as u8)
.map(|i| (AccountId32::from([i; 32]), AccountRole::Validator, GENESIS_BALANCE))
Expand Down
8 changes: 4 additions & 4 deletions state-chain/cf-integration-tests/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use state_chain_runtime::{
};
pub const GENESIS_BALANCE: FlipBalance = TOTAL_ISSUANCE / 100;

const EPOCH_DURATION: u32 = 1000;
const BLOCKS_PER_EPOCH: u32 = 1000;

pub fn with_test_defaults() -> ExtBuilder {
ExtBuilder::default()
Expand All @@ -26,7 +26,7 @@ pub fn with_test_defaults() -> ExtBuilder {
(AccountId::from(LIQUIDITY_PROVIDER), AccountRole::LiquidityProvider, GENESIS_BALANCE),
])
.root(AccountId::from(ERIN))
.epoch_duration(EPOCH_DURATION)
.blocks_per_epoch(BLOCKS_PER_EPOCH)
}

#[test]
Expand Down Expand Up @@ -62,8 +62,8 @@ fn state_of_genesis_is_as_expected() {
}

assert_eq!(
Validator::epoch_duration(),
EPOCH_DURATION,
Validator::blocks_per_epoch(),
BLOCKS_PER_EPOCH,
"epochs will not rotate automatically from genesis"
);

Expand Down
10 changes: 5 additions & 5 deletions state-chain/cf-integration-tests/src/mock_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ use cf_primitives::{
pub struct ExtBuilder {
pub genesis_accounts: Vec<(AccountId, AccountRole, FlipBalance)>,
root: Option<AccountId>,
epoch_duration: BlockNumber,
blocks_per_epoch: BlockNumber,
max_authorities: AuthorityCount,
min_authorities: AuthorityCount,
}
Expand All @@ -79,7 +79,7 @@ impl Default for ExtBuilder {
min_authorities: 1,
genesis_accounts: Default::default(),
root: Default::default(),
epoch_duration: Default::default(),
blocks_per_epoch: Default::default(),
}
}
}
Expand All @@ -103,8 +103,8 @@ impl ExtBuilder {
self
}

pub fn epoch_duration(mut self, epoch_duration: BlockNumber) -> Self {
self.epoch_duration = epoch_duration;
pub fn blocks_per_epoch(mut self, blocks_per_epoch: BlockNumber) -> Self {
self.blocks_per_epoch = blocks_per_epoch;
self
}

Expand Down Expand Up @@ -184,7 +184,7 @@ impl ExtBuilder {
})
.collect(),
genesis_backups: Default::default(),
epoch_duration: self.epoch_duration,
blocks_per_epoch: self.blocks_per_epoch,
bond: self
.genesis_accounts
.iter()
Expand Down
2 changes: 1 addition & 1 deletion state-chain/cf-integration-tests/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ impl Network {
/// Move to the last block of the epoch - next block will start Authority rotation
pub fn move_to_the_end_of_epoch(&mut self) {
let current_block = System::block_number();
let target = Validator::current_epoch_started_at() + Validator::epoch_duration();
let target = Validator::current_epoch_started_at() + Validator::blocks_per_epoch();
if target > current_block {
self.move_forward_blocks(target - current_block - 1)
}
Expand Down
8 changes: 4 additions & 4 deletions state-chain/cf-integration-tests/src/new_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use state_chain_runtime::{

#[test]
fn auction_repeats_after_failure_because_of_liveness() {
const EPOCH_DURATION_BLOCKS: BlockNumber = 1000;
const EPOCH_BLOCKS: BlockNumber = 1000;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_DURATION_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
// As we run a rotation at genesis we will need accounts to support
// having 5 authorities as the default is 3 (Alice, Bob and Charlie)
.accounts(vec![
Expand Down Expand Up @@ -107,7 +107,7 @@ fn epoch_rotates() {
const EPOCH_BLOCKS: BlockNumber = 1000;
const MAX_SET_SIZE: AuthorityCount = 5;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.min_authorities(MAX_SET_SIZE)
.build()
.execute_with(|| {
Expand Down Expand Up @@ -247,7 +247,7 @@ fn can_consolidate_bitcoin_utxos() {
const MAX_AUTHORITIES: AuthorityCount = 5;
const CONSOLIDATION_SIZE: u32 = 2;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.build()
.execute_with(|| {
let (mut testnet, _, _) =
Expand Down
16 changes: 8 additions & 8 deletions state-chain/cf-integration-tests/src/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ fn schedule_deposit_to_swap(

#[test]
fn can_build_solana_batch_all() {
const EPOCH_DURATION_BLOCKS: u32 = 100;
const EPOCH_BLOCKS: u32 = 100;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_DURATION_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.with_additional_accounts(&[
(DORIS, AccountRole::LiquidityProvider, 5 * FLIPPERINOS_PER_FLIP),
Expand Down Expand Up @@ -225,7 +225,7 @@ fn can_rotate_solana_vault() {
const EPOCH_BLOCKS: u32 = 100;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand Down Expand Up @@ -284,7 +284,7 @@ fn can_send_solana_ccm() {
const EPOCH_BLOCKS: u32 = 100;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.with_additional_accounts(&[
(DORIS, AccountRole::LiquidityProvider, 5 * FLIPPERINOS_PER_FLIP),
Expand Down Expand Up @@ -363,7 +363,7 @@ fn solana_ccm_fails_with_invalid_input() {
const EPOCH_BLOCKS: u32 = 100;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.with_additional_accounts(&[
(DORIS, AccountRole::LiquidityProvider, 5 * FLIPPERINOS_PER_FLIP),
Expand Down Expand Up @@ -528,7 +528,7 @@ fn failed_ccm_does_not_consume_durable_nonce() {
const EPOCH_BLOCKS: u32 = 100;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.with_additional_accounts(&[
(DORIS, AccountRole::LiquidityProvider, 5 * FLIPPERINOS_PER_FLIP),
Expand Down Expand Up @@ -590,7 +590,7 @@ fn solana_resigning() {
const EPOCH_BLOCKS: u32 = 100;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.with_additional_accounts(&[
(DORIS, AccountRole::LiquidityProvider, 5 * FLIPPERINOS_PER_FLIP),
Expand Down Expand Up @@ -666,7 +666,7 @@ fn solana_ccm_execution_error_can_trigger_fallback() {
const EPOCH_BLOCKS: u32 = 100;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.with_additional_accounts(&[
(DORIS, AccountRole::LiquidityProvider, 5 * FLIPPERINOS_PER_FLIP),
Expand Down
6 changes: 3 additions & 3 deletions state-chain/cf-integration-tests/src/swapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,10 +767,10 @@ fn ethereum_ccm_can_calculate_gas_limits() {

#[test]
fn can_resign_failed_ccm() {
const EPOCH_DURATION_BLOCKS: u32 = 1000;
const EPOCH_BLOCKS: u32 = 1000;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_DURATION_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand Down Expand Up @@ -882,7 +882,7 @@ fn can_handle_failed_vault_transfer() {
const EPOCH_BLOCKS: u32 = 1000;
const MAX_AUTHORITIES: AuthorityCount = 10;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand Down
6 changes: 3 additions & 3 deletions state-chain/cf-integration-tests/src/witnessing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use pallet_cf_witnesser::{CallHash, CallHashExecuted, WitnessDeadline};

#[test]
fn can_punish_failed_witnesser() {
const EPOCH_DURATION_BLOCKS: u32 = 1000;
const EPOCH_BLOCKS: u32 = 1000;
const MAX_AUTHORITIES: AuthorityCount = 50;
super::genesis::with_test_defaults()
.epoch_duration(EPOCH_DURATION_BLOCKS)
.blocks_per_epoch(EPOCH_BLOCKS)
.max_authorities(MAX_AUTHORITIES)
.build()
.execute_with(|| {
Expand All @@ -46,7 +46,7 @@ fn can_punish_failed_witnesser() {
assert_ok!(Reputation::set_penalty(
pallet_cf_governance::RawOrigin::GovernanceApproval.into(),
Offence::FailedToWitnessInTime,
Penalty { reputation: -100, suspension: EPOCH_DURATION_BLOCKS },
Penalty { reputation: -100, suspension: EPOCH_BLOCKS },
));

// Before the deadline is set, no one has been reported.
Expand Down
Loading

0 comments on commit b724f08

Please sign in to comment.