Skip to content

Commit

Permalink
On node creation, if reconfiguration is enabled, load network info fr…
Browse files Browse the repository at this point in the history
…om on chain
  • Loading branch information
lanvidr committed Jun 30, 2022
1 parent 2eeafef commit efc36d7
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions crates/sui-config/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ impl<R: ::rand::RngCore + ::rand::CryptoRng> ConfigBuilder<R> {
consensus_config: Some(consensus_config),
enable_event_processing: false,
enable_gossip: true,
enable_reconfig: false,
genesis: crate::node::Genesis::new(genesis.clone()),
}
})
Expand Down
3 changes: 3 additions & 0 deletions crates/sui-config/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub struct NodeConfig {
#[serde(default)]
pub enable_gossip: bool,

#[serde(default)]
pub enable_reconfig: bool,

pub genesis: Genesis,
}

Expand Down
1 change: 1 addition & 0 deletions crates/sui-config/src/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl NetworkConfig {
consensus_config: None,
enable_event_processing: true,
enable_gossip: true,
enable_reconfig: false,
genesis: validator_config.genesis.clone(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ impl AuthorityState {
adapter::new_move_vm(native_functions.clone())
.expect("We defined natives to not fail here"),
);

// TODO: update this function to not take genesis, committee if store already exists
// Only initialize an empty database.
if store
.database_is_empty()
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,7 @@ pub async fn generate_genesis_system_object<S: Eq + Serialize + for<'de> Deseria
CallArg::Pure(bcs::to_bytes(&pubkeys).unwrap()),
CallArg::Pure(bcs::to_bytes(&sui_addresses).unwrap()),
CallArg::Pure(bcs::to_bytes(&names).unwrap()),
// TODO: below is netaddress, for now just use names as we don't yet want to expose them.
// TODO Laura: below is netaddress, for now just use names as we don't yet want to expose them.
CallArg::Pure(bcs::to_bytes(&names).unwrap()),
CallArg::Pure(bcs::to_bytes(&stakes).unwrap()),
],
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-core/src/epoch/reconfiguration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ where
self.gateway_metrics.clone(),
));
self.net.store(new_net.clone());
// TODO: Also reconnect network if changed.
// TODO Laura: Also reconnect network if changed.
// This is blocked for now since we are not storing network info on-chain yet.

// TODO: Update all committee in all components safely,
Expand Down
38 changes: 31 additions & 7 deletions crates/sui-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
use anyhow::Result;
use futures::TryFutureExt;
use jsonrpsee::http_server::HttpServerHandle;
use jsonrpsee::ws_server::WsServerBuilder;
use jsonrpsee::ws_server::WsServerHandle;
use multiaddr::Multiaddr;
use parking_lot::Mutex;
use prometheus::Registry;
use std::option::Option::None;
use std::{collections::BTreeMap, sync::Arc, time::Duration};

use tracing::info;

use sui_config::NodeConfig;
Expand All @@ -33,6 +35,8 @@ use sui_json_rpc::event_api::EventReadApiImpl;
use sui_json_rpc::event_api::EventStreamingApiImpl;
use sui_json_rpc::read_api::FullNodeApi;
use sui_json_rpc::read_api::ReadApi;
use sui_json_rpc_api::EventApiServer;
use sui_types::crypto::PublicKeyBytes;

pub mod metrics;

Expand Down Expand Up @@ -126,12 +130,32 @@ impl SuiNode {
net_config.http2_keepalive_interval = Some(Duration::from_secs(5));

let mut authority_clients = BTreeMap::new();
for validator in genesis.validator_set() {
let channel = net_config
.connect_lazy(validator.network_address())
.unwrap();
let client = NetworkAuthorityClient::new(channel);
authority_clients.insert(validator.public_key(), client);

if config.enable_reconfig {
// Create NetworkAuthorityClient with this epoch's network information
let sui_system_state = state.get_sui_system_state_object().await?;
let epoch_validators = &sui_system_state.validators.active_validators;

for validator in epoch_validators {
let net_addr: &[u8] = &validator.metadata.net_address.clone();
let str_addr = std::str::from_utf8(net_addr)?;
let address: Multiaddr = str_addr.parse().unwrap();
//let address = Multiaddr::try_from(net_addr)?;
let channel = net_config.connect_lazy(&address)?;
let client = NetworkAuthorityClient::new(channel);
let name: &[u8] = &validator.metadata.name;
let public_key_bytes = PublicKeyBytes::try_from(name)?;
authority_clients.insert(public_key_bytes, client);
}
} else {
// Create NetworkAuthorityClient with the genesis set
for validator in genesis.validator_set() {
let channel = net_config
.connect_lazy(validator.network_address())
.unwrap();
let client = NetworkAuthorityClient::new(channel);
authority_clients.insert(validator.public_key(), client);
}
}

let gateway_metrics =
Expand Down

0 comments on commit efc36d7

Please sign in to comment.