From bbe9242811b5dc14d991506bc4d076f0ce98b3cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Thu, 30 May 2024 20:18:35 +0100 Subject: [PATCH] replace instant with web-time (#5800) * replace instant with web_time * Merge branch 'unstable' into replace-instant-gossipsub # Conflicts: # Cargo.lock # beacon_node/lighthouse_network/Cargo.toml --- Cargo.lock | 13 +++++++++++-- beacon_node/lighthouse_network/Cargo.toml | 2 -- beacon_node/lighthouse_network/gossipsub/Cargo.toml | 5 ++--- .../lighthouse_network/gossipsub/src/backoff.rs | 2 +- .../lighthouse_network/gossipsub/src/behaviour.rs | 3 +-- .../gossipsub/src/gossip_promises.rs | 2 +- .../lighthouse_network/gossipsub/src/handler.rs | 2 +- .../lighthouse_network/gossipsub/src/peer_score.rs | 2 +- .../lighthouse_network/gossipsub/src/time_cache.rs | 2 +- .../lighthouse_network/gossipsub/src/types.rs | 2 +- 10 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 22ed5178715..a7feed4633a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3376,7 +3376,6 @@ dependencies = [ "futures-timer", "getrandom", "hex_fmt", - "instant", "libp2p", "prometheus-client", "quick-protobuf", @@ -3388,6 +3387,7 @@ dependencies = [ "sha2 0.10.8", "tracing", "void", + "web-time", ] [[package]] @@ -4956,7 +4956,6 @@ dependencies = [ "futures", "gossipsub", "hex", - "instant", "lazy_static", "libp2p", "libp2p-mplex", @@ -9365,6 +9364,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "web3signer_tests" version = "0.1.0" diff --git a/beacon_node/lighthouse_network/Cargo.toml b/beacon_node/lighthouse_network/Cargo.toml index 13baf2e9ce7..b318bd4fb32 100644 --- a/beacon_node/lighthouse_network/Cargo.toml +++ b/beacon_node/lighthouse_network/Cargo.toml @@ -45,7 +45,6 @@ bytes = { workspace = true } either = { workspace = true } # Local dependencies -instant = "0.1.12" void = "1.0.2" libp2p-mplex = "0.41" @@ -64,4 +63,3 @@ async-channel = { workspace = true } [features] libp2p-websocket = [] - diff --git a/beacon_node/lighthouse_network/gossipsub/Cargo.toml b/beacon_node/lighthouse_network/gossipsub/Cargo.toml index d484edd81c4..d8fa445e63f 100644 --- a/beacon_node/lighthouse_network/gossipsub/Cargo.toml +++ b/beacon_node/lighthouse_network/gossipsub/Cargo.toml @@ -10,7 +10,7 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [features] -wasm-bindgen = ["getrandom/js", "instant/wasm-bindgen"] +wasm-bindgen = ["getrandom/js"] [dependencies] async-channel = { workspace = true } @@ -25,7 +25,6 @@ futures-ticker = "0.0.3" futures-timer = "3.0.2" getrandom = "0.2.12" hex_fmt = "0.3.0" -instant = "0.1.12" libp2p = { version = "0.53", default-features = false } quick-protobuf = "0.8" quick-protobuf-codec = "0.3" @@ -35,8 +34,8 @@ serde = { version = "1", optional = true, features = ["derive"] } sha2 = "0.10.8" tracing = "0.1.37" void = "1.0.2" - prometheus-client = "0.22.0" +web-time = "1.1.0" [dev-dependencies] quickcheck = { workspace = true } diff --git a/beacon_node/lighthouse_network/gossipsub/src/backoff.rs b/beacon_node/lighthouse_network/gossipsub/src/backoff.rs index 2567a3691e0..f83a24baafe 100644 --- a/beacon_node/lighthouse_network/gossipsub/src/backoff.rs +++ b/beacon_node/lighthouse_network/gossipsub/src/backoff.rs @@ -20,13 +20,13 @@ //! Data structure for efficiently storing known back-off's when pruning peers. use crate::topic::TopicHash; -use instant::Instant; use libp2p::identity::PeerId; use std::collections::{ hash_map::{Entry, HashMap}, HashSet, }; use std::time::Duration; +use web_time::Instant; #[derive(Copy, Clone)] struct HeartbeatIndex(usize); diff --git a/beacon_node/lighthouse_network/gossipsub/src/behaviour.rs b/beacon_node/lighthouse_network/gossipsub/src/behaviour.rs index ce0437342e3..ccebb4e267f 100644 --- a/beacon_node/lighthouse_network/gossipsub/src/behaviour.rs +++ b/beacon_node/lighthouse_network/gossipsub/src/behaviour.rs @@ -34,7 +34,6 @@ use futures_ticker::Ticker; use prometheus_client::registry::Registry; use rand::{seq::SliceRandom, thread_rng}; -use instant::Instant; use libp2p::core::{multiaddr::Protocol::Ip4, multiaddr::Protocol::Ip6, Endpoint, Multiaddr}; use libp2p::identity::Keypair; use libp2p::identity::PeerId; @@ -44,6 +43,7 @@ use libp2p::swarm::{ ConnectionDenied, ConnectionId, NetworkBehaviour, NotifyHandler, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, }; +use web_time::{Instant, SystemTime}; use super::gossip_promises::GossipPromises; use super::handler::{Handler, HandlerEvent, HandlerIn}; @@ -67,7 +67,6 @@ use super::{ types::RpcOut, }; use super::{PublishError, SubscriptionError, TopicScoreParams, ValidationError}; -use instant::SystemTime; use quick_protobuf::{MessageWrite, Writer}; use std::{cmp::Ordering::Equal, fmt::Debug}; diff --git a/beacon_node/lighthouse_network/gossipsub/src/gossip_promises.rs b/beacon_node/lighthouse_network/gossipsub/src/gossip_promises.rs index 43ca178556b..2bfb20595a8 100644 --- a/beacon_node/lighthouse_network/gossipsub/src/gossip_promises.rs +++ b/beacon_node/lighthouse_network/gossipsub/src/gossip_promises.rs @@ -21,9 +21,9 @@ use super::peer_score::RejectReason; use super::MessageId; use super::ValidationError; -use instant::Instant; use libp2p::identity::PeerId; use std::collections::HashMap; +use web_time::Instant; /// Tracks recently sent `IWANT` messages and checks if peers respond to them. #[derive(Default)] diff --git a/beacon_node/lighthouse_network/gossipsub/src/handler.rs b/beacon_node/lighthouse_network/gossipsub/src/handler.rs index 298570955fc..359bf8da428 100644 --- a/beacon_node/lighthouse_network/gossipsub/src/handler.rs +++ b/beacon_node/lighthouse_network/gossipsub/src/handler.rs @@ -26,7 +26,6 @@ use asynchronous_codec::Framed; use futures::future::Either; use futures::prelude::*; use futures::StreamExt; -use instant::Instant; use libp2p::core::upgrade::DeniedUpgrade; use libp2p::swarm::handler::{ ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, DialUpgradeError, @@ -37,6 +36,7 @@ use std::{ pin::Pin, task::{Context, Poll}, }; +use web_time::Instant; /// The event emitted by the Handler. This informs the behaviour of various events created /// by the handler. diff --git a/beacon_node/lighthouse_network/gossipsub/src/peer_score.rs b/beacon_node/lighthouse_network/gossipsub/src/peer_score.rs index 4d609434f13..fa02f06f69d 100644 --- a/beacon_node/lighthouse_network/gossipsub/src/peer_score.rs +++ b/beacon_node/lighthouse_network/gossipsub/src/peer_score.rs @@ -24,11 +24,11 @@ use super::metrics::{Metrics, Penalty}; use super::time_cache::TimeCache; use super::{MessageId, TopicHash}; -use instant::Instant; use libp2p::identity::PeerId; use std::collections::{hash_map, HashMap, HashSet}; use std::net::IpAddr; use std::time::Duration; +use web_time::Instant; mod params; use super::ValidationError; diff --git a/beacon_node/lighthouse_network/gossipsub/src/time_cache.rs b/beacon_node/lighthouse_network/gossipsub/src/time_cache.rs index 89fd4afee09..a3e5c01ac4c 100644 --- a/beacon_node/lighthouse_network/gossipsub/src/time_cache.rs +++ b/beacon_node/lighthouse_network/gossipsub/src/time_cache.rs @@ -21,13 +21,13 @@ //! This implements a time-based LRU cache for checking gossipsub message duplicates. use fnv::FnvHashMap; -use instant::Instant; use std::collections::hash_map::{ self, Entry::{Occupied, Vacant}, }; use std::collections::VecDeque; use std::time::Duration; +use web_time::Instant; struct ExpiringElement { /// The element that expires diff --git a/beacon_node/lighthouse_network/gossipsub/src/types.rs b/beacon_node/lighthouse_network/gossipsub/src/types.rs index 712698b42ac..84bdfb786f9 100644 --- a/beacon_node/lighthouse_network/gossipsub/src/types.rs +++ b/beacon_node/lighthouse_network/gossipsub/src/types.rs @@ -25,7 +25,6 @@ use async_channel::{Receiver, Sender}; use futures::stream::Peekable; use futures::{Future, Stream, StreamExt}; use futures_timer::Delay; -use instant::Duration; use libp2p::identity::PeerId; use libp2p::swarm::ConnectionId; use prometheus_client::encoding::EncodeLabelValue; @@ -36,6 +35,7 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; use std::task::{Context, Poll}; use std::{fmt, pin::Pin}; +use web_time::Duration; use crate::rpc_proto::proto; #[cfg(feature = "serde")]