diff --git a/crates/iroha/tests/extra_functional/connected_peers.rs b/crates/iroha/tests/extra_functional/connected_peers.rs index 915614c3fd4..2591ff1f63e 100644 --- a/crates/iroha/tests/extra_functional/connected_peers.rs +++ b/crates/iroha/tests/extra_functional/connected_peers.rs @@ -28,7 +28,7 @@ async fn register_new_peer() -> Result<()> { network .config() // only one random peer - .write(["sumeragi", "trusted_peers"], [network.peer().peer()]), + .write(["trusted_peers"], [network.peer().peer()]), None, ) .await; diff --git a/crates/iroha_config/iroha_test_config.toml b/crates/iroha_config/iroha_test_config.toml index 0fb2e8ff6d3..ad2f5b238d8 100644 --- a/crates/iroha_config/iroha_test_config.toml +++ b/crates/iroha_config/iroha_test_config.toml @@ -2,6 +2,13 @@ chain = "00000000-0000-0000-0000-000000000000" public_key = "ed01201C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B" private_key = "802620282ED9F3CF92811C3818DBC4AE594ED59DC1A2F78E4241E31924E101D6B1FB83" +trusted_peers = [ + "ed01201C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B@127.0.0.1:1337", + "ed0120CC25624D62896D3A0BFD8940F928DC2ABF27CC57CEFEB442AA96D9081AAE58A1@127.0.0.1:1338", + "ed0120FACA9E8AA83225CB4D16D67F27DD4F93FC30FFA11ADC1F5C88FD5495ECC91020@127.0.0.1:1339", + "ed01208E351A70B6A603ED285D666B8D689B680865913BA03CE29FB7D13A166C4E7F1F@127.0.0.1:1340", +] + [network] address = "127.0.0.1:1337" public_address = "127.0.0.1:1337" @@ -13,21 +20,5 @@ file = "./genesis.signed.scale" [torii] address = "127.0.0.1:8080" -[[sumeragi.trusted_peers]] -address = "127.0.0.1:1337" -public_key = "ed01201C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B" - -[[sumeragi.trusted_peers]] -address = "127.0.0.1:1338" -public_key = "ed0120CC25624D62896D3A0BFD8940F928DC2ABF27CC57CEFEB442AA96D9081AAE58A1" - -[[sumeragi.trusted_peers]] -address = "127.0.0.1:1339" -public_key = "ed0120FACA9E8AA83225CB4D16D67F27DD4F93FC30FFA11ADC1F5C88FD5495ECC91020" - -[[sumeragi.trusted_peers]] -address = "127.0.0.1:1340" -public_key = "ed01208E351A70B6A603ED285D666B8D689B680865913BA03CE29FB7D13A166C4E7F1F" - [logger] format = "pretty" diff --git a/crates/iroha_config/src/parameters/actual.rs b/crates/iroha_config/src/parameters/actual.rs index 015f9a4bf40..5b1ed6630ea 100644 --- a/crates/iroha_config/src/parameters/actual.rs +++ b/crates/iroha_config/src/parameters/actual.rs @@ -70,6 +70,7 @@ pub struct Common { pub chain: ChainId, pub key_pair: KeyPair, pub peer: Peer, + pub trusted_peers: WithOrigin, } /// Network options @@ -119,10 +120,9 @@ impl Default for Queue { } } -#[derive(Debug, Clone)] +#[derive(Debug, Copy, Clone)] #[allow(missing_docs)] pub struct Sumeragi { - pub trusted_peers: WithOrigin, pub debug_force_soft_fork: bool, } diff --git a/crates/iroha_config/src/parameters/user.rs b/crates/iroha_config/src/parameters/user.rs index 6edfe2077f8..30c9ef1bf87 100644 --- a/crates/iroha_config/src/parameters/user.rs +++ b/crates/iroha_config/src/parameters/user.rs @@ -60,6 +60,8 @@ pub struct Root { public_key: WithOrigin, #[config(env = "PRIVATE_KEY")] private_key: WithOrigin, + #[config(env = "TRUSTED_PEERS", default)] + trusted_peers: WithOrigin, #[config(nested)] genesis: Genesis, #[config(nested)] @@ -104,11 +106,28 @@ impl Root { .change_context(ParseError::BadKeyPair) .ok_or_emit(&mut emitter); + let (network, block_sync, transaction_gossiper) = self.network.parse(); + let Some((peer, trusted_peers)) = key_pair.as_ref().map(|key_pair| { + let peer = Peer::new( + network.address.value().clone(), + key_pair.public_key().clone(), + ); + + ( + peer.clone(), + self.trusted_peers.map(|x| actual::TrustedPeers { + myself: peer, + others: x.0, + }), + ) + }) else { + panic!("Key pair is missing"); + }; + let genesis = self.genesis.into(); let kura = self.kura.parse(); - let (network, block_sync, transaction_gossiper) = self.network.parse(); let logger = self.logger; let queue = self.queue; let snapshot = self.snapshot; @@ -116,16 +135,7 @@ impl Root { let (torii, live_query_store) = self.torii.parse(); let telemetry = self.telemetry.map(actual::Telemetry::from); - let peer = key_pair.as_ref().map(|key_pair| { - Peer::new( - network.address.value().clone(), - key_pair.public_key().clone(), - ) - }); - - let sumeragi = peer - .as_ref() - .map(|peer| self.sumeragi.parse_and_push_self(peer.clone())); + let sumeragi = self.sumeragi.parse(); emitter.into_result()?; @@ -133,7 +143,8 @@ impl Root { let peer = actual::Common { chain: self.chain.0, key_pair, - peer: peer.unwrap(), + peer, + trusted_peers, }; Ok(actual::Root { @@ -142,7 +153,7 @@ impl Root { genesis, torii, kura, - sumeragi: sumeragi.unwrap(), + sumeragi, block_sync, transaction_gossiper, live_query_store, @@ -211,16 +222,14 @@ impl Kura { } } -#[derive(Debug, Copy, Clone, ReadConfig)] +#[derive(Debug, Clone, Copy, ReadConfig)] pub struct KuraDebug { #[config(env = "KURA_DEBUG_OUTPUT_NEW_BLOCKS", default)] output_new_blocks: bool, } -#[derive(Debug, ReadConfig)] +#[derive(Debug, Clone, Copy, ReadConfig)] pub struct Sumeragi { - #[config(env = "TRUSTED_PEERS", default)] - pub trusted_peers: WithOrigin, #[config(nested)] pub debug: SumeragiDebug, } @@ -246,17 +255,12 @@ impl Default for TrustedPeers { } impl Sumeragi { - fn parse_and_push_self(self, self_id: Peer) -> actual::Sumeragi { + fn parse(self) -> actual::Sumeragi { let Self { - trusted_peers, debug: SumeragiDebug { force_soft_fork }, } = self; actual::Sumeragi { - trusted_peers: trusted_peers.map(|x| actual::TrustedPeers { - myself: self_id, - others: x.0, - }), debug_force_soft_fork: force_soft_fork, } } diff --git a/crates/iroha_config/tests/fixtures.rs b/crates/iroha_config/tests/fixtures.rs index 6ccb67eef4b..dd75782b990 100644 --- a/crates/iroha_config/tests/fixtures.rs +++ b/crates/iroha_config/tests/fixtures.rs @@ -85,6 +85,26 @@ fn minimal_config_snapshot() { address: 127.0.0.1:1337, id: ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB, }, + trusted_peers: WithOrigin { + value: TrustedPeers { + myself: Peer { + address: 127.0.0.1:1337, + id: ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB, + }, + others: UniqueVec( + [ + Peer { + address: 127.0.0.1:1338, + id: ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB, + }, + ], + ), + }, + origin: File { + id: ParameterId(trusted_peers), + path: "tests/fixtures/base_trusted_peers.toml", + }, + }, }, network: Network { address: WithOrigin { @@ -135,26 +155,6 @@ fn minimal_config_snapshot() { debug_output_new_blocks: false, }, sumeragi: Sumeragi { - trusted_peers: WithOrigin { - value: TrustedPeers { - myself: Peer { - address: 127.0.0.1:1337, - id: ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB, - }, - others: UniqueVec( - [ - Peer { - address: 127.0.0.1:1338, - id: ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB, - }, - ], - ), - }, - origin: File { - id: ParameterId(sumeragi.trusted_peers), - path: "tests/fixtures/base_trusted_peers.toml", - }, - }, debug_force_soft_fork: false, }, block_sync: BlockSync { @@ -210,7 +210,7 @@ fn self_is_presented_in_trusted_peers() { load_config_from_fixtures("minimal_alone_with_genesis.toml").expect("valid config"); assert!(config - .sumeragi + .common .trusted_peers .value() .clone() diff --git a/crates/iroha_config/tests/fixtures/base_trusted_peers.toml b/crates/iroha_config/tests/fixtures/base_trusted_peers.toml index 1314cd70026..5532e451185 100644 --- a/crates/iroha_config/tests/fixtures/base_trusted_peers.toml +++ b/crates/iroha_config/tests/fixtures/base_trusted_peers.toml @@ -1,3 +1,3 @@ -[[sumeragi.trusted_peers]] -address = "127.0.0.1:1338" -public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB" +trusted_peers = [ + "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB@127.0.0.1:1338", +] diff --git a/crates/iroha_config/tests/fixtures/full.env b/crates/iroha_config/tests/fixtures/full.env index 3d09c06d861..6a8c4b7b4ea 100644 --- a/crates/iroha_config/tests/fixtures/full.env +++ b/crates/iroha_config/tests/fixtures/full.env @@ -14,4 +14,4 @@ LOG_LEVEL=DEBUG LOG_FORMAT=pretty SNAPSHOT_MODE=read_write SNAPSHOT_STORE_DIR=/snapshot/path/from/env -TRUSTED_PEERS=[{"address":"iroha2:1339","public_key":"ed0120312C1B7B5DE23D366ADCF23CD6DB92CE18B2AA283C7D9F5033B969C2DC2B92F4"}] +TRUSTED_PEERS=["ed0120312C1B7B5DE23D366ADCF23CD6DB92CE18B2AA283C7D9F5033B969C2DC2B92F4@iroha2:1339"] diff --git a/crates/iroha_config/tests/fixtures/full.toml b/crates/iroha_config/tests/fixtures/full.toml index c65fcf9d382..2ec566fa69a 100644 --- a/crates/iroha_config/tests/fixtures/full.toml +++ b/crates/iroha_config/tests/fixtures/full.toml @@ -4,6 +4,10 @@ chain = "0" public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB" private_key = "8026208F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F" +trusted_peers = [ + "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB@localhost:8081", +] + [genesis] public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB" file = "genesis.signed.scale" @@ -32,10 +36,6 @@ blocks_in_memory = 128 [kura.debug] output_new_blocks = true -[[sumeragi.trusted_peers]] -address = "localhost:8081" -public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB" - [sumeragi.debug] force_soft_fork = true diff --git a/crates/iroha_core/src/sumeragi/mod.rs b/crates/iroha_core/src/sumeragi/mod.rs index c256b4eddc3..c3a6f51e711 100644 --- a/crates/iroha_core/src/sumeragi/mod.rs +++ b/crates/iroha_core/src/sumeragi/mod.rs @@ -140,7 +140,9 @@ impl SumeragiStartArgs { #[allow(clippy::too_many_lines)] pub fn start(self, shutdown_signal: ShutdownSignal) -> (SumeragiHandle, Child) { let Self { - sumeragi_config, + config: SumeragiConfig { + debug_force_soft_fork, + }, common_config, events_sender, state, @@ -151,7 +153,7 @@ impl SumeragiStartArgs { genesis_network, block_count: BlockCount(block_count), #[cfg(feature = "telemetry")] - sumeragi_metrics: + metrics: SumeragiMetrics { view_changes, dropped_messages, @@ -176,7 +178,7 @@ impl SumeragiStartArgs { topology = match state_view.height() { 0 => Topology::new( - sumeragi_config + common_config .trusted_peers .value() .clone() @@ -207,11 +209,6 @@ impl SumeragiStartArgs { info!("Sumeragi has finished loading blocks and setting up the state"); - #[cfg(debug_assertions)] - let debug_force_soft_fork = sumeragi_config.debug_force_soft_fork; - #[cfg(not(debug_assertions))] - let debug_force_soft_fork = false; - let peer = common_config.peer; let sumeragi = main_loop::Sumeragi { chain_id: common_config.chain, @@ -295,7 +292,7 @@ impl VotingBlock<'_> { /// Arguments for [`SumeragiHandle::start`] function #[allow(missing_docs)] pub struct SumeragiStartArgs { - pub sumeragi_config: SumeragiConfig, + pub config: SumeragiConfig, pub common_config: CommonConfig, pub events_sender: EventsSender, pub state: Arc, @@ -306,7 +303,7 @@ pub struct SumeragiStartArgs { pub genesis_network: GenesisWithPubKey, pub block_count: BlockCount, #[cfg(feature = "telemetry")] - pub sumeragi_metrics: SumeragiMetrics, + pub metrics: SumeragiMetrics, } /// Relevant sumeragi metrics diff --git a/crates/iroha_data_model/src/peer.rs b/crates/iroha_data_model/src/peer.rs index ef398bf0ecb..c7205bb2942 100644 --- a/crates/iroha_data_model/src/peer.rs +++ b/crates/iroha_data_model/src/peer.rs @@ -2,14 +2,15 @@ #[cfg(not(feature = "std"))] use alloc::{format, string::String, vec::Vec}; -use core::hash::Hash; +use core::{hash::Hash, str::FromStr}; use derive_more::{Constructor, DebugCustom, Display}; +use iroha_crypto::PublicKey; use iroha_data_model_derive::model; use iroha_primitives::addr::SocketAddr; pub use self::model::*; -use crate::{Identifiable, PublicKey, Registered}; +use crate::{Identifiable, ParseError, Registered}; #[model] mod model { @@ -17,7 +18,7 @@ mod model { use iroha_data_model_derive::IdEqOrdHash; use iroha_schema::IntoSchema; use parity_scale_codec::{Decode, Encode}; - use serde::{Deserialize, Serialize}; + use serde_with::{DeserializeFromStr, SerializeDisplay}; use super::*; @@ -37,15 +38,14 @@ mod model { Hash, Decode, Encode, - Deserialize, - Serialize, + DeserializeFromStr, + SerializeDisplay, IntoSchema, Getters, )] #[display(fmt = "{public_key}")] #[debug(fmt = "{public_key}")] #[getset(get = "pub")] - #[serde(transparent)] #[repr(transparent)] // TODO: Make it transparent in FFI? #[ffi_type(opaque)] @@ -62,23 +62,30 @@ mod model { IdEqOrdHash, Decode, Encode, - Deserialize, - Serialize, + DeserializeFromStr, + SerializeDisplay, IntoSchema, Getters, )] - #[display(fmt = "{id}@@{address}")] + #[display(fmt = "{id}@{address}")] #[ffi_type] pub struct Peer { /// Address of the [`Peer`]'s entrypoint. #[getset(get = "pub")] pub address: SocketAddr, - #[serde(rename = "public_key")] /// Peer Identification. pub id: PeerId, } } +impl FromStr for PeerId { + type Err = iroha_crypto::error::ParseError; + + fn from_str(s: &str) -> Result { + PublicKey::from_str(s).map(Self::new) + } +} + impl From for PeerId { fn from(public_key: PublicKey) -> Self { Self { public_key } @@ -96,6 +103,33 @@ impl Peer { } } +impl FromStr for Peer { + type Err = ParseError; + + fn from_str(s: &str) -> Result { + match s.rsplit_once("@") { + None => Err(ParseError { + reason: "Peer should have format `public_key@address`", + }), + Some(("", _)) => Err(ParseError { + reason: "Empty `public_key` part in `public_key@address`", + }), + Some((_, "")) => Err(ParseError { + reason: "Empty `address` part in `public_key@address`", + }), + Some((public_key_candidate, address_candidate)) => { + let public_key: PublicKey = public_key_candidate.parse().map_err(|_| ParseError { + reason: r#"Failed to parse `public_key` part in `public_key@address`. `public_key` should have multihash format e.g. "ed0120...""#, + })?; + let address = address_candidate.parse().map_err(|_| ParseError { + reason: "Failed to parse `address` part in `public_key@address`", + })?; + Ok(Self::new(address, public_key)) + } + } + } +} + impl Registered for Peer { type With = PeerId; } diff --git a/crates/iroha_data_model/src/trigger.rs b/crates/iroha_data_model/src/trigger.rs index a14e7ae85f4..e98fa606f8d 100644 --- a/crates/iroha_data_model/src/trigger.rs +++ b/crates/iroha_data_model/src/trigger.rs @@ -57,7 +57,7 @@ mod model { #[derive( Debug, Display, Clone, IdEqOrdHash, Decode, Encode, Deserialize, Serialize, IntoSchema, )] - #[display(fmt = "@@{id}")] + #[display(fmt = "{id}")] #[ffi_type] pub struct Trigger { /// [`Id`] of the [`Trigger`]. diff --git a/crates/iroha_derive/src/lib.rs b/crates/iroha_derive/src/lib.rs index ea5c79c1ab2..aea054f5219 100644 --- a/crates/iroha_derive/src/lib.rs +++ b/crates/iroha_derive/src/lib.rs @@ -68,6 +68,7 @@ pub fn from_variant_derive(input: TokenStream) -> Result { /// It allows you to specify where bounds for `Serialize` and `Deserialize` traits with a more concise syntax. /// /// ```rust +/// use iroha_derive::serde_where; /// use serde::{Deserialize, Serialize}; /// /// trait Trait { diff --git a/crates/iroha_swarm/src/lib.rs b/crates/iroha_swarm/src/lib.rs index 6c252ada9ca..59ac5a7479c 100644 --- a/crates/iroha_swarm/src/lib.rs +++ b/crates/iroha_swarm/src/lib.rs @@ -303,7 +303,7 @@ mod tests { P2P_ADDRESS: 0.0.0.0:1337 API_ADDRESS: 0.0.0.0:8080 GENESIS_PUBLIC_KEY: ed0120F9F92758E815121F637C9704DFDA54842BA937AA721C0603018E208D6E25787E - TRUSTED_PEERS: '[{"address":"irohad3:1340","public_key":"ed012063ED3DFEDEBD8A86B4941CC4379D2EF0B74BDFE61F033FC0C89867D57C882A26"},{"address":"irohad1:1338","public_key":"ed012064BD9B25BF8477144D03B26FC8CF5D8A354B2F780DA310EE69933DC1E86FBCE2"},{"address":"irohad2:1339","public_key":"ed01208EA177921AF051CD12FC07E3416419320908883A1104B31401B650EEB820A300"}]' + TRUSTED_PEERS: '["ed012063ED3DFEDEBD8A86B4941CC4379D2EF0B74BDFE61F033FC0C89867D57C882A26@irohad3:1340","ed012064BD9B25BF8477144D03B26FC8CF5D8A354B2F780DA310EE69933DC1E86FBCE2@irohad1:1338","ed01208EA177921AF051CD12FC07E3416419320908883A1104B31401B650EEB820A300@irohad2:1339"]' GENESIS_PRIVATE_KEY: 802620FB8B867188E4952F1E83534B9B2E0A12D5122BD6F417CBC79D50D8A8C9C917B0 GENESIS: /tmp/genesis.signed.scale TOPOLOGY: '["ed012063ED3DFEDEBD8A86B4941CC4379D2EF0B74BDFE61F033FC0C89867D57C882A26","ed012064BD9B25BF8477144D03B26FC8CF5D8A354B2F780DA310EE69933DC1E86FBCE2","ed012087FDCACF58B891947600B0C37795CADB5A2AE6DE612338FDA9489AB21CE427BA","ed01208EA177921AF051CD12FC07E3416419320908883A1104B31401B650EEB820A300"]' @@ -346,7 +346,7 @@ mod tests { P2P_ADDRESS: 0.0.0.0:1338 API_ADDRESS: 0.0.0.0:8081 GENESIS_PUBLIC_KEY: ed0120F9F92758E815121F637C9704DFDA54842BA937AA721C0603018E208D6E25787E - TRUSTED_PEERS: '[{"address":"irohad3:1340","public_key":"ed012063ED3DFEDEBD8A86B4941CC4379D2EF0B74BDFE61F033FC0C89867D57C882A26"},{"address":"irohad0:1337","public_key":"ed012087FDCACF58B891947600B0C37795CADB5A2AE6DE612338FDA9489AB21CE427BA"},{"address":"irohad2:1339","public_key":"ed01208EA177921AF051CD12FC07E3416419320908883A1104B31401B650EEB820A300"}]' + TRUSTED_PEERS: '["ed012063ED3DFEDEBD8A86B4941CC4379D2EF0B74BDFE61F033FC0C89867D57C882A26@irohad3:1340","ed012087FDCACF58B891947600B0C37795CADB5A2AE6DE612338FDA9489AB21CE427BA@irohad0:1337","ed01208EA177921AF051CD12FC07E3416419320908883A1104B31401B650EEB820A300@irohad2:1339"]' ports: - 1338:1338 - 8081:8081 @@ -367,7 +367,7 @@ mod tests { P2P_ADDRESS: 0.0.0.0:1339 API_ADDRESS: 0.0.0.0:8082 GENESIS_PUBLIC_KEY: ed0120F9F92758E815121F637C9704DFDA54842BA937AA721C0603018E208D6E25787E - TRUSTED_PEERS: '[{"address":"irohad3:1340","public_key":"ed012063ED3DFEDEBD8A86B4941CC4379D2EF0B74BDFE61F033FC0C89867D57C882A26"},{"address":"irohad1:1338","public_key":"ed012064BD9B25BF8477144D03B26FC8CF5D8A354B2F780DA310EE69933DC1E86FBCE2"},{"address":"irohad0:1337","public_key":"ed012087FDCACF58B891947600B0C37795CADB5A2AE6DE612338FDA9489AB21CE427BA"}]' + TRUSTED_PEERS: '["ed012063ED3DFEDEBD8A86B4941CC4379D2EF0B74BDFE61F033FC0C89867D57C882A26@irohad3:1340","ed012064BD9B25BF8477144D03B26FC8CF5D8A354B2F780DA310EE69933DC1E86FBCE2@irohad1:1338","ed012087FDCACF58B891947600B0C37795CADB5A2AE6DE612338FDA9489AB21CE427BA@irohad0:1337"]' ports: - 1339:1339 - 8082:8082 @@ -388,7 +388,7 @@ mod tests { P2P_ADDRESS: 0.0.0.0:1340 API_ADDRESS: 0.0.0.0:8083 GENESIS_PUBLIC_KEY: ed0120F9F92758E815121F637C9704DFDA54842BA937AA721C0603018E208D6E25787E - TRUSTED_PEERS: '[{"address":"irohad1:1338","public_key":"ed012064BD9B25BF8477144D03B26FC8CF5D8A354B2F780DA310EE69933DC1E86FBCE2"},{"address":"irohad0:1337","public_key":"ed012087FDCACF58B891947600B0C37795CADB5A2AE6DE612338FDA9489AB21CE427BA"},{"address":"irohad2:1339","public_key":"ed01208EA177921AF051CD12FC07E3416419320908883A1104B31401B650EEB820A300"}]' + TRUSTED_PEERS: '["ed012064BD9B25BF8477144D03B26FC8CF5D8A354B2F780DA310EE69933DC1E86FBCE2@irohad1:1338","ed012087FDCACF58B891947600B0C37795CADB5A2AE6DE612338FDA9489AB21CE427BA@irohad0:1337","ed01208EA177921AF051CD12FC07E3416419320908883A1104B31401B650EEB820A300@irohad2:1339"]' ports: - 1340:1340 - 8083:8083 @@ -478,7 +478,7 @@ mod tests { P2P_ADDRESS: 0.0.0.0:1337 API_ADDRESS: 0.0.0.0:8080 GENESIS_PUBLIC_KEY: ed0120F9F92758E815121F637C9704DFDA54842BA937AA721C0603018E208D6E25787E - TRUSTED_PEERS: '[{"address":"irohad3:1340","public_key":"ed012063ED3DFEDEBD8A86B4941CC4379D2EF0B74BDFE61F033FC0C89867D57C882A26"},{"address":"irohad1:1338","public_key":"ed012064BD9B25BF8477144D03B26FC8CF5D8A354B2F780DA310EE69933DC1E86FBCE2"},{"address":"irohad2:1339","public_key":"ed01208EA177921AF051CD12FC07E3416419320908883A1104B31401B650EEB820A300"}]' + TRUSTED_PEERS: '["ed012063ED3DFEDEBD8A86B4941CC4379D2EF0B74BDFE61F033FC0C89867D57C882A26@irohad3:1340","ed012064BD9B25BF8477144D03B26FC8CF5D8A354B2F780DA310EE69933DC1E86FBCE2@irohad1:1338","ed01208EA177921AF051CD12FC07E3416419320908883A1104B31401B650EEB820A300@irohad2:1339"]' GENESIS_PRIVATE_KEY: 802620FB8B867188E4952F1E83534B9B2E0A12D5122BD6F417CBC79D50D8A8C9C917B0 GENESIS: /tmp/genesis.signed.scale TOPOLOGY: '["ed012063ED3DFEDEBD8A86B4941CC4379D2EF0B74BDFE61F033FC0C89867D57C882A26","ed012064BD9B25BF8477144D03B26FC8CF5D8A354B2F780DA310EE69933DC1E86FBCE2","ed012087FDCACF58B891947600B0C37795CADB5A2AE6DE612338FDA9489AB21CE427BA","ed01208EA177921AF051CD12FC07E3416419320908883A1104B31401B650EEB820A300"]' @@ -525,7 +525,7 @@ mod tests { P2P_ADDRESS: 0.0.0.0:1338 API_ADDRESS: 0.0.0.0:8081 GENESIS_PUBLIC_KEY: ed0120F9F92758E815121F637C9704DFDA54842BA937AA721C0603018E208D6E25787E - TRUSTED_PEERS: '[{"address":"irohad3:1340","public_key":"ed012063ED3DFEDEBD8A86B4941CC4379D2EF0B74BDFE61F033FC0C89867D57C882A26"},{"address":"irohad0:1337","public_key":"ed012087FDCACF58B891947600B0C37795CADB5A2AE6DE612338FDA9489AB21CE427BA"},{"address":"irohad2:1339","public_key":"ed01208EA177921AF051CD12FC07E3416419320908883A1104B31401B650EEB820A300"}]' + TRUSTED_PEERS: '["ed012063ED3DFEDEBD8A86B4941CC4379D2EF0B74BDFE61F033FC0C89867D57C882A26@irohad3:1340","ed012087FDCACF58B891947600B0C37795CADB5A2AE6DE612338FDA9489AB21CE427BA@irohad0:1337","ed01208EA177921AF051CD12FC07E3416419320908883A1104B31401B650EEB820A300@irohad2:1339"]' ports: - 1338:1338 - 8081:8081 @@ -550,7 +550,7 @@ mod tests { P2P_ADDRESS: 0.0.0.0:1339 API_ADDRESS: 0.0.0.0:8082 GENESIS_PUBLIC_KEY: ed0120F9F92758E815121F637C9704DFDA54842BA937AA721C0603018E208D6E25787E - TRUSTED_PEERS: '[{"address":"irohad3:1340","public_key":"ed012063ED3DFEDEBD8A86B4941CC4379D2EF0B74BDFE61F033FC0C89867D57C882A26"},{"address":"irohad1:1338","public_key":"ed012064BD9B25BF8477144D03B26FC8CF5D8A354B2F780DA310EE69933DC1E86FBCE2"},{"address":"irohad0:1337","public_key":"ed012087FDCACF58B891947600B0C37795CADB5A2AE6DE612338FDA9489AB21CE427BA"}]' + TRUSTED_PEERS: '["ed012063ED3DFEDEBD8A86B4941CC4379D2EF0B74BDFE61F033FC0C89867D57C882A26@irohad3:1340","ed012064BD9B25BF8477144D03B26FC8CF5D8A354B2F780DA310EE69933DC1E86FBCE2@irohad1:1338","ed012087FDCACF58B891947600B0C37795CADB5A2AE6DE612338FDA9489AB21CE427BA@irohad0:1337"]' ports: - 1339:1339 - 8082:8082 @@ -575,7 +575,7 @@ mod tests { P2P_ADDRESS: 0.0.0.0:1340 API_ADDRESS: 0.0.0.0:8083 GENESIS_PUBLIC_KEY: ed0120F9F92758E815121F637C9704DFDA54842BA937AA721C0603018E208D6E25787E - TRUSTED_PEERS: '[{"address":"irohad1:1338","public_key":"ed012064BD9B25BF8477144D03B26FC8CF5D8A354B2F780DA310EE69933DC1E86FBCE2"},{"address":"irohad0:1337","public_key":"ed012087FDCACF58B891947600B0C37795CADB5A2AE6DE612338FDA9489AB21CE427BA"},{"address":"irohad2:1339","public_key":"ed01208EA177921AF051CD12FC07E3416419320908883A1104B31401B650EEB820A300"}]' + TRUSTED_PEERS: '["ed012064BD9B25BF8477144D03B26FC8CF5D8A354B2F780DA310EE69933DC1E86FBCE2@irohad1:1338","ed012087FDCACF58B891947600B0C37795CADB5A2AE6DE612338FDA9489AB21CE427BA@irohad0:1337","ed01208EA177921AF051CD12FC07E3416419320908883A1104B31401B650EEB820A300@irohad2:1339"]' ports: - 1340:1340 - 8083:8083 diff --git a/crates/iroha_swarm/src/schema.rs b/crates/iroha_swarm/src/schema.rs index a0aa9620fe2..d37197e3b0b 100644 --- a/crates/iroha_swarm/src/schema.rs +++ b/crates/iroha_swarm/src/schema.rs @@ -163,7 +163,7 @@ impl<'a> PeerEnv<'a> { .iter() .find(|&peer| peer.id().public_key() == public_key) .unwrap() - .address + .address() .clone(); Self { chain, diff --git a/crates/iroha_test_network/src/lib.rs b/crates/iroha_test_network/src/lib.rs index 187ca60eb0c..05cf094b246 100644 --- a/crates/iroha_test_network/src/lib.rs +++ b/crates/iroha_test_network/src/lib.rs @@ -182,11 +182,11 @@ impl Network { /// Base configuration of all peers. /// - /// Includes `sumeragi.trusted_peers` parameter, containing all currently present peers. + /// Includes `trusted_peers` parameter, containing all currently present peers. pub fn config(&self) -> Table { self.config .clone() - .write(["sumeragi", "trusted_peers"], self.topology()) + .write(["trusted_peers"], self.topology()) } /// Network genesis block. @@ -521,7 +521,7 @@ impl NetworkPeer { /// Spawn the child process. /// - /// Passed configuration must contain network topology in the `sumeragi.trusted_peers` parameter. + /// Passed configuration must contain network topology in the `trusted_peers` parameter. /// /// This function doesn't wait for peer server to start working, or for it to commit genesis block. /// Iroha could as well terminate immediately with an error, and it is not tracked by this function. diff --git a/crates/irohad/src/main.rs b/crates/irohad/src/main.rs index 6c7daafc4e0..b3f4339c488 100644 --- a/crates/irohad/src/main.rs +++ b/crates/irohad/src/main.rs @@ -260,14 +260,14 @@ impl Iroha { ); let (peers_gossiper, child) = PeersGossiper::start( - config.sumeragi.trusted_peers.value().clone(), + config.common.trusted_peers.value().clone(), network.clone(), supervisor.shutdown_signal(), ); supervisor.monitor(child); let (sumeragi, child) = SumeragiStartArgs { - sumeragi_config: config.sumeragi.clone(), + config: config.sumeragi, common_config: config.common.clone(), events_sender: events_sender.clone(), state: state.clone(), @@ -281,7 +281,7 @@ impl Iroha { }, block_count, #[cfg(feature = "telemetry")] - sumeragi_metrics: SumeragiMetrics { + metrics: SumeragiMetrics { dropped_messages: metrics_reporter.metrics().dropped_messages.clone(), view_changes: metrics_reporter.metrics().view_changes.clone(), }, @@ -554,17 +554,17 @@ fn validate_config(config: &Config) -> Result<(), ConfigError> { if config.genesis.file.is_none() && !config - .sumeragi + .common .trusted_peers .value() .contains_other_trusted_peers() { emitter.emit(Report::new(ConfigError::LonePeer).attach_printable("\ - Reason: the network consists from this one peer only (no `sumeragi.trusted_peers` provided).\n\ + Reason: the network consists from this one peer only (no `trusted_peers` provided).\n\ Since `genesis.file` is not set, there is no way to receive the genesis block.\n\ Either provide the genesis by setting `genesis.file` configuration parameter,\n\ - or increase the number of trusted peers in the network using `sumeragi.trusted_peers` configuration parameter.\ - ").attach_printable(config.sumeragi.trusted_peers.clone().into_attachment().display_as_debug())); + or increase the number of trusted peers in the network using `trusted_peers` configuration parameter.\ + ").attach_printable(config.common.trusted_peers.clone().into_attachment().display_as_debug())); } if config.network.address.value() == config.torii.address.value() { diff --git a/defaults/docker-compose.local.yml b/defaults/docker-compose.local.yml index 43ec3d21de4..0fe84117f91 100644 --- a/defaults/docker-compose.local.yml +++ b/defaults/docker-compose.local.yml @@ -15,7 +15,7 @@ services: P2P_ADDRESS: 0.0.0.0:1337 API_ADDRESS: 0.0.0.0:8080 GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 - TRUSTED_PEERS: '[{"address":"irohad2:1339","public_key":"ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10"},{"address":"irohad1:1338","public_key":"ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D"},{"address":"irohad3:1340","public_key":"ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE"}]' + TRUSTED_PEERS: '["ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10@irohad2:1339","ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D@irohad1:1338","ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE@irohad3:1340"]' GENESIS_PRIVATE_KEY: 80262082B3BDE54AEBECA4146257DA0DE8D59D8E46D5FE34887DCD8072866792FCB3AD GENESIS: /tmp/genesis.signed.scale TOPOLOGY: '["ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10","ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D","ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D","ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE"]' @@ -64,7 +64,7 @@ services: P2P_ADDRESS: 0.0.0.0:1338 API_ADDRESS: 0.0.0.0:8081 GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 - TRUSTED_PEERS: '[{"address":"irohad2:1339","public_key":"ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10"},{"address":"irohad0:1337","public_key":"ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D"},{"address":"irohad3:1340","public_key":"ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE"}]' + TRUSTED_PEERS: '["ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10@irohad2:1339","ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D@irohad0:1337","ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE@irohad3:1340"]' ports: - 1338:1338 - 8081:8081 @@ -91,7 +91,7 @@ services: P2P_ADDRESS: 0.0.0.0:1339 API_ADDRESS: 0.0.0.0:8082 GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 - TRUSTED_PEERS: '[{"address":"irohad1:1338","public_key":"ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D"},{"address":"irohad0:1337","public_key":"ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D"},{"address":"irohad3:1340","public_key":"ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE"}]' + TRUSTED_PEERS: '["ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D@irohad1:1338","ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D@irohad0:1337","ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE@irohad3:1340"]' ports: - 1339:1339 - 8082:8082 @@ -118,7 +118,7 @@ services: P2P_ADDRESS: 0.0.0.0:1340 API_ADDRESS: 0.0.0.0:8083 GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 - TRUSTED_PEERS: '[{"address":"irohad2:1339","public_key":"ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10"},{"address":"irohad1:1338","public_key":"ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D"},{"address":"irohad0:1337","public_key":"ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D"}]' + TRUSTED_PEERS: '["ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10@irohad2:1339","ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D@irohad1:1338","ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D@irohad0:1337"]' ports: - 1340:1340 - 8083:8083 diff --git a/defaults/docker-compose.yml b/defaults/docker-compose.yml index 675e9b943ee..cc94927f745 100644 --- a/defaults/docker-compose.yml +++ b/defaults/docker-compose.yml @@ -13,7 +13,7 @@ services: P2P_ADDRESS: 0.0.0.0:1337 API_ADDRESS: 0.0.0.0:8080 GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 - TRUSTED_PEERS: '[{"address":"irohad2:1339","public_key":"ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10"},{"address":"irohad1:1338","public_key":"ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D"},{"address":"irohad3:1340","public_key":"ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE"}]' + TRUSTED_PEERS: '["ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10@irohad2:1339","ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D@irohad1:1338","ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE@irohad3:1340"]' GENESIS_PRIVATE_KEY: 80262082B3BDE54AEBECA4146257DA0DE8D59D8E46D5FE34887DCD8072866792FCB3AD GENESIS: /tmp/genesis.signed.scale TOPOLOGY: '["ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10","ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D","ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D","ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE"]' @@ -59,7 +59,7 @@ services: P2P_ADDRESS: 0.0.0.0:1338 API_ADDRESS: 0.0.0.0:8081 GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 - TRUSTED_PEERS: '[{"address":"irohad2:1339","public_key":"ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10"},{"address":"irohad0:1337","public_key":"ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D"},{"address":"irohad3:1340","public_key":"ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE"}]' + TRUSTED_PEERS: '["ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10@irohad2:1339","ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D@irohad0:1337","ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE@irohad3:1340"]' ports: - 1338:1338 - 8081:8081 @@ -83,7 +83,7 @@ services: P2P_ADDRESS: 0.0.0.0:1339 API_ADDRESS: 0.0.0.0:8082 GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 - TRUSTED_PEERS: '[{"address":"irohad1:1338","public_key":"ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D"},{"address":"irohad0:1337","public_key":"ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D"},{"address":"irohad3:1340","public_key":"ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE"}]' + TRUSTED_PEERS: '["ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D@irohad1:1338","ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D@irohad0:1337","ed0120CACF3A84B8DC8710CE9D6B968EE95EC7EE4C93C85858F026F3B4417F569592CE@irohad3:1340"]' ports: - 1339:1339 - 8082:8082 @@ -107,7 +107,7 @@ services: P2P_ADDRESS: 0.0.0.0:1340 API_ADDRESS: 0.0.0.0:8083 GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 - TRUSTED_PEERS: '[{"address":"irohad2:1339","public_key":"ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10"},{"address":"irohad1:1338","public_key":"ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D"},{"address":"irohad0:1337","public_key":"ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D"}]' + TRUSTED_PEERS: '["ed01204EE2FCD53E1730AF142D1E23951198678295047F9314B4006B0CB61850B1DB10@irohad2:1339","ed01209897952D14BDFAEA780087C38FF3EB800CB20B882748FC95A575ADB9CD2CB21D@irohad1:1338","ed0120A98BAFB0663CE08D75EBD506FEC38A84E576A7C9B0897693ED4B04FD9EF2D18D@irohad0:1337"]' ports: - 1340:1340 - 8083:8083 diff --git a/docs/source/references/peer.template.toml b/docs/source/references/peer.template.toml index af6867671ec..298bb9ecb02 100644 --- a/docs/source/references/peer.template.toml +++ b/docs/source/references/peer.template.toml @@ -13,6 +13,8 @@ # public_key = # private_key = +# trusted_peers = + [genesis] # public_key = # file = @@ -37,11 +39,6 @@ # store_dir = "./storage" # blocks_in_memory = 128 -## Add more of this section for each trusted peer -# [[sumeragi.trusted_peers]] -# address = -# public_key = - [logger] # level = "INFO" # format = "full" diff --git a/scripts/test_env.py b/scripts/test_env.py index eba7d41410d..f6829cc06ad 100755 --- a/scripts/test_env.py +++ b/scripts/test_env.py @@ -36,7 +36,7 @@ def __init__(self, args: argparse.Namespace): self.peers = [_Peer(args, i) for i in range(args.n_peers)] logging.info("Generating shared configuration...") - trusted_peers = [{"address": f"{peer.host_ip}:{peer.p2p_port}", "public_key": peer.public_key} for peer in self.peers] + trusted_peers = [peer.public_key + f"@{peer.host_ip}:{peer.p2p_port}" for peer in self.peers] topology = [peer.public_key for peer in self.peers] genesis_path = pathlib.Path(args.out_dir) / "genesis.json" genesis_key_pair = kagami_generate_key_pair(args.out_dir, seed="Irohagenesis") @@ -44,12 +44,10 @@ def __init__(self, args: argparse.Namespace): genesis_private_key = genesis_key_pair["private_key"] shared_config = { "chain": "00000000-0000-0000-0000-000000000000", + "trusted_peers": trusted_peers, "genesis": { "public_key": genesis_public_key }, - "sumeragi": { - "trusted_peers": trusted_peers - }, "logger": { "level": "INFO", "format": "pretty", @@ -85,7 +83,7 @@ def wait_for_genesis(self, n_tries: int): sys.exit(2) def run(self): - for i, peer in enumerate(self.peers): + for peer in self.peers: peer.run() self.wait_for_genesis(20)