Skip to content

Commit

Permalink
testing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
pls148 committed Feb 28, 2025
1 parent 30ece9f commit b987c63
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 61 deletions.
1 change: 1 addition & 0 deletions hotshot-examples/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ pub trait RunDa<
TestInstanceState::default(),
self.config().config.epoch_height,
self.config().config.epoch_start_block,
vec![],
)
.await
.expect("Couldn't generate genesis block");
Expand Down
1 change: 1 addition & 0 deletions hotshot-orchestrator/run-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fixed_leader_for_gpuvid = 1
next_view_timeout = 30000
num_bootstrap = 5
epoch_height = 0
epoch_start_block = 0

[random_builder]
txn_in_block = 100
Expand Down
1 change: 1 addition & 0 deletions hotshot-query-service/examples/simple-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ async fn init_consensus(
TestInstanceState::default(),
0,
0,
vec![],
)
.await
.unwrap(),
Expand Down
1 change: 1 addition & 0 deletions hotshot-query-service/src/testing/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ impl<D: DataSourceLifeCycle + UpdateStatusData> MockNetwork<D> {
TestInstanceState::default(),
0,
0,
vec![],
)
.await
.unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion hotshot-task-impls/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl<TYPES: NodeType + Default> Default for LeafChainTraversalOutcome<TYPES> {
/// # Panics
/// If the leaf chain contains no decided leaf while reaching a decided view, which should be
/// impossible.
pub async fn decide_from_proposal_2<TYPES: NodeType, V: Versions>(
pub async fn decide_from_proposal_2<TYPES: NodeType>(
proposal: &QuorumProposalWrapper<TYPES>,
consensus: OuterConsensus<TYPES>,
existing_upgrade_cert: Arc<RwLock<Option<UpgradeCertificate<TYPES>>>>,
Expand Down
2 changes: 1 addition & 1 deletion hotshot-task-impls/src/quorum_vote/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ pub(crate) async fn handle_quorum_proposal_validated<
included_txns,
decided_upgrade_cert,
} = if version >= V::Epochs::VERSION {
decide_from_proposal_2::<TYPES, V>(
decide_from_proposal_2(
proposal,
OuterConsensus::new(Arc::clone(&task_state.consensus.inner_consensus)),
Arc::clone(&task_state.upgrade_lock.decided_upgrade_certificate),
Expand Down
19 changes: 16 additions & 3 deletions hotshot-testing/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
// along with the HotShot repository. If not, see <https://mit-license.org/>.

#![allow(clippy::panic)]
use std::{collections::BTreeMap, fmt::Debug, hash::Hash, marker::PhantomData, sync::Arc};

use async_broadcast::{Receiver, Sender};
use async_lock::RwLock;
use bitvec::bitvec;
use committable::Committable;
use hotshot::{
traits::{BlockPayload, NodeImplementation, TestableNodeImplementation},
types::{SignatureKey, SystemContextHandle},
HotShotInitializer, SystemContext,
HotShotInitializer, InitializerEpochInfo, SystemContext,
};
use hotshot_example_types::{
auction_results_provider_types::TestAuctionResultsProvider,
Expand All @@ -24,9 +22,11 @@ use hotshot_example_types::{
storage_types::TestStorage,
};
use hotshot_task_impls::events::HotShotEvent;
use hotshot_types::traits::node_implementation::ConsensusTime;
use hotshot_types::{
consensus::ConsensusMetricsValue,
data::{vid_commitment, Leaf2, VidCommitment, VidDisperse, VidDisperseShare},
drb::INITIAL_DRB_RESULT,
message::{Proposal, UpgradeLock},
simple_certificate::DaCertificate2,
simple_vote::{DaData2, DaVote2, SimpleVote, VersionedVoteData},
Expand All @@ -41,6 +41,7 @@ use hotshot_types::{
};
use primitive_types::U256;
use serde::Serialize;
use std::{collections::BTreeMap, fmt::Debug, hash::Hash, marker::PhantomData, sync::Arc};
use vbs::version::Version;

use crate::{test_builder::TestDescription, test_launcher::TestLauncher};
Expand Down Expand Up @@ -106,6 +107,18 @@ pub async fn build_system_handle_from_launcher<
TestInstanceState::new(launcher.metadata.async_delay_config.clone()),
launcher.metadata.test_config.epoch_height,
launcher.metadata.test_config.epoch_start_block,
vec![
InitializerEpochInfo::<TYPES> {
epoch: TYPES::Epoch::new(1),
drb_result: INITIAL_DRB_RESULT,
block_header: None,
},
InitializerEpochInfo::<TYPES> {
epoch: TYPES::Epoch::new(2),
drb_result: INITIAL_DRB_RESULT,
block_header: None,
},
],
)
.await
.unwrap();
Expand Down
12 changes: 9 additions & 3 deletions hotshot-testing/src/test_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@
// You should have received a copy of the MIT License
// along with the HotShot repository. If not, see <https://mit-license.org/>.

use std::{collections::HashMap, num::NonZeroUsize, rc::Rc, sync::Arc, time::Duration};

use async_lock::RwLock;
use hotshot::{
tasks::EventTransformerState,
traits::{NetworkReliability, NodeImplementation, TestableNodeImplementation},
types::SystemContextHandle,
HotShotInitializer, MarketplaceConfig, SystemContext, TwinsHandlerState,
HotShotInitializer, InitializerEpochInfo, MarketplaceConfig, SystemContext, TwinsHandlerState,
};
use hotshot_example_types::{
auction_results_provider_types::TestAuctionResultsProvider, node_types::TestTypes,
state_types::TestInstanceState, storage_types::TestStorage, testable_delay::DelayConfig,
};
use hotshot_types::traits::node_implementation::ConsensusTime;
use hotshot_types::{
consensus::ConsensusMetricsValue,
drb::INITIAL_DRB_RESULT,
traits::node_implementation::{NodeType, Versions},
HotShotConfig, PeerConfig, ValidatorConfig,
};
use hotshot_utils::anytrace::*;
use std::{collections::HashMap, num::NonZeroUsize, rc::Rc, sync::Arc, time::Duration};
use tide_disco::Url;
use vec1::Vec1;

Expand Down Expand Up @@ -241,6 +242,11 @@ pub async fn create_test_handle<
TestInstanceState::new(metadata.async_delay_config),
metadata.test_config.epoch_height,
metadata.test_config.epoch_start_block,
vec![InitializerEpochInfo::<TYPES> {
epoch: TYPES::Epoch::new(1),
drb_result: INITIAL_DRB_RESULT,
block_header: None,
}],
)
.await
.unwrap();
Expand Down
42 changes: 14 additions & 28 deletions hotshot-testing/src/test_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@
// along with the HotShot repository. If not, see <https://mit-license.org/>.

#![allow(clippy::panic)]
use std::{
collections::{BTreeMap, HashMap, HashSet},
marker::PhantomData,
sync::Arc,
};

use async_broadcast::{broadcast, Receiver, Sender};
use async_lock::RwLock;
use futures::future::join_all;
use hotshot::InitializerEpochInfo;
use hotshot::{
traits::TestableNodeImplementation,
types::{Event, SystemContextHandle},
Expand All @@ -38,14 +33,17 @@ use hotshot_types::{
network::ConnectedNetwork,
node_implementation::{ConsensusTime, NodeImplementation, NodeType, Versions},
},
utils::genesis_epoch_from_version,
HotShotConfig, ValidatorConfig,
};
use std::{
collections::{BTreeMap, HashMap, HashSet},
marker::PhantomData,
sync::Arc,
};
use tide_disco::Url;
use tokio::{spawn, task::JoinHandle};
#[allow(deprecated)]
use tracing::info;
use vbs::version::StaticVersionType;

use super::{
completion_task::CompletionTask, consistency_task::ConsistencyTask, txn_task::TxnTask,
Expand Down Expand Up @@ -397,22 +395,10 @@ where
let mut results = vec![];
let config = self.launcher.metadata.test_config.clone();

// TODO This is only a workaround. Number of nodes changes from epoch to epoch. Builder should be made epoch-aware.
let mut temp_memberships = <TYPES as NodeType>::Membership::new(
config.known_nodes_with_stake.clone(),
config.known_da_nodes.clone(),
);

// if we're doing epochs, then tell the membership
if V::Base::VERSION >= V::Epochs::VERSION {
temp_memberships
.set_first_epoch(<TYPES as NodeType>::Epoch::new(1), INITIAL_DRB_RESULT);
}

// #3967 is it enough to check versions now? Or should we also be checking epoch_height?
let num_nodes = temp_memberships.total_nodes(genesis_epoch_from_version::<V, TYPES>());
// Num_nodes is updated on the fly now via claim_block_with_num_nodes. This stays around to seed num_nodes
// in the builders for tests which don't update that field.
let (mut builder_tasks, builder_urls, fallback_builder_url) =
self.init_builders::<B>(num_nodes).await;
self.init_builders::<B>(0).await;

if self.launcher.metadata.start_solver {
self.add_solver(builder_urls.clone()).await;
Expand All @@ -431,11 +417,6 @@ where
self.next_node_id += 1;
tracing::debug!("launch node {}", i);

//let memberships =Arc::new(RwLock::new(<TYPES as NodeType>::Membership::new(
//config.known_nodes_with_stake.clone(),
//config.known_da_nodes.clone(),
//)));

config.builder_urls = builder_urls
.clone()
.try_into()
Expand Down Expand Up @@ -487,6 +468,11 @@ where
TestInstanceState::new(self.launcher.metadata.async_delay_config.clone()),
config.epoch_height,
config.epoch_start_block,
vec![InitializerEpochInfo::<TYPES> {
epoch: TYPES::Epoch::new(1),
drb_result: INITIAL_DRB_RESULT,
block_header: None,
}],
)
.await
.unwrap();
Expand Down
31 changes: 10 additions & 21 deletions hotshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,24 +248,14 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> SystemContext<T
membership: &Arc<RwLock<TYPES::Membership>>,
start_epoch_info: &Vec<InitializerEpochInfo<TYPES>>,
) {
/* if let Some(epoch) = epoch {
// #2652 REVIEW NOTE: This epoch can't be right; what if a node starts up between when we upgrade to epochs
// and when we're at epoch+2? This would cause the current node to propagate the non-epochs stake table
// up.
memberships
.write()
.await
.set_first_epoch(epoch, INITIAL_DRB_RESULT);
}*/

// Iterate through start_epoch_info, find the first block header
for epoch_info in start_epoch_info {
if epoch_info.block_header.is_some() {
// If the first element in start_epoch_info does not have a block header,
// use that to set_first_epoch instead
if let Some(epoch_info) = start_epoch_info.first() {
if epoch_info.block_header.is_none() {
membership
.write()
.await
.set_first_epoch(epoch_info.epoch, INITIAL_DRB_RESULT);
break;
}
}

Expand Down Expand Up @@ -360,8 +350,6 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> SystemContext<T

Self::load_start_epoch_info(&membership, &initializer.start_epoch_info).await;

// Populate

// Insert the validated state to state map.
let mut validated_state_map = BTreeMap::default();
validated_state_map.insert(
Expand Down Expand Up @@ -1050,10 +1038,10 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> ConsensusApi<TY

#[derive(Clone)]
pub struct InitializerEpochInfo<TYPES: NodeType> {
epoch: TYPES::Epoch,
drb_result: DrbResult,
// stake_table: Option<StakeTable>, // TODO: Figure out how to connect this up
block_header: Option<TYPES::BlockHeader>,
pub epoch: TYPES::Epoch,
pub drb_result: DrbResult,
// pub stake_table: Option<StakeTable>, // TODO: Figure out how to connect this up
pub block_header: Option<TYPES::BlockHeader>,
}

#[derive(Clone)]
Expand Down Expand Up @@ -1123,6 +1111,7 @@ impl<TYPES: NodeType> HotShotInitializer<TYPES> {
instance_state: TYPES::InstanceState,
epoch_height: u64,
epoch_start_block: u64,
start_epoch_info: Vec<InitializerEpochInfo<TYPES>>,
) -> Result<Self, HotShotError<TYPES>> {
let (validated_state, state_delta) = TYPES::ValidatedState::genesis(&instance_state);
let high_qc = QuorumCertificate2::genesis::<V>(&validated_state, &instance_state).await;
Expand All @@ -1144,7 +1133,7 @@ impl<TYPES: NodeType> HotShotInitializer<TYPES> {
saved_vid_shares: BTreeMap::new(),
epoch_height,
epoch_start_block,
start_epoch_info: Vec::new(),
start_epoch_info,
})
}

Expand Down
6 changes: 2 additions & 4 deletions hotshot/src/traits/election/static_committee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,16 @@ impl<TYPES: NodeType> Membership<TYPES> for StaticCommittee<TYPES> {
/// Get the stake table for the current view
fn stake_table(
&self,
epoch: Option<<TYPES as NodeType>::Epoch>,
_epoch: Option<<TYPES as NodeType>::Epoch>,
) -> Vec<<<TYPES as NodeType>::SignatureKey as SignatureKey>::StakeTableEntry> {
self.check_first_epoch(epoch);
self.stake_table.clone()
}

/// Get the stake table for the current view
fn da_stake_table(
&self,
epoch: Option<<TYPES as NodeType>::Epoch>,
_epoch: Option<<TYPES as NodeType>::Epoch>,
) -> Vec<<<TYPES as NodeType>::SignatureKey as SignatureKey>::StakeTableEntry> {
self.check_first_epoch(epoch);
self.da_stake_table.clone()
}

Expand Down

0 comments on commit b987c63

Please sign in to comment.