Skip to content

Commit

Permalink
Integrate consensus Parameters into NodeConfig (#18767)
Browse files Browse the repository at this point in the history
## Description 

This allows setting consensus Parameters via NodeConfig.
Also, do some minor cleanups. But the bulk of the cleanup will happen
when we stop supporting Narwhal.

## Test plan 

CI. Private testnet.

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
mwtian authored and suiwombat committed Sep 16, 2024
1 parent 50ad154 commit d7e00dd
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 32 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/sui-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ clap.workspace = true
object_store.workspace = true
reqwest.workspace = true

consensus-config.workspace = true
narwhal-config.workspace = true
sui-keys.workspace = true
sui-protocol-config.workspace = true
Expand Down
17 changes: 9 additions & 8 deletions crates/sui-config/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use crate::p2p::P2pConfig;
use crate::transaction_deny_config::TransactionDenyConfig;
use crate::Config;
use anyhow::Result;
use narwhal_config::Parameters as ConsensusParameters;
use consensus_config::Parameters as ConsensusParameters;
use narwhal_config::Parameters as NarwhalParameters;
use once_cell::sync::OnceCell;
use rand::rngs::OsRng;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -406,13 +407,9 @@ pub enum ConsensusProtocol {
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct ConsensusConfig {
pub address: Multiaddr,
// Base consensus DB path for all epochs.
pub db_path: PathBuf,

/// Optional alternative address preferentially used by a primary to talk to its own worker.
/// For example, this could be used to connect to co-located workers over a private LAN address.
pub internal_worker_address: Option<Multiaddr>,

/// Maximum number of pending transactions to submit to consensus, including those
/// in submission wait.
/// Assuming 10_000 txn tps * 10 sec consensus latency = 100_000 inflight consensus txns,
Expand All @@ -428,7 +425,11 @@ pub struct ConsensusConfig {
/// on consensus latency estimates.
pub submit_delay_step_override_millis: Option<u64>,

pub narwhal_config: ConsensusParameters,
// Deprecated: Narwhal specific configs.
pub address: Multiaddr,
pub narwhal_config: NarwhalParameters,

pub parameters: ConsensusParameters,
}

impl ConsensusConfig {
Expand All @@ -449,7 +450,7 @@ impl ConsensusConfig {
.map(Duration::from_millis)
}

pub fn narwhal_config(&self) -> &ConsensusParameters {
pub fn narwhal_config(&self) -> &NarwhalParameters {
&self.narwhal_config
}
}
Expand Down
9 changes: 5 additions & 4 deletions crates/sui-core/src/consensus_manager/mysticeti_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ impl MysticetiManager {
}
}

#[allow(unused)]
fn get_store_path(&self, epoch: EpochId) -> PathBuf {
let mut store_path = self.storage_base_path.clone();
store_path.push(format!("{}", epoch));
Expand Down Expand Up @@ -100,7 +99,7 @@ impl MysticetiManager {
impl ConsensusManagerTrait for MysticetiManager {
async fn start(
&self,
_config: &NodeConfig,
config: &NodeConfig,
epoch_store: Arc<AuthorityPerEpochStore>,
consensus_handler_initializer: ConsensusHandlerInitializer,
tx_validator: SuiTxValidator,
Expand All @@ -122,10 +121,12 @@ impl ConsensusManagerTrait for MysticetiManager {
return;
};

// TODO(mysticeti): Fill in the other fields
let consensus_config = config
.consensus_config()
.expect("consensus_config should exist");
let parameters = Parameters {
db_path: Some(self.get_store_path(epoch)),
..Default::default()
..consensus_config.parameters.clone()
};

let own_protocol_key = self.protocol_keypair.public();
Expand Down
2 changes: 0 additions & 2 deletions crates/sui-swarm-config/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub struct ValidatorGenesisConfig {
pub narwhal_primary_address: Multiaddr,
pub narwhal_worker_address: Multiaddr,
pub consensus_address: Multiaddr,
pub consensus_internal_worker_address: Option<Multiaddr>,
#[serde(default = "default_stake")]
pub stake: u64,
pub name: Option<String>,
Expand Down Expand Up @@ -207,7 +206,6 @@ impl ValidatorGenesisConfigBuilder {
narwhal_primary_address,
narwhal_worker_address,
consensus_address,
consensus_internal_worker_address: None,
stake: sui_types::governance::VALIDATOR_LOW_STAKE_THRESHOLD_MIST,
name: None,
}
Expand Down
3 changes: 1 addition & 2 deletions crates/sui-swarm-config/src/node_config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,10 @@ impl ValidatorConfigBuilder {
let network_address = validator.network_address;
let consensus_address = validator.consensus_address;
let consensus_db_path = config_directory.join(CONSENSUS_DB_NAME).join(key_path);
let internal_worker_address = validator.consensus_internal_worker_address;
let localhost = local_ip_utils::localhost_for_testing();
let consensus_config = ConsensusConfig {
address: consensus_address,
db_path: consensus_db_path,
internal_worker_address,
max_pending_transactions: None,
max_submit_position: self.max_submit_position,
submit_delay_step_override_millis: self.submit_delay_step_override_millis,
Expand All @@ -154,6 +152,7 @@ impl ValidatorConfigBuilder {
},
..Default::default()
},
parameters: Default::default(),
};

let p2p_config = P2pConfig {
Expand Down
1 change: 0 additions & 1 deletion crates/sui-swarm-config/tests/snapshot_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ fn network_config_snapshot_matches() {
if let Some(consensus_config) = validator_config.consensus_config.as_mut() {
consensus_config.address = Multiaddr::empty();
consensus_config.db_path = PathBuf::from("/tmp/foo/");
consensus_config.internal_worker_address = Some(Multiaddr::empty());
consensus_config
.narwhal_config
.prometheus_metrics
Expand Down
Loading

0 comments on commit d7e00dd

Please sign in to comment.