Skip to content

Commit

Permalink
testing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
pls148 committed Mar 1, 2025
1 parent 69bb3a7 commit 244d761
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 125 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
19 changes: 2 additions & 17 deletions hotshot-task-impls/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use hotshot_task::dependency::{Dependency, EventDependency};
use hotshot_types::{
consensus::OuterConsensus,
data::{Leaf2, QuorumProposalWrapper, ViewChangeEvidence2},
drb::INITIAL_DRB_RESULT,
event::{Event, EventType, LeafInfo},
message::{Proposal, UpgradeLock},
request_response::ProposalRequestPayload,
Expand All @@ -39,7 +38,6 @@ use std::{
};
use tokio::time::timeout;
use tracing::instrument;
use vbs::version::StaticVersionType;

use crate::{events::HotShotEvent, quorum_proposal_recv::ValidationInfo, request::REQUEST_TIMEOUT};

Expand Down Expand Up @@ -187,6 +185,7 @@ async fn decide_epoch_root<TYPES: NodeType>(
TYPES::Epoch::new(epoch_from_block_number(decided_block_number, epoch_height) + 1);

let write_callback = {
tracing::debug!("Calling add_epoch_root for epoch {:?}", next_epoch_number);
let membership_reader = membership.read().await;
membership_reader
.add_epoch_root(next_epoch_number, decided_leaf.block_header().clone())
Expand Down Expand Up @@ -257,7 +256,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 Expand Up @@ -502,20 +501,6 @@ pub async fn decide_from_proposal<TYPES: NodeType, V: Versions>(
}
}

if let (Some(decided_upgrade_cert), Some(decided_leaf_info)) =
(&res.decided_upgrade_cert, res.leaf_views.last())
{
if decided_upgrade_cert.data.new_version == V::Epochs::VERSION {
let decided_block_number = decided_leaf_info.leaf.block_header().block_number();
let first_epoch_number =
TYPES::Epoch::new(epoch_from_block_number(decided_block_number, epoch_height));
membership
.write()
.await
.set_first_epoch(first_epoch_number, INITIAL_DRB_RESULT);
}
}

res
}

Expand Down
19 changes: 17 additions & 2 deletions hotshot-task-impls/src/quorum_vote/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use committable::Committable;
use hotshot_types::{
consensus::OuterConsensus,
data::{Leaf2, QuorumProposalWrapper, VidDisperseShare},
drb::{compute_drb_result, DrbResult},
drb::{compute_drb_result, DrbResult, INITIAL_DRB_RESULT},
event::{Event, EventType},
message::{Proposal, UpgradeLock},
simple_vote::{HasEpoch, QuorumData2, QuorumVote2},
Expand Down Expand Up @@ -51,6 +51,7 @@ async fn notify_membership_of_drb_result<TYPES: NodeType>(
epoch: <TYPES as NodeType>::Epoch,
drb_result: DrbResult,
) {
tracing::debug!("Calling add_drb_result for epoch {:?}", epoch);
membership.write().await.add_drb_result(epoch, drb_result);
}

Expand Down Expand Up @@ -369,7 +370,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 Expand Up @@ -406,12 +407,26 @@ pub(crate) async fn handle_quorum_proposal_validated<
.await
.update_decided_upgrade_certificate(Some(cert.clone()))
.await;

task_state.staged_epoch_upgrade_certificate = None;
}
};

if let Some(cert) = decided_upgrade_cert.clone() {
if cert.data.new_version == V::Epochs::VERSION {
task_state.staged_epoch_upgrade_certificate = Some(cert);

let epoch_height = task_state.consensus.read().await.epoch_height;
let first_epoch_number = TYPES::Epoch::new(epoch_from_block_number(
task_state.epoch_upgrade_block_height,
epoch_height,
));
tracing::debug!("Calling set_first_epoch for epoch {:?}", first_epoch_number);
task_state
.membership
.write()
.await
.set_first_epoch(first_epoch_number, INITIAL_DRB_RESULT);
} else {
let mut decided_certificate_lock = task_state
.upgrade_lock
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
45 changes: 15 additions & 30 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 @@ -322,7 +320,6 @@ where

pub async fn init_builders<B: TestBuilderImplementation<TYPES>>(
&self,
num_nodes: usize,
) -> (Vec<Box<dyn BuilderTask<TYPES>>>, Vec<Url>, Url) {
let config = self.launcher.metadata.test_config.clone();
let mut builder_tasks = Vec::new();
Expand All @@ -332,7 +329,7 @@ where
let builder_url =
Url::parse(&format!("http://localhost:{builder_port}")).expect("Invalid URL");
let builder_task = B::start(
num_nodes,
0, // This field gets updated while the test is running, 0 is just to seed it
builder_url.clone(),
B::Config::default(),
metadata.changes.clone(),
Expand Down Expand Up @@ -397,22 +394,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>().await;

if self.launcher.metadata.start_solver {
self.add_solver(builder_urls.clone()).await;
Expand All @@ -431,11 +416,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 +467,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
2 changes: 1 addition & 1 deletion hotshot-testing/tests/tests_6/test_epochs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// You should have received a copy of the MIT License
// along with the HotShot repository. If not, see <https://mit-license.org/>.

use std::time::Duration;
use hotshot_example_types::{
node_types::{
CombinedImpl, EpochUpgradeTestVersions, EpochsTestVersions, Libp2pImpl, MemoryImpl,
Expand All @@ -23,6 +22,7 @@ use hotshot_testing::{
test_builder::{TestDescription, TimingData},
view_sync_task::ViewSyncTaskDescription,
};
use std::time::Duration;

cross_tests!(
TestName: test_success_with_epochs,
Expand Down
Loading

0 comments on commit 244d761

Please sign in to comment.