Skip to content

Commit

Permalink
[TECH DEBT] Refactor memberships, remove non-staked nodes (#3653)
Browse files Browse the repository at this point in the history
* refactor memberships

* fmt

* improve API

* Make sure each node has above-zero stake

* remove non-staked node support

* PR comments

* fix `random/fixed` leader election to use `eligible_leaders`
  • Loading branch information
rob-maron authored Sep 10, 2024
1 parent a6f1177 commit 8d0fca6
Show file tree
Hide file tree
Showing 24 changed files with 307 additions and 481 deletions.
5 changes: 2 additions & 3 deletions crates/example-types/src/node_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl NodeType for TestTypes {
type Transaction = TestTransaction;
type ValidatedState = TestValidatedState;
type InstanceState = TestInstanceState;
type Membership = GeneralStaticCommittee<TestTypes, Self::SignatureKey>;
type Membership = GeneralStaticCommittee<TestTypes>;
type BuilderSignatureKey = BuilderKey;
}

Expand Down Expand Up @@ -81,8 +81,7 @@ impl NodeType for TestConsecutiveLeaderTypes {
type Transaction = TestTransaction;
type ValidatedState = TestValidatedState;
type InstanceState = TestInstanceState;
type Membership =
StaticCommitteeLeaderForTwoViews<TestConsecutiveLeaderTypes, Self::SignatureKey>;
type Membership = StaticCommitteeLeaderForTwoViews<TestConsecutiveLeaderTypes>;
type BuilderSignatureKey = BuilderKey;
}

Expand Down
20 changes: 11 additions & 9 deletions crates/examples/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,32 +377,34 @@ pub trait RunDa<
// Get KeyPair for certificate Aggregation
let pk = config.config.my_own_validator_config.public_key.clone();
let sk = config.config.my_own_validator_config.private_key.clone();
let known_nodes_with_stake = config.config.known_nodes_with_stake.clone();

let network = self.network();

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

// Create the quorum membership from all nodes
let quorum_membership = <TYPES as NodeType>::Membership::create_election(
known_nodes_with_stake.clone(),
known_nodes_with_stake.clone(),
let quorum_membership = <TYPES as NodeType>::Membership::new(
all_nodes.clone(),
all_nodes.clone(),
Topic::Global,
#[cfg(feature = "fixed-leader-election")]
config.config.fixed_leader_for_gpuvid,
);

// Create the quorum membership from all nodes, specifying the committee
// as the known da nodes
let da_membership = <TYPES as NodeType>::Membership::create_election(
known_nodes_with_stake.clone(),
config.config.known_da_nodes.clone(),
let da_membership = <TYPES as NodeType>::Membership::new(
all_nodes.clone(),
da_nodes,
Topic::Da,
#[cfg(feature = "fixed-leader-election")]
config.config.fixed_leader_for_gpuvid,
);

let memberships = Memberships {
quorum_membership: quorum_membership.clone(),
da_membership,
vid_membership: quorum_membership.clone(),
view_sync_membership: quorum_membership,
};

let marketplace_config = MarketplaceConfig {
Expand Down
8 changes: 2 additions & 6 deletions crates/hotshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,10 @@ pub struct MarketplaceConfig<TYPES: NodeType, I: NodeImplementation<TYPES>> {
/// Bundle of all the memberships a consensus instance uses
#[derive(Clone)]
pub struct Memberships<TYPES: NodeType> {
/// Quorum Membership
/// The entire quorum
pub quorum_membership: TYPES::Membership,
/// DA
/// The DA nodes
pub da_membership: TYPES::Membership,
/// VID
pub vid_membership: TYPES::Membership,
/// View Sync
pub view_sync_membership: TYPES::Membership,
}

/// Holds the state needed to participate in `HotShot` consensus
Expand Down
16 changes: 6 additions & 10 deletions crates/hotshot/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,6 @@ where
let network = Arc::clone(&handle.network);
let quorum_membership = handle.memberships.quorum_membership.clone();
let da_membership = handle.memberships.da_membership.clone();
let vid_membership = handle.memberships.vid_membership.clone();
let view_sync_membership = handle.memberships.view_sync_membership.clone();

self.add_network_event_task(
handle,
Expand All @@ -507,7 +505,7 @@ where
self.add_network_event_task(
handle,
Arc::clone(&network),
quorum_membership,
quorum_membership.clone(),
network::upgrade_filter,
);
self.add_network_event_task(
Expand All @@ -519,13 +517,13 @@ where
self.add_network_event_task(
handle,
Arc::clone(&network),
view_sync_membership,
quorum_membership.clone(),
network::view_sync_filter,
);
self.add_network_event_task(
handle,
Arc::clone(&network),
vid_membership,
quorum_membership,
network::vid_filter,
);
}
Expand Down Expand Up @@ -577,8 +575,6 @@ pub fn add_network_event_tasks<TYPES: NodeType, I: NodeImplementation<TYPES>, V:
let network = Arc::clone(&handle.network);
let quorum_membership = handle.memberships.quorum_membership.clone();
let da_membership = handle.memberships.da_membership.clone();
let vid_membership = handle.memberships.vid_membership.clone();
let view_sync_membership = handle.memberships.view_sync_membership.clone();

add_network_event_task(
handle,
Expand All @@ -589,7 +585,7 @@ pub fn add_network_event_tasks<TYPES: NodeType, I: NodeImplementation<TYPES>, V:
add_network_event_task(
handle,
Arc::clone(&network),
quorum_membership,
quorum_membership.clone(),
network::upgrade_filter,
);
add_network_event_task(
Expand All @@ -601,13 +597,13 @@ pub fn add_network_event_tasks<TYPES: NodeType, I: NodeImplementation<TYPES>, V:
add_network_event_task(
handle,
Arc::clone(&network),
view_sync_membership,
quorum_membership.clone(),
network::view_sync_filter,
);
add_network_event_task(
handle,
Arc::clone(&network),
vid_membership,
quorum_membership,
network::vid_filter,
);
}
9 changes: 2 additions & 7 deletions crates/hotshot/src/tasks/task_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState
cur_view: handle.cur_view().await,
vote_collector: None,
network: Arc::clone(&handle.hotshot.network),
membership: handle.hotshot.memberships.vid_membership.clone().into(),
membership: handle.hotshot.memberships.quorum_membership.clone().into(),
public_key: handle.public_key().clone(),
private_key: handle.private_key().clone(),
id: handle.hotshot.id,
Expand Down Expand Up @@ -161,12 +161,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState
current_view: cur_view,
next_view: cur_view,
network: Arc::clone(&handle.hotshot.network),
membership: handle
.hotshot
.memberships
.view_sync_membership
.clone()
.into(),
membership: handle.hotshot.memberships.quorum_membership.clone().into(),
public_key: handle.public_key().clone(),
private_key: handle.private_key().clone(),
num_timeouts_tracked: 0,
Expand Down
Loading

0 comments on commit 8d0fca6

Please sign in to comment.