From 20eddf267cc0fa5b82f7ff2cd3189194e44c4fbb Mon Sep 17 00:00:00 2001 From: Nacho Avecilla Date: Tue, 19 Mar 2024 17:00:52 -0300 Subject: [PATCH] Node state for the RPC server (#67) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What ❔ Make the `ReplicaState` struct and additional information about the node state available on the RPC server side. ## Why ❔ For future tests, it would be necessary to have access to the state of different running nodes in order to assess the behavior of the entire consensus network. This could involve getting different metrics such as the last saved view for each node, proposals, highest vote or quorum certificate (QC), etc. --- node/Cargo.lock | 262 +++++++++--------- node/tests/src/main.rs | 12 +- node/tools/src/bin/deployer.rs | 17 +- node/tools/src/k8s.rs | 4 +- node/tools/src/main.rs | 6 +- node/tools/src/rpc/methods/config.rs | 47 ---- node/tools/src/rpc/methods/health_check.rs | 31 +-- .../src/rpc/methods/last_commited_block.rs | 34 +++ node/tools/src/rpc/methods/last_view.rs | 34 +++ node/tools/src/rpc/methods/mod.rs | 16 +- node/tools/src/rpc/methods/peers.rs | 40 --- node/tools/src/rpc/server.rs | 56 ++-- 12 files changed, 266 insertions(+), 293 deletions(-) delete mode 100644 node/tools/src/rpc/methods/config.rs create mode 100644 node/tools/src/rpc/methods/last_commited_block.rs create mode 100644 node/tools/src/rpc/methods/last_view.rs delete mode 100644 node/tools/src/rpc/methods/peers.rs diff --git a/node/Cargo.lock b/node/Cargo.lock index 8f242b32..95ad4a8f 100644 --- a/node/Cargo.lock +++ b/node/Cargo.lock @@ -54,9 +54,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.9" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d713b3834d76b85304d4d525563c1276e2e30dc97cc67bfb4585a4a29fc2c89f" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", "getrandom", @@ -103,9 +103,9 @@ checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] name = "anstream" -version = "0.6.12" +version = "0.6.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96b09b5178381e0874812a9b157f7fe84982617e48f71f4e3235482775e5b540" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" dependencies = [ "anstyle", "anstyle-parse", @@ -169,7 +169,7 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -249,7 +249,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -355,10 +355,11 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.0.88" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02f341c093d19155a6e41631ce5971aac4e9a868262212153124c15fa22d1cdc" +checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" dependencies = [ + "jobserver", "libc", ] @@ -403,15 +404,15 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.34" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" +checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" dependencies = [ "android-tzdata", "iana-time-zone", "num-traits", "serde", - "windows-targets 0.52.3", + "windows-targets 0.52.4", ] [[package]] @@ -465,9 +466,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.1" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da" +checksum = "b230ab84b0ffdf890d5a10abdbc8b83ae1c4918275daea1ab8801f71536b2651" dependencies = [ "clap_builder", "clap_derive", @@ -475,9 +476,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.1" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" dependencies = [ "anstream", "anstyle", @@ -494,7 +495,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -657,7 +658,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -681,7 +682,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -692,7 +693,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ "darling_core", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -942,7 +943,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -998,9 +999,9 @@ dependencies = [ [[package]] name = "ghash" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d930750de5717d2dd0b8c0d42c076c0e884c81a73e6cab859bbd2339c71e3e40" +checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1" dependencies = [ "opaque-debug", "polyval", @@ -1065,9 +1066,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "379dada1584ad501b383485dd706b8afb7a70fcbc7f4da7d780638a5a6124a60" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "hex" @@ -1086,9 +1087,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" dependencies = [ "bytes", "fnv", @@ -1231,9 +1232,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.3" +version = "2.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177" +checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" dependencies = [ "equivalent", "hashbrown", @@ -1292,11 +1293,20 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +[[package]] +name = "jobserver" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" -version = "0.3.68" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] @@ -1517,7 +1527,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -1566,12 +1576,12 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "libloading" -version = "0.8.1" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" +checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-sys 0.48.0", + "windows-targets 0.52.4", ] [[package]] @@ -1603,22 +1613,22 @@ dependencies = [ [[package]] name = "linkme" -version = "0.3.23" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a78816ac097580aa7fd9d2e9cc7395dda34367c07267a8657516d4ad5e2e3d3" +checksum = "bb2cfee0de9bd869589fb9a015e155946d1be5ff415cb844c2caccc6cc4b5db9" dependencies = [ "linkme-impl", ] [[package]] name = "linkme-impl" -version = "0.3.23" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee9023a564f8bf7fe3da285a50c3e70de0df3e2bf277ff7c4e76d66008ef93b0" +checksum = "adf157a4dc5a29b7b464aa8fe7edeff30076e07e13646a1c3874f58477dc99f8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -1639,9 +1649,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "logos" @@ -1663,7 +1673,7 @@ dependencies = [ "proc-macro2", "quote", "regex-syntax 0.6.29", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -1720,7 +1730,7 @@ checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -1849,9 +1859,9 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" [[package]] name = "opaque-debug" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "openssl-probe" @@ -1933,9 +1943,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.7" +version = "2.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "219c0dcc30b6a27553f9cc242972b67f75b60eb0db71f0b5462f38b058c41546" +checksum = "56f8023d0fb78c8e03784ea1c7f3fa36e68a723138990b8d5a47d916b651e7a8" dependencies = [ "memchr", "thiserror", @@ -1944,9 +1954,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.7.7" +version = "2.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e1288dbd7786462961e69bfd4df7848c1e37e8b74303dbdab82c3a9cdd2809" +checksum = "b0d24f72393fd16ab6ac5738bc33cdb6a9aa73f8b902e8fe29cf4e67d7dd1026" dependencies = [ "pest", "pest_generator", @@ -1954,22 +1964,22 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.7" +version = "2.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1381c29a877c6d34b8c176e734f35d7f7f5b3adaefe940cb4d1bb7af94678e2e" +checksum = "fdc17e2a6c7d0a492f0158d7a4bd66cc17280308bbaff78d5bef566dca35ab80" dependencies = [ "pest", "pest_meta", "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] name = "pest_meta" -version = "2.7.7" +version = "2.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0934d6907f148c22a3acbda520c7eed243ad7487a30f51f6ce52b58b7077a8a" +checksum = "934cd7631c050f4674352a6e835d5f6711ffbfb9345c2fc0107155ac495ae293" dependencies = [ "once_cell", "pest", @@ -1988,22 +1998,22 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0302c4a0442c456bd56f841aee5c3bfd17967563f6fadc9ceb9f9c23cf3807e0" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -2081,9 +2091,9 @@ dependencies = [ [[package]] name = "polyval" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52cff9d1d4dee5fe6d03729099f4a310a41179e0a10dbf542039873f2e826fb" +checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25" dependencies = [ "cfg-if", "cpufeatures", @@ -2120,7 +2130,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" dependencies = [ "proc-macro2", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -2152,7 +2162,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -2182,7 +2192,7 @@ dependencies = [ "prost", "prost-types", "regex", - "syn 2.0.51", + "syn 2.0.52", "tempfile", "which", ] @@ -2197,7 +2207,7 @@ dependencies = [ "itertools 0.11.0", "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -2339,9 +2349,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7237101a77a10773db45d62004a272517633fbcc3df19d96455ede1122e051" +checksum = "e4963ed1bc86e4f3ee217022bd855b297cef07fb9eac5dfa1f788b220b49b3bd" dependencies = [ "either", "rayon-core", @@ -2383,7 +2393,7 @@ checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.5", + "regex-automata 0.4.6", "regex-syntax 0.8.2", ] @@ -2398,9 +2408,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ "aho-corasick", "memchr", @@ -2657,7 +2667,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -2882,9 +2892,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.51" +version = "2.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ab617d94515e94ae53b8406c628598680aa0c9587474ecbe58188f7b345d66c" +checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" dependencies = [ "proc-macro2", "quote", @@ -2905,22 +2915,22 @@ dependencies = [ [[package]] name = "test-casing" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2378d657757969a2cec9ec4eb616be8f01be98c21c6467991f91cb182e4653b" +checksum = "f4d233764420cbfe244e6a50177798a01b20184df210eb626898cd1b20c06633" dependencies = [ "test-casing-macro", ] [[package]] name = "test-casing-macro" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cfbe7811249c4c914b06141b8ac0f2cee2733fb883d05eb19668a45fc60c3d5" +checksum = "f9b53c7124dd88026d5d98a1eb1fd062a578b7d783017c9298825526c7fb6427" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -2954,7 +2964,7 @@ checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -3057,7 +3067,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -3167,7 +3177,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -3352,14 +3362,14 @@ source = "git+https://github.com/matter-labs/vise.git?rev=1c9cc500e92cf9ea052b23 dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] name = "walkdir" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" dependencies = [ "same-file", "winapi-util", @@ -3382,9 +3392,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -3392,24 +3402,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3417,28 +3427,28 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "web-sys" -version = "0.3.68" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96565907687f7aceb35bc5fc03770a8a0471d82e479f25832f54a0e3f4b28446" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" dependencies = [ "js-sys", "wasm-bindgen", @@ -3493,7 +3503,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.3", + "windows-targets 0.52.4", ] [[package]] @@ -3511,7 +3521,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.3", + "windows-targets 0.52.4", ] [[package]] @@ -3531,17 +3541,17 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.3" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d380ba1dc7187569a8a9e91ed34b8ccfc33123bbacb8c0aed2d1ad7f3ef2dc5f" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" dependencies = [ - "windows_aarch64_gnullvm 0.52.3", - "windows_aarch64_msvc 0.52.3", - "windows_i686_gnu 0.52.3", - "windows_i686_msvc 0.52.3", - "windows_x86_64_gnu 0.52.3", - "windows_x86_64_gnullvm 0.52.3", - "windows_x86_64_msvc 0.52.3", + "windows_aarch64_gnullvm 0.52.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", ] [[package]] @@ -3552,9 +3562,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.3" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68e5dcfb9413f53afd9c8f86e56a7b4d86d9a2fa26090ea2dc9e40fba56c6ec6" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" [[package]] name = "windows_aarch64_msvc" @@ -3564,9 +3574,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.3" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dab469ebbc45798319e69eebf92308e541ce46760b49b18c6b3fe5e8965b30f" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" [[package]] name = "windows_i686_gnu" @@ -3576,9 +3586,9 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.3" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a4e9b6a7cac734a8b4138a4e1044eac3404d8326b6c0f939276560687a033fb" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" [[package]] name = "windows_i686_msvc" @@ -3588,9 +3598,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.3" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b0ec9c422ca95ff34a78755cfa6ad4a51371da2a5ace67500cf7ca5f232c58" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" [[package]] name = "windows_x86_64_gnu" @@ -3600,9 +3610,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.3" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "704131571ba93e89d7cd43482277d6632589b18ecf4468f591fbae0a8b101614" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" [[package]] name = "windows_x86_64_gnullvm" @@ -3612,9 +3622,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.3" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42079295511643151e98d61c38c0acc444e52dd42ab456f7ccfd5152e8ecf21c" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" [[package]] name = "windows_x86_64_msvc" @@ -3624,9 +3634,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.3" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0770833d60a970638e989b3fa9fd2bb1aaadcf88963d1659fd7d9990196ed2d6" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" [[package]] name = "yansi" @@ -3651,7 +3661,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -3671,7 +3681,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] @@ -3914,7 +3924,7 @@ dependencies = [ "prost-reflect", "protox", "quote", - "syn 2.0.51", + "syn 2.0.52", ] [[package]] diff --git a/node/tests/src/main.rs b/node/tests/src/main.rs index 46bebaec..1436dada 100644 --- a/node/tests/src/main.rs +++ b/node/tests/src/main.rs @@ -1,12 +1,9 @@ //! This is a simple test for the RPC server. It checks if the server is running and can respond to. use anyhow::{ensure, Context}; use clap::{Parser, Subcommand}; -use jsonrpsee::{core::client::ClientT, http_client::HttpClientBuilder, rpc_params, types::Params}; +use jsonrpsee::{core::client::ClientT, http_client::HttpClientBuilder, rpc_params}; use std::{fs, io::Write, net::SocketAddr, path::PathBuf, str::FromStr}; -use zksync_consensus_tools::{ - k8s, - rpc::methods::{health_check::HealthCheck, RPCMethod}, -}; +use zksync_consensus_tools::{k8s, rpc::methods::health_check}; /// Command line arguments. #[derive(Debug, Parser)] @@ -80,12 +77,11 @@ pub async fn sanity_test() { let socket = SocketAddr::from_str(socket).unwrap(); let url = format!("http://{}", socket); let rpc_client = HttpClientBuilder::default().build(url).unwrap(); - let params = Params::new(None); let response: serde_json::Value = rpc_client - .request(HealthCheck::method(), rpc_params!()) + .request(health_check::method(), rpc_params!()) .await .unwrap(); - assert_eq!(response, HealthCheck::callback(params).unwrap()); + assert_eq!(response, health_check::callback().unwrap()); } } diff --git a/node/tools/src/bin/deployer.rs b/node/tools/src/bin/deployer.rs index 57a026f0..f8863a03 100644 --- a/node/tools/src/bin/deployer.rs +++ b/node/tools/src/bin/deployer.rs @@ -1,13 +1,11 @@ //! Deployer for the kubernetes cluster. use clap::Parser; use std::collections::HashMap; -use zksync_consensus_roles::{node, validator}; +use zksync_consensus_roles::node::SecretKey; +use zksync_consensus_roles::validator; use zksync_consensus_tools::k8s::ConsensusNode; use zksync_consensus_tools::{k8s, AppConfig}; -/// K8s namespace for consensus nodes. -const NAMESPACE: &str = "consensus"; - /// Command line arguments. #[derive(Debug, Parser)] #[command(name = "deployer")] @@ -35,7 +33,7 @@ fn generate_consensus_nodes(nodes: usize, seed_nodes_amount: Option) -> V // Each node will have `gossip_peers` outbound peers. let peers = 2; - let node_keys: Vec = (0..nodes).map(|_| node::SecretKey::generate()).collect(); + let node_keys: Vec = (0..nodes).map(|_| SecretKey::generate()).collect(); let default_config = AppConfig::default_for(setup.genesis.clone()); @@ -65,7 +63,7 @@ fn generate_consensus_nodes(nodes: usize, seed_nodes_amount: Option) -> V async fn deploy(nodes_amount: usize, seed_nodes_amount: Option) -> anyhow::Result<()> { let mut consensus_nodes = generate_consensus_nodes(nodes_amount, seed_nodes_amount); let client = k8s::get_client().await?; - k8s::create_or_reuse_namespace(&client, NAMESPACE).await?; + k8s::create_or_reuse_namespace(&client, k8s::DEFAULT_NAMESPACE).await?; let seed_nodes = &mut HashMap::new(); let mut non_seed_nodes = HashMap::new(); @@ -81,12 +79,13 @@ async fn deploy(nodes_amount: usize, seed_nodes_amount: Option) -> anyhow // Deploy seed peer(s) for node in seed_nodes.values_mut() { - node.deploy(&client, NAMESPACE).await?; + node.deploy(&client, k8s::DEFAULT_NAMESPACE).await?; } // Fetch and complete node addrs into seed nodes for node in seed_nodes.values_mut() { - node.fetch_and_assign_pod_ip(&client, NAMESPACE).await?; + node.fetch_and_assign_pod_ip(&client, k8s::DEFAULT_NAMESPACE) + .await?; } // Build a vector of (PublicKey, SocketAddr) to provide as gossip_static_outbound @@ -106,7 +105,7 @@ async fn deploy(nodes_amount: usize, seed_nodes_amount: Option) -> anyhow // Deploy the rest of the nodes for node in non_seed_nodes.values_mut() { node.config.gossip_static_outbound.extend(peers.clone()); - node.deploy(&client, NAMESPACE).await?; + node.deploy(&client, k8s::DEFAULT_NAMESPACE).await?; } Ok(()) diff --git a/node/tools/src/k8s.rs b/node/tools/src/k8s.rs index e1c757b7..87463aeb 100644 --- a/node/tools/src/k8s.rs +++ b/node/tools/src/k8s.rs @@ -195,7 +195,7 @@ pub async fn get_consensus_nodes_address(client: &Client) -> anyhow::Result = Vec::new(); - for pod in pods.into_iter() { + for pod in pods { let pod_spec = pod.spec.as_ref().context("Failed to get pod spec")?; let pod_container = pod_spec .containers @@ -218,7 +218,7 @@ pub async fn get_consensus_nodes_address(client: &Client) -> anyhow::Result anyhow::Result<()> { rpc_addr.set_port(rpc_addr.port() + 100); } - // cloning configuration to let RPCServer show it - // TODO this should be queried in real time instead, to reflect any possible change in config - let rpc_server = RPCServer::new(rpc_addr, configs.app.clone()); + // Create the RPC server with the executor's storage. + let node_storage = executor.block_store.clone(); + let rpc_server = RPCServer::new(rpc_addr, node_storage); // Initialize the storage. scope::run!(ctx, |ctx, s| async { diff --git a/node/tools/src/rpc/methods/config.rs b/node/tools/src/rpc/methods/config.rs deleted file mode 100644 index 3c94e382..00000000 --- a/node/tools/src/rpc/methods/config.rs +++ /dev/null @@ -1,47 +0,0 @@ -//! Peers method for RPC server. -use super::RPCMethod; -use crate::{config::encode_json, decode_json, AppConfig}; -use jsonrpsee::types::{error::ErrorCode, Params}; -use std::fs::{self}; -use zksync_protobuf::serde::Serde; - -/// Config method for RPC server. -pub(crate) struct ConfigInfo; - -// RPCMethod trait should be more general to allow external parameters like this case -// TODO fix the trait and implement this code in it -impl ConfigInfo { - /// Provide the node's config information - pub(crate) fn info(config: AppConfig) -> Result { - // This may change in the future since we are assuming that the executor binary is being run inside the config directory. - Ok(serde_json::json!({ - "config": encode_json(&Serde(config)) - })) - } -} - -impl RPCMethod for ConfigInfo { - /// Config response for /config endpoint. - fn callback(_params: Params) -> Result { - // This may change in the future since we are assuming that the executor binary is being run inside the config directory. - let node_config = - fs::read_to_string("config.json").map_err(|_e| ErrorCode::InternalError)?; - let node_config = decode_json::>(&node_config) - .map_err(|_e| ErrorCode::InternalError)? - .0; - let config = encode_json(&Serde(node_config)); - Ok(serde_json::json!({ - "config": config - })) - } - - /// Config method name. - fn method() -> &'static str { - "config" - } - - /// Method path for GET requests. - fn path() -> &'static str { - "/config" - } -} diff --git a/node/tools/src/rpc/methods/health_check.rs b/node/tools/src/rpc/methods/health_check.rs index c92f6e90..c36d7498 100644 --- a/node/tools/src/rpc/methods/health_check.rs +++ b/node/tools/src/rpc/methods/health_check.rs @@ -1,23 +1,16 @@ -//! Health check method for RPC server. -use super::RPCMethod; -use jsonrpsee::types::{error::ErrorCode, Params}; +use jsonrpsee::core::RpcResult; -/// Health check method for RPC server. -pub struct HealthCheck; - -impl RPCMethod for HealthCheck { - /// Health check response for /health endpoint. - fn callback(_params: Params) -> Result { - Ok(serde_json::json!({"health": true})) - } +/// Health check response for /health endpoint. +pub fn callback() -> RpcResult { + Ok(serde_json::json!({"health": true})) +} - /// Health check method name. - fn method() -> &'static str { - "health_check" - } +/// Health check method name. +pub fn method() -> &'static str { + "health_check" +} - /// Method path for GET requests. - fn path() -> &'static str { - "/health" - } +/// Method path for GET requests. +pub fn path() -> &'static str { + "/health" } diff --git a/node/tools/src/rpc/methods/last_commited_block.rs b/node/tools/src/rpc/methods/last_commited_block.rs new file mode 100644 index 00000000..1f28bdb7 --- /dev/null +++ b/node/tools/src/rpc/methods/last_commited_block.rs @@ -0,0 +1,34 @@ +//! Peers method for RPC server. +use anyhow::Context; +use jsonrpsee::{ + core::RpcResult, + types::{error::ErrorCode, ErrorObjectOwned}, +}; +use std::sync::Arc; +use zksync_consensus_storage::BlockStore; + +/// Last view response for /last_view endpoint. +pub fn callback(node_storage: Arc) -> RpcResult { + let sub = &mut node_storage.subscribe(); + let state = sub.borrow().clone(); + let last_commited_block_header = state + .last + .context("Failed to get last state") + .map_err(|_| ErrorObjectOwned::from(ErrorCode::InternalError))? + .header() + .number + .0; + Ok(serde_json::json!({ + "last_commited_block": last_commited_block_header + })) +} + +/// Last view method name. +pub fn method() -> &'static str { + "last_commited_block" +} + +/// Method path for GET requests. +pub fn path() -> &'static str { + "/last_commited_block" +} diff --git a/node/tools/src/rpc/methods/last_view.rs b/node/tools/src/rpc/methods/last_view.rs new file mode 100644 index 00000000..162ca902 --- /dev/null +++ b/node/tools/src/rpc/methods/last_view.rs @@ -0,0 +1,34 @@ +//! Peers method for RPC server. +use anyhow::Context; +use jsonrpsee::{ + core::RpcResult, + types::{error::ErrorCode, ErrorObjectOwned}, +}; +use std::sync::Arc; +use zksync_consensus_storage::BlockStore; + +/// Last view response for /last_view endpoint. +pub fn callback(node_storage: Arc) -> RpcResult { + let sub = &mut node_storage.subscribe(); + let state = sub.borrow().clone(); + let last_view = state + .last + .context("Failed to get last state") + .map_err(|_| ErrorObjectOwned::from(ErrorCode::InternalError))? + .view() + .number + .0; + Ok(serde_json::json!({ + "last_view": last_view + })) +} + +/// Last view method name. +pub fn method() -> &'static str { + "last_view" +} + +/// Method path for GET requests. +pub fn path() -> &'static str { + "/last_view" +} diff --git a/node/tools/src/rpc/methods/mod.rs b/node/tools/src/rpc/methods/mod.rs index 8c104ae5..dc44e62d 100644 --- a/node/tools/src/rpc/methods/mod.rs +++ b/node/tools/src/rpc/methods/mod.rs @@ -1,15 +1,3 @@ -use jsonrpsee::types::{error::ErrorCode, Params}; - -/// Trait to implement for new RPC methods. -pub trait RPCMethod { - /// Method response logic when called. - fn callback(params: Params) -> Result; - /// Method name. - fn method() -> &'static str; - /// Method path for GET requests. - fn path() -> &'static str; -} - -pub(crate) mod config; pub mod health_check; -pub(crate) mod peers; +pub mod last_commited_block; +pub mod last_view; diff --git a/node/tools/src/rpc/methods/peers.rs b/node/tools/src/rpc/methods/peers.rs deleted file mode 100644 index fcd50355..00000000 --- a/node/tools/src/rpc/methods/peers.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! Peers method for RPC server. -use super::RPCMethod; -use crate::{decode_json, AppConfig}; -use jsonrpsee::types::{error::ErrorCode, Params}; -use std::fs::{self}; -use zksync_consensus_crypto::TextFmt; -use zksync_protobuf::serde::Serde; - -/// Peers method for RPC server. -pub(crate) struct PeersInfo; - -impl RPCMethod for PeersInfo { - /// Peers response for /peers endpoint. - fn callback(_params: Params) -> Result { - // This may change in the future since we are assuming that the executor binary is being run inside the config directory. - let node_config = - fs::read_to_string("config.json").map_err(|_e| ErrorCode::InternalError)?; - let node_config = decode_json::>(&node_config) - .map_err(|_e| ErrorCode::InternalError)? - .0; - let peers: Vec = node_config - .gossip_static_inbound - .iter() - .map(|x| x.encode()) - .collect(); - Ok(serde_json::json!({ - "peers": peers - })) - } - - /// Peers method name. - fn method() -> &'static str { - "peers" - } - - /// Method path for GET requests. - fn path() -> &'static str { - "/peers" - } -} diff --git a/node/tools/src/rpc/server.rs b/node/tools/src/rpc/server.rs index c23801be..e9522051 100644 --- a/node/tools/src/rpc/server.rs +++ b/node/tools/src/rpc/server.rs @@ -1,20 +1,23 @@ -use super::methods::{config::ConfigInfo, health_check::HealthCheck, peers::PeersInfo, RPCMethod}; -use crate::AppConfig; +use super::methods::{health_check, last_commited_block, last_view}; use jsonrpsee::server::{middleware::http::ProxyGetRequestLayer, RpcModule, Server}; -use std::net::SocketAddr; +use std::{net::SocketAddr, sync::Arc}; use zksync_concurrency::{ctx, scope}; +use zksync_consensus_storage::BlockStore; /// RPC server. pub struct RPCServer { /// IP address to bind to. ip_address: SocketAddr, - /// AppConfig - config: AppConfig, + /// Node storage. + node_storage: Arc, } impl RPCServer { - pub fn new(ip_address: SocketAddr, config: AppConfig) -> Self { - Self { ip_address, config } + pub fn new(ip_address: SocketAddr, node_storage: Arc) -> Self { + Self { + ip_address, + node_storage, + } } /// Runs the RPC server. @@ -23,35 +26,38 @@ impl RPCServer { let service_builder = tower::ServiceBuilder::new() // Proxy `GET /` requests to internal methods. .layer(ProxyGetRequestLayer::new( - HealthCheck::path(), - HealthCheck::method(), + health_check::path(), + health_check::method(), )?) .layer(ProxyGetRequestLayer::new( - PeersInfo::path(), - PeersInfo::method(), + last_view::path(), + last_view::method(), )?) .layer(ProxyGetRequestLayer::new( - ConfigInfo::path(), - ConfigInfo::method(), + last_commited_block::path(), + last_commited_block::method(), )?); - let server = Server::builder() - .set_http_middleware(service_builder) - .build(self.ip_address) - .await?; - let mut module = RpcModule::new(()); - module.register_method(HealthCheck::method(), |params, _| { - HealthCheck::callback(params) + module.register_method(health_check::method(), |_params, _| { + health_check::callback() + })?; + + let node_storage = self.node_storage.clone(); + module.register_method(last_view::method(), move |_params, _| { + last_view::callback(node_storage.clone()) })?; - module.register_method(PeersInfo::method(), |params, _| PeersInfo::callback(params))?; - // TODO find a better way to implement this as I had to clone the clone and move it to pass the borrow checker - let config = self.config.clone(); - module.register_method(ConfigInfo::method(), move |_params, _| { - ConfigInfo::info(config.clone()) + let node_storage = self.node_storage.clone(); + module.register_method(last_commited_block::method(), move |_params, _| { + last_commited_block::callback(node_storage.clone()) })?; + let server = Server::builder() + .set_http_middleware(service_builder) + .build(self.ip_address) + .await?; + let handle = server.start(module); scope::run!(ctx, |ctx, s| async { s.spawn_bg(async {