Skip to content

Commit bf11f93

Browse files
divagant-martianAgeManningackintosh
authored andcommitted
upgrade to libp2p 0.52 (sigp#4431)
Upgrade libp2p to v0.52 - **Workflows**: remove installation of `protoc` - **Book**: remove installation of `protoc` - **`Dockerfile`s and `cross`**: remove custom base `Dockerfile` for cross since it's no longer needed. Remove `protoc` from remaining `Dockerfiles`s - **Upgrade `discv5` to `v0.3.1`:** we have some cool stuff in there: no longer needs `protoc` and faster ip updates on cold start - **Upgrade `prometheus` to `0.21.0`**, now it no longer needs encoding checks - **things that look like refactors:** bunch of api types were renamed and need to be accessed in a different (clearer) way - **Lighthouse network** - connection limits is now a behaviour - banned peers no longer exist on the swarm level, but at the behaviour level - `connection_event_buffer_size` now is handled per connection with a buffer size of 4 - `mplex` is deprecated and was removed - rpc handler now logs the peer to which it belongs Tried to keep as much behaviour unchanged as possible. However, there is a great deal of improvements we can do _after_ this upgrade: - Smart connection limits: Connection limits have been checked only based on numbers, we can now use information about the incoming peer to decide if we want it - More powerful peer management: Dial attempts from other behaviours can be rejected early - Incoming connections can be rejected early - Banning can be returned exclusively to the peer management: We should not get connections to banned peers anymore making use of this - TCP Nat updates: We might be able to take advantage of confirmed external addresses to check out tcp ports/ips Co-authored-by: Age Manning <[email protected]> Co-authored-by: Akihito Nakano <[email protected]>
1 parent 223e1ec commit bf11f93

File tree

27 files changed

+391
-371
lines changed

27 files changed

+391
-371
lines changed

.github/workflows/release.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,6 @@ jobs:
7979
if: startsWith(matrix.arch, 'x86_64-windows')
8080
run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV
8181

82-
# ==============================
83-
# Windows & Mac dependencies
84-
# ==============================
85-
- name: Install Protoc
86-
if: contains(matrix.arch, 'darwin') || contains(matrix.arch, 'windows')
87-
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
88-
with:
89-
repo-token: ${{ secrets.GITHUB_TOKEN }}
90-
9182
# ==============================
9283
# Builds
9384
# ==============================

.github/workflows/test-suite.yml

Lines changed: 2 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ jobs:
6060
- name: Get latest version of stable Rust
6161
if: env.SELF_HOSTED_RUNNERS == false
6262
run: rustup update stable
63-
- name: Install Protoc
64-
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
65-
with:
66-
repo-token: ${{ secrets.GITHUB_TOKEN }}
6763
- name: Install Foundry (anvil)
6864
uses: foundry-rs/foundry-toolchain@v1
6965
- name: Run tests in release
@@ -83,7 +79,7 @@ jobs:
8379
node-version: '14'
8480
- name: Install windows build tools
8581
run: |
86-
choco install python protoc visualstudio2019-workload-vctools -y
82+
choco install python visualstudio2019-workload-vctools -y
8783
npm config set msvs_version 2019
8884
- name: Install Foundry (anvil)
8985
uses: foundry-rs/foundry-toolchain@v1
@@ -108,10 +104,6 @@ jobs:
108104
- name: Get latest version of stable Rust
109105
if: env.SELF_HOSTED_RUNNERS == false
110106
run: rustup update stable
111-
- name: Install Protoc
112-
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
113-
with:
114-
repo-token: ${{ secrets.GITHUB_TOKEN }}
115107
- name: Run beacon_chain tests for all known forks
116108
run: make test-beacon-chain
117109
op-pool-tests:
@@ -122,10 +114,6 @@ jobs:
122114
- uses: actions/checkout@v3
123115
- name: Get latest version of stable Rust
124116
run: rustup update stable
125-
- name: Install Protoc
126-
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
127-
with:
128-
repo-token: ${{ secrets.GITHUB_TOKEN }}
129117
- name: Run operation_pool tests for all known forks
130118
run: make test-op-pool
131119
slasher-tests:
@@ -148,10 +136,6 @@ jobs:
148136
- name: Get latest version of stable Rust
149137
if: env.SELF_HOSTED_RUNNERS == false
150138
run: rustup update stable
151-
- name: Install Protoc
152-
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
153-
with:
154-
repo-token: ${{ secrets.GITHUB_TOKEN }}
155139
- name: Install Foundry (anvil)
156140
uses: foundry-rs/foundry-toolchain@v1
157141
- name: Run tests in debug
@@ -164,10 +148,6 @@ jobs:
164148
- uses: actions/checkout@v3
165149
- name: Get latest version of stable Rust
166150
run: rustup update stable
167-
- name: Install Protoc
168-
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
169-
with:
170-
repo-token: ${{ secrets.GITHUB_TOKEN }}
171151
- name: Run state_transition_vectors in release.
172152
run: make run-state-transition-tests
173153
ef-tests-ubuntu:
@@ -180,10 +160,6 @@ jobs:
180160
- name: Get latest version of stable Rust
181161
if: env.SELF_HOSTED_RUNNERS == false
182162
run: rustup update stable
183-
- name: Install Protoc
184-
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
185-
with:
186-
repo-token: ${{ secrets.GITHUB_TOKEN }}
187163
- name: Run consensus-spec-tests with blst, milagro and fake_crypto
188164
run: make test-ef
189165
dockerfile-ubuntu:
@@ -206,10 +182,6 @@ jobs:
206182
- uses: actions/checkout@v3
207183
- name: Get latest version of stable Rust
208184
run: rustup update stable
209-
- name: Install Protoc
210-
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
211-
with:
212-
repo-token: ${{ secrets.GITHUB_TOKEN }}
213185
- name: Install Foundry (anvil)
214186
uses: foundry-rs/foundry-toolchain@v1
215187
- name: Run the beacon chain sim that starts from an eth1 contract
@@ -222,10 +194,6 @@ jobs:
222194
- uses: actions/checkout@v3
223195
- name: Get latest version of stable Rust
224196
run: rustup update stable
225-
- name: Install Protoc
226-
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
227-
with:
228-
repo-token: ${{ secrets.GITHUB_TOKEN }}
229197
- name: Install Foundry (anvil)
230198
uses: foundry-rs/foundry-toolchain@v1
231199
- name: Run the beacon chain sim and go through the merge transition
@@ -238,10 +206,6 @@ jobs:
238206
- uses: actions/checkout@v3
239207
- name: Get latest version of stable Rust
240208
run: rustup update stable
241-
- name: Install Protoc
242-
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
243-
with:
244-
repo-token: ${{ secrets.GITHUB_TOKEN }}
245209
- name: Run the beacon chain sim without an eth1 connection
246210
run: cargo run --release --bin simulator no-eth1-sim
247211
syncing-simulator-ubuntu:
@@ -252,10 +216,6 @@ jobs:
252216
- uses: actions/checkout@v3
253217
- name: Get latest version of stable Rust
254218
run: rustup update stable
255-
- name: Install Protoc
256-
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
257-
with:
258-
repo-token: ${{ secrets.GITHUB_TOKEN }}
259219
- name: Install Foundry (anvil)
260220
uses: foundry-rs/foundry-toolchain@v1
261221
- name: Run the syncing simulator
@@ -268,10 +228,6 @@ jobs:
268228
- uses: actions/checkout@v3
269229
- name: Get latest version of stable Rust
270230
run: rustup update stable
271-
- name: Install Protoc
272-
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
273-
with:
274-
repo-token: ${{ secrets.GITHUB_TOKEN }}
275231
- name: Install geth
276232
run: |
277233
sudo add-apt-repository -y ppa:ethereum/ethereum
@@ -303,10 +259,6 @@ jobs:
303259
dotnet-version: '6.0.201'
304260
- name: Get latest version of stable Rust
305261
run: rustup update stable
306-
- name: Install Protoc
307-
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
308-
with:
309-
repo-token: ${{ secrets.GITHUB_TOKEN }}
310262
- name: Run exec engine integration tests in release
311263
run: make test-exec-engine
312264
check-benchmarks:
@@ -317,10 +269,6 @@ jobs:
317269
- uses: actions/checkout@v3
318270
- name: Get latest version of stable Rust
319271
run: rustup update stable
320-
- name: Install Protoc
321-
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
322-
with:
323-
repo-token: ${{ secrets.GITHUB_TOKEN }}
324272
- name: Typecheck benchmark code without running it
325273
run: make check-benches
326274
clippy:
@@ -331,10 +279,6 @@ jobs:
331279
- uses: actions/checkout@v3
332280
- name: Get latest version of stable Rust
333281
run: rustup update stable
334-
- name: Install Protoc
335-
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
336-
with:
337-
repo-token: ${{ secrets.GITHUB_TOKEN }}
338282
- name: Lint code for quality and style with Clippy
339283
run: make lint
340284
- name: Certify Cargo.lock freshness
@@ -347,10 +291,6 @@ jobs:
347291
- uses: actions/checkout@v3
348292
- name: Install Rust @ MSRV (${{ needs.extract-msrv.outputs.MSRV }})
349293
run: rustup override set ${{ needs.extract-msrv.outputs.MSRV }}
350-
- name: Install Protoc
351-
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
352-
with:
353-
repo-token: ${{ secrets.GITHUB_TOKEN }}
354294
- name: Run cargo check
355295
run: cargo check --workspace
356296
arbitrary-check:
@@ -389,10 +329,6 @@ jobs:
389329
- uses: actions/checkout@v3
390330
- name: Install Rust (${{ env.PINNED_NIGHTLY }})
391331
run: rustup toolchain install $PINNED_NIGHTLY
392-
- name: Install Protoc
393-
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
394-
with:
395-
repo-token: ${{ secrets.GITHUB_TOKEN }}
396332
- name: Install cargo-udeps
397333
run: cargo install cargo-udeps --locked --force
398334
- name: Create Cargo config dir
@@ -410,7 +346,7 @@ jobs:
410346
steps:
411347
- uses: actions/checkout@v3
412348
- name: Install dependencies
413-
run: sudo apt install -y git gcc g++ make cmake pkg-config llvm-dev libclang-dev clang protobuf-compiler
349+
run: sudo apt install -y git gcc g++ make cmake pkg-config llvm-dev libclang-dev clang
414350
- name: Use Rust beta
415351
run: rustup override set beta
416352
- name: Run make

Cross.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[target.x86_64-unknown-linux-gnu]
2-
dockerfile = './scripts/cross/Dockerfile'
2+
pre-build = ["apt-get install -y cmake clang-3.9"]
33

44
[target.aarch64-unknown-linux-gnu]
5-
dockerfile = './scripts/cross/Dockerfile'
5+
pre-build = ["apt-get install -y cmake clang-3.9"]

beacon_node/http_api/src/test_utils.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@ use directory::DEFAULT_ROOT_DIR;
77
use eth2::{BeaconNodeHttpClient, Timeouts};
88
use lighthouse_network::{
99
discv5::enr::{CombinedKey, EnrBuilder},
10-
libp2p::{
11-
core::connection::ConnectionId,
12-
swarm::{
13-
behaviour::{ConnectionEstablished, FromSwarm},
14-
NetworkBehaviour,
15-
},
10+
libp2p::swarm::{
11+
behaviour::{ConnectionEstablished, FromSwarm},
12+
ConnectionId, NetworkBehaviour,
1613
},
1714
rpc::methods::{MetaData, MetaDataV2},
1815
types::{EnrAttestationBitfield, EnrSyncCommitteeBitfield, SyncState},
@@ -167,7 +164,7 @@ pub async fn create_api_server_on_port<T: BeaconChainTypes>(
167164
local_addr: EXTERNAL_ADDR.parse().unwrap(),
168165
send_back_addr: EXTERNAL_ADDR.parse().unwrap(),
169166
};
170-
let connection_id = ConnectionId::new(1);
167+
let connection_id = ConnectionId::new_unchecked(1);
171168
pm.on_swarm_event(FromSwarm::ConnectionEstablished(ConnectionEstablished {
172169
peer_id,
173170
connection_id,

beacon_node/http_metrics/src/metrics.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::Context;
22
use beacon_chain::BeaconChainTypes;
3-
use lighthouse_metrics::{Encoder, TextEncoder};
3+
use lighthouse_metrics::TextEncoder;
44
use lighthouse_network::prometheus_client::encoding::text::encode;
55
use malloc_utils::scrape_allocator_metrics;
66

@@ -9,7 +9,7 @@ pub use lighthouse_metrics::*;
99
pub fn gather_prometheus_metrics<T: BeaconChainTypes>(
1010
ctx: &Context<T>,
1111
) -> std::result::Result<String, String> {
12-
let mut buffer = vec![];
12+
let mut buffer = String::new();
1313
let encoder = TextEncoder::new();
1414

1515
// There are two categories of metrics:
@@ -50,7 +50,7 @@ pub fn gather_prometheus_metrics<T: BeaconChainTypes>(
5050
}
5151

5252
encoder
53-
.encode(&lighthouse_metrics::gather(), &mut buffer)
53+
.encode_utf8(&lighthouse_metrics::gather(), &mut buffer)
5454
.unwrap();
5555
// encode gossipsub metrics also if they exist
5656
if let Some(registry) = ctx.gossipsub_registry.as_ref() {
@@ -59,5 +59,5 @@ pub fn gather_prometheus_metrics<T: BeaconChainTypes>(
5959
}
6060
}
6161

62-
String::from_utf8(buffer).map_err(|e| format!("Failed to encode prometheus info: {:?}", e))
62+
Ok(buffer)
6363
}

beacon_node/lighthouse_network/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["Sigma Prime <[email protected]>"]
55
edition = "2021"
66

77
[dependencies]
8-
discv5 = { version = "0.3.0", features = ["libp2p"]}
8+
discv5 = { version = "0.3.1", features = ["libp2p"] }
99
unsigned-varint = { version = "0.6.0", features = ["codec"] }
1010
types = { path = "../../consensus/types" }
1111
ssz_types = "0.5.3"
@@ -40,15 +40,15 @@ directory = { path = "../../common/directory" }
4040
regex = "1.5.5"
4141
strum = { version = "0.24.0", features = ["derive"] }
4242
superstruct = "0.5.0"
43-
prometheus-client = "0.18.0"
43+
prometheus-client = "0.21.0"
4444
unused_port = { path = "../../common/unused_port" }
4545
delay_map = "0.3.0"
4646
void = "1"
4747

4848
[dependencies.libp2p]
49-
version = "0.50.0"
49+
version = "0.52"
5050
default-features = false
51-
features = ["websocket", "identify", "mplex", "yamux", "noise", "gossipsub", "dns", "tcp", "tokio", "plaintext", "secp256k1", "macros", "ecdsa"]
51+
features = ["websocket", "identify", "yamux", "noise", "gossipsub", "dns", "tcp", "tokio", "plaintext", "secp256k1", "macros", "ecdsa"]
5252

5353
[dev-dependencies]
5454
slog-term = "2.6.0"

beacon_node/lighthouse_network/src/config.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ use directory::{
66
DEFAULT_BEACON_NODE_DIR, DEFAULT_HARDCODED_NETWORK, DEFAULT_NETWORK_DIR, DEFAULT_ROOT_DIR,
77
};
88
use discv5::{Discv5Config, Discv5ConfigBuilder};
9-
use libp2p::gossipsub::{
10-
FastMessageId, GossipsubConfig, GossipsubConfigBuilder, GossipsubMessage, MessageId,
11-
RawGossipsubMessage, ValidationMode,
12-
};
9+
use libp2p::gossipsub;
1310
use libp2p::Multiaddr;
1411
use serde_derive::{Deserialize, Serialize};
1512
use sha2::{Digest, Sha256};
@@ -83,7 +80,7 @@ pub struct Config {
8380

8481
/// Gossipsub configuration parameters.
8582
#[serde(skip)]
86-
pub gs_config: GossipsubConfig,
83+
pub gs_config: gossipsub::Config,
8784

8885
/// Discv5 configuration parameters.
8986
#[serde(skip)]
@@ -265,7 +262,7 @@ impl Default for Config {
265262

266263
// Note: Using the default config here. Use `gossipsub_config` function for getting
267264
// Lighthouse specific configuration for gossipsub.
268-
let gs_config = GossipsubConfigBuilder::default()
265+
let gs_config = gossipsub::ConfigBuilder::default()
269266
.build()
270267
.expect("valid gossipsub configuration");
271268

@@ -416,16 +413,16 @@ impl From<u8> for NetworkLoad {
416413
}
417414

418415
/// Return a Lighthouse specific `GossipsubConfig` where the `message_id_fn` depends on the current fork.
419-
pub fn gossipsub_config(network_load: u8, fork_context: Arc<ForkContext>) -> GossipsubConfig {
416+
pub fn gossipsub_config(network_load: u8, fork_context: Arc<ForkContext>) -> gossipsub::Config {
420417
// The function used to generate a gossipsub message id
421418
// We use the first 8 bytes of SHA256(topic, data) for content addressing
422-
let fast_gossip_message_id = |message: &RawGossipsubMessage| {
419+
let fast_gossip_message_id = |message: &gossipsub::RawMessage| {
423420
let data = [message.topic.as_str().as_bytes(), &message.data].concat();
424-
FastMessageId::from(&Sha256::digest(data)[..8])
421+
gossipsub::FastMessageId::from(&Sha256::digest(data)[..8])
425422
};
426423
fn prefix(
427424
prefix: [u8; 4],
428-
message: &GossipsubMessage,
425+
message: &gossipsub::Message,
429426
fork_context: Arc<ForkContext>,
430427
) -> Vec<u8> {
431428
let topic_bytes = message.topic.as_str().as_bytes();
@@ -453,8 +450,8 @@ pub fn gossipsub_config(network_load: u8, fork_context: Arc<ForkContext>) -> Gos
453450
}
454451

455452
let is_merge_enabled = fork_context.fork_exists(ForkName::Merge);
456-
let gossip_message_id = move |message: &GossipsubMessage| {
457-
MessageId::from(
453+
let gossip_message_id = move |message: &gossipsub::Message| {
454+
gossipsub::MessageId::from(
458455
&Sha256::digest(
459456
prefix(MESSAGE_DOMAIN_VALID_SNAPPY, message, fork_context.clone()).as_slice(),
460457
)[..20],
@@ -463,7 +460,7 @@ pub fn gossipsub_config(network_load: u8, fork_context: Arc<ForkContext>) -> Gos
463460

464461
let load = NetworkLoad::from(network_load);
465462

466-
GossipsubConfigBuilder::default()
463+
gossipsub::ConfigBuilder::default()
467464
.max_transmit_size(gossip_max_size(is_merge_enabled))
468465
.heartbeat_interval(load.heartbeat_interval)
469466
.mesh_n(load.mesh_n)
@@ -476,7 +473,7 @@ pub fn gossipsub_config(network_load: u8, fork_context: Arc<ForkContext>) -> Gos
476473
.max_messages_per_rpc(Some(500)) // Responses to IWANT can be quite large
477474
.history_gossip(load.history_gossip)
478475
.validate_messages() // require validation before propagation
479-
.validation_mode(ValidationMode::Anonymous)
476+
.validation_mode(gossipsub::ValidationMode::Anonymous)
480477
.duplicate_cache_time(DUPLICATE_CACHE_TIME)
481478
.message_id_fn(gossip_message_id)
482479
.fast_message_id_fn(fast_gossip_message_id)

0 commit comments

Comments
 (0)