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

View File

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

View File

@@ -45,22 +45,24 @@ pub trait Eth2Enr {
impl Eth2Enr for Enr { impl Eth2Enr for Enr {
fn attestation_bitfield<E: EthSpec>(&self) -> Result<EnrAttestationBitfield<E>, &'static str> { fn attestation_bitfield<E: EthSpec>(&self) -> Result<EnrAttestationBitfield<E>, &'static str> {
let bitfield_bytes = self let bitfield_bytes: Vec<u8> = self
.get(ATTESTATION_BITFIELD_ENR_KEY) .get_decodable(ATTESTATION_BITFIELD_ENR_KEY)
.ok_or("ENR attestation bitfield non-existent")?; .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") .map_err(|_| "Could not decode the ENR attnets bitfield")
} }
fn sync_committee_bitfield<E: EthSpec>( fn sync_committee_bitfield<E: EthSpec>(
&self, &self,
) -> Result<EnrSyncCommitteeBitfield<E>, &'static str> { ) -> Result<EnrSyncCommitteeBitfield<E>, &'static str> {
let bitfield_bytes = self let bitfield_bytes: Vec<u8> = self
.get(SYNC_COMMITTEE_BITFIELD_ENR_KEY) .get_decodable(SYNC_COMMITTEE_BITFIELD_ENR_KEY)
.ok_or("ENR sync committee bitfield non-existent")?; .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") .map_err(|_| "Could not decode the ENR syncnets bitfield")
} }
@@ -78,9 +80,12 @@ impl Eth2Enr for Enr {
} }
fn eth2(&self) -> Result<EnrForkId, &'static str> { 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.quic4() == disk_enr.quic4()
&& local_enr.quic6() == disk_enr.quic6() && local_enr.quic6() == disk_enr.quic6()
// must match on the same fork // 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 // take preference over disk udp port if one is not specified
&& (local_enr.udp4().is_none() || local_enr.udp4() == disk_enr.udp4()) && (local_enr.udp4().is_none() || local_enr.udp4() == disk_enr.udp4())
&& (local_enr.udp6().is_none() || local_enr.udp6() == disk_enr.udp6()) && (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 // 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 // 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. // 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_decodable::<Vec<u8>>(ATTESTATION_BITFIELD_ENR_KEY) == disk_enr.get_decodable(ATTESTATION_BITFIELD_ENR_KEY)
&& local_enr.get(SYNC_COMMITTEE_BITFIELD_ENR_KEY) == disk_enr.get(SYNC_COMMITTEE_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(PEERDAS_CUSTODY_SUBNET_COUNT_ENR_KEY) == disk_enr.get(PEERDAS_CUSTODY_SUBNET_COUNT_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 /// 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 // NOTE: We assume libp2p itself can keep track of IP changes and we do
// not inform it about IP changes found via discovery. // not inform it about IP changes found via discovery.
} }
discv5::Event::EnrAdded { .. } _ => {} // Ignore all other discv5 server events
| discv5::Event::TalkRequest(_)
| discv5::Event::NodeInserted { .. }
| discv5::Event::SessionEstablished { .. } => {} // Ignore all other discv5 server events
} }
} }
} }

View File

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

View File

@@ -45,14 +45,23 @@ impl StoreItem for PersistedDht {
} }
fn as_store_bytes(&self) -> Vec<u8> { 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> { fn from_store_bytes(bytes: &[u8]) -> Result<Self, StoreError> {
let rlp = rlp::Rlp::new(bytes); let mut enrs: Vec<Enr> = Vec::new();
let enrs: Vec<Enr> = rlp let mut rlp = alloy_rlp::Rlp::new(bytes)
.as_list() .map_err(|e| StoreError::RlpError(format!("Failed to decode RLP: {}", e)))?;
.map_err(|e| StoreError::RlpError(format!("{}", 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 }) Ok(PersistedDht { enrs })
} }
} }

View File

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