From 17ad54dea6366c633161470a6cfe4c6cabf63802 Mon Sep 17 00:00:00 2001 From: Tumas Date: Wed, 30 Oct 2024 11:59:07 +0200 Subject: [PATCH] Update eth2_libp2p - This updates both `libp2p` and `discv5` - Remove duplicated `BlobSidecarSubnetCount` type --- Cargo.lock | 316 ++++++++++------------------- Cargo.toml | 8 +- eth2_libp2p | 2 +- fork_choice_control/src/helpers.rs | 2 +- fork_choice_store/src/store.rs | 3 +- helper_functions/src/misc.rs | 6 +- p2p/src/messages.rs | 8 +- p2p/src/network.rs | 150 ++++++++++---- runtime/src/runtime.rs | 5 +- types/src/combined.rs | 72 +++++++ types/src/deneb/consts.rs | 5 +- 11 files changed, 301 insertions(+), 276 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b40252c9..20e29f20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,15 +36,6 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" -[[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" @@ -55,19 +46,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "aes" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" -dependencies = [ - "cfg-if", - "cipher 0.3.0", - "cpufeatures", - "ctr 0.8.0", - "opaque-debug", -] - [[package]] name = "aes" version = "0.8.4" @@ -75,36 +53,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" dependencies = [ "cfg-if", - "cipher 0.4.4", + "cipher", "cpufeatures", "zeroize", ] -[[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", - "aes 0.8.4", - "cipher 0.4.4", - "ctr 0.9.2", - "ghash 0.5.1", + "aead", + "aes", + "cipher", + "ctr", + "ghash", "subtle", ] @@ -142,6 +106,16 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +[[package]] +name = "alloy-rlp" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0822426598f95e45dd1ea32a738dac057529a709ee645fcc516ffa4cbde08f" +dependencies = [ + "arrayvec", + "bytes", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -493,19 +467,6 @@ dependencies = [ "syn 2.0.79", ] -[[package]] -name = "asynchronous-codec" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4057f2c32adbb2fc158e22fb38433c8e9bbf76b75a4732c7c0cbaf695fb65568" -dependencies = [ - "bytes", - "futures-sink", - "futures-util", - "memchr", - "pin-project-lite", -] - [[package]] name = "asynchronous-codec" version = "0.7.0" @@ -1137,7 +1098,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" dependencies = [ "cfg-if", - "cipher 0.4.4", + "cipher", "cpufeatures", ] @@ -1147,9 +1108,9 @@ 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", + "cipher", "poly1305", "zeroize", ] @@ -1196,15 +1157,6 @@ dependencies = [ "half", ] -[[package]] -name = "cipher" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" -dependencies = [ - "generic-array", -] - [[package]] name = "cipher" version = "0.4.4" @@ -1544,31 +1496,13 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "026ac6ceace6298d2c557ef5ed798894962296469ec7842288ea64674201a2d1" -[[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" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "049bb91fb4aaf0e3c7efa6cd5ef877dbbbd15b39dad06d9948de4ec8a75761ea" -dependencies = [ - "cipher 0.3.0", -] - [[package]] name = "ctr" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" dependencies = [ - "cipher 0.4.4", + "cipher", ] [[package]] @@ -1915,13 +1849,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", + "aes-gcm", + "alloy-rlp", "arrayvec", + "ctr", "delay_map 0.3.0", "enr", "fnv", @@ -1930,12 +1866,12 @@ dependencies = [ "hex", "hkdf", "lazy_static", - "libp2p", + "libp2p-identity", "lru", "more-asserts", + "multiaddr", "parking_lot 0.11.2", "rand", - "rlp", "smallvec", "socket2 0.4.10", "tokio", @@ -2054,10 +1990,10 @@ dependencies = [ name = "eip_2335" version = "0.0.0" dependencies = [ - "aes 0.8.4", + "aes", "anyhow", "bls", - "ctr 0.9.2", + "ctr", "derive_more 1.0.0", "hex", "hex-literal", @@ -2140,10 +2076,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", @@ -2151,7 +2088,6 @@ dependencies = [ "k256", "log", "rand", - "rlp", "serde", "sha3", "zeroize", @@ -2370,10 +2306,11 @@ dependencies = [ name = "eth2_libp2p" version = "0.2.0" dependencies = [ + "alloy-rlp", "anyhow", "async-channel 1.9.0", "async-std", - "asynchronous-codec 0.7.0", + "asynchronous-codec", "bls", "bytes", "delay_map 0.4.0", @@ -2390,6 +2327,7 @@ dependencies = [ "grandine_version", "helper_functions", "hex", + "itertools 0.13.0", "libp2p", "libp2p-mplex", "lru", @@ -2398,7 +2336,7 @@ dependencies = [ "prometheus", "prometheus-client", "quick-protobuf", - "quick-protobuf-codec 0.3.1", + "quick-protobuf-codec", "quickcheck", "quickcheck_macros", "rand", @@ -2411,6 +2349,7 @@ dependencies = [ "smallvec", "snap", "ssz", + "std_ext", "strum", "tempfile", "tiny-keccak", @@ -2930,16 +2869,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" @@ -2947,7 +2876,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1" dependencies = [ "opaque-debug", - "polyval 0.6.2", + "polyval", ] [[package]] @@ -3009,7 +2938,7 @@ name = "gossipsub" version = "0.5.0" dependencies = [ "async-channel 1.9.0", - "asynchronous-codec 0.7.0", + "asynchronous-codec", "base64 0.21.7", "byteorder", "bytes", @@ -3024,7 +2953,7 @@ dependencies = [ "libp2p", "prometheus-client", "quick-protobuf", - "quick-protobuf-codec 0.3.1", + "quick-protobuf-codec", "quickcheck", "rand", "regex", @@ -4453,16 +4382,15 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "libp2p" -version = "0.53.2" +version = "0.54.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "681fb3f183edfbedd7a57d32ebe5dcdc0b9f94061185acf3c30249349cc6fc99" +checksum = "bbbe80f9c7e00526cd6b838075b9c171919404a4732cb2fa8ece0a093223bfc4" dependencies = [ "bytes", "either", "futures", "futures-timer", "getrandom", - "instant", "libp2p-allow-block-list", "libp2p-connection-limits", "libp2p-core", @@ -4488,9 +4416,9 @@ dependencies = [ [[package]] name = "libp2p-allow-block-list" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "107b238b794cb83ab53b74ad5dcf7cca3200899b72fe662840cfb52f5b0a32e6" +checksum = "d1027ccf8d70320ed77e984f273bc8ce952f623762cb9bf2d126df73caef8041" dependencies = [ "libp2p-core", "libp2p-identity", @@ -4500,9 +4428,9 @@ dependencies = [ [[package]] name = "libp2p-connection-limits" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7cd50a78ccfada14de94cbacd3ce4b0138157f376870f13d3a8422cd075b4fd" +checksum = "8d003540ee8baef0d254f7b6bfd79bac3ddf774662ca0abf69186d517ef82ad8" dependencies = [ "libp2p-core", "libp2p-identity", @@ -4512,9 +4440,9 @@ dependencies = [ [[package]] name = "libp2p-core" -version = "0.41.3" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5a8920cbd8540059a01950c1e5c96ea8d89eb50c51cd366fc18bdf540a6e48f" +checksum = "a61f26c83ed111104cd820fe9bc3aaabbac5f1652a1d213ed6e900b7918a1298" dependencies = [ "either", "fnv", @@ -4541,9 +4469,9 @@ dependencies = [ [[package]] name = "libp2p-dns" -version = "0.41.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d17cbcf7160ff35c3e8e560de4a068fe9d6cb777ea72840e48eb76ff9576c4b6" +checksum = "97f37f30d5c7275db282ecd86e54f29dd2176bd3ac656f06abf43bedb21eb8bd" dependencies = [ "async-trait", "futures", @@ -4557,12 +4485,12 @@ dependencies = [ [[package]] name = "libp2p-gossipsub" -version = "0.46.1" +version = "0.47.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d665144a616dadebdc5fff186b1233488cdcd8bfb1223218ff084b6d052c94f7" +checksum = "b4e830fdf24ac8c444c12415903174d506e1e077fbe3875c404a78c5935a8543" dependencies = [ - "asynchronous-codec 0.7.0", - "base64 0.21.7", + "asynchronous-codec", + "base64 0.22.1", "byteorder", "bytes", "either", @@ -4571,13 +4499,12 @@ dependencies = [ "futures-ticker", "getrandom", "hex_fmt", - "instant", "libp2p-core", "libp2p-identity", "libp2p-swarm", "prometheus-client", "quick-protobuf", - "quick-protobuf-codec 0.3.1", + "quick-protobuf-codec", "rand", "regex", "serde", @@ -4585,15 +4512,16 @@ dependencies = [ "smallvec", "tracing", "void", + "web-time", ] [[package]] name = "libp2p-identify" -version = "0.44.2" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5d635ebea5ca0c3c3e77d414ae9b67eccf2a822be06091b9c1a0d13029a1e2f" +checksum = "1711b004a273be4f30202778856368683bd9a83c4c7dcc8f848847606831a4e3" dependencies = [ - "asynchronous-codec 0.7.0", + "asynchronous-codec", "either", "futures", "futures-bounded", @@ -4603,7 +4531,7 @@ dependencies = [ "libp2p-swarm", "lru", "quick-protobuf", - "quick-protobuf-codec 0.3.1", + "quick-protobuf-codec", "smallvec", "thiserror", "tracing", @@ -4636,24 +4564,23 @@ dependencies = [ [[package]] name = "libp2p-kad" -version = "0.45.3" +version = "0.46.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc5767727d062c4eac74dd812c998f0e488008e82cce9c33b463d38423f9ad2" +checksum = "ced237d0bd84bbebb7c2cad4c073160dacb4fe40534963c32ed6d4c6bb7702a3" dependencies = [ "arrayvec", - "asynchronous-codec 0.7.0", + "asynchronous-codec", "bytes", "either", "fnv", "futures", "futures-bounded", "futures-timer", - "instant", "libp2p-core", "libp2p-identity", "libp2p-swarm", "quick-protobuf", - "quick-protobuf-codec 0.3.1", + "quick-protobuf-codec", "rand", "serde", "sha2 0.10.8", @@ -4662,13 +4589,14 @@ dependencies = [ "tracing", "uint", "void", + "web-time", ] [[package]] name = "libp2p-mdns" -version = "0.45.1" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49007d9a339b3e1d7eeebc4d67c05dbf23d300b7d091193ec2d3f26802d7faf2" +checksum = "14b8546b6644032565eb29046b42744aee1e9f261ed99671b2c93fb140dba417" dependencies = [ "data-encoding", "futures", @@ -4687,27 +4615,27 @@ dependencies = [ [[package]] name = "libp2p-metrics" -version = "0.14.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdac91ae4f291046a3b2660c039a2830c931f84df2ee227989af92f7692d3357" +checksum = "77ebafa94a717c8442d8db8d3ae5d1c6a15e30f2d347e0cd31d057ca72e42566" dependencies = [ "futures", - "instant", "libp2p-core", "libp2p-identify", "libp2p-identity", "libp2p-swarm", "pin-project", "prometheus-client", + "web-time", ] [[package]] name = "libp2p-mplex" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e895765e27e30217b25f7cb7ac4686dad1ff80bf2fdeffd1d898566900a924" +checksum = "41187ab8f6c835ad864edf94224f666f636ee2d270601422c1441f739e0abccc" dependencies = [ - "asynchronous-codec 0.6.2", + "asynchronous-codec", "bytes", "futures", "libp2p-core", @@ -4717,16 +4645,16 @@ dependencies = [ "rand", "smallvec", "tracing", - "unsigned-varint 0.7.2", + "unsigned-varint 0.8.0", ] [[package]] name = "libp2p-noise" -version = "0.44.0" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecd0545ce077f6ea5434bcb76e8d0fe942693b4380aaad0d34a358c2bd05793" +checksum = "36b137cb1ae86ee39f8e5d6245a296518912014eaa87427d24e6ff58cfc1b28c" dependencies = [ - "asynchronous-codec 0.7.0", + "asynchronous-codec", "bytes", "curve25519-dalek", "futures", @@ -4748,25 +4676,25 @@ dependencies = [ [[package]] name = "libp2p-plaintext" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67330af40b67217e746d42551913cfb7ad04c74fa300fb329660a56318590b3f" +checksum = "5b63d926c6be56a2489e0e7316b17fe95a70bc5c4f3e85740bb3e67c0f3c6a44" dependencies = [ - "asynchronous-codec 0.6.2", + "asynchronous-codec", "bytes", "futures", "libp2p-core", "libp2p-identity", "quick-protobuf", - "quick-protobuf-codec 0.2.0", + "quick-protobuf-codec", "tracing", ] [[package]] name = "libp2p-quic" -version = "0.10.3" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c67296ad4e092e23f92aea3d2bdb6f24eab79c0929ed816dfb460ea2f4567d2b" +checksum = "46352ac5cd040c70e88e7ff8257a2ae2f891a4076abad2c439584a31c15fd24e" dependencies = [ "bytes", "futures", @@ -4788,15 +4716,14 @@ dependencies = [ [[package]] name = "libp2p-swarm" -version = "0.44.2" +version = "0.45.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80cae6cb75f89dbca53862f9ebe0b9f463aa7b302762fcfaafb9e51dcc9b0f7e" +checksum = "d7dd6741793d2c1fb2088f67f82cf07261f25272ebe3c0b0c311e0c6b50e851a" dependencies = [ "either", "fnv", "futures", "futures-timer", - "instant", "libp2p-core", "libp2p-identity", "libp2p-swarm-derive", @@ -4808,13 +4735,14 @@ dependencies = [ "tokio", "tracing", "void", + "web-time", ] [[package]] name = "libp2p-swarm-derive" -version = "0.34.2" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5daceb9dd908417b6dfcfe8e94098bc4aac54500c282e78120b885dadc09b999" +checksum = "206e0aa0ebe004d778d79fb0966aa0de996c19894e2c0605ba2f8524dd4443d8" dependencies = [ "heck 0.5.0", "proc-macro2 1.0.86", @@ -4824,9 +4752,9 @@ dependencies = [ [[package]] name = "libp2p-tcp" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b2460fc2748919adff99ecbc1aab296e4579e41f374fb164149bd2c9e529d4c" +checksum = "ad964f312c59dcfcac840acd8c555de8403e295d39edf96f5240048b5fcaa314" dependencies = [ "futures", "futures-timer", @@ -4841,9 +4769,9 @@ dependencies = [ [[package]] name = "libp2p-tls" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b7b831e55ce2aa6c354e6861a85fdd4dd0a2b97d5e276fabac0e4810a71776" +checksum = "47b23dddc2b9c355f73c1e36eb0c3ae86f7dc964a3715f0731cfad352db4d847" dependencies = [ "futures", "futures-rustls", @@ -4860,9 +4788,9 @@ dependencies = [ [[package]] name = "libp2p-upnp" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccf04b0e3ff3de52d07d5fd6c3b061d0e7f908ffc683c32d9638caedce86fc8" +checksum = "01bf2d1b772bd3abca049214a3304615e6a36fa6ffc742bdd1ba774486200b8f" dependencies = [ "futures", "futures-timer", @@ -4876,9 +4804,9 @@ dependencies = [ [[package]] name = "libp2p-yamux" -version = "0.45.2" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddd5265f6b80f94d48a3963541aad183cc598a645755d2f1805a373e41e0716b" +checksum = "788b61c80789dba9760d8c669a5bedb642c8267555c803fabd8396e4ca5c5882" dependencies = [ "either", "futures", @@ -5953,19 +5881,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]] @@ -5977,7 +5893,7 @@ dependencies = [ "cfg-if", "cpufeatures", "opaque-debug", - "universal-hash 0.5.1", + "universal-hash", ] [[package]] @@ -6195,26 +6111,13 @@ dependencies = [ "byteorder", ] -[[package]] -name = "quick-protobuf-codec" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8ededb1cd78531627244d51dd0c7139fbe736c7d57af0092a76f0ffb2f56e98" -dependencies = [ - "asynchronous-codec 0.6.2", - "bytes", - "quick-protobuf", - "thiserror", - "unsigned-varint 0.7.2", -] - [[package]] name = "quick-protobuf-codec" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15a0580ab32b169745d7a39db2ba969226ca16738931be152a3209b409de2474" dependencies = [ - "asynchronous-codec 0.7.0", + "asynchronous-codec", "bytes", "quick-protobuf", "thiserror", @@ -6874,7 +6777,7 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213" dependencies = [ - "cipher 0.4.4", + "cipher", ] [[package]] @@ -7454,7 +7357,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", @@ -8381,16 +8284,6 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" -[[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" @@ -8412,10 +8305,6 @@ name = "unsigned-varint" version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6889a77d49f1f013504cec6bf97a2c730394adedaeb1deb5ea08949a50541105" -dependencies = [ - "asynchronous-codec 0.6.2", - "bytes", -] [[package]] name = "unsigned-varint" @@ -8423,6 +8312,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb066959b24b5196ae73cb057f45598450d2c5f71460e98c49b738086eff9c06" dependencies = [ + "asynchronous-codec", "bytes", "tokio-util", ] diff --git a/Cargo.toml b/Cargo.toml index 7183fb16..e4a56794 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -275,6 +275,7 @@ private_intra_doc_links = 'allow' [workspace.dependencies] aes = { version = '0.8', features = ['zeroize'] } +alloy-rlp = '0.3.9' anyhow = { version = '1', features = ['backtrace'] } arc-swap = '1' assert-json-diff = '2' @@ -309,7 +310,7 @@ delay_map = '0.4' derivative = '2' derive_more = { version = '1', features = ["full"] } dirs = '5' -discv5 = { version = '0.4', features = ['libp2p'] } +discv5 = { version = '0.7', features = ['libp2p'] } drain_filter_polyfill = '0.1' duplicate = '1' easy-ext = '1' @@ -332,6 +333,7 @@ git-version = '0.3' glob = '0.3' good_lp = { version = '1', default-features = false, features = ['highs'] } hash_hasher = '2' +hashlink = '0.9' hex = { version = '0.4', features = ['serde'] } hex-literal = '0.4' hex_fmt = '0.3' @@ -355,8 +357,8 @@ jwt-simple = { version = '0.12', default-features = false, features = ['pure-rus kzg = { git = 'https://github.com/grandinetech/rust-kzg.git', branch = 'integration-raw' } lazy_static = '1' libmdbx = { git = 'https://github.com/paradigmxyz/reth.git', package = 'reth-libmdbx', rev = 'c228fe15808c3acbf18dc3af1a03ef5cbdcda07a' } -libp2p = { version = '0.53', default-features = false, features = ['metrics', 'dns', 'ecdsa', 'identify', 'macros', 'noise', 'plaintext', 'secp256k1', 'serde', 'tcp', 'tokio', 'yamux', 'quic', 'upnp'] } -libp2p-mplex = '0.41' +libp2p = { version = '0.54', default-features = false, features = ['metrics', 'dns', 'ecdsa', 'identify', 'macros', 'noise', 'plaintext', 'secp256k1', 'serde', 'tcp', 'tokio', 'yamux', 'quic', 'upnp'] } +libp2p-mplex = '0.42' log = '0.4' lru = '0.12' mediatype = '0.19' diff --git a/eth2_libp2p b/eth2_libp2p index 6328be39..cd94317b 160000 --- a/eth2_libp2p +++ b/eth2_libp2p @@ -1 +1 @@ -Subproject commit 6328be3924252d5e8bd6b7a7207f26ba1aee9faf +Subproject commit cd94317bcf623e7f501cfd5370423bd95fdaff65 diff --git a/fork_choice_control/src/helpers.rs b/fork_choice_control/src/helpers.rs index 6560ebe8..9b62421d 100644 --- a/fork_choice_control/src/helpers.rs +++ b/fork_choice_control/src/helpers.rs @@ -253,7 +253,7 @@ impl Context

{ } pub fn on_blob_sidecar(&mut self, blob_sidecar: BlobSidecar

) -> Option> { - let subnet_id = misc::compute_subnet_for_blob_sidecar(blob_sidecar.index); + let subnet_id = misc::compute_subnet_for_blob_sidecar(self.config(), blob_sidecar.index); self.controller().on_gossip_blob_sidecar( Arc::new(blob_sidecar), diff --git a/fork_choice_store/src/store.rs b/fork_choice_store/src/store.rs index 62384c11..3af44240 100644 --- a/fork_choice_store/src/store.rs +++ b/fork_choice_store/src/store.rs @@ -1706,7 +1706,8 @@ impl Store

{ // [REJECT] The sidecar is for the correct subnet -- i.e. compute_subnet_for_blob_sidecar(blob_sidecar.index) == subnet_id. if let Some(actual) = origin.subnet_id() { - let expected = misc::compute_subnet_for_blob_sidecar(blob_sidecar.index); + let expected = + misc::compute_subnet_for_blob_sidecar(&self.chain_config, blob_sidecar.index); ensure!( actual == expected, diff --git a/helper_functions/src/misc.rs b/helper_functions/src/misc.rs index c5818a64..a730d935 100644 --- a/helper_functions/src/misc.rs +++ b/helper_functions/src/misc.rs @@ -17,7 +17,7 @@ use types::{ combined::{Attestation, SignedBeaconBlock}, config::Config, deneb::{ - consts::{BlobCommitmentTreeDepth, BlobSidecarSubnetCount, VERSIONED_HASH_VERSION_KZG}, + consts::{BlobCommitmentTreeDepth, VERSIONED_HASH_VERSION_KZG}, containers::BlobSidecar, primitives::{ Blob, BlobCommitmentInclusionProof, BlobIndex, KzgCommitment, KzgProof, VersionedHash, @@ -204,8 +204,8 @@ pub fn compute_subnet_for_attestation( /// [`compute_subnet_for_blob_sidecar`](https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/deneb/validator.md#sidecar) #[must_use] -pub fn compute_subnet_for_blob_sidecar(blob_index: BlobIndex) -> SubnetId { - blob_index.mod_typenum::() +pub const fn compute_subnet_for_blob_sidecar(config: &Config, blob_index: BlobIndex) -> SubnetId { + blob_index % config.blob_sidecar_subnet_count } /// diff --git a/p2p/src/messages.rs b/p2p/src/messages.rs index 377c8324..7b37f701 100644 --- a/p2p/src/messages.rs +++ b/p2p/src/messages.rs @@ -3,10 +3,10 @@ use std::{collections::BTreeMap, sync::Arc}; use anyhow::Result; use bls::PublicKeyBytes; use eth2_libp2p::{ - rpc::{GoodbyeReason, StatusMessage}, + rpc::{GoodbyeReason, RequestId as IncomingRequestId, RequestType, StatusMessage}, types::{EnrForkId, GossipKind}, GossipId, GossipTopic, MessageAcceptance, NetworkEvent, PeerAction, PeerId, PeerRequestId, - PubsubMessage, ReportSource, Request, Response, Subnet, SubnetDiscovery, + PubsubMessage, ReportSource, Response, Subnet, SubnetDiscovery, }; use futures::channel::{mpsc::UnboundedSender, oneshot::Sender}; use log::debug; @@ -195,8 +195,8 @@ pub enum ServiceInboundMessage { Publish(PubsubMessage

), ReportPeer(PeerId, PeerAction, ReportSource, &'static str), ReportMessageValidationResult(GossipId, MessageAcceptance), - SendRequest(PeerId, RequestId, Request), - SendResponse(PeerId, PeerRequestId, Box>), + SendRequest(PeerId, RequestId, RequestType

), + SendResponse(PeerId, PeerRequestId, IncomingRequestId, Box>), Subscribe(GossipTopic), SubscribeKind(GossipKind), SubscribeNewForkTopics(Phase, ForkDigest), diff --git a/p2p/src/network.rs b/p2p/src/network.rs index 17d3fd63..9f8eb6e9 100644 --- a/p2p/src/network.rs +++ b/p2p/src/network.rs @@ -12,15 +12,15 @@ use eth1_api::RealController; use eth2_libp2p::{ rpc::{ methods::{ - BlobsByRangeRequest, BlobsByRootRequest, BlocksByRangeRequest, BlocksByRootRequest, + BlobsByRangeRequest, BlobsByRootRequest, BlocksByRootRequest, OldBlocksByRangeRequest, }, - GoodbyeReason, StatusMessage, + GoodbyeReason, Request, RequestId as IncomingRequestId, RequestType, StatusMessage, }, service::Network as Service, types::{core_topics_to_subscribe, EnrForkId, ForkContext, GossipEncoding}, Context, GossipId, GossipTopic, MessageAcceptance, MessageId, NetworkConfig, NetworkEvent, - NetworkGlobals, PeerAction, PeerId, PeerRequestId, PubsubMessage, ReportSource, Request, - Response, ShutdownReason, Subnet, SubnetDiscovery, SyncInfo, SyncStatus, TaskExecutor, + NetworkGlobals, PeerAction, PeerId, PeerRequestId, PubsubMessage, ReportSource, Response, + ShutdownReason, Subnet, SubnetDiscovery, SyncInfo, SyncStatus, TaskExecutor, }; use fork_choice_control::{BlockWithRoot, P2pMessage}; use futures::{ @@ -125,7 +125,7 @@ impl Network

{ #[allow(clippy::too_many_arguments)] pub async fn new( - network_config: &NetworkConfig, + network_config: Arc, controller: RealController

, slot: Slot, channels: Channels

, @@ -150,7 +150,8 @@ impl Network

{ let executor = TaskExecutor::new(logger.clone(), shutdown_tx); let context = Context { - config: network_config, + chain_config: chain_config.clone_arc(), + config: network_config.clone_arc(), enr_fork_id, fork_context: fork_context.clone_arc(), libp2p_registry, @@ -168,7 +169,7 @@ impl Network

{ let mut port_mappings = None; if network_config.upnp_enabled && !network_config.disable_discovery { - match PortMappings::new(network_config) { + match PortMappings::new(&network_config) { Ok(mappings) => port_mappings = Some(mappings), Err(error) => warn!("error while initializing UPnP: {error}"), } @@ -533,7 +534,11 @@ impl Network

{ } fn publish_blob_sidecar(&self, blob_sidecar: Arc>) { - let subnet_id = misc::compute_subnet_for_blob_sidecar(blob_sidecar.index); + let subnet_id = misc::compute_subnet_for_blob_sidecar( + self.controller.chain_config(), + blob_sidecar.index, + ); + let blob_identifier: BlobIdentifier = blob_sidecar.as_ref().into(); debug!("publishing blob sidecar: {blob_identifier:?}, subnet_id: {subnet_id}"); @@ -826,43 +831,67 @@ impl Network

{ &self, peer_id: PeerId, peer_request_id: PeerRequestId, - request: Request, + request: Request

, ) -> Result<()> { - match request { - Request::Status(remote) => { - self.handle_status_request(peer_id, peer_request_id, remote); + let request_id = request.id; + + match request.r#type { + RequestType::Status(remote) => { + self.handle_status_request(peer_id, peer_request_id, request_id, remote); Ok(()) } - Request::BlocksByRange(request) => { - self.handle_blocks_by_range_request(peer_id, peer_request_id, request) + RequestType::BlocksByRange(request) => { + self.handle_blocks_by_range_request(peer_id, peer_request_id, request_id, request) + } + RequestType::BlocksByRoot(request) => { + self.handle_blocks_by_root_request(peer_id, peer_request_id, request_id, request); + Ok(()) + } + RequestType::DataColumnsByRange(_) => { + debug!("received DataColumnsByRange request (peer_id: {peer_id})"); + Ok(()) } - Request::BlocksByRoot(request) => { - self.handle_blocks_by_root_request(peer_id, peer_request_id, request); + RequestType::DataColumnsByRoot(_) => { + debug!("received DataColumnsByRoot request (peer_id: {peer_id})"); Ok(()) } - Request::LightClientBootstrap(_) => { + RequestType::LightClientBootstrap(_) => { // TODO(Altair Light Client Sync Protocol) debug!("received LightClientBootstrap request (peer_id: {peer_id})"); - Ok(()) } - Request::LightClientFinalityUpdate => { + RequestType::LightClientFinalityUpdate => { // TODO(Altair Light Client Sync Protocol) debug!("received LightClientFinalityUpdate request (peer_id: {peer_id})"); - Ok(()) } - Request::LightClientOptimisticUpdate => { + RequestType::LightClientOptimisticUpdate => { // TODO(Altair Light Client Sync Protocol) debug!("received LightClientOptimisticUpdate request (peer_id: {peer_id})"); - Ok(()) } - Request::BlobsByRange(request) => { - self.handle_blobs_by_range_request(peer_id, peer_request_id, request) + RequestType::LightClientUpdatesByRange(_) => { + // TODO(Altair Light Client Sync Protocol) + debug!("received LightClientUpdatesByRange request (peer_id: {peer_id})"); + Ok(()) + } + RequestType::BlobsByRange(request) => { + self.handle_blobs_by_range_request(peer_id, peer_request_id, request_id, request) + } + RequestType::BlobsByRoot(request) => { + self.handle_blobs_by_root_request(peer_id, peer_request_id, request_id, request); + Ok(()) + } + RequestType::Goodbye(goodbye_reason) => { + debug!("received GoodBye request (peer_id: {peer_id}, reason: {goodbye_reason:?})"); + Ok(()) } - Request::BlobsByRoot(request) => { - self.handle_blobs_by_root_request(peer_id, peer_request_id, request); + RequestType::Ping(ping) => { + debug!("received Ping request (peer_id: {peer_id}, ping: {ping:?})"); + Ok(()) + } + RequestType::MetaData(request) => { + debug!("received MetaData request (peer_id: {peer_id}, request: {request:?})"); Ok(()) } } @@ -872,6 +901,7 @@ impl Network

{ &self, peer_id: PeerId, peer_request_id: PeerRequestId, + request_id: IncomingRequestId, remote: StatusMessage, ) { debug!("received Status request (peer_id: {peer_id}, remote: {remote:?})"); @@ -883,7 +913,12 @@ impl Network

{ local: {local:?})", ); - self.respond(peer_id, peer_request_id, Response::

::Status(local)); + self.respond( + peer_id, + peer_request_id, + request_id, + Response::

::Status(local), + ); self.check_status(&local, remote, peer_id); } @@ -892,7 +927,8 @@ impl Network

{ &self, peer_id: PeerId, peer_request_id: PeerRequestId, - request: BlocksByRangeRequest, + request_id: IncomingRequestId, + request: OldBlocksByRangeRequest, ) -> Result<()> { debug!("received BeaconBlocksByRange request (peer_id: {peer_id}, request: {request:?})"); @@ -927,6 +963,7 @@ impl Network

{ ServiceInboundMessage::SendResponse( peer_id, peer_request_id, + request_id, Box::new(Response::BlocksByRange(Some(block))), ) .send(&network_to_service_tx); @@ -937,6 +974,7 @@ impl Network

{ ServiceInboundMessage::SendResponse( peer_id, peer_request_id, + request_id, Box::new(Response::BlocksByRange(None)), ) .send(&network_to_service_tx); @@ -952,6 +990,7 @@ impl Network

{ &self, peer_id: PeerId, peer_request_id: PeerRequestId, + request_id: IncomingRequestId, request: BlobsByRangeRequest, ) -> Result<()> { debug!("received BlobSidecarsByRange request (peer_id: {peer_id}, request: {request:?})"); @@ -990,6 +1029,7 @@ impl Network

{ ServiceInboundMessage::SendResponse( peer_id, peer_request_id, + request_id, Box::new(Response::BlobsByRange(Some(blob_sidecar))), ) .send(&network_to_service_tx); @@ -1000,6 +1040,7 @@ impl Network

{ ServiceInboundMessage::SendResponse( peer_id, peer_request_id, + request_id, Box::new(Response::BlobsByRange(None)), ) .send(&network_to_service_tx); @@ -1015,6 +1056,7 @@ impl Network

{ &self, peer_id: PeerId, peer_request_id: PeerRequestId, + request_id: IncomingRequestId, request: BlobsByRootRequest, ) { debug!("received BlobsByRootRequest request (peer_id: {peer_id}, request: {request:?})"); @@ -1050,6 +1092,7 @@ impl Network

{ ServiceInboundMessage::SendResponse( peer_id, peer_request_id, + request_id, Box::new(Response::BlobsByRoot(Some(blob_sidecar))), ) .send(&network_to_service_tx); @@ -1060,6 +1103,7 @@ impl Network

{ ServiceInboundMessage::SendResponse( peer_id, peer_request_id, + request_id, Box::new(Response::BlobsByRoot(None)), ) .send(&network_to_service_tx); @@ -1073,6 +1117,7 @@ impl Network

{ &self, peer_id: PeerId, peer_request_id: PeerRequestId, + request_id: IncomingRequestId, request: BlocksByRootRequest, ) { let block_roots = request.block_roots(); @@ -1104,6 +1149,7 @@ impl Network

{ ServiceInboundMessage::SendResponse( peer_id, peer_request_id, + request_id, Box::new(Response::BlocksByRoot(Some(block))), ) .send(&network_to_service_tx); @@ -1114,6 +1160,7 @@ impl Network

{ ServiceInboundMessage::SendResponse( peer_id, peer_request_id, + request_id, Box::new(Response::BlocksByRoot(None)), ) .send(&network_to_service_tx); @@ -1257,6 +1304,7 @@ impl Network

{ request_id: {request_id}", ); } + Response::DataColumnsByRange(_) | Response::DataColumnsByRoot(_) => {} Response::LightClientBootstrap(_) => { // TODO(Altair Light Client Sync Protocol) debug!("received LightClientBootstrap response chunk (peer_id: {peer_id})"); @@ -1269,6 +1317,10 @@ impl Network

{ // TODO(Altair Light Client Sync Protocol) debug!("received LightClientOptimisticUpdate response (peer_id: {peer_id})"); } + Response::LightClientUpdatesByRange(_) => { + // TODO(Altair Light Client Sync Protocol) + debug!("received LightClientUpdatesByRange response (peer_id: {peer_id})"); + } } } @@ -1339,9 +1391,7 @@ impl Network

{ block_seen, ); } - PubsubMessage::DataColumnSidecar(_) => { - // TODO - } + PubsubMessage::DataColumnSidecar(_) => {} PubsubMessage::AggregateAndProofAttestation(aggregate_and_proof) => { if let Some(metrics) = self.metrics.as_ref() { metrics.register_gossip_object(&["aggregate_and_proof_attestation"]); @@ -1497,7 +1547,7 @@ impl Network

{ status: {status:?})" ); - self.request(peer_id, request_id, Request::Status(status)); + self.request(peer_id, request_id, RequestType::Status(status)); } fn local_status(&self) -> StatusMessage { @@ -1604,7 +1654,7 @@ impl Network

{ request: {request:?})", ); - self.request(peer_id, request_id, Request::BlobsByRange(request)); + self.request(peer_id, request_id, RequestType::BlobsByRange(request)); } fn request_blobs_by_root( @@ -1638,7 +1688,7 @@ impl Network

{ request: {request:?})", ); - self.request(peer_id, request_id, Request::BlobsByRoot(request)); + self.request(peer_id, request_id, RequestType::BlobsByRoot(request)); } fn request_blocks_by_range( @@ -1648,14 +1698,15 @@ impl Network

{ start_slot: Slot, count: u64, ) { - let request = BlocksByRangeRequest::new(start_slot, count); + // TODO: + let request = OldBlocksByRangeRequest::new(start_slot, count, 1); debug!( "sending BeaconBlocksByRange request (reqeuest_id: {request_id}, peer_id: {peer_id},\ request: {request:?})", ); - self.request(peer_id, request_id, Request::BlocksByRange(request)); + self.request(peer_id, request_id, RequestType::BlocksByRange(request)); } fn request_block_by_root(&self, request_id: RequestId, peer_id: PeerId, block_root: H256) { @@ -1674,7 +1725,7 @@ impl Network

{ request: {request:?})", ); - self.request(peer_id, request_id, Request::BlocksByRoot(request)); + self.request(peer_id, request_id, RequestType::BlocksByRoot(request)); } fn subscribe_to_core_topics(&self) { @@ -1691,7 +1742,7 @@ impl Network

{ let current_phase = self.fork_context.current_fork(); - for kind in core_topics_to_subscribe(current_phase) + for kind in core_topics_to_subscribe(self.controller.chain_config(), current_phase) .iter() .filter(|kind| !subscribed_topics.contains(kind)) .cloned() @@ -1720,14 +1771,25 @@ impl Network

{ ServiceInboundMessage::Publish(message).send(&self.network_to_service_tx); } - fn request(&self, peer_id: PeerId, request_id: RequestId, request: Request) { + fn request(&self, peer_id: PeerId, request_id: RequestId, request: RequestType

) { ServiceInboundMessage::SendRequest(peer_id, request_id, request) .send(&self.network_to_service_tx); } - fn respond(&self, peer_id: PeerId, peer_request_id: PeerRequestId, response: Response

) { - ServiceInboundMessage::SendResponse(peer_id, peer_request_id, Box::new(response)) - .send(&self.network_to_service_tx); + fn respond( + &self, + peer_id: PeerId, + peer_request_id: PeerRequestId, + request_id: IncomingRequestId, + response: Response

, + ) { + ServiceInboundMessage::SendResponse( + peer_id, + peer_request_id, + request_id, + Box::new(response), + ) + .send(&self.network_to_service_tx); } fn subnet_gossip_topic(&self, subnet: Subnet) -> Option { @@ -1855,8 +1917,8 @@ fn run_network_service( warn!("Unable to send request to peer: {peer_id}: {error:?}"); } } - ServiceInboundMessage::SendResponse(peer_id, peer_request_id, response) => { - service.send_response(peer_id, peer_request_id, *response); + ServiceInboundMessage::SendResponse(peer_id, peer_request_id, request_id, response) => { + service.send_response(peer_id, peer_request_id, request_id, *response); } ServiceInboundMessage::Subscribe(gossip_topic) => { service.subscribe(gossip_topic); diff --git a/runtime/src/runtime.rs b/runtime/src/runtime.rs index 4c9e36b6..66b49417 100644 --- a/runtime/src/runtime.rs +++ b/runtime/src/runtime.rs @@ -547,9 +547,10 @@ pub async fn run_after_genesis( // and the metrics server to convert collected metrics to an HTTP response for Prometheus. let gossip_registry = prometheus_client::registry::Registry::default(); let mut registry = network_config.metrics_enabled.then_some(gossip_registry); + let network_config = Arc::new(network_config); let network = Network::new( - &network_config, + network_config.clone_arc(), controller.clone_arc(), current_tick.slot, p2p_channels, @@ -588,7 +589,7 @@ pub async fn run_after_genesis( eth1_api, validator_keys, validator_config, - network_config: Arc::new(network_config), + network_config, http_api_config, attestation_agg_pool, sync_committee_agg_pool, diff --git a/types/src/combined.rs b/types/src/combined.rs index fefe566c..37e6881a 100644 --- a/types/src/combined.rs +++ b/types/src/combined.rs @@ -19,6 +19,7 @@ use crate::{ BeaconBlock as AltairBeaconBlock, LightClientBootstrap as AltairLightClientBootstrap, LightClientFinalityUpdate as AltairLightClientFinalityUpdate, LightClientOptimisticUpdate as AltairLightClientOptimisticUpdate, + LightClientUpdate as AltairLightClientUpdate, SignedBeaconBlock as AltairSignedBeaconBlock, }, }, @@ -41,6 +42,7 @@ use crate::{ LightClientBootstrap as CapellaLightClientBootstrap, LightClientFinalityUpdate as CapellaLightClientFinalityUpdate, LightClientOptimisticUpdate as CapellaLightClientOptimisticUpdate, + LightClientUpdate as CapellaLightClientUpdate, SignedBeaconBlock as CapellaSignedBeaconBlock, SignedBlindedBeaconBlock as CapellaSignedBlindedBeaconBlock, }, @@ -55,6 +57,7 @@ use crate::{ LightClientBootstrap as DenebLightClientBootstrap, LightClientFinalityUpdate as DenebLightClientFinalityUpdate, LightClientOptimisticUpdate as DenebLightClientOptimisticUpdate, + LightClientUpdate as DenebLightClientUpdate, SignedBeaconBlock as DenebSignedBeaconBlock, SignedBlindedBeaconBlock as DenebSignedBlindedBeaconBlock, }, @@ -69,6 +72,7 @@ use crate::{ LightClientBootstrap as ElectraLightClientBootstrap, LightClientFinalityUpdate as ElectraLightClientFinalityUpdate, LightClientOptimisticUpdate as ElectraLightClientOptimisticUpdate, + LightClientUpdate as ElectraLightClientUpdate, SignedAggregateAndProof as ElectraSignedAggregateAndProof, SignedBeaconBlock as ElectraSignedBeaconBlock, SignedBlindedBeaconBlock as ElectraSignedBlindedBeaconBlock, @@ -1214,6 +1218,64 @@ impl SszWrite for LightClientOptimisticUpdate

{ } } +#[derive(Clone, PartialEq, Eq, Debug)] +pub enum LightClientUpdate { + // Boxed to pass `clippy::large_enum_variant`. + Altair(Box>), + Capella(Box>), + Deneb(Box>), + Electra(Box>), +} + +// It is difficult to implement `SszRead` for the combined `LightClientUpdate`. +// `attested_header` starts with a slot, but `LightClientHeader` becomes variable-size in Capella. +// It is possible to distinguish variants of `LightClientUpdate` by length as of Capella, +// but it becomes more difficult in Deneb and may become impossible in later phases. +assert_not_impl_any!(LightClientUpdate: SszRead); + +impl SszSize for LightClientUpdate

{ + // The const parameter should be `Self::VARIANT_COUNT`, but `Self` refers to a generic type. + // Type parameters cannot be used in `const` contexts until `generic_const_exprs` is stable. + const SIZE: Size = Size::for_untagged_union::<{ Phase::CARDINALITY - 2 }>([ + AltairLightClientUpdate::

::SIZE, + CapellaLightClientUpdate::

::SIZE, + DenebLightClientUpdate::

::SIZE, + ElectraLightClientUpdate::

::SIZE, + ]); +} + +impl SszWrite for LightClientUpdate

{ + fn write_variable(&self, bytes: &mut Vec) -> Result<(), WriteError> { + match self { + Self::Altair(update) => { + let size = AltairLightClientUpdate::

::SIZE.get(); + let length_before = bytes.len(); + let length_after = length_before + size; + + bytes.resize(length_after, 0); + update.write_fixed(&mut bytes[length_before..]); + + Ok(()) + } + Self::Capella(update) => update.write_variable(bytes), + Self::Deneb(update) => update.write_variable(bytes), + Self::Electra(update) => update.write_variable(bytes), + } + } +} + +impl LightClientUpdate

{ + #[must_use] + pub fn signature_slot(&self) -> Slot { + match self { + Self::Altair(update) => update.signature_slot, + Self::Capella(update) => update.signature_slot, + Self::Deneb(update) => update.signature_slot, + Self::Electra(update) => update.signature_slot, + } + } +} + #[derive(Clone, PartialEq, Eq, Debug, From, Deserialize, Serialize)] #[serde(bound = "", untagged)] pub enum AggregateAndProof { @@ -1591,30 +1653,40 @@ mod spec_tests { ["consensus-spec-tests/tests/minimal/altair/ssz_static/LightClientFinalityUpdate/*/*"] [altair_minimal_finality_update] [LightClientFinalityUpdate] [Minimal] [Altair]; ["consensus-spec-tests/tests/mainnet/altair/ssz_static/LightClientOptimisticUpdate/*/*"] [altair_mainnet_optimistic_update] [LightClientOptimisticUpdate] [Mainnet] [Altair]; ["consensus-spec-tests/tests/minimal/altair/ssz_static/LightClientOptimisticUpdate/*/*"] [altair_minimal_optimistic_update] [LightClientOptimisticUpdate] [Minimal] [Altair]; + ["consensus-spec-tests/tests/mainnet/altair/ssz_static/LightClientUpdate/*/*"] [altair_mainnet_update] [LightClientUpdate] [Mainnet] [Altair]; + ["consensus-spec-tests/tests/minimal/altair/ssz_static/LightClientUpdate/*/*"] [altair_minimal_update] [LightClientUpdate] [Minimal] [Altair]; ["consensus-spec-tests/tests/mainnet/bellatrix/ssz_static/LightClientBootstrap/*/*"] [bellatrix_mainnet_bootstrap] [LightClientBootstrap] [Mainnet] [Altair]; ["consensus-spec-tests/tests/minimal/bellatrix/ssz_static/LightClientBootstrap/*/*"] [bellatrix_minimal_bootstrap] [LightClientBootstrap] [Minimal] [Altair]; ["consensus-spec-tests/tests/mainnet/bellatrix/ssz_static/LightClientFinalityUpdate/*/*"] [bellatrix_mainnet_finality_update] [LightClientFinalityUpdate] [Mainnet] [Altair]; ["consensus-spec-tests/tests/minimal/bellatrix/ssz_static/LightClientFinalityUpdate/*/*"] [bellatrix_minimal_finality_update] [LightClientFinalityUpdate] [Minimal] [Altair]; ["consensus-spec-tests/tests/mainnet/bellatrix/ssz_static/LightClientOptimisticUpdate/*/*"] [bellatrix_mainnet_optimistic_update] [LightClientOptimisticUpdate] [Mainnet] [Altair]; ["consensus-spec-tests/tests/minimal/bellatrix/ssz_static/LightClientOptimisticUpdate/*/*"] [bellatrix_minimal_optimistic_update] [LightClientOptimisticUpdate] [Minimal] [Altair]; + ["consensus-spec-tests/tests/mainnet/bellatrix/ssz_static/LightClientUpdate/*/*"] [bellatrix_mainnet_update] [LightClientUpdate] [Mainnet] [Altair]; + ["consensus-spec-tests/tests/minimal/bellatrix/ssz_static/LightClientUpdate/*/*"] [bellatrix_minimal_update] [LightClientUpdate] [Minimal] [Altair]; ["consensus-spec-tests/tests/mainnet/capella/ssz_static/LightClientBootstrap/*/*"] [capella_mainnet_bootstrap] [LightClientBootstrap] [Mainnet] [Capella]; ["consensus-spec-tests/tests/minimal/capella/ssz_static/LightClientBootstrap/*/*"] [capella_minimal_bootstrap] [LightClientBootstrap] [Minimal] [Capella]; ["consensus-spec-tests/tests/mainnet/capella/ssz_static/LightClientFinalityUpdate/*/*"] [capella_mainnet_finality_update] [LightClientFinalityUpdate] [Mainnet] [Capella]; ["consensus-spec-tests/tests/minimal/capella/ssz_static/LightClientFinalityUpdate/*/*"] [capella_minimal_finality_update] [LightClientFinalityUpdate] [Minimal] [Capella]; ["consensus-spec-tests/tests/mainnet/capella/ssz_static/LightClientOptimisticUpdate/*/*"] [capella_mainnet_optimistic_update] [LightClientOptimisticUpdate] [Mainnet] [Capella]; ["consensus-spec-tests/tests/minimal/capella/ssz_static/LightClientOptimisticUpdate/*/*"] [capella_minimal_optimistic_update] [LightClientOptimisticUpdate] [Minimal] [Capella]; + ["consensus-spec-tests/tests/mainnet/capella/ssz_static/LightClientUpdate/*/*"] [capella_mainnet_update] [LightClientUpdate] [Mainnet] [Capella]; + ["consensus-spec-tests/tests/minimal/capella/ssz_static/LightClientUpdate/*/*"] [capella_minimal_update] [LightClientUpdate] [Minimal] [Capella]; ["consensus-spec-tests/tests/mainnet/deneb/ssz_static/LightClientBootstrap/*/*"] [deneb_mainnet_bootstrap] [LightClientBootstrap] [Mainnet] [Deneb]; ["consensus-spec-tests/tests/minimal/deneb/ssz_static/LightClientBootstrap/*/*"] [deneb_minimal_bootstrap] [LightClientBootstrap] [Minimal] [Deneb]; ["consensus-spec-tests/tests/mainnet/deneb/ssz_static/LightClientFinalityUpdate/*/*"] [deneb_mainnet_finality_update] [LightClientFinalityUpdate] [Mainnet] [Deneb]; ["consensus-spec-tests/tests/minimal/deneb/ssz_static/LightClientFinalityUpdate/*/*"] [deneb_minimal_finality_update] [LightClientFinalityUpdate] [Minimal] [Deneb]; ["consensus-spec-tests/tests/mainnet/deneb/ssz_static/LightClientOptimisticUpdate/*/*"] [deneb_mainnet_optimistic_update] [LightClientOptimisticUpdate] [Mainnet] [Deneb]; ["consensus-spec-tests/tests/minimal/deneb/ssz_static/LightClientOptimisticUpdate/*/*"] [deneb_minimal_optimistic_update] [LightClientOptimisticUpdate] [Minimal] [Deneb]; + ["consensus-spec-tests/tests/mainnet/deneb/ssz_static/LightClientUpdate/*/*"] [deneb_mainnet_update] [LightClientUpdate] [Mainnet] [Deneb]; + ["consensus-spec-tests/tests/minimal/deneb/ssz_static/LightClientUpdate/*/*"] [deneb_minimal_update] [LightClientUpdate] [Minimal] [Deneb]; ["consensus-spec-tests/tests/mainnet/electra/ssz_static/LightClientBootstrap/*/*"] [electra_mainnet_bootstrap] [LightClientBootstrap] [Mainnet] [Electra]; ["consensus-spec-tests/tests/minimal/electra/ssz_static/LightClientBootstrap/*/*"] [electra_minimal_bootstrap] [LightClientBootstrap] [Minimal] [Electra]; ["consensus-spec-tests/tests/mainnet/electra/ssz_static/LightClientFinalityUpdate/*/*"] [electra_mainnet_finality_update] [LightClientFinalityUpdate] [Mainnet] [Electra]; ["consensus-spec-tests/tests/minimal/electra/ssz_static/LightClientFinalityUpdate/*/*"] [electra_minimal_finality_update] [LightClientFinalityUpdate] [Minimal] [Electra]; ["consensus-spec-tests/tests/mainnet/electra/ssz_static/LightClientOptimisticUpdate/*/*"] [electra_mainnet_optimistic_update] [LightClientOptimisticUpdate] [Mainnet] [Electra]; ["consensus-spec-tests/tests/minimal/electra/ssz_static/LightClientOptimisticUpdate/*/*"] [electra_minimal_optimistic_update] [LightClientOptimisticUpdate] [Minimal] [Electra]; + ["consensus-spec-tests/tests/mainnet/electra/ssz_static/LightClientUpdate/*/*"] [electra_mainnet_update] [LightClientUpdate] [Mainnet] [Electra]; + ["consensus-spec-tests/tests/minimal/electra/ssz_static/LightClientUpdate/*/*"] [electra_minimal_update] [LightClientUpdate] [Minimal] [Electra]; )] #[test_resources(glob)] fn function_name(case: Case) { diff --git a/types/src/deneb/consts.rs b/types/src/deneb/consts.rs index 02ed3dfa..a49647d3 100644 --- a/types/src/deneb/consts.rs +++ b/types/src/deneb/consts.rs @@ -1,14 +1,11 @@ use hex_literal::hex; use ssz::MerkleElements; -use typenum::{U32, U6}; +use typenum::U32; use crate::{deneb::primitives::KzgCommitment, preset::Preset}; pub const VERSIONED_HASH_VERSION_KZG: &[u8] = &hex!("01"); -// TODO(feature/deneb): Can `BlobSidecarSubnetCount` be a `const`? -// It's never used as a type even in `eth2_libp2p`. -pub type BlobSidecarSubnetCount = U6; pub type BytesPerFieldElement = U32; pub type BlobCommitmentTreeDepth

= <