Skip to content

Commit

Permalink
chore: upgrade tentacle
Browse files Browse the repository at this point in the history
  • Loading branch information
driftluo committed Nov 20, 2024
1 parent f99e0be commit 762d3e1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

27 changes: 2 additions & 25 deletions network/src/services/dump_peer_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ const DEFAULT_DUMP_INTERVAL: Duration = Duration::from_secs(3600); // 1 hour
/// Save current peer store data regularly
pub struct DumpPeerStoreService {
network_state: Arc<NetworkState>,
#[cfg(not(target_family = "wasm"))]
interval: Option<tokio::time::Interval>,
#[cfg(target_family = "wasm")]
interval: Option<p2p::runtime::Interval>,
}

Expand Down Expand Up @@ -57,32 +54,12 @@ impl Drop for DumpPeerStoreService {
impl Future for DumpPeerStoreService {
type Output = ();

#[cfg(not(target_family = "wasm"))]
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if self.interval.is_none() {
self.interval = {
let mut interval = tokio::time::interval_at(
tokio::time::Instant::now() + DEFAULT_DUMP_INTERVAL,
DEFAULT_DUMP_INTERVAL,
);
// The dump peer store service does not need to urgently compensate for the missed wake,
// just delay behavior is enough
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Delay);
Some(interval)
}
}
while self.interval.as_mut().unwrap().poll_tick(cx).is_ready() {
self.dump_peer_store()
}
Poll::Pending
}

#[cfg(target_family = "wasm")]
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
use futures::StreamExt;
if self.interval.is_none() {
self.interval = {
let mut interval = p2p::runtime::Interval::new(DEFAULT_DUMP_INTERVAL);
let mut interval =
p2p::runtime::Interval::new_at(DEFAULT_DUMP_INTERVAL, DEFAULT_DUMP_INTERVAL);
// The outbound service does not need to urgently compensate for the missed wake,
// just skip behavior is enough
interval.set_missed_tick_behavior(p2p::runtime::MissedTickBehavior::Skip);
Expand Down
3 changes: 2 additions & 1 deletion network/src/services/outbound_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ impl Future for OutboundPeerService {
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if self.interval.is_none() {
self.interval = {
let mut interval = Interval::new(self.try_connect_interval);
let mut interval =
Interval::new_at(self.try_connect_interval, self.try_connect_interval);
// The outbound service does not need to urgently compensate for the missed wake,
// just skip behavior is enough
interval.set_missed_tick_behavior(MissedTickBehavior::Skip);
Expand Down
2 changes: 1 addition & 1 deletion network/src/services/protocol_type_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Future for ProtocolTypeCheckerService {
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if self.interval.is_none() {
self.interval = {
let mut interval = Interval::new(CHECK_INTERVAL);
let mut interval = Interval::new_at(CHECK_INTERVAL, CHECK_INTERVAL);
// The protocol type checker service does not need to urgently compensate for the missed wake,
// just skip behavior is enough
interval.set_missed_tick_behavior(MissedTickBehavior::Skip);
Expand Down

0 comments on commit 762d3e1

Please sign in to comment.