diff --git a/crates/example-types/src/node_types.rs b/crates/example-types/src/node_types.rs index c7899aa3de..166976c3a0 100644 --- a/crates/example-types/src/node_types.rs +++ b/crates/example-types/src/node_types.rs @@ -52,8 +52,6 @@ use crate::{ /// to select our traits pub struct TestTypes; impl NodeType for TestTypes { - const EPOCH_HEIGHT: u64 = 10; - type AuctionResult = TestAuctionResult; type View = ViewNumber; type Epoch = EpochNumber; @@ -84,8 +82,6 @@ impl NodeType for TestTypes { /// to select our traits pub struct TestTypesRandomizedLeader; impl NodeType for TestTypesRandomizedLeader { - const EPOCH_HEIGHT: u64 = 10; - type AuctionResult = TestAuctionResult; type View = ViewNumber; type Epoch = EpochNumber; @@ -119,8 +115,6 @@ pub struct TestTypesRandomizedCommitteeMembers { } impl NodeType for TestTypesRandomizedCommitteeMembers { - const EPOCH_HEIGHT: u64 = 10; - type AuctionResult = TestAuctionResult; type View = ViewNumber; type Epoch = EpochNumber; @@ -152,8 +146,6 @@ impl NodeType for TestTypesRandomizedCommitteeMember /// to select our traits pub struct TestConsecutiveLeaderTypes; impl NodeType for TestConsecutiveLeaderTypes { - const EPOCH_HEIGHT: u64 = 10; - type AuctionResult = TestAuctionResult; type View = ViewNumber; type Epoch = EpochNumber; @@ -184,8 +176,6 @@ impl NodeType for TestConsecutiveLeaderTypes { /// to select our traits pub struct TestTwoStakeTablesTypes; impl NodeType for TestTwoStakeTablesTypes { - const EPOCH_HEIGHT: u64 = 10; - type AuctionResult = TestAuctionResult; type View = ViewNumber; type Epoch = EpochNumber; diff --git a/crates/hotshot/src/tasks/task_state.rs b/crates/hotshot/src/tasks/task_state.rs index c854624bc3..9023722a66 100644 --- a/crates/hotshot/src/tasks/task_state.rs +++ b/crates/hotshot/src/tasks/task_state.rs @@ -57,6 +57,7 @@ impl, V: Versions> CreateTaskState id: handle.hotshot.id, shutdown_flag: Arc::new(AtomicBool::new(false)), spawned_tasks: BTreeMap::new(), + epoch_height: handle.epoch_height, } } } diff --git a/crates/task-impls/src/helpers.rs b/crates/task-impls/src/helpers.rs index b480841197..251cb049f0 100644 --- a/crates/task-impls/src/helpers.rs +++ b/crates/task-impls/src/helpers.rs @@ -159,7 +159,7 @@ pub(crate) async fn fetch_proposal( leaf: leaf.commit(), state, delta: None, - epoch: leaf.epoch(), + epoch: leaf.epoch(epoch_height), }, }; Ok((leaf, view)) @@ -814,7 +814,7 @@ pub(crate) async fn validate_proposal_view_and_certs< { let epoch = TYPES::Epoch::new(epoch_from_block_number( proposal.data.block_header.block_number(), - TYPES::EPOCH_HEIGHT, + validation_info.epoch_height, )); UpgradeCertificate::validate( &proposal.data.upgrade_certificate, diff --git a/crates/task-impls/src/quorum_vote/handlers.rs b/crates/task-impls/src/quorum_vote/handlers.rs index bf9c5dec5c..cbc65bd672 100644 --- a/crates/task-impls/src/quorum_vote/handlers.rs +++ b/crates/task-impls/src/quorum_vote/handlers.rs @@ -203,7 +203,7 @@ async fn start_drb_task, V: Versio ) { let current_epoch_number = TYPES::Epoch::new(epoch_from_block_number( proposal.block_header.block_number(), - TYPES::EPOCH_HEIGHT, + task_state.epoch_height, )); // Start the new task if we're in the committee for this epoch @@ -615,17 +615,18 @@ pub(crate) async fn submit_vote, V leaf: Leaf2, vid_share: Proposal>, extended_vote: bool, + epoch_height: u64, ) -> Result<()> { let epoch_number = TYPES::Epoch::new(epoch_from_block_number( leaf.block_header().block_number(), - TYPES::EPOCH_HEIGHT, + epoch_height, )); let membership_reader = membership.read().await; let committee_member_in_current_epoch = membership_reader.has_stake(&public_key, epoch_number); // If the proposed leaf is for the last block in the epoch and the node is part of the quorum committee // in the next epoch, the node should vote to achieve the double quorum. - let committee_member_in_next_epoch = is_last_block_in_epoch(leaf.height(), TYPES::EPOCH_HEIGHT) + let committee_member_in_next_epoch = is_last_block_in_epoch(leaf.height(), epoch_height) && membership_reader.has_stake(&public_key, epoch_number + 1); drop(membership_reader); diff --git a/crates/task-impls/src/quorum_vote/mod.rs b/crates/task-impls/src/quorum_vote/mod.rs index 29ebc612d2..8ee1223cf9 100644 --- a/crates/task-impls/src/quorum_vote/mod.rs +++ b/crates/task-impls/src/quorum_vote/mod.rs @@ -257,6 +257,7 @@ impl + 'static, V: Versions> Handl leaf, vid_share, false, + self.epoch_height, ) .await { @@ -767,6 +768,7 @@ impl, V: Versions> QuorumVoteTaskS proposed_leaf, updated_vid, is_vote_leaf_extended, + self.epoch_height, ) .await { diff --git a/crates/task-impls/src/request.rs b/crates/task-impls/src/request.rs index b487497408..3e1d75dff2 100644 --- a/crates/task-impls/src/request.rs +++ b/crates/task-impls/src/request.rs @@ -83,6 +83,9 @@ pub struct NetworkRequestState> { /// A flag indicating that `HotShotEvent::Shutdown` has been received pub spawned_tasks: BTreeMap>>, + + /// Number of blocks in an epoch, zero means there are no epochs + pub epoch_height: u64, } impl> Drop for NetworkRequestState { @@ -111,7 +114,7 @@ impl> TaskState for NetworkRequest let prop_view = proposal.data.view_number(); let prop_epoch = TYPES::Epoch::new(epoch_from_block_number( proposal.data.block_header.block_number(), - TYPES::EPOCH_HEIGHT, + self.epoch_height, )); // If we already have the VID shares for the next view, do nothing. diff --git a/crates/testing/src/helpers.rs b/crates/testing/src/helpers.rs index 6d945894f3..d0a5631fc5 100644 --- a/crates/testing/src/helpers.rs +++ b/crates/testing/src/helpers.rs @@ -26,13 +26,12 @@ use hotshot_example_types::{ use hotshot_task_impls::events::HotShotEvent; use hotshot_types::{ consensus::ConsensusMetricsValue, - data::{Leaf2, QuorumProposal2, VidDisperse, VidDisperseShare2}, - message::{GeneralConsensusMessage, Proposal, UpgradeLock}, + data::{Leaf2, VidDisperse, VidDisperseShare2}, + message::{Proposal, UpgradeLock}, simple_certificate::DaCertificate2, - simple_vote::{DaData2, DaVote2, QuorumData2, QuorumVote2, SimpleVote, VersionedVoteData}, + simple_vote::{DaData2, DaVote2, SimpleVote, VersionedVoteData}, traits::{ block_contents::vid_commitment, - consensus_api::ConsensusApi, election::Membership, node_implementation::{ConsensusTime, NodeType, Versions}, }, @@ -47,7 +46,7 @@ use serde::Serialize; use crate::{test_builder::TestDescription, test_launcher::TestLauncher}; -/// create the [`SystemContextHandle`] from a node id +/// create the [`SystemContextHandle`] from a node id, with no epochs /// # Panics /// if cannot create a [`HotShotInitializer`] pub async fn build_system_handle< @@ -65,7 +64,8 @@ pub async fn build_system_handle< Sender>>, Receiver>>, ) { - let builder: TestDescription = TestDescription::default_multiple_rounds(); + let mut builder: TestDescription = TestDescription::default_multiple_rounds(); + builder.epoch_height = 0; let launcher = builder.gen_launcher(node_id); build_system_handle_from_launcher(node_id, &launcher).await @@ -397,28 +397,6 @@ pub async fn build_da_certificate( .await } -pub async fn build_vote, V: Versions>( - handle: &SystemContextHandle, - proposal: QuorumProposal2, -) -> GeneralConsensusMessage { - let view = proposal.view_number; - - let leaf: Leaf2<_> = Leaf2::from_quorum_proposal(&proposal); - let vote = QuorumVote2::::create_signed_vote( - QuorumData2 { - leaf_commit: leaf.commit(), - epoch: leaf.epoch(), - }, - view, - &handle.public_key(), - handle.private_key(), - &handle.hotshot.upgrade_lock, - ) - .await - .expect("Failed to create quorum vote"); - GeneralConsensusMessage::::Vote(vote.to_vote()) -} - /// This function permutes the provided input vector `inputs`, given some order provided within the /// `order` vector. /// diff --git a/crates/testing/src/overall_safety_task.rs b/crates/testing/src/overall_safety_task.rs index edabe71f90..600e4a87a8 100644 --- a/crates/testing/src/overall_safety_task.rs +++ b/crates/testing/src/overall_safety_task.rs @@ -95,6 +95,8 @@ pub struct OverallSafetyTask>>, /// sender to test event channel pub test_sender: Sender, + /// Number of blocks in an epoch, zero means there are no epochs + pub epoch_height: u64, } impl, V: Versions> @@ -186,8 +188,8 @@ impl, V: Versions> TestTas }; if let Some(ref key) = key { - if *key.epoch() > self.ctx.latest_epoch { - self.ctx.latest_epoch = *key.epoch(); + if *key.epoch(self.epoch_height) > self.ctx.latest_epoch { + self.ctx.latest_epoch = *key.epoch(self.epoch_height); } } diff --git a/crates/testing/src/test_builder.rs b/crates/testing/src/test_builder.rs index c91d45a4d3..266dc39b7e 100644 --- a/crates/testing/src/test_builder.rs +++ b/crates/testing/src/test_builder.rs @@ -4,9 +4,7 @@ // You should have received a copy of the MIT License // along with the HotShot repository. If not, see . -use std::{ - any::TypeId, collections::HashMap, num::NonZeroUsize, rc::Rc, sync::Arc, time::Duration, -}; +use std::{collections::HashMap, num::NonZeroUsize, rc::Rc, sync::Arc, time::Duration}; use anyhow::{ensure, Result}; use async_lock::RwLock; @@ -17,8 +15,8 @@ use hotshot::{ HotShotInitializer, MarketplaceConfig, SystemContext, TwinsHandlerState, }; use hotshot_example_types::{ - auction_results_provider_types::TestAuctionResultsProvider, node_types::EpochsTestVersions, - state_types::TestInstanceState, storage_types::TestStorage, testable_delay::DelayConfig, + auction_results_provider_types::TestAuctionResultsProvider, state_types::TestInstanceState, + storage_types::TestStorage, testable_delay::DelayConfig, }; use hotshot_types::{ consensus::ConsensusMetricsValue, @@ -101,6 +99,8 @@ pub struct TestDescription, V: Ver pub start_solver: bool, /// boxed closure used to validate the resulting transactions pub validate_transactions: TransactionValidator, + /// Number of blocks in an epoch, zero means there are no epochs + pub epoch_height: u64, } pub fn nonempty_block_threshold(threshold: (u64, u64)) -> TransactionValidator { @@ -387,6 +387,7 @@ impl, V: Versions> Default fn default() -> Self { let num_nodes_with_stake = 7; Self { + epoch_height: 10, timing_data: TimingData::default(), num_nodes_with_stake, start_nodes: num_nodes_with_stake, @@ -487,12 +488,6 @@ where // This is the config for node 0 0 < da_staked_committee_size, ); - // let da_committee_nodes = known_nodes[0..da_committee_size].to_vec(); - let epoch_height = if TypeId::of::() == TypeId::of::() { - 10 - } else { - 0 - }; let config = HotShotConfig { start_threshold: (1, 1), num_nodes_with_stake: NonZeroUsize::new(num_nodes_with_stake).unwrap(), @@ -516,7 +511,7 @@ where stop_proposing_time: 0, start_voting_time: u64::MAX, stop_voting_time: 0, - epoch_height, + epoch_height: self.epoch_height, }; let TimingData { next_view_timeout, diff --git a/crates/testing/src/test_runner.rs b/crates/testing/src/test_runner.rs index 7d0c1cc6bb..600be48823 100644 --- a/crates/testing/src/test_runner.rs +++ b/crates/testing/src/test_runner.rs @@ -202,6 +202,7 @@ where // add safety task let overall_safety_task_state = OverallSafetyTask { handles: Arc::clone(&handles), + epoch_height: launcher.metadata.epoch_height, ctx: RoundCtx::default(), properties: launcher.metadata.overall_safety_properties.clone(), error: None, diff --git a/crates/testing/tests/tests_1/libp2p.rs b/crates/testing/tests/tests_1/libp2p.rs index c9f7ae33db..3a267651bc 100644 --- a/crates/testing/tests/tests_1/libp2p.rs +++ b/crates/testing/tests/tests_1/libp2p.rs @@ -37,6 +37,7 @@ async fn libp2p_network() { next_view_timeout: 4000, ..Default::default() }, + epoch_height: 0, ..TestDescription::default_multiple_rounds() }; @@ -68,6 +69,7 @@ async fn libp2p_network_failures_2() { next_view_timeout: 4000, ..Default::default() }, + epoch_height: 0, ..TestDescription::default_multiple_rounds() }; diff --git a/crates/testing/tests/tests_1/test_success.rs b/crates/testing/tests/tests_1/test_success.rs index 987a07224a..e3b7441fa7 100644 --- a/crates/testing/tests/tests_1/test_success.rs +++ b/crates/testing/tests/tests_1/test_success.rs @@ -37,6 +37,7 @@ cross_tests!( duration: Duration::from_secs(60), }, ), + epoch_height: 0, ..TestDescription::default() } }, @@ -56,6 +57,7 @@ cross_tests!( duration: Duration::from_secs(60), }, ), + epoch_height: 10, ..TestDescription::default() } }, @@ -75,6 +77,7 @@ cross_tests!( // duration: Duration::from_secs(60), // }, // ), +// epoch_height: 10, // ..TestDescription::default() // } // }, @@ -94,6 +97,7 @@ cross_tests!( duration: Duration::from_secs(60), }, ), + epoch_height: 0, ..TestDescription::default() }; @@ -126,6 +130,7 @@ cross_tests!( duration: Duration::from_secs(60), }, ), + epoch_height: 10, ..TestDescription::default() }; @@ -158,6 +163,7 @@ cross_tests!( duration: Duration::from_secs(60), }, ), + epoch_height: 0, ..TestDescription::default() }; @@ -198,6 +204,7 @@ cross_tests!( duration: Duration::from_secs(60), }, ), + epoch_height: 10, ..TestDescription::default() }; @@ -232,6 +239,7 @@ cross_tests!( Ignore: false, Metadata: { let mut metadata = TestDescription::default_more_nodes(); + metadata.epoch_height = 0; metadata.num_bootstrap_nodes = 10; metadata.num_nodes_with_stake = 12; metadata.da_staked_committee_size = 12; @@ -254,6 +262,7 @@ cross_tests!( Metadata: { let mut metadata = TestDescription::default_more_nodes(); metadata.num_bootstrap_nodes = 10; + metadata.epoch_height = 10; metadata.num_nodes_with_stake = 12; metadata.da_staked_committee_size = 12; metadata.start_nodes = 12; @@ -283,6 +292,7 @@ cross_tests!( start_nodes: 11, num_bootstrap_nodes: 11, da_staked_committee_size: 11, + epoch_height: 10, ..TestDescription::default() } }, @@ -303,6 +313,7 @@ cross_tests!( duration: Duration::from_millis(100000), }, ), + epoch_height: 10, ..TestDescription::default() }; // after the first 3 leaders the next leader is down. It's a hack to make sure we decide in diff --git a/crates/testing/tests/tests_1/test_with_failures_2.rs b/crates/testing/tests/tests_1/test_with_failures_2.rs index 242b5ea2c0..cf9ac8c83f 100644 --- a/crates/testing/tests/tests_1/test_with_failures_2.rs +++ b/crates/testing/tests/tests_1/test_with_failures_2.rs @@ -42,6 +42,7 @@ cross_tests!( Ignore: false, Metadata: { let mut metadata = TestDescription::default_more_nodes(); + metadata.epoch_height = 0; metadata.num_bootstrap_nodes = 10; metadata.num_nodes_with_stake = 12; metadata.da_staked_committee_size = 12; @@ -84,6 +85,7 @@ cross_tests!( metadata.num_nodes_with_stake = 12; metadata.da_staked_committee_size = 12; metadata.start_nodes = 12; + metadata.epoch_height = 10; let dead_nodes = vec![ ChangeNode { idx: 10, @@ -124,6 +126,7 @@ cross_tests!( Ignore: false, Metadata: { let mut metadata = TestDescription::default_more_nodes(); + metadata.epoch_height = 0; metadata.num_bootstrap_nodes = 10; metadata.num_nodes_with_stake = 12; metadata.da_staked_committee_size = 12; diff --git a/crates/testing/tests/tests_2/catchup.rs b/crates/testing/tests/tests_2/catchup.rs index bf48a2558c..f012c22f2a 100644 --- a/crates/testing/tests/tests_2/catchup.rs +++ b/crates/testing/tests/tests_2/catchup.rs @@ -45,6 +45,7 @@ async fn test_catchup() { updown: NodeAction::Up, }]; + metadata.epoch_height = 0; metadata.timing_data = timing_data; metadata.start_nodes = 19; metadata.num_nodes_with_stake = 20; @@ -103,6 +104,7 @@ async fn test_catchup_cdn() { idx: 18, updown: NodeAction::Up, }]; + metadata.epoch_height = 0; metadata.timing_data = timing_data; metadata.start_nodes = 19; metadata.num_nodes_with_stake = 20; @@ -156,6 +158,7 @@ async fn test_catchup_one_node() { idx: 18, updown: NodeAction::Up, }]; + metadata.epoch_height = 0; metadata.timing_data = timing_data; metadata.start_nodes = 19; metadata.num_nodes_with_stake = 20; @@ -218,6 +221,7 @@ async fn test_catchup_in_view_sync() { }, ]; + metadata.epoch_height = 0; metadata.timing_data = timing_data; metadata.start_nodes = 18; metadata.num_nodes_with_stake = 20; @@ -275,6 +279,7 @@ async fn test_catchup_reload() { updown: NodeAction::Up, }]; + metadata.epoch_height = 0; metadata.timing_data = timing_data; metadata.start_nodes = 19; metadata.skip_late = true; @@ -329,6 +334,7 @@ cross_tests!( } metadata.timing_data = timing_data; + metadata.epoch_height = 0; metadata.start_nodes = 20; metadata.num_nodes_with_stake = 20; @@ -385,6 +391,7 @@ cross_tests!( metadata.timing_data = timing_data; metadata.start_nodes = 20; metadata.num_nodes_with_stake = 20; + metadata.epoch_height = 0; // Explicitly make the DA tiny to exaggerate a missing proposal. metadata.da_staked_committee_size = 1; @@ -446,6 +453,7 @@ cross_tests!( metadata.start_nodes = 10; metadata.num_nodes_with_stake = 10; + metadata.epoch_height = 0; // Explicitly make the DA small to simulate real network. metadata.da_staked_committee_size = 4; diff --git a/crates/testing/tests/tests_3/byzantine_tests.rs b/crates/testing/tests/tests_3/byzantine_tests.rs index 0ab5f68d19..2a08d2c871 100644 --- a/crates/testing/tests/tests_3/byzantine_tests.rs +++ b/crates/testing/tests/tests_3/byzantine_tests.rs @@ -51,6 +51,7 @@ cross_tests!( }, ), behaviour, + epoch_height: 0, ..TestDescription::default() } }, @@ -78,6 +79,7 @@ cross_tests!( ), behaviour, num_nodes_with_stake: 12, + epoch_height: 0, ..TestDescription::default() }; @@ -115,6 +117,7 @@ cross_tests!( }, ), behaviour, + epoch_height: 0, ..TestDescription::default() }; @@ -155,6 +158,7 @@ cross_tests!( }, ), behaviour, + epoch_height: 0, ..TestDescription::default() }; @@ -196,6 +200,7 @@ cross_tests!( }, ), behaviour, + epoch_height: 0, ..TestDescription::default() }; @@ -237,6 +242,7 @@ cross_tests!( duration: Duration::from_secs(60), }, ), + epoch_height: 0, behaviour, ..TestDescription::default() }; diff --git a/crates/testing/tests/tests_3/memory_network.rs b/crates/testing/tests/tests_3/memory_network.rs index b99961af3e..875e5b40e9 100644 --- a/crates/testing/tests/tests_3/memory_network.rs +++ b/crates/testing/tests/tests_3/memory_network.rs @@ -52,8 +52,6 @@ use tracing::{instrument, trace}; pub struct Test; impl NodeType for Test { - const EPOCH_HEIGHT: u64 = 10; - type AuctionResult = TestAuctionResult; type View = ViewNumber; type Epoch = EpochNumber; diff --git a/crates/testing/tests/tests_3/test_with_failures_half_f.rs b/crates/testing/tests/tests_3/test_with_failures_half_f.rs index a8a2dbb14b..3dd8e3ceb7 100644 --- a/crates/testing/tests/tests_3/test_with_failures_half_f.rs +++ b/crates/testing/tests/tests_3/test_with_failures_half_f.rs @@ -23,6 +23,7 @@ cross_tests!( Ignore: false, Metadata: { let mut metadata = TestDescription::default_more_nodes(); + metadata.epoch_height = 0; metadata.num_bootstrap_nodes = 17; // The first 14 (i.e., 20 - f) nodes are in the DA committee and we may shutdown the // remaining 6 (i.e., f) nodes. We could remove this restriction after fixing the @@ -60,7 +61,9 @@ cross_tests!( Ignore: false, Metadata: { let mut metadata = TestDescription::default_more_nodes(); + metadata.epoch_height = 0; metadata.num_bootstrap_nodes = 17; + metadata.epoch_height = 10; // The first 14 (i.e., 20 - f) nodes are in the DA committee and we may shutdown the // remaining 6 (i.e., f) nodes. We could remove this restriction after fixing the // following issue. diff --git a/crates/testing/tests/tests_4/byzantine_tests.rs b/crates/testing/tests/tests_4/byzantine_tests.rs index 7d89d6c870..d9173aebd3 100644 --- a/crates/testing/tests/tests_4/byzantine_tests.rs +++ b/crates/testing/tests/tests_4/byzantine_tests.rs @@ -41,6 +41,7 @@ // }, // ), // behaviour, +// epoch_height: 0, // ..TestDescription::default() // }; diff --git a/crates/testing/tests/tests_4/test_marketplace.rs b/crates/testing/tests/tests_4/test_marketplace.rs index b8a7d8c84c..02bb7fee5e 100644 --- a/crates/testing/tests/tests_4/test_marketplace.rs +++ b/crates/testing/tests/tests_4/test_marketplace.rs @@ -37,6 +37,7 @@ cross_tests!( duration: Duration::from_secs(60), }, ), + epoch_height: 0, fallback_builder: BuilderDescription { changes: HashMap::from([(0, BuilderChange::Down)]) @@ -65,6 +66,7 @@ cross_tests!( duration: Duration::from_secs(60), }, ), + epoch_height: 0, upgrade_view: Some(5), validate_transactions: nonempty_block_threshold((40,50)), ..TestDescription::default() @@ -88,6 +90,7 @@ cross_tests!( duration: Duration::from_secs(60), }, ), + epoch_height: 0, builders: vec1![ BuilderDescription { changes: HashMap::from([(0, BuilderChange::Down)]) @@ -118,6 +121,7 @@ cross_tests!( duration: Duration::from_secs(60), }, ), + epoch_height: 0, builders: vec1![ BuilderDescription { changes: HashMap::from([(0, BuilderChange::Down)]) diff --git a/crates/testing/tests/tests_4/test_with_builder_failures.rs b/crates/testing/tests/tests_4/test_with_builder_failures.rs index 947ece0404..03430c41e4 100644 --- a/crates/testing/tests/tests_4/test_with_builder_failures.rs +++ b/crates/testing/tests/tests_4/test_with_builder_failures.rs @@ -23,12 +23,14 @@ cross_tests!( Ignore: false, Metadata: { let mut metadata = TestDescription::default_multiple_rounds(); + metadata.epoch_height = 0; // Every block should contain at least one transaction - builders are never offline // simultaneously metadata.overall_safety_properties.transaction_threshold = 1; // Generate a lot of transactions so that freshly restarted builders still have // transactions metadata.txn_description = TxnTaskDescription::RoundRobinTimeBased(Duration::from_millis(1)); + metadata.epoch_height = 0; // Two builders running as follows: // view 1st 2nd diff --git a/crates/testing/tests/tests_4/test_with_failures_f.rs b/crates/testing/tests/tests_4/test_with_failures_f.rs index 4fd033d0af..04382e8344 100644 --- a/crates/testing/tests/tests_4/test_with_failures_f.rs +++ b/crates/testing/tests/tests_4/test_with_failures_f.rs @@ -23,6 +23,7 @@ cross_tests!( Ignore: false, Metadata: { let mut metadata = TestDescription::default_more_nodes(); + metadata.epoch_height = 0; metadata.overall_safety_properties.num_failed_views = 6; // Make sure we keep committing rounds after the bad leaders, but not the full 50 because of the numerous timeouts metadata.overall_safety_properties.num_successful_views = 20; diff --git a/crates/testing/tests/tests_5/combined_network.rs b/crates/testing/tests/tests_5/combined_network.rs index 67fb0e4030..e47bf9ad2f 100644 --- a/crates/testing/tests/tests_5/combined_network.rs +++ b/crates/testing/tests/tests_5/combined_network.rs @@ -42,6 +42,7 @@ async fn test_combined_network() { duration: Duration::from_secs(120), }, ), + epoch_height: 0, ..TestDescription::default_multiple_rounds() }; @@ -75,6 +76,7 @@ async fn test_combined_network_cdn_crash() { duration: Duration::from_secs(220), }, ), + epoch_height: 0, ..TestDescription::default_multiple_rounds() }; @@ -122,6 +124,7 @@ async fn test_combined_network_reup() { duration: Duration::from_secs(220), }, ), + epoch_height: 0, ..TestDescription::default_multiple_rounds() }; @@ -173,6 +176,7 @@ async fn test_combined_network_half_dc() { duration: Duration::from_secs(220), }, ), + epoch_height: 0, ..TestDescription::default_multiple_rounds() }; @@ -245,6 +249,7 @@ async fn test_stress_combined_network_fuzzy() { duration: Duration::from_secs(120), }, ), + epoch_height: 0, ..TestDescription::default_stress() }; diff --git a/crates/testing/tests/tests_5/push_cdn.rs b/crates/testing/tests/tests_5/push_cdn.rs index b90a038d99..bac333ebb5 100644 --- a/crates/testing/tests/tests_5/push_cdn.rs +++ b/crates/testing/tests/tests_5/push_cdn.rs @@ -37,6 +37,7 @@ async fn push_cdn_network() { duration: Duration::from_secs(60), }, ), + epoch_height: 0, ..TestDescription::default() }; metadata diff --git a/crates/testing/tests/tests_5/test_with_failures.rs b/crates/testing/tests/tests_5/test_with_failures.rs index 4fc96e5564..349007d152 100644 --- a/crates/testing/tests/tests_5/test_with_failures.rs +++ b/crates/testing/tests/tests_5/test_with_failures.rs @@ -24,6 +24,7 @@ cross_tests!( Ignore: false, Metadata: { let mut metadata = TestDescription::default_more_nodes(); + metadata.epoch_height = 0; metadata.num_bootstrap_nodes = 19; // The first 14 (i.e., 20 - f) nodes are in the DA committee and we may shutdown the // remaining 6 (i.e., f) nodes. We could remove this restriction after fixing the diff --git a/crates/testing/tests/tests_5/timeout.rs b/crates/testing/tests/tests_5/timeout.rs index 4466a4e2f6..54f6e267d2 100644 --- a/crates/testing/tests/tests_5/timeout.rs +++ b/crates/testing/tests/tests_5/timeout.rs @@ -27,6 +27,7 @@ async fn test_timeout() { let mut metadata: TestDescription = TestDescription { num_nodes_with_stake: 10, start_nodes: 10, + epoch_height: 0, ..Default::default() }; let dead_nodes = vec![ChangeNode { diff --git a/crates/testing/tests/tests_5/unreliable_network.rs b/crates/testing/tests/tests_5/unreliable_network.rs index 8bc6e2d885..7d1e5545b8 100644 --- a/crates/testing/tests/tests_5/unreliable_network.rs +++ b/crates/testing/tests/tests_5/unreliable_network.rs @@ -37,6 +37,7 @@ async fn libp2p_network_sync() { delay_high_ms: 30, delay_low_ms: 4, })), + epoch_height: 0, ..TestDescription::default_multiple_rounds() }; @@ -71,6 +72,7 @@ async fn test_memory_network_sync() { delay_high_ms: 30, delay_low_ms: 4, })), + epoch_height: 0, ..TestDescription::default() }; metadata @@ -108,6 +110,7 @@ async fn libp2p_network_async() { delay_low_ms: 4, delay_high_ms: 30, })), + epoch_height: 0, ..TestDescription::default_multiple_rounds() }; @@ -155,6 +158,7 @@ async fn test_memory_network_async() { delay_low_ms: 4, delay_high_ms: 30, })), + epoch_height: 0, ..TestDescription::default() }; metadata @@ -206,6 +210,7 @@ async fn test_memory_network_partially_sync() { gst: std::time::Duration::from_millis(1000), start: Instant::now(), })), + epoch_height: 0, ..TestDescription::default() }; metadata @@ -244,6 +249,7 @@ async fn libp2p_network_partially_sync() { gst: std::time::Duration::from_millis(1000), start: Instant::now(), })), + epoch_height: 0, ..TestDescription::default_multiple_rounds() }; @@ -283,6 +289,7 @@ async fn test_memory_network_chaos() { repeat_low: 1, repeat_high: 5, })), + epoch_height: 0, ..TestDescription::default() }; metadata @@ -316,6 +323,7 @@ async fn libp2p_network_chaos() { repeat_low: 1, repeat_high: 5, })), + epoch_height: 0, ..TestDescription::default_multiple_rounds() }; diff --git a/crates/types/src/data.rs b/crates/types/src/data.rs index 2acafe1268..03738c1407 100644 --- a/crates/types/src/data.rs +++ b/crates/types/src/data.rs @@ -675,7 +675,6 @@ impl From> for Leaf2 { Self { view_number: leaf.view_number, - epoch: TYPES::Epoch::genesis(), justify_qc: leaf.justify_qc.to_qc2(), next_epoch_justify_qc: None, parent_commitment: Commitment::from_raw(bytes), @@ -802,9 +801,6 @@ pub struct Leaf2 { /// CurView from leader when proposing leaf view_number: TYPES::View, - /// An epoch to which the data belongs to. Relevant for validating against the correct stake table - epoch: TYPES::Epoch, - /// Per spec, justification justify_qc: QuorumCertificate2, @@ -879,7 +875,6 @@ impl Leaf2 { upgrade_certificate: None, block_header: block_header.clone(), block_payload: Some(payload), - epoch: TYPES::Epoch::genesis(), view_change_evidence: None, } } @@ -888,8 +883,11 @@ impl Leaf2 { self.view_number } /// Epoch in which this leaf was created. - pub fn epoch(&self) -> TYPES::Epoch { - self.epoch + pub fn epoch(&self, epoch_height: u64) -> TYPES::Epoch { + TYPES::Epoch::new(epoch_from_block_number( + self.block_header.block_number(), + epoch_height, + )) } /// Height of this leaf in the chain. /// @@ -1038,7 +1036,6 @@ impl PartialEq for Leaf2 { fn eq(&self, other: &Self) -> bool { let Leaf2 { view_number, - epoch, justify_qc, next_epoch_justify_qc, parent_commitment, @@ -1049,7 +1046,6 @@ impl PartialEq for Leaf2 { } = self; *view_number == other.view_number - && *epoch == other.epoch && *justify_qc == other.justify_qc && *next_epoch_justify_qc == other.next_epoch_justify_qc && *parent_commitment == other.parent_commitment @@ -1424,10 +1420,6 @@ impl Leaf2 { Self { view_number: *view_number, - epoch: TYPES::Epoch::new(epoch_from_block_number( - quorum_proposal.block_header.block_number(), - TYPES::EPOCH_HEIGHT, - )), justify_qc: justify_qc.clone(), next_epoch_justify_qc: next_epoch_justify_qc.clone(), parent_commitment: justify_qc.data().leaf_commit, diff --git a/crates/types/src/traits/node_implementation.rs b/crates/types/src/traits/node_implementation.rs index f783c95dec..77a4971e24 100644 --- a/crates/types/src/traits/node_implementation.rs +++ b/crates/types/src/traits/node_implementation.rs @@ -212,8 +212,6 @@ pub trait NodeType: type View: ConsensusTime + Display; /// Same as above but for epoch. type Epoch: ConsensusTime + Display; - /// constant for epoch height - const EPOCH_HEIGHT: u64; /// The AuctionSolverResult is a type that holds the data associated with a particular solver /// run, for a particular view. type AuctionResult: Debug