Skip to content

Commit 1aa098d

Browse files
santos227divagant-martianmxinden
authored
protocols/gossipsub: Revert back to wasm_timer for interval (#2506)
Removed the custom interval implementation and removes support for wasm32-unknown-unknown. See libp2p/rust-libp2p#2497 for details. Co-authored-by: Diva M <[email protected]> Co-authored-by: Max Inden <[email protected]>
1 parent ca0e9f9 commit 1aa098d

15 files changed

+37
-229
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@
6969
- Update to `libp2p-websocket` `v0.34.0`.
7070
- Update to `libp2p-yamux` `v0.36.0`.
7171

72+
- Drop support for gossipsub in the wasm32-unknown-unknown target (see [PR 2506]).
73+
74+
[PR 2506]: https://github.com/libp2p/rust-libp2p/pull/2506
75+
7276
## Version 0.42.1 [2022-02-02]
7377

7478
- Update individual crates.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ libp2p-autonat = { version = "0.2.0", path = "protocols/autonat", optional = tru
8181
libp2p-core = { version = "0.32.0", path = "core", default-features = false }
8282
libp2p-dcutr = { version = "0.1.0", path = "protocols/dcutr", optional = true }
8383
libp2p-floodsub = { version = "0.34.0", path = "protocols/floodsub", optional = true }
84-
libp2p-gossipsub = { version = "0.36.0", path = "./protocols/gossipsub", optional = true }
8584
libp2p-identify = { version = "0.34.0", path = "protocols/identify", optional = true }
8685
libp2p-kad = { version = "0.35.0", path = "protocols/kad", optional = true }
8786
libp2p-metrics = { version = "0.4.0", path = "misc/metrics", optional = true }
@@ -111,6 +110,9 @@ libp2p-mdns = { version = "0.35.0", path = "protocols/mdns", optional = true }
111110
libp2p-tcp = { version = "0.32.0", path = "transports/tcp", default-features = false, optional = true }
112111
libp2p-websocket = { version = "0.34.0", path = "transports/websocket", optional = true }
113112

113+
[target.'cfg(not(target_os = "unknown"))'.dependencies]
114+
libp2p-gossipsub = { version = "0.36.0", path = "protocols/gossipsub", optional = true }
115+
114116
[dev-dependencies]
115117
async-std = { version = "1.6.2", features = ["attributes"] }
116118
async-trait = "0.1"

misc/metrics/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
- Move from `open-metrics-client` to `prometheus-client` (see [PR 2442]).
1616

17+
- Drop support for gossipsub in wasm32-unknown-unknown target (see [PR 2506]).
18+
1719
[PR 2442]: https://github.com/libp2p/rust-libp2p/pull/2442
20+
[PR 2506]: https://github.com/libp2p/rust-libp2p/pull/2506
1821

1922
# 0.3.0 [2022-01-27]
2023

misc/metrics/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ dcutr = ["libp2p-dcutr"]
2121
[dependencies]
2222
libp2p-core = { version = "0.32.0", path = "../../core", default-features = false }
2323
libp2p-dcutr = { version = "0.1.0", path = "../../protocols/dcutr", optional = true }
24-
libp2p-gossipsub = { version = "0.36.0", path = "../../protocols/gossipsub", optional = true }
2524
libp2p-identify = { version = "0.34.0", path = "../../protocols/identify", optional = true }
2625
libp2p-kad = { version = "0.35.0", path = "../../protocols/kad", optional = true }
2726
libp2p-ping = { version = "0.34.0", path = "../../protocols/ping", optional = true }
2827
libp2p-relay = { version = "0.7.0", path = "../../protocols/relay", optional = true }
2928
libp2p-swarm = { version = "0.34.0", path = "../../swarm" }
3029
prometheus-client = "0.15.0"
3130

31+
[target.'cfg(not(target_os = "unknown"))'.dependencies]
32+
libp2p-gossipsub = { version = "0.36.0", path = "../../protocols/gossipsub", optional = true }
33+
3234
[dev-dependencies]
3335
env_logger = "0.8.1"
3436
futures = "0.3.1"

misc/metrics/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#[cfg(feature = "dcutr")]
2929
mod dcutr;
3030
#[cfg(feature = "gossipsub")]
31+
#[cfg(not(target_os = "unknown"))]
3132
mod gossipsub;
3233
#[cfg(feature = "identify")]
3334
mod identify;
@@ -46,6 +47,7 @@ pub struct Metrics {
4647
#[cfg(feature = "dcutr")]
4748
dcutr: dcutr::Metrics,
4849
#[cfg(feature = "gossipsub")]
50+
#[cfg(not(target_os = "unknown"))]
4951
gossipsub: gossipsub::Metrics,
5052
#[cfg(feature = "identify")]
5153
identify: identify::Metrics,
@@ -73,6 +75,7 @@ impl Metrics {
7375
#[cfg(feature = "dcutr")]
7476
dcutr: dcutr::Metrics::new(sub_registry),
7577
#[cfg(feature = "gossipsub")]
78+
#[cfg(not(target_os = "unknown"))]
7679
gossipsub: gossipsub::Metrics::new(sub_registry),
7780
#[cfg(feature = "identify")]
7881
identify: identify::Metrics::new(sub_registry),

protocols/gossipsub/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010

1111
- Merge NetworkBehaviour's inject_\* paired methods (see PR 2445).
1212

13+
- Revert to wasm-timer (see [PR 2506]).
14+
1315
[PR 2442]: https://github.com/libp2p/rust-libp2p/pull/2442
1416
[PR 2481]: https://github.com/libp2p/rust-libp2p/pull/2481
1517
[PR 2445]: https://github.com/libp2p/rust-libp2p/pull/2445
18+
[PR 2506]: https://github.com/libp2p/rust-libp2p/pull/2506
1619

1720
# 0.35.0 [2022-01-27]
1821

protocols/gossipsub/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ smallvec = "1.6.1"
2727
prost = "0.9"
2828
hex_fmt = "0.3.0"
2929
regex = "1.4.0"
30-
futures-timer = "3.0.2"
31-
pin-project = "1.0.8"
32-
instant = "0.1.11"
3330
serde = { version = "1", optional = true, features = ["derive"] }
31+
wasm-timer = "0.2.5"
32+
instant = "0.1.11"
3433
# Metrics dependencies
3534
prometheus-client = "0.15.0"
3635

protocols/gossipsub/src/backoff.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020

2121
//! Data structure for efficiently storing known back-off's when pruning peers.
2222
use crate::topic::TopicHash;
23-
use instant::Instant;
24-
use libp2p_core::PeerId;
25-
use std::collections::{
26-
hash_map::{Entry, HashMap},
27-
HashSet,
28-
};
29-
use std::time::Duration;
23+
use libp2p_core::PeerId;
24+
use std::collections::{
25+
hash_map::{Entry, HashMap},
26+
HashSet,
27+
};
28+
use std::time::Duration;
29+
use wasm_timer::Instant;
3030

3131
#[derive(Copy, Clone)]
3232
struct HeartbeatIndex(usize);

protocols/gossipsub/src/behaviour.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use prometheus_client::registry::Registry;
3636
use prost::Message;
3737
use rand::{seq::SliceRandom, thread_rng};
3838

39-
use instant::Instant;
4039
use libp2p_core::{
4140
connection::ConnectionId, identity::Keypair, multiaddr::Protocol::Ip4,
4241
multiaddr::Protocol::Ip6, ConnectedPoint, Multiaddr, PeerId,
@@ -45,7 +44,9 @@ use libp2p_swarm::{
4544
dial_opts::{self, DialOpts},
4645
IntoProtocolsHandler, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters,
4746
};
47+
use wasm_timer::Instant;
4848

49+
use crate::backoff::BackoffStorage;
4950
use crate::config::{GossipsubConfig, ValidationMode};
5051
use crate::error::{PublishError, SubscriptionError, ValidationError};
5152
use crate::gossip_promises::GossipPromises;
@@ -63,9 +64,9 @@ use crate::types::{
6364
GossipsubSubscriptionAction, MessageAcceptance, MessageId, PeerInfo, RawGossipsubMessage,
6465
};
6566
use crate::types::{GossipsubRpc, PeerConnections, PeerKind};
66-
use crate::{backoff::BackoffStorage, interval::Interval};
6767
use crate::{rpc_proto, TopicScoreParams};
6868
use std::{cmp::Ordering::Equal, fmt::Debug};
69+
use wasm_timer::Interval;
6970

7071
#[cfg(test)]
7172
mod tests;
@@ -439,8 +440,8 @@ where
439440
config.backoff_slack(),
440441
),
441442
mcache: MessageCache::new(config.history_gossip(), config.history_length()),
442-
heartbeat: Interval::new_initial(
443-
config.heartbeat_initial_delay(),
443+
heartbeat: Interval::new_at(
444+
Instant::now() + config.heartbeat_initial_delay(),
444445
config.heartbeat_interval(),
445446
),
446447
heartbeat_ticks: 0,

protocols/gossipsub/src/gossip_promises.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
use crate::error::ValidationError;
2222
use crate::peer_score::RejectReason;
2323
use crate::MessageId;
24-
use instant::Instant;
2524
use libp2p_core::PeerId;
2625
use log::debug;
2726
use std::collections::HashMap;
27+
use wasm_timer::Instant;
2828

2929
/// Tracks recently sent `IWANT` messages and checks if peers respond to them.
3030
#[derive(Default)]

protocols/gossipsub/src/interval.rs

Lines changed: 0 additions & 209 deletions
This file was deleted.

protocols/gossipsub/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ mod behaviour;
142142
mod config;
143143
mod gossip_promises;
144144
mod handler;
145-
mod interval;
146145
mod mcache;
147146
pub mod metrics;
148147
mod peer_score;

0 commit comments

Comments
 (0)