Skip to content

Commit

Permalink
[cleanup] Remove some unused code (#12231)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyan-gupta authored Oct 16, 2024
1 parent 778b173 commit da5bbca
Show file tree
Hide file tree
Showing 12 changed files with 0 additions and 130 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion chain/chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions chain/chain/src/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion chain/client-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 0 additions & 51 deletions chain/client-primitives/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -197,55 +195,6 @@ impl ShardSyncDownload {
}
}

pub fn format_shard_sync_phase_per_shard(
new_shard_sync: &HashMap<ShardId, ShardSyncDownload>,
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::<Vec<(_, _)>>()
}

/// 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,
Expand Down
21 changes: 0 additions & 21 deletions chain/network/src/concurrency/scope/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,27 +228,6 @@ impl<E: 'static> Drop for Service<E> {
}

impl<E: 'static + Send> Service<E> {
/// 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<Output = ctx::OrCanceled<()>> + 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,
Expand Down
4 changes: 0 additions & 4 deletions chain/network/src/network_protocol/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u16> {
self.addr.map(|addr| addr.port())
}
}

// Note, `Display` automatically implements `ToString` which must be reciprocal to `FromStr`.
Expand Down
15 changes: 0 additions & 15 deletions chain/network/src/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@ impl<T> Sink<T> {
}
}

impl<T: Send + 'static> Sink<T> {
// 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<dyn Send + 'static + FnOnce()> {
let maybe_ev = self.0.as_ref().map(|_| make());
let this = self.clone();
Box::new(move || {
maybe_ev.map(|ev| this.push(ev));
})
}
}

impl<T: 'static + std::fmt::Debug + Send> Sink<T> {
pub fn compose<U>(&self, f: impl Send + Sync + 'static + Fn(U) -> T) -> Sink<U> {
match self.0.clone() {
Expand Down
8 changes: 0 additions & 8 deletions core/o11y/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions core/primitives/src/state_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 0 additions & 6 deletions core/primitives/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ impl<T> MaybeValidated<T> {
}
}

/// 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.
Expand Down
10 changes: 0 additions & 10 deletions core/store/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
match self {
Self::ReadOnly | Self::ReadWriteExisting => Some(self),
Self::ReadWrite => Some(Self::ReadWriteExisting),
Self::Create => None,
}
}
}

impl StoreConfig {
Expand Down

0 comments on commit da5bbca

Please sign in to comment.