Skip to content

Commit

Permalink
Fix conditional DA: remove node indexing (#3045)
Browse files Browse the repository at this point in the history
* fix conditional DA: remove node indexing

* fix genesis DAC by using DA membership in tests

* PR comments

* PR comment
  • Loading branch information
rob-maron authored Apr 27, 2024
1 parent dba082f commit 6097b09
Show file tree
Hide file tree
Showing 26 changed files with 280 additions and 413 deletions.
3 changes: 1 addition & 2 deletions crates/example-types/src/node_types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use hotshot::traits::{
election::static_committee::{GeneralStaticCommittee, StaticCommittee, StaticElectionConfig},
election::static_committee::{GeneralStaticCommittee, StaticCommittee},
implementations::{
CombinedNetworks, Libp2pNetwork, MemoryNetwork, PushCdnNetwork, WebServerNetwork,
},
Expand Down Expand Up @@ -42,7 +42,6 @@ impl NodeType for TestTypes {
type BlockPayload = TestBlockPayload;
type SignatureKey = BLSPubKey;
type Transaction = TestTransaction;
type ElectionConfigType = StaticElectionConfig;
type ValidatedState = TestValidatedState;
type InstanceState = TestInstanceState;
type Membership = GeneralStaticCommittee<TestTypes, Self::SignatureKey>;
Expand Down
138 changes: 59 additions & 79 deletions crates/examples/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub struct OrchestratorArgs<TYPES: NodeType> {
/// The url the orchestrator runs on; this should be in the form of `http://localhost:5555` or `http://0.0.0.0:5555`
pub url: Url,
/// The configuration file to be used for this run
pub config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
pub config: NetworkConfig<TYPES::SignatureKey>,
}

#[derive(Parser, Debug, Clone)]
Expand All @@ -96,10 +96,8 @@ impl Default for ConfigArgs {
/// # Panics
/// If unable to read the config file from the command line
#[allow(clippy::too_many_lines)]
pub fn read_orchestrator_init_config<TYPES: NodeType>() -> (
NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
Url,
) {
pub fn read_orchestrator_init_config<TYPES: NodeType>() -> (NetworkConfig<TYPES::SignatureKey>, Url)
{
// assign default setting
let mut orchestrator_url = Url::parse("http://localhost:4444").unwrap();
let mut args = ConfigArgs::default();
Expand Down Expand Up @@ -211,7 +209,7 @@ pub fn read_orchestrator_init_config<TYPES: NodeType>() -> (
} else {
error!("No config file provided, we'll use the default one.");
}
let mut config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType> =
let mut config: NetworkConfig<TYPES::SignatureKey> =
load_config_from_file::<TYPES>(&args.config_file);

if let Some(total_nodes_string) = matches.get_one::<String>("total_nodes") {
Expand Down Expand Up @@ -282,15 +280,14 @@ pub fn read_orchestrator_init_config<TYPES: NodeType>() -> (
#[must_use]
pub fn load_config_from_file<TYPES: NodeType>(
config_file: &str,
) -> NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType> {
) -> NetworkConfig<TYPES::SignatureKey> {
let config_file_as_string: String = fs::read_to_string(config_file)
.unwrap_or_else(|_| panic!("Could not read config file located at {config_file}"));
let config_toml: NetworkConfigFile<TYPES::SignatureKey> =
toml::from_str::<NetworkConfigFile<TYPES::SignatureKey>>(&config_file_as_string)
.expect("Unable to convert config file to TOML");

let mut config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType> =
config_toml.into();
let mut config: NetworkConfig<TYPES::SignatureKey> = config_toml.into();

// my_own_validator_config would be best to load from file,
// but its type is too complex to load so we'll generate it from seed now.
Expand All @@ -314,11 +311,7 @@ pub async fn run_orchestrator<
OrchestratorArgs { url, config }: OrchestratorArgs<TYPES>,
) {
println!("Starting orchestrator",);
let _result = hotshot_orchestrator::run_orchestrator::<
TYPES::SignatureKey,
TYPES::ElectionConfigType,
>(config, url)
.await;
let _ = hotshot_orchestrator::run_orchestrator::<TYPES::SignatureKey>(config, url).await;
}

/// Helper function to calculate the nuymber of transactions to send per node per round
Expand All @@ -339,7 +332,7 @@ fn calculate_num_tx_per_round(
/// # Panics
/// Panics if the web server config doesn't exist in `config`
fn webserver_network_from_config<TYPES: NodeType, NetworkVersion: StaticVersionType + 'static>(
config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
config: NetworkConfig<TYPES::SignatureKey>,
pub_key: TYPES::SignatureKey,
) -> WebServerNetwork<TYPES, NetworkVersion> {
// Get the configuration for the web server
Expand Down Expand Up @@ -372,7 +365,7 @@ pub trait RunDA<
{
/// Initializes networking, returns self
async fn initialize_networking(
config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
config: NetworkConfig<TYPES::SignatureKey>,
libp2p_advertise_address: Option<SocketAddr>,
) -> Self;

Expand All @@ -394,46 +387,32 @@ pub trait RunDA<
let da_network = self.get_da_channel();
let quorum_network = self.get_quorum_channel();

// Since we do not currently pass the election config type in the NetworkConfig, this will always be the default election config
let quorum_election_config = config.config.election_config.clone().unwrap_or_else(|| {
TYPES::Membership::default_election_config(
config.config.num_nodes_with_stake.get() as u64,
config.config.num_nodes_without_stake as u64,
)
});

let committee_election_config = TYPES::Membership::default_election_config(
// Use the number of _actual_ DA nodes connected for the committee size
config.config.known_da_nodes.len() as u64,
config.config.num_nodes_without_stake as u64,
);
let networks_bundle = Networks {
quorum_network: quorum_network.clone().into(),
da_network: da_network.clone().into(),
_pd: PhantomData,
};

// 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(),
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(),
known_nodes_with_stake,
config.config.fixed_leader_for_gpuvid,
);

let memberships = Memberships {
quorum_membership: <TYPES as NodeType>::Membership::create_election(
known_nodes_with_stake.clone(),
quorum_election_config.clone(),
config.config.fixed_leader_for_gpuvid,
),
da_membership: <TYPES as NodeType>::Membership::create_election(
known_nodes_with_stake.clone(),
committee_election_config,
config.config.fixed_leader_for_gpuvid,
),
vid_membership: <TYPES as NodeType>::Membership::create_election(
known_nodes_with_stake.clone(),
quorum_election_config.clone(),
config.config.fixed_leader_for_gpuvid,
),
view_sync_membership: <TYPES as NodeType>::Membership::create_election(
known_nodes_with_stake.clone(),
quorum_election_config,
config.config.fixed_leader_for_gpuvid,
),
quorum_membership: quorum_membership.clone(),
da_membership,
vid_membership: quorum_membership.clone(),
view_sync_membership: quorum_membership,
};

SystemContext::init(
Expand Down Expand Up @@ -620,15 +599,15 @@ pub trait RunDA<
fn get_quorum_channel(&self) -> QUORUMNET;

/// Returns the config for this run
fn get_config(&self) -> NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>;
fn get_config(&self) -> NetworkConfig<TYPES::SignatureKey>;
}

// WEB SERVER

/// Represents a web server-based run
pub struct WebServerDARun<TYPES: NodeType, NetworkVersion: StaticVersionType> {
/// the network configuration
config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
config: NetworkConfig<TYPES::SignatureKey>,
/// quorum channel
quorum_channel: WebServerNetwork<TYPES, NetworkVersion>,
/// data availability channel
Expand Down Expand Up @@ -665,7 +644,7 @@ where
NetworkVersion: 'static,
{
async fn initialize_networking(
config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
config: NetworkConfig<TYPES::SignatureKey>,
_libp2p_advertise_address: Option<SocketAddr>,
) -> WebServerDARun<TYPES, NetworkVersion> {
// Get our own key
Expand Down Expand Up @@ -701,7 +680,7 @@ where
self.quorum_channel.clone()
}

fn get_config(&self) -> NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType> {
fn get_config(&self) -> NetworkConfig<TYPES::SignatureKey> {
self.config.clone()
}
}
Expand All @@ -711,7 +690,7 @@ where
/// Represents a Push CDN-based run
pub struct PushCdnDaRun<TYPES: NodeType> {
/// The underlying configuration
config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
config: NetworkConfig<TYPES::SignatureKey>,
/// The quorum channel
quorum_channel: PushCdnNetwork<TYPES>,
/// The DA channel
Expand Down Expand Up @@ -740,7 +719,7 @@ where
Self: Sync,
{
async fn initialize_networking(
config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
config: NetworkConfig<TYPES::SignatureKey>,
_libp2p_advertise_address: Option<SocketAddr>,
) -> PushCdnDaRun<TYPES> {
// Get our own key
Expand Down Expand Up @@ -787,7 +766,7 @@ where
self.quorum_channel.clone()
}

fn get_config(&self) -> NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType> {
fn get_config(&self) -> NetworkConfig<TYPES::SignatureKey> {
self.config.clone()
}
}
Expand All @@ -797,7 +776,7 @@ where
/// Represents a libp2p-based run
pub struct Libp2pDARun<TYPES: NodeType> {
/// the network configuration
config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
config: NetworkConfig<TYPES::SignatureKey>,
/// quorum channel
quorum_channel: Libp2pNetwork<Message<TYPES>, TYPES::SignatureKey>,
/// data availability channel
Expand Down Expand Up @@ -832,7 +811,7 @@ where
Self: Sync,
{
async fn initialize_networking(
config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
config: NetworkConfig<TYPES::SignatureKey>,
libp2p_advertise_address: Option<SocketAddr>,
) -> Libp2pDARun<TYPES> {
// Extrapolate keys for ease of use
Expand Down Expand Up @@ -885,7 +864,7 @@ where
self.quorum_channel.clone()
}

fn get_config(&self) -> NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType> {
fn get_config(&self) -> NetworkConfig<TYPES::SignatureKey> {
self.config.clone()
}
}
Expand All @@ -895,7 +874,7 @@ where
/// Represents a combined-network-based run
pub struct CombinedDARun<TYPES: NodeType> {
/// the network configuration
config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
config: NetworkConfig<TYPES::SignatureKey>,
/// quorum channel
quorum_channel: CombinedNetworks<TYPES>,
/// data availability channel
Expand Down Expand Up @@ -924,7 +903,7 @@ where
Self: Sync,
{
async fn initialize_networking(
config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
config: NetworkConfig<TYPES::SignatureKey>,
libp2p_advertise_address: Option<SocketAddr>,
) -> CombinedDARun<TYPES> {
// Initialize our Libp2p network
Expand Down Expand Up @@ -981,7 +960,7 @@ where
self.quorum_channel.clone()
}

fn get_config(&self) -> NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType> {
fn get_config(&self) -> NetworkConfig<TYPES::SignatureKey> {
self.config.clone()
}
}
Expand Down Expand Up @@ -1020,11 +999,13 @@ pub async fn main_entry_point<
let orchestrator_client: OrchestratorClient = OrchestratorClient::new(args.clone());

// We assume one node will not call this twice to generate two validator_config-s with same identity.
let my_own_validator_config = NetworkConfig::<TYPES::SignatureKey, TYPES::ElectionConfigType>::generate_init_validator_config(
&orchestrator_client,
// This is false for now, we only use it to generate the keypair
false
).await;
let my_own_validator_config =
NetworkConfig::<TYPES::SignatureKey>::generate_init_validator_config(
&orchestrator_client,
// This is false for now, we only use it to generate the keypair
false,
)
.await;

// Derives our Libp2p private key from our private key, and then returns the public key of that key
let libp2p_public_key =
Expand All @@ -1037,18 +1018,17 @@ pub async fn main_entry_point<
// It returns the complete config which also includes peer's public key and public config.
// This function will be taken solely by sequencer right after OrchestratorClient::new,
// which means the previous `generate_validator_config_when_init` will not be taken by sequencer, it's only for key pair generation for testing in hotshot.
let (mut run_config, source) =
NetworkConfig::<TYPES::SignatureKey, TYPES::ElectionConfigType>::get_complete_config(
&orchestrator_client,
args.clone().network_config_file,
my_own_validator_config,
args.advertise_address,
Some(libp2p_public_key),
// If `indexed_da` is true: use the node index to determine if we are a DA node.
true,
)
.await
.expect("failed to get config");
let (mut run_config, source) = NetworkConfig::<TYPES::SignatureKey>::get_complete_config(
&orchestrator_client,
args.clone().network_config_file,
my_own_validator_config,
args.advertise_address,
Some(libp2p_public_key),
// If `indexed_da` is true: use the node index to determine if we are a DA node.
true,
)
.await
.expect("failed to get config");

let builder_task = match run_config.builder {
BuilderType::External => None,
Expand Down
6 changes: 2 additions & 4 deletions crates/examples/push-cdn/whitelist-adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ async fn main() -> Result<()> {

// Attempt to get the config from the orchestrator.
// Loops internally until the config is received.
let config: NetworkConfig<
<TestTypes as NodeType>::SignatureKey,
<TestTypes as NodeType>::ElectionConfigType,
> = orchestrator_client.get_config_after_collection().await;
let config: NetworkConfig<<TestTypes as NodeType>::SignatureKey> =
orchestrator_client.get_config_after_collection().await;

tracing::info!("Received config from orchestrator");

Expand Down
6 changes: 3 additions & 3 deletions crates/hotshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub struct SystemContext<TYPES: NodeType, I: NodeImplementation<TYPES>> {
private_key: <TYPES::SignatureKey as SignatureKey>::PrivateKey,

/// Configuration items for this hotshot instance
pub config: HotShotConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
pub config: HotShotConfig<TYPES::SignatureKey>,

/// Networks used by the instance of hotshot
pub networks: Arc<Networks<TYPES, I>>,
Expand Down Expand Up @@ -205,7 +205,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>> SystemContext<TYPES, I> {
public_key: TYPES::SignatureKey,
private_key: <TYPES::SignatureKey as SignatureKey>::PrivateKey,
nonce: u64,
config: HotShotConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
config: HotShotConfig<TYPES::SignatureKey>,
memberships: Memberships<TYPES>,
networks: Networks<TYPES, I>,
initializer: HotShotInitializer<TYPES>,
Expand Down Expand Up @@ -483,7 +483,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>> SystemContext<TYPES, I> {
public_key: TYPES::SignatureKey,
private_key: <TYPES::SignatureKey as SignatureKey>::PrivateKey,
node_id: u64,
config: HotShotConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
config: HotShotConfig<TYPES::SignatureKey>,
memberships: Memberships<TYPES>,
networks: Networks<TYPES, I>,
initializer: HotShotInitializer<TYPES>,
Expand Down
Loading

0 comments on commit 6097b09

Please sign in to comment.