Skip to content

Commit

Permalink
chore: more clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Dec 2, 2024
1 parent 2f4a3a3 commit dd3f92d
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 252 deletions.
5 changes: 0 additions & 5 deletions src/server/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,26 @@ pub enum Error {
pub struct HttpServer {
stats_client: StatsClient,
port: u16,
squad: Squad,
p2p_service_client: Sender<P2pServiceQuery>,
shutdown_signal: ShutdownSignal,
}

#[derive(Clone)]
pub(crate) struct AppState {
pub stats_client: StatsClient,
pub squad: Squad,
pub p2p_service_client: Sender<P2pServiceQuery>,
}

impl HttpServer {
pub fn new(
stats_client: StatsClient,
port: u16,
squad: Squad,
p2p_service_client: Sender<P2pServiceQuery>,
shutdown_signal: ShutdownSignal,
) -> Self {
Self {
stats_client,
port,
squad,
p2p_service_client,
shutdown_signal,
}
Expand All @@ -80,7 +76,6 @@ impl HttpServer {
.route("/connections", get(handlers::handle_connections))
.with_state(AppState {
stats_client: self.stats_client.clone(),
squad: self.squad.clone(),
p2p_service_client: self.p2p_service_client.clone(),
})
}
Expand Down
5 changes: 0 additions & 5 deletions src/server/http/stats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@

use tari_core::proof_of_work::PowAlgorithm;

/// Returns a stat key with the provided PoW algorithm.
pub fn algo_stat_key(algo: PowAlgorithm, stat_key: &str) -> String {
format!("{}_{}", algo.to_string().to_lowercase(), stat_key)
}

pub mod handlers;
pub mod models;

Expand Down
48 changes: 0 additions & 48 deletions src/server/http/stats/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,59 +32,11 @@ impl From<Arc<P2Block>> for StatsBlock {
}
}

#[derive(Serialize, Deserialize, Clone)]
pub struct EstimatedEarnings {
#[serde(rename = "1min")]
pub one_minute: MicroMinotari,
#[serde(rename = "1h")]
pub one_hour: MicroMinotari,
#[serde(rename = "1d")]
pub one_day: MicroMinotari,
#[serde(rename = "1w")]
pub one_week: MicroMinotari,
#[serde(rename = "30d")]
pub one_month: MicroMinotari,
}

impl EstimatedEarnings {
pub fn new(one_minute_earning: MicroMinotari) -> Self {
Self {
one_minute: one_minute_earning,
one_hour: MicroMinotari::from(one_minute_earning.as_u64() * 60),
one_day: MicroMinotari::from(one_minute_earning.as_u64() * 60 * 24),
one_week: MicroMinotari::from(one_minute_earning.as_u64() * 60 * 24 * 7),
one_month: MicroMinotari::from(one_minute_earning.as_u64() * 60 * 24 * 30),
}
}
}

#[derive(Serialize, Deserialize, Clone)]
pub struct BlockStats {
pub accepted: u64,
pub rejected: u64,
pub submitted: u64,
}

impl BlockStats {
pub fn new(accepted: u64, rejected: u64) -> Self {
Self {
accepted,
rejected,
submitted: accepted + rejected,
}
}
}

#[derive(Serialize, Deserialize, Clone)]
pub struct SquadDetails {
pub id: String,
pub name: String,
}
impl SquadDetails {
pub fn new(id: String, name: String) -> Self {
Self { id, name }
}
}

#[derive(Serialize, Clone)]
pub struct Stats {
Expand Down
71 changes: 31 additions & 40 deletions src/server/http/stats_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ pub(crate) struct StatsCollector {
request_tx: tokio::sync::mpsc::Sender<StatsRequest>,
request_rx: tokio::sync::mpsc::Receiver<StatsRequest>,
first_stat_received: Option<EpochTime>,
miner_accepted: u64,
miner_rejected: u64,
pool_accepted: u64,
pool_rejected: u64,
miner_rx_accepted: u64,
miner_sha_accepted: u64,
// miner_rejected: u64,
pool_rx_accepted: u64,
pool_sha_accepted: u64,
// pool_rejected: u64,
sha_network_difficulty: Difficulty,
sha_target_difficulty: Difficulty,
randomx_network_difficulty: Difficulty,
Expand Down Expand Up @@ -49,10 +51,12 @@ impl StatsCollector {
request_rx: rx,
request_tx: tx,
first_stat_received: None,
miner_accepted: 0,
miner_rejected: 0,
pool_accepted: 0,
pool_rejected: 0,
miner_rx_accepted: 0,
miner_sha_accepted: 0,
// miner_rejected: 0,
pool_rx_accepted: 0,
pool_sha_accepted: 0,
// pool_rejected: 0,
sha3x_chain_height: 0,
sha3x_chain_length: 0,
randomx_chain_height: 0,
Expand Down Expand Up @@ -80,17 +84,21 @@ impl StatsCollector {

fn handle_stat(&mut self, sample: StatData) {
match sample {
StatData::MinerBlockAccepted { .. } => {
self.miner_accepted += 1;
},
StatData::MinerBlockRejected { .. } => {
self.miner_rejected += 1;
},
StatData::PoolBlockAccepted { .. } => {
self.pool_accepted += 1;
StatData::MinerBlockAccepted { pow_algo, .. } => match pow_algo {
PowAlgorithm::Sha3x => {
self.miner_sha_accepted += 1;
},
PowAlgorithm::RandomX => {
self.miner_rx_accepted += 1;
},
},
StatData::PoolBlockRejected { .. } => {
self.pool_rejected += 1;
StatData::PoolBlockAccepted { pow_algo, .. } => match pow_algo {
PowAlgorithm::Sha3x => {
self.pool_sha_accepted += 1;
},
PowAlgorithm::RandomX => {
self.pool_rx_accepted += 1;
},
},
StatData::ChainChanged {
algo, height, length, ..
Expand Down Expand Up @@ -172,7 +180,7 @@ impl StatsCollector {
let formatter = Formatter::new();

info!(target: LOG_TARGET,
"========= Uptime: {}. v{} Chains: Rx {}..{}, Sha3 {}..{}. Difficulty (Target/Network): Rx: {}/{} Sha3x: {}/{} Miner(A/R): {}/{}. Pool(A/R) {}/{}. Peers(a/g/b) {}/{}/{} libp2p (i/o) {}/{} Last gossip: {}==== ",
"========= Uptime: {}. v{} Chains: Rx {}..{}, Sha3 {}..{}. Difficulty (Target/Network): Rx: {}/{} Sha3x: {}/{} Miner accepts(rx/sha): {}/{}. Pool accepts (rx/sha) {}/{}. Peers(a/g/b) {}/{}/{} libp2p (i/o) {}/{} Last gossip: {}==== ",
humantime::format_duration(Duration::from_secs(
EpochTime::now().as_u64().checked_sub(
self.first_stat_received.unwrap_or(EpochTime::now()).as_u64())
Expand All @@ -186,10 +194,10 @@ impl StatsCollector {
formatter.format( self.randomx_network_difficulty.as_u64() as f64),
formatter.format(self.sha_target_difficulty.as_u64() as f64),
formatter.format(self.sha_network_difficulty.as_u64() as f64),
self.miner_accepted,
self.miner_rejected,
self.pool_accepted,
self.pool_rejected,
self.miner_rx_accepted,
self.miner_sha_accepted,
self.pool_rx_accepted,
self.pool_sha_accepted,
self.total_peers,
self.total_grey_list,
self.total_black_list,
Expand Down Expand Up @@ -270,13 +278,6 @@ pub(crate) struct GetStatsResponse {
total_shares: u64,
}

#[derive(Clone)]
pub(crate) struct ChainStats {
pow_algo: PowAlgorithm,
height: u64,
length: u64,
}

#[derive(Clone)]
pub(crate) enum StatData {
TargetDifficultyChanged {
Expand All @@ -293,18 +294,10 @@ pub(crate) enum StatData {
pow_algo: PowAlgorithm,
timestamp: EpochTime,
},
MinerBlockRejected {
pow_algo: PowAlgorithm,
timestamp: EpochTime,
},
PoolBlockAccepted {
pow_algo: PowAlgorithm,
timestamp: EpochTime,
},
PoolBlockRejected {
pow_algo: PowAlgorithm,
timestamp: EpochTime,
},
ChainChanged {
algo: PowAlgorithm,
height: u64,
Expand Down Expand Up @@ -333,9 +326,7 @@ impl StatData {
pub fn timestamp(&self) -> EpochTime {
match self {
StatData::MinerBlockAccepted { timestamp, .. } => *timestamp,
StatData::MinerBlockRejected { timestamp, .. } => *timestamp,
StatData::PoolBlockAccepted { timestamp, .. } => *timestamp,
StatData::PoolBlockRejected { timestamp, .. } => *timestamp,
StatData::ChainChanged { timestamp, .. } => *timestamp,
StatData::NewPeer { timestamp, .. } => *timestamp,
StatData::TargetDifficultyChanged { timestamp, .. } => *timestamp,
Expand Down
121 changes: 0 additions & 121 deletions src/server/p2p/global_ip.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/server/p2p/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
pub use network::*;

pub mod client;
mod global_ip;
pub mod messages;
mod network;
pub mod peer_store;
Expand Down
12 changes: 3 additions & 9 deletions src/server/p2p/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ pub struct Squad {
inner: String,
}

impl Squad {
pub fn to_string(&self) -> String {
self.inner.clone()
impl Display for Squad {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", &self.inner)
}
}

Expand All @@ -146,12 +146,6 @@ impl From<String> for Squad {
}
}

impl Display for Squad {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.inner.clone())
}
}

#[derive(Clone, Debug)]
pub(crate) struct Config {
pub external_addr: Option<String>,
Expand Down
Loading

0 comments on commit dd3f92d

Please sign in to comment.