From 0c15cb661d09bfe48ccf50014395acaef66e2388 Mon Sep 17 00:00:00 2001 From: avalonche Date: Sat, 26 Oct 2024 07:44:25 +1100 Subject: [PATCH] fix metrics server --- .env.example | 2 + Cargo.lock | 596 ++++++++++++++++++++++++++++--------------------- Cargo.toml | 4 +- README.md | 4 + src/error.rs | 2 +- src/main.rs | 24 +- src/metrics.rs | 4 +- src/proxy.rs | 29 ++- src/server.rs | 76 ++++--- 9 files changed, 441 insertions(+), 300 deletions(-) diff --git a/.env.example b/.env.example index 5ce40ef..dd8b0d6 100644 --- a/.env.example +++ b/.env.example @@ -1,8 +1,10 @@ JWT_TOKEN=688f5d737bad920bdfb2fc2f488d6b6209eebda1dae949a8de91398d932c517a +BUILDER_JWT_TOKEN=688f5d737bad920bdfb2fc2f488d6b6209eebda1dae949a8de91398d932c517a L2_URL=http://localhost:8551 BUILDER_URL=http://localhost:8552 RPC_HOST=0.0.0.0 RPC_PORT=8081 TRACING=false LOG_LEVEL=info +METRICS=false BOOST_SYNC=false \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 62c7e94..442dc1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,17 +17,6 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" -[[package]] -name = "ahash" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - [[package]] name = "ahash" version = "0.8.11" @@ -41,15 +30,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "aho-corasick" -version = "0.7.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" -dependencies = [ - "memchr", -] - [[package]] name = "aho-corasick" version = "1.1.3" @@ -300,7 +280,7 @@ dependencies = [ "async-stream", "async-trait", "auto_impl", - "dashmap 6.1.0", + "dashmap", "futures", "futures-utils-wasm", "lru", @@ -333,7 +313,7 @@ checksum = "4d0f2d905ebd295e7effec65e5f6868d153936130ae718352771de3e7d03c75c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -532,7 +512,7 @@ dependencies = [ "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -544,11 +524,11 @@ dependencies = [ "alloy-sol-macro-input", "const-hex", "heck", - "indexmap 2.5.0", + "indexmap 2.6.0", "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", "syn-solidity", "tiny-keccak", ] @@ -564,7 +544,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", "syn-solidity", ] @@ -722,7 +702,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -899,7 +879,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -910,16 +890,7 @@ checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", -] - -[[package]] -name = "atomic-shim" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67cd4b51d303cf3501c301e8125df442128d3c6d7c69f71b27833d253de47e77" -dependencies = [ - "crossbeam-utils", + "syn 2.0.85", ] [[package]] @@ -946,7 +917,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -955,6 +926,33 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +[[package]] +name = "aws-lc-rs" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdd82dba44d209fddb11c190e0a94b78651f95299598e472215667417a03ff1d" +dependencies = [ + "aws-lc-sys", + "mirai-annotations", + "paste", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df7a4168111d7eb622a31b214057b8509c0a7e1794f44c546d742330dc793972" +dependencies = [ + "bindgen 0.69.4", + "cc", + "cmake", + "dunce", + "fs_extra", + "libc", + "paste", +] + [[package]] name = "backtrace" version = "0.3.74" @@ -1015,12 +1013,33 @@ dependencies = [ "itertools 0.10.5", "lazy_static", "lazycell", + "log", + "prettyplease", "proc-macro2", "quote", "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.77", + "syn 2.0.85", + "which", +] + +[[package]] +name = "bindgen" +version = "0.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f49d8fed880d473ea71efb9bf597651e77201bdd4893efe54c9e5d65ae04ce6f" +dependencies = [ + "bitflags 2.6.0", + "cexpr", + "clang-sys", + "itertools 0.13.0", + "proc-macro2", + "quote", + "regex", + "rustc-hash 1.1.0", + "shlex", + "syn 2.0.85", ] [[package]] @@ -1235,7 +1254,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -1244,6 +1263,15 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +[[package]] +name = "cmake" +version = "0.1.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb1e43aa7fd152b1f968787f7dbcdeb306d1867ff373c69955211876c053f91a" +dependencies = [ + "cc", +] + [[package]] name = "colorchoice" version = "1.0.2" @@ -1411,7 +1439,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -1422,17 +1450,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.77", -] - -[[package]] -name = "dashmap" -version = "4.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c" -dependencies = [ - "cfg-if", - "num_cpus", + "syn 2.0.85", ] [[package]] @@ -1446,7 +1464,7 @@ dependencies = [ "hashbrown 0.14.5", "lock_api", "once_cell", - "parking_lot_core 0.9.10", + "parking_lot_core", ] [[package]] @@ -1488,7 +1506,7 @@ checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -1509,7 +1527,7 @@ dependencies = [ "convert_case", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", "unicode-xid", ] @@ -1642,7 +1660,7 @@ checksum = "2f9ed6b3789237c8a0c1c505af1c7eb2c560df6186f01b098c3a1064ea532f38" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -1737,6 +1755,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "foreign-types" version = "0.3.2" @@ -1761,6 +1785,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "fsevent-sys" version = "4.1.0" @@ -1832,7 +1862,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -1891,7 +1921,7 @@ dependencies = [ "cfg-if", "js-sys", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "wasm-bindgen", ] @@ -1930,22 +1960,13 @@ dependencies = [ "futures-core", "futures-sink", "http 1.1.0", - "indexmap 2.5.0", + "indexmap 2.6.0", "slab", "tokio", "tokio-util", "tracing", ] -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -dependencies = [ - "ahash 0.7.8", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -1964,11 +1985,20 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ - "ahash 0.8.11", + "ahash", "allocator-api2", "serde", ] +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "foldhash", +] + [[package]] name = "heck" version = "0.5.0" @@ -2005,6 +2035,15 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "http" version = "0.2.12" @@ -2073,29 +2112,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" -[[package]] -name = "hyper" -version = "0.14.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c08302e8fa335b151b788c775ff56e7a03ae64ff85c548ee820fecb70356e85" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "http 0.2.12", - "http-body 0.4.6", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - [[package]] name = "hyper" version = "1.4.1" @@ -2125,10 +2141,11 @@ checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ "futures-util", "http 1.1.0", - "hyper 1.4.1", + "hyper", "hyper-util", "log", "rustls", + "rustls-native-certs 0.8.0", "rustls-pki-types", "tokio", "tokio-rustls", @@ -2143,7 +2160,7 @@ checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" dependencies = [ "bytes", "http-body-util", - "hyper 1.4.1", + "hyper", "hyper-util", "native-tls", "tokio", @@ -2162,7 +2179,7 @@ dependencies = [ "futures-util", "http 1.1.0", "http-body 1.0.1", - "hyper 1.4.1", + "hyper", "pin-project-lite", "socket2", "tokio", @@ -2182,7 +2199,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2268,12 +2285,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.14.5", + "hashbrown 0.15.0", "serde", ] @@ -2297,15 +2314,6 @@ dependencies = [ "libc", ] -[[package]] -name = "instant" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" -dependencies = [ - "cfg-if", -] - [[package]] name = "ipnet" version = "2.10.0" @@ -2408,7 +2416,7 @@ dependencies = [ "http-body 1.0.1", "http-body-util", "jsonrpsee-types", - "parking_lot 0.12.3", + "parking_lot", "rand", "rustc-hash 2.0.0", "serde", @@ -2427,7 +2435,7 @@ dependencies = [ "async-trait", "base64 0.22.1", "http-body 1.0.1", - "hyper 1.4.1", + "hyper", "hyper-rustls", "hyper-util", "jsonrpsee-core", @@ -2453,7 +2461,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -2466,7 +2474,7 @@ dependencies = [ "http 1.1.0", "http-body 1.0.1", "http-body-util", - "hyper 1.4.1", + "hyper", "hyper-util", "jsonrpsee-core", "jsonrpsee-types", @@ -2579,9 +2587,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.161" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "libloading" @@ -2599,6 +2607,17 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "libproc" +version = "0.14.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78a09b56be5adbcad5aa1197371688dc6bb249a26da3bca2011ee2fb987ebfb" +dependencies = [ + "bindgen 0.70.1", + "errno", + "libc", +] + [[package]] name = "libredox" version = "0.1.3" @@ -2607,7 +2626,7 @@ checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ "bitflags 2.6.0", "libc", - "redox_syscall 0.5.4", + "redox_syscall", ] [[package]] @@ -2648,10 +2667,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75761162ae2b0e580d7e7c390558127e5f01b4194debd6221fd8c207fc80e3f5" [[package]] -name = "mach" -version = "0.3.2" +name = "mach2" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" dependencies = [ "libc", ] @@ -2680,23 +2699,13 @@ dependencies = [ "libc", ] -[[package]] -name = "metrics" -version = "0.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55586aa936c35f34ba8aa5d97356d554311206e1ce1f9e68fe7b07288e5ad827" -dependencies = [ - "ahash 0.7.8", - "metrics-macros", -] - [[package]] name = "metrics" version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "884adb57038347dfbaf2d5065887b6cf4312330dc8e94bc30a1a839bd79d3261" dependencies = [ - "ahash 0.8.11", + "ahash", "portable-atomic", ] @@ -2706,7 +2715,7 @@ version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ae428771d17306715c5091d446327d1cfdedc82185c65ba8423ab404e45bf10" dependencies = [ - "ahash 0.8.11", + "ahash", "portable-atomic", ] @@ -2719,56 +2728,59 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] name = "metrics-exporter-prometheus" -version = "0.7.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aee04ed06085ea4eb1e1378c4fd973d95e0d3e32897913cd58aedc3b10e71452" +checksum = "85b6f8152da6d7892ff1b7a1c0fa3f435e92b5918ad67035c3bb432111d9a29b" dependencies = [ - "hyper 0.14.31", + "base64 0.22.1", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "indexmap 2.6.0", "ipnet", - "metrics 0.17.1", + "metrics 0.24.0", "metrics-util", - "parking_lot 0.11.2", "quanta", "thiserror", "tokio", + "tracing", ] [[package]] -name = "metrics-macros" -version = "0.4.1" +name = "metrics-process" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0daa0ab3a0ae956d0e2c1f42511422850e577d36a255357d1a7d08d45ee3a2f1" +checksum = "57ca8ecd85575fbb143b2678cb123bb818779391ec0f745b1c4a9dbabadde407" dependencies = [ - "lazy_static", - "proc-macro2", - "quote", - "regex", - "syn 1.0.109", + "libc", + "libproc", + "mach2", + "metrics 0.24.0", + "once_cell", + "procfs", + "rlimit", + "windows 0.58.0", ] [[package]] name = "metrics-util" -version = "0.10.2" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1174223789e331d9d47a4a953dac36e397db60fa8d2a111ac505388c6c7fe32e" +checksum = "15b482df36c13dd1869d73d14d28cd4855fbd6cfc32294bee109908a9f4a4ed7" dependencies = [ - "ahash 0.7.8", - "aho-corasick 0.7.20", - "atomic-shim", + "aho-corasick", "crossbeam-epoch", "crossbeam-utils", - "dashmap 4.0.2", - "hashbrown 0.11.2", - "indexmap 1.9.3", - "metrics 0.17.1", - "num_cpus", + "hashbrown 0.15.0", + "indexmap 2.6.0", + "metrics 0.24.0", "ordered-float", - "parking_lot 0.11.2", "quanta", "radix_trie", "sketches-ddsketch", @@ -2803,7 +2815,7 @@ checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", "log", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "windows-sys 0.48.0", ] @@ -2815,10 +2827,16 @@ checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ "hermit-abi", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "windows-sys 0.52.0", ] +[[package]] +name = "mirai-annotations" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9be0862c1b3f26a88803c4a49de6889c10e608b3ee9344e6ef5b45fb37ad3d1" + [[package]] name = "modular-bitfield" version = "0.11.2" @@ -3026,7 +3044,7 @@ checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -3163,7 +3181,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -3186,9 +3204,9 @@ dependencies = [ [[package]] name = "ordered-float" -version = "2.10.1" +version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c" +checksum = "83e7ccb95e240b7c9506a3d544f10d935e142cc90b0a1d56954fb44d89ad6b97" dependencies = [ "num-traits", ] @@ -3248,17 +3266,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "parking_lot" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core 0.8.6", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -3266,21 +3273,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", - "parking_lot_core 0.9.10", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall 0.2.16", - "smallvec", - "winapi", + "parking_lot_core", ] [[package]] @@ -3291,7 +3284,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.5.4", + "redox_syscall", "smallvec", "windows-targets 0.52.6", ] @@ -3346,7 +3339,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -3428,6 +3421,16 @@ dependencies = [ "termtree", ] +[[package]] +name = "prettyplease" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" +dependencies = [ + "proc-macro2", + "syn 2.0.85", +] + [[package]] name = "primeorder" version = "0.13.6" @@ -3500,7 +3503,7 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -3512,6 +3515,28 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "procfs" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc5b72d8145275d844d4b5f6d4e1eef00c8cd889edb6035c21675d1bb1f45c9f" +dependencies = [ + "bitflags 2.6.0", + "hex", + "procfs-core", + "rustix", +] + +[[package]] +name = "procfs-core" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "239df02d8349b06fc07398a3a1697b06418223b1c7725085e801e7c0fc6a12ec" +dependencies = [ + "bitflags 2.6.0", + "hex", +] + [[package]] name = "proptest" version = "1.5.0" @@ -3540,21 +3565,20 @@ checksum = "6ff7ff745a347b87471d859a377a9a404361e7efc2a971d73424a6d183c0fc77" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] name = "quanta" -version = "0.9.3" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20afe714292d5e879d8b12740aa223c6a88f118af41870e8b6196e39a02238a8" +checksum = "8e5167a477619228a0b284fac2674e3c388cba90631d7b7de620e6f1fcd08da5" dependencies = [ "crossbeam-utils", "libc", - "mach", "once_cell", "raw-cpuid", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi", "web-sys", "winapi", ] @@ -3631,11 +3655,11 @@ dependencies = [ [[package]] name = "raw-cpuid" -version = "10.7.0" +version = "11.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c297679cb867470fa8c9f67dbba74a78d78e3e98d7cf2b08d6d71540f797332" +checksum = "1ab240315c661615f2ee9f0f2cd32d5a7343a84d5ebcccb99d46e6637565e7b0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.6.0", ] [[package]] @@ -3658,15 +3682,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_syscall" version = "0.5.4" @@ -3682,7 +3697,7 @@ version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ - "aho-corasick 1.1.3", + "aho-corasick", "memchr", "regex-automata 0.4.7", "regex-syntax 0.8.4", @@ -3703,7 +3718,7 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ - "aho-corasick 1.1.3", + "aho-corasick", "memchr", "regex-syntax 0.8.4", ] @@ -3735,7 +3750,7 @@ dependencies = [ "http 1.1.0", "http-body 1.0.1", "http-body-util", - "hyper 1.4.1", + "hyper", "hyper-rustls", "hyper-tls", "hyper-util", @@ -3810,7 +3825,7 @@ dependencies = [ "auto_impl", "derive_more", "metrics 0.23.0", - "parking_lot 0.12.3", + "parking_lot", "pin-project", "reth-chainspec", "reth-errors", @@ -3871,7 +3886,7 @@ dependencies = [ "convert_case", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -4127,10 +4142,10 @@ source = "git+https://github.com/paradigmxyz/reth.git?tag=v1.0.7#75b7172cf77eb4f dependencies = [ "bitflags 2.6.0", "byteorder", - "dashmap 6.1.0", + "dashmap", "derive_more", - "indexmap 2.5.0", - "parking_lot 0.12.3", + "indexmap 2.6.0", + "parking_lot", "reth-mdbx-sys", "thiserror", "tracing", @@ -4141,7 +4156,7 @@ name = "reth-mdbx-sys" version = "1.0.7" source = "git+https://github.com/paradigmxyz/reth.git?tag=v1.0.7#75b7172cf77eb4fd65fe1a6924f75066fb09fcd1" dependencies = [ - "bindgen", + "bindgen 0.69.4", "cc", ] @@ -4162,7 +4177,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -4401,11 +4416,11 @@ dependencies = [ "alloy-primitives", "alloy-rpc-types-engine", "auto_impl", - "dashmap 6.1.0", + "dashmap", "itertools 0.13.0", "metrics 0.23.0", "notify", - "parking_lot 0.12.3", + "parking_lot", "rayon", "reth-blockchain-tree-api", "reth-chain-state", @@ -4610,7 +4625,7 @@ dependencies = [ "bitflags 2.6.0", "futures-util", "metrics 0.23.0", - "parking_lot 0.12.3", + "parking_lot", "reth-chain-state", "reth-chainspec", "reth-eth-wire-types", @@ -4797,6 +4812,15 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "rlimit" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7043b63bd0cd1aaa628e476b80e6d4023a3b50eb32789f2728908107bd0c793a" +dependencies = [ + "libc", +] + [[package]] name = "rlp" version = "0.5.2" @@ -4842,12 +4866,14 @@ dependencies = [ "http 1.1.0", "http-body 0.4.6", "http-body-util", - "hyper 1.4.1", + "hyper", "hyper-util", "jsonrpsee", "metrics 0.24.0", "metrics-derive", "metrics-exporter-prometheus", + "metrics-process", + "metrics-util", "op-alloy-rpc-types", "op-alloy-rpc-types-engine", "predicates", @@ -4961,6 +4987,7 @@ version = "0.23.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ + "aws-lc-rs", "log", "once_cell", "ring", @@ -4983,6 +5010,19 @@ dependencies = [ "security-framework", ] +[[package]] +name = "rustls-native-certs" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcaf18a4f2be7326cd874a5fa579fae794320a0f388d365dca7e480e55f83f8a" +dependencies = [ + "openssl-probe", + "rustls-pemfile", + "rustls-pki-types", + "schannel", + "security-framework", +] + [[package]] name = "rustls-pemfile" version = "2.1.3" @@ -5011,7 +5051,7 @@ dependencies = [ "log", "once_cell", "rustls", - "rustls-native-certs", + "rustls-native-certs 0.7.3", "rustls-platform-verifier-android", "rustls-webpki", "security-framework", @@ -5032,6 +5072,7 @@ version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ + "aws-lc-rs", "ring", "rustls-pki-types", "untrusted", @@ -5085,7 +5126,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9a8ef13a93c54d20580de1e5c413e624e53121d42fc7e2c11d10ef7f8b02367" dependencies = [ - "ahash 0.8.11", + "ahash", "cfg-if", "hashbrown 0.13.2", ] @@ -5194,7 +5235,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -5203,7 +5244,7 @@ version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ - "indexmap 2.5.0", + "indexmap 2.6.0", "itoa", "memchr", "ryu", @@ -5218,7 +5259,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -5243,7 +5284,7 @@ dependencies = [ "chrono", "hex", "indexmap 1.9.3", - "indexmap 2.5.0", + "indexmap 2.6.0", "serde", "serde_derive", "serde_json", @@ -5260,7 +5301,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -5353,9 +5394,9 @@ dependencies = [ [[package]] name = "sketches-ddsketch" -version = "0.1.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04d2ecae5fcf33b122e2e6bd520a57ccf152d2dde3b38c71039df1a6867264ee" +checksum = "c1e9a774a6c28142ac54bb25d25562e6bcf957493a184f15ad4eebccb23e410a" [[package]] name = "slab" @@ -5451,7 +5492,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -5486,9 +5527,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.77" +version = "2.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" dependencies = [ "proc-macro2", "quote", @@ -5504,7 +5545,7 @@ dependencies = [ "paste", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -5533,7 +5574,7 @@ dependencies = [ "libc", "ntapi", "once_cell", - "windows", + "windows 0.52.0", ] [[package]] @@ -5599,7 +5640,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -5706,7 +5747,7 @@ dependencies = [ "bytes", "libc", "mio 1.0.2", - "parking_lot 0.12.3", + "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", @@ -5722,7 +5763,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -5784,7 +5825,7 @@ version = "0.22.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b072cee73c449a636ffd6f32bd8de3a9f7119139aff882f44943ce2986dc5cf" dependencies = [ - "indexmap 2.5.0", + "indexmap 2.6.0", "toml_datetime", "winnow", ] @@ -5863,7 +5904,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -6089,12 +6130,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -6123,7 +6158,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", "wasm-bindgen-shared", ] @@ -6157,7 +6192,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -6187,6 +6222,18 @@ dependencies = [ "rustls-pki-types", ] +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + [[package]] name = "winapi" version = "0.3.9" @@ -6224,7 +6271,17 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" dependencies = [ - "windows-core", + "windows-core 0.52.0", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +dependencies = [ + "windows-core 0.58.0", "windows-targets 0.52.6", ] @@ -6237,6 +6294,41 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-implement" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.85", +] + +[[package]] +name = "windows-interface" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.85", +] + [[package]] name = "windows-registry" version = "0.2.0" @@ -6451,7 +6543,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] @@ -6471,7 +6563,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.85", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index d345405..85faad4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,9 @@ reth-optimism-payload-builder = { git = "https://github.com/paradigmxyz/reth.git futures = "0.3.31" metrics-derive = "0.1" metrics = "0.24.0" -metrics-exporter-prometheus = "0.7" +metrics-exporter-prometheus = "0.16.0" +metrics-process = "2.3.1" +metrics-util = "0.18.0" [dev-dependencies] anyhow = "1.0" diff --git a/README.md b/README.md index 43fe1f8..a066ea2 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,16 @@ cargo run -- [OPTIONS] ### Command-line Options - `--jwt-token `: JWT token for authentication (required) +- `--jwt-path `: Path to the JWT secret file (required if `--jwt-token` is not provided) - `--l2-url `: URL of the local L2 execution engine (required) - `--builder-url `: URL of the builder execution engine (required) +- `--builder-jwt-token `: JWT token for builder authentication. defaults to the value of `--jwt-token` if not provided +- `--builder-jwt-path `: Path to the builder JWT secret file. - `--rpc-host `: Host to run the server on (default: 0.0.0.0) - `--rpc-port `: Port to run the server on (default: 8081) - `--tracing`: Enable tracing (default: false) - `--log-level `: Log level (default: info) +- `--metrics`: Enable metrics (default: false) - `--boost-sync`: Enable syncing the builder with the proposer op-node (default: false) ### Environment Variables diff --git a/src/error.rs b/src/error.rs index adff823..734dd7c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -8,6 +8,6 @@ pub enum Error { InitRPCClient(String), #[error("Error Initializing RPC Server: {0}")] InitRPCServer(String), - #[error("Error Initializing Metrics: {0}")] + #[error("Error Initializing Prometheus Metrics: {0}")] InitMetrics(String), } diff --git a/src/main.rs b/src/main.rs index b353ee1..aa29107 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ use jsonrpsee::server::Server; use jsonrpsee::RpcModule; use metrics::ServerMetrics; use metrics_exporter_prometheus::PrometheusBuilder; +use metrics_util::layers::{PrefixLayer, Stack}; use proxy::ProxyLayer; use reth_rpc_layer::{AuthClientLayer, AuthClientService}; use server::{EngineApiServer, EthEngineApi}; @@ -66,6 +67,10 @@ struct Args { #[arg(long, env, default_value = "false")] tracing: bool, + // Enable Prometheus metrics + #[arg(long, env, default_value = "false")] + metrics: bool, + /// Log level #[arg(long, env, default_value = "info")] log_level: Level, @@ -84,10 +89,20 @@ async fn main() -> Result<()> { .with_env_filter(EnvFilter::new(args.log_level.to_string())) // Set the log level .init(); - PrometheusBuilder::new() - .install() - .map_err(|e| Error::InitMetrics(e.to_string()))?; - let metrics = ServerMetrics::default(); + let (metrics, handler) = if args.metrics { + let recorder = PrometheusBuilder::new().build_recorder(); + let handle = recorder.handle(); + + // Build metrics stack + Stack::new(recorder) + .push(PrefixLayer::new("rollup-boost")) + .install() + .map_err(|e| Error::InitMetrics(e.to_string()))?; + + (Some(Arc::new(ServerMetrics::default())), Some(handle)) + } else { + (None, None) + }; // Handle JWT secret let jwt_secret = match (args.jwt_path, args.jwt_token) { @@ -140,6 +155,7 @@ async fn main() -> Result<()> { args.l2_url .parse::() .map_err(|e| Error::InvalidArgs(e.to_string()))?, + handler, )); let server = Server::builder() .set_http_middleware(service_builder) diff --git a/src/metrics.rs b/src/metrics.rs index c648252..ac25905 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -2,9 +2,9 @@ use metrics::Counter; use metrics_derive::Metrics; #[derive(Metrics)] -#[metrics(scope = "metrics_custom")] +#[metrics(scope = "rpc")] pub struct ServerMetrics { - #[metric(describe = "Count of fork_choice_updated_v3 calls proxied to the builder")] + #[metric(describe = "Count of forkchoice_updated_v3 calls proxied to the builder")] pub fcu_count: Counter, #[metric(describe = "Count of new_payload_v3 calls proxied to the builder")] diff --git a/src/proxy.rs b/src/proxy.rs index a1e2156..aa9fb9d 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -1,9 +1,11 @@ -use http::Uri; +use http::header::CONTENT_TYPE; +use http::{HeaderValue, Uri}; use hyper_util::client::legacy::connect::HttpConnector; use hyper_util::client::legacy::Client; use hyper_util::rt::TokioExecutor; use jsonrpsee::core::{http_helpers, BoxError}; use jsonrpsee::http_client::{HttpBody, HttpRequest, HttpResponse}; +use metrics_exporter_prometheus::PrometheusHandle; use std::task::{Context, Poll}; use std::{future::Future, pin::Pin}; use tower::{Layer, Service}; @@ -14,11 +16,12 @@ const MULTIPLEX_METHODS: [&str; 2] = ["engine_", "eth_sendRawTransaction"]; #[derive(Debug, Clone)] pub struct ProxyLayer { target_url: Uri, + handle: Option, } impl ProxyLayer { - pub fn new(target_url: Uri) -> Self { - ProxyLayer { target_url } + pub fn new(target_url: Uri, handle: Option) -> Self { + ProxyLayer { target_url, handle } } } @@ -30,15 +33,17 @@ impl Layer for ProxyLayer { inner, client: Client::builder(TokioExecutor::new()).build_http(), target_url: self.target_url.clone(), + handle: self.handle.clone(), } } } -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct ProxyService { inner: S, client: Client, target_url: Uri, + handle: Option, } impl Service> for ProxyService @@ -60,7 +65,18 @@ where fn call(&mut self, req: HttpRequest) -> Self::Future { match req.uri().path() { "/healthz" => return Box::pin(async { Ok(Self::Response::new(HttpBody::from("OK"))) }), - "/metrics" => {} + "/metrics" => { + if let Some(handle) = self.handle.as_ref() { + let metrics = handle.render(); + return Box::pin(async { + let mut response = Self::Response::new(HttpBody::from(metrics)); + response + .headers_mut() + .insert(CONTENT_TYPE, HeaderValue::from_static("text/plain")); + Ok::(response) + }); + } + } _ => {} }; @@ -238,7 +254,8 @@ mod tests { /// Spawn a new RPC server with a proxy layer. async fn spawn_proxy_server() -> ServerHandle { let addr = format!("{ADDR}:{PORT}"); - let proxy_layer = ProxyLayer::new(format!("http://{ADDR}:{PROXY_PORT}").parse().unwrap()); + let proxy_layer = + ProxyLayer::new(format!("http://{ADDR}:{PROXY_PORT}").parse().unwrap(), None); // Create a layered server let server = ServerBuilder::default() .set_http_middleware(tower::ServiceBuilder::new().layer(proxy_layer)) diff --git a/src/server.rs b/src/server.rs index cf488b6..4445e6f 100644 --- a/src/server.rs +++ b/src/server.rs @@ -18,7 +18,6 @@ use std::sync::Arc; use tracing::{debug, error, info}; use crate::metrics::ServerMetrics; -use crate::selector::{DefaultPayloadSelector, PayloadSelector}; #[rpc(server, client, namespace = "engine")] pub trait EngineApi { @@ -54,7 +53,7 @@ pub struct EthEngineApi> { l2_client: Arc>, builder_client: Arc>, boost_sync: bool, - metrics: ServerMetrics, + metrics: Option>, } impl EthEngineApi { @@ -62,14 +61,13 @@ impl EthEngineApi { l2_client: Arc>, builder_client: Arc>, boost_sync: bool, - metrics: ServerMetrics, + metrics: Option>, ) -> Self { Self { l2_client, builder_client, boost_sync, metrics, - payload_selector: Arc::new(DefaultPayloadSelector), } } } @@ -81,16 +79,19 @@ impl EthApiServer for EthEngineApi { message = "received send_raw_transaction", "bytes_len" = bytes.len() ); - for builder in self.builder_clients.iter() { - self.metrics.send_raw_tx_count.increment(1); - let builder = builder.clone(); - let tx_bytes = bytes.clone(); - tokio::spawn(async move { - builder.send_raw_transaction(tx_bytes).await.map_err(|e| { - error!(message = "error calling send_raw_transaction for builder", "error" = %e); - }) - }); + + if let Some(metrics) = &self.metrics { + metrics.send_raw_tx_count.increment(1); } + + let builder = self.builder_client.clone(); + let tx_bytes = bytes.clone(); + tokio::spawn(async move { + builder.send_raw_transaction(tx_bytes).await.map_err(|e| { + error!(message = "error calling send_raw_transaction for builder", "error" = %e); + }) + }); + self.l2_client .send_raw_transaction(bytes) .await @@ -132,13 +133,14 @@ impl EngineApiServer for EthEngineApi { }; if should_send_to_builder { - // async call to each builder to trigger payload building and sync - for builder in self.builder_clients.iter() { - self.metrics.fcu_count.increment(1); - let builder = builder.clone(); - let attr = payload_attributes.clone(); - tokio::spawn(async move { - builder.fork_choice_updated_v3(fork_choice_state, attr).await.map(|response| { + // async call to builder to trigger payload building and sync + if let Some(metrics) = &self.metrics { + metrics.fcu_count.increment(1); + } + let builder = self.builder_client.clone(); + let attr = payload_attributes.clone(); + tokio::spawn(async move { + builder.fork_choice_updated_v3(fork_choice_state, attr).await.map(|response| { let payload_id_str = response.payload_id.map(|id| id.to_string()).unwrap_or_default(); if response.is_invalid() { error!(message = "builder rejected fork_choice_updated_v3 with attributes", "payload_id" = payload_id_str, "validation_error" = %response.payload_status.status); @@ -175,13 +177,14 @@ impl EngineApiServer for EthEngineApi { ) -> RpcResult { info!(message = "received get_payload_v3", "payload_id" = %payload_id); let l2_client_future = self.l2_client.get_payload_v3(payload_id); - let builder_client_futures = self.builder_clients.iter().map(|builder| { - let builder = builder.clone(); - Box::pin(async move { - self.metrics.get_payload_count.increment(1); - let payload = builder.get_payload_v3(payload_id).await.map_err(|e| { - error!(message = "error calling get_payload_v3 from builder", "error" = %e, "payload_id" = %payload_id); - e + let builder_client_future = Box::pin(async move { + if let Some(metrics) = &self.metrics { + metrics.get_payload_count.increment(1); + } + let builder = self.builder_client.clone(); + let payload = builder.get_payload_v3(payload_id).await.map_err(|e| { + error!(message = "error calling get_payload_v3 from builder", "error" = %e, "payload_id" = %payload_id); + e })?; info!(message = "received payload from builder", "payload_id" = %payload_id, "block_hash" = %payload.as_v1_payload().block_hash); @@ -189,6 +192,9 @@ impl EngineApiServer for EthEngineApi { // Send the payload to the local execution engine with engine_newPayload to validate the block from the builder. // Otherwise, we do not want to risk the network to a halt since op-node will not be able to propose the block. // If validation fails, return the local block since that one has already been validated. + if let Some(metrics) = &self.metrics { + metrics.new_payload_count.increment(1); + } let payload_status = self.l2_client.new_payload_v3(payload.execution_payload.clone(), vec![], payload.parent_beacon_block_root).await.map_err(|e| { error!(message = "error calling new_payload_v3 to validate builder payload", "error" = %e, "payload_id" = %payload_id); e @@ -232,13 +238,15 @@ impl EngineApiServer for EthEngineApi { // async call to builder to sync the builder node if self.boost_sync { - for builder in self.builder_clients.iter() { - self.metrics.new_payload_count.increment(1); - let builder = builder.clone(); - let builder_payload = payload.clone(); - let builder_versioned_hashes = versioned_hashes.clone(); - tokio::spawn(async move { - builder.new_payload_v3(builder_payload, builder_versioned_hashes, parent_beacon_block_root).await + if let Some(metrics) = &self.metrics { + metrics.new_payload_count.increment(1); + } + + let builder = self.builder_client.clone(); + let builder_payload = payload.clone(); + let builder_versioned_hashes = versioned_hashes.clone(); + tokio::spawn(async move { + builder.new_payload_v3(builder_payload, builder_versioned_hashes, parent_beacon_block_root).await .map(|response: PayloadStatus| { if response.is_invalid() { error!(message = "builder rejected new_payload_v3", "block_hash" = %block_hash);