diff --git a/client/tests/tests/mod.rs b/client/tests/tests/mod.rs index d801bbde22e..7f916835741 100644 --- a/client/tests/tests/mod.rs +++ b/client/tests/tests/mod.rs @@ -11,7 +11,6 @@ mod offline_peers; mod pagination; mod permissions; mod restart_peer; -mod status; mod transfer_asset; mod tx_history; mod tx_rollback; diff --git a/client/tests/tests/status.rs b/client/tests/tests/status.rs deleted file mode 100644 index 1f8f0c29ff6..00000000000 --- a/client/tests/tests/status.rs +++ /dev/null @@ -1,92 +0,0 @@ -#![allow(clippy::pedantic, clippy::restriction)] - -use std::thread; - -use iroha_client::client::Client; -use iroha_core::config::Configuration; -use iroha_crypto::KeyPair; -use iroha_data_model::prelude::*; -use test_network::{Network as TestNetwork, TestConfiguration}; - -fn ready_for_mint(client: &mut Client) -> MintBox { - let create_domain = RegisterBox::new(IdentifiableBox::Domain(Domain::new("domain").into())); - let account_id = AccountId::new("account", "domain"); - let create_account = RegisterBox::new(IdentifiableBox::NewAccount( - NewAccount::with_signatory( - account_id.clone(), - KeyPair::generate() - .expect("Failed to generate KeyPair.") - .public_key, - ) - .into(), - )); - let asset_definition_id = AssetDefinitionId::new("asset", "domain"); - let create_asset = RegisterBox::new(IdentifiableBox::AssetDefinition( - AssetDefinition::new_quantity(asset_definition_id.clone()).into(), - )); - - client - .submit_all(vec![ - create_domain.into(), - create_account.into(), - create_asset.into(), - ]) - .expect("Failed to prepare state."); - - MintBox::new( - Value::U32(1), - IdBox::AssetId(AssetId::new(asset_definition_id, account_id)), - ) -} - -#[test] -fn connected_peers() { - const N_PEERS: u64 = 4; - let mut n_peers; - - let (rt, network, mut client) = ::start_test_with_runtime(N_PEERS as u32, 1); - client.status_url.insert_str(0, "http://"); - let pipeline_time = Configuration::pipeline_time(); - - // Confirm all peers connected - n_peers = client.get_status().unwrap().peers; - assert_eq!(n_peers, N_PEERS - 1); - - // Add a peer then #peers should be incremented - let (mut peer, _) = rt.block_on(network.add_peer()); - n_peers = client.get_status().unwrap().peers; - assert_eq!(n_peers, N_PEERS); - - // Drop the peer then #peers should be decremented - peer.stop(); - thread::sleep(pipeline_time * 5); - n_peers = client.get_status().unwrap().peers; - // FIXME 'assertion failed: `(left == right)` left: `4`, right: `3`' - assert_eq!(n_peers, N_PEERS - 1); -} - -#[test] -fn committed_blocks() { - const N_BLOCKS: u64 = 10; - const MAX_TXS_IN_BLOCK: u32 = 1; - - let (_, _, mut client) = ::start_test_with_runtime(4, MAX_TXS_IN_BLOCK); - client.status_url.insert_str(0, "http://"); - let pipeline_time = Configuration::pipeline_time(); - thread::sleep(pipeline_time * 2); - - // Confirm only the genesis block committed - assert_eq!(client.get_status().unwrap().blocks, 1); - - // Send transactions then #blocks should be increased - // FIXME Not sending message to myself - let mint = ready_for_mint(&mut client); - thread::sleep(pipeline_time); - let n_txs = N_BLOCKS * MAX_TXS_IN_BLOCK as u64; - for _ in 0..n_txs { - client.submit(mint.clone()).unwrap(); - thread::sleep(pipeline_time / 4); - } - thread::sleep(pipeline_time * 5); - assert_eq!(client.get_status().unwrap().blocks, 1 + N_BLOCKS) -} diff --git a/core/src/lib.rs b/core/src/lib.rs index a6d7e13d052..89c46222e3f 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -246,7 +246,6 @@ where Arc::clone(&queue), query_validator, events_sender, - network_addr.clone(), ); let torii = Some(torii); Ok(Self { diff --git a/core/src/torii/mod.rs b/core/src/torii/mod.rs index 318fe819dbc..4621b25020b 100644 --- a/core/src/torii/mod.rs +++ b/core/src/torii/mod.rs @@ -29,7 +29,7 @@ use crate::{ permissions::IsQueryAllowedBoxed, }, wsv::WorldTrait, - Addr, Configuration, IrohaNetwork, + Configuration, }; /// Main network handler and the only entrypoint of the Iroha. @@ -39,7 +39,6 @@ pub struct Torii { events: EventsSender, query_validator: Arc>, queue: Arc, - network: Addr, } /// Torii errors. @@ -72,8 +71,8 @@ pub enum Error { /// Failed to push into queue. #[error("Failed to push into queue")] PushIntoQueue(#[source] Box), - /// Error while getting or setting configuration - #[error("Failed to get network status")] + /// Error while getting status + #[error("Failed to get status")] Status(#[source] iroha_actor::Error), } @@ -129,7 +128,6 @@ impl Torii { queue: Arc, query_validator: Arc>, events: EventsSender, - network: Addr, ) -> Self { Self { iroha_cfg, @@ -137,7 +135,6 @@ impl Torii { events, query_validator, queue, - network, } } @@ -147,14 +144,12 @@ impl Torii { let queue = Arc::clone(&self.queue); let iroha_cfg = self.iroha_cfg.clone(); let query_validator = Arc::clone(&self.query_validator); - let network = self.network.clone(); Arc::new(InnerToriiState { iroha_cfg, wsv, queue, query_validator, - network, }) } @@ -282,7 +277,6 @@ struct InnerToriiState { wsv: Arc>, queue: Arc, query_validator: Arc>, - network: Addr, } type ToriiState = Arc>; @@ -408,16 +402,9 @@ async fn handle_subscription(events: EventsSender, stream: WebSocket) -> eyre::R Ok(()) } +#[allow(clippy::unused_async)] async fn handle_status(state: ToriiState) -> Result { - let peers = state - .network - .send(iroha_p2p::network::GetConnectedPeers) - .await - .map_err(Error::Status)? - .peers - .len() as u64; let status = Status { - peers, blocks: state.wsv.height(), }; Ok(reply::json(&status)) @@ -445,7 +432,7 @@ pub mod uri { pub const STATUS: &str = "status"; // TODO /// Metrics URI is used to export metrics according to [Prometheus // /// Guidance](https://prometheus.io/docs/instrumenting/writing_exporters/). - // pub const METRICS: &str = "/metrics"; + // pub const METRICS: &str = "metrics"; } /// This module contains all configuration related logic. @@ -457,13 +444,13 @@ pub mod config { pub const DEFAULT_TORII_P2P_ADDR: &str = "127.0.0.1:1337"; /// Default socket for listening on external requests pub const DEFAULT_TORII_API_URL: &str = "127.0.0.1:8080"; - /// Default socket for reporting internal metrics + /// Default socket for reporting internal status pub const DEFAULT_TORII_STATUS_URL: &str = "127.0.0.1:8180"; /// Default maximum size of single transaction pub const DEFAULT_TORII_MAX_TRANSACTION_SIZE: usize = 2_usize.pow(15); /// Default maximum instruction number pub const DEFAULT_TORII_MAX_INSTRUCTION_NUMBER: u64 = 2_u64.pow(12); - /// Default maximum size of [`Sumeragi`] message size + /// Default maximum [`Sumeragi`] message size pub const DEFAULT_TORII_MAX_SUMERAGI_MESSAGE_SIZE: usize = 2_usize.pow(12) * 4000; /// `ToriiConfiguration` provides an ability to define parameters such as `TORII_URL`. @@ -507,7 +494,6 @@ mod tests { use std::{convert::TryInto, time::Duration}; use futures::future::FutureExt; - use iroha_actor::{broker::Broker, Actor}; use tokio::time; use super::*; @@ -518,6 +504,7 @@ mod tests { wsv::World, }; + #[allow(clippy::unused_async)] async fn create_torii() -> (Torii, KeyPair) { let config = get_config(get_trusted_peers(None), None); let (events, _) = tokio::sync::broadcast::channel(100); @@ -539,26 +526,9 @@ mod tests { ), ); let queue = Arc::new(Queue::from_configuration(&config.queue)); - let network = IrohaNetwork::new( - Broker::new(), - config.torii.p2p_addr.clone(), - config.public_key.clone(), - config.network.mailbox, - ) - .await - .expect("Failed to create network") - .start() - .await; ( - Torii::from_configuration( - config, - wsv, - queue, - Arc::new(AllowAll.into()), - events, - network, - ), + Torii::from_configuration(config, wsv, queue, Arc::new(AllowAll.into()), events), keys, ) } @@ -979,7 +949,6 @@ mod tests { .await } - // FIXME ? move to client integration tests #[tokio::test] async fn status_committed_block() { use iroha_crypto::HashOf; diff --git a/data_model/src/fixed.rs b/data_model/src/fixed.rs index 8b5b966cce1..a4d86aa93c0 100644 --- a/data_model/src/fixed.rs +++ b/data_model/src/fixed.rs @@ -28,7 +28,9 @@ pub type FixNum = FixedPoint; /// An encapsulation of [`Fixed`] in encodable form. [`Fixed`] values /// should never become negative. -#[derive(Clone, Copy, Debug, Serialize, Deserialize, IntoSchema, PartialEq, Ord, PartialOrd, Eq)] +#[derive( + Clone, Copy, Debug, Serialize, Deserialize, IntoSchema, PartialEq, Ord, PartialOrd, Eq, +)] pub struct Fixed(FixNum); impl Fixed { diff --git a/data_model/src/lib.rs b/data_model/src/lib.rs index 2c02bb51c42..31959384405 100644 --- a/data_model/src/lib.rs +++ b/data_model/src/lib.rs @@ -382,11 +382,9 @@ pub fn current_time() -> Duration { .expect("Failed to get the current system time") } -/// Response body for get status request +/// Response body for GET status request #[derive(Clone, Copy, Debug, Default, Deserialize, Serialize)] pub struct Status { - /// Number of connected peers, except for the reporting peer itself - pub peers: u64, /// Number of committed blocks pub blocks: u64, } diff --git a/docs/source/references/api_spec.md b/docs/source/references/api_spec.md index 25738519d06..c9d285869e6 100644 --- a/docs/source/references/api_spec.md +++ b/docs/source/references/api_spec.md @@ -166,11 +166,9 @@ Also returns current status of peer in json string: **Responses**: - 200 OK - reports status: - + Number of connected peers, except for the reporting peer itself + Number of committed blocks ```json { - "peers": 3, "blocks": 1 } ```