Upgrade to discv5 0.7.0 (#6385)

* Upgrade to discv5 v0.7.0
This commit is contained in:
Age Manning
2024-09-12 10:26:20 +10:00
committed by GitHub
parent a94b12b4d5
commit e5a40fb73b
7 changed files with 84 additions and 235 deletions

251
Cargo.lock generated
View File

@@ -84,15 +84,6 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"
[[package]]
name = "aead"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877"
dependencies = [
"generic-array",
]
[[package]]
name = "aead"
version = "0.5.2"
@@ -127,31 +118,17 @@ dependencies = [
"cpufeatures",
]
[[package]]
name = "aes-gcm"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc3be92e19a7ef47457b8e6f90707e12b6ac5d20c6f3866584fa3be0787d839f"
dependencies = [
"aead 0.4.3",
"aes 0.7.5",
"cipher 0.3.0",
"ctr 0.7.0",
"ghash 0.4.4",
"subtle",
]
[[package]]
name = "aes-gcm"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1"
dependencies = [
"aead 0.5.2",
"aead",
"aes 0.8.4",
"cipher 0.4.4",
"ctr 0.9.2",
"ghash 0.5.1",
"ghash",
"subtle",
]
@@ -1277,7 +1254,7 @@ version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35"
dependencies = [
"aead 0.5.2",
"aead",
"chacha20",
"cipher 0.4.4",
"poly1305",
@@ -1748,15 +1725,6 @@ dependencies = [
"subtle",
]
[[package]]
name = "ctr"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a232f92a03f37dd7d7dd2adc67166c77e9cd88de5b019b9a9eecfaeaf7bfd481"
dependencies = [
"cipher 0.3.0",
]
[[package]]
name = "ctr"
version = "0.8.0"
@@ -2200,13 +2168,15 @@ dependencies = [
[[package]]
name = "discv5"
version = "0.4.1"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bac33cb3f99889a57e56a8c6ccb77aaf0cfc7787602b7af09783f736d77314e1"
checksum = "f569b8c367554666c8652305621e8bae3634a2ff5c6378081d5bd8c399c99f23"
dependencies = [
"aes 0.7.5",
"aes-gcm 0.9.2",
"aes 0.8.4",
"aes-gcm",
"alloy-rlp",
"arrayvec",
"ctr 0.9.2",
"delay_map",
"enr",
"fnv",
@@ -2215,12 +2185,12 @@ dependencies = [
"hex",
"hkdf",
"lazy_static",
"libp2p 0.53.2",
"libp2p-identity",
"lru",
"more-asserts",
"multiaddr",
"parking_lot 0.11.2",
"rand",
"rlp",
"smallvec",
"socket2 0.4.10",
"tokio",
@@ -2405,10 +2375,11 @@ dependencies = [
[[package]]
name = "enr"
version = "0.10.0"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a3d8dc56e02f954cac8eb489772c552c473346fc34f67412bb6244fd647f7e4"
checksum = "972070166c68827e64bd1ebc8159dd8e32d9bc2da7ebe8f20b61308f7974ad30"
dependencies = [
"alloy-rlp",
"base64 0.21.7",
"bytes",
"ed25519-dalek",
@@ -2416,7 +2387,6 @@ dependencies = [
"k256 0.13.3",
"log",
"rand",
"rlp",
"serde",
"sha3 0.10.8",
"zeroize",
@@ -3454,16 +3424,6 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "ghash"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1583cc1656d7839fd3732b80cf4f38850336cdb9b8ded1cd399ca62958de3c99"
dependencies = [
"opaque-debug",
"polyval 0.5.3",
]
[[package]]
name = "ghash"
version = "0.5.1"
@@ -3471,7 +3431,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1"
dependencies = [
"opaque-debug",
"polyval 0.6.2",
"polyval",
]
[[package]]
@@ -3523,7 +3483,7 @@ dependencies = [
"getrandom",
"hashlink 0.9.1",
"hex_fmt",
"libp2p 0.54.1",
"libp2p",
"prometheus-client",
"quick-protobuf",
"quick-protobuf-codec",
@@ -4599,29 +4559,6 @@ dependencies = [
"thiserror",
]
[[package]]
name = "libp2p"
version = "0.53.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "681fb3f183edfbedd7a57d32ebe5dcdc0b9f94061185acf3c30249349cc6fc99"
dependencies = [
"bytes",
"either",
"futures",
"futures-timer",
"getrandom",
"instant",
"libp2p-allow-block-list 0.3.0",
"libp2p-connection-limits 0.3.1",
"libp2p-core 0.41.3",
"libp2p-identity",
"libp2p-swarm 0.44.2",
"multiaddr",
"pin-project",
"rw-stream-sink",
"thiserror",
]
[[package]]
name = "libp2p"
version = "0.54.1"
@@ -4633,9 +4570,9 @@ dependencies = [
"futures",
"futures-timer",
"getrandom",
"libp2p-allow-block-list 0.4.0",
"libp2p-connection-limits 0.4.0",
"libp2p-core 0.42.0",
"libp2p-allow-block-list",
"libp2p-connection-limits",
"libp2p-core",
"libp2p-dns",
"libp2p-identify",
"libp2p-identity",
@@ -4644,7 +4581,7 @@ dependencies = [
"libp2p-noise",
"libp2p-plaintext",
"libp2p-quic",
"libp2p-swarm 0.45.1",
"libp2p-swarm",
"libp2p-tcp",
"libp2p-upnp",
"libp2p-yamux",
@@ -4654,39 +4591,15 @@ dependencies = [
"thiserror",
]
[[package]]
name = "libp2p-allow-block-list"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "107b238b794cb83ab53b74ad5dcf7cca3200899b72fe662840cfb52f5b0a32e6"
dependencies = [
"libp2p-core 0.41.3",
"libp2p-identity",
"libp2p-swarm 0.44.2",
"void",
]
[[package]]
name = "libp2p-allow-block-list"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1027ccf8d70320ed77e984f273bc8ce952f623762cb9bf2d126df73caef8041"
dependencies = [
"libp2p-core 0.42.0",
"libp2p-core",
"libp2p-identity",
"libp2p-swarm 0.45.1",
"void",
]
[[package]]
name = "libp2p-connection-limits"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7cd50a78ccfada14de94cbacd3ce4b0138157f376870f13d3a8422cd075b4fd"
dependencies = [
"libp2p-core 0.41.3",
"libp2p-identity",
"libp2p-swarm 0.44.2",
"libp2p-swarm",
"void",
]
@@ -4696,40 +4609,12 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d003540ee8baef0d254f7b6bfd79bac3ddf774662ca0abf69186d517ef82ad8"
dependencies = [
"libp2p-core 0.42.0",
"libp2p-core",
"libp2p-identity",
"libp2p-swarm 0.45.1",
"libp2p-swarm",
"void",
]
[[package]]
name = "libp2p-core"
version = "0.41.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5a8920cbd8540059a01950c1e5c96ea8d89eb50c51cd366fc18bdf540a6e48f"
dependencies = [
"either",
"fnv",
"futures",
"futures-timer",
"libp2p-identity",
"multiaddr",
"multihash",
"multistream-select",
"once_cell",
"parking_lot 0.12.3",
"pin-project",
"quick-protobuf",
"rand",
"rw-stream-sink",
"smallvec",
"thiserror",
"tracing",
"unsigned-varint 0.8.0",
"void",
"web-time",
]
[[package]]
name = "libp2p-core"
version = "0.42.0"
@@ -4767,7 +4652,7 @@ dependencies = [
"async-trait",
"futures",
"hickory-resolver",
"libp2p-core 0.42.0",
"libp2p-core",
"libp2p-identity",
"parking_lot 0.12.3",
"smallvec",
@@ -4785,9 +4670,9 @@ dependencies = [
"futures",
"futures-bounded",
"futures-timer",
"libp2p-core 0.42.0",
"libp2p-core",
"libp2p-identity",
"libp2p-swarm 0.45.1",
"libp2p-swarm",
"lru",
"quick-protobuf",
"quick-protobuf-codec",
@@ -4830,9 +4715,9 @@ dependencies = [
"futures",
"hickory-proto",
"if-watch",
"libp2p-core 0.42.0",
"libp2p-core",
"libp2p-identity",
"libp2p-swarm 0.45.1",
"libp2p-swarm",
"rand",
"smallvec",
"socket2 0.5.7",
@@ -4848,10 +4733,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77ebafa94a717c8442d8db8d3ae5d1c6a15e30f2d347e0cd31d057ca72e42566"
dependencies = [
"futures",
"libp2p-core 0.42.0",
"libp2p-core",
"libp2p-identify",
"libp2p-identity",
"libp2p-swarm 0.45.1",
"libp2p-swarm",
"pin-project",
"prometheus-client",
"web-time",
@@ -4866,7 +4751,7 @@ dependencies = [
"asynchronous-codec",
"bytes",
"futures",
"libp2p-core 0.42.0",
"libp2p-core",
"libp2p-identity",
"nohash-hasher",
"parking_lot 0.12.3",
@@ -4886,7 +4771,7 @@ dependencies = [
"bytes",
"curve25519-dalek",
"futures",
"libp2p-core 0.42.0",
"libp2p-core",
"libp2p-identity",
"multiaddr",
"multihash",
@@ -4911,7 +4796,7 @@ dependencies = [
"asynchronous-codec",
"bytes",
"futures",
"libp2p-core 0.42.0",
"libp2p-core",
"libp2p-identity",
"quick-protobuf",
"quick-protobuf-codec",
@@ -4928,7 +4813,7 @@ dependencies = [
"futures",
"futures-timer",
"if-watch",
"libp2p-core 0.42.0",
"libp2p-core",
"libp2p-identity",
"libp2p-tls",
"parking_lot 0.12.3",
@@ -4942,28 +4827,6 @@ dependencies = [
"tracing",
]
[[package]]
name = "libp2p-swarm"
version = "0.44.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80cae6cb75f89dbca53862f9ebe0b9f463aa7b302762fcfaafb9e51dcc9b0f7e"
dependencies = [
"either",
"fnv",
"futures",
"futures-timer",
"instant",
"libp2p-core 0.41.3",
"libp2p-identity",
"lru",
"multistream-select",
"once_cell",
"rand",
"smallvec",
"tracing",
"void",
]
[[package]]
name = "libp2p-swarm"
version = "0.45.1"
@@ -4974,7 +4837,7 @@ dependencies = [
"fnv",
"futures",
"futures-timer",
"libp2p-core 0.42.0",
"libp2p-core",
"libp2p-identity",
"libp2p-swarm-derive",
"lru",
@@ -5010,7 +4873,7 @@ dependencies = [
"futures-timer",
"if-watch",
"libc",
"libp2p-core 0.42.0",
"libp2p-core",
"libp2p-identity",
"socket2 0.5.7",
"tokio",
@@ -5025,7 +4888,7 @@ checksum = "47b23dddc2b9c355f73c1e36eb0c3ae86f7dc964a3715f0731cfad352db4d847"
dependencies = [
"futures",
"futures-rustls",
"libp2p-core 0.42.0",
"libp2p-core",
"libp2p-identity",
"rcgen",
"ring 0.17.8",
@@ -5045,8 +4908,8 @@ dependencies = [
"futures",
"futures-timer",
"igd-next",
"libp2p-core 0.42.0",
"libp2p-swarm 0.45.1",
"libp2p-core",
"libp2p-swarm",
"tokio",
"tracing",
"void",
@@ -5060,7 +4923,7 @@ checksum = "788b61c80789dba9760d8c669a5bedb642c8267555c803fabd8396e4ca5c5882"
dependencies = [
"either",
"futures",
"libp2p-core 0.42.0",
"libp2p-core",
"thiserror",
"tracing",
"yamux 0.12.1",
@@ -5215,7 +5078,7 @@ dependencies = [
"gossipsub",
"hex",
"itertools 0.10.5",
"libp2p 0.54.1",
"libp2p",
"libp2p-mplex",
"lighthouse_metrics",
"lighthouse_version",
@@ -5767,6 +5630,7 @@ name = "network"
version = "0.2.0"
dependencies = [
"alloy-primitives",
"alloy-rlp",
"anyhow",
"async-channel",
"beacon_chain",
@@ -5792,7 +5656,6 @@ dependencies = [
"operation_pool",
"parking_lot 0.12.3",
"rand",
"rlp",
"slog",
"slog-async",
"slog-term",
@@ -6450,19 +6313,7 @@ checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf"
dependencies = [
"cpufeatures",
"opaque-debug",
"universal-hash 0.5.1",
]
[[package]]
name = "polyval"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1"
dependencies = [
"cfg-if",
"cpufeatures",
"opaque-debug",
"universal-hash 0.4.0",
"universal-hash",
]
[[package]]
@@ -6474,7 +6325,7 @@ dependencies = [
"cfg-if",
"cpufeatures",
"opaque-debug",
"universal-hash 0.5.1",
"universal-hash",
]
[[package]]
@@ -8116,7 +7967,7 @@ version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "850948bee068e713b8ab860fe1adc4d109676ab4c3b621fd8147f06b261f2f85"
dependencies = [
"aes-gcm 0.10.3",
"aes-gcm",
"blake2",
"chacha20poly1305",
"curve25519-dalek",
@@ -9205,16 +9056,6 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a"
[[package]]
name = "universal-hash"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402"
dependencies = [
"generic-array",
"subtle",
]
[[package]]
name = "universal-hash"
version = "0.5.1"

View File

@@ -116,7 +116,7 @@ derivative = "2"
dirs = "3"
either = "1.9"
rust_eth_kzg = "0.5.1"
discv5 = { version = "0.4.1", features = ["libp2p"] }
discv5 = { version = "0.7", features = ["libp2p"] }
env_logger = "0.9"
error-chain = "0.12"
ethereum_hashing = "0.7.0"

View File

@@ -45,22 +45,24 @@ pub trait Eth2Enr {
impl Eth2Enr for Enr {
fn attestation_bitfield<E: EthSpec>(&self) -> Result<EnrAttestationBitfield<E>, &'static str> {
let bitfield_bytes = self
.get(ATTESTATION_BITFIELD_ENR_KEY)
.ok_or("ENR attestation bitfield non-existent")?;
let bitfield_bytes: Vec<u8> = self
.get_decodable(ATTESTATION_BITFIELD_ENR_KEY)
.ok_or("ENR attestation bitfield non-existent")?
.map_err(|_| "Invalid RLP Encoding")?;
BitVector::<E::SubnetBitfieldLength>::from_ssz_bytes(bitfield_bytes)
BitVector::<E::SubnetBitfieldLength>::from_ssz_bytes(&bitfield_bytes)
.map_err(|_| "Could not decode the ENR attnets bitfield")
}
fn sync_committee_bitfield<E: EthSpec>(
&self,
) -> Result<EnrSyncCommitteeBitfield<E>, &'static str> {
let bitfield_bytes = self
.get(SYNC_COMMITTEE_BITFIELD_ENR_KEY)
.ok_or("ENR sync committee bitfield non-existent")?;
let bitfield_bytes: Vec<u8> = self
.get_decodable(SYNC_COMMITTEE_BITFIELD_ENR_KEY)
.ok_or("ENR sync committee bitfield non-existent")?
.map_err(|_| "Invalid RLP Encoding")?;
BitVector::<E::SyncCommitteeSubnetCount>::from_ssz_bytes(bitfield_bytes)
BitVector::<E::SyncCommitteeSubnetCount>::from_ssz_bytes(&bitfield_bytes)
.map_err(|_| "Could not decode the ENR syncnets bitfield")
}
@@ -78,9 +80,12 @@ impl Eth2Enr for Enr {
}
fn eth2(&self) -> Result<EnrForkId, &'static str> {
let eth2_bytes = self.get(ETH2_ENR_KEY).ok_or("ENR has no eth2 field")?;
let eth2_bytes: Vec<u8> = self
.get_decodable(ETH2_ENR_KEY)
.ok_or("ENR has no eth2 field")?
.map_err(|_| "Invalid RLP Encoding")?;
EnrForkId::from_ssz_bytes(eth2_bytes).map_err(|_| "Could not decode EnrForkId")
EnrForkId::from_ssz_bytes(&eth2_bytes).map_err(|_| "Could not decode EnrForkId")
}
}
@@ -270,16 +275,16 @@ fn compare_enr(local_enr: &Enr, disk_enr: &Enr) -> bool {
&& local_enr.quic4() == disk_enr.quic4()
&& local_enr.quic6() == disk_enr.quic6()
// must match on the same fork
&& local_enr.get(ETH2_ENR_KEY) == disk_enr.get(ETH2_ENR_KEY)
&& local_enr.get_decodable::<Vec<u8>>(ETH2_ENR_KEY) == disk_enr.get_decodable(ETH2_ENR_KEY)
// take preference over disk udp port if one is not specified
&& (local_enr.udp4().is_none() || local_enr.udp4() == disk_enr.udp4())
&& (local_enr.udp6().is_none() || local_enr.udp6() == disk_enr.udp6())
// we need the ATTESTATION_BITFIELD_ENR_KEY and SYNC_COMMITTEE_BITFIELD_ENR_KEY and
// PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY key to match, otherwise we use a new ENR. This will
// likely only be true for non-validating nodes.
&& local_enr.get(ATTESTATION_BITFIELD_ENR_KEY) == disk_enr.get(ATTESTATION_BITFIELD_ENR_KEY)
&& local_enr.get(SYNC_COMMITTEE_BITFIELD_ENR_KEY) == disk_enr.get(SYNC_COMMITTEE_BITFIELD_ENR_KEY)
&& local_enr.get(PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY) == disk_enr.get(PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY)
&& local_enr.get_decodable::<Vec<u8>>(ATTESTATION_BITFIELD_ENR_KEY) == disk_enr.get_decodable(ATTESTATION_BITFIELD_ENR_KEY)
&& local_enr.get_decodable::<Vec<u8>>(SYNC_COMMITTEE_BITFIELD_ENR_KEY) == disk_enr.get_decodable(SYNC_COMMITTEE_BITFIELD_ENR_KEY)
&& local_enr.get_decodable::<Vec<u8>>(PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY) == disk_enr.get_decodable(PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY)
}
/// Loads enr from the given directory

View File

@@ -1072,10 +1072,7 @@ impl<E: EthSpec> NetworkBehaviour for Discovery<E> {
// NOTE: We assume libp2p itself can keep track of IP changes and we do
// not inform it about IP changes found via discovery.
}
discv5::Event::EnrAdded { .. }
| discv5::Event::TalkRequest(_)
| discv5::Event::NodeInserted { .. }
| discv5::Event::SessionEstablished { .. } => {} // Ignore all other discv5 server events
_ => {} // Ignore all other discv5 server events
}
}
}

View File

@@ -33,7 +33,7 @@ tokio-stream = { workspace = true }
smallvec = { workspace = true }
rand = { workspace = true }
fnv = { workspace = true }
rlp = "0.5.0"
alloy-rlp = { workspace = true }
lighthouse_metrics = { workspace = true }
logging = { workspace = true }
task_executor = { workspace = true }

View File

@@ -45,14 +45,23 @@ impl StoreItem for PersistedDht {
}
fn as_store_bytes(&self) -> Vec<u8> {
rlp::encode_list(&self.enrs).to_vec()
let mut buffer = Vec::<u8>::new();
alloy_rlp::encode_list(&self.enrs, &mut buffer);
buffer
}
fn from_store_bytes(bytes: &[u8]) -> Result<Self, StoreError> {
let rlp = rlp::Rlp::new(bytes);
let enrs: Vec<Enr> = rlp
.as_list()
.map_err(|e| StoreError::RlpError(format!("{}", e)))?;
let mut enrs: Vec<Enr> = Vec::new();
let mut rlp = alloy_rlp::Rlp::new(bytes)
.map_err(|e| StoreError::RlpError(format!("Failed to decode RLP: {}", e)))?;
loop {
match rlp.get_next() {
Ok(Some(enr)) => enrs.push(enr),
Ok(None) => break, // No more list elements
Err(e) => return Err(StoreError::RlpError(format!("{}", e))),
}
}
Ok(PersistedDht { enrs })
}
}

View File

@@ -145,16 +145,13 @@ pub async fn run<E: EthSpec>(
Some(event) = event_stream.recv() => {
match event {
discv5::Event::Discovered(_enr) => {
// An ENR has bee obtained by the server
// An ENR has been obtained by the server
// Ignore these events here
}
discv5::Event::EnrAdded { .. } => {} // Ignore
discv5::Event::TalkRequest(_) => {} // Ignore
discv5::Event::NodeInserted { .. } => {} // Ignore
discv5::Event::SocketUpdated(socket_addr) => {
info!(log, "Advertised socket address updated"; "socket_addr" => %socket_addr);
}
discv5::Event::SessionEstablished{ .. } => {} // Ignore
_ => {} // Ignore
}
}
}