Skip to content

Commit

Permalink
testing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
pls148 committed Feb 27, 2025
1 parent 415416e commit 8e85bb6
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 27 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
24 changes: 15 additions & 9 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,8 +33,14 @@ use hotshot_types::{
network::ConnectedNetwork,
node_implementation::{ConsensusTime, NodeImplementation, NodeType, Versions},
},
utils::genesis_epoch_from_version,
HotShotConfig, ValidatorConfig,
//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};
Expand Down Expand Up @@ -410,7 +411,7 @@ where
}

// #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>());
let num_nodes = 0; // temp_memberships.total_nodes(genesis_epoch_from_version::<V, TYPES>());
let (mut builder_tasks, builder_urls, fallback_builder_url) =
self.init_builders::<B>(num_nodes).await;

Expand Down Expand Up @@ -487,6 +488,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
13 changes: 7 additions & 6 deletions hotshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> SystemContext<T

// 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 epoch_info.block_header.is_none() {
membership
.write()
.await
Expand Down Expand Up @@ -1050,10 +1050,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 +1123,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 +1145,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 8e85bb6

Please sign in to comment.