diff --git a/client/benches/tps/utils.rs b/client/benches/tps/utils.rs index 045a95527fe..c1a3494260f 100644 --- a/client/benches/tps/utils.rs +++ b/client/benches/tps/utils.rs @@ -56,7 +56,7 @@ impl Config { pub fn measure(self) -> Result { // READY - let (_rt, network, client) = ::start_test_with_runtime(self.peers, None); + let (_rt, network, client) = Network::start_test_with_runtime(self.peers, None); let clients = network.clients(); wait_for_genesis_committed(&clients, 0); diff --git a/client/tests/integration/asset_propagation.rs b/client/tests/integration/asset_propagation.rs index cb88cbef3e6..d248d160f86 100644 --- a/client/tests/integration/asset_propagation.rs +++ b/client/tests/integration/asset_propagation.rs @@ -16,7 +16,7 @@ use test_network::*; fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount_on_another_peer( ) -> Result<()> { // Given - let (_rt, network, client) = ::start_test_with_runtime(4, Some(10_450)); + let (_rt, network, client) = Network::start_test_with_runtime(4, Some(10_450)); wait_for_genesis_committed(&network.clients(), 0); let pipeline_time = Configuration::pipeline_time(); diff --git a/client/tests/integration/config.rs b/client/tests/integration/config.rs index 54c7f4f596b..1c71aba683d 100644 --- a/client/tests/integration/config.rs +++ b/client/tests/integration/config.rs @@ -1,4 +1,4 @@ -use iroha_data_model::Level; +use iroha_client::data_model::Level; use test_network::*; #[test] diff --git a/client/tests/integration/connected_peers.rs b/client/tests/integration/connected_peers.rs index 6d80fe530cf..9d9634316d1 100644 --- a/client/tests/integration/connected_peers.rs +++ b/client/tests/integration/connected_peers.rs @@ -4,13 +4,15 @@ use eyre::{Context, Result}; use iroha_client::{ client::Client, data_model::{ - parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder}, + isi::{Register, Unregister}, peer::Peer as DataModelPeer, - prelude::*, }, }; use iroha_config::iroha::Configuration; +use iroha_primitives::unique_vec; +use rand::{seq::SliceRandom, thread_rng, Rng}; use test_network::*; +use tokio::runtime::Runtime; #[ignore = "ignore, more in #2851"] #[test] @@ -23,11 +25,50 @@ fn connected_peers_with_f_1_0_1() -> Result<()> { connected_peers_with_f(1, Some(11_000)) } +#[test] +fn register_new_peer() -> Result<()> { + let (_rt, network, _) = Network::start_test_with_runtime(4, Some(11_180)); + wait_for_genesis_committed(&network.clients(), 0); + let pipeline_time = Configuration::pipeline_time(); + + let mut peer_clients: Vec<_> = Network::peers(&network) + .zip(Network::clients(&network)) + .collect(); + + check_status(&peer_clients, 1); + + // Start new peer + let mut configuration = Configuration::test(); + configuration.sumeragi.trusted_peers.peers = + unique_vec![peer_clients.choose(&mut thread_rng()).unwrap().0.id.clone()]; + let rt = Runtime::test(); + let new_peer = rt.block_on( + PeerBuilder::new() + .with_configuration(configuration) + .with_into_genesis(WithGenesis::None) + .with_port(11_200) + .start(), + ); + + let register_peer = Register::peer(DataModelPeer::new(new_peer.id.clone())); + peer_clients + .choose(&mut thread_rng()) + .unwrap() + .1 + .submit_blocking(register_peer)?; + peer_clients.push((&new_peer, Client::test(&new_peer.api_address))); + thread::sleep(pipeline_time * 2); // Wait for some time to allow peers to connect + + check_status(&peer_clients, 2); + + Ok(()) +} + /// Test the number of connected peers, changing the number of faults tolerated down and up fn connected_peers_with_f(faults: u64, start_port: Option) -> Result<()> { let n_peers = 3 * faults + 1; - let (_rt, network, client) = ::start_test_with_runtime( + let (_rt, network, _) = Network::start_test_with_runtime( (n_peers) .try_into() .wrap_err("`faults` argument `u64` value too high, cannot convert to `u32`")?, @@ -36,40 +77,52 @@ fn connected_peers_with_f(faults: u64, start_port: Option) -> Result<()> { wait_for_genesis_committed(&network.clients(), 0); let pipeline_time = Configuration::pipeline_time(); - client.submit_all_blocking( - ParametersBuilder::new() - .add_parameter(MAX_TRANSACTIONS_IN_BLOCK, 1u32)? - .into_set_parameters(), - )?; - - // Confirm all peers connected - let mut status = client.get_status()?; - assert_eq!(status.peers, n_peers - 1); - assert_eq!(status.blocks, 2); - - // Unregister a peer: committed with f = `faults` - // then `status.peers` decrements - let peer = network.peers.values().last().unwrap(); - let peer_client = Client::test(&peer.api_address); - let unregister_peer = Unregister::peer(peer.id.clone()); - client.submit_blocking(unregister_peer)?; + let mut peer_clients: Vec<_> = Network::peers(&network) + .zip(Network::clients(&network)) + .collect(); + + check_status(&peer_clients, 1); + + // Unregister a peer: committed with f = `faults` then `status.peers` decrements + let removed_peer_idx = rand::thread_rng().gen_range(0..peer_clients.len()); + let (removed_peer, _) = &peer_clients[removed_peer_idx]; + let unregister_peer = Unregister::peer(removed_peer.id.clone()); + peer_clients + .choose(&mut thread_rng()) + .unwrap() + .1 + .submit_blocking(unregister_peer)?; thread::sleep(pipeline_time * 2); // Wait for some time to allow peers to connect - status = client.get_status()?; - assert_eq!(status.peers, n_peers - 2); - assert_eq!(status.blocks, 3); - status = peer_client.get_status()?; + let (removed_peer, removed_peer_client) = peer_clients.remove(removed_peer_idx); + + check_status(&peer_clients, 2); + let status = removed_peer_client.get_status()?; + // Peer might have been disconnected before getting the block + assert!(status.blocks == 1 || status.blocks == 2); assert_eq!(status.peers, 0); - // Re-register the peer: committed with f = `faults` - 1 then - // `status.peers` increments - let register_peer = Register::peer(DataModelPeer::new(peer.id.clone())); - client.submit_blocking(register_peer)?; - thread::sleep(pipeline_time * 4); // Wait for some time to allow peers to connect - status = client.get_status()?; - assert_eq!(status.peers, n_peers - 1); - assert_eq!(status.blocks, 4); - status = peer_client.get_status()?; - assert_eq!(status.peers, n_peers - 1); - assert_eq!(status.blocks, 4); + // Re-register the peer: committed with f = `faults` - 1 then `status.peers` increments + let register_peer = Register::peer(DataModelPeer::new(removed_peer.id.clone())); + peer_clients + .choose(&mut thread_rng()) + .unwrap() + .1 + .submit_blocking(register_peer)?; + peer_clients.insert(removed_peer_idx, (removed_peer, removed_peer_client)); + thread::sleep(pipeline_time * 2); // Wait for some time to allow peers to connect + + check_status(&peer_clients, 3); + Ok(()) } + +fn check_status(peer_clients: &[(&Peer, Client)], expected_blocks: u64) { + let n_peers = peer_clients.len() as u64; + + for (_, peer_client) in peer_clients { + let status = peer_client.get_status().unwrap(); + + assert_eq!(status.peers, n_peers - 1); + assert_eq!(status.blocks, expected_blocks); + } +} diff --git a/client/tests/integration/events/pipeline.rs b/client/tests/integration/events/pipeline.rs index ec4579bcbe4..77d99dd1b57 100644 --- a/client/tests/integration/events/pipeline.rs +++ b/client/tests/integration/events/pipeline.rs @@ -40,7 +40,7 @@ fn test_with_instruction_and_status_and_port( port: u16, ) -> Result<()> { let (_rt, network, client) = - ::start_test_with_runtime(PEER_COUNT.try_into().unwrap(), Some(port)); + Network::start_test_with_runtime(PEER_COUNT.try_into().unwrap(), Some(port)); let clients = network.clients(); wait_for_genesis_committed(&clients, 0); let pipeline_time = Configuration::pipeline_time(); diff --git a/client/tests/integration/multiple_blocks_created.rs b/client/tests/integration/multiple_blocks_created.rs index a674bb357da..bac51f52cd7 100644 --- a/client/tests/integration/multiple_blocks_created.rs +++ b/client/tests/integration/multiple_blocks_created.rs @@ -18,7 +18,7 @@ const N_BLOCKS: usize = 510; #[test] fn long_multiple_blocks_created() -> Result<()> { // Given - let (_rt, network, client) = ::start_test_with_runtime(4, Some(10_965)); + let (_rt, network, client) = Network::start_test_with_runtime(4, Some(10_965)); wait_for_genesis_committed(&network.clients(), 0); let pipeline_time = Configuration::pipeline_time(); diff --git a/client/tests/integration/multisignature_transaction.rs b/client/tests/integration/multisignature_transaction.rs index ef88d276d9b..4cf5739788b 100644 --- a/client/tests/integration/multisignature_transaction.rs +++ b/client/tests/integration/multisignature_transaction.rs @@ -16,7 +16,7 @@ use test_network::*; #[allow(clippy::too_many_lines)] #[test] fn multisignature_transactions_should_wait_for_all_signatures() -> Result<()> { - let (_rt, network, client) = ::start_test_with_runtime(4, Some(10_945)); + let (_rt, network, client) = Network::start_test_with_runtime(4, Some(10_945)); wait_for_genesis_committed(&network.clients(), 0); let pipeline_time = Configuration::pipeline_time(); diff --git a/client/tests/integration/offline_peers.rs b/client/tests/integration/offline_peers.rs index 193ff34afaf..fc14502caa3 100644 --- a/client/tests/integration/offline_peers.rs +++ b/client/tests/integration/offline_peers.rs @@ -1,11 +1,13 @@ use eyre::Result; use iroha_client::{ - client::{self, QueryResult}, + client::{self, Client, QueryResult}, data_model::{ - parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder}, + peer::{Peer as DataModelPeer, PeerId}, prelude::*, }, }; +use iroha_config::iroha::Configuration; +use iroha_crypto::KeyPair; use test_network::*; use tokio::runtime::Runtime; @@ -14,19 +16,13 @@ fn genesis_block_is_committed_with_some_offline_peers() -> Result<()> { // Given let rt = Runtime::test(); - let (network, client) = rt.block_on(::start_test_with_offline_and_set_n_shifts( + let (network, client) = rt.block_on(Network::start_test_with_offline_and_set_n_shifts( 4, 1, Some(10_560), )); wait_for_genesis_committed(&network.clients(), 1); - client.submit_all_blocking( - ParametersBuilder::new() - .add_parameter(MAX_TRANSACTIONS_IN_BLOCK, 1u32)? - .into_set_parameters(), - )?; - //When let alice_id: AccountId = "alice@wonderland".parse()?; let roses = "rose#wonderland".parse()?; @@ -43,3 +39,41 @@ fn genesis_block_is_committed_with_some_offline_peers() -> Result<()> { assert_eq!(AssetValue::Quantity(alice_has_roses), *asset.value()); Ok(()) } + +#[test] +fn register_offline_peer() -> Result<()> { + let n_peers = 4; + + let (_rt, network, client) = Network::start_test_with_runtime(n_peers, Some(11_160)); + wait_for_genesis_committed(&network.clients(), 0); + let pipeline_time = Configuration::pipeline_time(); + let peer_clients = Network::clients(&network); + + check_status(&peer_clients, 1); + + let address = "128.0.0.2:8085".parse()?; + let key_pair = KeyPair::generate().unwrap(); + let public_key = key_pair.public_key().clone(); + let peer_id = PeerId::new(&address, &public_key); + let register_peer = Register::peer(DataModelPeer::new(peer_id)); + + // Wait for some time to allow peers to connect + client.submit_blocking(register_peer)?; + std::thread::sleep(pipeline_time * 2); + + // Make sure status hasn't change + check_status(&peer_clients, 2); + + Ok(()) +} + +fn check_status(peer_clients: &[Client], expected_blocks: u64) { + let n_peers = peer_clients.len() as u64; + + for peer_client in peer_clients { + let status = peer_client.get_status().unwrap(); + + assert_eq!(status.peers, n_peers - 1); + assert_eq!(status.blocks, expected_blocks); + } +} diff --git a/client/tests/integration/restart_peer.rs b/client/tests/integration/restart_peer.rs index 2faa56e8815..8249edee078 100644 --- a/client/tests/integration/restart_peer.rs +++ b/client/tests/integration/restart_peer.rs @@ -1,50 +1,51 @@ -use std::{str::FromStr, sync::Arc}; +use std::{str::FromStr, thread}; use eyre::Result; use iroha_client::{ - client::{self, QueryResult}, + client::{self, Client, QueryResult}, data_model::prelude::*, }; use iroha_config::iroha::Configuration; -use iroha_primitives::unique_vec; -use tempfile::TempDir; +use rand::{seq::SliceRandom, thread_rng, Rng}; use test_network::*; use tokio::runtime::Runtime; #[test] fn restarted_peer_should_have_the_same_asset_amount() -> Result<()> { - let temp_dir = Arc::new(TempDir::new()?); - - let mut configuration = Configuration::test(); - let mut peer = ::new().with_port(10_000).build()?; - configuration.sumeragi.trusted_peers.peers = unique_vec![peer.id.clone()]; - let account_id = AccountId::from_str("alice@wonderland").unwrap(); let asset_definition_id = AssetDefinitionId::from_str("xor#wonderland").unwrap(); - let create_asset = - Register::asset_definition(AssetDefinition::quantity(asset_definition_id.clone())); let quantity: u32 = 200; - let iroha_client = client::Client::test(&peer.api_address); + let mut removed_peer = { + let n_peers = 4; - { - let rt = Runtime::test(); - rt.block_on( - PeerBuilder::new() - .with_configuration(configuration.clone()) - .with_dir(temp_dir.clone()) - .start_with_peer(&mut peer), - ); - wait_for_genesis_committed(&vec![iroha_client.clone()], 0); + let (_rt, network, _) = Network::start_test_with_runtime(n_peers, Some(11_200)); + wait_for_genesis_committed(&network.clients(), 0); + let pipeline_time = Configuration::pipeline_time(); + let peer_clients = Network::clients(&network); + + let create_asset = + Register::asset_definition(AssetDefinition::quantity(asset_definition_id.clone())); + peer_clients + .choose(&mut thread_rng()) + .unwrap() + .submit_blocking(create_asset)?; - iroha_client.submit_blocking(create_asset)?; let mint_asset = Mint::asset_quantity( quantity, AssetId::new(asset_definition_id.clone(), account_id.clone()), ); - iroha_client.submit_blocking(mint_asset)?; + peer_clients + .choose(&mut thread_rng()) + .unwrap() + .submit_blocking(mint_asset)?; + + // Wait for observing peer to get the block + thread::sleep(pipeline_time); - let assets = iroha_client + let assets = peer_clients + .choose(&mut thread_rng()) + .unwrap() .request(client::asset::by_account_id(account_id.clone()))? .collect::>>()?; let asset = assets @@ -52,20 +53,29 @@ fn restarted_peer_should_have_the_same_asset_amount() -> Result<()> { .find(|asset| asset.id().definition_id == asset_definition_id) .expect("Asset not found"); assert_eq!(AssetValue::Quantity(quantity), *asset.value()); - peer.stop(); - } + let mut all_peers: Vec<_> = core::iter::once(network.genesis) + .chain(network.peers.into_values()) + .collect(); + let removed_peer_idx = rand::thread_rng().gen_range(0..all_peers.len()); + let mut removed_peer = all_peers.swap_remove(removed_peer_idx); + removed_peer.stop(); + removed_peer + }; + // All peers have been stopped here + + // Restart just one peer and check if it updates itself from the blockstore { let rt = Runtime::test(); rt.block_on( PeerBuilder::new() - .with_configuration(configuration) - .with_dir(temp_dir) - .start_with_peer(&mut peer), + .with_dir(removed_peer.temp_dir.as_ref().unwrap().clone()) + .start_with_peer(&mut removed_peer), ); - wait_for_genesis_committed(&vec![iroha_client.clone()], 0); + let removed_peer_client = Client::test(&removed_peer.api_address); + wait_for_genesis_committed(&vec![removed_peer_client.clone()], 0); - iroha_client.poll_request(client::asset::by_account_id(account_id), |result| { + removed_peer_client.poll_request(client::asset::by_account_id(account_id), |result| { let assets = result.collect::>>().expect("Valid"); iroha_logger::error!(?assets); diff --git a/client/tests/integration/triggers/trigger_rollback.rs b/client/tests/integration/triggers/trigger_rollback.rs index 182045a2c7e..3565301e26f 100644 --- a/client/tests/integration/triggers/trigger_rollback.rs +++ b/client/tests/integration/triggers/trigger_rollback.rs @@ -1,8 +1,10 @@ use std::str::FromStr as _; use eyre::Result; -use iroha_client::client::QueryResult; -use iroha_data_model::{prelude::*, query::asset::FindAllAssetsDefinitions, trigger::TriggerId}; +use iroha_client::{ + client::QueryResult, + data_model::{prelude::*, query::asset::FindAllAssetsDefinitions, trigger::TriggerId}, +}; use test_network::*; #[test] diff --git a/client/tests/integration/unregister_peer.rs b/client/tests/integration/unregister_peer.rs index 78ed01325ac..3121bf1de76 100644 --- a/client/tests/integration/unregister_peer.rs +++ b/client/tests/integration/unregister_peer.rs @@ -99,7 +99,7 @@ fn init() -> Result<( AccountId, AssetDefinitionId, )> { - let (rt, network, client) = ::start_test_with_runtime(4, Some(10_925)); + let (rt, network, client) = Network::start_test_with_runtime(4, Some(10_925)); let pipeline_time = Configuration::pipeline_time(); iroha_logger::info!("Started"); let parameters = ParametersBuilder::new() diff --git a/client/tests/integration/unstable_network.rs b/client/tests/integration/unstable_network.rs index cf711cfd9d4..84d1b2d9762 100644 --- a/client/tests/integration/unstable_network.rs +++ b/client/tests/integration/unstable_network.rs @@ -59,7 +59,7 @@ fn unstable_network( { configuration.sumeragi.debug_force_soft_fork = force_soft_fork; } - let network = ::new_with_offline_peers( + let network = Network::new_with_offline_peers( Some(configuration), n_peers + n_offline_peers, 0, diff --git a/config/src/iroha.rs b/config/src/iroha.rs index 6fc69f5069b..ffa28eddc2e 100644 --- a/config/src/iroha.rs +++ b/config/src/iroha.rs @@ -144,11 +144,8 @@ impl ConfigurationProxy { message: "Torii config should have at least `p2p_addr` provided for sumeragi finalisation", }); } - // Finally, if trusted peers were not supplied, we can fall back to inserting itself as - // the only trusted one - if sumeragi_proxy.trusted_peers.is_none() { - sumeragi_proxy.insert_self_as_trusted_peers() - } + + sumeragi_proxy.insert_self_as_trusted_peers() } Ok(()) diff --git a/config/src/sumeragi.rs b/config/src/sumeragi.rs index 18698d634c6..a4eb7760069 100644 --- a/config/src/sumeragi.rs +++ b/config/src/sumeragi.rs @@ -94,11 +94,16 @@ impl ConfigurationProxy { pub fn insert_self_as_trusted_peers(&mut self) { let peer_id = self .peer_id - .clone() + .as_ref() .expect("Insertion of `self` as `trusted_peers` implies that `peer_id` field should be initialized"); - self.trusted_peers = Some(TrustedPeers { - peers: unique_vec![peer_id], - }); + self.trusted_peers = if let Some(mut trusted_peers) = self.trusted_peers.take() { + trusted_peers.peers.push(peer_id.clone()); + Some(trusted_peers) + } else { + Some(TrustedPeers { + peers: unique_vec![peer_id.clone()], + }) + }; } } diff --git a/core/src/block.rs b/core/src/block.rs index 21a7405ef42..164dc6b5456 100644 --- a/core/src/block.rs +++ b/core/src/block.rs @@ -267,27 +267,28 @@ mod valid { topology: &Topology, wsv: &mut WorldStateView, ) -> Result { - let actual_commit_topology = &block.payload().commit_topology; - let expected_commit_topology = &topology.ordered_peers; - - if actual_commit_topology != expected_commit_topology { - let actual_commit_topology = actual_commit_topology.clone(); - - return Err(( - block, - BlockValidationError::TopologyMismatch { - expected: expected_commit_topology.clone(), - actual: actual_commit_topology, - }, - )); - } + if !block.payload().header.is_genesis() { + let actual_commit_topology = &block.payload().commit_topology; + let expected_commit_topology = &topology.ordered_peers; + + if actual_commit_topology != expected_commit_topology { + let actual_commit_topology = actual_commit_topology.clone(); + + return Err(( + block, + BlockValidationError::TopologyMismatch { + expected: expected_commit_topology.clone(), + actual: actual_commit_topology, + }, + )); + } - if !block.payload().header.is_genesis() - && topology + if topology .filter_signatures_by_roles(&[Role::Leader], block.signatures()) .is_empty() - { - return Err((block, SignatureVerificationError::LeaderMissing.into())); + { + return Err((block, SignatureVerificationError::LeaderMissing.into())); + } } let expected_block_height = wsv.height() + 1; diff --git a/core/src/gossiper.rs b/core/src/gossiper.rs index 5856dfd4a1b..365ebb7ac7a 100644 --- a/core/src/gossiper.rs +++ b/core/src/gossiper.rs @@ -100,7 +100,6 @@ impl TransactionGossiper { .n_random_transactions(self.gossip_batch_size, &self.wsv); if txs.is_empty() { - iroha_logger::debug!("Nothing to gossip"); return; } diff --git a/core/src/kiso.rs b/core/src/kiso.rs index 464b01acb0e..cb6d98bf05b 100644 --- a/core/src/kiso.rs +++ b/core/src/kiso.rs @@ -117,11 +117,11 @@ struct Actor { impl Actor { async fn run(&mut self) { while let Some(msg) = self.handle.recv().await { - self.handle_message(msg).await + self.handle_message(msg) } } - async fn handle_message(&mut self, msg: Message) { + fn handle_message(&mut self, msg: Message) { match msg { Message::GetDTO { respond_to } => { let dto = ConfigurationDTO::from(&self.state); diff --git a/core/src/sumeragi/main_loop.rs b/core/src/sumeragi/main_loop.rs index b24b263188a..33e5e41515f 100644 --- a/core/src/sumeragi/main_loop.rs +++ b/core/src/sumeragi/main_loop.rs @@ -186,7 +186,7 @@ impl Sumeragi { &mut self, shutdown_receiver: &mut tokio::sync::oneshot::Receiver<()>, ) -> Result<(), EarlyReturn> { - trace!("Listen for genesis"); + info!(addr = %self.peer_id.address, "Listen for genesis"); loop { std::thread::sleep(Duration::from_millis(50)); @@ -223,6 +223,8 @@ impl Sumeragi { } }; + new_wsv.world_mut().trusted_peers_ids = + block.payload().commit_topology.clone(); self.commit_block(block, new_wsv); return Err(EarlyReturn::GenesisBlockReceivedAndCommitted); } @@ -295,7 +297,7 @@ impl Sumeragi { info!( addr=%self.peer_id.address, role=%self.current_topology.role(&self.peer_id), - block_height=%self.wsv.height(), + block_height=%block.payload().header.height, block_hash=%block.hash(), "{}", Strategy::LOG_MESSAGE, ); @@ -313,11 +315,8 @@ impl Sumeragi { // Parameters are updated before updating public copy of sumeragi self.update_params(); - let new_topology = Topology::recreate_topology( - block.as_ref(), - 0, - self.wsv.peers_ids().iter().cloned().collect(), - ); + let new_topology = + Topology::recreate_topology(block.as_ref(), 0, self.wsv.peers().cloned().collect()); let events = block.produce_events(); // https://github.com/hyperledger/iroha/issues/3396 @@ -801,10 +800,10 @@ pub(crate) fn run( }; span.exit(); - trace!( - me=%sumeragi.peer_id.public_key, + info!( + addr=%sumeragi.peer_id.address, role_in_next_round=%sumeragi.current_topology.role(&sumeragi.peer_id), - "Finished sumeragi init.", + "Sumeragi initialized", ); let mut voting_block = None; @@ -1125,7 +1124,7 @@ fn handle_block_sync( let last_committed_block = new_wsv .latest_block_ref() .expect("Not in genesis round so must have at least genesis block"); - let new_peers = new_wsv.peers_ids().clone(); + let new_peers = new_wsv.peers().cloned().collect(); let view_change_index = block.payload().header().view_change_index; Topology::recreate_topology(&last_committed_block, view_change_index, new_peers) }; @@ -1145,7 +1144,7 @@ fn handle_block_sync( let last_committed_block = new_wsv .latest_block_ref() .expect("Not in genesis round so must have at least genesis block"); - let new_peers = new_wsv.peers_ids().clone(); + let new_peers = new_wsv.peers().cloned().collect(); let view_change_index = block.payload().header().view_change_index; Topology::recreate_topology(&last_committed_block, view_change_index, new_peers) }; diff --git a/core/src/sumeragi/mod.rs b/core/src/sumeragi/mod.rs index 7066d5e9e05..8c82663ee6c 100644 --- a/core/src/sumeragi/mod.rs +++ b/core/src/sumeragi/mod.rs @@ -10,7 +10,7 @@ use std::{ use eyre::{Result, WrapErr as _}; use iroha_config::sumeragi::Configuration; use iroha_crypto::{KeyPair, SignatureOf}; -use iroha_data_model::prelude::*; +use iroha_data_model::{block::SignedBlock, prelude::*}; use iroha_genesis::GenesisNetwork; use iroha_logger::prelude::*; use iroha_telemetry::metrics::Metrics; @@ -226,6 +226,28 @@ impl SumeragiHandle { } } + fn replay_block( + block: &SignedBlock, + wsv: &mut WorldStateView, + current_topology: &Topology, + ) -> Topology { + let block = ValidBlock::validate(block.clone(), current_topology, wsv) + .expect("Kura blocks should be valid") + .commit(current_topology) + .expect("Kura blocks should be valid"); + + if block.payload().header.is_genesis() { + wsv.world_mut().trusted_peers_ids = block.payload().commit_topology.clone(); + } + + wsv.apply_without_execution(&block).expect( + "Block application in init should not fail. \ + Blocks loaded from kura assumed to be valid", + ); + + Topology::recreate_topology(block.as_ref(), 0, wsv.peers().cloned().collect()) + } + /// Start [`Sumeragi`] actor and return handle to it. /// /// # Panics @@ -254,7 +276,7 @@ impl SumeragiHandle { ) }); - let current_topology = match wsv.height() { + let mut current_topology = match wsv.height() { 0 => { assert!(!configuration.trusted_peers.peers.is_empty()); Topology::new(configuration.trusted_peers.peers.clone()) @@ -264,40 +286,21 @@ impl SumeragiHandle { "Sumeragi could not load block that was reported as present. \ Please check that the block storage was not disconnected.", ); - Topology::recreate_topology( - &block_ref, - 0, - wsv.peers_ids().iter().cloned().collect(), - ) + Topology::recreate_topology(&block_ref, 0, wsv.peers().cloned().collect()) } }; let block_iter_except_last = (&mut blocks_iter).take(block_count.saturating_sub(skip_block_count + 1)); for block in block_iter_except_last { - let block = ValidBlock::validate(Clone::clone(&block), ¤t_topology, &mut wsv) - .expect("Kura blocks should be valid") - .commit(¤t_topology) - .expect("Kura blocks should be valid"); - wsv.apply_without_execution(&block).expect( - "Block application in init should not fail. \ - Blocks loaded from kura assumed to be valid", - ); + current_topology = Self::replay_block(&block, &mut wsv, ¤t_topology); } // finalized_wsv is one block behind let finalized_wsv = wsv.clone(); - if let Some(latest_block) = blocks_iter.next() { - let latest_block = - ValidBlock::validate(Clone::clone(&latest_block), ¤t_topology, &mut wsv) - .expect("Kura blocks should be valid") - .commit(¤t_topology) - .expect("Kura blocks should be valid"); - wsv.apply_without_execution(&latest_block).expect( - "Block application in init should not fail. \ - Blocks loaded from kura assumed to be valid", - ); + if let Some(block) = blocks_iter.next() { + current_topology = Self::replay_block(&block, &mut wsv, ¤t_topology); } info!("Sumeragi has finished loading blocks and setting up the WSV"); diff --git a/core/src/wsv.rs b/core/src/wsv.rs index 01c4e8e8d30..0e653e6c488 100644 --- a/core/src/wsv.rs +++ b/core/src/wsv.rs @@ -855,12 +855,6 @@ impl WorldStateView { &mut self.world } - /// Returns reference for trusted peer ids - #[inline] - pub fn peers_ids(&self) -> &PeersIds { - &self.world.trusted_peers_ids - } - /// Return an iterator over blockchain block hashes starting with the block of the given `height` pub fn block_hashes_from_height(&self, height: usize) -> Vec> { self.block_hashes diff --git a/core/test_network/src/lib.rs b/core/test_network/src/lib.rs index b51e1726e47..bf61826e05c 100644 --- a/core/test_network/src/lib.rs +++ b/core/test_network/src/lib.rs @@ -26,7 +26,7 @@ use iroha_primitives::{ unique_vec, unique_vec::UniqueVec, }; -use rand::seq::IteratorRandom; +use rand::{seq::IteratorRandom, thread_rng}; use serde_json::json; use tempfile::TempDir; use tokio::{ @@ -179,7 +179,12 @@ impl Network { ) .await .expect("Failed to init peers"); - let client = Client::test(&network.genesis.api_address); + let client = Client::test( + &Network::peers(&network) + .choose(&mut thread_rng()) + .unwrap() + .api_address, + ); (network, client) } @@ -197,7 +202,12 @@ impl Network { /// Adds peer to network and waits for it to start block /// synchronization. pub async fn add_peer(&self) -> (Peer, Client) { - let genesis_client = Client::test(&self.genesis.api_address); + let client = Client::test( + &Network::peers(self) + .choose(&mut thread_rng()) + .unwrap() + .api_address, + ); let mut config = Configuration::test(); config.sumeragi.trusted_peers.peers = @@ -212,13 +222,10 @@ impl Network { time::sleep(Configuration::pipeline_time() + Configuration::block_sync_gossip_time()).await; let add_peer = Register::peer(DataModelPeer::new(peer.id.clone())); - genesis_client - .submit(add_peer) - .expect("Failed to add new peer."); - - let client = Client::test(&peer.api_address); + client.submit(add_peer).expect("Failed to add new peer."); - (peer, client) + let peer_client = Client::test(&peer.api_address); + (peer, peer_client) } /// Creates new network with some offline peers @@ -359,7 +366,7 @@ pub struct Peer { pub iroha: Option, /// Temporary directory // Note: last field to be dropped after Iroha (struct fields drops in FIFO RFC 1857) - temp_dir: Option>, + pub temp_dir: Option>, } impl From for Box { @@ -556,7 +563,7 @@ impl PeerBuilder { /// Set Iroha configuration #[must_use] pub fn with_configuration(mut self, configuration: Configuration) -> Self { - self.configuration.replace(configuration); + self.configuration = Some(configuration); self } diff --git a/docker-compose.dev.local.yml b/docker-compose.dev.local.yml index 162572d7dd7..a1d0855dc04 100644 --- a/docker-compose.dev.local.yml +++ b/docker-compose.dev.local.yml @@ -13,7 +13,7 @@ services: TORII_API_URL: iroha0:8080 IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 IROHA_GENESIS_ACCOUNT_PRIVATE_KEY: '{"digest_function":"ed25519","payload":"82b3bde54aebeca4146257da0de8d59d8e46d5fe34887dcd8072866792fcb3ad4164bf554923ece1fd412d241036d863a6ae430476c898248b8237d77534cfc4"}' - SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha1:1338","public_key":"ed0120815BBDC9775D28C3633269B25F22D048E2AA2E36017CBE5AD85F15220BEB6F6F"},{"address":"iroha0:1337","public_key":"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"},{"address":"iroha3:1340","public_key":"ed0120A66522370D60B9C09E79ADE2E9BB1EF2E78733A944B999B3A6AEE687CE476D61"},{"address":"iroha2:1339","public_key":"ed0120F417E0371E6ADB32FD66749477402B1AB67F84A8E9B082E997980CC91F327736"}]' + SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha1:1338","public_key":"ed0120815BBDC9775D28C3633269B25F22D048E2AA2E36017CBE5AD85F15220BEB6F6F"},{"address":"iroha3:1340","public_key":"ed0120A66522370D60B9C09E79ADE2E9BB1EF2E78733A944B999B3A6AEE687CE476D61"},{"address":"iroha2:1339","public_key":"ed0120F417E0371E6ADB32FD66749477402B1AB67F84A8E9B082E997980CC91F327736"}]' ports: - 1337:1337 - 8080:8080 @@ -30,7 +30,7 @@ services: TORII_P2P_ADDR: iroha1:1338 TORII_API_URL: iroha1:8081 IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 - SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha1:1338","public_key":"ed0120815BBDC9775D28C3633269B25F22D048E2AA2E36017CBE5AD85F15220BEB6F6F"},{"address":"iroha0:1337","public_key":"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"},{"address":"iroha3:1340","public_key":"ed0120A66522370D60B9C09E79ADE2E9BB1EF2E78733A944B999B3A6AEE687CE476D61"},{"address":"iroha2:1339","public_key":"ed0120F417E0371E6ADB32FD66749477402B1AB67F84A8E9B082E997980CC91F327736"}]' + SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha0:1337","public_key":"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"},{"address":"iroha3:1340","public_key":"ed0120A66522370D60B9C09E79ADE2E9BB1EF2E78733A944B999B3A6AEE687CE476D61"},{"address":"iroha2:1339","public_key":"ed0120F417E0371E6ADB32FD66749477402B1AB67F84A8E9B082E997980CC91F327736"}]' ports: - 1338:1338 - 8081:8081 @@ -46,7 +46,7 @@ services: TORII_P2P_ADDR: iroha2:1339 TORII_API_URL: iroha2:8082 IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 - SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha1:1338","public_key":"ed0120815BBDC9775D28C3633269B25F22D048E2AA2E36017CBE5AD85F15220BEB6F6F"},{"address":"iroha0:1337","public_key":"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"},{"address":"iroha3:1340","public_key":"ed0120A66522370D60B9C09E79ADE2E9BB1EF2E78733A944B999B3A6AEE687CE476D61"},{"address":"iroha2:1339","public_key":"ed0120F417E0371E6ADB32FD66749477402B1AB67F84A8E9B082E997980CC91F327736"}]' + SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha1:1338","public_key":"ed0120815BBDC9775D28C3633269B25F22D048E2AA2E36017CBE5AD85F15220BEB6F6F"},{"address":"iroha0:1337","public_key":"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"},{"address":"iroha3:1340","public_key":"ed0120A66522370D60B9C09E79ADE2E9BB1EF2E78733A944B999B3A6AEE687CE476D61"}]' ports: - 1339:1339 - 8082:8082 @@ -62,7 +62,7 @@ services: TORII_P2P_ADDR: iroha3:1340 TORII_API_URL: iroha3:8083 IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 - SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha1:1338","public_key":"ed0120815BBDC9775D28C3633269B25F22D048E2AA2E36017CBE5AD85F15220BEB6F6F"},{"address":"iroha0:1337","public_key":"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"},{"address":"iroha3:1340","public_key":"ed0120A66522370D60B9C09E79ADE2E9BB1EF2E78733A944B999B3A6AEE687CE476D61"},{"address":"iroha2:1339","public_key":"ed0120F417E0371E6ADB32FD66749477402B1AB67F84A8E9B082E997980CC91F327736"}]' + SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha1:1338","public_key":"ed0120815BBDC9775D28C3633269B25F22D048E2AA2E36017CBE5AD85F15220BEB6F6F"},{"address":"iroha0:1337","public_key":"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"},{"address":"iroha2:1339","public_key":"ed0120F417E0371E6ADB32FD66749477402B1AB67F84A8E9B082E997980CC91F327736"}]' ports: - 1340:1340 - 8083:8083 diff --git a/docker-compose.dev.single.yml b/docker-compose.dev.single.yml index 9a4891ff227..b817eece0c8 100644 --- a/docker-compose.dev.single.yml +++ b/docker-compose.dev.single.yml @@ -13,7 +13,6 @@ services: TORII_API_URL: iroha0:8080 IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 IROHA_GENESIS_ACCOUNT_PRIVATE_KEY: '{"digest_function":"ed25519","payload":"82b3bde54aebeca4146257da0de8d59d8e46d5fe34887dcd8072866792fcb3ad4164bf554923ece1fd412d241036d863a6ae430476c898248b8237d77534cfc4"}' - SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha0:1337","public_key":"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"}]' ports: - 1337:1337 - 8080:8080 diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 9c45d746a06..54404425d99 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -13,7 +13,7 @@ services: TORII_API_URL: iroha0:8080 IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 IROHA_GENESIS_ACCOUNT_PRIVATE_KEY: '{"digest_function":"ed25519","payload":"82b3bde54aebeca4146257da0de8d59d8e46d5fe34887dcd8072866792fcb3ad4164bf554923ece1fd412d241036d863a6ae430476c898248b8237d77534cfc4"}' - SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha1:1338","public_key":"ed0120815BBDC9775D28C3633269B25F22D048E2AA2E36017CBE5AD85F15220BEB6F6F"},{"address":"iroha0:1337","public_key":"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"},{"address":"iroha3:1340","public_key":"ed0120A66522370D60B9C09E79ADE2E9BB1EF2E78733A944B999B3A6AEE687CE476D61"},{"address":"iroha2:1339","public_key":"ed0120F417E0371E6ADB32FD66749477402B1AB67F84A8E9B082E997980CC91F327736"}]' + SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha1:1338","public_key":"ed0120815BBDC9775D28C3633269B25F22D048E2AA2E36017CBE5AD85F15220BEB6F6F"},{"address":"iroha3:1340","public_key":"ed0120A66522370D60B9C09E79ADE2E9BB1EF2E78733A944B999B3A6AEE687CE476D61"},{"address":"iroha2:1339","public_key":"ed0120F417E0371E6ADB32FD66749477402B1AB67F84A8E9B082E997980CC91F327736"}]' ports: - 1337:1337 - 8080:8080 @@ -30,7 +30,7 @@ services: TORII_P2P_ADDR: iroha1:1338 TORII_API_URL: iroha1:8081 IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 - SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha1:1338","public_key":"ed0120815BBDC9775D28C3633269B25F22D048E2AA2E36017CBE5AD85F15220BEB6F6F"},{"address":"iroha0:1337","public_key":"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"},{"address":"iroha3:1340","public_key":"ed0120A66522370D60B9C09E79ADE2E9BB1EF2E78733A944B999B3A6AEE687CE476D61"},{"address":"iroha2:1339","public_key":"ed0120F417E0371E6ADB32FD66749477402B1AB67F84A8E9B082E997980CC91F327736"}]' + SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha0:1337","public_key":"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"},{"address":"iroha3:1340","public_key":"ed0120A66522370D60B9C09E79ADE2E9BB1EF2E78733A944B999B3A6AEE687CE476D61"},{"address":"iroha2:1339","public_key":"ed0120F417E0371E6ADB32FD66749477402B1AB67F84A8E9B082E997980CC91F327736"}]' ports: - 1338:1338 - 8081:8081 @@ -46,7 +46,7 @@ services: TORII_P2P_ADDR: iroha2:1339 TORII_API_URL: iroha2:8082 IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 - SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha1:1338","public_key":"ed0120815BBDC9775D28C3633269B25F22D048E2AA2E36017CBE5AD85F15220BEB6F6F"},{"address":"iroha0:1337","public_key":"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"},{"address":"iroha3:1340","public_key":"ed0120A66522370D60B9C09E79ADE2E9BB1EF2E78733A944B999B3A6AEE687CE476D61"},{"address":"iroha2:1339","public_key":"ed0120F417E0371E6ADB32FD66749477402B1AB67F84A8E9B082E997980CC91F327736"}]' + SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha1:1338","public_key":"ed0120815BBDC9775D28C3633269B25F22D048E2AA2E36017CBE5AD85F15220BEB6F6F"},{"address":"iroha0:1337","public_key":"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"},{"address":"iroha3:1340","public_key":"ed0120A66522370D60B9C09E79ADE2E9BB1EF2E78733A944B999B3A6AEE687CE476D61"}]' ports: - 1339:1339 - 8082:8082 @@ -62,7 +62,7 @@ services: TORII_P2P_ADDR: iroha3:1340 TORII_API_URL: iroha3:8083 IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 - SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha1:1338","public_key":"ed0120815BBDC9775D28C3633269B25F22D048E2AA2E36017CBE5AD85F15220BEB6F6F"},{"address":"iroha0:1337","public_key":"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"},{"address":"iroha3:1340","public_key":"ed0120A66522370D60B9C09E79ADE2E9BB1EF2E78733A944B999B3A6AEE687CE476D61"},{"address":"iroha2:1339","public_key":"ed0120F417E0371E6ADB32FD66749477402B1AB67F84A8E9B082E997980CC91F327736"}]' + SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha1:1338","public_key":"ed0120815BBDC9775D28C3633269B25F22D048E2AA2E36017CBE5AD85F15220BEB6F6F"},{"address":"iroha0:1337","public_key":"ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB"},{"address":"iroha2:1339","public_key":"ed0120F417E0371E6ADB32FD66749477402B1AB67F84A8E9B082E997980CC91F327736"}]' ports: - 1340:1340 - 8083:8083 diff --git a/docker-compose.single.yml b/docker-compose.single.yml index d46667110c2..454f92ff312 100644 --- a/docker-compose.single.yml +++ b/docker-compose.single.yml @@ -3,6 +3,7 @@ services: iroha0: build: . image: iroha2:lts + platform: linux/amd64 environment: TORII_P2P_ADDR: iroha0:1337 TORII_API_URL: iroha0:8080 diff --git a/docker-compose.stable.single.yml b/docker-compose.stable.single.yml index e2c07b8e2fc..dfb250f6d9f 100644 --- a/docker-compose.stable.single.yml +++ b/docker-compose.stable.single.yml @@ -3,13 +3,13 @@ services: iroha0: build: . image: iroha2:stable + platform: linux/amd64 environment: TORII_P2P_ADDR: iroha0:1337 TORII_API_URL: iroha0:8080 TORII_TELEMETRY_URL: iroha0:8180 IROHA_PUBLIC_KEY: "ed01201C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B" IROHA_PRIVATE_KEY: '{"digest_function": "ed25519", "payload": "282ED9F3CF92811C3818DBC4AE594ED59DC1A2F78E4241E31924E101D6B1FB831C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B"}' - SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha0:1337", "public_key": "ed01201C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B"}]' IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: 'ed01203F4E3E98571B55514EDC5CCF7E53CA7509D89B2868E62921180A6F57C2F4E255' IROHA_GENESIS_ACCOUNT_PRIVATE_KEY: '{"digest_function": "ed25519", "payload": "038AE16B219DA35AA036335ED0A43C28A2CC737150112C78A7B8034B9D99C9023F4E3E98571B55514EDC5CCF7E53CA7509D89B2868E62921180A6F57C2F4E255"}' IROHA_GENESIS_WAIT_FOR_PEERS_RETRY_COUNT_LIMIT: 100 @@ -18,7 +18,6 @@ services: ports: - "1337:1337" - "8080:8080" - - "8180:8180" init: true command: iroha --submit-genesis volumes: diff --git a/docker-compose.stable.yml b/docker-compose.stable.yml index e57463504fc..95cdf9e04d8 100644 --- a/docker-compose.stable.yml +++ b/docker-compose.stable.yml @@ -2,13 +2,14 @@ version: "3.8" services: iroha0: image: hyperledger/iroha2:stable + platform: linux/amd64 environment: TORII_P2P_ADDR: iroha0:1337 TORII_API_URL: iroha0:8080 TORII_TELEMETRY_URL: iroha0:8180 IROHA_PUBLIC_KEY: "ed01201C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B" IROHA_PRIVATE_KEY: '{"digest_function": "ed25519", "payload": "282ED9F3CF92811C3818DBC4AE594ED59DC1A2F78E4241E31924E101D6B1FB831C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B"}' - SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha0:1337", "public_key": "ed01201C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B"}, {"address":"iroha1:1338", "public_key": "ed0120CC25624D62896D3A0BFD8940F928DC2ABF27CC57CEFEB442AA96D9081AAE58A1"}, {"address": "iroha2:1339", "public_key": "ed0120FACA9E8AA83225CB4D16D67F27DD4F93FC30FFA11ADC1F5C88FD5495ECC91020"}, {"address": "iroha3:1340", "public_key": "ed01208E351A70B6A603ED285D666B8D689B680865913BA03CE29FB7D13A166C4E7F1F"}]' + SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha1:1338", "public_key": "ed0120CC25624D62896D3A0BFD8940F928DC2ABF27CC57CEFEB442AA96D9081AAE58A1"}, {"address": "iroha2:1339", "public_key": "ed0120FACA9E8AA83225CB4D16D67F27DD4F93FC30FFA11ADC1F5C88FD5495ECC91020"}, {"address": "iroha3:1340", "public_key": "ed01208E351A70B6A603ED285D666B8D689B680865913BA03CE29FB7D13A166C4E7F1F"}]' IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: 'ed01203f4e3e98571b55514edc5ccf7e53ca7509d89b2868e62921180a6f57c2f4e255' IROHA_GENESIS_ACCOUNT_PRIVATE_KEY: '{ "digest_function": "ed25519", "payload": "038AE16B219DA35AA036335ED0A43C28A2CC737150112C78A7B8034B9D99C9023F4E3E98571B55514EDC5CCF7E53CA7509D89B2868E62921180A6F57C2F4E255" }' IROHA_GENESIS_WAIT_FOR_PEERS_RETRY_COUNT_LIMIT: 100 @@ -17,7 +18,6 @@ services: ports: - "1337:1337" - "8080:8080" - - "8180:8180" volumes: - './configs/peer/stable:/config' init: true @@ -25,13 +25,14 @@ services: iroha1: image: hyperledger/iroha2:stable + platform: linux/amd64 environment: TORII_P2P_ADDR: iroha1:1338 TORII_API_URL: iroha1:8081 TORII_TELEMETRY_URL: iroha1:8181 IROHA_PUBLIC_KEY: "ed0120CC25624D62896D3A0BFD8940F928DC2ABF27CC57CEFEB442AA96D9081AAE58A1" IROHA_PRIVATE_KEY: '{"digest_function": "ed25519", "payload": "3BAC34CDA9E3763FA069C1198312D1EC73B53023B8180C822AC355435EDC4A24CC25624D62896D3A0BFD8940F928DC2ABF27CC57CEFEB442AA96D9081AAE58A1"}' - SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha0:1337", "public_key": "ed01201C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B"}, {"address":"iroha1:1338", "public_key": "ed0120CC25624D62896D3A0BFD8940F928DC2ABF27CC57CEFEB442AA96D9081AAE58A1"}, {"address": "iroha2:1339", "public_key": "ed0120FACA9E8AA83225CB4D16D67F27DD4F93FC30FFA11ADC1F5C88FD5495ECC91020"}, {"address": "iroha3:1340", "public_key": "ed01208E351A70B6A603ED285D666B8D689B680865913BA03CE29FB7D13A166C4E7F1F"}]' + SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha0:1337", "public_key": "ed01201C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B"}, {"address": "iroha2:1339", "public_key": "ed0120FACA9E8AA83225CB4D16D67F27DD4F93FC30FFA11ADC1F5C88FD5495ECC91020"}, {"address": "iroha3:1340", "public_key": "ed01208E351A70B6A603ED285D666B8D689B680865913BA03CE29FB7D13A166C4E7F1F"}]' IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: 'ed01203F4E3E98571B55514EDC5CCF7E53CA7509D89B2868E62921180A6F57C2F4E255' IROHA_GENESIS_WAIT_FOR_PEERS_RETRY_COUNT_LIMIT: 100 IROHA_GENESIS_WAIT_FOR_PEERS_RETRY_PERIOD_MS: 500 @@ -39,20 +40,20 @@ services: ports: - "1338:1338" - "8081:8081" - - "8181:8181" volumes: - './configs/peer/stable:/config' init: true iroha2: image: hyperledger/iroha2:stable + platform: linux/amd64 environment: TORII_P2P_ADDR: iroha2:1339 TORII_API_URL: iroha2:8082 TORII_TELEMETRY_URL: iroha2:8182 IROHA_PUBLIC_KEY: "ed0120FACA9E8AA83225CB4D16D67F27DD4F93FC30FFA11ADC1F5C88FD5495ECC91020" IROHA_PRIVATE_KEY: '{"digest_function": "ed25519", "payload": "1261A436D36779223D7D6CF20E8B644510E488E6A50BAFD77A7485264D27197DFACA9E8AA83225CB4D16D67F27DD4F93FC30FFA11ADC1F5C88FD5495ECC91020"}' - SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha0:1337", "public_key": "ed01201C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B"}, {"address":"iroha1:1338", "public_key": "ed0120CC25624D62896D3A0BFD8940F928DC2ABF27CC57CEFEB442AA96D9081AAE58A1"}, {"address": "iroha2:1339", "public_key": "ed0120FACA9E8AA83225CB4D16D67F27DD4F93FC30FFA11ADC1F5C88FD5495ECC91020"}, {"address": "iroha3:1340", "public_key": "ed01208E351A70B6A603ED285D666B8D689B680865913BA03CE29FB7D13A166C4E7F1F"}]' + SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha0:1337", "public_key": "ed01201C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B"}, {"address":"iroha1:1338", "public_key": "ed0120CC25624D62896D3A0BFD8940F928DC2ABF27CC57CEFEB442AA96D9081AAE58A1"}, {"address": "iroha3:1340", "public_key": "ed01208E351A70B6A603ED285D666B8D689B680865913BA03CE29FB7D13A166C4E7F1F"}]' IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: 'ed01203F4E3E98571B55514EDC5CCF7E53CA7509D89B2868E62921180A6F57C2F4E255' IROHA_GENESIS_WAIT_FOR_PEERS_RETRY_COUNT_LIMIT: 100 IROHA_GENESIS_WAIT_FOR_PEERS_RETRY_PERIOD_MS: 500 @@ -60,20 +61,20 @@ services: ports: - "1339:1339" - "8082:8082" - - "8182:8182" volumes: - './configs/peer/stable:/config' init: true iroha3: image: hyperledger/iroha2:stable + platform: linux/amd64 environment: TORII_P2P_ADDR: iroha3:1340 TORII_API_URL: iroha3:8083 TORII_TELEMETRY_URL: iroha3:8183 IROHA_PUBLIC_KEY: "ed01208E351A70B6A603ED285D666B8D689B680865913BA03CE29FB7D13A166C4E7F1F" IROHA_PRIVATE_KEY: '{"digest_function": "ed25519", "payload": "A70DAB95C7482EB9F159111B65947E482108CFE67DF877BD8D3B9441A781C7C98E351A70B6A603ED285D666B8D689B680865913BA03CE29FB7D13A166C4E7F1F"}' - SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha0:1337", "public_key": "ed01201C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B"}, {"address":"iroha1:1338", "public_key": "ed0120CC25624D62896D3A0BFD8940F928DC2ABF27CC57CEFEB442AA96D9081AAE58A1"}, {"address": "iroha2:1339", "public_key": "ed0120FACA9E8AA83225CB4D16D67F27DD4F93FC30FFA11ADC1F5C88FD5495ECC91020"}, {"address": "iroha3:1340", "public_key": "ed01208E351A70B6A603ED285D666B8D689B680865913BA03CE29FB7D13A166C4E7F1F"}]' + SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha0:1337", "public_key": "ed01201C61FAF8FE94E253B93114240394F79A607B7FA55F9E5A41EBEC74B88055768B"}, {"address":"iroha1:1338", "public_key": "ed0120CC25624D62896D3A0BFD8940F928DC2ABF27CC57CEFEB442AA96D9081AAE58A1"}, {"address": "iroha2:1339", "public_key": "ed0120FACA9E8AA83225CB4D16D67F27DD4F93FC30FFA11ADC1F5C88FD5495ECC91020"}]' IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: 'ed01203F4E3E98571B55514EDC5CCF7E53CA7509D89B2868E62921180A6F57C2F4E255' IROHA_GENESIS_WAIT_FOR_PEERS_RETRY_COUNT_LIMIT: 100 IROHA_GENESIS_WAIT_FOR_PEERS_RETRY_PERIOD_MS: 500 @@ -81,7 +82,6 @@ services: ports: - "1340:1340" - "8083:8083" - - "8183:8183" volumes: - './configs/peer/stable:/config' init: true diff --git a/docker-compose.yml b/docker-compose.yml index e781607ee9a..d24025c2fb3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,7 @@ version: "3.8" services: iroha0: image: hyperledger/iroha2:lts + platform: linux/amd64 environment: TORII_P2P_ADDR: iroha0:1337 TORII_API_URL: iroha0:8080 @@ -25,6 +26,7 @@ services: iroha1: image: hyperledger/iroha2:lts + platform: linux/amd64 environment: TORII_P2P_ADDR: iroha1:1338 TORII_API_URL: iroha1:8081 @@ -46,6 +48,7 @@ services: iroha2: image: hyperledger/iroha2:lts + platform: linux/amd64 environment: TORII_P2P_ADDR: iroha2:1339 TORII_API_URL: iroha2:8082 @@ -67,6 +70,7 @@ services: iroha3: image: hyperledger/iroha2:lts + platform: linux/amd64 environment: TORII_P2P_ADDR: iroha3:1340 TORII_API_URL: iroha3:8083 diff --git a/p2p/src/network.rs b/p2p/src/network.rs index 751eb779d3d..51b97d661e2 100644 --- a/p2p/src/network.rs +++ b/p2p/src/network.rs @@ -366,7 +366,7 @@ impl NetworkBase { }: Connected, ) { if !self.current_topology.contains_key(&peer_id) { - iroha_logger::warn!(topology=?self.current_topology, "Peer not present in topology is trying to connect"); + iroha_logger::warn!(%peer_id, topology=?self.current_topology, "Peer not present in topology is trying to connect"); return; } diff --git a/smart_contract/executor/derive/src/validate.rs b/smart_contract/executor/derive/src/validate.rs index e552005dbf1..3b7df471f0f 100644 --- a/smart_contract/executor/derive/src/validate.rs +++ b/smart_contract/executor/derive/src/validate.rs @@ -154,7 +154,7 @@ impl FromAttributes for ValidateAttribute { let res = accumulator.handle(result); - accumulator.finish().map(|_| res.unwrap()) + accumulator.finish().map(|()| res.unwrap()) } } diff --git a/smart_contract/src/lib.rs b/smart_contract/src/lib.rs index 2bdd93706db..db86863330d 100644 --- a/smart_contract/src/lib.rs +++ b/smart_contract/src/lib.rs @@ -351,7 +351,7 @@ impl> Iterator for QueryOutputCursorIterator { let mut next_iter = match self.next_batch() { Ok(next_iter) => next_iter, Err(QueryOutputCursorError::Validation(ValidationFail::QueryFailed( - iroha_data_model::query::error::QueryExecutionFail::UnknownCursor, + data_model::query::error::QueryExecutionFail::UnknownCursor, ))) => return None, Err(err) => return Some(Err(err)), }; diff --git a/telemetry/src/metrics.rs b/telemetry/src/metrics.rs index 1043cbb9954..ad4f7744750 100644 --- a/telemetry/src/metrics.rs +++ b/telemetry/src/metrics.rs @@ -35,10 +35,10 @@ impl Encode for Uptime { /// Response body for GET status request #[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, Encode)] pub struct Status { - /// Number of connected peers, except for the reporting peer itself + /// Number of currently connected peers excluding the reporting peer #[codec(compact)] pub peers: u64, - /// Number of committed blocks + /// Number of committed blocks (blockchain height) #[codec(compact)] pub blocks: u64, /// Number of accepted transactions @@ -77,9 +77,9 @@ impl> From<&T> for Status { pub struct Metrics { /// Total number of transactions pub txs: IntCounterVec, - /// Current block height + /// Number of committed blocks (blockchain height) pub block_height: IntCounter, - /// Total number of currently connected peers + /// Number of currently connected peers excluding the reporting peer pub connected_peers: GenericGauge, /// Uptime of the network, starting from commit of the genesis block pub uptime_since_genesis_ms: GenericGauge, diff --git a/tools/swarm/src/compose.rs b/tools/swarm/src/compose.rs index e08ab109e91..36c43317750 100644 --- a/tools/swarm/src/compose.rs +++ b/tools/swarm/src/compose.rs @@ -215,7 +215,8 @@ struct FullPeerEnv { iroha_genesis_account_public_key: Option, #[serde(skip_serializing_if = "Option::is_none")] iroha_genesis_account_private_key: Option>, - sumeragi_trusted_peers: SerializeAsJsonStr>, + #[serde(skip_serializing_if = "Option::is_none")] + sumeragi_trusted_peers: Option>>, } struct CompactPeerEnv { @@ -237,7 +238,11 @@ impl From for FullPeerEnv { iroha_genesis_account_private_key: value.genesis_private_key.map(SerializeAsJsonStr), torii_p2p_addr: value.p2p_addr, torii_api_url: value.api_addr, - sumeragi_trusted_peers: SerializeAsJsonStr(value.trusted_peers), + sumeragi_trusted_peers: if value.trusted_peers.is_empty() { + None + } else { + Some(SerializeAsJsonStr(value.trusted_peers)) + }, } } } @@ -311,7 +316,11 @@ impl DockerComposeBuilder<'_> { peer, service_source.clone(), volumes.clone(), - trusted_peers.clone(), + trusted_peers + .iter() + .filter(|trusted_peer| trusted_peer.public_key() != peer.key_pair.public_key()) + .cloned() + .collect(), Some(genesis_key_pair.public_key().clone()), Some(genesis_key_pair.private_key().clone()), ); @@ -325,7 +334,13 @@ impl DockerComposeBuilder<'_> { peer, service_source.clone(), volumes.clone(), - trusted_peers.clone(), + trusted_peers + .iter() + .filter(|trusted_peer| { + trusted_peer.public_key() != peer.key_pair.public_key() + }) + .cloned() + .collect(), Some(genesis_key_pair.public_key().clone()), None, ); @@ -615,7 +630,6 @@ mod tests { TORII_API_URL: iroha1:1338 IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: ed012039E5BF092186FACC358770792A493CA98A83740643A3D41389483CF334F748C8 IROHA_GENESIS_ACCOUNT_PRIVATE_KEY: '{"digest_function":"ed25519","payload":"db9d90d20f969177bd5882f9fe211d14d1399d5440d04e3468783d169bbc4a8e39e5bf092186facc358770792a493ca98a83740643a3d41389483cf334f748c8"}' - SUMERAGI_TRUSTED_PEERS: '[]' ports: - 1337:1337 - 8080:8080 @@ -651,7 +665,6 @@ mod tests { TORII_P2P_ADDR: iroha0:1337 TORII_API_URL: iroha0:1337 IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: ed0120415388A90FA238196737746A70565D041CFB32EAA0C89FF8CB244C7F832A6EBD - SUMERAGI_TRUSTED_PEERS: '[]' "#]]; expected.assert_eq(&actual); } @@ -691,7 +704,7 @@ mod tests { TORII_API_URL: iroha0:8080 IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: ed01203420F48A9EEB12513B8EB7DAF71979CE80A1013F5F341C10DCDA4F6AA19F97A9 IROHA_GENESIS_ACCOUNT_PRIVATE_KEY: '{"digest_function":"ed25519","payload":"5a6d5f06a90d29ad906e2f6ea8b41b4ef187849d0d397081a4a15ffcbe71e7c73420f48a9eeb12513b8eb7daf71979ce80a1013f5f341c10dcda4f6aa19f97a9"}' - SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha2:1339","public_key":"ed0120312C1B7B5DE23D366ADCF23CD6DB92CE18B2AA283C7D9F5033B969C2DC2B92F4"},{"address":"iroha3:1340","public_key":"ed0120854457B2E3D6082181DA73DC01C1E6F93A72D0C45268DC8845755287E98A5DEE"},{"address":"iroha1:1338","public_key":"ed0120A88554AA5C86D28D0EEBEC497235664433E807881CD31E12A1AF6C4D8B0F026C"},{"address":"iroha0:1337","public_key":"ed0120F0321EB4139163C35F88BF78520FF7071499D7F4E79854550028A196C7B49E13"}]' + SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha2:1339","public_key":"ed0120312C1B7B5DE23D366ADCF23CD6DB92CE18B2AA283C7D9F5033B969C2DC2B92F4"},{"address":"iroha3:1340","public_key":"ed0120854457B2E3D6082181DA73DC01C1E6F93A72D0C45268DC8845755287E98A5DEE"},{"address":"iroha1:1338","public_key":"ed0120A88554AA5C86D28D0EEBEC497235664433E807881CD31E12A1AF6C4D8B0F026C"}]' ports: - 1337:1337 - 8080:8080 @@ -708,7 +721,7 @@ mod tests { TORII_P2P_ADDR: iroha1:1338 TORII_API_URL: iroha1:8081 IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: ed01203420F48A9EEB12513B8EB7DAF71979CE80A1013F5F341C10DCDA4F6AA19F97A9 - SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha2:1339","public_key":"ed0120312C1B7B5DE23D366ADCF23CD6DB92CE18B2AA283C7D9F5033B969C2DC2B92F4"},{"address":"iroha3:1340","public_key":"ed0120854457B2E3D6082181DA73DC01C1E6F93A72D0C45268DC8845755287E98A5DEE"},{"address":"iroha1:1338","public_key":"ed0120A88554AA5C86D28D0EEBEC497235664433E807881CD31E12A1AF6C4D8B0F026C"},{"address":"iroha0:1337","public_key":"ed0120F0321EB4139163C35F88BF78520FF7071499D7F4E79854550028A196C7B49E13"}]' + SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha2:1339","public_key":"ed0120312C1B7B5DE23D366ADCF23CD6DB92CE18B2AA283C7D9F5033B969C2DC2B92F4"},{"address":"iroha3:1340","public_key":"ed0120854457B2E3D6082181DA73DC01C1E6F93A72D0C45268DC8845755287E98A5DEE"},{"address":"iroha0:1337","public_key":"ed0120F0321EB4139163C35F88BF78520FF7071499D7F4E79854550028A196C7B49E13"}]' ports: - 1338:1338 - 8081:8081 @@ -724,7 +737,7 @@ mod tests { TORII_P2P_ADDR: iroha2:1339 TORII_API_URL: iroha2:8082 IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: ed01203420F48A9EEB12513B8EB7DAF71979CE80A1013F5F341C10DCDA4F6AA19F97A9 - SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha2:1339","public_key":"ed0120312C1B7B5DE23D366ADCF23CD6DB92CE18B2AA283C7D9F5033B969C2DC2B92F4"},{"address":"iroha3:1340","public_key":"ed0120854457B2E3D6082181DA73DC01C1E6F93A72D0C45268DC8845755287E98A5DEE"},{"address":"iroha1:1338","public_key":"ed0120A88554AA5C86D28D0EEBEC497235664433E807881CD31E12A1AF6C4D8B0F026C"},{"address":"iroha0:1337","public_key":"ed0120F0321EB4139163C35F88BF78520FF7071499D7F4E79854550028A196C7B49E13"}]' + SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha3:1340","public_key":"ed0120854457B2E3D6082181DA73DC01C1E6F93A72D0C45268DC8845755287E98A5DEE"},{"address":"iroha1:1338","public_key":"ed0120A88554AA5C86D28D0EEBEC497235664433E807881CD31E12A1AF6C4D8B0F026C"},{"address":"iroha0:1337","public_key":"ed0120F0321EB4139163C35F88BF78520FF7071499D7F4E79854550028A196C7B49E13"}]' ports: - 1339:1339 - 8082:8082 @@ -740,7 +753,7 @@ mod tests { TORII_P2P_ADDR: iroha3:1340 TORII_API_URL: iroha3:8083 IROHA_GENESIS_ACCOUNT_PUBLIC_KEY: ed01203420F48A9EEB12513B8EB7DAF71979CE80A1013F5F341C10DCDA4F6AA19F97A9 - SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha2:1339","public_key":"ed0120312C1B7B5DE23D366ADCF23CD6DB92CE18B2AA283C7D9F5033B969C2DC2B92F4"},{"address":"iroha3:1340","public_key":"ed0120854457B2E3D6082181DA73DC01C1E6F93A72D0C45268DC8845755287E98A5DEE"},{"address":"iroha1:1338","public_key":"ed0120A88554AA5C86D28D0EEBEC497235664433E807881CD31E12A1AF6C4D8B0F026C"},{"address":"iroha0:1337","public_key":"ed0120F0321EB4139163C35F88BF78520FF7071499D7F4E79854550028A196C7B49E13"}]' + SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha2:1339","public_key":"ed0120312C1B7B5DE23D366ADCF23CD6DB92CE18B2AA283C7D9F5033B969C2DC2B92F4"},{"address":"iroha1:1338","public_key":"ed0120A88554AA5C86D28D0EEBEC497235664433E807881CD31E12A1AF6C4D8B0F026C"},{"address":"iroha0:1337","public_key":"ed0120F0321EB4139163C35F88BF78520FF7071499D7F4E79854550028A196C7B49E13"}]' ports: - 1340:1340 - 8083:8083