From 684b14c8a796de7e53fbce91ca18a577a3d199a5 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 20 Apr 2023 14:48:15 -0700 Subject: [PATCH 01/18] enable sasl for kafka --- Cargo.lock | 45 +++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 1 + web3_proxy/Cargo.toml | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index ae05a0fb..354b1f40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1452,6 +1452,18 @@ version = "0.15.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03d8c417d7a8cb362e0c37e5d815f5eb7c37f79ff93707329d5a194e42e54ca0" +[[package]] +name = "duct" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37ae3fc31835f74c2a7ceda3aeede378b0ae2e74c8f1c36559fcc9ae2a4e7d3e" +dependencies = [ + "libc", + "once_cell", + "os_pipe", + "shared_child", +] + [[package]] name = "dunce" version = "1.0.3" @@ -3594,6 +3606,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "os_pipe" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a53dbb20faf34b16087a931834cba2d7a73cc74af2b7ef345a4c8324e2409a12" +dependencies = [ + "libc", + "windows-sys 0.45.0", +] + [[package]] name = "os_str_bytes" version = "6.4.1" @@ -4307,6 +4329,7 @@ dependencies = [ "num_enum 0.5.11", "openssl-sys", "pkg-config", + "sasl2-sys", "zstd-sys", ] @@ -4711,6 +4734,18 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "sasl2-sys" +version = "0.1.20+2.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e645bd98535fc8fd251c43ba7c7c1f9be1e0369c99b6a5ea719052a773e655c" +dependencies = [ + "cc", + "duct", + "libc", + "pkg-config", +] + [[package]] name = "scale-info" version = "2.3.1" @@ -5289,6 +5324,16 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shared_child" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0d94659ad3c2137fef23ae75b03d5241d633f8acded53d672decfa0e6e0caef" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "signal-hook" version = "0.3.15" diff --git a/Dockerfile b/Dockerfile index e1bbb8e2..a09e71ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,7 @@ RUN apt-get update && \ cmake \ liblz4-dev \ libpthread-stubs0-dev \ + libsasl2-dev \ libssl-dev \ libzstd-dev \ make \ diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index 1136ad26..dbcc230e 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -10,7 +10,7 @@ default-run = "web3_proxy_cli" default = ["deadlock_detection"] deadlock_detection = ["parking_lot/deadlock_detection"] tokio-console = ["dep:tokio-console", "dep:console-subscriber"] -rdkafka-src = ["rdkafka/cmake-build", "rdkafka/libz", "rdkafka/ssl", "rdkafka/zstd-pkg-config"] +rdkafka-src = ["rdkafka/cmake-build", "rdkafka/gssapi", "rdkafka/libz", "rdkafka/ssl", "rdkafka/zstd-pkg-config"] [dependencies] deferred-rate-limiter = { path = "../deferred-rate-limiter" } From 4d2c0dae533023e330117a9685c25f28a40c2da2 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 20 Apr 2023 18:08:53 -0700 Subject: [PATCH 02/18] no sasl --- Cargo.lock | 45 ------------------------------------------- web3_proxy/Cargo.toml | 2 +- 2 files changed, 1 insertion(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 354b1f40..ae05a0fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1452,18 +1452,6 @@ version = "0.15.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03d8c417d7a8cb362e0c37e5d815f5eb7c37f79ff93707329d5a194e42e54ca0" -[[package]] -name = "duct" -version = "0.13.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ae3fc31835f74c2a7ceda3aeede378b0ae2e74c8f1c36559fcc9ae2a4e7d3e" -dependencies = [ - "libc", - "once_cell", - "os_pipe", - "shared_child", -] - [[package]] name = "dunce" version = "1.0.3" @@ -3606,16 +3594,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "os_pipe" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a53dbb20faf34b16087a931834cba2d7a73cc74af2b7ef345a4c8324e2409a12" -dependencies = [ - "libc", - "windows-sys 0.45.0", -] - [[package]] name = "os_str_bytes" version = "6.4.1" @@ -4329,7 +4307,6 @@ dependencies = [ "num_enum 0.5.11", "openssl-sys", "pkg-config", - "sasl2-sys", "zstd-sys", ] @@ -4734,18 +4711,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "sasl2-sys" -version = "0.1.20+2.1.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e645bd98535fc8fd251c43ba7c7c1f9be1e0369c99b6a5ea719052a773e655c" -dependencies = [ - "cc", - "duct", - "libc", - "pkg-config", -] - [[package]] name = "scale-info" version = "2.3.1" @@ -5324,16 +5289,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "shared_child" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0d94659ad3c2137fef23ae75b03d5241d633f8acded53d672decfa0e6e0caef" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "signal-hook" version = "0.3.15" diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index dbcc230e..1136ad26 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -10,7 +10,7 @@ default-run = "web3_proxy_cli" default = ["deadlock_detection"] deadlock_detection = ["parking_lot/deadlock_detection"] tokio-console = ["dep:tokio-console", "dep:console-subscriber"] -rdkafka-src = ["rdkafka/cmake-build", "rdkafka/gssapi", "rdkafka/libz", "rdkafka/ssl", "rdkafka/zstd-pkg-config"] +rdkafka-src = ["rdkafka/cmake-build", "rdkafka/libz", "rdkafka/ssl", "rdkafka/zstd-pkg-config"] [dependencies] deferred-rate-limiter = { path = "../deferred-rate-limiter" } From 7a087415a2fbb08fdddb33260c08769afa35843e Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 20 Apr 2023 19:55:18 -0700 Subject: [PATCH 03/18] hash instead of block_hash --- web3_proxy/src/rpcs/blockchain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web3_proxy/src/rpcs/blockchain.rs b/web3_proxy/src/rpcs/blockchain.rs index 34a09e7a..1eb28f18 100644 --- a/web3_proxy/src/rpcs/blockchain.rs +++ b/web3_proxy/src/rpcs/blockchain.rs @@ -43,7 +43,7 @@ impl Serialize for Web3ProxyBlock { state.serialize_field("age", &self.age())?; let block = json!({ - "block_hash": self.block.hash, + "hash": self.block.hash, "parent_hash": self.block.parent_hash, "number": self.block.number, "timestamp": self.block.timestamp, From 78fceb1fbf114d0c763c2ede29430a1a2cb9daac Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 20 Apr 2023 20:00:54 -0700 Subject: [PATCH 04/18] features on tests --- Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index a09e71ff..8e904724 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,20 +35,20 @@ COPY . . # test the application with cargo-nextest RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/app/target \ - cargo nextest run + cargo nextest run --features "rdkafka-src tokio-uring" --no-default-features # build the application # using a "release" profile (which install does) is **very** important RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/app/target \ cargo install \ - --features tokio-uring \ + --features "rdkafka-src tokio-uring" \ --locked \ - --features rdkafka-src \ --no-default-features \ --path ./web3_proxy \ --profile faster_release \ - --root /usr/local/bin + --root /usr/local/bin \ + ; # # We do not need the Rust toolchain to run the binary! From 56fdf481298df7fa7d4e3678ccadae20418e01f1 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 24 Apr 2023 11:00:12 -0700 Subject: [PATCH 05/18] Send transactions to protected and public rpcs (#57) * move protected transactions into their own function and dry stats sending * cargo upgrade * comments * time to live instead of time to idle * minor workaround for eth_chainId * cargo upgrade --- Cargo.lock | 125 +++++----- entities/Cargo.toml | 2 +- migration/Cargo.toml | 2 +- redis-rate-limiter/Cargo.toml | 2 +- web3_proxy/Cargo.toml | 4 +- web3_proxy/src/app/mod.rs | 349 ++++++++++++++-------------- web3_proxy/src/bin/wait_for_sync.rs | 2 + web3_proxy/src/block_number.rs | 7 +- web3_proxy/src/rpcs/many.rs | 8 +- web3_proxy/src/rpcs/one.rs | 4 +- web3_proxy/src/rpcs/request.rs | 11 +- 11 files changed, 262 insertions(+), 254 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ae05a0fb..e1f6cfa2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -74,9 +74,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.20" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +checksum = "67fc08ce920c31afb70f013dcce1bfc3a3195de6a228474e45e1f145b36f8d04" dependencies = [ "memchr", ] @@ -408,9 +408,9 @@ checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" [[package]] name = "base64ct" -version = "1.5.3" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b645a089122eccb6111b4f81cbc1a49f5900ac4666bb93ac027feaecf15607bf" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "bech32" @@ -492,9 +492,9 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ "generic-array", ] @@ -555,9 +555,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.12.0" +version = "3.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" +checksum = "9b1ce199063694f33ffb7dd4e0ee620741495c32833cde5aa08f02a0bf96f0c8" [[package]] name = "byte-slice-cast" @@ -567,19 +567,20 @@ checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" [[package]] name = "bytecheck" -version = "0.6.9" +version = "0.6.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d11cac2c12b5adc6570dad2ee1b87eff4955dac476fe12d81e5fdd352e52406f" +checksum = "13fe11640a23eb24562225322cd3e452b93a3d4091d62fab69c70542fcd17d1f" dependencies = [ "bytecheck_derive", "ptr_meta", + "simdutf8", ] [[package]] name = "bytecheck_derive" -version = "0.6.9" +version = "0.6.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13e576ebe98e605500b3c8041bb888e966653577172df6dd97398714eb30b9bf" +checksum = "e31225543cb46f81a7e224762764f4a6a0f097b1db0b175f69e8065efaa42de5" dependencies = [ "proc-macro2", "quote", @@ -817,21 +818,19 @@ dependencies = [ [[package]] name = "coins-bip39" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad2a68a46b9d8cc90484f0689adc0e4c890eb215bf698ae52e5235bb88f40be7" +checksum = "84f4d04ee18e58356accd644896aeb2094ddeafb6a713e056cef0c0a8e468c15" dependencies = [ "bitvec 0.17.4", "coins-bip32", "getrandom", - "hex", "hmac", "once_cell", "pbkdf2 0.12.1", "rand", "sha2 0.10.6", "thiserror", - "tracing", ] [[package]] @@ -965,7 +964,7 @@ dependencies = [ "tonic", "tracing", "tracing-core", - "tracing-subscriber 0.3.16", + "tracing-subscriber 0.3.17", ] [[package]] @@ -1019,9 +1018,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.5" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +checksum = "3e4c1eaa2012c47becbbad2ab175484c2a84d1185b566fb2cc5b8707343dfe58" dependencies = [ "libc", ] @@ -1087,9 +1086,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.14" +version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" +checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" dependencies = [ "cfg-if", ] @@ -1270,9 +1269,9 @@ dependencies = [ [[package]] name = "deadpool-redis" -version = "0.11.1" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b8bde44cbfdf17ae5baa45c9f43073b320f1a19955389315629304a23909ad2" +checksum = "5f1760f60ffc6653b4afd924c5792098d8c00d9a3deb6b3d989eac17949dc422" dependencies = [ "deadpool", "redis", @@ -1387,7 +1386,7 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" dependencies = [ - "block-buffer 0.10.3", + "block-buffer 0.10.4", "const-oid 0.9.2", "crypto-common", "subtle", @@ -3004,7 +3003,7 @@ dependencies = [ "petgraph", "pico-args", "regex", - "regex-syntax", + "regex-syntax 0.6.29", "string_cache", "term", "tiny-keccak", @@ -3031,9 +3030,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.141" +version = "0.2.142" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" +checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317" [[package]] name = "libm" @@ -3576,9 +3575,9 @@ dependencies = [ [[package]] name = "ordered-float" -version = "3.6.0" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13a384337e997e6860ffbaa83708b2ef329fd8c54cb67a5f64d421e0f943254f" +checksum = "2fc2dbde8f8a79f2102cc474ceb0ad68e3b80b85289ea62389b60e66777e4213" dependencies = [ "num-traits", ] @@ -3596,9 +3595,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.4.1" +version = "6.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" +checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" [[package]] name = "ouroboros" @@ -4312,9 +4311,9 @@ dependencies = [ [[package]] name = "redis" -version = "0.22.3" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa8455fa3621f6b41c514946de66ea0531f57ca017b2e6c7cc368035ea5b46df" +checksum = "3ea8c51b5dc1d8e5fd3350ec8167f464ec0995e79f2e90a075b63371500d557f" dependencies = [ "async-trait", "bytes", @@ -4370,13 +4369,13 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.3" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" +checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.7.1", ] [[package]] @@ -4385,7 +4384,7 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" dependencies = [ - "regex-syntax", + "regex-syntax 0.6.29", ] [[package]] @@ -4394,6 +4393,12 @@ version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" +[[package]] +name = "regex-syntax" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c" + [[package]] name = "rend" version = "0.4.0" @@ -4683,9 +4688,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" +checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" [[package]] name = "ryu" @@ -4795,9 +4800,9 @@ dependencies = [ [[package]] name = "sea-orm" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5d875e2fcd965320e50066028ac0b4877ff07edbb734a6ddfeff48a87dbab38" +checksum = "fade86e8d41fd1a4721f84cb834f4ca2783f973cc30e6212b7fafc134f169214" dependencies = [ "async-stream", "async-trait", @@ -4823,9 +4828,9 @@ dependencies = [ [[package]] name = "sea-orm-cli" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ead9f7dac975f10447f17d08edbb2046daa087b5e0b50bbf8211f303459078c" +checksum = "efbf34a2caf70c2e3be9bb1e674e9540f6dfd7c8f40f6f05daf3b9740e476005" dependencies = [ "chrono", "clap", @@ -4833,15 +4838,15 @@ dependencies = [ "regex", "sea-schema", "tracing", - "tracing-subscriber 0.3.16", + "tracing-subscriber 0.3.17", "url", ] [[package]] name = "sea-orm-macros" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9b593e9c0cdbb18cafd4da7b92e67a9c2d9892934f3a2d8bbac73d5ba4a98a1" +checksum = "28936f26d62234ff0be16f80115dbdeb3237fe9c25cf18fbcd1e3b3592360f20" dependencies = [ "bae", "heck 0.3.3", @@ -4852,9 +4857,9 @@ dependencies = [ [[package]] name = "sea-orm-migration" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edba7a6123c1035b0530deb713820688f0234431ab6c1893b14dce493ade76af" +checksum = "278d3adfd0832b6ffc17d3cfbc574d3695a5c1b38814e0bc8ac238d33f3d87cf" dependencies = [ "async-trait", "clap", @@ -4864,7 +4869,7 @@ dependencies = [ "sea-orm-cli", "sea-schema", "tracing", - "tracing-subscriber 0.3.16", + "tracing-subscriber 0.3.17", ] [[package]] @@ -5339,6 +5344,12 @@ dependencies = [ "rand_core", ] +[[package]] +name = "simdutf8" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" + [[package]] name = "siphasher" version = "0.3.10" @@ -5932,7 +5943,7 @@ dependencies = [ "toml 0.5.11", "tonic", "tracing", - "tracing-subscriber 0.3.16", + "tracing-subscriber 0.3.17", "tui", ] @@ -6191,13 +6202,13 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" +checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.15", ] [[package]] @@ -6275,9 +6286,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70" +checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" dependencies = [ "matchers 0.1.0", "nu-ansi-term", @@ -6978,9 +6989,9 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" [[package]] name = "zeroize" -version = "1.5.7" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" [[package]] name = "zip" diff --git a/entities/Cargo.toml b/entities/Cargo.toml index 8fe7206e..1d9a1d54 100644 --- a/entities/Cargo.toml +++ b/entities/Cargo.toml @@ -10,7 +10,7 @@ path = "src/mod.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -sea-orm = "0.11.2" +sea-orm = "0.11.3" serde = "1.0.160" uuid = "1.3.1" ethers = "2.0.3" diff --git a/migration/Cargo.toml b/migration/Cargo.toml index 22d5c752..b6fa5de2 100644 --- a/migration/Cargo.toml +++ b/migration/Cargo.toml @@ -12,7 +12,7 @@ path = "src/lib.rs" tokio = { version = "1.27.0", features = ["full", "tracing"] } [dependencies.sea-orm-migration] -version = "0.11.2" +version = "0.11.3" features = [ # Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI. # View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime. diff --git a/redis-rate-limiter/Cargo.toml b/redis-rate-limiter/Cargo.toml index 5f0480e8..7c7c4c71 100644 --- a/redis-rate-limiter/Cargo.toml +++ b/redis-rate-limiter/Cargo.toml @@ -7,5 +7,5 @@ edition = "2021" [dependencies] anyhow = "1.0.70" chrono = "0.4.24" -deadpool-redis = { version = "0.11.1", features = ["rt_tokio_1", "serde"] } +deadpool-redis = { version = "0.12.0", features = ["rt_tokio_1", "serde"] } tokio = "1.27.0" diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index 1136ad26..7db6e8f4 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -58,13 +58,13 @@ moka = { version = "0.10.2", default-features = false, features = ["future"] } num = "0.4.0" num-traits = "0.2.15" once_cell = { version = "1.17.1" } -ordered-float = "3.6.0" +ordered-float = "3.7.0" pagerduty-rs = { version = "0.1.6", default-features = false, features = ["async", "rustls", "sync"] } parking_lot = { version = "0.12.1", features = ["arc_lock"] } prettytable = "*" proctitle = "0.1.1" rdkafka = { version = "0.29.0" } -regex = "1.7.3" +regex = "1.8.1" reqwest = { version = "0.11.16", default-features = false, features = ["json", "tokio-rustls"] } rmp-serde = "1.1.1" rustc-hash = "1.1.0" diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index eec2883f..0f4b30fa 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -670,12 +670,13 @@ impl Web3ProxyApp { // TODO: capacity from configs // all these are the same size, so no need for a weigher - // TODO: ttl on this? or is max_capacity fine? + // TODO: this used to have a time_to_idle let pending_transactions = Cache::builder() .max_capacity(10_000) // TODO: different chains might handle this differently // TODO: what should we set? 5 minutes is arbitrary. the nodes themselves hold onto transactions for much longer - .time_to_idle(Duration::from_secs(300)) + // TODO: this used to be time_to_update, but + .time_to_live(Duration::from_secs(300)) .build_with_hasher(hashbrown::hash_map::DefaultHashBuilder::default()); // responses can be very different in sizes, so this is a cache with a max capacity and a weigher @@ -695,7 +696,7 @@ impl Web3ProxyApp { } }) // TODO: what should we set? 10 minutes is arbitrary. the nodes themselves hold onto transactions for much longer - .time_to_idle(Duration::from_secs(600)) + .time_to_live(Duration::from_secs(600)) .build_with_hasher(hashbrown::hash_map::DefaultHashBuilder::default()); // all the users are the same size, so no need for a weigher @@ -1208,14 +1209,101 @@ impl Web3ProxyApp { } } + /// try to send transactions to the best available rpcs with private mempools + /// if no private rpcs are configured, then some public rpcs are used instead + async fn try_send_protected( + self: &Arc, + authorization: &Arc, + request: &JsonRpcRequest, + request_metadata: Arc, + num_public_rpcs: Option, + head_block_num: Option, + ) -> Web3ProxyResult { + // TODO: error/wait if no head block? + // TODO: configurable lag + let min_block_needed = head_block_num + .or(self.balanced_rpcs.head_block_num()) + .ok_or_else(|| Web3ProxyError::NoServersSynced)? + .saturating_sub(3.into()); + + if let Some(protected_rpcs) = self.private_rpcs.as_ref() { + if !protected_rpcs.is_empty() { + // send to protected and public rpcs at the same time + // TODO: send to tier 0 of private, wait a block, ..., tier N of private, wait a block, public + // TODO: allow premium users to choose specifically where they want transactions to go + let public_f = { + let authorization = authorization.clone(); + let clone = self.clone(); + // TODO: should request be in an arc? inside the request metadata? + let request = request.clone(); + let request_metadata = Some(request_metadata.clone()); + + async move { + clone + .balanced_rpcs + .try_send_all_synced_connections( + &authorization, + &request, + request_metadata, + Some(&min_block_needed), + None, + Level::Trace, + num_public_rpcs, + true, + ) + .await + } + }; + + let public_handle = tokio::spawn(public_f); + + let protected_response = protected_rpcs + .try_send_all_synced_connections( + authorization, + request, + Some(request_metadata), + None, + None, + Level::Trace, + None, + true, + ) + .await?; + + // wait for sending to the public rpcs to finish + // TODO: let this run in the background instead? + public_handle.await??; + + return Ok(protected_response); + } + } + + // no private rpcs to send to. send to a few public rpcs + // try_send_all_upstream_servers puts the request id into the response. no need to do that ourselves here. + self.balanced_rpcs + .try_send_all_synced_connections( + authorization, + request, + Some(request_metadata), + Some(&min_block_needed), + None, + Level::Trace, + num_public_rpcs, + true, + ) + .await + } + // TODO: more robust stats and kafka logic! if we use the try operator, they aren't saved! + // TODO: move this to another module async fn proxy_cached_request( self: &Arc, authorization: &Arc, mut request: JsonRpcRequest, head_block_num: Option, ) -> Web3ProxyResult<(JsonRpcForwardedResponse, Vec>)> { - // trace!("Received request: {:?}", request); + // TODO: move this code to another module so that its easy to turn this trace logging on in dev + trace!("Received request: {:?}", request); let request_metadata = Arc::new(RequestMetadata::new(request.num_bytes())); @@ -1287,7 +1375,7 @@ impl Web3ProxyApp { // TODO: if eth_chainId or net_version, serve those without querying the backend // TODO: don't clone? - let partial_response: serde_json::Value = match request_method.as_ref() { + let response: JsonRpcForwardedResponse = match request_method.as_ref() { // lots of commands are blocked method @ ("db_getHex" | "db_getString" @@ -1357,14 +1445,11 @@ impl Web3ProxyApp { | "shh_version") => { // i don't think we will ever support these methods // TODO: what error code? - return Ok(( - JsonRpcForwardedResponse::from_string( - format!("method unsupported: {}", method), - None, - Some(request_id), - ), - vec![], - )); + JsonRpcForwardedResponse::from_string( + format!("method unsupported: {}", method), + None, + Some(request_id), + ) } // TODO: implement these commands method @ ("eth_getFilterChanges" @@ -1376,36 +1461,29 @@ impl Web3ProxyApp { | "eth_uninstallFilter") => { // TODO: unsupported command stat. use the count to prioritize new features // TODO: what error code? - return Ok(( - // TODO: what code? - JsonRpcForwardedResponse::from_string( - format!("not yet implemented: {}", method), - None, - Some(request_id), - ), - vec![], - )); + JsonRpcForwardedResponse::from_string( + format!("not yet implemented: {}", method), + None, + Some(request_id), + ) } method @ ("debug_bundler_sendBundleNow" | "debug_bundler_clearState" | "debug_bundler_dumpMempool") => { - return Ok(( - JsonRpcForwardedResponse::from_string( - // TODO: we should probably have some escaping on this. but maybe serde will protect us enough - format!("method unsupported: {}", method), - None, - Some(request_id), - ), - vec![], - )); + JsonRpcForwardedResponse::from_string( + // TODO: we should probably have some escaping on this. but maybe serde will protect us enough + format!("method unsupported: {}", method), + None, + Some(request_id), + ) } - method @ ("eth_sendUserOperation" + _method @ ("eth_sendUserOperation" | "eth_estimateUserOperationGas" | "eth_getUserOperationByHash" | "eth_getUserOperationReceipt" | "eth_supportedEntryPoints") => match self.bundler_4337_rpcs.as_ref() { Some(bundler_4337_rpcs) => { - let response = bundler_4337_rpcs + bundler_4337_rpcs .try_proxy_connection( authorization, request, @@ -1413,56 +1491,39 @@ impl Web3ProxyApp { None, None, ) - .await?; - - // TODO: DRY - let rpcs = request_metadata.backend_requests.lock().clone(); - - if let Some(stat_sender) = self.stat_sender.as_ref() { - let response_stat = RpcQueryStats::new( - Some(method.to_string()), - authorization.clone(), - request_metadata, - response.num_bytes(), - ); - - stat_sender - .send_async(response_stat.into()) - .await - .map_err(Web3ProxyError::SendAppStatError)?; - } - - return Ok((response, rpcs)); + .await? } None => { // TODO: stats! + // TODO: not synced error? return Err(anyhow::anyhow!("no bundler_4337_rpcs available").into()); } }, - // some commands can use local data or caches "eth_accounts" => { - // no stats on this. its cheap - serde_json::Value::Array(vec![]) + JsonRpcForwardedResponse::from_value(serde_json::Value::Array(vec![]), request_id) } "eth_blockNumber" => { match head_block_num.or(self.balanced_rpcs.head_block_num()) { Some(head_block_num) => { - json!(head_block_num) + JsonRpcForwardedResponse::from_value(json!(head_block_num), request_id) } None => { // TODO: what does geth do if this happens? - return Err(Web3ProxyError::UnknownBlockNumber); + // TODO: standard not synced error + return Err(Web3ProxyError::NoServersSynced); } } } - "eth_chainId" => json!(U64::from(self.config.chain_id)), + "eth_chainId" => JsonRpcForwardedResponse::from_value( + json!(U64::from(self.config.chain_id)), + request_id, + ), // TODO: eth_callBundle (https://docs.flashbots.net/flashbots-auction/searchers/advanced/rpc-endpoint#eth_callbundle) // TODO: eth_cancelPrivateTransaction (https://docs.flashbots.net/flashbots-auction/searchers/advanced/rpc-endpoint#eth_cancelprivatetransaction, but maybe just reject) // TODO: eth_sendPrivateTransaction (https://docs.flashbots.net/flashbots-auction/searchers/advanced/rpc-endpoint#eth_sendprivatetransaction) "eth_coinbase" => { // no need for serving coinbase - // no stats on this. its cheap - json!(Address::zero()) + JsonRpcForwardedResponse::from_value(json!(Address::zero()), request_id) } "eth_estimateGas" => { let mut response = self @@ -1501,22 +1562,17 @@ impl Web3ProxyApp { gas_estimate += gas_increase; - json!(gas_estimate) + JsonRpcForwardedResponse::from_value(json!(gas_estimate), request_id) } // TODO: eth_gasPrice that does awesome magic to predict the future - "eth_hashrate" => { - // no stats on this. its cheap - json!(U64::zero()) - } + "eth_hashrate" => JsonRpcForwardedResponse::from_value(json!(U64::zero()), request_id), "eth_mining" => { - // no stats on this. its cheap - serde_json::Value::Bool(false) + JsonRpcForwardedResponse::from_value(serde_json::Value::Bool(false), request_id) } - // TODO: eth_sendBundle (flashbots command) + // TODO: eth_sendBundle (flashbots/eden command) // broadcast transactions to all private rpcs at once "eth_sendRawTransaction" => { - // TODO: how should we handle private_mode here? - let default_num = match authorization.checks.proxy_mode { + let num_public_rpcs = match authorization.checks.proxy_mode { // TODO: how many balanced rpcs should we send to? configurable? percentage of total? ProxyMode::Best | ProxyMode::Debug => Some(4), ProxyMode::Fastest(0) => None, @@ -1527,47 +1583,26 @@ impl Web3ProxyApp { ProxyMode::Versus => None, }; - let (private_rpcs, num) = if let Some(private_rpcs) = self.private_rpcs.as_ref() { - if !private_rpcs.is_empty() && authorization.checks.private_txs { - // if we are sending the transaction privately, no matter the proxy_mode, we send to ALL private rpcs - (private_rpcs, None) - } else { - // TODO: send to balanced_rpcs AND private_rpcs - (&self.balanced_rpcs, default_num) - } - } else { - (&self.balanced_rpcs, default_num) - }; - - let head_block_num = head_block_num - .or(self.balanced_rpcs.head_block_num()) - .ok_or_else(|| Web3ProxyError::NoServersSynced)?; - - // TODO: error/wait if no head block! - - // try_send_all_upstream_servers puts the request id into the response. no need to do that ourselves here. - // TODO: what lag should we allow? - let mut response = private_rpcs - .try_send_all_synced_connections( + let mut response = self + .try_send_protected( authorization, &request, - Some(request_metadata.clone()), - Some(&head_block_num.saturating_sub(2.into())), - None, - Level::Trace, - num, - true, + request_metadata.clone(), + num_public_rpcs, + head_block_num, ) .await?; // sometimes we get an error that the transaction is already known by our nodes, - // that's not really an error. Just return the hash like a successful response would. + // that's not really an error. Return the hash like a successful response would. + // TODO: move this to a helper function if let Some(response_error) = response.error.as_ref() { if response_error.code == -32000 && (response_error.message == "ALREADY_EXISTS: already known" || response_error.message == "INTERNAL_ERROR: existing tx with same hash") { + // TODO: expect instead of web3_context? let params = request .params .web3_context("there must be params if we got this far")?; @@ -1598,9 +1633,7 @@ impl Web3ProxyApp { } } - let rpcs = request_metadata.backend_requests.lock().clone(); - - // emit stats + // emit transaction count stats if let Some(salt) = self.config.public_recent_ips_salt.as_ref() { if let Some(tx_hash) = response.result.clone() { let now = Utc::now().timestamp(); @@ -1638,47 +1671,35 @@ impl Web3ProxyApp { } } - return Ok((response, rpcs)); + response } "eth_syncing" => { // no stats on this. its cheap // TODO: return a real response if all backends are syncing or if no servers in sync - serde_json::Value::Bool(false) - } - "eth_subscribe" => { - return Ok(( - JsonRpcForwardedResponse::from_str( - "notifications not supported. eth_subscribe is only available over a websocket", - Some(-32601), - Some(request_id), - ), - vec![], - )); - } - "eth_unsubscribe" => { - return Ok(( - JsonRpcForwardedResponse::from_str( - "notifications not supported. eth_unsubscribe is only available over a websocket", - Some(-32601), - Some(request_id), - ), - vec![], - )); + JsonRpcForwardedResponse::from_value(serde_json::Value::Bool(false), request_id) } + "eth_subscribe" => JsonRpcForwardedResponse::from_str( + "notifications not supported. eth_subscribe is only available over a websocket", + Some(-32601), + Some(request_id), + ), + "eth_unsubscribe" => JsonRpcForwardedResponse::from_str( + "notifications not supported. eth_unsubscribe is only available over a websocket", + Some(-32601), + Some(request_id), + ), "net_listening" => { - // no stats on this. its cheap // TODO: only if there are some backends on balanced_rpcs? - serde_json::Value::Bool(true) - } - "net_peerCount" => { - // no stats on this. its cheap - // TODO: do something with proxy_mode here? - json!(U64::from(self.balanced_rpcs.num_synced_rpcs())) - } - "web3_clientVersion" => { - // no stats on this. its cheap - serde_json::Value::String(APP_USER_AGENT.to_string()) + JsonRpcForwardedResponse::from_value(serde_json::Value::Bool(true), request_id) } + "net_peerCount" => JsonRpcForwardedResponse::from_value( + json!(U64::from(self.balanced_rpcs.num_synced_rpcs())), + request_id, + ), + "web3_clientVersion" => JsonRpcForwardedResponse::from_value( + serde_json::Value::String(APP_USER_AGENT.to_string()), + request_id, + ), "web3_sha3" => { // returns Keccak-256 (not the standardized SHA3-256) of the given data. match &request.params { @@ -1713,32 +1734,23 @@ impl Web3ProxyApp { let hash = H256::from(keccak256(param)); - json!(hash) + JsonRpcForwardedResponse::from_value(json!(hash), request_id) } _ => { // TODO: this needs the correct error code in the response - // TODO: emit stat? - return Ok(( - JsonRpcForwardedResponse::from_str( - "invalid request", - Some(StatusCode::BAD_REQUEST.as_u16().into()), - Some(request_id), - ), - vec![], - )); + JsonRpcForwardedResponse::from_str( + "invalid request", + Some(StatusCode::BAD_REQUEST.as_u16().into()), + Some(request_id), + ) } } } - "test" => { - return Ok(( - JsonRpcForwardedResponse::from_str( - "The method test does not exist/is not available.", - Some(-32601), - Some(request_id), - ), - vec![], - )); - } + "test" => JsonRpcForwardedResponse::from_str( + "The method test does not exist/is not available.", + Some(-32601), + Some(request_id), + ), // anything else gets sent to backend rpcs and cached method => { if method.starts_with("admin_") { @@ -1893,32 +1905,14 @@ impl Web3ProxyApp { // replace the id with our request's id. response.id = request_id; - // TODO: DRY! - let rpcs = request_metadata.backend_requests.lock().clone(); - - if let Some(stat_sender) = self.stat_sender.as_ref() { - let response_stat = RpcQueryStats::new( - Some(method.to_string()), - authorization.clone(), - request_metadata, - response.num_bytes(), - ); - - stat_sender - .send_async(response_stat.into()) - .await - .map_err(Web3ProxyError::SendAppStatError)?; - } - - return Ok((response, rpcs)); + response } }; - let response = JsonRpcForwardedResponse::from_value(partial_response, request_id); - - // TODO: DRY + // save the rpcs so they can be included in a response header let rpcs = request_metadata.backend_requests.lock().clone(); + // send stats used for accounting and graphs if let Some(stat_sender) = self.stat_sender.as_ref() { let response_stat = RpcQueryStats::new( Some(request_method), @@ -1933,6 +1927,7 @@ impl Web3ProxyApp { .map_err(Web3ProxyError::SendAppStatError)?; } + // send debug info as a kafka log if let Some((kafka_topic, kafka_key, kafka_headers)) = kafka_stuff { let kafka_producer = self .kafka_producer diff --git a/web3_proxy/src/bin/wait_for_sync.rs b/web3_proxy/src/bin/wait_for_sync.rs index c13d5fe5..a44a377c 100644 --- a/web3_proxy/src/bin/wait_for_sync.rs +++ b/web3_proxy/src/bin/wait_for_sync.rs @@ -131,10 +131,12 @@ struct JsonRpcChainIdResult { } async fn get_chain_id(rpc: &str, client: &reqwest::Client) -> anyhow::Result { + // empty params aren't required by the spec, but some rpc providers require them let get_chain_id_request = json!({ "id": "1", "jsonrpc": "2.0", "method": "eth_chainId", + "params": [], }); // TODO: loop until chain id is found? diff --git a/web3_proxy/src/block_number.rs b/web3_proxy/src/block_number.rs index a32392e1..729e36e0 100644 --- a/web3_proxy/src/block_number.rs +++ b/web3_proxy/src/block_number.rs @@ -177,12 +177,13 @@ pub async fn block_needed( "eth_getLogs" => { // TODO: think about this more // TODO: jsonrpc has a specific code for this - // TODO: this shouldn't be a 500. this should be a 400. 500 will make haproxy retry a bunch let obj = params .get_mut(0) - .ok_or_else(|| anyhow::anyhow!("invalid format. no params"))? + .ok_or_else(|| Web3ProxyError::BadRequest("invalid format. no params".to_string()))? .as_object_mut() - .ok_or_else(|| Web3ProxyError::BadRequest("invalid format".to_string()))?; + .ok_or_else(|| { + Web3ProxyError::BadRequest("invalid format. params not object".to_string()) + })?; if obj.contains_key("blockHash") { return Ok(BlockNeeded::CacheSuccessForever); diff --git a/web3_proxy/src/rpcs/many.rs b/web3_proxy/src/rpcs/many.rs index dbead8a8..7a48cdf0 100644 --- a/web3_proxy/src/rpcs/many.rs +++ b/web3_proxy/src/rpcs/many.rs @@ -157,19 +157,21 @@ impl Web3Rpcs { // these blocks don't have full transactions, but they do have rather variable amounts of transaction hashes // TODO: how can we do the weigher better? need to know actual allocated size + // TODO: time_to_idle instead? // TODO: limits from config let blocks_by_hash: BlocksByHashCache = Cache::builder() .max_capacity(1024 * 1024 * 1024) .weigher(|_k, v: &Web3ProxyBlock| { 1 + v.block.transactions.len().try_into().unwrap_or(u32::MAX) }) - .time_to_idle(Duration::from_secs(600)) + .time_to_live(Duration::from_secs(30 * 60)) .build_with_hasher(hashbrown::hash_map::DefaultHashBuilder::default()); // all block numbers are the same size, so no need for weigher // TODO: limits from config + // TODO: time_to_idle instead? let blocks_by_number = Cache::builder() - .time_to_idle(Duration::from_secs(600)) + .time_to_live(Duration::from_secs(30 * 60)) .max_capacity(10_000) .build_with_hasher(hashbrown::hash_map::DefaultHashBuilder::default()); @@ -1099,7 +1101,7 @@ impl Web3Rpcs { /// be sure there is a timeout on this or it might loop forever #[allow(clippy::too_many_arguments)] pub async fn try_send_all_synced_connections( - &self, + self: &Arc, authorization: &Arc, request: &JsonRpcRequest, request_metadata: Option>, diff --git a/web3_proxy/src/rpcs/one.rs b/web3_proxy/src/rpcs/one.rs index 1b7246e2..09a4af4a 100644 --- a/web3_proxy/src/rpcs/one.rs +++ b/web3_proxy/src/rpcs/one.rs @@ -560,12 +560,12 @@ impl Web3Rpc { .context(format!("waiting for request handle on {}", self))? .request( "eth_chainId", - &json!(Option::None::<()>), + &json!(Vec::<()>::new()), Level::Trace.into(), unlocked_provider.clone(), ) .await; - // trace!("found_chain_id: {:?}", found_chain_id); + trace!("found_chain_id: {:#?}", found_chain_id); match found_chain_id { Ok(found_chain_id) => { diff --git a/web3_proxy/src/rpcs/request.rs b/web3_proxy/src/rpcs/request.rs index 4c6b2dbf..ffcfbcee 100644 --- a/web3_proxy/src/rpcs/request.rs +++ b/web3_proxy/src/rpcs/request.rs @@ -219,13 +219,10 @@ impl OpenRequestHandle { .fetch_sub(1, std::sync::atomic::Ordering::Relaxed); // // TODO: i think ethers already has trace logging (and does it much more fancy) - // trace!( - // "response from {} for {} {:?}: {:?}", - // self.rpc, - // method, - // params, - // response, - // ); + debug!( + "response from {} for {} {:?}: {:?}", + self.rpc, method, params, response, + ); if let Err(err) = &response { // only save reverts for some types of calls From 1fab1b1d46e1e66616b6cf5738dc69cd59579147 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 24 Apr 2023 11:21:53 -0700 Subject: [PATCH 06/18] oops. lower this log level --- web3_proxy/src/rpcs/request.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web3_proxy/src/rpcs/request.rs b/web3_proxy/src/rpcs/request.rs index ffcfbcee..bbad1ab9 100644 --- a/web3_proxy/src/rpcs/request.rs +++ b/web3_proxy/src/rpcs/request.rs @@ -218,8 +218,8 @@ impl OpenRequestHandle { .active_requests .fetch_sub(1, std::sync::atomic::Ordering::Relaxed); - // // TODO: i think ethers already has trace logging (and does it much more fancy) - debug!( + // TODO: i think ethers already has trace logging (and does it much more fancy) + trace!( "response from {} for {} {:?}: {:?}", self.rpc, method, params, response, ); From 2ad509a5fc85de6c5e097e2bf4118e03d72e9f45 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 24 Apr 2023 23:23:33 -0700 Subject: [PATCH 07/18] rust 1.69.0 --- Dockerfile | 2 +- rust-toolchain.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8e904724..d9717123 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.68.2-bullseye AS builder +FROM rust:1.69.0-bullseye AS builder WORKDIR /app ENV CARGO_TERM_COLOR always diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 864d3c41..f2415f83 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.68.2" +channel = "1.69.0" From cc3c9462a378288c8ef1d0739bc98f08d5f55995 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Tue, 25 Apr 2023 05:39:09 -0700 Subject: [PATCH 08/18] cargo upgrade --- Cargo.lock | 14 +++++++------- web3_proxy/Cargo.toml | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e1f6cfa2..f03c9941 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3511,9 +3511,9 @@ dependencies = [ [[package]] name = "openssl" -version = "0.10.45" +version = "0.10.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1" +checksum = "01b8574602df80f7b85fdfc5392fa884a4e3b3f4f35402c070ab34c3d3f78d56" dependencies = [ "bitflags", "cfg-if", @@ -3526,13 +3526,13 @@ dependencies = [ [[package]] name = "openssl-macros" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.15", ] [[package]] @@ -3543,9 +3543,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.85" +version = "0.9.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d3d193fb1488ad46ffe3aaabc912cc931d02ee8518fe2959aea8ef52718b0c0" +checksum = "8e17f59264b2809d77ae94f0e1ebabc434773f370d6ca667bd223ea10e06cc7e" dependencies = [ "cc", "libc", diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index 7db6e8f4..9831da50 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -48,9 +48,9 @@ handlebars = "4.3.6" hashbrown = { version = "0.13.2", features = ["serde"] } hdrhistogram = "7.5.2" http = "0.2.9" +hostname = "0.3.1" influxdb2 = { version = "0.4", features = ["rustls"] } influxdb2-structmap = "0.2.0" -hostname = "0.3.1" ipnet = "2.7.2" itertools = "0.10.5" log = "0.4.17" From a236f7364d2e1ee568c4247671eb67232b7d780c Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Tue, 25 Apr 2023 07:42:00 -0700 Subject: [PATCH 09/18] DRY stats (#58) * DRY functions for saving stats and batch tsdb stats * move comments --- web3_proxy/src/stats/mod.rs | 231 +++++++++++++++++++----------------- 1 file changed, 124 insertions(+), 107 deletions(-) diff --git a/web3_proxy/src/stats/mod.rs b/web3_proxy/src/stats/mod.rs index 6b960219..c391ee9f 100644 --- a/web3_proxy/src/stats/mod.rs +++ b/web3_proxy/src/stats/mod.rs @@ -14,7 +14,7 @@ use futures::stream; use hashbrown::HashMap; use influxdb2::api::write::TimestampPrecision; use influxdb2::models::DataPoint; -use log::{error, info}; +use log::{error, info, trace}; use migration::sea_orm::{self, DatabaseConnection, EntityTrait}; use migration::{Expr, OnConflict}; use std::num::NonZeroU64; @@ -114,9 +114,10 @@ impl RpcQueryStats { } } - /// all queries are aggregated + /// all rpc keys are aggregated in the global stats /// TODO: should we store "anon" or "registered" as a key just to be able to split graphs? fn global_timeseries_key(&self) -> RpcQueryKey { + // we include the method because that can be helpful for predicting load let method = self.method.clone(); // we don't store origin in the timeseries db. its only used for optional accounting let origin = None; @@ -133,15 +134,15 @@ impl RpcQueryStats { } } - fn opt_in_timeseries_key(&self) -> RpcQueryKey { + /// rpc keys can opt into more detailed tracking + fn opt_in_timeseries_key(&self) -> Option { // we don't store origin in the timeseries db. its only optionaly used for accounting let origin = None; let (method, rpc_secret_key_id) = match self.authorization.checks.tracking_level { TrackingLevel::None => { // this RPC key requested no tracking. this is the default. - // we still want graphs though, so we just use None as the rpc_secret_key_id - (self.method.clone(), None) + return None; } TrackingLevel::Aggregated => { // this RPC key requested tracking aggregated across all methods @@ -156,14 +157,16 @@ impl RpcQueryStats { } }; - RpcQueryKey { + let key = RpcQueryKey { response_timestamp: self.response_timestamp, archive_needed: self.archive_request, error_response: self.error_response, method, rpc_secret_key_id, origin, - } + }; + + Some(key) } } @@ -201,6 +204,10 @@ pub struct StatBuffer { tsdb_save_interval_seconds: u32, db_save_interval_seconds: u32, billing_period_seconds: i64, + global_timeseries_buffer: HashMap, + opt_in_timeseries_buffer: HashMap, + accounting_db_buffer: HashMap, + timestamp_precision: TimestampPrecision, } impl BufferedRpcQueryStats { @@ -310,18 +317,12 @@ impl BufferedRpcQueryStats { Ok(()) } - // TODO: change this to return a DataPoint? - async fn save_timeseries( + async fn build_timeseries_point( self, - bucket: &str, measurement: &str, chain_id: u64, - influxdb2_clent: &influxdb2::Client, key: RpcQueryKey, - ) -> anyhow::Result<()> { - // TODO: error if key.origin is set? - - // TODO: what name? + ) -> anyhow::Result { let mut builder = DataPoint::builder(measurement); builder = builder.tag("chain_id", chain_id.to_string()); @@ -347,16 +348,10 @@ impl BufferedRpcQueryStats { .field("sum_response_bytes", self.sum_response_bytes as i64); builder = builder.timestamp(key.response_timestamp); - let timestamp_precision = TimestampPrecision::Seconds; - let points = [builder.build()?]; + let point = builder.build()?; - // TODO: bucket should be an enum so that we don't risk typos - influxdb2_clent - .write_with_precision(bucket, stream::iter(points), timestamp_precision) - .await?; - - Ok(()) + Ok(point) } } @@ -423,6 +418,7 @@ impl StatBuffer { let (stat_sender, stat_receiver) = flume::unbounded(); + let timestamp_precision = TimestampPrecision::Seconds; let mut new = Self { chain_id, db_conn, @@ -430,6 +426,10 @@ impl StatBuffer { db_save_interval_seconds, tsdb_save_interval_seconds, billing_period_seconds, + global_timeseries_buffer: Default::default(), + opt_in_timeseries_buffer: Default::default(), + accounting_db_buffer: Default::default(), + timestamp_precision, }; // any errors inside this task will cause the application to exit @@ -452,11 +452,6 @@ impl StatBuffer { let mut db_save_interval = interval(Duration::from_secs(self.db_save_interval_seconds as u64)); - // TODO: this is used for rpc_accounting_v2 and influxdb. give it a name to match that? "stat" of some kind? - let mut global_timeseries_buffer = HashMap::::new(); - let mut opt_in_timeseries_buffer = HashMap::::new(); - let mut accounting_db_buffer = HashMap::::new(); - // TODO: Somewhere here we should probably be updating the balance of the user // And also update the credits used etc. for the referred user @@ -472,15 +467,15 @@ impl StatBuffer { let global_timeseries_key = stat.global_timeseries_key(); - global_timeseries_buffer.entry(global_timeseries_key).or_default().add(stat.clone()); + self.global_timeseries_buffer.entry(global_timeseries_key).or_default().add(stat.clone()); - let opt_in_timeseries_key = stat.opt_in_timeseries_key(); - - opt_in_timeseries_buffer.entry(opt_in_timeseries_key).or_default().add(stat.clone()); + if let Some(opt_in_timeseries_key) = stat.opt_in_timeseries_key() { + self.opt_in_timeseries_buffer.entry(opt_in_timeseries_key).or_default().add(stat.clone()); + } } if self.db_conn.is_some() { - accounting_db_buffer.entry(stat.accounting_key(self.billing_period_seconds)).or_default().add(stat); + self.accounting_db_buffer.entry(stat.accounting_key(self.billing_period_seconds)).or_default().add(stat); } } Err(err) => { @@ -491,34 +486,16 @@ impl StatBuffer { } _ = db_save_interval.tick() => { // info!("DB save internal tick"); - let db_conn = self.db_conn.as_ref().expect("db connection should always exist if there are buffered stats"); - - // TODO: batch saves - for (key, stat) in accounting_db_buffer.drain() { - // TODO: i don't like passing key (which came from the stat) to the function on the stat. but it works for now - if let Err(err) = stat.save_db(self.chain_id, db_conn, key).await { - error!("unable to save accounting entry! err={:?}", err); - }; + let count = self.save_relational_stats().await; + if count > 0 { + trace!("Saved {} stats to the relational db", count); } } _ = tsdb_save_interval.tick() => { // info!("TSDB save internal tick"); - // TODO: batch saves - // TODO: better bucket names - let influxdb_client = self.influxdb_client.as_ref().expect("influxdb client should always exist if there are buffered stats"); - - for (key, stat) in global_timeseries_buffer.drain() { - // TODO: i don't like passing key (which came from the stat) to the function on the stat. but it works for now - if let Err(err) = stat.save_timeseries(bucket.clone().as_ref(), "global_proxy", self.chain_id, influxdb_client, key).await { - error!("unable to save global stat! err={:?}", err); - }; - } - - for (key, stat) in opt_in_timeseries_buffer.drain() { - // TODO: i don't like passing key (which came from the stat) to the function on the stat. but it works for now - if let Err(err) = stat.save_timeseries(bucket.clone().as_ref(), "opt_in_proxy", self.chain_id, influxdb_client, key).await { - error!("unable to save opt-in stat! err={:?}", err); - }; + let count = self.save_tsdb_stats(&bucket).await; + if count > 0 { + trace!("Saved {} stats to the tsdb", count); } } x = shutdown_receiver.recv() => { @@ -534,62 +511,102 @@ impl StatBuffer { } } - // TODO: dry - if let Some(db_conn) = self.db_conn.as_ref() { - info!( - "saving {} buffered accounting entries", - accounting_db_buffer.len(), - ); + let saved_relational = self.save_relational_stats().await; - for (key, stat) in accounting_db_buffer.drain() { - if let Err(err) = stat.save_db(self.chain_id, db_conn, key).await { - error!( - "Unable to save accounting entry while shutting down! err={:?}", - err - ); - }; - } - } + info!("saved {} pending relational stats", saved_relational); - // TODO: dry - if let Some(influxdb_client) = self.influxdb_client.as_ref() { - info!( - "saving {} buffered global stats", - global_timeseries_buffer.len(), - ); + let saved_tsdb = self.save_tsdb_stats(&bucket).await; - for (key, stat) in global_timeseries_buffer.drain() { - if let Err(err) = stat - .save_timeseries(&bucket, "global_proxy", self.chain_id, influxdb_client, key) - .await - { - error!( - "Unable to save global stat while shutting down! err={:?}", - err - ); - }; - } - - info!( - "saving {} buffered opt-in stats", - opt_in_timeseries_buffer.len(), - ); - - for (key, stat) in opt_in_timeseries_buffer.drain() { - if let Err(err) = stat - .save_timeseries(&bucket, "opt_in_proxy", self.chain_id, influxdb_client, key) - .await - { - error!( - "unable to save opt-in stat while shutting down! err={:?}", - err - ); - }; - } - } + info!("saved {} pending tsdb stats", saved_tsdb); info!("accounting and stat save loop complete"); Ok(()) } + + async fn save_relational_stats(&mut self) -> usize { + let mut count = 0; + + if let Some(db_conn) = self.db_conn.as_ref() { + count = self.accounting_db_buffer.len(); + for (key, stat) in self.accounting_db_buffer.drain() { + // TODO: batch saves + // TODO: i don't like passing key (which came from the stat) to the function on the stat. but it works for now + if let Err(err) = stat.save_db(self.chain_id, db_conn, key).await { + error!("unable to save accounting entry! err={:?}", err); + }; + } + } + + count + } + + // TODO: bucket should be an enum so that we don't risk typos + async fn save_tsdb_stats(&mut self, bucket: &str) -> usize { + let mut count = 0; + + if let Some(influxdb_client) = self.influxdb_client.as_ref() { + // TODO: use stream::iter properly to avoid allocating this Vec + let mut points = vec![]; + + for (key, stat) in self.global_timeseries_buffer.drain() { + // TODO: i don't like passing key (which came from the stat) to the function on the stat. but it works for now + match stat + .build_timeseries_point("global_proxy", self.chain_id, key) + .await + { + Ok(point) => { + points.push(point); + } + Err(err) => { + error!("unable to build global stat! err={:?}", err); + } + }; + } + + for (key, stat) in self.opt_in_timeseries_buffer.drain() { + // TODO: i don't like passing key (which came from the stat) to the function on the stat. but it works for now + match stat + .build_timeseries_point("opt_in_proxy", self.chain_id, key) + .await + { + Ok(point) => { + points.push(point); + } + Err(err) => { + // TODO: if this errors, we throw away some of the pending stats! we should probably buffer them somewhere to be tried again + error!("unable to build opt-in stat! err={:?}", err); + } + }; + } + + count = points.len(); + + if count > 0 { + // TODO: put max_batch_size in config? + // TODO: i think the real limit is the byte size of the http request. so, a simple line count won't work very well + let max_batch_size = 100; + + let mut num_left = count; + + while num_left > 0 { + let batch_size = num_left.min(max_batch_size); + + let p = points.split_off(batch_size); + + num_left -= batch_size; + + if let Err(err) = influxdb_client + .write_with_precision(bucket, stream::iter(p), self.timestamp_precision) + .await + { + // TODO: if this errors, we throw away some of the pending stats! we should probably buffer them somewhere to be tried again + error!("unable to save {} tsdb stats! err={:?}", batch_size, err); + } + } + } + } + + count + } } From 93f243696a9f86c7fbe9b37a7078181d071a9d68 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 27 Apr 2023 11:15:45 -0700 Subject: [PATCH 10/18] simple match statement --- web3_proxy/src/stats/mod.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/web3_proxy/src/stats/mod.rs b/web3_proxy/src/stats/mod.rs index c391ee9f..0b9a7411 100644 --- a/web3_proxy/src/stats/mod.rs +++ b/web3_proxy/src/stats/mod.rs @@ -139,21 +139,19 @@ impl RpcQueryStats { // we don't store origin in the timeseries db. its only optionaly used for accounting let origin = None; - let (method, rpc_secret_key_id) = match self.authorization.checks.tracking_level { + // depending on tracking level, we either skip opt-in stats, track without method, or track with method + let method = match self.authorization.checks.tracking_level { TrackingLevel::None => { // this RPC key requested no tracking. this is the default. return None; } TrackingLevel::Aggregated => { // this RPC key requested tracking aggregated across all methods - (None, self.authorization.checks.rpc_secret_key_id) + None } TrackingLevel::Detailed => { // detailed tracking keeps track of the method - ( - self.method.clone(), - self.authorization.checks.rpc_secret_key_id, - ) + self.method.clone() } }; @@ -162,7 +160,7 @@ impl RpcQueryStats { archive_needed: self.archive_request, error_response: self.error_response, method, - rpc_secret_key_id, + rpc_secret_key_id: self.authorization.checks.rpc_secret_key_id, origin, }; From 91acbcaf751cf4f5d8f16d7852ee98ffc78c4088 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sat, 29 Apr 2023 18:38:31 -0700 Subject: [PATCH 11/18] Fix sort order --- web3_proxy/src/rpcs/many.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/web3_proxy/src/rpcs/many.rs b/web3_proxy/src/rpcs/many.rs index 7a48cdf0..dca48282 100644 --- a/web3_proxy/src/rpcs/many.rs +++ b/web3_proxy/src/rpcs/many.rs @@ -511,12 +511,13 @@ impl Web3Rpcs { min_block_needed: Option<&U64>, max_block_needed: Option<&U64>, ) -> Web3ProxyResult { - let usable_rpcs_by_tier_and_head_number: BTreeMap<(u64, Option), Vec>> = { + let usable_rpcs_by_tier_and_head_number: BTreeMap<(u64, Reverse>), Vec>> = { + let mut m = BTreeMap::new(); + if self.watch_consensus_head_sender.is_none() { // pick any server - let mut m = BTreeMap::new(); - let key = (0, None); + let key = (0, Reverse); for x in self.by_name.read().values() { if skip.contains(x) { @@ -527,8 +528,6 @@ impl Web3Rpcs { m.entry(key).or_insert_with(Vec::new).push(x.clone()); } - - m } else { let synced_connections = self.watch_consensus_rpcs_sender.borrow().clone(); @@ -569,9 +568,6 @@ impl Web3Rpcs { trace!("needed_blocks_comparison: {:?}", needed_blocks_comparison); // collect "usable_rpcs_by_head_num_and_weight" - // TODO: MAKE SURE None SORTS LAST? - let mut m = BTreeMap::new(); - match needed_blocks_comparison { cmp::Ordering::Less => { // need an old block. check all the rpcs. ignore rpcs that are still syncing @@ -634,7 +630,7 @@ impl Web3Rpcs { } } - let key = (x.tier, Some(*x_head_num)); + let key = (x.tier, Reverse); m.entry(key).or_insert_with(Vec::new).push(x); } @@ -647,7 +643,7 @@ impl Web3Rpcs { // the key doesn't matter if we are checking synced connections // they are all at the same block and it is already sized to what we need - let key = (0, None); + let key = (0, Reverse); for x in synced_connections.best_rpcs.iter() { if skip.contains(x) { @@ -664,9 +660,9 @@ impl Web3Rpcs { return Ok(OpenRequestResult::NotReady); } } - - m } + + m }; trace!( From ffb554d0b3c7cadeec8351b083ebdf70af7fc7f8 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sat, 29 Apr 2023 18:50:26 -0700 Subject: [PATCH 12/18] online editor isn't actually nice when it misses syntax errors :( --- web3_proxy/src/rpcs/many.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/web3_proxy/src/rpcs/many.rs b/web3_proxy/src/rpcs/many.rs index dca48282..6e6d121b 100644 --- a/web3_proxy/src/rpcs/many.rs +++ b/web3_proxy/src/rpcs/many.rs @@ -511,13 +511,16 @@ impl Web3Rpcs { min_block_needed: Option<&U64>, max_block_needed: Option<&U64>, ) -> Web3ProxyResult { - let usable_rpcs_by_tier_and_head_number: BTreeMap<(u64, Reverse>), Vec>> = { + let usable_rpcs_by_tier_and_head_number: BTreeMap< + (u64, Reverse>), + Vec>, + > = { let mut m = BTreeMap::new(); if self.watch_consensus_head_sender.is_none() { // pick any server - let key = (0, Reverse); + let key = (0, Reverse(None)); for x in self.by_name.read().values() { if skip.contains(x) { @@ -630,7 +633,7 @@ impl Web3Rpcs { } } - let key = (x.tier, Reverse); + let key = (x.tier, Reverse(Some(*x_head_num))); m.entry(key).or_insert_with(Vec::new).push(x); } @@ -643,7 +646,7 @@ impl Web3Rpcs { // the key doesn't matter if we are checking synced connections // they are all at the same block and it is already sized to what we need - let key = (0, Reverse); + let key = (0, Reverse(None)); for x in synced_connections.best_rpcs.iter() { if skip.contains(x) { From aff53ce36a579e7271b6a137540a106f48add158 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sat, 6 May 2023 14:17:08 -0600 Subject: [PATCH 13/18] automatic retry for eth_getTransactionReceipt and eth_getTransactionByHash thanks for the report Lefteris @ Rotki --- web3_proxy/src/app/mod.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 0f4b30fa..e2e1e0df 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -1564,6 +1564,37 @@ impl Web3ProxyApp { JsonRpcForwardedResponse::from_value(json!(gas_estimate), request_id) } + "eth_getTransactionReceipt" | "eth_getTransactionByHash" => { + // try to get the transaction without specifying a min_block_height + let mut response = self + .balanced_rpcs + .try_proxy_connection( + authorization, + request, + Some(&request_metadata), + None, + None, + ) + .await?; + + // if we got "null", it is probably because the tx is old. retry requiring nodes with old block data + if let Some(ref result) = response.result { + if result.get() == "null" { + response = self + .balanced_rpcs + .try_proxy_connection( + authorization, + request, + Some(&request_metadata), + Some(&U64::one()), + None, + ) + .await?; + } + } + + response + } // TODO: eth_gasPrice that does awesome magic to predict the future "eth_hashrate" => JsonRpcForwardedResponse::from_value(json!(U64::zero()), request_id), "eth_mining" => { From 8916533a2ae8daabd07f848875ed29b9b63cc24e Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sat, 6 May 2023 21:03:03 -0600 Subject: [PATCH 14/18] set archive_request to true on transaction retrying --- web3_proxy/src/app/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index e2e1e0df..048dbda1 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -1577,9 +1577,13 @@ impl Web3ProxyApp { ) .await?; - // if we got "null", it is probably because the tx is old. retry requiring nodes with old block data + // if we got "null", it is probably because the tx is old. retry on nodes with old block data if let Some(ref result) = response.result { if result.get() == "null" { + request_metadata + .archive_request + .store(true, atomic::Ordering::Release); + response = self .balanced_rpcs .try_proxy_connection( From c2e3d710809a3cccd3f937606a9d8e5957365b76 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 5 May 2023 14:02:31 -0600 Subject: [PATCH 15/18] if protected rpcs, only use protected rpcs --- web3_proxy/src/app/mod.rs | 44 +-------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 048dbda1..17ad6a21 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -1217,46 +1217,9 @@ impl Web3ProxyApp { request: &JsonRpcRequest, request_metadata: Arc, num_public_rpcs: Option, - head_block_num: Option, ) -> Web3ProxyResult { - // TODO: error/wait if no head block? - // TODO: configurable lag - let min_block_needed = head_block_num - .or(self.balanced_rpcs.head_block_num()) - .ok_or_else(|| Web3ProxyError::NoServersSynced)? - .saturating_sub(3.into()); - if let Some(protected_rpcs) = self.private_rpcs.as_ref() { if !protected_rpcs.is_empty() { - // send to protected and public rpcs at the same time - // TODO: send to tier 0 of private, wait a block, ..., tier N of private, wait a block, public - // TODO: allow premium users to choose specifically where they want transactions to go - let public_f = { - let authorization = authorization.clone(); - let clone = self.clone(); - // TODO: should request be in an arc? inside the request metadata? - let request = request.clone(); - let request_metadata = Some(request_metadata.clone()); - - async move { - clone - .balanced_rpcs - .try_send_all_synced_connections( - &authorization, - &request, - request_metadata, - Some(&min_block_needed), - None, - Level::Trace, - num_public_rpcs, - true, - ) - .await - } - }; - - let public_handle = tokio::spawn(public_f); - let protected_response = protected_rpcs .try_send_all_synced_connections( authorization, @@ -1270,10 +1233,6 @@ impl Web3ProxyApp { ) .await?; - // wait for sending to the public rpcs to finish - // TODO: let this run in the background instead? - public_handle.await??; - return Ok(protected_response); } } @@ -1285,7 +1244,7 @@ impl Web3ProxyApp { authorization, request, Some(request_metadata), - Some(&min_block_needed), + None, None, Level::Trace, num_public_rpcs, @@ -1624,7 +1583,6 @@ impl Web3ProxyApp { &request, request_metadata.clone(), num_public_rpcs, - head_block_num, ) .await?; From e7da6cd3d64028e0e3de16a8a1768596924b7efc Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 8 May 2023 10:42:03 -0600 Subject: [PATCH 16/18] clone for now. this will change to use refs soon --- web3_proxy/src/app/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 17ad6a21..03c7df72 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -1529,7 +1529,7 @@ impl Web3ProxyApp { .balanced_rpcs .try_proxy_connection( authorization, - request, + request.clone(), Some(&request_metadata), None, None, From 4d64bf95806a8553cc324bdaaa41fa77a4abfcf3 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 8 May 2023 10:44:01 -0600 Subject: [PATCH 17/18] cargo upgrade --- Cargo.lock | 352 ++++++++++++++----------------- deferred-rate-limiter/Cargo.toml | 6 +- entities/Cargo.toml | 6 +- migration/Cargo.toml | 2 +- rate-counter/Cargo.toml | 2 +- redis-rate-limiter/Cargo.toml | 4 +- web3_proxy/Cargo.toml | 22 +- 7 files changed, 180 insertions(+), 214 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f03c9941..845d66c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,7 +46,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "433cfd6710c9986c576a25ca913c39d66a6474107b406f34f91d4a8923395241" dependencies = [ "cfg-if", - "cipher 0.4.3", + "cipher 0.4.4", "cpufeatures", ] @@ -107,9 +107,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.70" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" +checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" dependencies = [ "backtrace", ] @@ -262,9 +262,9 @@ dependencies = [ [[package]] name = "auto_impl" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a8c1df849285fbacd587de7818cc7d13be6cd2cbcd47a04fb1801b0e2706e33" +checksum = "fee3da8ef1276b0bee5dd1c7258010d8fffd31801447323115a25560e1327b89" dependencies = [ "proc-macro-error", "proc-macro2", @@ -280,9 +280,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "axum" -version = "0.6.16" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "113713495a32dd0ab52baf5c10044725aa3aec00b31beda84218e469029b72a3" +checksum = "f8175979259124331c1d7bf6586ee7e0da434155e4b2d48ec2c8386281d8df39" dependencies = [ "async-trait", "axum-core", @@ -316,9 +316,9 @@ dependencies = [ [[package]] name = "axum-client-ip" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d719fabd6813392bbc10e1fe67f2977fad52791a836e51236f7e02f2482e017" +checksum = "df8e81eacc93f36480825da5f46a33b5fb2246ed024eacc9e8933425b80c5807" dependencies = [ "axum", "forwarded-header-value", @@ -631,9 +631,9 @@ dependencies = [ [[package]] name = "camino" -version = "1.1.2" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c77df041dc383319cc661b428b6961a005db4d6808d5e12536931b1ca9556055" +checksum = "c530edf18f37068ac2d977409ed5cd50d53d73bc653c7647b48eb78976ac9ae2" dependencies = [ "serde", ] @@ -722,9 +722,9 @@ dependencies = [ [[package]] name = "cipher" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1873270f8f7942c191139cb8a40fd228da6c3fd2fc376d7e92d47aa14aeb59e" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" dependencies = [ "crypto-common", "inout", @@ -1042,9 +1042,9 @@ checksum = "6548a0ad5d2549e111e1f6a11a6c2e2d00ce6a3dafe22948d67c2b443f775e52" [[package]] name = "crossbeam-channel" -version = "0.5.6" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" dependencies = [ "cfg-if", "crossbeam-utils", @@ -1052,9 +1052,9 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" dependencies = [ "cfg-if", "crossbeam-epoch", @@ -1063,9 +1063,9 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.13" +version = "0.9.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" +checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" dependencies = [ "autocfg", "cfg-if", @@ -1149,9 +1149,9 @@ dependencies = [ [[package]] name = "crypto-bigint" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c2538c4e68e52548bacb3e83ac549f903d44f011ac9d5abb5e132e67d0808f7" +checksum = "cf4c2f4e1afd912bc40bfd6fed5d9dc1f288e0ba01bfcc835cc5bc3eb13efe15" dependencies = [ "generic-array", "rand_core", @@ -1196,7 +1196,7 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" dependencies = [ - "cipher 0.4.3", + "cipher 0.4.4", ] [[package]] @@ -1294,7 +1294,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef552e6f588e446098f6ba40d89ac146c8c7b64aade83c051ee00bb5d2bc18d" dependencies = [ "serde", - "uuid 1.3.1", + "uuid 1.3.2", ] [[package]] @@ -1332,9 +1332,9 @@ dependencies = [ [[package]] name = "der" -version = "0.7.3" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82b10af9f9f9f2134a42d3f8aa74658660f2e0234b0eb81bd171df8aa32779ed" +checksum = "05e58dffcdcc8ee7b22f0c1f71a69243d7c2d9ad87b5a14361f2424a1565c219" dependencies = [ "const-oid 0.9.2", "zeroize", @@ -1453,9 +1453,9 @@ checksum = "03d8c417d7a8cb362e0c37e5d815f5eb7c37f79ff93707329d5a194e42e54ca0" [[package]] name = "dunce" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bd4b30a6560bbd9b4620f4de34c3f14f60848e58a9b7216801afcb4c7b31c3c" +checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" [[package]] name = "ecdsa" @@ -1475,7 +1475,7 @@ version = "0.16.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a48e5d537b8a30c0b023116d981b16334be1485af7ca68db3a2b7024cbc957fd" dependencies = [ - "der 0.7.3", + "der 0.7.5", "digest 0.10.6", "elliptic-curve 0.13.4", "rfc6979 0.4.0", @@ -1514,23 +1514,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75c71eaa367f2e5d556414a8eea812bc62985c879748d6403edabd9cb03f16e7" dependencies = [ "base16ct 0.2.0", - "crypto-bigint 0.5.1", + "crypto-bigint 0.5.2", "digest 0.10.6", "ff 0.13.0", "generic-array", "group 0.13.0", "pkcs8 0.10.2", "rand_core", - "sec1 0.7.1", + "sec1 0.7.2", "subtle", "zeroize", ] [[package]] name = "ena" -version = "0.14.0" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7402b94a93c24e742487327a7cd839dc9d36fec9de9fb25b09f2dae459f36c3" +checksum = "c533630cf40e9caa44bd91aadc88a75d75a4c3a12b4cfde353cbed41daa1e1f1" dependencies = [ "log", ] @@ -1558,9 +1558,9 @@ dependencies = [ [[package]] name = "enr" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb4d5fbf6f56acecd38f5988eb2e4ae412008a2a30268c748c701ec6322f39d4" +checksum = "cf56acd72bb22d2824e66ae8e9e5ada4d0de17a69c7fd35569dde2ada8ec9116" dependencies = [ "base64 0.13.1", "bytes", @@ -1582,7 +1582,7 @@ dependencies = [ "sea-orm", "serde", "ulid", - "uuid 1.3.1", + "uuid 1.3.2", ] [[package]] @@ -1711,9 +1711,9 @@ dependencies = [ [[package]] name = "ethers" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "356eaf2e3947efa975c3f953e33f73193e5e21b9d8bab26c3ca532676931696f" +checksum = "8d5486fdc149826f38c388f26a7df72534ee3f20d3a3f72539376fa7b3bbc43d" dependencies = [ "ethers-addressbook", "ethers-contract", @@ -1727,9 +1727,9 @@ dependencies = [ [[package]] name = "ethers-addressbook" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d56f1c92cb7c406794c8324158da4caf9e54018e28b776df8155085e1d06db75" +checksum = "1c66a426b824a0f6d1361ad74b6b01adfd26c44ee1e14c3662dcf28406763ec5" dependencies = [ "ethers-core", "once_cell", @@ -1739,9 +1739,9 @@ dependencies = [ [[package]] name = "ethers-contract" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a328cb42014ac0ac577a8dac32eb658ee0f32b5a9a5317a0329ac1d4201f1c6" +checksum = "dfa43e2e69632492d7b38e59465d125a0066cf4c477390ece00d3acbd11b338b" dependencies = [ "ethers-contract-abigen", "ethers-contract-derive", @@ -1758,9 +1758,9 @@ dependencies = [ [[package]] name = "ethers-contract-abigen" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96813e4b58b6c6b817367380db900dddbd67bfe27610ec89fd3263778d5a4aa" +checksum = "2edb8fdbf77459819a443234b461171a024476bfc12f1853b889a62c6e1185ff" dependencies = [ "Inflector", "dunce", @@ -1785,9 +1785,9 @@ dependencies = [ [[package]] name = "ethers-contract-derive" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "373068bb24b4dea8fe0d1758aadab2dd4ec9de1d2c28316439cadcda3ed48eae" +checksum = "939b0c37746929f869285ee37d270b7c998d80cc7404c2e20dda8efe93e3b295" dependencies = [ "Inflector", "ethers-contract-abigen", @@ -1801,9 +1801,9 @@ dependencies = [ [[package]] name = "ethers-core" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a5f8f85ba96698eab9a4782ed2215d0979b1981b99f1be0726c200ffdac22f5" +checksum = "198ea9efa8480fa69f73d31d41b1601dace13d053c6fe4be6f5878d9dfcf0108" dependencies = [ "arrayvec", "bytes", @@ -1832,9 +1832,9 @@ dependencies = [ [[package]] name = "ethers-etherscan" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cfc3d36be9e16bac241e1d59ec9ace00e8e4241c09f604a0f65158eb37d4878" +checksum = "196a21d6939ab78b7a1e4c45c2b33b0c2dd821a2e1af7c896f06721e1ba2a0c7" dependencies = [ "ethers-core", "ethers-solc", @@ -1849,9 +1849,9 @@ dependencies = [ [[package]] name = "ethers-middleware" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e6f3543b4f6679b2558901c4b323cecb06b19239439d2588fa8b489bac9675d" +checksum = "75594cc450992fc7de701c9145de612325fd8a18be765b8ae78767ba2b74876f" dependencies = [ "async-trait", "auto_impl", @@ -1876,9 +1876,9 @@ dependencies = [ [[package]] name = "ethers-providers" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c9d2cbed43cf618004dbe339e389e10dae46ea8e55872ab63a25fad25a6082a" +checksum = "1009041f40476b972b5d79346cc512e97c662b1a0a2f78285eabe9a122909783" dependencies = [ "async-trait", "auto_impl", @@ -1914,9 +1914,9 @@ dependencies = [ [[package]] name = "ethers-signers" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d56871f70b97cc5cced5c39c88a0196c206d8f7fb8e1e0952fbf1fb73c033219" +checksum = "c3bd11ad6929f01f01be74bb00d02bbd6552f22de030865c898b340a3a592db1" dependencies = [ "async-trait", "coins-bip32", @@ -1933,9 +1933,9 @@ dependencies = [ [[package]] name = "ethers-solc" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e967e60bca8fc83d640a7aebd1492d625c43e86b88a5a5bb08b1019472d5d6b" +checksum = "2284784306de73d8ad1bc792ecc1b87da0268185683698d60fd096d23d168c99" dependencies = [ "cfg-if", "dunce", @@ -2569,11 +2569,11 @@ dependencies = [ [[package]] name = "home" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "747309b4b440c06d57b0b25f2aee03ee9b5e5397d288c60e21fc709bb98a7408" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" dependencies = [ - "winapi", + "windows-sys 0.48.0", ] [[package]] @@ -2980,28 +2980,27 @@ dependencies = [ [[package]] name = "keccak" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3afef3b6eff9ce9d8ff9b3601125eec7f0c8cbac7abd14f355d053fa56c98768" +checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" dependencies = [ "cpufeatures", ] [[package]] name = "lalrpop" -version = "0.19.8" +version = "0.19.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b30455341b0e18f276fa64540aff54deafb54c589de6aca68659c63dd2d5d823" +checksum = "0a1cbf952127589f2851ab2046af368fd20645491bb4b376f04b7f94d7a9837b" dependencies = [ "ascii-canvas", - "atty", "bit-set", "diff", "ena", + "is-terminal", "itertools", "lalrpop-util", "petgraph", - "pico-args", "regex", "regex-syntax 0.6.29", "string_cache", @@ -3012,9 +3011,9 @@ dependencies = [ [[package]] name = "lalrpop-util" -version = "0.19.8" +version = "0.19.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf796c978e9b4d983414f4caedc9273aa33ee214c5b887bd55fde84c85d2dc4" +checksum = "d3c48237b9604c5a4702de6b824e02006c3214327564636aef27c1028a8fa0ed" dependencies = [ "regex", ] @@ -3030,9 +3029,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.142" +version = "0.2.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317" +checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" [[package]] name = "libm" @@ -3069,9 +3068,9 @@ checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" [[package]] name = "linux-raw-sys" -version = "0.3.3" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b085a4f2cde5781fc4b1717f2e86c62f5cda49de7ba99a7c2eae02b61c9064c" +checksum = "ece97ea872ece730aed82664c424eb4c8291e1ff2480247ccf7409044bc6479f" [[package]] name = "lock_api" @@ -3139,9 +3138,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memoffset" -version = "0.7.1" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" +checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" dependencies = [ "autocfg", ] @@ -3211,9 +3210,9 @@ dependencies = [ [[package]] name = "moka" -version = "0.10.2" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0d3b8e76a2e4b17de765db9432e377a171c42fbe0512b8bc860ff1bfe2e273b" +checksum = "934030d03f6191edbb4ba16835ccdb80d560788ac686570a8e2986a0fb59ded8" dependencies = [ "async-io", "async-lock", @@ -3231,7 +3230,7 @@ dependencies = [ "tagptr", "thiserror", "triomphe", - "uuid 1.3.1", + "uuid 1.3.2", ] [[package]] @@ -3277,15 +3276,6 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "nom8" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8" -dependencies = [ - "memchr", -] - [[package]] name = "nonempty" version = "0.7.0" @@ -3439,7 +3429,7 @@ version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799" dependencies = [ - "proc-macro-crate 1.3.0", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 1.0.109", @@ -3451,7 +3441,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" dependencies = [ - "proc-macro-crate 1.3.0", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 2.0.15", @@ -3642,15 +3632,15 @@ checksum = "bd10bab2b6df910bbe6c4987d76aa4221235103d9a9c000cfabcee6a6abc8f7a" dependencies = [ "reqwest", "serde", - "time 0.3.20", + "time 0.3.21", "url", ] [[package]] name = "parity-scale-codec" -version = "3.4.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "637935964ff85a605d114591d4d2c13c5d1ba2806dae97cea6bf180238a749ac" +checksum = "5ddb756ca205bd108aee3c62c6d3c994e1df84a59b9d6d4a5ea42ee1fd5a9a28" dependencies = [ "arrayvec", "bitvec 1.0.1", @@ -3666,7 +3656,7 @@ version = "3.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86b26a931f824dd4eca30b3e43bb4f31cd5f0d3a403c5f5ff27106b805bfde7b" dependencies = [ - "proc-macro-crate 1.3.0", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 1.0.109", @@ -3904,12 +3894,6 @@ dependencies = [ "siphasher", ] -[[package]] -name = "pico-args" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468" - [[package]] name = "pin-project" version = "1.0.12" @@ -3980,8 +3964,8 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" dependencies = [ - "der 0.7.3", - "spki 0.7.1", + "der 0.7.5", + "spki 0.7.2", ] [[package]] @@ -4065,12 +4049,12 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66618389e4ec1c7afe67d51a9bf34ff9236480f8d51e7489b7d5ab0303c13f34" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" dependencies = [ "once_cell", - "toml_edit 0.18.1", + "toml_edit", ] [[package]] @@ -4188,9 +4172,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.26" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "8f4f29d145265ec1c483c7c654450edde0bfe043d3938d6972630663356d9500" dependencies = [ "proc-macro2", ] @@ -4410,9 +4394,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.16" +version = "0.11.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27b71749df584b7f4cac2c426c127a7c785a5106cc98f7a8feb044115f0fa254" +checksum = "13293b639a097af28fc8a90f22add145a9c954e49d77da06263d58cf44d5fb91" dependencies = [ "base64 0.21.0", "bytes", @@ -4653,15 +4637,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.12" +version = "0.37.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "722529a737f5a942fdbac3a46cee213053196737c5eaa3386d52e85b786f2659" +checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" dependencies = [ "bitflags", "errno 0.3.1", "io-lifetimes", "libc", - "linux-raw-sys 0.3.3", + "linux-raw-sys 0.3.7", "windows-sys 0.48.0", ] @@ -4704,7 +4688,7 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213" dependencies = [ - "cipher 0.4.3", + "cipher 0.4.4", ] [[package]] @@ -4718,9 +4702,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.3.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "001cf62ece89779fd16105b5f515ad0e5cedcd5440d3dd806bb067978e7c3608" +checksum = "dfdef77228a4c05dc94211441595746732131ad7f6530c6c18f045da7b7ab937" dependencies = [ "cfg-if", "derive_more", @@ -4730,11 +4714,11 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.3.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "303959cf613a6f6efd19ed4b4ad5bf79966a13352716299ad532cfb115f4205c" +checksum = "53012eae69e5aa5c14671942a5dd47de59d4cdcff8532a6dd0e081faf1119482" dependencies = [ - "proc-macro-crate 1.3.0", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 1.0.109", @@ -4820,10 +4804,10 @@ dependencies = [ "serde_json", "sqlx", "thiserror", - "time 0.3.20", + "time 0.3.21", "tracing", "url", - "uuid 1.3.1", + "uuid 1.3.2", ] [[package]] @@ -4883,8 +4867,8 @@ dependencies = [ "rust_decimal", "sea-query-derive", "serde_json", - "time 0.3.20", - "uuid 1.3.1", + "time 0.3.21", + "uuid 1.3.2", ] [[package]] @@ -4899,8 +4883,8 @@ dependencies = [ "sea-query", "serde_json", "sqlx", - "time 0.3.20", - "uuid 1.3.1", + "time 0.3.21", + "uuid 1.3.2", ] [[package]] @@ -4983,12 +4967,12 @@ dependencies = [ [[package]] name = "sec1" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48518a2b5775ba8ca5b46596aae011caa431e6ce7e4a67ead66d92f08884220e" +checksum = "f0aec48e813d6b90b15f0b8948af3c63483992dee44c03e9930b3eebdabe046e" dependencies = [ "base16ct 0.2.0", - "der 0.7.3", + "der 0.7.5", "generic-array", "pkcs8 0.10.2", "subtle", @@ -5141,25 +5125,25 @@ dependencies = [ "serde", "serde_json", "thiserror", - "time 0.3.20", + "time 0.3.21", "url", - "uuid 1.3.1", + "uuid 1.3.2", ] [[package]] name = "serde" -version = "1.0.160" +version = "1.0.162" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" +checksum = "71b2f6e1ab5c2b98c05f0f35b236b22e8df7ead6ffbf51d7808da7f8817e7ab6" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.160" +version = "1.0.162" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" +checksum = "a2a0814352fd64b58489904a44ea8d90cb1a91dcb6b4f5ebabc32c8318e93cb6" dependencies = [ "proc-macro2", "quote", @@ -5179,9 +5163,9 @@ dependencies = [ [[package]] name = "serde_path_to_error" -version = "0.1.9" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b04f22b563c91331a10074bda3dd5492e3cc39d56bd557e91c0af42b6c7341" +checksum = "f7f05c1d5476066defcdfacce1f52fc3cae3af1d3089727100c02ae92e5abbe0" dependencies = [ "serde", ] @@ -5277,9 +5261,9 @@ dependencies = [ [[package]] name = "sha3" -version = "0.10.6" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdf0c33fae925bdc080598b84bc15c55e7b9a4a43b3c704da051f977469691c9" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" dependencies = [ "digest 0.10.6", "keccak", @@ -5369,7 +5353,7 @@ dependencies = [ "rand", "sha3", "thiserror", - "time 0.3.20", + "time 0.3.21", ] [[package]] @@ -5484,12 +5468,12 @@ dependencies = [ [[package]] name = "spki" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37a5be806ab6f127c3da44b7378837ebf01dadca8510a0e572460216b228bd0e" +checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" dependencies = [ "base64ct", - "der 0.7.3", + "der 0.7.5", ] [[package]] @@ -5561,10 +5545,10 @@ dependencies = [ "sqlx-rt", "stringprep", "thiserror", - "time 0.3.20", + "time 0.3.21", "tokio-stream", "url", - "uuid 1.3.1", + "uuid 1.3.2", "webpki-roots", ] @@ -5612,9 +5596,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "string_cache" -version = "0.8.4" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213494b7a2b503146286049378ce02b482200519accc31872ee8be91fa820a08" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" dependencies = [ "new_debug_unreachable", "once_cell", @@ -5669,9 +5653,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "svm-rs" -version = "0.2.20" +version = "0.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1b8e811a6443e8d93665a5e532efa8429ea8e2052a234a82e2cd69478913310" +checksum = "01afefe60c02f4a2271fb15d1965c37856712cebb338330b06649d12afec42df" dependencies = [ "anyhow", "cfg-if", @@ -5747,7 +5731,7 @@ dependencies = [ "cfg-if", "fastrand", "redox_syscall 0.3.5", - "rustix 0.37.12", + "rustix 0.37.19", "windows-sys 0.45.0", ] @@ -5849,9 +5833,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.20" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd0cbfecb4d19b5ea75bb31ad904eb5b9fa13f21079c3b92017ebdf4999a5890" +checksum = "8f3403384eaacbca9923fa06940178ac13e4edb725486d70e8e15881d0c836cc" dependencies = [ "itoa", "serde", @@ -5861,15 +5845,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" +checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" [[package]] name = "time-macros" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd80a657e71da814b8e5d60d3374fc6d35045062245d80224748ae522dd76f36" +checksum = "372950940a5f07bf38dbe211d7283c9e6d7327df53794992d293e534c733d09b" dependencies = [ "time-core", ] @@ -5900,9 +5884,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.27.0" +version = "1.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" +checksum = "c3c786bf8134e5a3a166db9b29ab8f48134739014a3eca7bc6bfa95d673b136f" dependencies = [ "autocfg", "bytes", @@ -5915,7 +5899,7 @@ dependencies = [ "socket2", "tokio-macros", "tracing", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -5959,9 +5943,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", @@ -5991,9 +5975,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.12" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fb52b74f05dbf495a8fba459fdc331812b96aa086d9eb78101fa0d4569c3313" +checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" dependencies = [ "futures-core", "pin-project-lite", @@ -6033,9 +6017,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.7" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2" +checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" dependencies = [ "bytes", "futures-core", @@ -6062,16 +6046,10 @@ checksum = "b403acf6f2bb0859c93c7f0d967cb4a75a7ac552100f9322faf64dc047669b21" dependencies = [ "serde", "serde_spanned", - "toml_datetime 0.6.1", - "toml_edit 0.19.8", + "toml_datetime", + "toml_edit", ] -[[package]] -name = "toml_datetime" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4553f467ac8e3d374bc9a177a26801e5d0f9b211aa1673fb137a403afd1c9cf5" - [[package]] name = "toml_datetime" version = "0.6.1" @@ -6081,17 +6059,6 @@ dependencies = [ "serde", ] -[[package]] -name = "toml_edit" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56c59d8dd7d0dcbc6428bf7aa2f0e823e26e43b3c9aca15bbc9475d23e5fa12b" -dependencies = [ - "indexmap", - "nom8", - "toml_datetime 0.5.1", -] - [[package]] name = "toml_edit" version = "0.19.8" @@ -6101,7 +6068,7 @@ dependencies = [ "indexmap", "serde", "serde_spanned", - "toml_datetime 0.6.1", + "toml_datetime", "winnow", ] @@ -6496,9 +6463,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.3.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b55a3fef2a1e3b3a00ce878640918820d3c51081576ac657d23af9fc7928fdb" +checksum = "4dad5567ad0cf5b760e5665964bec1b47dfd077ba8a2544b513f3556d3d239a2" dependencies = [ "getrandom", "serde", @@ -6530,12 +6497,11 @@ checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" [[package]] name = "walkdir" -version = "2.3.2" +version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" dependencies = [ "same-file", - "winapi", "winapi-util", ] @@ -6707,7 +6673,7 @@ dependencies = [ "serde_prometheus", "siwe", "thread-fast-rng", - "time 0.3.20", + "time 0.3.21", "tokio", "tokio-console", "tokio-stream", @@ -6717,7 +6683,7 @@ dependencies = [ "tower-http", "ulid", "url", - "uuid 1.3.1", + "uuid 1.3.2", ] [[package]] @@ -6937,9 +6903,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "winnow" -version = "0.4.1" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae8970b36c66498d8ff1d66685dc86b91b29db0c7739899012f63a63814b4b28" +checksum = "61de7bac303dc551fe038e2b3cef0f571087a47571ea6e79a87692ac99b99699" dependencies = [ "memchr", ] @@ -7009,7 +6975,7 @@ dependencies = [ "hmac", "pbkdf2 0.11.0", "sha1", - "time 0.3.20", + "time 0.3.21", "zstd", ] @@ -7034,9 +7000,9 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.7+zstd.1.5.4" +version = "2.0.8+zstd.1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5" +checksum = "5556e6ee25d32df2586c098bbfa278803692a20d0ab9565e049480d52707ec8c" dependencies = [ "cc", "libc", diff --git a/deferred-rate-limiter/Cargo.toml b/deferred-rate-limiter/Cargo.toml index 752e2d8d..9051e90c 100644 --- a/deferred-rate-limiter/Cargo.toml +++ b/deferred-rate-limiter/Cargo.toml @@ -7,8 +7,8 @@ edition = "2021" [dependencies] redis-rate-limiter = { path = "../redis-rate-limiter" } -anyhow = "1.0.70" +anyhow = "1.0.71" hashbrown = "0.13.2" log = "0.4.17" -moka = { version = "0.10.2", default-features = false, features = ["future"] } -tokio = "1.27.0" +moka = { version = "0.11.0", default-features = false, features = ["future"] } +tokio = "1.28.0" diff --git a/entities/Cargo.toml b/entities/Cargo.toml index 1d9a1d54..19d64ae1 100644 --- a/entities/Cargo.toml +++ b/entities/Cargo.toml @@ -11,7 +11,7 @@ path = "src/mod.rs" [dependencies] sea-orm = "0.11.3" -serde = "1.0.160" -uuid = "1.3.1" -ethers = "2.0.3" +serde = "1.0.162" +uuid = "1.3.2" +ethers = "2.0.4" ulid = "1.0.0" diff --git a/migration/Cargo.toml b/migration/Cargo.toml index b6fa5de2..69827f5a 100644 --- a/migration/Cargo.toml +++ b/migration/Cargo.toml @@ -9,7 +9,7 @@ name = "migration" path = "src/lib.rs" [dependencies] -tokio = { version = "1.27.0", features = ["full", "tracing"] } +tokio = { version = "1.28.0", features = ["full", "tracing"] } [dependencies.sea-orm-migration] version = "0.11.3" diff --git a/rate-counter/Cargo.toml b/rate-counter/Cargo.toml index 06dbf0b8..d31bb777 100644 --- a/rate-counter/Cargo.toml +++ b/rate-counter/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" [dependencies] flume = "0.10.14" -tokio = { version = "1.27.0", features = ["time"] } +tokio = { version = "1.28.0", features = ["time"] } diff --git a/redis-rate-limiter/Cargo.toml b/redis-rate-limiter/Cargo.toml index 7c7c4c71..1db687cb 100644 --- a/redis-rate-limiter/Cargo.toml +++ b/redis-rate-limiter/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Bryan Stitt "] edition = "2021" [dependencies] -anyhow = "1.0.70" +anyhow = "1.0.71" chrono = "0.4.24" deadpool-redis = { version = "0.12.0", features = ["rt_tokio_1", "serde"] } -tokio = "1.27.0" +tokio = "1.28.0" diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index 9831da50..a8c0bb18 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -25,10 +25,10 @@ thread-fast-rng = { path = "../thread-fast-rng" } # TODO: import chrono from sea-orm so we always have the same version # TODO: make sure this time version matches siwe. PR to put this in their prelude -anyhow = { version = "1.0.70", features = ["backtrace"] } +anyhow = { version = "1.0.71", features = ["backtrace"] } argh = "0.1.10" -axum = { version = "0.6.16", features = ["headers", "ws"] } -axum-client-ip = "0.4.0" +axum = { version = "0.6.18", features = ["headers", "ws"] } +axum-client-ip = "0.4.1" axum-macros = "0.3.7" chrono = "0.4.24" console-subscriber = { version = "*", optional = true } @@ -36,7 +36,7 @@ counter = "0.5.7" derive_more = "0.99.17" dotenv = "0.15.0" env_logger = "0.10.0" -ethers = { version = "2.0.3", default-features = false, features = ["rustls", "ws"] } +ethers = { version = "2.0.4", default-features = false, features = ["rustls", "ws"] } ewma = "0.1.1" fdlimit = "0.2.1" flume = "0.10.14" @@ -54,7 +54,7 @@ influxdb2-structmap = "0.2.0" ipnet = "2.7.2" itertools = "0.10.5" log = "0.4.17" -moka = { version = "0.10.2", default-features = false, features = ["future"] } +moka = { version = "0.11.0", default-features = false, features = ["future"] } num = "0.4.0" num-traits = "0.2.15" once_cell = { version = "1.17.1" } @@ -65,22 +65,22 @@ prettytable = "*" proctitle = "0.1.1" rdkafka = { version = "0.29.0" } regex = "1.8.1" -reqwest = { version = "0.11.16", default-features = false, features = ["json", "tokio-rustls"] } +reqwest = { version = "0.11.17", default-features = false, features = ["json", "tokio-rustls"] } rmp-serde = "1.1.1" rustc-hash = "1.1.0" sentry = { version = "0.31.0", default-features = false, features = ["backtrace", "contexts", "panic", "anyhow", "reqwest", "rustls", "log", "sentry-log"] } -serde = { version = "1.0.160", features = [] } +serde = { version = "1.0.162", features = [] } serde_json = { version = "1.0.96", default-features = false, features = ["alloc", "raw_value"] } serde_prometheus = "0.2.2" siwe = "0.5.0" -time = "0.3.20" -tokio = { version = "1.27.0", features = ["full"] } +time = "0.3.21" +tokio = { version = "1.28.0", features = ["full"] } tokio-console = { version = "*", optional = true } -tokio-stream = { version = "0.1.12", features = ["sync"] } +tokio-stream = { version = "0.1.14", features = ["sync"] } tokio-uring = { version = "0.4.0", optional = true } toml = "0.7.3" tower = "0.4.13" tower-http = { version = "0.4.0", features = ["cors", "sensitive-headers"] } ulid = { version = "1.0.0", features = ["serde"] } url = "2.3.1" -uuid = "1.3.1" +uuid = "1.3.2" From 96a9a3978930c36fca1049b842d240f6b8293f8c Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 11 May 2023 13:07:31 -0700 Subject: [PATCH 18/18] add support for http basic auth --- TODO.md | 18 +++++------ web3_proxy/src/rpcs/one.rs | 28 ++++++++++++----- web3_proxy/src/rpcs/provider.rs | 53 ++++++++++++++++++++++++++------- 3 files changed, 72 insertions(+), 27 deletions(-) diff --git a/TODO.md b/TODO.md index 5417d951..b405b251 100644 --- a/TODO.md +++ b/TODO.md @@ -410,9 +410,9 @@ These are not yet ordered. There might be duplicates. We might not actually need - [-] add configurable size limits to all the Caches - instead of configuring each cache with MB sizes, have one value for total memory footprint and then percentages for each cache - https://github.com/moka-rs/moka/issues/201 -- [ ] all anyhow::Results need to be replaced with FrontendErrorResponse. - - [ ] rename FrontendErrorResponse to Web3ProxyError - - [ ] almost all the anyhows should be Web3ProxyError::BadRequest +- [x] all anyhow::Results need to be replaced with FrontendErrorResponse. + - [x] rename FrontendErrorResponse to Web3ProxyError + - [x] almost all the anyhows should be Web3ProxyError::BadRequest - as is, these errors are seen as 500 errors and so haproxy keeps retrying them - change premium concurrency limit to be against ip+rpckey - then sites like curve.fi don't have to worry about their user count @@ -422,18 +422,18 @@ These are not yet ordered. There might be duplicates. We might not actually need - all nodes have all blocks - most nodes have all receipts - only archives have old state -- [ ] don't use new_head_provider anywhere except new head subscription -- [ ] enable mev protected transactions with either a /protect/ url (instead of /private/) or the database (when on /rpc/) -- [-] have private transactions be enabled by a url setting rather than a setting on the key +- [x] don't use new_head_provider anywhere except new head subscription +- [x] add support for http basic auth +- [-] enable mev protected transactions with either a /protect/ url (instead of /private/) or the database (when on /rpc/) +- [ ] a **lot** got done that wasn't included in this todo list. go through commits and update this - [ ] eth_sendRawTransaction should only forward if the chain_id matches what we are running - [ ] cli for adding rpc keys to an existing user - [ ] rename "private" to "mev protected" to avoid confusion about private transactions being public once they are mined - [ ] allow restricting an rpc key to specific chains -- [ ] writes to request_latency should be handled by a background task so they don't slow down the request - - maybe we can use https://docs.rs/hdrhistogram/latest/hdrhistogram/sync/struct.SyncHistogram.html +- [-] writes to request_latency should be handled by a background task so they don't slow down the request - [ ] keep re-broadcasting transactions until they are confirmed - [ ] if mev protection is disabled, we should send to *both* balanced_rpcs *and* private_rps -- [ ] if mev protection is enabled, we should sent to *only* private_rpcs +- [x] if mev protection is enabled, we should sent to *only* private_rpcs - [ ] rate limiting/throttling on query_user_stats - [ ] web3rpc configs should have a max_concurrent_requests - will probably want a tool for calculating a safe value for this. too low and we could kill our performance diff --git a/web3_proxy/src/rpcs/one.rs b/web3_proxy/src/rpcs/one.rs index 09a4af4a..5ec2bfac 100644 --- a/web3_proxy/src/rpcs/one.rs +++ b/web3_proxy/src/rpcs/one.rs @@ -20,6 +20,7 @@ use redis_rate_limiter::{RedisPool, RedisRateLimitResult, RedisRateLimiter}; use serde::ser::{SerializeStruct, Serializer}; use serde::Serialize; use serde_json::json; +use std::borrow::Cow; use std::cmp::min; use std::fmt; use std::hash::{Hash, Hasher}; @@ -29,6 +30,7 @@ use thread_fast_rng::rand::Rng; use thread_fast_rng::thread_fast_rng; use tokio::sync::{broadcast, oneshot, watch, RwLock as AsyncRwLock}; use tokio::time::{sleep, sleep_until, timeout, Duration, Instant}; +use url::Url; pub struct Latency { /// exponentially weighted moving average of how many milliseconds behind the fastest node we are @@ -99,8 +101,8 @@ pub struct Web3Rpc { pub name: String, pub display_name: Option, pub db_conn: Option, - pub(super) ws_url: Option, - pub(super) http_url: Option, + pub(super) ws_url: Option, + pub(super) http_url: Option, /// Some connections use an http_client. we keep a clone for reconnecting pub(super) http_client: Option, /// provider is in a RwLock so that we can replace it if re-connecting @@ -227,13 +229,25 @@ impl Web3Rpc { let (disconnect_sender, disconnect_receiver) = watch::channel(false); let reconnect = reconnect.into(); + let http_url = if let Some(http_url) = config.http_url { + Some(http_url.parse()?) + } else { + None + }; + + let ws_url = if let Some(ws_url) = config.ws_url { + Some(ws_url.parse()?) + } else { + None + }; + let new_connection = Self { name, db_conn: db_conn.clone(), display_name: config.display_name, http_client, - ws_url: config.ws_url, - http_url: config.http_url, + ws_url, + http_url, hard_limit, hard_limit_until, soft_limit: config.soft_limit, @@ -526,7 +540,7 @@ impl Web3Rpc { } } - let p = Web3Provider::from_str(ws_url.as_str(), None) + let p = Web3Provider::new(Cow::Borrowed(ws_url), None) .await .context(format!("failed connecting to {}", ws_url))?; @@ -536,7 +550,7 @@ impl Web3Rpc { } else { // http client if let Some(url) = &self.http_url { - let p = Web3Provider::from_str(url, self.http_client.clone()) + let p = Web3Provider::new(Cow::Borrowed(url), self.http_client.clone()) .await .context(format!("failed connecting to {}", url))?; @@ -1481,7 +1495,7 @@ mod tests { let x = Web3Rpc { name: "name".to_string(), - ws_url: Some("ws://example.com".to_string()), + ws_url: Some("ws://example.com".parse::().unwrap()), soft_limit: 1_000, automatic_block_limit: false, backup: false, diff --git a/web3_proxy/src/rpcs/provider.rs b/web3_proxy/src/rpcs/provider.rs index d5ab318e..a70bc88f 100644 --- a/web3_proxy/src/rpcs/provider.rs +++ b/web3_proxy/src/rpcs/provider.rs @@ -1,6 +1,8 @@ -use anyhow::Context; +use anyhow::anyhow; use derive_more::From; -use std::time::Duration; +use ethers::providers::{Authorization, ConnectionDetails}; +use std::{borrow::Cow, time::Duration}; +use url::Url; // TODO: our own structs for these that handle streaming large responses type EthersHttpProvider = ethers::providers::Provider; @@ -34,24 +36,53 @@ impl Web3Provider { } } - pub async fn from_str( - url_str: &str, + /// Note, if the http url has an authority the http_client param is ignored and a dedicated http_client will be used + /// TODO: take a reqwest::Client or a reqwest::ClientBuilder. that way we can do things like set compression even when auth is set + pub async fn new( + mut url: Cow<'_, Url>, http_client: Option, ) -> anyhow::Result { - let provider = if url_str.starts_with("http") { - let url: url::Url = url_str.parse()?; + let auth = if let Some(pass) = url.password().map(|x| x.to_string()) { + // to_string is needed because we are going to remove these items from the url + let user = url.username().to_string(); - let http_client = http_client.context("no http_client")?; + // clear username and password from the url + let mut_url = url.to_mut(); - let provider = ethers::providers::Http::new_with_client(url, http_client); + mut_url + .set_username("") + .map_err(|_| anyhow!("unable to clear username on websocket"))?; + mut_url + .set_password(None) + .map_err(|_| anyhow!("unable to clear password on websocket"))?; + + // keep them + Some(Authorization::basic(user, pass)) + } else { + None + }; + + let provider = if url.scheme().starts_with("http") { + let provider = if let Some(auth) = auth { + ethers::providers::Http::new_with_auth(url.into_owned(), auth)? + } else if let Some(http_client) = http_client { + ethers::providers::Http::new_with_client(url.into_owned(), http_client) + } else { + ethers::providers::Http::new(url.into_owned()) + }; - // TODO: dry this up (needs https://github.com/gakonst/ethers-rs/issues/592) // TODO: i don't think this interval matters for our uses, but we should probably set it to like `block time / 2` ethers::providers::Provider::new(provider) .interval(Duration::from_secs(12)) .into() - } else if url_str.starts_with("ws") { - let provider = ethers::providers::Ws::connect(url_str).await?; + } else if url.scheme().starts_with("ws") { + let provider = if auth.is_some() { + let connection_details = ConnectionDetails::new(url.as_str(), auth); + + ethers::providers::Ws::connect(connection_details).await? + } else { + ethers::providers::Ws::connect(url.as_str()).await? + }; // TODO: dry this up (needs https://github.com/gakonst/ethers-rs/issues/592) // TODO: i don't think this interval matters