Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatten memberships into a single type #3867

Merged
merged 17 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions crates/examples/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use hotshot::{
BlockPayload, NodeImplementation,
},
types::SystemContextHandle,
MarketplaceConfig, Memberships, SystemContext,
MarketplaceConfig, SystemContext,
};
use hotshot_example_types::{
auction_results_provider_types::TestAuctionResultsProvider,
Expand All @@ -55,7 +55,7 @@ use hotshot_types::{
traits::{
block_contents::{BlockHeader, TestableBlock},
election::Membership,
network::{ConnectedNetwork, Topic},
network::ConnectedNetwork,
node_implementation::{ConsensusTime, NodeType, Versions},
states::TestableState,
},
Expand Down Expand Up @@ -381,22 +381,9 @@ pub trait RunDa<

let da_nodes = config.config.known_da_nodes.clone();

// Create the quorum membership from all nodes
let quorum_membership = <TYPES as NodeType>::Membership::new(
all_nodes.clone(),
all_nodes.clone(),
Topic::Global,
);

// Create the quorum membership from all nodes, specifying the committee
// as the known da nodes
let da_membership =
<TYPES as NodeType>::Membership::new(all_nodes.clone(), da_nodes, Topic::Da);

let memberships = Memberships {
quorum_membership: quorum_membership.clone(),
da_membership,
};
let memberships = <TYPES as NodeType>::Membership::new(all_nodes.clone(), da_nodes);
ss-es marked this conversation as resolved.
Show resolved Hide resolved

let marketplace_config = MarketplaceConfig {
auction_results_provider: TestAuctionResultsProvider::<TYPES>::default().into(),
Expand Down Expand Up @@ -544,7 +531,6 @@ pub trait RunDa<
let num_eligible_leaders = context
.hotshot
.memberships
.quorum_membership
.committee_leaders(TYPES::View::genesis(), TYPES::Epoch::genesis())
.len();
let total_num_views = usize::try_from(consensus.locked_view().u64()).unwrap();
Expand Down Expand Up @@ -752,7 +738,7 @@ where

// Create the qurorum membership from the list of known nodes
let all_nodes = config.config.known_nodes_with_stake.clone();
let quorum_membership = TYPES::Membership::new(all_nodes.clone(), all_nodes, Topic::Global);
let quorum_membership = TYPES::Membership::new(all_nodes.clone(), all_nodes);
ss-es marked this conversation as resolved.
Show resolved Hide resolved

// Derive the bind address
let bind_address =
Expand Down
22 changes: 6 additions & 16 deletions crates/hotshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,6 @@ pub struct MarketplaceConfig<TYPES: NodeType, I: NodeImplementation<TYPES>> {
pub fallback_builder_url: Url,
}

/// Bundle of all the memberships a consensus instance uses
#[derive(Clone)]
pub struct Memberships<TYPES: NodeType> {
/// The entire quorum
pub quorum_membership: TYPES::Membership,
/// The DA nodes
pub da_membership: TYPES::Membership,
}

/// Holds the state needed to participate in `HotShot` consensus
pub struct SystemContext<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> {
/// The public key of this node
Expand All @@ -116,7 +107,7 @@ pub struct SystemContext<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versi
pub network: Arc<I::Network>,

/// Memberships used by consensus
pub memberships: Arc<Memberships<TYPES>>,
pub memberships: Arc<TYPES::Membership>,

/// the metrics that the implementor is using.
metrics: Arc<ConsensusMetricsValue>,
Expand Down Expand Up @@ -207,7 +198,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> SystemContext<T
private_key: <TYPES::SignatureKey as SignatureKey>::PrivateKey,
nonce: u64,
config: HotShotConfig<TYPES::SignatureKey>,
memberships: Memberships<TYPES>,
memberships: TYPES::Membership,
network: Arc<I::Network>,
initializer: HotShotInitializer<TYPES>,
metrics: ConsensusMetricsValue,
Expand Down Expand Up @@ -260,7 +251,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> SystemContext<T
private_key: <TYPES::SignatureKey as SignatureKey>::PrivateKey,
nonce: u64,
config: HotShotConfig<TYPES::SignatureKey>,
memberships: Memberships<TYPES>,
memberships: TYPES::Membership,
network: Arc<I::Network>,
initializer: HotShotInitializer<TYPES>,
metrics: ConsensusMetricsValue,
Expand Down Expand Up @@ -507,7 +498,6 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> SystemContext<T
})?;

spawn(async move {
let da_membership = &api.memberships.da_membership.clone();
join! {
// TODO We should have a function that can return a network error if there is one
// but first we'd need to ensure our network implementations can support that
Expand All @@ -519,7 +509,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> SystemContext<T
api
.network.da_broadcast_message(
serialized_message,
da_membership.committee_members(view_number, TYPES::Epoch::new(1)).iter().cloned().collect(),
api.memberships.da_committee_members(view_number, TYPES::Epoch::new(1)).iter().cloned().collect(),
BroadcastDelay::None,
),
api
Expand Down Expand Up @@ -604,7 +594,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> SystemContext<T
private_key: <TYPES::SignatureKey as SignatureKey>::PrivateKey,
node_id: u64,
config: HotShotConfig<TYPES::SignatureKey>,
memberships: Memberships<TYPES>,
memberships: TYPES::Membership,
network: Arc<I::Network>,
initializer: HotShotInitializer<TYPES>,
metrics: ConsensusMetricsValue,
Expand Down Expand Up @@ -767,7 +757,7 @@ where
private_key: <TYPES::SignatureKey as SignatureKey>::PrivateKey,
nonce: u64,
config: HotShotConfig<TYPES::SignatureKey>,
memberships: Memberships<TYPES>,
memberships: TYPES::Membership,
network: Arc<I::Network>,
initializer: HotShotInitializer<TYPES>,
metrics: ConsensusMetricsValue,
Expand Down
34 changes: 10 additions & 24 deletions crates/hotshot/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use vbs::version::StaticVersionType;
use crate::{
tasks::task_state::CreateTaskState, types::SystemContextHandle, ConsensusApi,
ConsensusMetricsValue, ConsensusTaskRegistry, HotShotConfig, HotShotInitializer,
MarketplaceConfig, Memberships, NetworkTaskRegistry, SignatureKey, SystemContext, Versions,
MarketplaceConfig, NetworkTaskRegistry, SignatureKey, SystemContext, Versions,
};

/// event for global event stream
Expand Down Expand Up @@ -82,7 +82,7 @@ pub fn add_response_task<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versi
) {
let state = NetworkResponseState::<TYPES>::new(
handle.hotshot.consensus(),
handle.hotshot.memberships.quorum_membership.clone().into(),
(*handle.hotshot.memberships).clone().into(),
handle.public_key().clone(),
handle.private_key().clone(),
handle.hotshot.id,
Expand Down Expand Up @@ -190,15 +190,13 @@ pub fn add_network_event_task<
>(
handle: &mut SystemContextHandle<TYPES, I, V>,
network: Arc<NET>,
quorum_membership: TYPES::Membership,
da_membership: TYPES::Membership,
membership: TYPES::Membership,
) {
let network_state: NetworkEventTaskState<_, V, _, _> = NetworkEventTaskState {
network,
view: TYPES::View::genesis(),
epoch: TYPES::Epoch::genesis(),
quorum_membership,
da_membership,
membership,
storage: Arc::clone(&handle.storage()),
consensus: OuterConsensus::new(handle.consensus()),
upgrade_lock: handle.hotshot.upgrade_lock.clone(),
Expand Down Expand Up @@ -323,7 +321,7 @@ where
private_key: <TYPES::SignatureKey as SignatureKey>::PrivateKey,
nonce: u64,
config: HotShotConfig<TYPES::SignatureKey>,
memberships: Memberships<TYPES>,
memberships: TYPES::Membership,
network: Arc<I::Network>,
initializer: HotShotInitializer<TYPES>,
metrics: ConsensusMetricsValue,
Expand Down Expand Up @@ -518,26 +516,18 @@ where
/// Adds the `NetworkEventTaskState` tasks possibly modifying them as well.
fn add_network_event_tasks(&self, handle: &mut SystemContextHandle<TYPES, I, V>) {
let network = Arc::clone(&handle.network);
let quorum_membership = handle.memberships.quorum_membership.clone();
let da_membership = handle.memberships.da_membership.clone();

self.add_network_event_task(
handle,
Arc::clone(&network),
quorum_membership.clone(),
da_membership,
);

self.add_network_event_task(handle, Arc::clone(&network), (*handle.memberships).clone());
}

/// Adds a `NetworkEventTaskState` task. Can be reimplemented to modify its behaviour.
fn add_network_event_task(
&self,
handle: &mut SystemContextHandle<TYPES, I, V>,
channel: Arc<<I as NodeImplementation<TYPES>>::Network>,
quorum_membership: TYPES::Membership,
da_membership: TYPES::Membership,
membership: TYPES::Membership,
) {
add_network_event_task(handle, channel, quorum_membership, da_membership);
add_network_event_task(handle, channel, membership);
}
}

Expand Down Expand Up @@ -570,13 +560,9 @@ pub async fn add_network_message_and_request_receiver_tasks<
pub fn add_network_event_tasks<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions>(
handle: &mut SystemContextHandle<TYPES, I, V>,
) {
let quorum_membership = handle.memberships.quorum_membership.clone();
let da_membership = handle.memberships.da_membership.clone();

add_network_event_task(
handle,
Arc::clone(&handle.network),
quorum_membership,
da_membership,
(*handle.memberships).clone(),
);
}
24 changes: 11 additions & 13 deletions crates/hotshot/src/tasks/task_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState
consensus: OuterConsensus::new(handle.hotshot.consensus()),
view: handle.cur_view().await,
delay: handle.hotshot.config.data_request_delay,
da_membership: handle.hotshot.memberships.da_membership.clone(),
da_membership: (*handle.hotshot.memberships).clone(),
public_key: handle.public_key().clone(),
private_key: handle.private_key().clone(),
id: handle.hotshot.id,
Expand All @@ -71,7 +71,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState
output_event_stream: handle.hotshot.external_event_stream.0.clone(),
cur_view: handle.cur_view().await,
cur_epoch: handle.cur_epoch().await,
quorum_membership: handle.hotshot.memberships.quorum_membership.clone().into(),
membership: (*handle.hotshot.memberships).clone().into(),
vote_collectors: BTreeMap::default(),
public_key: handle.public_key().clone(),
private_key: handle.private_key().clone(),
Expand All @@ -92,7 +92,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState
output_event_stream: handle.hotshot.external_event_stream.0.clone(),
cur_view: handle.cur_view().await,
cur_epoch: handle.cur_epoch().await,
quorum_membership: handle.hotshot.memberships.quorum_membership.clone().into(),
membership: (*handle.hotshot.memberships).clone().into(),
network: Arc::clone(&handle.hotshot.network),
vote_collector: None.into(),
public_key: handle.public_key().clone(),
Expand Down Expand Up @@ -121,7 +121,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState
cur_view: handle.cur_view().await,
cur_epoch: handle.cur_epoch().await,
network: Arc::clone(&handle.hotshot.network),
membership: handle.hotshot.memberships.quorum_membership.clone().into(),
membership: (*handle.hotshot.memberships).clone().into(),
public_key: handle.public_key().clone(),
private_key: handle.private_key().clone(),
id: handle.hotshot.id,
Expand All @@ -137,9 +137,8 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState
Self {
consensus: OuterConsensus::new(handle.hotshot.consensus()),
output_event_stream: handle.hotshot.external_event_stream.0.clone(),
da_membership: handle.hotshot.memberships.da_membership.clone().into(),
membership: (*handle.hotshot.memberships).clone().into(),
network: Arc::clone(&handle.hotshot.network),
quorum_membership: handle.hotshot.memberships.quorum_membership.clone().into(),
cur_view: handle.cur_view().await,
cur_epoch: handle.cur_epoch().await,
vote_collectors: BTreeMap::default(),
Expand All @@ -163,7 +162,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState
cur_view,
next_view: cur_view,
cur_epoch: handle.cur_epoch().await,
membership: handle.hotshot.memberships.quorum_membership.clone().into(),
membership: (*handle.hotshot.memberships).clone().into(),
public_key: handle.public_key().clone(),
private_key: handle.private_key().clone(),
num_timeouts_tracked: 0,
Expand All @@ -190,7 +189,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState
consensus: OuterConsensus::new(handle.hotshot.consensus()),
cur_view: handle.cur_view().await,
cur_epoch: handle.cur_epoch().await,
membership: handle.hotshot.memberships.quorum_membership.clone().into(),
membership: (*handle.hotshot.memberships).clone().into(),
public_key: handle.public_key().clone(),
private_key: handle.private_key().clone(),
instance_state: handle.hotshot.instance_state(),
Expand Down Expand Up @@ -231,8 +230,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState
latest_voted_view: handle.cur_view().await,
vote_dependencies: BTreeMap::new(),
network: Arc::clone(&handle.hotshot.network),
quorum_membership: handle.hotshot.memberships.quorum_membership.clone().into(),
da_membership: handle.hotshot.memberships.da_membership.clone().into(),
membership: (*handle.hotshot.memberships).clone().into(),
output_event_stream: handle.hotshot.external_event_stream.0.clone(),
id: handle.hotshot.id,
storage: Arc::clone(&handle.storage),
Expand All @@ -254,7 +252,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState
proposal_dependencies: BTreeMap::new(),
consensus: OuterConsensus::new(consensus),
instance_state: handle.hotshot.instance_state(),
quorum_membership: handle.hotshot.memberships.quorum_membership.clone().into(),
membership: (*handle.hotshot.memberships).clone().into(),
public_key: handle.public_key().clone(),
private_key: handle.private_key().clone(),
storage: Arc::clone(&handle.storage),
Expand All @@ -281,7 +279,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState
consensus: OuterConsensus::new(consensus),
cur_view: handle.cur_view().await,
cur_epoch: handle.cur_epoch().await,
quorum_membership: handle.hotshot.memberships.quorum_membership.clone().into(),
quorum_membership: (*handle.hotshot.memberships).clone().into(),
timeout: handle.hotshot.config.next_view_timeout,
output_event_stream: handle.hotshot.external_event_stream.0.clone(),
storage: Arc::clone(&handle.storage),
Expand All @@ -305,7 +303,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState
private_key: handle.private_key().clone(),
instance_state: handle.hotshot.instance_state(),
network: Arc::clone(&handle.hotshot.network),
quorum_membership: handle.hotshot.memberships.quorum_membership.clone().into(),
membership: (*handle.hotshot.memberships).clone().into(),
vote_collectors: BTreeMap::default(),
timeout_vote_collectors: BTreeMap::default(),
cur_view: handle.cur_view().await,
Expand Down
Loading
Loading