Skip to content

Commit

Permalink
Derive narwhal ports from sui (MystenLabs#1518)
Browse files Browse the repository at this point in the history
  • Loading branch information
asonnino authored Apr 21, 2022
1 parent c104597 commit a6762c9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
35 changes: 35 additions & 0 deletions sui/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,41 @@ impl NetworkConfig {
})
.collect()
}

pub fn make_narwhal_committee(&self) -> ConsensusCommittee<Ed25519PublicKey> {
ConsensusCommittee {
authorities: self
.authorities
.iter()
.map(|x| {
let name = x.key_pair.make_narwhal_keypair().name;
let primary = PrimaryAddresses {
primary_to_primary: format!("{}:{}", x.host, x.port + 1).parse().unwrap(),
worker_to_primary: format!("{}:{}", x.host, x.port + 2).parse().unwrap(),
};
let workers = [(
/* worker_id */ 0,
WorkerAddresses {
primary_to_worker: format!("{}:{}", x.host, x.port + 3)
.parse()
.unwrap(),
transactions: x.consensus_address,
worker_to_worker: format!("{}:{}", x.host, x.port + 4).parse().unwrap(),
},
)]
.iter()
.cloned()
.collect();
let authority = Authority {
stake: x.stake as Stake,
primary,
workers,
};
(name, authority)
})
.collect(),
}
}
}

impl From<&NetworkConfig> for Committee {
Expand Down
3 changes: 1 addition & 2 deletions sui/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use anyhow::anyhow;
use clap::*;
use narwhal_config::Parameters as ConsensusParameters;
use std::path::PathBuf;
use sui::config::make_default_narwhal_committee;
use sui::{
config::{GenesisConfig, NetworkConfig, PersistedConfig, CONSENSUS_DB_NAME},
sui_commands::{genesis, make_server},
Expand Down Expand Up @@ -100,7 +99,7 @@ async fn main() -> Result<(), anyhow::Error> {
net_cfg.port
);

let consensus_committee = make_default_narwhal_committee(&network_config.authorities)?;
let consensus_committee = network_config.make_narwhal_committee();
let consensus_parameters = ConsensusParameters::default();
let consensus_store_path = sui_config_dir()?
.join(CONSENSUS_DB_NAME)
Expand Down

0 comments on commit a6762c9

Please sign in to comment.