From da5bbca668dd3348497825e58cb8fc08eb4bcbf4 Mon Sep 17 00:00:00 2001 From: Shreyan Gupta Date: Wed, 16 Oct 2024 12:49:23 +0100 Subject: [PATCH] [cleanup] Remove some unused code (#12231) --- Cargo.lock | 2 - chain/chain/Cargo.toml | 1 - chain/chain/src/orphan.rs | 6 --- chain/client-primitives/Cargo.toml | 1 - chain/client-primitives/src/types.rs | 51 ---------------------- chain/network/src/concurrency/scope/mod.rs | 21 --------- chain/network/src/network_protocol/peer.rs | 4 -- chain/network/src/sink.rs | 15 ------- core/o11y/src/lib.rs | 8 ---- core/primitives/src/state_sync.rs | 5 --- core/primitives/src/utils.rs | 6 --- core/store/src/config.rs | 10 ----- 12 files changed, 130 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 884068d3495..d1886e9972f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4035,7 +4035,6 @@ dependencies = [ "thiserror", "time", "tracing", - "yansi", ] [[package]] @@ -4193,7 +4192,6 @@ dependencies = [ "thiserror", "time", "tracing", - "yansi", ] [[package]] diff --git a/chain/chain/Cargo.toml b/chain/chain/Cargo.toml index f7968f417a6..51df850215b 100644 --- a/chain/chain/Cargo.toml +++ b/chain/chain/Cargo.toml @@ -31,7 +31,6 @@ tempfile.workspace = true thiserror.workspace = true time.workspace = true tracing.workspace = true -yansi.workspace = true near-async.workspace = true near-cache.workspace = true diff --git a/chain/chain/src/orphan.rs b/chain/chain/src/orphan.rs index f503f6b6c07..dec76709dd8 100644 --- a/chain/chain/src/orphan.rs +++ b/chain/chain/src/orphan.rs @@ -415,12 +415,6 @@ impl Chain { self.orphans.len() } - /// Returns number of evicted orphans. - #[inline] - pub fn orphans_evicted_len(&self) -> usize { - self.orphans.len_evicted() - } - /// Check if hash is for a known orphan. #[inline] pub fn is_orphan(&self, hash: &CryptoHash) -> bool { diff --git a/chain/client-primitives/Cargo.toml b/chain/client-primitives/Cargo.toml index d2ad45f7b5a..23b1daa0c45 100644 --- a/chain/client-primitives/Cargo.toml +++ b/chain/client-primitives/Cargo.toml @@ -20,7 +20,6 @@ strum.workspace = true thiserror.workspace = true time.workspace = true tracing.workspace = true -yansi.workspace = true near-time.workspace = true near-chain-primitives.workspace = true diff --git a/chain/client-primitives/src/types.rs b/chain/client-primitives/src/types.rs index d618690b1e7..53bc901f437 100644 --- a/chain/client-primitives/src/types.rs +++ b/chain/client-primitives/src/types.rs @@ -22,8 +22,6 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use time::{Duration, OffsetDateTime as Utc}; use tracing::debug_span; -use yansi::Color::Magenta; -use yansi::Style; /// Combines errors coming from chain, tx pool and block producer. #[derive(Debug, thiserror::Error)] @@ -197,55 +195,6 @@ impl ShardSyncDownload { } } -pub fn format_shard_sync_phase_per_shard( - new_shard_sync: &HashMap, - use_colour: bool, -) -> Vec<(ShardId, String)> { - new_shard_sync - .iter() - .map(|(&shard_id, shard_progress)| { - (shard_id, format_shard_sync_phase(shard_progress, use_colour)) - }) - .collect::>() -} - -/// Applies style if `use_colour` is enabled. -fn paint(s: &str, style: Style, use_style: bool) -> String { - if use_style { - style.paint(s).to_string() - } else { - s.to_string() - } -} - -/// Formats the given ShardSyncDownload for logging. -pub fn format_shard_sync_phase( - shard_sync_download: &ShardSyncDownload, - use_colour: bool, -) -> String { - match &shard_sync_download.status { - ShardSyncStatus::StateDownloadHeader => format!( - "{} requests sent {}, last target {:?}", - paint("HEADER", Magenta.style().bold(), use_colour), - shard_sync_download.downloads.get(0).map_or(0, |x| x.state_requests_count), - shard_sync_download.downloads.get(0).map_or(None, |x| x.last_target.as_ref()), - ), - ShardSyncStatus::StateDownloadParts => { - let mut num_parts_done = 0; - let mut num_parts_not_done = 0; - for download in shard_sync_download.downloads.iter() { - if download.done { - num_parts_done += 1; - } else { - num_parts_not_done += 1; - } - } - format!("num_parts_done={num_parts_done} num_parts_not_done={num_parts_not_done}") - } - status => format!("{status:?}"), - } -} - #[derive(Clone, Debug)] pub struct StateSyncStatus { pub sync_hash: CryptoHash, diff --git a/chain/network/src/concurrency/scope/mod.rs b/chain/network/src/concurrency/scope/mod.rs index 893e05a50e0..0b5ebfbf30e 100644 --- a/chain/network/src/concurrency/scope/mod.rs +++ b/chain/network/src/concurrency/scope/mod.rs @@ -228,27 +228,6 @@ impl Drop for Service { } impl Service { - /// Checks if the referred scope has been terminated. - pub fn is_terminated(&self) -> bool { - self.0.upgrade().is_none() - } - - /// Waits until the scope is terminated. - /// - /// Returns `ErrCanceled` iff `ctx` was canceled before that. - pub fn terminated<'a>( - &'a self, - ) -> impl Future> + Send + Sync + 'a { - let terminated = self.0.upgrade().map(|inner| inner.terminated.clone()); - async move { - if let Some(t) = terminated { - ctx::wait(t.recv()).await - } else { - Ok(()) - } - } - } - /// Cancels the scope's context and waits until the scope is terminated. /// /// Note that ErrCanceled is returned if the `ctx` passed as argument is canceled before that, diff --git a/chain/network/src/network_protocol/peer.rs b/chain/network/src/network_protocol/peer.rs index 29aaedd6aed..cbf7d232f2f 100644 --- a/chain/network/src/network_protocol/peer.rs +++ b/chain/network/src/network_protocol/peer.rs @@ -37,10 +37,6 @@ impl PeerInfo { pub fn random() -> Self { PeerInfo { id: PeerId::random(), addr: None, account_id: None } } - - pub fn addr_port(&self) -> Option { - self.addr.map(|addr| addr.port()) - } } // Note, `Display` automatically implements `ToString` which must be reciprocal to `FromStr`. diff --git a/chain/network/src/sink.rs b/chain/network/src/sink.rs index 21329e264b8..3d5255fc5bc 100644 --- a/chain/network/src/sink.rs +++ b/chain/network/src/sink.rs @@ -31,21 +31,6 @@ impl Sink { } } -impl Sink { - // Accepts a constructor of the value to push. - // Returns a function which does the push. - // If sink is null it doesn't call make() at all, - // therefore you can use this to skip expensive computation - // in non-test env. - pub fn delayed_push(&self, make: impl FnOnce() -> T) -> Box { - let maybe_ev = self.0.as_ref().map(|_| make()); - let this = self.clone(); - Box::new(move || { - maybe_ev.map(|ev| this.push(ev)); - }) - } -} - impl Sink { pub fn compose(&self, f: impl Send + Sync + 'static + Fn(U) -> T) -> Sink { match self.0.clone() { diff --git a/core/o11y/src/lib.rs b/core/o11y/src/lib.rs index 8bcfbd50931..19dc68bbfbd 100644 --- a/core/o11y/src/lib.rs +++ b/core/o11y/src/lib.rs @@ -40,14 +40,6 @@ macro_rules! io_trace { ($($fields:tt)*) => {}; } -/// Prints backtrace to stderr. -/// -/// This is intended as a printf-debugging aid. -pub fn print_backtrace() { - let bt = std::backtrace::Backtrace::force_capture(); - eprintln!("{bt:?}") -} - /// Asserts that the condition is true, logging an error otherwise. /// /// This macro complements `assert!` and `debug_assert`. All three macros should diff --git a/core/primitives/src/state_sync.rs b/core/primitives/src/state_sync.rs index ceeddf337fb..58f5d24bf94 100644 --- a/core/primitives/src/state_sync.rs +++ b/core/primitives/src/state_sync.rs @@ -65,11 +65,6 @@ impl BitArray { let num_bytes = (capacity + 7) / 8; Self { data: vec![0; num_bytes as usize], capacity } } - - pub fn set_bit(&mut self, bit: u64) { - assert!(bit < self.capacity); - self.data[(bit / 8) as usize] |= 1 << (bit % 8); - } } #[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)] diff --git a/core/primitives/src/utils.rs b/core/primitives/src/utils.rs index 1f91c8cc2a1..ead8ec029e9 100644 --- a/core/primitives/src/utils.rs +++ b/core/primitives/src/utils.rs @@ -112,12 +112,6 @@ impl MaybeValidated { } } - /// Marks the payload as valid. No verification is performed; it’s caller’s - /// responsibility to make sure the payload has indeed been validated. - pub fn mark_as_valid(&self) { - self.validated.set(true); - } - /// Applies function to the payload (whether it’s been validated or not) and /// returns new object with result of the function as payload. Validated /// state is not changed. diff --git a/core/store/src/config.rs b/core/store/src/config.rs index f7c155ab32d..d788dace044 100644 --- a/core/store/src/config.rs +++ b/core/store/src/config.rs @@ -152,16 +152,6 @@ impl Mode { pub const fn must_create(self) -> bool { matches!(self, Mode::Create) } - - /// Returns variant of the mode which prohibits creation of the database or - /// `None` if the mode requires creation of a new database. - pub const fn but_cannot_create(self) -> Option { - match self { - Self::ReadOnly | Self::ReadWriteExisting => Some(self), - Self::ReadWrite => Some(Self::ReadWriteExisting), - Self::Create => None, - } - } } impl StoreConfig {