From 8c9d43587af0896431af9c7b33aab36aa9a87232 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Wed, 9 Nov 2022 13:32:50 +0100 Subject: [PATCH 01/19] jsonrpsee v0.16 --- Cargo.lock | 499 +++++++++++++------- Cargo.toml | 3 + bin/node/cli/tests/common.rs | 4 +- client/beefy/rpc/src/lib.rs | 2 +- client/finality-grandpa/rpc/src/lib.rs | 2 +- client/rpc-servers/Cargo.toml | 3 + client/rpc-servers/src/lib.rs | 131 ++--- client/rpc-servers/src/middleware.rs | 128 ++--- client/rpc-spec-v2/src/chain_spec/tests.rs | 2 +- client/rpc/src/author/tests.rs | 2 +- client/rpc/src/chain/tests.rs | 2 +- client/rpc/src/state/mod.rs | 3 +- client/rpc/src/state/tests.rs | 2 +- client/rpc/src/system/tests.rs | 2 +- client/service/src/lib.rs | 54 +-- utils/frame/remote-externalities/src/lib.rs | 120 +++-- utils/frame/rpc/client/src/lib.rs | 5 +- 17 files changed, 529 insertions(+), 435 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d65411de0125c..e4ec5c125b444 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,7 +42,7 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "cipher", "cpufeatures", "opaque-debug 0.3.0", @@ -82,6 +82,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "alloc-no-stdlib" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" + +[[package]] +name = "alloc-stdlib" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" +dependencies = [ + "alloc-no-stdlib", +] + [[package]] name = "ansi_term" version = "0.12.1" @@ -183,6 +198,20 @@ dependencies = [ "futures-core", ] +[[package]] +name = "async-compression" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "345fd392ab01f746c717b1357165b76f0b67a60192007b234058c9045fdcf695" +dependencies = [ + "brotli", + "flate2", + "futures-core", + "memchr", + "pin-project-lite 0.2.9", + "tokio", +] + [[package]] name = "async-executor" version = "1.4.0" @@ -258,7 +287,7 @@ checksum = "cf2c06e30a24e8c78a3987d07f0930edf76ef35e027e7bdb063fccafdad1f60c" dependencies = [ "async-io", "blocking", - "cfg-if", + "cfg-if 1.0.0", "event-listener", "futures-lite", "libc", @@ -290,7 +319,7 @@ dependencies = [ "memchr", "num_cpus", "once_cell", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "pin-utils", "slab", "wasm-bindgen-futures", @@ -359,7 +388,7 @@ dependencies = [ "futures-sink", "futures-util", "memchr", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", ] [[package]] @@ -393,7 +422,7 @@ checksum = "5e121dee8023ce33ab248d9ce1493df03c3b38a659b240096fcbd7048ff9c31f" dependencies = [ "addr2line", "cc", - "cfg-if", + "cfg-if 1.0.0", "libc", "miniz_oxide", "object 0.27.1", @@ -623,7 +652,7 @@ dependencies = [ "arrayref", "arrayvec 0.7.2", "cc", - "cfg-if", + "cfg-if 1.0.0", "constant_time_eq", ] @@ -680,6 +709,27 @@ dependencies = [ "once_cell", ] +[[package]] +name = "brotli" +version = "3.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1a0b1dbcc8ae29329621f8d4f0d835787c1c38bb1401979b49d13b0b305ff68" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", + "brotli-decompressor", +] + +[[package]] +name = "brotli-decompressor" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ad2d4653bf5ca36ae797b1f4bb4dbddb60ce49ca4aed8a2ce4829f60425b80" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + [[package]] name = "bs58" version = "0.4.0" @@ -842,6 +892,12 @@ dependencies = [ "smallvec", ] +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "cfg-if" version = "1.0.0" @@ -860,7 +916,7 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c80e5460aa66fe3b91d40bcbdab953a597b60053e34d684ac6903f863b680a6" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "cipher", "cpufeatures", "zeroize", @@ -934,7 +990,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56ccb671c5921be8a84686e6212ca184cb1d7c51cadcdbfcbd1cc3f042f5dfb8" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -1078,7 +1134,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44919ecaf6f99e8e737bc239408931c9a01e9a6c74814fee8242dd2506b65390" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "glob", ] @@ -1261,7 +1317,7 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -1308,7 +1364,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "crossbeam-utils", ] @@ -1318,7 +1374,7 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "crossbeam-epoch", "crossbeam-utils", ] @@ -1329,7 +1385,7 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "crossbeam-utils", "lazy_static", "memoffset", @@ -1342,7 +1398,7 @@ version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "lazy_static", ] @@ -1354,9 +1410,9 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "crypto-bigint" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f2b443d17d49dad5ef0ede301c3179cc923b8822f3393b4d2c28c269dd4a122" +checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" dependencies = [ "generic-array 0.14.4", "rand_core 0.6.2", @@ -1656,7 +1712,7 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "339ee130d97a610ea5a5872d2bbb130fdf68884ff09d3028b81bec8a1ac23bbc" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "dirs-sys-next", ] @@ -1695,7 +1751,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4d33be9473d06f75f58220f71f7a9317aca647dc061dbd3c361b0bef505fbea" dependencies = [ "byteorder", - "quick-error", + "quick-error 1.2.3", ] [[package]] @@ -1777,9 +1833,9 @@ dependencies = [ [[package]] name = "ecdsa" -version = "0.14.7" +version = "0.14.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85789ce7dfbd0f0624c07ef653a08bb2ebf43d3e16531361f46d36dd54334fed" +checksum = "413301934810f597c1d19ca71c8710e99a3f1ba28a0d2ebc01551a2daeea3c5c" dependencies = [ "der", "elliptic-curve", @@ -2009,9 +2065,9 @@ dependencies = [ [[package]] name = "ff" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df689201f395c6b90dfe87127685f8dbfc083a5e779e613575d8bd7314300c3e" +checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" dependencies = [ "rand_core 0.6.2", "subtle", @@ -2033,7 +2089,7 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0408e2626025178a6a7f7ffc05a25bc47103229f19c113755de7bf63816290c" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "redox_syscall", "winapi", @@ -2080,7 +2136,7 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "crc32fast", "libc", "libz-sys", @@ -2279,7 +2335,7 @@ version = "15.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df6bb8542ef006ef0de09a5c4420787d79823c0ed7924225822362fd2bf2ff2d" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "parity-scale-codec", "scale-info", "serde", @@ -2535,7 +2591,7 @@ dependencies = [ "futures-io", "memchr", "parking", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "waker-fn", ] @@ -2592,7 +2648,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "pin-utils", "slab", ] @@ -2661,7 +2717,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "js-sys", "libc", "wasi 0.9.0+wasi-snapshot-preview1", @@ -2674,7 +2730,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "wasi 0.10.0+wasi-snapshot-preview1", ] @@ -2758,9 +2814,9 @@ dependencies = [ [[package]] name = "group" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7391856def869c1c81063a03457c676fbcd419709c3dfb33d8d319de484b154d" +checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" dependencies = [ "ff", "rand_core 0.6.2", @@ -2794,16 +2850,16 @@ checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3" [[package]] name = "handlebars" -version = "4.3.5" +version = "4.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "433e4ab33f1213cdc25b5fa45c76881240cfe79284cf2b395e8b9e312a30a2fd" +checksum = "99d6a30320f094710245150395bc763ad23128d6a1ebbad7594dc4164b62c56b" dependencies = [ "log", "pest", "pest_derive", + "quick-error 2.0.0", "serde", "serde_json", - "thiserror", ] [[package]] @@ -2839,6 +2895,16 @@ dependencies = [ "ahash", ] +[[package]] +name = "hdrhistogram" +version = "7.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f19b9f54f7c7f55e31401bb647626ce0cf0f67b0004982ce815b3ee72a02aa8" +dependencies = [ + "byteorder", + "num-traits", +] + [[package]] name = "heck" version = "0.4.0" @@ -2935,20 +3001,26 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.2" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ "bytes", "http", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", ] +[[package]] +name = "http-range-header" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfe8eed0a9285ef776bb792479ea3834e8b94e13d615c2f66d03dd50a435a29" + [[package]] name = "httparse" -version = "1.8.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" +checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" [[package]] name = "httpdate" @@ -2964,9 +3036,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.22" +version = "0.14.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abfba89e19b959ca163c7752ba59d737c1ceea53a5d31a149c805446fc958064" +checksum = "b7ec3e62bdc98a2f0393a5048e4c30ef659440ea6e0e572965103e72bd836f55" dependencies = [ "bytes", "futures-channel", @@ -2977,8 +3049,8 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa 1.0.4", - "pin-project-lite 0.2.6", + "itoa 0.4.8", + "pin-project-lite 0.2.9", "socket2", "tokio", "tower-service", @@ -3092,7 +3164,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -3134,6 +3206,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" +[[package]] +name = "iri-string" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f0f7638c1e223529f1bfdc48c8b133b9e0b434094d1d28473161ee48b235f78" +dependencies = [ + "nom", +] + [[package]] name = "itertools" version = "0.10.3" @@ -3176,23 +3257,20 @@ dependencies = [ [[package]] name = "jsonrpsee" version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bd0d559d5e679b1ab2f869b486a11182923863b1b3ee8b421763cdd707b783a" +source = "git+https://github.com/paritytech/jsonrpsee?branch=master#457da328e0b4050199eca74b986a4a559159b09d" dependencies = [ "jsonrpsee-core", - "jsonrpsee-http-server", "jsonrpsee-proc-macros", + "jsonrpsee-server", "jsonrpsee-types", "jsonrpsee-ws-client", - "jsonrpsee-ws-server", "tracing", ] [[package]] name = "jsonrpsee-client-transport" version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8752740ecd374bcbf8b69f3e80b0327942df76f793f8d4e60d3355650c31fb74" +source = "git+https://github.com/paritytech/jsonrpsee?branch=master#457da328e0b4050199eca74b986a4a559159b09d" dependencies = [ "futures-util", "http", @@ -3212,8 +3290,7 @@ dependencies = [ [[package]] name = "jsonrpsee-core" version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3dc3e9cf2ba50b7b1d7d76a667619f82846caa39e8e8daa8a4962d74acaddca" +source = "git+https://github.com/paritytech/jsonrpsee?branch=master#457da328e0b4050199eca74b986a4a559159b09d" dependencies = [ "anyhow", "arrayvec 0.7.2", @@ -3224,10 +3301,8 @@ dependencies = [ "futures-timer", "futures-util", "globset", - "http", "hyper", "jsonrpsee-types", - "lazy_static", "parking_lot 0.12.1", "rand 0.8.5", "rustc-hash", @@ -3237,45 +3312,45 @@ dependencies = [ "thiserror", "tokio", "tracing", - "tracing-futures", - "unicase", ] [[package]] -name = "jsonrpsee-http-server" +name = "jsonrpsee-proc-macros" version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03802f0373a38c2420c70b5144742d800b509e2937edc4afb116434f07120117" +source = "git+https://github.com/paritytech/jsonrpsee?branch=master#457da328e0b4050199eca74b986a4a559159b09d" +dependencies = [ + "heck", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "jsonrpsee-server" +version = "0.15.1" +source = "git+https://github.com/paritytech/jsonrpsee?branch=master#457da328e0b4050199eca74b986a4a559159b09d" dependencies = [ "futures-channel", "futures-util", + "http", "hyper", "jsonrpsee-core", "jsonrpsee-types", "serde", "serde_json", + "soketto", "tokio", + "tokio-stream", + "tokio-util", + "tower", "tracing", - "tracing-futures", -] - -[[package]] -name = "jsonrpsee-proc-macros" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd67957d4280217247588ac86614ead007b301ca2fa9f19c19f880a536f029e3" -dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "syn", ] [[package]] name = "jsonrpsee-types" version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e290bba767401b646812f608c099b922d8142603c9e73a50fb192d3ac86f4a0d" +source = "git+https://github.com/paritytech/jsonrpsee?branch=master#457da328e0b4050199eca74b986a4a559159b09d" dependencies = [ "anyhow", "beef", @@ -3288,8 +3363,7 @@ dependencies = [ [[package]] name = "jsonrpsee-ws-client" version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ee5feddd5188e62ac08fcf0e56478138e581509d4730f3f7be9b57dd402a4ff" +source = "git+https://github.com/paritytech/jsonrpsee?branch=master#457da328e0b4050199eca74b986a4a559159b09d" dependencies = [ "http", "jsonrpsee-client-transport", @@ -3297,33 +3371,13 @@ dependencies = [ "jsonrpsee-types", ] -[[package]] -name = "jsonrpsee-ws-server" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d488ba74fb369e5ab68926feb75a483458b88e768d44319f37e4ecad283c7325" -dependencies = [ - "futures-channel", - "futures-util", - "http", - "jsonrpsee-core", - "jsonrpsee-types", - "serde_json", - "soketto", - "tokio", - "tokio-stream", - "tokio-util", - "tracing", - "tracing-futures", -] - [[package]] name = "k256" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3636d281d46c3b64182eb3a0a42b7b483191a2ecc3f05301fa67403f7c9bc949" +checksum = "72c1e0b51e7ec0a97369623508396067a486bd0cbed95a2659a4b863d28cfc8b" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "ecdsa", "elliptic-curve", "sha2 0.10.2", @@ -3527,7 +3581,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f84d96438c15fcd6c3f244c8fce01d1e2b9c6b5623e9c711dc9286d8fc92d6a" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "winapi", ] @@ -4018,7 +4072,7 @@ version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "value-bag", ] @@ -4090,6 +4144,12 @@ dependencies = [ "libc", ] +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + [[package]] name = "match_cfg" version = "0.1.0" @@ -4192,6 +4252,22 @@ dependencies = [ "zeroize", ] +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -4226,7 +4302,7 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2be9a9090bc1cac2930688fa9478092a64c6a92ddc6ae0692d46b37d9cab709" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "downcast", "fragile", "lazy_static", @@ -4241,7 +4317,7 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86d702a0530a0141cf4ed147cf5ec7be6f2c187d4e37fcbefc39cf34116bfe8f" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "proc-macro2", "quote", "syn", @@ -4445,7 +4521,7 @@ checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6" dependencies = [ "bitflags", "cc", - "cfg-if", + "cfg-if 1.0.0", "libc", "memoffset", ] @@ -4457,7 +4533,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" dependencies = [ "bitflags", - "cfg-if", + "cfg-if 1.0.0", "libc", ] @@ -6429,7 +6505,7 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d32c34f4f5ca7f9196001c0aba5a1f9a5a12382c8944b8b0f90233282d1e8f8" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "hashbrown 0.12.3", "impl-trait-for-tuples", "parity-util-mem-derive", @@ -6489,7 +6565,7 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "instant", "libc", "redox_syscall", @@ -6503,7 +6579,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28141e0cc4143da2443301914478dc976a61ffdb3f043058310c70df2fed8954" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "redox_syscall", "smallvec", @@ -6548,19 +6624,18 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pest" -version = "2.4.0" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbc7bc69c062e492337d74d59b120c274fd3d261b6bf6d3207d499b4b379c41a" +checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" dependencies = [ - "thiserror", "ucd-trie", ] [[package]] name = "pest_derive" -version = "2.4.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b75706b9642ebcb34dab3bc7750f811609a0eb1dd8b88c2d15bf628c1c65b2" +checksum = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0" dependencies = [ "pest", "pest_generator", @@ -6568,9 +6643,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.4.0" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f9272122f5979a6511a749af9db9bfc810393f63119970d7085fed1c4ea0db" +checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55" dependencies = [ "pest", "pest_meta", @@ -6581,13 +6656,13 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.4.0" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8717927f9b79515e565a64fe46c38b8cd0427e64c40680b14a7365ab09ac8d" +checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d" dependencies = [ - "once_cell", + "maplit", "pest", - "sha1", + "sha-1 0.8.2", ] [[package]] @@ -6628,9 +6703,9 @@ checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" [[package]] name = "pin-project-lite" -version = "0.2.6" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" [[package]] name = "pin-utils" @@ -6690,15 +6765,14 @@ dependencies = [ [[package]] name = "polling" -version = "2.4.0" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab4609a838d88b73d8238967b60dd115cc08d38e2bbaf51ee1e4b695f89122e2" +checksum = "a2a7bc6b2a29e632e45451c941832803a18cce6781db04de8a04696cdca8bde4" dependencies = [ - "autocfg", - "cfg-if", + "cfg-if 0.1.10", "libc", "log", - "wepoll-ffi", + "wepoll-sys", "winapi", ] @@ -6719,7 +6793,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", "opaque-debug 0.3.0", "universal-hash", @@ -6835,7 +6909,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7f64969ffd5dd8f39bd57a68ac53c163a095ed9d0fb707146da1b27025a3504" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "fnv", "lazy_static", "memchr", @@ -6967,6 +7041,12 @@ version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" +[[package]] +name = "quick-error" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ac73b1112776fc109b2e61909bc46c7e1bf0d7f690ffb1676553acce16d5cda" + [[package]] name = "quickcheck" version = "1.0.3" @@ -7278,14 +7358,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52e44394d2086d010551b14b53b1f24e31647570cd1deb0379e2c21b329aba00" dependencies = [ "hostname", - "quick-error", + "quick-error 1.2.3", ] [[package]] name = "rfc6979" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88c86280f057430a52f4861551b092a01b419b8eacefc7c995eacb9dc132fe32" +checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" dependencies = [ "crypto-bigint", "hmac 0.12.1", @@ -7463,7 +7543,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" dependencies = [ "fnv", - "quick-error", + "quick-error 1.2.3", "tempfile", ] @@ -8028,7 +8108,7 @@ dependencies = [ name = "sc-executor-wasmtime" version = "0.10.0-dev" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "log", "once_cell", @@ -8505,11 +8585,14 @@ name = "sc-rpc-server" version = "4.0.0-dev" dependencies = [ "futures", + "http", "jsonrpsee", "log", "serde_json", "substrate-prometheus-endpoint", "tokio", + "tower", + "tower-http", ] [[package]] @@ -8831,7 +8914,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8980cafbe98a7ee7a9cc16b32ebce542c77883f512d83fbf2ddc8f6a85ea74c9" dependencies = [ "bitvec", - "cfg-if", + "cfg-if 1.0.0", "derive_more", "parity-scale-codec", "scale-info-derive", @@ -9062,6 +9145,18 @@ dependencies = [ "serde", ] +[[package]] +name = "sha-1" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" +dependencies = [ + "block-buffer 0.7.3", + "digest 0.8.1", + "fake-simd", + "opaque-debug 0.2.3", +] + [[package]] name = "sha-1" version = "0.9.4" @@ -9069,23 +9164,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfebf75d25bd900fd1e7d11501efab59bc846dbc76196839663e6637bba9f25f" dependencies = [ "block-buffer 0.9.0", - "cfg-if", + "cfg-if 1.0.0", "cpuid-bool", "digest 0.9.0", "opaque-debug 0.3.0", ] -[[package]] -name = "sha1" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "006769ba83e921b3085caa8334186b00cf92b4cb1a6cf4632fbccc8eff5c7549" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest 0.10.3", -] - [[package]] name = "sha2" version = "0.8.2" @@ -9105,7 +9189,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" dependencies = [ "block-buffer 0.9.0", - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", "digest 0.9.0", "opaque-debug 0.3.0", @@ -9117,7 +9201,7 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", "digest 0.10.3", ] @@ -9168,9 +9252,9 @@ dependencies = [ [[package]] name = "signature" -version = "1.6.3" +version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deb766570a2825fa972bceff0d195727876a9cdf2460ab2e52d455dc2de47fd9" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" dependencies = [ "digest 0.10.3", "rand_core 0.6.2", @@ -9249,10 +9333,11 @@ dependencies = [ "bytes", "flate2", "futures", + "http", "httparse", "log", "rand 0.8.5", - "sha-1", + "sha-1 0.9.4", ] [[package]] @@ -10382,7 +10467,7 @@ version = "2.0.0" dependencies = [ "beefy-merkle-tree", "beefy-primitives", - "cfg-if", + "cfg-if 1.0.0", "frame-support", "frame-system", "frame-system-rpc-runtime-api", @@ -10571,7 +10656,7 @@ version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "fastrand", "libc", "redox_syscall", @@ -10729,7 +10814,7 @@ dependencies = [ "num_cpus", "once_cell", "parking_lot 0.12.1", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "signal-hook-registry", "socket2", "tokio-macros", @@ -10765,7 +10850,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b2f3f698253f03119ac0102beaa64f67a67e08074d03a22d18784104543727f" dependencies = [ "futures-core", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "tokio", ] @@ -10792,7 +10877,7 @@ dependencies = [ "futures-core", "futures-io", "futures-sink", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "tokio", "tracing", ] @@ -10806,6 +10891,63 @@ dependencies = [ "serde", ] +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "hdrhistogram", + "indexmap", + "pin-project", + "pin-project-lite 0.2.9", + "rand 0.8.5", + "slab", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c530c8675c1dbf98facee631536fa116b5fb6382d7dd6dc1b118d970eafe3ba" +dependencies = [ + "async-compression", + "base64", + "bitflags", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-range-header", + "httpdate", + "iri-string", + "mime", + "mime_guess", + "percent-encoding", + "pin-project-lite 0.2.9", + "tokio", + "tokio-util", + "tower", + "tower-layer", + "tower-service", + "tracing", + "uuid", +] + +[[package]] +name = "tower-layer" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "343bc9466d3fe6b0f960ef45960509f84480bf4fd96f92901afe7ff3df9d3a62" + [[package]] name = "tower-service" version = "0.3.1" @@ -10818,9 +10960,9 @@ version = "0.1.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "log", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "tracing-attributes", "tracing-core", ] @@ -10961,7 +11103,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f7f83d1e4a0e4358ac54c5c3681e5d7da5efc5a7a632c90bb6d6669ddd9bc26" dependencies = [ "async-trait", - "cfg-if", + "cfg-if 1.0.0", "data-encoding", "enum-as-inner", "futures-channel", @@ -10984,7 +11126,7 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aff21aa4dcefb0a1afbfac26deb0adc93888c7d295fb63ab273ef276ba2b7cfe" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "futures-util", "ipconfig", "lazy_static", @@ -11058,7 +11200,7 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "digest 0.10.3", "rand 0.8.5", "static_assertions", @@ -11173,6 +11315,15 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "uuid" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd6469f4314d5f1ffec476e05f17cc9a78bc7a27a6a857842170bdf8d6f98d2f" +dependencies = [ + "getrandom 0.2.3", +] + [[package]] name = "valuable" version = "0.1.0" @@ -11273,7 +11424,7 @@ version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e68338db6becec24d3c7977b5bf8a48be992c934b5d07177e3931f5dc9b076c" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "wasm-bindgen-macro", ] @@ -11298,7 +11449,7 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3de431a2910c86679c34283a33f66f4e4abd7e0aec27b6669060148872aadf94" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "js-sys", "wasm-bindgen", "web-sys", @@ -11404,7 +11555,7 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f727a39e7161f7438ddb8eafe571b67c576a8c2fb459f666d9053b5bba4afdea" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "indexmap", "js-sys", "loupe", @@ -11524,7 +11675,7 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccd7fdc60e252a795c849b3f78a81a134783051407e7e279c10b7019139ef8dc" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "enum-iterator", "enumset", "leb128", @@ -11549,7 +11700,7 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcff0cd2c01a8de6009fd863b14ea883132a468a24f2d2ee59dc34453d3a31b5" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "enum-iterator", "enumset", "leb128", @@ -11596,7 +11747,7 @@ checksum = "afdc46158517c2769f9938bc222a7d41b3bb330824196279d8aa2d667cd40641" dependencies = [ "backtrace", "cc", - "cfg-if", + "cfg-if 1.0.0", "enum-iterator", "indexmap", "libc", @@ -11667,7 +11818,7 @@ checksum = "8a10dc9784d8c3a33c970e3939180424955f08af2e7f20368ec02685a0e8f065" dependencies = [ "anyhow", "bincode", - "cfg-if", + "cfg-if 1.0.0", "indexmap", "libc", "log", @@ -11693,7 +11844,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee4dbdc6daf68528cad1275ac91e3f51848ce9824385facc94c759f529decdf8" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -11765,7 +11916,7 @@ dependencies = [ "addr2line", "anyhow", "bincode", - "cfg-if", + "cfg-if 1.0.0", "cpp_demangle", "gimli 0.26.1", "log", @@ -11800,7 +11951,7 @@ checksum = "ae79e0515160bd5abee5df50a16c4eb8db9f71b530fc988ae1d9ce34dcb8dd01" dependencies = [ "anyhow", "cc", - "cfg-if", + "cfg-if 1.0.0", "indexmap", "libc", "log", @@ -11877,10 +12028,10 @@ dependencies = [ ] [[package]] -name = "wepoll-ffi" -version = "0.1.2" +name = "wepoll-sys" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" +checksum = "0fcb14dea929042224824779fbc82d9fab8d2e6d3cbc0ac404de8edf489e77ff" dependencies = [ "cc", ] diff --git a/Cargo.toml b/Cargo.toml index 45aa5f9854d25..94ebed8dd32c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -310,3 +310,6 @@ inherits = "release" lto = "fat" # https://doc.rust-lang.org/rustc/codegen-options/index.html#codegen-units codegen-units = 1 + +[patch.crates-io] +jsonrpsee = { git = "https://github.com/paritytech/jsonrpsee", branch = "master" } diff --git a/bin/node/cli/tests/common.rs b/bin/node/cli/tests/common.rs index 358c09779d59a..79c5e79dfaa5c 100644 --- a/bin/node/cli/tests/common.rs +++ b/bin/node/cli/tests/common.rs @@ -163,14 +163,14 @@ pub fn find_ws_url_from_output(read: impl Read + Send) -> (String, String) { data.push_str(&line); // does the line contain our port (we expect this specific output from substrate). - let sock_addr = match line.split_once("Running JSON-RPC WS server: addr=") { + let sock_addr = match line.split_once("Running JSON-RPC server: addr=") { None => return None, Some((_, after)) => after.split_once(",").unwrap().0, }; Some(format!("ws://{}", sock_addr)) }) - .expect("We should get a WebSocket address"); + .expect("We should get an address"); (ws_url, data) } diff --git a/client/beefy/rpc/src/lib.rs b/client/beefy/rpc/src/lib.rs index d29ed433c38db..59a133b86214e 100644 --- a/client/beefy/rpc/src/lib.rs +++ b/client/beefy/rpc/src/lib.rs @@ -172,7 +172,7 @@ mod tests { }; use beefy_primitives::{known_payloads, Payload, SignedCommitment}; use codec::{Decode, Encode}; - use jsonrpsee::{types::EmptyParams, RpcModule}; + use jsonrpsee::{types::EmptyServerParams as EmptyParams, RpcModule}; use sp_runtime::traits::{BlakeTwo256, Hash}; use substrate_test_runtime_client::runtime::Block; diff --git a/client/finality-grandpa/rpc/src/lib.rs b/client/finality-grandpa/rpc/src/lib.rs index 85df72de77b54..dfdad666ba8f3 100644 --- a/client/finality-grandpa/rpc/src/lib.rs +++ b/client/finality-grandpa/rpc/src/lib.rs @@ -138,7 +138,7 @@ mod tests { use std::{collections::HashSet, convert::TryInto, sync::Arc}; use jsonrpsee::{ - types::{EmptyParams, SubscriptionId}, + types::{EmptyServerParams as EmptyParams, SubscriptionId}, RpcModule, }; use parity_scale_codec::{Decode, Encode}; diff --git a/client/rpc-servers/Cargo.toml b/client/rpc-servers/Cargo.toml index ef2e6bec4cdb0..10861570f7901 100644 --- a/client/rpc-servers/Cargo.toml +++ b/client/rpc-servers/Cargo.toml @@ -19,3 +19,6 @@ log = "0.4.17" serde_json = "1.0.85" tokio = { version = "1.17.0", features = ["parking_lot"] } prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0.10.0-dev", path = "../../utils/prometheus" } +tower-http = { version = "0.3.4", features = ["full"] } +tower = { version = "0.4.13", features = ["full"] } +http = "0.2.8" diff --git a/client/rpc-servers/src/lib.rs b/client/rpc-servers/src/lib.rs index 7eb825e169bfa..44fa092fa2e74 100644 --- a/client/rpc-servers/src/lib.rs +++ b/client/rpc-servers/src/lib.rs @@ -21,17 +21,21 @@ #![warn(missing_docs)] use jsonrpsee::{ - http_server::{AccessControlBuilder, HttpServerBuilder, HttpServerHandle}, - ws_server::{WsServerBuilder, WsServerHandle}, + server::{ + middleware::proxy_get_request::ProxyGetRequestLayer, AllowHosts, ServerBuilder, + ServerHandle, + }, RpcModule, }; use std::{error::Error as StdError, net::SocketAddr}; -pub use crate::middleware::{RpcMetrics, RpcMiddleware}; +pub use crate::middleware::RpcMetrics; +use http::header::HeaderValue; pub use jsonrpsee::core::{ id_providers::{RandomIntegerIdProvider, RandomStringIdProvider}, traits::IdProvider, }; +use tower_http::cors::{AllowOrigin, CorsLayer}; const MEGABYTE: usize = 1024 * 1024; @@ -46,13 +50,12 @@ const WS_MAX_SUBS_PER_CONN: usize = 1024; pub mod middleware; -/// Type alias for http server -pub type HttpServer = HttpServerHandle; -/// Type alias for ws server -pub type WsServer = WsServerHandle; +/// Type alias JSON-RPC server +pub type Server = ServerHandle; -/// WebSocket specific settings on the server. -pub struct WsConfig { +/// Server config. +#[derive(Debug, Clone)] +pub struct Config { /// Maximum connections. pub max_connections: Option, /// Maximum subscriptions per connection. @@ -63,12 +66,12 @@ pub struct WsConfig { pub max_payload_out_mb: Option, } -impl WsConfig { +impl Config { // Deconstructs the config to get the finalized inner values. // // `Payload size` or `max subs per connection` bigger than u32::MAX will be truncated. - fn deconstruct(self) -> (u32, u32, u64, u32) { - let max_conns = self.max_connections.unwrap_or(WS_MAX_CONNECTIONS) as u64; + fn deconstruct(self) -> (u32, u32, u32, u32) { + let max_conns = self.max_connections.unwrap_or(WS_MAX_CONNECTIONS) as u32; let max_payload_in_mb = payload_size_or_default(self.max_payload_in_mb) as u32; let max_payload_out_mb = payload_size_or_default(self.max_payload_out_mb) as u32; let max_subs_per_conn = self.max_subs_per_conn.unwrap_or(WS_MAX_SUBS_PER_CONN) as u32; @@ -77,87 +80,46 @@ impl WsConfig { } } -/// Start HTTP server listening on given address. -pub async fn start_http( - addrs: [SocketAddr; 2], - cors: Option<&Vec>, - max_payload_in_mb: Option, - max_payload_out_mb: Option, - metrics: Option, - rpc_api: RpcModule, - rt: tokio::runtime::Handle, -) -> Result> { - let max_payload_in = payload_size_or_default(max_payload_in_mb); - let max_payload_out = payload_size_or_default(max_payload_out_mb); - - let mut acl = AccessControlBuilder::new(); - - if let Some(cors) = cors { - // Whitelist listening address. - // NOTE: set_allowed_hosts will whitelist both ports but only one will used. - acl = acl.set_allowed_hosts(format_allowed_hosts(&addrs[..]))?; - acl = acl.set_allowed_origins(cors)?; - }; - - let builder = HttpServerBuilder::new() - .max_request_body_size(max_payload_in as u32) - .max_response_body_size(max_payload_out as u32) - .set_access_control(acl.build()) - .health_api("/health", "system_health")? - .custom_tokio_runtime(rt); - - let rpc_api = build_rpc_api(rpc_api); - let (handle, addr) = if let Some(metrics) = metrics { - let middleware = RpcMiddleware::new(metrics, "http".into()); - let builder = builder.set_middleware(middleware); - let server = builder.build(&addrs[..]).await?; - let addr = server.local_addr(); - (server.start(rpc_api)?, addr) - } else { - let server = builder.build(&addrs[..]).await?; - let addr = server.local_addr(); - (server.start(rpc_api)?, addr) - }; - - log::info!( - "Running JSON-RPC HTTP server: addr={}, allowed origins={:?}", - addr.map_or_else(|_| "unknown".to_string(), |a| a.to_string()), - cors - ); - - Ok(handle) -} - /// Start WS server listening on given address. -pub async fn start_ws( +pub async fn start_server( addrs: [SocketAddr; 2], cors: Option<&Vec>, - ws_config: WsConfig, + config: Config, metrics: Option, rpc_api: RpcModule, rt: tokio::runtime::Handle, id_provider: Option>, -) -> Result> { +) -> Result> { let (max_payload_in, max_payload_out, max_connections, max_subs_per_conn) = - ws_config.deconstruct(); - - let mut acl = AccessControlBuilder::new(); - - if let Some(cors) = cors { - // Whitelist listening address. - // NOTE: set_allowed_hosts will whitelist both ports but only one will used. - acl = acl.set_allowed_hosts(format_allowed_hosts(&addrs[..]))?; - acl = acl.set_allowed_origins(cors)?; + config.deconstruct(); + + let (allow_hosts, cors) = { + if let Some(cors) = cors { + let mut list = Vec::new(); + for origin in cors { + list.push(HeaderValue::from_str(origin.as_str())?); + } + (allowed_hosts(&addrs), CorsLayer::new().allow_origin(AllowOrigin::list(list))) + } else { + // allow all cors + (AllowHosts::Any, CorsLayer::permissive()) + } }; - let mut builder = WsServerBuilder::new() + let middleware = tower::ServiceBuilder::new() + // Proxy `GET /health` requests to internal `system_health` method. + .layer(ProxyGetRequestLayer::new("/health", "system_health")?) + .layer(cors.clone()); + + let mut builder = ServerBuilder::new() .max_request_body_size(max_payload_in) .max_response_body_size(max_payload_out) .max_connections(max_connections) .max_subscriptions_per_connection(max_subs_per_conn) .ping_interval(std::time::Duration::from_secs(30)) - .custom_tokio_runtime(rt) - .set_access_control(acl.build()); + .set_host_filtering(allow_hosts) + .set_middleware(middleware) + .custom_tokio_runtime(rt); if let Some(provider) = id_provider { builder = builder.set_id_provider(provider); @@ -167,8 +129,7 @@ pub async fn start_ws( let rpc_api = build_rpc_api(rpc_api); let (handle, addr) = if let Some(metrics) = metrics { - let middleware = RpcMiddleware::new(metrics, "ws".into()); - let builder = builder.set_middleware(middleware); + let builder = builder.set_logger(metrics); let server = builder.build(&addrs[..]).await?; let addr = server.local_addr(); (server.start(rpc_api)?, addr) @@ -179,7 +140,7 @@ pub async fn start_ws( }; log::info!( - "Running JSON-RPC WS server: addr={}, allowed origins={:?}", + "Running JSON-RPC server: addr={}, cors={:?}", addr.map_or_else(|_| "unknown".to_string(), |a| a.to_string()), cors ); @@ -187,13 +148,13 @@ pub async fn start_ws( Ok(handle) } -fn format_allowed_hosts(addrs: &[SocketAddr]) -> Vec { +fn allowed_hosts(addrs: &[SocketAddr]) -> AllowHosts { let mut hosts = Vec::with_capacity(addrs.len() * 2); for addr in addrs { - hosts.push(format!("localhost:{}", addr.port())); - hosts.push(format!("127.0.0.1:{}", addr.port())); + hosts.push(format!("localhost:{}", addr.port()).into()); + hosts.push(format!("127.0.0.1:{}", addr.port()).into()); } - hosts + AllowHosts::Only(hosts) } fn build_rpc_api(mut rpc_api: RpcModule) -> RpcModule { diff --git a/client/rpc-servers/src/middleware.rs b/client/rpc-servers/src/middleware.rs index 0d77442323241..ccb2f01109f27 100644 --- a/client/rpc-servers/src/middleware.rs +++ b/client/rpc-servers/src/middleware.rs @@ -16,9 +16,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -//! RPC middlware to collect prometheus metrics on RPC calls. +//! RPC middleware to collect prometheus metrics on RPC calls. -use jsonrpsee::core::middleware::{Headers, HttpMiddleware, MethodKind, Params, WsMiddleware}; +use jsonrpsee::server::logger::{HttpRequest, Logger, MethodKind, Params, TransportProtocol}; use prometheus_endpoint::{ register, Counter, CounterVec, HistogramOpts, HistogramVec, Opts, PrometheusError, Registry, U64, @@ -54,9 +54,9 @@ pub struct RpcMetrics { calls_started: CounterVec, /// Number of calls completed. calls_finished: CounterVec, - /// Number of Websocket sessions opened (Websocket only). + /// Number of Websocket sessions opened. ws_sessions_opened: Option>, - /// Number of Websocket sessions closed (Websocket only). + /// Number of Websocket sessions closed. ws_sessions_closed: Option>, } @@ -139,62 +139,61 @@ impl RpcMetrics { } } -#[derive(Clone)] -/// Middleware for RPC calls -pub struct RpcMiddleware { - metrics: RpcMetrics, - transport_label: &'static str, -} +impl Logger for RpcMetrics { + type Instant = std::time::Instant; -impl RpcMiddleware { - /// Create a new [`RpcMiddleware`] with the provided [`RpcMetrics`]. - pub fn new(metrics: RpcMetrics, transport_label: &'static str) -> Self { - Self { metrics, transport_label } + fn on_connect( + &self, + _remote_addr: SocketAddr, + _request: &HttpRequest, + transport: TransportProtocol, + ) { + if let TransportProtocol::WebSocket = transport { + self.ws_sessions_opened.as_ref().map(|counter| counter.inc()); + } } - /// Called when a new JSON-RPC request comes to the server. - fn on_request(&self) -> std::time::Instant { + fn on_request(&self, transport: TransportProtocol) -> Self::Instant { + let transport_label = transport_label_str(transport); let now = std::time::Instant::now(); - self.metrics.requests_started.with_label_values(&[self.transport_label]).inc(); + self.requests_started.with_label_values(&[transport_label]).inc(); now } - /// Called on each JSON-RPC method call, batch requests will trigger `on_call` multiple times. - fn on_call(&self, name: &str, params: Params, kind: MethodKind) { + fn on_call(&self, name: &str, params: Params, kind: MethodKind, transport: TransportProtocol) { + let transport_label = transport_label_str(transport); log::trace!( target: "rpc_metrics", "[{}] on_call name={} params={:?} kind={}", - self.transport_label, + transport_label, name, params, kind, ); - self.metrics - .calls_started - .with_label_values(&[self.transport_label, name]) - .inc(); + self.calls_started.with_label_values(&[transport_label, name]).inc(); } - /// Called on each JSON-RPC method completion, batch requests will trigger `on_result` multiple - /// times. - fn on_result(&self, name: &str, success: bool, started_at: std::time::Instant) { + fn on_result( + &self, + name: &str, + success: bool, + started_at: Self::Instant, + transport: TransportProtocol, + ) { + let transport_label = transport_label_str(transport); let micros = started_at.elapsed().as_micros(); log::debug!( target: "rpc_metrics", "[{}] {} call took {} μs", - self.transport_label, + transport_label, name, micros, ); - self.metrics - .calls_time - .with_label_values(&[self.transport_label, name]) - .observe(micros as _); + self.calls_time.with_label_values(&[transport_label, name]).observe(micros as _); - self.metrics - .calls_finished + self.calls_finished .with_label_values(&[ - self.transport_label, + transport_label, name, // the label "is_error", so `success` should be regarded as false // and vice-versa to be registrered correctly. @@ -203,57 +202,22 @@ impl RpcMiddleware { .inc(); } - /// Called once the JSON-RPC request is finished and response is sent to the output buffer. - fn on_response(&self, _result: &str, started_at: std::time::Instant) { - log::trace!(target: "rpc_metrics", "[{}] on_response started_at={:?}", self.transport_label, started_at); - self.metrics.requests_finished.with_label_values(&[self.transport_label]).inc(); - } -} - -impl WsMiddleware for RpcMiddleware { - type Instant = std::time::Instant; - - fn on_connect(&self, _remote_addr: SocketAddr, _headers: &Headers) { - self.metrics.ws_sessions_opened.as_ref().map(|counter| counter.inc()); - } - - fn on_request(&self) -> Self::Instant { - self.on_request() - } - - fn on_call(&self, name: &str, params: Params, kind: MethodKind) { - self.on_call(name, params, kind) + fn on_response(&self, _result: &str, started_at: Self::Instant, transport: TransportProtocol) { + let transport_label = transport_label_str(transport); + log::trace!(target: "rpc_metrics", "[{}] on_response started_at={:?}", transport_label, started_at); + self.requests_finished.with_label_values(&[transport_label]).inc(); } - fn on_result(&self, name: &str, success: bool, started_at: Self::Instant) { - self.on_result(name, success, started_at) - } - - fn on_response(&self, _result: &str, started_at: Self::Instant) { - self.on_response(_result, started_at) - } - - fn on_disconnect(&self, _remote_addr: SocketAddr) { - self.metrics.ws_sessions_closed.as_ref().map(|counter| counter.inc()); + fn on_disconnect(&self, _remote_addr: SocketAddr, transport: TransportProtocol) { + if let TransportProtocol::WebSocket = transport { + self.ws_sessions_closed.as_ref().map(|counter| counter.inc()); + } } } -impl HttpMiddleware for RpcMiddleware { - type Instant = std::time::Instant; - - fn on_request(&self, _remote_addr: SocketAddr, _headers: &Headers) -> Self::Instant { - self.on_request() - } - - fn on_call(&self, name: &str, params: Params, kind: MethodKind) { - self.on_call(name, params, kind) - } - - fn on_result(&self, name: &str, success: bool, started_at: Self::Instant) { - self.on_result(name, success, started_at) - } - - fn on_response(&self, _result: &str, started_at: Self::Instant) { - self.on_response(_result, started_at) +fn transport_label_str(t: TransportProtocol) -> &'static str { + match t { + TransportProtocol::Http => "http", + TransportProtocol::WebSocket => "ws", } } diff --git a/client/rpc-spec-v2/src/chain_spec/tests.rs b/client/rpc-spec-v2/src/chain_spec/tests.rs index 6c078b2974e98..6f662ba422bc4 100644 --- a/client/rpc-spec-v2/src/chain_spec/tests.rs +++ b/client/rpc-spec-v2/src/chain_spec/tests.rs @@ -17,7 +17,7 @@ // along with this program. If not, see . use super::*; -use jsonrpsee::{types::EmptyParams, RpcModule}; +use jsonrpsee::{types::EmptyServerParams as EmptyParams, RpcModule}; use sc_chain_spec::Properties; const CHAIN_NAME: &'static str = "TEST_CHAIN_NAME"; diff --git a/client/rpc/src/author/tests.rs b/client/rpc/src/author/tests.rs index f969812e5b14c..573d01630de32 100644 --- a/client/rpc/src/author/tests.rs +++ b/client/rpc/src/author/tests.rs @@ -23,7 +23,7 @@ use assert_matches::assert_matches; use codec::Encode; use jsonrpsee::{ core::Error as RpcError, - types::{error::CallError, EmptyParams}, + types::{error::CallError, EmptyServerParams as EmptyParams}, RpcModule, }; use sc_transaction_pool::{BasicPool, FullChainApi}; diff --git a/client/rpc/src/chain/tests.rs b/client/rpc/src/chain/tests.rs index 1e6dbd5aca148..224d021f9409e 100644 --- a/client/rpc/src/chain/tests.rs +++ b/client/rpc/src/chain/tests.rs @@ -19,7 +19,7 @@ use super::*; use crate::testing::{test_executor, timeout_secs}; use assert_matches::assert_matches; -use jsonrpsee::types::EmptyParams; +use jsonrpsee::types::EmptyServerParams as EmptyParams; use sc_block_builder::BlockBuilderProvider; use sp_consensus::BlockOrigin; use sp_rpc::list::ListOrValue; diff --git a/client/rpc/src/state/mod.rs b/client/rpc/src/state/mod.rs index 7213e4360ae2b..fd802e5a80391 100644 --- a/client/rpc/src/state/mod.rs +++ b/client/rpc/src/state/mod.rs @@ -28,9 +28,8 @@ use std::sync::Arc; use crate::SubscriptionTaskExecutor; use jsonrpsee::{ - core::{Error as JsonRpseeError, RpcResult}, + core::{server::rpc_module::SubscriptionSink, Error as JsonRpseeError, RpcResult}, types::SubscriptionResult, - ws_server::SubscriptionSink, }; use sc_rpc_api::{state::ReadProof, DenyUnsafe}; diff --git a/client/rpc/src/state/tests.rs b/client/rpc/src/state/tests.rs index 53dd8ebf50499..3ef59e5ca9a7c 100644 --- a/client/rpc/src/state/tests.rs +++ b/client/rpc/src/state/tests.rs @@ -23,7 +23,7 @@ use assert_matches::assert_matches; use futures::executor; use jsonrpsee::{ core::Error as RpcError, - types::{error::CallError as RpcCallError, EmptyParams, ErrorObject}, + types::{error::CallError as RpcCallError, EmptyServerParams as EmptyParams, ErrorObject}, }; use sc_block_builder::BlockBuilderProvider; use sc_rpc_api::DenyUnsafe; diff --git a/client/rpc/src/system/tests.rs b/client/rpc/src/system/tests.rs index 2f91648008ff7..00ab9c46861e2 100644 --- a/client/rpc/src/system/tests.rs +++ b/client/rpc/src/system/tests.rs @@ -21,7 +21,7 @@ use assert_matches::assert_matches; use futures::prelude::*; use jsonrpsee::{ core::Error as RpcError, - types::{error::CallError, EmptyParams}, + types::{error::CallError, EmptyServerParams as EmptyParams}, RpcModule, }; use sc_network::{self, config::Role, PeerId}; diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index 091b4bbe9fe5f..e330f80e5604f 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -43,7 +43,6 @@ use log::{debug, error, warn}; use sc_client_api::{blockchain::HeaderBackend, BlockBackend, BlockchainEvents, ProofProvider}; use sc_network::PeerId; use sc_network_common::{config::MultiaddrWithPeerId, service::NetworkBlock}; -use sc_rpc_server::WsConfig; use sc_utils::mpsc::TracingUnboundedReceiver; use sp_blockchain::HeaderMetadata; use sp_consensus::SyncOracle; @@ -294,20 +293,9 @@ async fn build_network_future< // Wrapper for HTTP and WS servers that makes sure they are properly shut down. mod waiting { - pub struct HttpServer(pub Option); + pub struct Server(pub Option); - impl Drop for HttpServer { - fn drop(&mut self) { - if let Some(server) = self.0.take() { - // This doesn't not wait for the server to be stopped but fires the signal. - let _ = server.stop(); - } - } - } - - pub struct WsServer(pub Option); - - impl Drop for WsServer { + impl Drop for Server { fn drop(&mut self) { if let Some(server) = self.0.take() { // This doesn't not wait for the server to be stopped but fires the signal. @@ -326,8 +314,7 @@ fn start_rpc_servers( where R: Fn(sc_rpc::DenyUnsafe) -> Result, Error>, { - let (max_request_size, ws_max_response_size, http_max_response_size) = - legacy_cli_parsing(config); + let (max_request_size, ws_max_response_size, _) = legacy_cli_parsing(config); fn deny_unsafe(addr: SocketAddr, methods: &RpcMethods) -> sc_rpc::DenyUnsafe { let is_exposed_addr = !addr.ip().is_loopback(); @@ -342,49 +329,32 @@ where addr }; - let ws_addr = config + let addr = config .rpc_ws .unwrap_or_else(|| "127.0.0.1:9944".parse().expect("valid sockaddr; qed")); - let ws_addr2 = random_port(ws_addr); - let http_addr = config - .rpc_http - .unwrap_or_else(|| "127.0.0.1:9933".parse().expect("valid sockaddr; qed")); - let http_addr2 = random_port(http_addr); + let addr2 = random_port(addr); let metrics = sc_rpc_server::RpcMetrics::new(config.prometheus_registry())?; - let http_fut = sc_rpc_server::start_http( - [http_addr, http_addr2], - config.rpc_cors.as_ref(), - max_request_size, - http_max_response_size, - metrics.clone(), - gen_rpc_module(deny_unsafe(ws_addr, &config.rpc_methods))?, - config.tokio_handle.clone(), - ); - - let ws_config = WsConfig { + let server_config = sc_rpc_server::Config { max_connections: config.rpc_ws_max_connections, max_payload_in_mb: max_request_size, max_payload_out_mb: ws_max_response_size, max_subs_per_conn: config.rpc_max_subs_per_conn, }; - let ws_fut = sc_rpc_server::start_ws( - [ws_addr, ws_addr2], + let server_fut = sc_rpc_server::start_server( + [addr, addr2], config.rpc_cors.as_ref(), - ws_config, + server_config, metrics, - gen_rpc_module(deny_unsafe(http_addr, &config.rpc_methods))?, + gen_rpc_module(deny_unsafe(addr, &config.rpc_methods))?, config.tokio_handle.clone(), rpc_id_provider, ); - match tokio::task::block_in_place(|| { - config.tokio_handle.block_on(futures::future::try_join(http_fut, ws_fut)) - }) { - Ok((http, ws)) => - Ok(Box::new((waiting::HttpServer(Some(http)), waiting::WsServer(Some(ws))))), + match tokio::task::block_in_place(|| config.tokio_handle.block_on(server_fut)) { + Ok(server) => Ok(Box::new(waiting::Server(Some(server)))), Err(e) => Err(Error::Application(e)), } } diff --git a/utils/frame/remote-externalities/src/lib.rs b/utils/frame/remote-externalities/src/lib.rs index 86cfc767bf3b5..4f95331c03bc8 100644 --- a/utils/frame/remote-externalities/src/lib.rs +++ b/utils/frame/remote-externalities/src/lib.rs @@ -39,7 +39,9 @@ use std::{ path::{Path, PathBuf}, sync::Arc, }; -use substrate_rpc_client::{rpc_params, ws_client, ChainApi, ClientT, StateApi, WsClient}; +use substrate_rpc_client::{ + rpc_params, ws_client, BatchRequestBuilder, ChainApi, ClientT, StateApi, WsClient, +}; type KeyValue = (StorageKey, StorageData); type TopKeyValues = Vec; @@ -334,33 +336,50 @@ where log::debug!(target: LOG_TARGET, "Querying a total of {} keys", keys.len()); let mut key_values: Vec = vec![]; + let mut batch_success = true; + let client = self.as_online().rpc_client(); for chunk_keys in keys.chunks(BATCH_SIZE) { - let batch = chunk_keys - .iter() - .cloned() - .map(|key| ("state_getStorage", rpc_params![key, at])) - .collect::>(); - - let values = client.batch_request::>(batch).await.map_err(|e| { - log::error!( - target: LOG_TARGET, - "failed to execute batch: {:?}. Error: {:?}", - chunk_keys.iter().map(HexDisplay::from).collect::>(), - e - ); - "batch failed." - })?; + let mut batch = BatchRequestBuilder::new(); - assert_eq!(chunk_keys.len(), values.len()); + for key in chunk_keys.iter() { + batch + .insert("state_getStorage", rpc_params![key, at]) + .map_err(|_| "Invalid batch params")?; + } + + let batch_response = + client.batch_request::>(batch).await.map_err(|e| { + log::error!( + target: LOG_TARGET, + "failed to execute batch: {:?}. Error: {:?}", + chunk_keys.iter().map(HexDisplay::from).collect::>(), + e + ); + "batch failed." + })?; + + assert_eq!(chunk_keys.len(), batch_response.len()); + + for (key, maybe_value) in chunk_keys.into_iter().zip(batch_response) { + match maybe_value { + Ok(Some(v)) => { + key_values.push((key.clone(), v)); + }, + Ok(None) => { + log::warn!( + target: LOG_TARGET, + "key {:?} had none corresponding value.", + &key + ); + key_values.push((key.clone(), StorageData(vec![]))); + }, + Err(e) => { + log::error!(target: LOG_TARGET, "key {:?} failed: {:?}", &key, e); + batch_success = false; + }, + }; - for (idx, key) in chunk_keys.iter().enumerate() { - let maybe_value = values[idx].clone(); - let value = maybe_value.unwrap_or_else(|| { - log::warn!(target: LOG_TARGET, "key {:?} had none corresponding value.", &key); - StorageData(vec![]) - }); - key_values.push((key.clone(), value)); if key_values.len() % (10 * BATCH_SIZE) == 0 { let ratio: f64 = key_values.len() as f64 / keys_count as f64; log::debug!( @@ -374,7 +393,11 @@ where } } - Ok(key_values) + if batch_success { + Ok(key_values) + } else { + Err("batch failed.") + } } /// Get the values corresponding to `child_keys` at the given `prefixed_top_key`. @@ -385,12 +408,14 @@ where at: B::Hash, ) -> Result, &'static str> { let mut child_kv_inner = vec![]; + let mut batch_success = true; + for batch_child_key in child_keys.chunks(BATCH_SIZE) { - let batch_request = batch_child_key - .iter() - .cloned() - .map(|key| { - ( + let mut batch_request = BatchRequestBuilder::new(); + + for key in batch_child_key { + batch_request + .insert( "childstate_getStorage", rpc_params![ PrefixedStorageKey::new(prefixed_top_key.as_ref().to_vec()), @@ -398,8 +423,8 @@ where at ], ) - }) - .collect::>(); + .map_err(|_| "Invalid batch params")?; + } let batch_response = self .as_online() @@ -418,17 +443,32 @@ where assert_eq!(batch_child_key.len(), batch_response.len()); - for (idx, key) in batch_child_key.iter().enumerate() { - let maybe_value = batch_response[idx].clone(); - let value = maybe_value.unwrap_or_else(|| { - log::warn!(target: LOG_TARGET, "key {:?} had none corresponding value.", &key); - StorageData(vec![]) - }); - child_kv_inner.push((key.clone(), value)); + for (key, maybe_value) in batch_child_key.iter().zip(batch_response) { + match maybe_value { + Ok(Some(v)) => { + child_kv_inner.push((key.clone(), v)); + }, + Ok(None) => { + log::warn!( + target: LOG_TARGET, + "key {:?} had none corresponding value.", + &key + ); + child_kv_inner.push((key.clone(), StorageData(vec![]))); + }, + Err(e) => { + log::error!(target: LOG_TARGET, "key {:?} failed: {:?}", &key, e); + batch_success = false; + }, + }; } } - Ok(child_kv_inner) + if batch_success { + Ok(child_kv_inner) + } else { + Err("batch failed.") + } } pub(crate) async fn rpc_child_get_keys( diff --git a/utils/frame/rpc/client/src/lib.rs b/utils/frame/rpc/client/src/lib.rs index 254cc193c0e67..a211fc6c6983e 100644 --- a/utils/frame/rpc/client/src/lib.rs +++ b/utils/frame/rpc/client/src/lib.rs @@ -43,7 +43,10 @@ use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; use std::collections::VecDeque; pub use jsonrpsee::{ - core::client::{ClientT, Subscription, SubscriptionClientT}, + core::{ + client::{ClientT, Subscription, SubscriptionClientT}, + params::BatchRequestBuilder, + }, rpc_params, ws_client::{WsClient, WsClientBuilder}, }; From 7c01e067b3df1e44f728c492e66dd24f1fa21181 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Wed, 9 Nov 2022 12:54:10 +0100 Subject: [PATCH 02/19] breaking: remove old CLI configs --- bin/node/cli/benches/block_production.rs | 8 +- bin/node/cli/benches/transaction_pool.rs | 8 +- client/cli/src/commands/run_cmd.rs | 65 +------------ client/cli/src/config.rs | 49 ++-------- client/rpc-servers/src/lib.rs | 116 ++++++++++++----------- client/rpc/src/state/mod.rs | 10 +- client/rpc/src/state/state_full.rs | 10 +- client/rpc/src/state/tests.rs | 24 ++--- client/service/src/builder.rs | 8 +- client/service/src/config.rs | 18 +--- client/service/src/lib.rs | 71 +++----------- client/service/test/src/lib.rs | 8 +- client/tracing/src/block/mod.rs | 51 +++------- 13 files changed, 127 insertions(+), 319 deletions(-) diff --git a/bin/node/cli/benches/block_production.rs b/bin/node/cli/benches/block_production.rs index 4fcebb123d9e3..ec1cac5f68bf6 100644 --- a/bin/node/cli/benches/block_production.rs +++ b/bin/node/cli/benches/block_production.rs @@ -86,18 +86,14 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase { offchain_worker: execution_strategy, other: execution_strategy, }, - rpc_http: None, - rpc_ws: None, - rpc_ipc: None, - rpc_ws_max_connections: None, + rpc_addr: None, + rpc_max_connections: None, rpc_cors: None, rpc_methods: Default::default(), - rpc_max_payload: None, rpc_max_request_size: None, rpc_max_response_size: None, rpc_id_provider: None, rpc_max_subs_per_conn: None, - ws_max_out_buffer_capacity: None, prometheus_config: None, telemetry_endpoints: None, default_heap_pages: None, diff --git a/bin/node/cli/benches/transaction_pool.rs b/bin/node/cli/benches/transaction_pool.rs index a8839642ddc26..1f744451d6d84 100644 --- a/bin/node/cli/benches/transaction_pool.rs +++ b/bin/node/cli/benches/transaction_pool.rs @@ -79,18 +79,14 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase { offchain_worker: sc_client_api::ExecutionStrategy::NativeWhenPossible, other: sc_client_api::ExecutionStrategy::NativeWhenPossible, }, - rpc_http: None, - rpc_ws: None, - rpc_ipc: None, - rpc_ws_max_connections: None, + rpc_addr: None, + rpc_max_connections: None, rpc_cors: None, rpc_methods: Default::default(), - rpc_max_payload: None, rpc_max_request_size: None, rpc_max_response_size: None, rpc_id_provider: None, rpc_max_subs_per_conn: None, - ws_max_out_buffer_capacity: None, prometheus_config: None, telemetry_endpoints: None, default_heap_pages: None, diff --git a/client/cli/src/commands/run_cmd.rs b/client/cli/src/commands/run_cmd.rs index 35181d83f805f..851619465de5d 100644 --- a/client/cli/src/commands/run_cmd.rs +++ b/client/cli/src/commands/run_cmd.rs @@ -81,26 +81,6 @@ pub struct RunCmd { )] pub rpc_methods: RpcMethods, - /// Listen to all Websocket interfaces. - /// - /// Default is local. Note: not all RPC methods are safe to be exposed publicly. Use an RPC - /// proxy server to filter out dangerous methods. More details: - /// . - /// Use `--unsafe-ws-external` to suppress the warning if you understand the risks. - #[arg(long)] - pub ws_external: bool, - - /// Listen to all Websocket interfaces. - /// - /// Same as `--ws-external` but doesn't warn you about it. - #[arg(long)] - pub unsafe_ws_external: bool, - - /// DEPRECATED, this has no affect anymore. Use `rpc_max_request_size` or - /// `rpc_max_response_size` instead. - #[arg(long)] - pub rpc_max_payload: Option, - /// Set the the maximum RPC request payload size for both HTTP and WS in megabytes. /// Default is 15MiB. #[arg(long)] @@ -122,25 +102,13 @@ pub struct RunCmd { #[arg(long)] pub prometheus_external: bool, - /// DEPRECATED, IPC support has been removed. - #[arg(long, value_name = "PATH")] - pub ipc_path: Option, - - /// Specify HTTP RPC server TCP port. + /// Specify JSON-RPC server TCP port. #[arg(long, value_name = "PORT")] pub rpc_port: Option, - /// Specify WebSockets RPC server TCP port. - #[arg(long, value_name = "PORT")] - pub ws_port: Option, - /// Maximum number of WS RPC server connections. #[arg(long, value_name = "COUNT")] - pub ws_max_connections: Option, - - /// DEPRECATED, this has no affect anymore. Use `rpc_max_response_size` instead. - #[arg(long)] - pub ws_max_out_buffer_capacity: Option, + pub rpc_max_connections: Option, /// Specify browser Origins allowed to access the HTTP & WS RPC servers. /// @@ -394,8 +362,8 @@ impl CliConfiguration for RunCmd { Ok(self.no_grandpa) } - fn rpc_ws_max_connections(&self) -> Result> { - Ok(self.ws_max_connections) + fn rpc_max_connections(&self) -> Result> { + Ok(self.rpc_max_connections) } fn rpc_cors(&self, is_dev: bool) -> Result>> { @@ -419,7 +387,7 @@ impl CliConfiguration for RunCmd { .into()) } - fn rpc_http(&self, default_listen_port: u16) -> Result> { + fn rpc_addr(&self, default_listen_port: u16) -> Result> { let interface = rpc_interface( self.rpc_external, self.unsafe_rpc_external, @@ -430,29 +398,10 @@ impl CliConfiguration for RunCmd { Ok(Some(SocketAddr::new(interface, self.rpc_port.unwrap_or(default_listen_port)))) } - fn rpc_ipc(&self) -> Result> { - Ok(self.ipc_path.clone()) - } - - fn rpc_ws(&self, default_listen_port: u16) -> Result> { - let interface = rpc_interface( - self.ws_external, - self.unsafe_ws_external, - self.rpc_methods, - self.validator, - )?; - - Ok(Some(SocketAddr::new(interface, self.ws_port.unwrap_or(default_listen_port)))) - } - fn rpc_methods(&self) -> Result { Ok(self.rpc_methods.into()) } - fn rpc_max_payload(&self) -> Result> { - Ok(self.rpc_max_payload) - } - fn rpc_max_request_size(&self) -> Result> { Ok(self.rpc_max_request_size) } @@ -465,10 +414,6 @@ impl CliConfiguration for RunCmd { Ok(self.rpc_max_subscriptions_per_connection) } - fn ws_max_out_buffer_capacity(&self) -> Result> { - Ok(self.ws_max_out_buffer_capacity) - } - fn transaction_pool(&self, is_dev: bool) -> Result { Ok(self.pool_config.transaction_pool(is_dev)) } diff --git a/client/cli/src/config.rs b/client/cli/src/config.rs index 77689708a231f..1002fea30dff4 100644 --- a/client/cli/src/config.rs +++ b/client/cli/src/config.rs @@ -57,20 +57,13 @@ pub trait DefaultConfigurationValues { 30333 } - /// The port Substrate should listen on for websocket connections. + /// The port Substrate should listen on for JSON-RPC connections. /// /// By default this is `9944`. - fn rpc_ws_listen_port() -> u16 { + fn rpc_listen_port() -> u16 { 9944 } - /// The port Substrate should listen on for http connections. - /// - /// By default this is `9933`. - fn rpc_http_listen_port() -> u16 { - 9933 - } - /// The port Substrate should listen on for prometheus connections. /// /// By default this is `9615`. @@ -302,24 +295,10 @@ pub trait CliConfiguration: Sized { .unwrap_or_default()) } - /// Get the RPC HTTP address (`None` if disabled). - /// - /// By default this is `None`. - fn rpc_http(&self, _default_listen_port: u16) -> Result> { - Ok(None) - } - - /// Get the RPC IPC path (`None` if disabled). + /// Get the RPC address (`None` if disabled). /// /// By default this is `None`. - fn rpc_ipc(&self) -> Result> { - Ok(None) - } - - /// Get the RPC websocket address (`None` if disabled). - /// - /// By default this is `None`. - fn rpc_ws(&self, _default_listen_port: u16) -> Result> { + fn rpc_addr(&self, _default_listen_port: u16) -> Result> { Ok(None) } @@ -334,7 +313,7 @@ pub trait CliConfiguration: Sized { /// Get the RPC websockets maximum connections (`None` if unlimited). /// /// By default this is `None`. - fn rpc_ws_max_connections(&self) -> Result> { + fn rpc_max_connections(&self) -> Result> { Ok(None) } @@ -345,11 +324,6 @@ pub trait CliConfiguration: Sized { Ok(Some(Vec::new())) } - /// Get maximum RPC payload. - fn rpc_max_payload(&self) -> Result> { - Ok(None) - } - /// Get maximum RPC request payload size. fn rpc_max_request_size(&self) -> Result> { Ok(None) @@ -365,11 +339,6 @@ pub trait CliConfiguration: Sized { Ok(None) } - /// Get maximum WS output buffer capacity. - fn ws_max_out_buffer_capacity(&self) -> Result> { - Ok(None) - } - /// Get the prometheus configuration (`None` if disabled) /// /// By default this is `None`. @@ -533,18 +502,14 @@ pub trait CliConfiguration: Sized { wasm_method: self.wasm_method()?, wasm_runtime_overrides: self.wasm_runtime_overrides(), execution_strategies: self.execution_strategies(is_dev, is_validator)?, - rpc_http: self.rpc_http(DCV::rpc_http_listen_port())?, - rpc_ws: self.rpc_ws(DCV::rpc_ws_listen_port())?, - rpc_ipc: self.rpc_ipc()?, + rpc_addr: self.rpc_addr(DCV::rpc_listen_port())?, rpc_methods: self.rpc_methods()?, - rpc_ws_max_connections: self.rpc_ws_max_connections()?, + rpc_max_connections: self.rpc_max_connections()?, rpc_cors: self.rpc_cors(is_dev)?, - rpc_max_payload: self.rpc_max_payload()?, rpc_max_request_size: self.rpc_max_request_size()?, rpc_max_response_size: self.rpc_max_response_size()?, rpc_id_provider: None, rpc_max_subs_per_conn: self.rpc_max_subscriptions_per_connection()?, - ws_max_out_buffer_capacity: self.ws_max_out_buffer_capacity()?, prometheus_config: self .prometheus_config(DCV::prometheus_listen_port(), &chain_spec)?, telemetry_endpoints, diff --git a/client/rpc-servers/src/lib.rs b/client/rpc-servers/src/lib.rs index 44fa092fa2e74..8768d1d2428ac 100644 --- a/client/rpc-servers/src/lib.rs +++ b/client/rpc-servers/src/lib.rs @@ -37,25 +37,29 @@ pub use jsonrpsee::core::{ }; use tower_http::cors::{AllowOrigin, CorsLayer}; -const MEGABYTE: usize = 1024 * 1024; +const MEGABYTE: u32 = 1024 * 1024; -/// Maximal payload accepted by RPC servers. -pub const RPC_MAX_PAYLOAD_DEFAULT: usize = 15 * MEGABYTE; +/// Maximal payload accepted by JSON-RPC servers. +pub const RPC_MAX_PAYLOAD_DEFAULT: u32 = 15 * MEGABYTE; -/// Default maximum number of connections for WS RPC servers. -const WS_MAX_CONNECTIONS: usize = 100; +/// Default maximum number of connections for JSON-RPC servers. +const RPC_MAX_CONNECTIONS: u32 = 100; -/// Default maximum number subscriptions per connection for WS RPC servers. -const WS_MAX_SUBS_PER_CONN: usize = 1024; +/// Default maximum number subscriptions per connection for JSON-RPC servers. +const RPC_MAX_SUBS_PER_CONN: u32 = 1024; pub mod middleware; -/// Type alias JSON-RPC server +/// Type alias for the JSON-RPC server. pub type Server = ServerHandle; /// Server config. -#[derive(Debug, Clone)] -pub struct Config { +#[derive(Debug)] +pub struct Config<'a, M: Send + Sync + 'static> { + /// Socket addresses. + pub addrs: [SocketAddr; 2], + /// CORS. + pub cors: Option<&'a Vec>, /// Maximum connections. pub max_connections: Option, /// Maximum subscriptions per connection. @@ -64,45 +68,44 @@ pub struct Config { pub max_payload_in_mb: Option, /// Maximum rpc response payload size. pub max_payload_out_mb: Option, -} - -impl Config { - // Deconstructs the config to get the finalized inner values. - // - // `Payload size` or `max subs per connection` bigger than u32::MAX will be truncated. - fn deconstruct(self) -> (u32, u32, u32, u32) { - let max_conns = self.max_connections.unwrap_or(WS_MAX_CONNECTIONS) as u32; - let max_payload_in_mb = payload_size_or_default(self.max_payload_in_mb) as u32; - let max_payload_out_mb = payload_size_or_default(self.max_payload_out_mb) as u32; - let max_subs_per_conn = self.max_subs_per_conn.unwrap_or(WS_MAX_SUBS_PER_CONN) as u32; - - (max_payload_in_mb, max_payload_out_mb, max_conns, max_subs_per_conn) - } + /// Metrics. + pub metrics: Option, + /// RPC API. + pub rpc_api: RpcModule, + /// Subscription ID provider. + pub id_provider: Option>, + /// Tokio runtime handle. + pub tokio_handle: tokio::runtime::Handle, } /// Start WS server listening on given address. -pub async fn start_server( - addrs: [SocketAddr; 2], - cors: Option<&Vec>, - config: Config, - metrics: Option, - rpc_api: RpcModule, - rt: tokio::runtime::Handle, - id_provider: Option>, +pub async fn start_server<'a, M: Send + Sync + 'static>( + config: Config<'a, M>, ) -> Result> { - let (max_payload_in, max_payload_out, max_connections, max_subs_per_conn) = - config.deconstruct(); - - let (allow_hosts, cors) = { + let Config { + addrs, + cors, + max_payload_in_mb, + max_payload_out_mb, + max_connections, + max_subs_per_conn, + metrics, + id_provider, + tokio_handle, + rpc_api, + } = config; + + let host_filter = hosts_filtering(cors.is_some(), &addrs); + + let cors = { if let Some(cors) = cors { let mut list = Vec::new(); for origin in cors { list.push(HeaderValue::from_str(origin.as_str())?); } - (allowed_hosts(&addrs), CorsLayer::new().allow_origin(AllowOrigin::list(list))) + CorsLayer::new().allow_origin(AllowOrigin::list(list)) } else { - // allow all cors - (AllowHosts::Any, CorsLayer::permissive()) + CorsLayer::permissive() } }; @@ -112,14 +115,16 @@ pub async fn start_server( .layer(cors.clone()); let mut builder = ServerBuilder::new() - .max_request_body_size(max_payload_in) - .max_response_body_size(max_payload_out) - .max_connections(max_connections) - .max_subscriptions_per_connection(max_subs_per_conn) + .max_request_body_size(payload_size_or_default(max_payload_in_mb)) + .max_response_body_size(payload_size_or_default(max_payload_out_mb)) + .max_connections(max_connections.map_or(RPC_MAX_CONNECTIONS, |m| m as u32)) + .max_subscriptions_per_connection( + max_subs_per_conn.map_or(RPC_MAX_SUBS_PER_CONN, |m| m as u32), + ) .ping_interval(std::time::Duration::from_secs(30)) - .set_host_filtering(allow_hosts) + .set_host_filtering(host_filter) .set_middleware(middleware) - .custom_tokio_runtime(rt); + .custom_tokio_runtime(tokio_handle); if let Some(provider) = id_provider { builder = builder.set_id_provider(provider); @@ -148,13 +153,18 @@ pub async fn start_server( Ok(handle) } -fn allowed_hosts(addrs: &[SocketAddr]) -> AllowHosts { - let mut hosts = Vec::with_capacity(addrs.len() * 2); - for addr in addrs { - hosts.push(format!("localhost:{}", addr.port()).into()); - hosts.push(format!("127.0.0.1:{}", addr.port()).into()); +fn hosts_filtering(enabled: bool, addrs: &[SocketAddr]) -> AllowHosts { + if enabled { + // NOTE The listening addresses are whitelisted by default. + let mut hosts = Vec::with_capacity(addrs.len() * 2); + for addr in addrs { + hosts.push(format!("localhost:{}", addr.port()).into()); + hosts.push(format!("127.0.0.1:{}", addr.port()).into()); + } + AllowHosts::Only(hosts) + } else { + AllowHosts::Any } - AllowHosts::Only(hosts) } fn build_rpc_api(mut rpc_api: RpcModule) -> RpcModule { @@ -172,6 +182,6 @@ fn build_rpc_api(mut rpc_api: RpcModule) -> RpcModu rpc_api } -fn payload_size_or_default(size_mb: Option) -> usize { - size_mb.map_or(RPC_MAX_PAYLOAD_DEFAULT, |mb| mb.saturating_mul(MEGABYTE)) +fn payload_size_or_default(size_mb: Option) -> u32 { + size_mb.map_or(RPC_MAX_PAYLOAD_DEFAULT, |mb| (mb as u32).saturating_mul(MEGABYTE)) } diff --git a/client/rpc/src/state/mod.rs b/client/rpc/src/state/mod.rs index fd802e5a80391..d5be2e3071e62 100644 --- a/client/rpc/src/state/mod.rs +++ b/client/rpc/src/state/mod.rs @@ -166,7 +166,6 @@ pub fn new_full( client: Arc, executor: SubscriptionTaskExecutor, deny_unsafe: DenyUnsafe, - rpc_max_payload: Option, ) -> (State, ChildState) where Block: BlockT + 'static, @@ -186,12 +185,9 @@ where + 'static, Client::Api: Metadata, { - let child_backend = Box::new(self::state_full::FullState::new( - client.clone(), - executor.clone(), - rpc_max_payload, - )); - let backend = Box::new(self::state_full::FullState::new(client, executor, rpc_max_payload)); + let child_backend = + Box::new(self::state_full::FullState::new(client.clone(), executor.clone())); + let backend = Box::new(self::state_full::FullState::new(client, executor)); (State { backend, deny_unsafe }, ChildState { backend: child_backend }) } diff --git a/client/rpc/src/state/state_full.rs b/client/rpc/src/state/state_full.rs index 64b6cacaad700..1ca035d858959 100644 --- a/client/rpc/src/state/state_full.rs +++ b/client/rpc/src/state/state_full.rs @@ -59,7 +59,6 @@ pub struct FullState { client: Arc, executor: SubscriptionTaskExecutor, _phantom: PhantomData<(BE, Block)>, - rpc_max_payload: Option, } impl FullState @@ -72,12 +71,8 @@ where Block: BlockT + 'static, { /// Create new state API backend for full nodes. - pub fn new( - client: Arc, - executor: SubscriptionTaskExecutor, - rpc_max_payload: Option, - ) -> Self { - Self { client, executor, _phantom: PhantomData, rpc_max_payload } + pub fn new(client: Arc, executor: SubscriptionTaskExecutor) -> Self { + Self { client, executor, _phantom: PhantomData } } /// Returns given block hash or best block hash if None is passed. @@ -454,7 +449,6 @@ where targets, storage_keys, methods, - self.rpc_max_payload, ) .trace_block() .map_err(|e| invalid_block::(block, None, e.to_string())) diff --git a/client/rpc/src/state/tests.rs b/client/rpc/src/state/tests.rs index 3ef59e5ca9a7c..124fab93dcc3d 100644 --- a/client/rpc/src/state/tests.rs +++ b/client/rpc/src/state/tests.rs @@ -55,7 +55,7 @@ async fn should_return_storage() { .add_extra_storage(b":map:acc2".to_vec(), vec![1, 2, 3]) .build(); let genesis_hash = client.genesis_hash(); - let (client, child) = new_full(Arc::new(client), test_executor(), DenyUnsafe::No, None); + let (client, child) = new_full(Arc::new(client), test_executor(), DenyUnsafe::No); let key = StorageKey(KEY.to_vec()); assert_eq!( @@ -100,7 +100,7 @@ async fn should_return_storage_entries() { .add_extra_child_storage(&child_info, KEY2.to_vec(), CHILD_VALUE2.to_vec()) .build(); let genesis_hash = client.genesis_hash(); - let (_client, child) = new_full(Arc::new(client), test_executor(), DenyUnsafe::No, None); + let (_client, child) = new_full(Arc::new(client), test_executor(), DenyUnsafe::No); let keys = &[StorageKey(KEY1.to_vec()), StorageKey(KEY2.to_vec())]; assert_eq!( @@ -131,7 +131,7 @@ async fn should_return_child_storage() { .build(), ); let genesis_hash = client.genesis_hash(); - let (_client, child) = new_full(client, test_executor(), DenyUnsafe::No, None); + let (_client, child) = new_full(client, test_executor(), DenyUnsafe::No); let child_key = prefixed_storage_key(); let key = StorageKey(b"key".to_vec()); @@ -162,7 +162,7 @@ async fn should_return_child_storage_entries() { .build(), ); let genesis_hash = client.genesis_hash(); - let (_client, child) = new_full(client, test_executor(), DenyUnsafe::No, None); + let (_client, child) = new_full(client, test_executor(), DenyUnsafe::No); let child_key = prefixed_storage_key(); let keys = vec![StorageKey(b"key1".to_vec()), StorageKey(b"key2".to_vec())]; @@ -193,7 +193,7 @@ async fn should_return_child_storage_entries() { async fn should_call_contract() { let client = Arc::new(substrate_test_runtime_client::new()); let genesis_hash = client.genesis_hash(); - let (client, _child) = new_full(client, test_executor(), DenyUnsafe::No, None); + let (client, _child) = new_full(client, test_executor(), DenyUnsafe::No); use jsonrpsee::{core::Error, types::error::CallError}; @@ -207,7 +207,7 @@ async fn should_call_contract() { async fn should_notify_about_storage_changes() { let mut sub = { let mut client = Arc::new(substrate_test_runtime_client::new()); - let (api, _child) = new_full(client.clone(), test_executor(), DenyUnsafe::No, None); + let (api, _child) = new_full(client.clone(), test_executor(), DenyUnsafe::No); let api_rpc = api.into_rpc(); let sub = api_rpc.subscribe("state_subscribeStorage", EmptyParams::new()).await.unwrap(); @@ -239,7 +239,7 @@ async fn should_notify_about_storage_changes() { async fn should_send_initial_storage_changes_and_notifications() { let mut sub = { let mut client = Arc::new(substrate_test_runtime_client::new()); - let (api, _child) = new_full(client.clone(), test_executor(), DenyUnsafe::No, None); + let (api, _child) = new_full(client.clone(), test_executor(), DenyUnsafe::No); let alice_balance_key = blake2_256(&runtime::system::balance_of_key(AccountKeyring::Alice.into())); @@ -275,7 +275,7 @@ async fn should_send_initial_storage_changes_and_notifications() { #[tokio::test] async fn should_query_storage() { async fn run_tests(mut client: Arc) { - let (api, _child) = new_full(client.clone(), test_executor(), DenyUnsafe::No, None); + let (api, _child) = new_full(client.clone(), test_executor(), DenyUnsafe::No); let mut add_block = |nonce| { let mut builder = client.new_block(Default::default()).unwrap(); @@ -477,7 +477,7 @@ async fn should_query_storage() { #[tokio::test] async fn should_return_runtime_version() { let client = Arc::new(substrate_test_runtime_client::new()); - let (api, _child) = new_full(client.clone(), test_executor(), DenyUnsafe::No, None); + let (api, _child) = new_full(client.clone(), test_executor(), DenyUnsafe::No); let result = "{\"specName\":\"test\",\"implName\":\"parity-test\",\"authoringVersion\":1,\ \"specVersion\":2,\"implVersion\":2,\"apis\":[[\"0xdf6acb689907609b\",4],\ @@ -498,7 +498,7 @@ async fn should_return_runtime_version() { async fn should_notify_on_runtime_version_initially() { let mut sub = { let client = Arc::new(substrate_test_runtime_client::new()); - let (api, _child) = new_full(client, test_executor(), DenyUnsafe::No, None); + let (api, _child) = new_full(client, test_executor(), DenyUnsafe::No); let api_rpc = api.into_rpc(); let sub = api_rpc @@ -527,7 +527,7 @@ fn should_deserialize_storage_key() { #[tokio::test] async fn wildcard_storage_subscriptions_are_rpc_unsafe() { let client = Arc::new(substrate_test_runtime_client::new()); - let (api, _child) = new_full(client, test_executor(), DenyUnsafe::Yes, None); + let (api, _child) = new_full(client, test_executor(), DenyUnsafe::Yes); let api_rpc = api.into_rpc(); let err = api_rpc.subscribe("state_subscribeStorage", EmptyParams::new()).await; @@ -537,7 +537,7 @@ async fn wildcard_storage_subscriptions_are_rpc_unsafe() { #[tokio::test] async fn concrete_storage_subscriptions_are_rpc_safe() { let client = Arc::new(substrate_test_runtime_client::new()); - let (api, _child) = new_full(client, test_executor(), DenyUnsafe::Yes, None); + let (api, _child) = new_full(client, test_executor(), DenyUnsafe::Yes); let api_rpc = api.into_rpc(); let key = StorageKey(STORAGE_KEY.to_vec()); diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 3cb064ec814c5..0547a2a19e87f 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -663,12 +663,8 @@ where let (chain, state, child_state) = { let chain = sc_rpc::chain::new_full(client.clone(), task_executor.clone()).into_rpc(); - let (state, child_state) = sc_rpc::state::new_full( - client.clone(), - task_executor.clone(), - deny_unsafe, - config.rpc_max_payload, - ); + let (state, child_state) = + sc_rpc::state::new_full(client.clone(), task_executor.clone(), deny_unsafe); let state = state.into_rpc(); let child_state = child_state.into_rpc(); diff --git a/client/service/src/config.rs b/client/service/src/config.rs index bca0697bcbd08..048a78fcd1bd7 100644 --- a/client/service/src/config.rs +++ b/client/service/src/config.rs @@ -87,23 +87,17 @@ pub struct Configuration { pub wasm_runtime_overrides: Option, /// Execution strategies. pub execution_strategies: ExecutionStrategies, - /// RPC over HTTP binding address. `None` if disabled. - pub rpc_http: Option, - /// RPC over Websockets binding address. `None` if disabled. - pub rpc_ws: Option, - /// RPC over IPC binding path. `None` if disabled. - pub rpc_ipc: Option, - /// Maximum number of connections for WebSockets RPC server. `None` if default. - pub rpc_ws_max_connections: Option, + /// JSON-RPC server binding address. `None` if disabled. + pub rpc_addr: Option, + /// Maximum number of connections for JSON-RPC server. `None` if default. + pub rpc_max_connections: Option, /// CORS settings for HTTP & WS servers. `None` if all origins are allowed. pub rpc_cors: Option>, /// RPC methods to expose (by default only a safe subset or all of them). pub rpc_methods: RpcMethods, - /// Maximum payload of rpc request/responses. - pub rpc_max_payload: Option, /// Maximum payload of a rpc request pub rpc_max_request_size: Option, - /// Maximum payload of a rpc request + /// Maximum payload of a rpc response. pub rpc_max_response_size: Option, /// Custom JSON-RPC subscription ID provider. /// @@ -113,8 +107,6 @@ pub struct Configuration { /// /// Default: 1024. pub rpc_max_subs_per_conn: Option, - /// Maximum size of the output buffer capacity for websocket connections. - pub ws_max_out_buffer_capacity: Option, /// Prometheus endpoint configuration. `None` if disabled. pub prometheus_config: Option, /// Telemetry service URL. `None` if disabled. diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index e330f80e5604f..ad4e325bf5f52 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -314,8 +314,6 @@ fn start_rpc_servers( where R: Fn(sc_rpc::DenyUnsafe) -> Result, Error>, { - let (max_request_size, ws_max_response_size, _) = legacy_cli_parsing(config); - fn deny_unsafe(addr: SocketAddr, methods: &RpcMethods) -> sc_rpc::DenyUnsafe { let is_exposed_addr = !addr.ip().is_loopback(); match (is_exposed_addr, methods) { @@ -330,28 +328,26 @@ where }; let addr = config - .rpc_ws + .rpc_addr .unwrap_or_else(|| "127.0.0.1:9944".parse().expect("valid sockaddr; qed")); let addr2 = random_port(addr); let metrics = sc_rpc_server::RpcMetrics::new(config.prometheus_registry())?; let server_config = sc_rpc_server::Config { - max_connections: config.rpc_ws_max_connections, - max_payload_in_mb: max_request_size, - max_payload_out_mb: ws_max_response_size, + addrs: [addr, addr2], + max_connections: config.rpc_max_connections, + max_payload_in_mb: config.rpc_max_request_size, + max_payload_out_mb: config.rpc_max_response_size, max_subs_per_conn: config.rpc_max_subs_per_conn, + rpc_api: gen_rpc_module(deny_unsafe(addr, &config.rpc_methods))?, + metrics, + id_provider: rpc_id_provider, + cors: config.rpc_cors.as_ref(), + tokio_handle: config.tokio_handle.clone(), }; - let server_fut = sc_rpc_server::start_server( - [addr, addr2], - config.rpc_cors.as_ref(), - server_config, - metrics, - gen_rpc_module(deny_unsafe(addr, &config.rpc_methods))?, - config.tokio_handle.clone(), - rpc_id_provider, - ); + let server_fut = sc_rpc_server::start_server(server_config); match tokio::task::block_in_place(|| config.tokio_handle.block_on(server_fut)) { Ok(server) => Ok(Box::new(waiting::Server(Some(server)))), @@ -458,51 +454,6 @@ where } } -fn legacy_cli_parsing(config: &Configuration) -> (Option, Option, Option) { - let ws_max_response_size = match ( - config.ws_max_out_buffer_capacity, - config.rpc_max_response_size, - ) { - (Some(legacy_max), max) => { - eprintln!("DEPRECATED: `--ws_max_out_buffer_capacity` has been removed; use `rpc-max-response-size or rpc-max-request-size` instead"); - eprintln!("Setting WS `rpc-max-response-size` to `max(ws_max_out_buffer_capacity, rpc_max_response_size)`"); - Some(std::cmp::max(legacy_max, max.unwrap_or(0))) - }, - (None, Some(m)) => Some(m), - (None, None) => None, - }; - - let max_request_size = match (config.rpc_max_payload, config.rpc_max_request_size) { - (Some(legacy_max), max) => { - eprintln!("DEPRECATED: `--rpc_max_payload` has been removed use `rpc-max-response-size or rpc-max-request-size` instead"); - eprintln!( - "Setting `rpc-max-response-size` to `max(rpc_max_payload, rpc_max_request_size)`" - ); - Some(std::cmp::max(legacy_max, max.unwrap_or(0))) - }, - (None, Some(max)) => Some(max), - (None, None) => None, - }; - - let http_max_response_size = match (config.rpc_max_payload, config.rpc_max_response_size) { - (Some(legacy_max), max) => { - eprintln!("DEPRECATED: `--rpc_max_payload` has been removed use `rpc-max-response-size or rpc-max-request-size` instead"); - eprintln!( - "Setting HTTP `rpc-max-response-size` to `max(rpc_max_payload, rpc_max_response_size)`" - ); - Some(std::cmp::max(legacy_max, max.unwrap_or(0))) - }, - (None, Some(max)) => Some(max), - (None, None) => None, - }; - - if config.rpc_ipc.is_some() { - eprintln!("DEPRECATED: `--ipc-path` has no effect anymore IPC support has been removed"); - } - - (max_request_size, ws_max_response_size, http_max_response_size) -} - #[cfg(test)] mod tests { use super::*; diff --git a/client/service/test/src/lib.rs b/client/service/test/src/lib.rs index 5d29d34a3cbf2..daa69581692a9 100644 --- a/client/service/test/src/lib.rs +++ b/client/service/test/src/lib.rs @@ -239,18 +239,14 @@ fn node_config< wasm_method: sc_service::config::WasmExecutionMethod::Interpreted, wasm_runtime_overrides: Default::default(), execution_strategies: Default::default(), - rpc_http: None, - rpc_ipc: None, - rpc_ws: None, - rpc_ws_max_connections: None, + rpc_addr: None, + rpc_max_connections: None, rpc_cors: None, rpc_methods: Default::default(), - rpc_max_payload: None, rpc_max_request_size: None, rpc_max_response_size: None, rpc_id_provider: None, rpc_max_subs_per_conn: None, - ws_max_out_buffer_capacity: None, prometheus_config: None, telemetry_endpoints: None, default_heap_pages: None, diff --git a/client/tracing/src/block/mod.rs b/client/tracing/src/block/mod.rs index 63fd1de374cba..39753ef29dbfb 100644 --- a/client/tracing/src/block/mod.rs +++ b/client/tracing/src/block/mod.rs @@ -34,38 +34,21 @@ use tracing::{ use crate::{SpanDatum, TraceEvent, Values}; use sc_client_api::BlockBackend; -use sc_rpc_server::RPC_MAX_PAYLOAD_DEFAULT; use sp_api::{Core, Encode, Metadata, ProvideRuntimeApi}; use sp_blockchain::HeaderBackend; use sp_core::hexdisplay::HexDisplay; -use sp_rpc::tracing::{BlockTrace, Span, TraceBlockResponse, TraceError}; +use sp_rpc::tracing::{BlockTrace, Span, TraceBlockResponse}; use sp_runtime::{ generic::BlockId, traits::{Block as BlockT, Header}, }; use sp_tracing::{WASM_NAME_KEY, WASM_TARGET_KEY, WASM_TRACE_IDENTIFIER}; -// Heuristic for average event size in bytes. -const AVG_EVENT: usize = 600 * 8; -// Heuristic for average span size in bytes. -const AVG_SPAN: usize = 100 * 8; -// Estimate of the max base RPC payload size when the Id is bound as a u64. If strings -// are used for the RPC Id this may need to be adjusted. Note: The base payload -// does not include the RPC result. -// -// The estimate is based on the JSON-RPC response message which has the following format: -// `{"jsonrpc":"2.0","result":[],"id":18446744073709551615}`. -// -// We care about the total size of the payload because jsonrpc-server will simply ignore -// messages larger than `sc_rpc_server::MAX_PAYLOAD` and the caller will not get any -// response. -const BASE_PAYLOAD: usize = 100; // Default to only pallet, frame support and state related traces const DEFAULT_TARGETS: &str = "pallet,frame,state"; const TRACE_TARGET: &str = "block_trace"; // The name of a field required for all events. const REQUIRED_EVENT_FIELD: &str = "method"; -const MEGABYTE: usize = 1024 * 1024; /// Tracing Block Result type alias pub type TraceBlockResult = Result; @@ -182,7 +165,6 @@ pub struct BlockExecutor { targets: Option, storage_keys: Option, methods: Option, - rpc_max_payload: usize, } impl BlockExecutor @@ -203,12 +185,8 @@ where targets: Option, storage_keys: Option, methods: Option, - rpc_max_payload: Option, ) -> Self { - let rpc_max_payload = rpc_max_payload - .map(|mb| mb.saturating_mul(MEGABYTE)) - .unwrap_or(RPC_MAX_PAYLOAD_DEFAULT); - Self { client, block, targets, storage_keys, methods, rpc_max_payload } + Self { client, block, targets, storage_keys, methods } } /// Execute block, record all spans and events belonging to `Self::targets` @@ -291,22 +269,15 @@ where .collect(); tracing::debug!(target: "state_tracing", "Captured {} spans and {} events", spans.len(), events.len()); - let approx_payload_size = BASE_PAYLOAD + events.len() * AVG_EVENT + spans.len() * AVG_SPAN; - let response = if approx_payload_size > self.rpc_max_payload { - TraceBlockResponse::TraceError(TraceError { - error: "Payload likely exceeds max payload size of RPC server.".to_string(), - }) - } else { - TraceBlockResponse::BlockTrace(BlockTrace { - block_hash: block_id_as_string(id), - parent_hash: block_id_as_string(parent_id), - tracing_targets: targets.to_string(), - storage_keys: self.storage_keys.clone().unwrap_or_default(), - methods: self.methods.clone().unwrap_or_default(), - spans, - events, - }) - }; + let response = TraceBlockResponse::BlockTrace(BlockTrace { + block_hash: block_id_as_string(id), + parent_hash: block_id_as_string(parent_id), + tracing_targets: targets.to_string(), + storage_keys: self.storage_keys.clone().unwrap_or_default(), + methods: self.methods.clone().unwrap_or_default(), + spans, + events, + }); Ok(response) } From 20780024c93085c16a01133116afff463f330c26 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Tue, 3 Jan 2023 12:23:30 +0100 Subject: [PATCH 03/19] remove patch.crates-io --- Cargo.toml | 3 --- client/rpc-servers/src/lib.rs | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9d0e68bafe64d..8f55d8e527ecd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -321,6 +321,3 @@ inherits = "release" lto = "fat" # https://doc.rust-lang.org/rustc/codegen-options/index.html#codegen-units codegen-units = 1 - -[patch.crates-io] -jsonrpsee = { git = "https://github.com/paritytech/jsonrpsee", branch = "master" } diff --git a/client/rpc-servers/src/lib.rs b/client/rpc-servers/src/lib.rs index 9a0c60e8c3004..1594cc2995491 100644 --- a/client/rpc-servers/src/lib.rs +++ b/client/rpc-servers/src/lib.rs @@ -22,6 +22,7 @@ pub mod middleware; +use http::header::HeaderValue; use jsonrpsee::{ server::{ middleware::proxy_get_request::ProxyGetRequestLayer, AllowHosts, ServerBuilder, @@ -29,9 +30,8 @@ use jsonrpsee::{ }, RpcModule, }; -use http::header::HeaderValue; -use tower_http::cors::{AllowOrigin, CorsLayer}; use std::{error::Error as StdError, net::SocketAddr}; +use tower_http::cors::{AllowOrigin, CorsLayer}; pub use crate::middleware::RpcMetrics; pub use jsonrpsee::core::{ From 17e90a70621a7dc251c0a11c02a968f3a966df69 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Tue, 14 Feb 2023 09:45:11 +0100 Subject: [PATCH 04/19] fix bad merge --- client/cli/src/runner.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs index c7a6f1f3c0f99..a796bb030e7ee 100644 --- a/client/cli/src/runner.rs +++ b/client/cli/src/runner.rs @@ -341,18 +341,14 @@ mod tests { wasm_method: Default::default(), wasm_runtime_overrides: None, execution_strategies: Default::default(), - rpc_http: None, - rpc_ws: None, - rpc_ipc: None, - rpc_ws_max_connections: None, + rpc_addr: None, + rpc_max_connections: None, rpc_cors: None, rpc_methods: Default::default(), - rpc_max_payload: None, rpc_max_request_size: None, rpc_max_response_size: None, rpc_id_provider: None, rpc_max_subs_per_conn: None, - ws_max_out_buffer_capacity: None, prometheus_config: None, telemetry_endpoints: None, default_heap_pages: None, From 10d60cc9a36fa10248c45a3aab8ecaf64f5edb7b Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Tue, 14 Feb 2023 17:39:44 +0100 Subject: [PATCH 05/19] fix clippy --- client/rpc-servers/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/rpc-servers/src/lib.rs b/client/rpc-servers/src/lib.rs index 1594cc2995491..54ee4c56d957f 100644 --- a/client/rpc-servers/src/lib.rs +++ b/client/rpc-servers/src/lib.rs @@ -77,8 +77,8 @@ pub struct Config<'a, M: Send + Sync + 'static> { } /// Start RPC server listening on given address. -pub async fn start_server<'a, M: Send + Sync + 'static>( - config: Config<'a, M>, +pub async fn start_server( + config: Config<'_, M>, ) -> Result> { let Config { addrs, From fb0ac35779d308aa082b695cbaff7fb9860d68cb Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Mon, 20 Mar 2023 11:47:07 +0100 Subject: [PATCH 06/19] fix bad merge --- client/tracing/src/block/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/tracing/src/block/mod.rs b/client/tracing/src/block/mod.rs index f18c914ec3244..c0442abc125b9 100644 --- a/client/tracing/src/block/mod.rs +++ b/client/tracing/src/block/mod.rs @@ -269,7 +269,7 @@ where Ok(TraceBlockResponse::BlockTrace(BlockTrace { block_hash: block_id_as_string(BlockId::::Hash(self.block)), - parent_hash: block_id_as_string(parent_id), + parent_hash: block_id_as_string(BlockId::::Hash(parent_hash)), tracing_targets: targets.to_string(), storage_keys: self.storage_keys.clone().unwrap_or_default(), methods: self.methods.clone().unwrap_or_default(), From 160e4922a553ca96da1ff7b5215b01be5ce0a94e Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Thu, 30 Mar 2023 11:32:48 +0200 Subject: [PATCH 07/19] fix grumbles --- client/cli/src/commands/run_cmd.rs | 2 +- client/service/src/lib.rs | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/client/cli/src/commands/run_cmd.rs b/client/cli/src/commands/run_cmd.rs index 93c6811899eb2..18575a56f6bea 100644 --- a/client/cli/src/commands/run_cmd.rs +++ b/client/cli/src/commands/run_cmd.rs @@ -106,7 +106,7 @@ pub struct RunCmd { #[arg(long, value_name = "PORT")] pub rpc_port: Option, - /// Maximum number of WS RPC server connections. + /// Maximum number of RPC server connections. #[arg(long, value_name = "COUNT")] pub rpc_max_connections: Option, diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index 4c32f4a297621..6e5516d04c47a 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -380,7 +380,8 @@ where } } - let random_port = |mut addr: SocketAddr| { + // if binding the specified port failed then a random port is assigned by the OS. + let backup_port = |mut addr: SocketAddr| { addr.set_port(0); addr }; @@ -388,12 +389,11 @@ where let addr = config .rpc_addr .unwrap_or_else(|| "127.0.0.1:9944".parse().expect("valid sockaddr; qed")); - let addr2 = random_port(addr); - + let backup_addr = backup_port(addr); let metrics = sc_rpc_server::RpcMetrics::new(config.prometheus_registry())?; let server_config = sc_rpc_server::Config { - addrs: [addr, addr2], + addrs: [addr, backup_addr], max_connections: config.rpc_max_connections, max_payload_in_mb: config.rpc_max_request_size, max_payload_out_mb: config.rpc_max_response_size, @@ -406,7 +406,6 @@ where }; let server_fut = sc_rpc_server::start_server(server_config); - match tokio::task::block_in_place(|| config.tokio_handle.block_on(server_fut)) { Ok(server) => Ok(Box::new(waiting::Server(Some(server)))), Err(e) => Err(Error::Application(e)), From ecace8e5a940337770371a890aaec0511b3b89be Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Thu, 30 Mar 2023 16:17:54 +0200 Subject: [PATCH 08/19] Update client/service/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- client/service/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index 6e5516d04c47a..6cb9e32736a2b 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -406,7 +406,7 @@ where }; let server_fut = sc_rpc_server::start_server(server_config); - match tokio::task::block_in_place(|| config.tokio_handle.block_on(server_fut)) { + match config.tokio_handle.block_on(server_fut) { Ok(server) => Ok(Box::new(waiting::Server(Some(server)))), Err(e) => Err(Error::Application(e)), } From 0d6760a8c47c19e316eeb8ffc918f7e7e86b979b Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Thu, 30 Mar 2023 23:31:54 +0200 Subject: [PATCH 09/19] revert block_in_place --- client/service/src/lib.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index 6cb9e32736a2b..6ef995f2ce3b1 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -405,8 +405,19 @@ where tokio_handle: config.tokio_handle.clone(), }; - let server_fut = sc_rpc_server::start_server(server_config); - match config.tokio_handle.block_on(server_fut) { + // `block_in_place` is basically a hack to allow callers of this method to call `block_on`. + // It's currently used in tests and could end up with a scenario as: + // + // async f() { + // Handle::current().block_on(time::sleep(Duration::from_millis(10))); + // 1 + // } + // + // rt.block_on(f()); + // + match tokio::task::block_in_place(|| { + config.tokio_handle.block_on(sc_rpc_server::start_server(server_config)) + }) { Ok(server) => Ok(Box::new(waiting::Server(Some(server)))), Err(e) => Err(Error::Application(e)), } From 226a8eacca100bbf8f13f2532da9dcfcebbfedcf Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Fri, 31 Mar 2023 09:23:06 +0200 Subject: [PATCH 10/19] add issue link in todo --- client/service/src/lib.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index 6ef995f2ce3b1..58190c6b742b8 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -405,16 +405,10 @@ where tokio_handle: config.tokio_handle.clone(), }; - // `block_in_place` is basically a hack to allow callers of this method to call `block_on`. - // It's currently used in tests and could end up with a scenario as: - // - // async f() { - // Handle::current().block_on(time::sleep(Duration::from_millis(10))); - // 1 - // } - // - // rt.block_on(f()); + // TODO: https://github.com/paritytech/substrate/issues/13773 // + // `block_in_place` is a hack to allow callers to call `block_on` prior to + // calling `start_rpc_servers`. match tokio::task::block_in_place(|| { config.tokio_handle.block_on(sc_rpc_server::start_server(server_config)) }) { From c6934d11209b34b8010f3c3f3b8906cd785b33b0 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Wed, 12 Apr 2023 10:53:14 +0200 Subject: [PATCH 11/19] Update client/cli/src/config.rs Co-authored-by: Dmitry Markin --- client/cli/src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cli/src/config.rs b/client/cli/src/config.rs index ec48065bcfb00..5f7c39c9c0353 100644 --- a/client/cli/src/config.rs +++ b/client/cli/src/config.rs @@ -310,7 +310,7 @@ pub trait CliConfiguration: Sized { Ok(Default::default()) } - /// Get the RPC websockets maximum connections (`None` if unlimited). + /// Get the maximum number of RPC server connections (`None` if unlimited). /// /// By default this is `None`. fn rpc_max_connections(&self) -> Result> { From 3a0b1ece6c4e36055d666896c29d1da55ffa1c4f Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Wed, 12 Apr 2023 11:12:50 +0200 Subject: [PATCH 12/19] grumbles: add ipv6 loopback address --- client/rpc-servers/src/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/client/rpc-servers/src/lib.rs b/client/rpc-servers/src/lib.rs index d7de37f02ed93..b9a96e63ff045 100644 --- a/client/rpc-servers/src/lib.rs +++ b/client/rpc-servers/src/lib.rs @@ -141,10 +141,13 @@ pub async fn start_server( fn hosts_filtering(enabled: bool, addrs: &[SocketAddr]) -> AllowHosts { if enabled { // NOTE The listening addresses are whitelisted by default. - let mut hosts = Vec::with_capacity(addrs.len() * 2); + let mut hosts = Vec::with_capacity(addrs.len() * 3); for addr in addrs { - hosts.push(format!("localhost:{}", addr.port()).into()); - hosts.push(format!("127.0.0.1:{}", addr.port()).into()); + let port = addr.port(); + + hosts.push(format!("localhost:{port}").into()); + hosts.push(format!("127.0.0.1:{port}").into()); + hosts.push(format!("[::1]:{port}").into()); } AllowHosts::Only(hosts) } else { From 7856c92eb2fcb270e152d3e9c1f4a8861298bba4 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Wed, 12 Apr 2023 13:11:39 +0200 Subject: [PATCH 13/19] Revert "grumbles: add ipv6 loopback address" This reverts commit 3a0b1ece6c4e36055d666896c29d1da55ffa1c4f. --- client/rpc-servers/src/lib.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/client/rpc-servers/src/lib.rs b/client/rpc-servers/src/lib.rs index b9a96e63ff045..d7de37f02ed93 100644 --- a/client/rpc-servers/src/lib.rs +++ b/client/rpc-servers/src/lib.rs @@ -141,13 +141,10 @@ pub async fn start_server( fn hosts_filtering(enabled: bool, addrs: &[SocketAddr]) -> AllowHosts { if enabled { // NOTE The listening addresses are whitelisted by default. - let mut hosts = Vec::with_capacity(addrs.len() * 3); + let mut hosts = Vec::with_capacity(addrs.len() * 2); for addr in addrs { - let port = addr.port(); - - hosts.push(format!("localhost:{port}").into()); - hosts.push(format!("127.0.0.1:{port}").into()); - hosts.push(format!("[::1]:{port}").into()); + hosts.push(format!("localhost:{}", addr.port()).into()); + hosts.push(format!("127.0.0.1:{}", addr.port()).into()); } AllowHosts::Only(hosts) } else { From be0485c476e096d2e9a5e0dca7662da891b03b71 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Wed, 12 Apr 2023 15:18:46 +0200 Subject: [PATCH 14/19] remove nits --- client/cli/src/commands/run_cmd.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/cli/src/commands/run_cmd.rs b/client/cli/src/commands/run_cmd.rs index 18575a56f6bea..9aa1f7f341226 100644 --- a/client/cli/src/commands/run_cmd.rs +++ b/client/cli/src/commands/run_cmd.rs @@ -69,7 +69,7 @@ pub struct RunCmd { /// /// - `unsafe`: Exposes every RPC method. /// - `safe`: Exposes only a safe subset of RPC methods, denying unsafe RPC methods. - /// - `auto`: Acts as `safe` if RPC is served externally, e.g. when `--{rpc,ws}-external` is + /// - `auto`: Acts as `safe` if RPC is served externally, e.g. when `--rpc--external` is /// passed, otherwise acts as `unsafe`. #[arg( long, @@ -470,7 +470,7 @@ fn rpc_interface( ) -> Result { if is_external && is_validator && rpc_methods != RpcMethods::Unsafe { return Err(Error::Input( - "--rpc-external and --ws-external options shouldn't be used if the node is running as \ + "--rpc-external option shouldn't be used if the node is running as \ a validator. Use `--unsafe-rpc-external` or `--rpc-methods=unsafe` if you understand \ the risks. See the options description for more information." .to_owned(), From cdc97ded37db8e8b4560f01d5a72b5f6fdd93d65 Mon Sep 17 00:00:00 2001 From: Javier Viola Date: Tue, 2 May 2023 11:38:20 -0300 Subject: [PATCH 15/19] bump zombienet version --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 100dd0d3d3ed9..654302de5aae4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -57,7 +57,7 @@ variables: RUSTY_CACHIER_COMPRESSION_METHOD: zstd NEXTEST_FAILURE_OUTPUT: immediate-final NEXTEST_SUCCESS_OUTPUT: final - ZOMBIENET_IMAGE: "docker.io/paritytech/zombienet:v1.3.43" + ZOMBIENET_IMAGE: "docker.io/paritytech/zombienet:v1.3.45" default: retry: From c2a9a0d3cc38c4eedd7e3421569dbc12ee25b367 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Tue, 2 May 2023 17:35:16 +0200 Subject: [PATCH 16/19] adress grumbles: provide structopt default_val_t --- bin/node/cli/benches/block_production.rs | 10 +++---- bin/node/cli/benches/transaction_pool.rs | 10 +++---- client/cli/src/commands/run_cmd.rs | 33 ++++++++++++------------ client/cli/src/config.rs | 24 +++++++---------- client/cli/src/runner.rs | 10 +++---- client/rpc-servers/src/lib.rs | 29 ++++++--------------- client/service/src/config.rs | 14 +++++----- client/service/src/lib.rs | 4 +-- client/service/test/src/lib.rs | 12 ++++----- 9 files changed, 62 insertions(+), 84 deletions(-) diff --git a/bin/node/cli/benches/block_production.rs b/bin/node/cli/benches/block_production.rs index 9125cb93a837f..36e8076925ebc 100644 --- a/bin/node/cli/benches/block_production.rs +++ b/bin/node/cli/benches/block_production.rs @@ -85,13 +85,13 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase { other: execution_strategy, }, rpc_addr: None, - rpc_max_connections: None, + rpc_max_connections: Default::default(), rpc_cors: None, rpc_methods: Default::default(), - rpc_max_request_size: None, - rpc_max_response_size: None, - rpc_id_provider: None, - rpc_max_subs_per_conn: None, + rpc_max_request_size: Default::default(), + rpc_max_response_size: Default::default(), + rpc_id_provider: Default::default(), + rpc_max_subs_per_conn: Default::default(), prometheus_config: None, telemetry_endpoints: None, default_heap_pages: None, diff --git a/bin/node/cli/benches/transaction_pool.rs b/bin/node/cli/benches/transaction_pool.rs index 830467b83701c..14d99c37a4a33 100644 --- a/bin/node/cli/benches/transaction_pool.rs +++ b/bin/node/cli/benches/transaction_pool.rs @@ -79,13 +79,13 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase { other: sc_client_api::ExecutionStrategy::NativeWhenPossible, }, rpc_addr: None, - rpc_max_connections: None, + rpc_max_connections: Default::default(), rpc_cors: None, rpc_methods: Default::default(), - rpc_max_request_size: None, - rpc_max_response_size: None, - rpc_id_provider: None, - rpc_max_subs_per_conn: None, + rpc_max_request_size: Default::default(), + rpc_max_response_size: Default::default(), + rpc_id_provider: Default::default(), + rpc_max_subs_per_conn: Default::default(), prometheus_config: None, telemetry_endpoints: None, default_heap_pages: None, diff --git a/client/cli/src/commands/run_cmd.rs b/client/cli/src/commands/run_cmd.rs index a0b0a6cf3eab8..e1f2298679736 100644 --- a/client/cli/src/commands/run_cmd.rs +++ b/client/cli/src/commands/run_cmd.rs @@ -79,26 +79,25 @@ pub struct RunCmd { /// Set the the maximum RPC request payload size for both HTTP and WS in megabytes. /// Default is 15MiB. - #[arg(long)] - pub rpc_max_request_size: Option, + #[arg(long, default_value_t = 15)] + pub rpc_max_request_size: u32, /// Set the the maximum RPC response payload size for both HTTP and WS in megabytes. /// Default is 15MiB. - #[arg(long)] - pub rpc_max_response_size: Option, + #[arg(long, default_value_t = 15)] + pub rpc_max_response_size: u32, /// Set the the maximum concurrent subscriptions per connection. - /// Default is 1024. - #[arg(long)] - pub rpc_max_subscriptions_per_connection: Option, + #[arg(long, default_value_t = 1024)] + pub rpc_max_subscriptions_per_connection: u32, /// Specify JSON-RPC server TCP port. - #[arg(long, value_name = "PORT")] - pub rpc_port: Option, + #[arg(long, value_name = "PORT", default_value_t = 9944)] + pub rpc_port: u16, /// Maximum number of RPC server connections. - #[arg(long, value_name = "COUNT")] - pub rpc_max_connections: Option, + #[arg(long, value_name = "COUNT", default_value_t = 100)] + pub rpc_max_connections: u32, /// Specify browser Origins allowed to access the HTTP & WS RPC servers. /// A comma-separated list of origins (protocol://domain or special `null` @@ -314,7 +313,7 @@ impl CliConfiguration for RunCmd { Ok(self.no_grandpa) } - fn rpc_max_connections(&self) -> Result> { + fn rpc_max_connections(&self) -> Result { Ok(self.rpc_max_connections) } @@ -339,7 +338,7 @@ impl CliConfiguration for RunCmd { .into()) } - fn rpc_addr(&self, default_listen_port: u16) -> Result> { + fn rpc_addr(&self, _default_listen_port: u16) -> Result> { let interface = rpc_interface( self.rpc_external, self.unsafe_rpc_external, @@ -347,22 +346,22 @@ impl CliConfiguration for RunCmd { self.validator, )?; - Ok(Some(SocketAddr::new(interface, self.rpc_port.unwrap_or(default_listen_port)))) + Ok(Some(SocketAddr::new(interface, self.rpc_port))) } fn rpc_methods(&self) -> Result { Ok(self.rpc_methods.into()) } - fn rpc_max_request_size(&self) -> Result> { + fn rpc_max_request_size(&self) -> Result { Ok(self.rpc_max_request_size) } - fn rpc_max_response_size(&self) -> Result> { + fn rpc_max_response_size(&self) -> Result { Ok(self.rpc_max_response_size) } - fn rpc_max_subscriptions_per_connection(&self) -> Result> { + fn rpc_max_subscriptions_per_connection(&self) -> Result { Ok(self.rpc_max_subscriptions_per_connection) } diff --git a/client/cli/src/config.rs b/client/cli/src/config.rs index 5f7c39c9c0353..92b1eea7ae266 100644 --- a/client/cli/src/config.rs +++ b/client/cli/src/config.rs @@ -295,9 +295,7 @@ pub trait CliConfiguration: Sized { .unwrap_or_default()) } - /// Get the RPC address (`None` if disabled). - /// - /// By default this is `None`. + /// Get the RPC address. fn rpc_addr(&self, _default_listen_port: u16) -> Result> { Ok(None) } @@ -310,11 +308,9 @@ pub trait CliConfiguration: Sized { Ok(Default::default()) } - /// Get the maximum number of RPC server connections (`None` if unlimited). - /// - /// By default this is `None`. - fn rpc_max_connections(&self) -> Result> { - Ok(None) + /// Get the maximum number of RPC server connections. + fn rpc_max_connections(&self) -> Result { + Ok(Default::default()) } /// Get the RPC cors (`None` if disabled) @@ -325,18 +321,18 @@ pub trait CliConfiguration: Sized { } /// Get maximum RPC request payload size. - fn rpc_max_request_size(&self) -> Result> { - Ok(None) + fn rpc_max_request_size(&self) -> Result { + Ok(Default::default()) } /// Get maximum RPC response payload size. - fn rpc_max_response_size(&self) -> Result> { - Ok(None) + fn rpc_max_response_size(&self) -> Result { + Ok(Default::default()) } /// Get maximum number of subscriptions per connection. - fn rpc_max_subscriptions_per_connection(&self) -> Result> { - Ok(None) + fn rpc_max_subscriptions_per_connection(&self) -> Result { + Ok(Default::default()) } /// Get the prometheus configuration (`None` if disabled) diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs index 0ac685c4bfea1..9db078046e3c5 100644 --- a/client/cli/src/runner.rs +++ b/client/cli/src/runner.rs @@ -288,13 +288,13 @@ mod tests { wasm_runtime_overrides: None, execution_strategies: Default::default(), rpc_addr: None, - rpc_max_connections: None, + rpc_max_connections: Default::default(), rpc_cors: None, rpc_methods: Default::default(), - rpc_max_request_size: None, - rpc_max_response_size: None, - rpc_id_provider: None, - rpc_max_subs_per_conn: None, + rpc_max_request_size: Default::default(), + rpc_max_response_size: Default::default(), + rpc_id_provider: Default::default(), + rpc_max_subs_per_conn: Default::default(), prometheus_config: None, telemetry_endpoints: None, default_heap_pages: None, diff --git a/client/rpc-servers/src/lib.rs b/client/rpc-servers/src/lib.rs index d7de37f02ed93..92b31937a0cbb 100644 --- a/client/rpc-servers/src/lib.rs +++ b/client/rpc-servers/src/lib.rs @@ -39,18 +39,11 @@ pub use jsonrpsee::core::{ traits::IdProvider, }; -/// Default maximum number of connections for JSON-RPC servers. -const RPC_MAX_CONNECTIONS: u32 = 100; -/// Default maximum number subscriptions per connection for JSON-RPC servers. -const RPC_MAX_SUBS_PER_CONN: u32 = 1024; const MEGABYTE: u32 = 1024 * 1024; /// Type alias for the JSON-RPC server. pub type Server = ServerHandle; -/// Maximal payload accepted by JSON-RPC servers. -pub const RPC_MAX_PAYLOAD_DEFAULT: u32 = 15 * MEGABYTE; - /// RPC server configuration. #[derive(Debug)] pub struct Config<'a, M: Send + Sync + 'static> { @@ -59,13 +52,13 @@ pub struct Config<'a, M: Send + Sync + 'static> { /// CORS. pub cors: Option<&'a Vec>, /// Maximum connections. - pub max_connections: Option, + pub max_connections: u32, /// Maximum subscriptions per connection. - pub max_subs_per_conn: Option, + pub max_subs_per_conn: u32, /// Maximum rpc request payload size. - pub max_payload_in_mb: Option, + pub max_payload_in_mb: u32, /// Maximum rpc response payload size. - pub max_payload_out_mb: Option, + pub max_payload_out_mb: u32, /// Metrics. pub metrics: Option, /// RPC API. @@ -101,12 +94,10 @@ pub async fn start_server( .layer(try_into_cors(cors)?); let mut builder = ServerBuilder::new() - .max_request_body_size(payload_size_or_default(max_payload_in_mb)) - .max_response_body_size(payload_size_or_default(max_payload_out_mb)) - .max_connections(max_connections.map_or(RPC_MAX_CONNECTIONS, |m| m as u32)) - .max_subscriptions_per_connection( - max_subs_per_conn.map_or(RPC_MAX_SUBS_PER_CONN, |m| m as u32), - ) + .max_request_body_size(max_payload_in_mb.saturating_mul(MEGABYTE)) + .max_response_body_size(max_payload_out_mb.saturating_mul(MEGABYTE)) + .max_connections(max_connections) + .max_subscriptions_per_connection(max_subs_per_conn) .ping_interval(std::time::Duration::from_secs(30)) .set_host_filtering(host_filter) .set_middleware(middleware) @@ -167,10 +158,6 @@ fn build_rpc_api(mut rpc_api: RpcModule) -> RpcModu rpc_api } -fn payload_size_or_default(size_mb: Option) -> u32 { - size_mb.map_or(RPC_MAX_PAYLOAD_DEFAULT, |mb| (mb as u32).saturating_mul(MEGABYTE)) -} - fn try_into_cors( maybe_cors: Option<&Vec>, ) -> Result> { diff --git a/client/service/src/config.rs b/client/service/src/config.rs index 636e8eb269fea..40f8c6a4f0445 100644 --- a/client/service/src/config.rs +++ b/client/service/src/config.rs @@ -83,26 +83,24 @@ pub struct Configuration { pub wasm_runtime_overrides: Option, /// Execution strategies. pub execution_strategies: ExecutionStrategies, - /// JSON-RPC server binding address. `None` if disabled. + /// JSON-RPC server binding address. pub rpc_addr: Option, - /// Maximum number of connections for JSON-RPC server. `None` if default. - pub rpc_max_connections: Option, + /// Maximum number of connections for JSON-RPC server. + pub rpc_max_connections: u32, /// CORS settings for HTTP & WS servers. `None` if all origins are allowed. pub rpc_cors: Option>, /// RPC methods to expose (by default only a safe subset or all of them). pub rpc_methods: RpcMethods, /// Maximum payload of a rpc request - pub rpc_max_request_size: Option, + pub rpc_max_request_size: u32, /// Maximum payload of a rpc response. - pub rpc_max_response_size: Option, + pub rpc_max_response_size: u32, /// Custom JSON-RPC subscription ID provider. /// /// Default: [`crate::RandomStringSubscriptionId`]. pub rpc_id_provider: Option>, /// Maximum allowed subscriptions per rpc connection - /// - /// Default: 1024. - pub rpc_max_subs_per_conn: Option, + pub rpc_max_subs_per_conn: u32, /// Prometheus endpoint configuration. `None` if disabled. pub prometheus_config: Option, /// Telemetry service URL. `None` if disabled. diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index 21d80cfad82b7..a5667717055b5 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -386,9 +386,7 @@ where addr }; - let addr = config - .rpc_addr - .unwrap_or_else(|| "127.0.0.1:9944".parse().expect("valid sockaddr; qed")); + let addr = config.rpc_addr.unwrap_or(([127, 0, 0, 1], 9944).into()); let backup_addr = backup_port(addr); let metrics = sc_rpc_server::RpcMetrics::new(config.prometheus_registry())?; diff --git a/client/service/test/src/lib.rs b/client/service/test/src/lib.rs index 8cbc126189d5b..0eb4489ad089a 100644 --- a/client/service/test/src/lib.rs +++ b/client/service/test/src/lib.rs @@ -246,14 +246,14 @@ fn node_config< wasm_method: Default::default(), wasm_runtime_overrides: Default::default(), execution_strategies: Default::default(), - rpc_addr: None, - rpc_max_connections: None, + rpc_addr: Default::default(), + rpc_max_connections: Default::default(), rpc_cors: None, rpc_methods: Default::default(), - rpc_max_request_size: None, - rpc_max_response_size: None, - rpc_id_provider: None, - rpc_max_subs_per_conn: None, + rpc_max_request_size: Default::default(), + rpc_max_response_size: Default::default(), + rpc_id_provider: Default::default(), + rpc_max_subs_per_conn: Default::default(), prometheus_config: None, telemetry_endpoints: None, default_heap_pages: None, From cee7789b9a558eebb1de39dfa836105243243518 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Tue, 2 May 2023 17:51:57 +0200 Subject: [PATCH 17/19] remove duplicate from structopt --- client/cli/src/commands/run_cmd.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/cli/src/commands/run_cmd.rs b/client/cli/src/commands/run_cmd.rs index e1f2298679736..8176643d73cd2 100644 --- a/client/cli/src/commands/run_cmd.rs +++ b/client/cli/src/commands/run_cmd.rs @@ -78,12 +78,10 @@ pub struct RunCmd { pub rpc_methods: RpcMethods, /// Set the the maximum RPC request payload size for both HTTP and WS in megabytes. - /// Default is 15MiB. #[arg(long, default_value_t = 15)] pub rpc_max_request_size: u32, /// Set the the maximum RPC response payload size for both HTTP and WS in megabytes. - /// Default is 15MiB. #[arg(long, default_value_t = 15)] pub rpc_max_response_size: u32, From 5b626032ef2a967b2daf1c4a41c3037045e49366 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Wed, 3 May 2023 10:10:42 +0200 Subject: [PATCH 18/19] bump zombienet v1.3.47 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 89b9a3613e8ba..51930ec2dd938 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -61,7 +61,7 @@ variables: NEXTEST_FAILURE_OUTPUT: immediate-final NEXTEST_SUCCESS_OUTPUT: final - ZOMBIENET_IMAGE: "docker.io/paritytech/zombienet:v1.3.45" + ZOMBIENET_IMAGE: "docker.io/paritytech/zombienet:v1.3.47" default: retry: From 9f1e259392825071d063e13f1ec928100ec575c4 Mon Sep 17 00:00:00 2001 From: Javier Viola Date: Wed, 3 May 2023 11:07:45 -0300 Subject: [PATCH 19/19] bump zombienet version --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 51930ec2dd938..b164c1de1544d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -61,7 +61,7 @@ variables: NEXTEST_FAILURE_OUTPUT: immediate-final NEXTEST_SUCCESS_OUTPUT: final - ZOMBIENET_IMAGE: "docker.io/paritytech/zombienet:v1.3.47" + ZOMBIENET_IMAGE: "docker.io/paritytech/zombienet:v1.3.48" default: retry: