Skip to content

Commit

Permalink
chore: update based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin committed Dec 6, 2024
1 parent 469e496 commit 7bbccf5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 33 deletions.
2 changes: 1 addition & 1 deletion ant-bootstrap/src/cache_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl BootstrapCacheStore {
Ok(store)
}

/// Create a CacheStore from the given peers argument.
/// Create a empty CacheStore from the given peers argument.
/// This also modifies the cfg if provided based on the PeersArgs.
/// And also performs some actions based on the PeersArgs.
pub fn new_from_peers_args(
Expand Down
7 changes: 2 additions & 5 deletions ant-networking/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,11 +1062,8 @@ impl SwarmDriver {
Self::duration_with_variance(bootstrap_cache.config().max_cache_save_duration, 1);

// scale up the interval until we reach the max
let new_duration = Duration::from_secs(
std::cmp::min(
current_interval.period().as_secs() * bootstrap_cache.config().cache_save_scaling_factor,
max_cache_save_duration.as_secs(),
));
let scaled = current_interval.period().as_secs().saturating_mul(bootstrap_cache.config().cache_save_scaling_factor);
let new_duration = Duration::from_secs(std::cmp::min(scaled, max_cache_save_duration.as_secs()));
info!("Scaling up the bootstrap cache save interval to {new_duration:?}");

// `Interval` ticks immediately for Tokio, but not for `wasmtimer`, which is used for wasm32.
Expand Down
18 changes: 9 additions & 9 deletions ant-networking/src/event/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,18 +515,18 @@ impl SwarmDriver {
}
};

// Just track failures during outgoing connection with `failed_peer_id` inside the bootstrap cache.
// OutgoingConnectionError without peer_id can happen when dialing multiple addresses of a peer.
// And similarly IncomingConnectionError can happen when a peer has multiple transports/listen addrs.
if let (Some((_, failed_addr, _)), Some(bootstrap_cache)) =
(connection_details, self.bootstrap_cache.as_mut())
{
bootstrap_cache.update_addr_status(&failed_addr, false);
}

if should_clean_peer {
warn!("Tracking issue of {failed_peer_id:?}. Clearing it out for now");

// Just track failures during outgoing connection with `failed_peer_id` inside the bootstrap cache.
// OutgoingConnectionError without peer_id can happen when dialing multiple addresses of a peer.
// And similarly IncomingConnectionError can happen when a peer has multiple transports/listen addrs.
if let (Some((_, failed_addr, _)), Some(bootstrap_cache)) =
(connection_details, self.bootstrap_cache.as_mut())
{
bootstrap_cache.update_addr_status(&failed_addr, false);
}

if let Some(dead_peer) = self
.swarm
.behaviour_mut()
Expand Down
2 changes: 2 additions & 0 deletions ant-node/src/bin/antnode/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ fn main() -> Result<()> {
// another process with these args.
#[cfg(feature = "metrics")]
rt.spawn(init_metrics(std::process::id()));
let initial_peres = rt.block_on(opt.peers.get_addrs(None))?;
debug!("Node's owner set to: {:?}", opt.owner);
let restart_options = rt.block_on(async move {
let mut node_builder = NodeBuilder::new(
Expand All @@ -307,6 +308,7 @@ fn main() -> Result<()> {
#[cfg(feature = "upnp")]
opt.upnp,
);
node_builder.initial_peers(initial_peres);
node_builder.bootstrap_cache(bootstrap_cache);
node_builder.is_behind_home_network(opt.home_network);
#[cfg(feature = "open-metrics")]
Expand Down
2 changes: 0 additions & 2 deletions ant-node/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ pub enum Error {
// ---------- Initialize Errors
#[error("Failed to generate a reward key")]
FailedToGenerateRewardKey,
#[error("Cannot set both initial_peers and bootstrap_cache")]
InitialPeersAndBootstrapCacheSet,

// ---------- Miscellaneous Errors
#[error("Failed to obtain node's current port")]
Expand Down
20 changes: 4 additions & 16 deletions ant-node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::{
};
#[cfg(feature = "open-metrics")]
use crate::metrics::NodeMetricsRecorder;
use crate::{error::Error, RunningNode};
use crate::RunningNode;
use ant_bootstrap::BootstrapCacheStore;
use ant_evm::{AttoTokens, RewardsAddress};
#[cfg(feature = "open-metrics")]
Expand Down Expand Up @@ -134,12 +134,12 @@ impl NodeBuilder {
self.metrics_server_port = port;
}

/// Set the initialized bootstrap cache. This is mutually exclusive with `initial_peers`
/// Set the initialized bootstrap cache.
pub fn bootstrap_cache(&mut self, cache: BootstrapCacheStore) {
self.bootstrap_cache = Some(cache);
}

/// Set the initial peers to dial at startup. This is mutually exclusive with `bootstrap_cache`
/// Set the initial peers to dial at startup.
pub fn initial_peers(&mut self, peers: Vec<Multiaddr>) {
self.initial_peers = peers;
}
Expand Down Expand Up @@ -177,18 +177,6 @@ impl NodeBuilder {
None
};

if !self.initial_peers.is_empty() && self.bootstrap_cache.is_some() {
return Err(Error::InitialPeersAndBootstrapCacheSet);
}

let initial_peers = if !self.initial_peers.is_empty() {
self.initial_peers.clone()
} else if let Some(cache) = &self.bootstrap_cache {
cache.get_sorted_addrs().cloned().collect()
} else {
vec![]
};

network_builder.listen_addr(self.addr);
#[cfg(feature = "open-metrics")]
network_builder.metrics_server_port(self.metrics_server_port);
Expand All @@ -207,7 +195,7 @@ impl NodeBuilder {
let node = NodeInner {
network: network.clone(),
events_channel: node_events_channel.clone(),
initial_peers,
initial_peers: self.initial_peers,
reward_address: self.evm_address,
#[cfg(feature = "open-metrics")]
metrics_recorder,
Expand Down

0 comments on commit 7bbccf5

Please sign in to comment.