diff --git a/Cargo.lock b/Cargo.lock index e191b69ebf53..2f7bdd6e359b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -170,7 +170,7 @@ dependencies = [ "alloy-transport", "futures", "futures-util", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -275,7 +275,7 @@ dependencies = [ "alloy-sol-types", "serde", "serde_json", - "thiserror 2.0.5", + "thiserror 2.0.6", "tracing", ] @@ -301,7 +301,7 @@ dependencies = [ "futures-utils-wasm", "serde", "serde_json", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -329,7 +329,7 @@ dependencies = [ "rand 0.8.5", "serde_json", "tempfile", - "thiserror 2.0.5", + "thiserror 2.0.6", "tracing", "url", ] @@ -400,7 +400,7 @@ dependencies = [ "schnellru", "serde", "serde_json", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tracing", "url", @@ -422,7 +422,7 @@ dependencies = [ "serde_json", "tokio", "tokio-stream", - "tower 0.5.1", + "tower 0.5.2", "tracing", ] @@ -467,7 +467,7 @@ dependencies = [ "serde_json", "tokio", "tokio-stream", - "tower 0.5.1", + "tower 0.5.2", "tracing", "url", "wasmtimer", @@ -533,7 +533,7 @@ dependencies = [ "alloy-serde", "serde", "serde_with", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -614,7 +614,7 @@ dependencies = [ "alloy-serde", "serde", "serde_json", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -652,7 +652,7 @@ dependencies = [ "auto_impl", "elliptic-curve", "k256", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -670,7 +670,7 @@ dependencies = [ "coins-bip39", "k256", "rand 0.8.5", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -755,9 +755,9 @@ dependencies = [ "futures-utils-wasm", "serde", "serde_json", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", - "tower 0.5.1", + "tower 0.5.2", "tracing", "url", "wasmtimer", @@ -773,7 +773,7 @@ dependencies = [ "alloy-transport", "reqwest", "serde_json", - "tower 0.5.1", + "tower 0.5.2", "tracing", "url", ] @@ -1220,7 +1220,7 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba5289ec98f68f28dd809fd601059e6aa908bb8f6108620930828283d4ee23d7" dependencies = [ - "fastrand 2.2.0", + "fastrand 2.3.0", "tokio", ] @@ -1577,9 +1577,9 @@ dependencies = [ [[package]] name = "bstr" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a68f1f47cdf0ec8ee4b941b2eee2a80cb796db73118c0dd09ac63fbe405be22" +checksum = "786a307d683a5bf92e6fd5fd69a7eb613751668d1d8d67d802846dfe367c62c8" dependencies = [ "memchr", "regex-automata 0.4.9", @@ -1741,9 +1741,9 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "chrono" -version = "0.4.38" +version = "0.4.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825" dependencies = [ "android-tzdata", "iana-time-zone", @@ -2665,7 +2665,7 @@ dependencies = [ "revm", "serde", "serde_json", - "thiserror 2.0.5", + "thiserror 2.0.6", "walkdir", ] @@ -2840,7 +2840,7 @@ dependencies = [ "reth-node-ethereum", "serde", "serde_json", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -2928,7 +2928,7 @@ dependencies = [ "reth-tracing", "reth-trie-db", "serde", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", ] @@ -3179,9 +3179,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "fastrlp" @@ -3696,7 +3696,7 @@ dependencies = [ "once_cell", "rand 0.8.5", "serde", - "thiserror 2.0.5", + "thiserror 2.0.6", "tinyvec", "tokio", "tracing", @@ -3720,7 +3720,7 @@ dependencies = [ "resolv-conf", "serde", "smallvec", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tracing", ] @@ -4691,9 +4691,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.167" +version = "0.2.168" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" +checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d" [[package]] name = "libloading" @@ -5421,7 +5421,7 @@ dependencies = [ "derive_more", "serde", "serde_with", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -5436,7 +5436,7 @@ dependencies = [ "alloy-sol-types", "serde", "serde_repr", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -5473,7 +5473,7 @@ dependencies = [ "op-alloy-consensus", "op-alloy-genesis", "serde", - "thiserror 2.0.5", + "thiserror 2.0.6", "tracing", "unsigned-varint", ] @@ -5527,7 +5527,7 @@ dependencies = [ "op-alloy-protocol", "serde", "snap", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -5701,7 +5701,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b7cafe60d6cf8e62e1b9b2ea516a089c008945bb5a275416789e7db0bc199dc" dependencies = [ "memchr", - "thiserror 2.0.5", + "thiserror 2.0.6", "ucd-trie", ] @@ -6151,7 +6151,7 @@ dependencies = [ "rustc-hash 2.1.0", "rustls", "socket2", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tracing", ] @@ -6170,7 +6170,7 @@ dependencies = [ "rustls", "rustls-pki-types", "slab", - "thiserror 2.0.5", + "thiserror 2.0.6", "tinyvec", "tracing", "web-time", @@ -6178,9 +6178,9 @@ dependencies = [ [[package]] name = "quinn-udp" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d5a626c6807713b15cac82a6acaccd6043c9a5408c24baae07611fec3f243da" +checksum = "52cd4b1eff68bf27940dd39811292c49e007f4d0b4c357358dc9b0197be6b527" dependencies = [ "cfg_aliases", "libc", @@ -6344,9 +6344,9 @@ checksum = "d3edd4d5d42c92f0a659926464d4cce56b562761267ecf0f469d85b7de384175" [[package]] name = "redox_syscall" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" dependencies = [ "bitflags 2.6.0", ] @@ -6453,7 +6453,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", - "sync_wrapper 1.0.2", + "sync_wrapper", "tokio", "tokio-rustls", "tokio-util", @@ -6628,7 +6628,7 @@ dependencies = [ "reth-tokio-util", "reth-tracing", "schnellru", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tokio-stream", "tracing", @@ -6664,7 +6664,7 @@ dependencies = [ "reth-rpc-types-compat", "reth-tracing", "serde", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tower 0.4.13", "tracing", @@ -6720,7 +6720,7 @@ dependencies = [ "reth-primitives", "reth-primitives-traits", "reth-storage-errors", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -6876,7 +6876,7 @@ dependencies = [ "reth-fs-util", "secp256k1", "serde", - "thiserror 2.0.5", + "thiserror 2.0.6", "tikv-jemallocator", "tracy-client", ] @@ -7022,7 +7022,7 @@ dependencies = [ "sysinfo", "tempfile", "test-fuzz", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -7079,7 +7079,7 @@ dependencies = [ "reth-trie-db", "serde", "serde_json", - "thiserror 2.0.5", + "thiserror 2.0.6", "tracing", ] @@ -7121,7 +7121,7 @@ dependencies = [ "schnellru", "secp256k1", "serde", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tokio-stream", "tracing", @@ -7146,7 +7146,7 @@ dependencies = [ "reth-network-peers", "reth-tracing", "secp256k1", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tracing", ] @@ -7173,7 +7173,7 @@ dependencies = [ "secp256k1", "serde", "serde_with", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tokio-stream", "tracing", @@ -7211,7 +7211,7 @@ dependencies = [ "reth-testing-utils", "reth-tracing", "tempfile", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tokio-stream", "tokio-util", @@ -7288,7 +7288,7 @@ dependencies = [ "secp256k1", "sha2 0.10.8", "sha3", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tokio-stream", "tokio-util", @@ -7344,7 +7344,7 @@ dependencies = [ "reth-primitives-traits", "reth-trie", "serde", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", ] @@ -7371,7 +7371,7 @@ dependencies = [ "reth-prune", "reth-stages-api", "reth-tasks", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tokio-stream", ] @@ -7427,7 +7427,7 @@ dependencies = [ "reth-trie-parallel", "reth-trie-sparse", "revm-primitives", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tracing", ] @@ -7473,7 +7473,7 @@ dependencies = [ "reth-execution-errors", "reth-fs-util", "reth-storage-errors", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -7506,7 +7506,7 @@ dependencies = [ "serde", "snap", "test-fuzz", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tokio-stream", "tokio-util", @@ -7535,7 +7535,7 @@ dependencies = [ "reth-primitives", "reth-primitives-traits", "serde", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -7601,7 +7601,7 @@ dependencies = [ "proptest-derive", "rustc-hash 2.1.0", "serde", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -7718,7 +7718,7 @@ dependencies = [ "reth-prune-types", "reth-storage-errors", "revm-primitives", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -7813,7 +7813,7 @@ dependencies = [ "reth-transaction-pool", "reth-trie-db", "tempfile", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", ] @@ -7840,7 +7840,7 @@ version = "1.1.4" dependencies = [ "serde", "serde_json", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -7883,7 +7883,7 @@ dependencies = [ "rand 0.8.5", "reth-tracing", "serde_json", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tokio-stream", "tokio-util", @@ -7908,7 +7908,7 @@ dependencies = [ "reth-mdbx-sys", "smallvec", "tempfile", - "thiserror 2.0.5", + "thiserror 2.0.6", "tracing", ] @@ -7947,7 +7947,7 @@ dependencies = [ "reqwest", "reth-tracing", "serde_with", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tracing", ] @@ -8007,7 +8007,7 @@ dependencies = [ "serial_test", "smallvec", "tempfile", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tokio-stream", "tokio-util", @@ -8032,7 +8032,7 @@ dependencies = [ "reth-network-types", "reth-tokio-util", "serde", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tokio-stream", ] @@ -8070,7 +8070,7 @@ dependencies = [ "secp256k1", "serde_json", "serde_with", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "url", ] @@ -8101,7 +8101,7 @@ dependencies = [ "reth-fs-util", "serde", "tempfile", - "thiserror 2.0.5", + "thiserror 2.0.6", "tracing", "zstd", ] @@ -8234,7 +8234,7 @@ dependencies = [ "serde", "shellexpand", "strum", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "toml", "tracing", @@ -8564,7 +8564,7 @@ dependencies = [ "reth-transaction-pool", "revm", "sha2 0.10.8", - "thiserror 2.0.5", + "thiserror 2.0.6", "tracing", ] @@ -8632,7 +8632,7 @@ dependencies = [ "reth-transaction-pool", "revm", "serde_json", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tracing", ] @@ -8697,7 +8697,7 @@ dependencies = [ "reth-primitives", "revm-primitives", "serde", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", ] @@ -8872,7 +8872,7 @@ dependencies = [ "reth-tokio-util", "reth-tracing", "rustc-hash 2.1.0", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tracing", ] @@ -8892,7 +8892,7 @@ dependencies = [ "serde", "serde_json", "test-fuzz", - "thiserror 2.0.5", + "thiserror 2.0.6", "toml", ] @@ -8978,7 +8978,7 @@ dependencies = [ "revm-primitives", "serde", "serde_json", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tokio-stream", "tower 0.4.13", @@ -9071,7 +9071,7 @@ dependencies = [ "reth-transaction-pool", "serde", "serde_json", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tokio-util", "tower 0.4.13", @@ -9112,7 +9112,7 @@ dependencies = [ "reth-tokio-util", "reth-transaction-pool", "serde", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tracing", ] @@ -9196,7 +9196,7 @@ dependencies = [ "schnellru", "serde", "serde_json", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tokio-stream", "tracing", @@ -9297,7 +9297,7 @@ dependencies = [ "reth-trie", "reth-trie-db", "tempfile", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tracing", ] @@ -9325,7 +9325,7 @@ dependencies = [ "reth-static-file-types", "reth-testing-utils", "reth-tokio-util", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tokio-stream", "tracing", @@ -9431,7 +9431,7 @@ dependencies = [ "pin-project", "rayon", "reth-metrics", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tracing", "tracing-futures", @@ -9516,7 +9516,7 @@ dependencies = [ "serde_json", "smallvec", "tempfile", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tokio-stream", "tracing", @@ -9632,7 +9632,7 @@ dependencies = [ "reth-trie", "reth-trie-common", "reth-trie-db", - "thiserror 2.0.5", + "thiserror 2.0.6", "tokio", "tracing", ] @@ -9658,7 +9658,7 @@ dependencies = [ "reth-trie", "reth-trie-common", "smallvec", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -9699,7 +9699,7 @@ dependencies = [ "colorchoice", "revm", "serde_json", - "thiserror 2.0.5", + "thiserror 2.0.6", ] [[package]] @@ -9975,22 +9975,22 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.41" +version = "0.38.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" +checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" dependencies = [ "bitflags 2.6.0", "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "rustls" -version = "0.23.19" +version = "0.23.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "934b404430bb06b3fae2cba809eb45a1ab1aecd64491213d7c3301b88393f8d1" +checksum = "5065c3f250cbd332cd894be57c40fa52387247659b14a2d6041d121547903b1b" dependencies = [ "log", "once_cell", @@ -10280,18 +10280,18 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.215" +version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.215" +version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" dependencies = [ "proc-macro2", "quote", @@ -10766,12 +10766,6 @@ dependencies = [ "syn 2.0.90", ] -[[package]] -name = "sync_wrapper" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" - [[package]] name = "sync_wrapper" version = "1.0.2" @@ -10824,7 +10818,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" dependencies = [ "cfg-if", - "fastrand 2.2.0", + "fastrand 2.3.0", "once_cell", "rustix", "windows-sys 0.59.0", @@ -10905,11 +10899,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.5" +version = "2.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "643caef17e3128658ff44d85923ef2d28af81bb71e0d67bbfe1d76f19a73e053" +checksum = "8fec2a1820ebd077e2b90c4df007bebf344cd394098a13c563957d0afc83ea47" dependencies = [ - "thiserror-impl 2.0.5", + "thiserror-impl 2.0.6", ] [[package]] @@ -10925,9 +10919,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.5" +version = "2.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "995d0bbc9995d1f19d28b7215a9352b0fc3cd3a2d2ec95c2cadc485cdedbcdde" +checksum = "d65750cab40f4ff1929fb1ba509e9914eb756131cef4210da8d5d700d26f6312" dependencies = [ "proc-macro2", "quote", @@ -11201,14 +11195,14 @@ dependencies = [ [[package]] name = "tower" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2873938d487c3cfb9aed7546dc9f2711d867c9f90c46b889989a2cb84eba6b4f" +checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" dependencies = [ "futures-core", "futures-util", "pin-project-lite", - "sync_wrapper 0.1.2", + "sync_wrapper", "tower-layer", "tower-service", ] @@ -11237,7 +11231,7 @@ dependencies = [ "pin-project-lite", "tokio", "tokio-util", - "tower 0.5.1", + "tower 0.5.2", "tower-layer", "tower-service", "tracing", diff --git a/Cargo.toml b/Cargo.toml index 3d652c5908eb..aec725de3d69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -648,4 +648,4 @@ tracy-client = "0.17.3" # op-alloy-consensus = { git = "https://github.com/alloy-rs/op-alloy", rev = "debfc29" } # op-alloy-network = { git = "https://github.com/alloy-rs/op-alloy", rev = "debfc29" } # op-alloy-rpc-types = { git = "https://github.com/alloy-rs/op-alloy", rev = "debfc29" } -# op-alloy-rpc-types-engine = { git = "https://github.com/alloy-rs/op-alloy", rev = "debfc29" } +# op-alloy-rpc-types-engine = { git = "https://github.com/alloy-rs/op-alloy", rev = "debfc29" } \ No newline at end of file diff --git a/crates/rpc/rpc-eth-api/src/helpers/block.rs b/crates/rpc/rpc-eth-api/src/helpers/block.rs index 5f0d9f744ef1..2a2caf9c5e2d 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/block.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/block.rs @@ -6,7 +6,7 @@ use alloy_consensus::BlockHeader; use alloy_eips::BlockId; use alloy_primitives::Sealable; use alloy_rlp::Encodable; -use alloy_rpc_types_eth::{Block, BlockTransactions, Header, Index}; +use alloy_rpc_types_eth::{Block, BlockNumberOrTag, BlockTransactions, Header, Index}; use futures::Future; use reth_node_api::BlockBody; use reth_primitives::{SealedBlockFor, SealedBlockWithSenders}; @@ -100,24 +100,33 @@ pub trait EthBlocks: LoadBlock { .provider() .pending_block() .map_err(Self::Error::from_eth_err)? - .map(|block| block.body.transactions().len())) + .map(|block| block.body.transactions().len())); } - let block_hash = match self - .provider() - .block_hash_for_id(block_id) - .map_err(Self::Error::from_eth_err)? - { - Some(block_hash) => block_hash, - None => return Ok(None), - }; - - Ok(self - .cache() - .get_sealed_block_with_senders(block_hash) - .await - .map_err(Self::Error::from_eth_err)? - .map(|b| b.body.transactions().len())) + match block_id { + BlockId::Number(BlockNumberOrTag::Latest) => Ok(self + .cache() + .latest_block_with_senders() + .await + .map_err(Self::Error::from_eth_err)? + .map(|b| b.body.transactions().len())), + _ => { + let block_hash = match self + .provider() + .block_hash_for_id(block_id) + .map_err(Self::Error::from_eth_err)? + { + Some(block_hash) => block_hash, + None => return Ok(None), + }; + Ok(self + .cache() + .get_sealed_block_with_senders(block_hash) + .await + .map_err(Self::Error::from_eth_err)? + .map(|b| b.body.transactions().len())) + } + } } } @@ -167,7 +176,7 @@ pub trait EthBlocks: LoadBlock { .get_block_and_receipts(block_hash) .await .map_err(Self::Error::from_eth_err) - .map(|b| b.map(|(b, r)| (b.block.clone(), r))) + .map(|b| b.map(|(b, r)| (b.block.clone(), r))); } Ok(None) @@ -253,19 +262,48 @@ pub trait LoadBlock: LoadPendingBlock + SpawnBlocking + RpcNodeCoreExt { }; } - let block_hash = match self - .provider() - .block_hash_for_id(block_id) - .map_err(Self::Error::from_eth_err)? - { - Some(block_hash) => block_hash, - None => return Ok(None), - }; + let block = match block_id { + BlockId::Number(BlockNumberOrTag::Latest) => { + if let Some(block) = self + .cache() + .latest_block_with_senders() + .await + .map_err(Self::Error::from_eth_err)? + { + Some(block) + } else { + // Fallback to traditional lookup if latest isn't cached + match self + .provider() + .block_hash_for_id(block_id) + .map_err(Self::Error::from_eth_err)? + { + Some(block_hash) => self + .cache() + .get_sealed_block_with_senders(block_hash) + .await + .map_err(Self::Error::from_eth_err)?, + None => None, + } + } + } + _ => { + let block_hash = match self + .provider() + .block_hash_for_id(block_id) + .map_err(Self::Error::from_eth_err)? + { + Some(block_hash) => block_hash, + None => return Ok(None), + }; - self.cache() - .get_sealed_block_with_senders(block_hash) - .await - .map_err(Self::Error::from_eth_err) + self.cache() + .get_sealed_block_with_senders(block_hash) + .await + .map_err(Self::Error::from_eth_err)? + } + }; + Ok(block) } } } diff --git a/crates/rpc/rpc-eth-types/src/cache/mod.rs b/crates/rpc/rpc-eth-types/src/cache/mod.rs index 168638872407..0ced498ce10a 100644 --- a/crates/rpc/rpc-eth-types/src/cache/mod.rs +++ b/crates/rpc/rpc-eth-types/src/cache/mod.rs @@ -61,15 +61,10 @@ type HeaderLruCache = MultiConsumerLruCache { to_service: UnboundedSender>, -} - -impl Clone for EthStateCache { - fn clone(&self) -> Self { - Self { to_service: self.to_service.clone() } - } + latest_chain_change: Option>, } impl EthStateCache { @@ -95,8 +90,9 @@ impl EthStateCache { action_rx: UnboundedReceiverStream::new(rx), action_task_spawner, rate_limiter: Arc::new(Semaphore::new(max_concurrent_db_operations)), + latest_chain_change: None, }; - let cache = Self { to_service }; + let cache = Self { to_service, latest_chain_change: None }; (cache, service) } @@ -186,6 +182,21 @@ impl EthStateCache { let _ = self.to_service.send(CacheAction::GetHeader { block_hash, response_tx }); rx.await.map_err(|_| ProviderError::CacheServiceUnavailable)? } + + /// Returns the most recent canonical block from the cache, if available. + /// Used to efficiently handle latest block requests and avoid race conditions during chain + /// reorgs. + /// Returns `None` if no canonical chain is tracked or during reorgs. + pub async fn latest_block_with_senders( + &self, + ) -> ProviderResult>>> { + if let Some(chain_change) = &self.latest_chain_change { + if let Some(latest_block) = chain_change.blocks.last() { + return self.get_sealed_block_with_senders(latest_block.hash()).await; + } + } + Ok(None) + } } /// A task than manages caches for data required by the `eth` rpc implementation. @@ -236,6 +247,8 @@ pub(crate) struct EthStateCacheService< action_task_spawner: Tasks, /// Rate limiter rate_limiter: Arc, + /// Tracks latest canonical chain state for cache consistency + latest_chain_change: Option>, } impl EthStateCacheService @@ -458,7 +471,8 @@ where } } CacheAction::CacheNewCanonicalChain { chain_change } => { - for block in chain_change.blocks { + this.latest_chain_change = Some(chain_change.clone()); + for block in chain_change.clone().blocks { this.on_new_block(block.hash(), Ok(Some(Arc::new(block)))); } @@ -527,12 +541,14 @@ enum CacheAction { }, } +#[derive(Clone, Debug)] struct BlockReceipts { block_hash: B256, receipts: Vec>, } /// A change of the canonical chain +#[derive(Debug, Clone)] struct ChainChange { blocks: Vec>, receipts: Vec>, @@ -558,9 +574,14 @@ impl ChainChange { /// Awaits for new chain events and directly inserts them into the cache so they're available /// immediately before they need to be fetched from disk. /// +/// Updates [`EthStateCache`] in two scenario : +/// 1. On reorgs: sets `EthStateCache::latest_chain_change` to None and removes reorged blocks +/// 2. On new canonical blocks: updates `EthStateCache::latest_chain_change` and caches the new +/// blocks +/// /// Reorged blocks are removed from the cache. pub async fn cache_new_blocks_task( - eth_state_cache: EthStateCache, + mut eth_state_cache: EthStateCache, mut events: St, ) where St: Stream> + Unpin + 'static, @@ -568,13 +589,13 @@ pub async fn cache_new_blocks_task( while let Some(event) = events.next().await { if let Some(reverted) = event.reverted() { let chain_change = ChainChange::new(reverted); - + eth_state_cache.latest_chain_change = None; let _ = eth_state_cache.to_service.send(CacheAction::RemoveReorgedChain { chain_change }); } let chain_change = ChainChange::new(event.committed()); - + eth_state_cache.latest_chain_change = Some(chain_change.clone()); let _ = eth_state_cache.to_service.send(CacheAction::CacheNewCanonicalChain { chain_change }); }