Skip to content

Commit

Permalink
Delete things related to the number of connected peers
Browse files Browse the repository at this point in the history
Signed-off-by: s8sato <49983831+s8sato@users.noreply.github.com>
  • Loading branch information
s8sato committed Nov 30, 2021
1 parent 5a6c205 commit b228b41
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 140 deletions.
1 change: 0 additions & 1 deletion client/tests/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
92 changes: 0 additions & 92 deletions client/tests/tests/status.rs

This file was deleted.

1 change: 0 additions & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ where
Arc::clone(&queue),
query_validator,
events_sender,
network_addr.clone(),
);
let torii = Some(torii);
Ok(Self {
Expand Down
49 changes: 9 additions & 40 deletions core/src/torii/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{
permissions::IsQueryAllowedBoxed,
},
wsv::WorldTrait,
Addr, Configuration, IrohaNetwork,
Configuration,
};

/// Main network handler and the only entrypoint of the Iroha.
Expand All @@ -39,7 +39,6 @@ pub struct Torii<W: WorldTrait> {
events: EventsSender,
query_validator: Arc<IsQueryAllowedBoxed<W>>,
queue: Arc<Queue>,
network: Addr<IrohaNetwork>,
}

/// Torii errors.
Expand Down Expand Up @@ -72,8 +71,8 @@ pub enum Error {
/// Failed to push into queue.
#[error("Failed to push into queue")]
PushIntoQueue(#[source] Box<queue::Error>),
/// 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),
}

Expand Down Expand Up @@ -129,15 +128,13 @@ impl<W: WorldTrait> Torii<W> {
queue: Arc<Queue>,
query_validator: Arc<IsQueryAllowedBoxed<W>>,
events: EventsSender,
network: Addr<IrohaNetwork>,
) -> Self {
Self {
iroha_cfg,
wsv,
events,
query_validator,
queue,
network,
}
}

Expand All @@ -147,14 +144,12 @@ impl<W: WorldTrait> Torii<W> {
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,
})
}

Expand Down Expand Up @@ -282,7 +277,6 @@ struct InnerToriiState<W: WorldTrait> {
wsv: Arc<WorldStateView<W>>,
queue: Arc<Queue>,
query_validator: Arc<IsQueryAllowedBoxed<W>>,
network: Addr<IrohaNetwork>,
}

type ToriiState<W> = Arc<InnerToriiState<W>>;
Expand Down Expand Up @@ -408,16 +402,9 @@ async fn handle_subscription(events: EventsSender, stream: WebSocket) -> eyre::R
Ok(())
}

#[allow(clippy::unused_async)]
async fn handle_status<W: WorldTrait>(state: ToriiState<W>) -> Result<Json> {
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))
Expand Down Expand Up @@ -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.
Expand All @@ -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`.
Expand Down Expand Up @@ -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::*;
Expand All @@ -518,6 +504,7 @@ mod tests {
wsv::World,
};

#[allow(clippy::unused_async)]
async fn create_torii() -> (Torii<World>, KeyPair) {
let config = get_config(get_trusted_peers(None), None);
let (events, _) = tokio::sync::broadcast::channel(100);
Expand All @@ -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,
)
}
Expand Down Expand Up @@ -979,7 +949,6 @@ mod tests {
.await
}

// FIXME ? move to client integration tests
#[tokio::test]
async fn status_committed_block() {
use iroha_crypto::HashOf;
Expand Down
4 changes: 3 additions & 1 deletion data_model/src/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ pub type FixNum = FixedPoint<Base, U9>;

/// 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 {
Expand Down
4 changes: 1 addition & 3 deletions data_model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 0 additions & 2 deletions docs/source/references/api_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```
Expand Down

0 comments on commit b228b41

Please sign in to comment.