From 4c3510da26deb3a7faba16c3fd0149a1a558855a Mon Sep 17 00:00:00 2001 From: renancloudwalk <53792026+renancloudwalk@users.noreply.github.com> Date: Sat, 4 May 2024 23:24:55 -0300 Subject: [PATCH] Tonic (#775) * chore: add tonic as a consensus server * add tonic into run with importer * lint * lint --- .github/workflows/_setup-e2e.yml | 5 +- .github/workflows/comment-tag-report.yml | 4 +- .github/workflows/doc-test.yml | 5 +- .github/workflows/e2e-contracts-postgres.yml | 3 + .github/workflows/e2e-contracts-rocks.yml | 3 + .github/workflows/e2e-contracts.yml | 3 + .github/workflows/int-test.yml | 3 + .github/workflows/lint-check.yml | 5 +- .github/workflows/outdated.yml | 8 +- .github/workflows/unit-test.yml | 5 +- Cargo.lock | 822 +++++-------------- Cargo.toml | 13 +- build.rs | 1 + proto/management.proto | 27 + src/bin/run_with_importer.rs | 11 +- src/eth/storage/rocks/consensus.rs | 156 +--- 16 files changed, 308 insertions(+), 766 deletions(-) create mode 100644 proto/management.proto diff --git a/.github/workflows/_setup-e2e.yml b/.github/workflows/_setup-e2e.yml index 4355be647..800829692 100644 --- a/.github/workflows/_setup-e2e.yml +++ b/.github/workflows/_setup-e2e.yml @@ -42,6 +42,9 @@ jobs: if: ${{ steps.cache-cargo.outputs.cache-hit != 'true' }} run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + - name: Install protobuf compiler + run: sudo apt-get install -y protobuf-compiler + - name: Set up Just uses: extractions/setup-just@v1 @@ -65,4 +68,4 @@ jobs: env: CARGO_PROFILE_RELEASE_DEBUG: 0 RUST_LOG: off - RELEASE: 1 \ No newline at end of file + RELEASE: 1 diff --git a/.github/workflows/comment-tag-report.yml b/.github/workflows/comment-tag-report.yml index 828776375..c05120ca7 100644 --- a/.github/workflows/comment-tag-report.yml +++ b/.github/workflows/comment-tag-report.yml @@ -20,6 +20,9 @@ jobs: - name: Set up Rust run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + - name: Install protobuf compiler + run: sudo apt-get install -y protobuf-compiler + - name: Setup Ruby uses: ruby/setup-ruby@v1 with: @@ -39,4 +42,3 @@ jobs: run: ruby utils/slack-notifiers/comments.rb env: SLACK_WEBHOOK_URL: ${{ secrets.STRATUS_SLACK_WEBHOOK_URL }} - \ No newline at end of file diff --git a/.github/workflows/doc-test.yml b/.github/workflows/doc-test.yml index 55e982149..79d76f869 100644 --- a/.github/workflows/doc-test.yml +++ b/.github/workflows/doc-test.yml @@ -47,8 +47,11 @@ jobs: if: ${{ steps.cache-cargo.outputs.cache-hit != 'true' }} run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + - name: Install protobuf compiler + run: sudo apt-get install -y protobuf-compiler + - name: Set up Just uses: extractions/setup-just@v1 - name: Test docs - run: just test-doc \ No newline at end of file + run: just test-doc diff --git a/.github/workflows/e2e-contracts-postgres.yml b/.github/workflows/e2e-contracts-postgres.yml index 2d43681c7..8bfda24cc 100644 --- a/.github/workflows/e2e-contracts-postgres.yml +++ b/.github/workflows/e2e-contracts-postgres.yml @@ -59,6 +59,9 @@ jobs: if: ${{ steps.cache-cargo.outputs.cache-hit != 'true' }} run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + - name: Install protobuf compiler + run: sudo apt-get install -y protobuf-compiler + - name: Set up Just uses: extractions/setup-just@v1 diff --git a/.github/workflows/e2e-contracts-rocks.yml b/.github/workflows/e2e-contracts-rocks.yml index bd0d0e0f2..3e7832b1e 100644 --- a/.github/workflows/e2e-contracts-rocks.yml +++ b/.github/workflows/e2e-contracts-rocks.yml @@ -60,6 +60,9 @@ jobs: if: ${{ steps.cache-cargo.outputs.cache-hit != 'true' }} run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + - name: Install protobuf compiler + run: sudo apt-get install -y protobuf-compiler + - name: Set up Just uses: extractions/setup-just@v1 diff --git a/.github/workflows/e2e-contracts.yml b/.github/workflows/e2e-contracts.yml index 4bbac338b..2a33ce7f6 100644 --- a/.github/workflows/e2e-contracts.yml +++ b/.github/workflows/e2e-contracts.yml @@ -59,6 +59,9 @@ jobs: if: ${{ steps.cache-cargo.outputs.cache-hit != 'true' }} run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + - name: Install protobuf compiler + run: sudo apt-get install -y protobuf-compiler + - name: Set up Just uses: extractions/setup-just@v1 diff --git a/.github/workflows/int-test.yml b/.github/workflows/int-test.yml index 735d0a9a0..b7de5f3f0 100644 --- a/.github/workflows/int-test.yml +++ b/.github/workflows/int-test.yml @@ -55,6 +55,9 @@ jobs: if: ${{ steps.cache-cargo.outputs.cache-hit != 'true' }} run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + - name: Install protobuf compiler + run: sudo apt-get install -y protobuf-compiler + - name: Set up Just uses: extractions/setup-just@v1 diff --git a/.github/workflows/lint-check.yml b/.github/workflows/lint-check.yml index f52233283..7c1b88348 100644 --- a/.github/workflows/lint-check.yml +++ b/.github/workflows/lint-check.yml @@ -53,8 +53,11 @@ jobs: - name: Set up Rust Nightly run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly-2024-01-01 + - name: Install protobuf compiler + run: sudo apt-get install -y protobuf-compiler + - name: Set up Just uses: extractions/setup-just@v1 - name: Just lint-check - run: just lint-check -2024-01-01 \ No newline at end of file + run: just lint-check -2024-01-01 diff --git a/.github/workflows/outdated.yml b/.github/workflows/outdated.yml index 2b2cc6586..73c4b0b86 100644 --- a/.github/workflows/outdated.yml +++ b/.github/workflows/outdated.yml @@ -18,8 +18,11 @@ jobs: uses: actions/checkout@v2 - name: Set up Rust - run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - + run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + + - name: Install protobuf compiler + run: sudo apt-get install -y protobuf-compiler + - name: Set up Just uses: extractions/setup-just@v1 @@ -36,4 +39,3 @@ jobs: env: SLACK_WEBHOOK_URL: ${{ secrets.STRATUS_SLACK_WEBHOOK_URL }} OUTDATED_TABLE_FILE_NAME: outdated.txt - \ No newline at end of file diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 0ddffda45..4d9d85c6e 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -54,8 +54,11 @@ jobs: if: ${{ steps.cache-cargo.outputs.cache-hit != 'true' }} run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + - name: Install protobuf compiler + run: sudo apt-get install -y protobuf-compiler + - name: Set up Just uses: extractions/setup-just@v1 - name: Unit tests - run: just test-unit \ No newline at end of file + run: just test-unit diff --git a/Cargo.lock b/Cargo.lock index 094faca45..7ccb64e02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -152,16 +152,19 @@ dependencies = [ ] [[package]] -name = "anyhow" -version = "1.0.82" +name = "anyerror" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" +checksum = "bcd04a72664a65fb9adeae7ced0c98efd68a2b7a45adda8319b3bb36538404b8" +dependencies = [ + "serde", +] [[package]] -name = "arc-swap" -version = "1.7.1" +name = "anyhow" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" +checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" [[package]] name = "ark-ff" @@ -312,7 +315,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -323,7 +326,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -353,7 +356,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -407,17 +410,6 @@ dependencies = [ "tower-service", ] -[[package]] -name = "backoff" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62ddb9cb1ec0a098ad4bbf9344d0713fa193ae1a80af55febcff2627b6a00c1" -dependencies = [ - "getrandom", - "instant", - "rand", -] - [[package]] name = "backtrace" version = "0.3.71" @@ -530,7 +522,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -635,7 +627,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", "syn_derive", ] @@ -651,6 +643,16 @@ version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" +[[package]] +name = "byte-unit" +version = "4.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da78b32057b8fdfc352504708feeba7216dcd65a2c9ab02978cbd288d1279b6c" +dependencies = [ + "serde", + "utf8-width", +] + [[package]] name = "byte-unit" version = "5.1.4" @@ -813,7 +815,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -1040,7 +1042,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -1062,7 +1064,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ "darling_core 0.20.8", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -1121,7 +1123,7 @@ checksum = "d150dea618e920167e5973d70ae6ece4385b7164e0d799fe7c122dd0a5d912ad" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -1164,27 +1166,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "dirs-next" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" -dependencies = [ - "cfg-if", - "dirs-sys-next", -] - -[[package]] -name = "dirs-sys-next" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - [[package]] name = "dotenv" version = "0.15.0" @@ -1206,7 +1187,7 @@ dependencies = [ "darling 0.20.8", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -1274,7 +1255,7 @@ checksum = "6fd000fd6988e73bbe993ea3db9b1aa64906ab88766d654973924340c8cddb42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -1484,6 +1465,12 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + [[package]] name = "flume" version = "0.11.0" @@ -1598,7 +1585,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -1641,15 +1628,6 @@ dependencies = [ "slab", ] -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - [[package]] name = "generic-array" version = "0.14.7" @@ -1672,18 +1650,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "getset" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e45727250e75cc04ff2846a66397da8ef2b3db8e40e0cef4df67950a07621eb9" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "gimli" version = "0.28.1" @@ -2042,25 +2008,6 @@ dependencies = [ "tokio-rustls 0.24.1", ] -[[package]] -name = "hyper-rustls" -version = "0.27.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "908bb38696d7a037a01ebcc68a00634112ac2bbf8ca74e30a2c3d2f4f021302b" -dependencies = [ - "futures-util", - "http 1.1.0", - "hyper 1.3.1", - "hyper-util", - "log", - "rustls 0.23.5", - "rustls-native-certs 0.7.0", - "rustls-pki-types", - "tokio", - "tokio-rustls 0.26.0", - "tower-service", -] - [[package]] name = "hyper-timeout" version = "0.4.1" @@ -2073,19 +2020,6 @@ dependencies = [ "tokio-io-timeout", ] -[[package]] -name = "hyper-timeout" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3203a961e5c83b6f5498933e78b6b263e208c197b63e9c6c53cc82ffd3f63793" -dependencies = [ - "hyper 1.3.1", - "hyper-util", - "pin-project-lite", - "tokio", - "tower-service", -] - [[package]] name = "hyper-tls" version = "0.6.0" @@ -2227,32 +2161,12 @@ dependencies = [ "serde", ] -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - [[package]] name = "ipnet" version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" -[[package]] -name = "is-terminal" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" -dependencies = [ - "hermit-abi", - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "itertools" version = "0.10.5" @@ -2295,33 +2209,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "json-patch" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55ff1e1486799e3f64129f8ccad108b38290df9cd7015cd31bed17239f0789d6" -dependencies = [ - "serde", - "serde_json", - "thiserror", - "treediff", -] - -[[package]] -name = "jsonpath-rust" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0268078319393f8430e850ee9d4706aeced256d34cf104d216bb496777137162" -dependencies = [ - "lazy_static", - "once_cell", - "pest", - "pest_derive", - "regex", - "serde_json", - "thiserror", -] - [[package]] name = "jsonrpsee" version = "0.22.4" @@ -2396,7 +2283,7 @@ checksum = "ac13bc1e44cd00448a5ff485824a128629c945f02077804cb659c07a0ba41395" dependencies = [ "async-trait", "hyper 0.14.28", - "hyper-rustls 0.24.2", + "hyper-rustls", "jsonrpsee-core", "jsonrpsee-types", "serde", @@ -2482,19 +2369,6 @@ dependencies = [ "sha2", ] -[[package]] -name = "k8s-openapi" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "550f99d93aa4c2b25de527bce492d772caf5e21d7ac9bd4b508ba781c8d91e30" -dependencies = [ - "base64 0.21.7", - "chrono", - "serde", - "serde-value", - "serde_json", -] - [[package]] name = "keccak" version = "0.1.5" @@ -2525,112 +2399,6 @@ dependencies = [ "tiny-keccak", ] -[[package]] -name = "kube" -version = "0.90.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65bfada4e00dac93a7b94e454ae4cde04ff8786645ac1b98f31352272e2682b5" -dependencies = [ - "k8s-openapi", - "kube-client", - "kube-core", - "kube-derive", - "kube-runtime", -] - -[[package]] -name = "kube-client" -version = "0.90.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0708306b5c0085f249f5e3d2d56a9bbfe0cbbf4fd4eb9ed4bbba542ba7649a7" -dependencies = [ - "base64 0.22.0", - "bytes", - "chrono", - "either", - "futures", - "home", - "http 1.1.0", - "http-body 1.0.0", - "http-body-util", - "hyper 1.3.1", - "hyper-rustls 0.27.1", - "hyper-timeout 0.5.1", - "hyper-util", - "jsonpath-rust", - "k8s-openapi", - "kube-core", - "pem", - "rustls 0.23.5", - "rustls-pemfile 2.1.2", - "secrecy", - "serde", - "serde_json", - "serde_yaml", - "thiserror", - "tokio", - "tokio-util", - "tower", - "tower-http", - "tracing", -] - -[[package]] -name = "kube-core" -version = "0.90.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7845bcc3e0f422df4d9049570baedd9bc1942f0504594e393e72fe24092559cf" -dependencies = [ - "chrono", - "form_urlencoded", - "http 1.1.0", - "json-patch", - "k8s-openapi", - "schemars", - "serde", - "serde_json", - "thiserror", -] - -[[package]] -name = "kube-derive" -version = "0.90.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d0d2527a6ff7adf00b34d558c4c5de9404abe28808cb0a4c64b57e2c1b0716a" -dependencies = [ - "darling 0.20.8", - "proc-macro2", - "quote", - "serde_json", - "syn 2.0.60", -] - -[[package]] -name = "kube-runtime" -version = "0.90.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4560e2c5c71366f6dceb6500ce33cf72299aede92381bb875dc2d4ba4f102c21" -dependencies = [ - "ahash 0.8.11", - "async-trait", - "backoff", - "derivative", - "futures", - "hashbrown 0.14.5", - "json-patch", - "k8s-openapi", - "kube-client", - "parking_lot", - "pin-project", - "serde", - "serde_json", - "smallvec", - "thiserror", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -2668,16 +2436,6 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" -[[package]] -name = "libredox" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" -dependencies = [ - "bitflags 2.5.0", - "libc", -] - [[package]] name = "librocksdb-sys" version = "0.16.0+8.10.0" @@ -2757,6 +2515,12 @@ dependencies = [ "libc", ] +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + [[package]] name = "matchers" version = "0.1.0" @@ -2825,7 +2589,7 @@ checksum = "38b4faf00617defe497754acde3024865bc143d44a86799b24e191ecff91354f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -2875,6 +2639,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "multimap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" + [[package]] name = "native-tls" version = "0.2.11" @@ -3049,7 +2819,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -3098,6 +2868,40 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "openraft" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d2207f55c562d269b93ed659d15bec46e511c39ad248f829d43908bdd4b7767" +dependencies = [ + "anyerror", + "byte-unit 4.0.19", + "clap", + "derive_more", + "futures", + "maplit", + "openraft-macros", + "rand", + "thiserror", + "tokio", + "tracing", + "tracing-futures", + "validit", +] + +[[package]] +name = "openraft-macros" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e429bba330d28a4a767f77bb641dccd960568389b27cb7b59c1871a7e5f017fc" +dependencies = [ + "chrono", + "proc-macro2", + "quote", + "semver 1.0.22", + "syn 2.0.58", +] + [[package]] name = "openssl" version = "0.10.64" @@ -3121,7 +2925,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -3208,7 +3012,7 @@ dependencies = [ "glob", "once_cell", "opentelemetry", - "ordered-float 4.2.0", + "ordered-float", "percent-encoding", "rand", "thiserror", @@ -3216,15 +3020,6 @@ dependencies = [ "tokio-stream", ] -[[package]] -name = "ordered-float" -version = "2.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c" -dependencies = [ - "num-traits", -] - [[package]] name = "ordered-float" version = "4.2.0" @@ -3306,16 +3101,6 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" -[[package]] -name = "pem" -version = "3.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e459365e590736a54c3fa561947c84837534b8e9af6fc5bf781307e82658fae" -dependencies = [ - "base64 0.22.0", - "serde", -] - [[package]] name = "pem-rfc7468" version = "0.7.0" @@ -3343,37 +3128,13 @@ dependencies = [ ] [[package]] -name = "pest_derive" -version = "2.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f73541b156d32197eecda1a4014d7f868fd2bcb3c550d5386087cfba442bf69c" -dependencies = [ - "pest", - "pest_generator", -] - -[[package]] -name = "pest_generator" -version = "2.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c35eeed0a3fab112f75165fdc026b3913f4183133f19b49be773ac9ea966e8bd" -dependencies = [ - "pest", - "pest_meta", - "proc-macro2", - "quote", - "syn 2.0.60", -] - -[[package]] -name = "pest_meta" -version = "2.7.9" +name = "petgraph" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2adbf29bb9776f28caece835398781ab24435585fe0d4dc1374a61db5accedca" +checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ - "once_cell", - "pest", - "sha2", + "fixedbitset", + "indexmap 2.2.6", ] [[package]] @@ -3431,7 +3192,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -3491,6 +3252,16 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "prettyplease" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d3928fb5db768cb86f891ff014f0144589297e3c6a1aba6ed7cecfdace270c7" +dependencies = [ + "proc-macro2", + "syn 2.0.58", +] + [[package]] name = "primitive-types" version = "0.12.2" @@ -3542,7 +3313,6 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn 1.0.109", "version_check", ] @@ -3565,9 +3335,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.81" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" dependencies = [ "unicode-ident", ] @@ -3603,46 +3373,46 @@ dependencies = [ ] [[package]] -name = "prost-derive" +name = "prost-build" version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" -dependencies = [ - "anyhow", - "itertools 0.12.1", - "proc-macro2", - "quote", - "syn 2.0.60", -] - -[[package]] -name = "protobuf" -version = "2.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" +checksum = "80b776a1b2dc779f5ee0641f8ade0125bc1298dd41a9a0c16d8bd57b42d222b1" dependencies = [ "bytes", + "heck 0.5.0", + "itertools 0.12.1", + "log", + "multimap", + "once_cell", + "petgraph", + "prettyplease", + "prost", + "prost-types", + "regex", + "syn 2.0.58", + "tempfile", ] [[package]] -name = "protobuf-build" -version = "0.14.1" +name = "prost-derive" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2df9942df2981178a930a72d442de47e2f0df18ad68e50a30f816f1848215ad0" +checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" dependencies = [ - "bitflags 1.3.2", - "protobuf", - "protobuf-codegen", - "regex", + "anyhow", + "itertools 0.12.1", + "proc-macro2", + "quote", + "syn 2.0.58", ] [[package]] -name = "protobuf-codegen" -version = "2.28.0" +name = "prost-types" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "033460afb75cf755fcfc16dfaed20b86468082a2ea24e05ac35ab4a099a017d6" +checksum = "3235c33eb02c1f1e212abdbe34c78b264b038fb58ca612664343271e36e55ffe" dependencies = [ - "protobuf", + "prost", ] [[package]] @@ -3702,36 +3472,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" -[[package]] -name = "raft" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12688b23a649902762d4c11d854d73c49c9b93138f2de16403ef9f571ad5bae" -dependencies = [ - "bytes", - "fxhash", - "getset", - "protobuf", - "raft-proto", - "rand", - "slog", - "slog-envlogger", - "slog-stdlog", - "slog-term", - "thiserror", -] - -[[package]] -name = "raft-proto" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb6884896294f553e8d5cfbdb55080b9f5f2f43394afff59c9f077e0f4b46d6b" -dependencies = [ - "bytes", - "protobuf", - "protobuf-build", -] - [[package]] name = "rand" version = "0.8.5" @@ -3798,17 +3538,6 @@ dependencies = [ "bitflags 2.5.0", ] -[[package]] -name = "redox_users" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" -dependencies = [ - "getrandom", - "libredox", - "thiserror", -] - [[package]] name = "regex" version = "1.10.4" @@ -4210,21 +3939,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "rustls" -version = "0.23.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afabcee0551bd1aa3e18e5adbf2c0544722014b899adb31bd186ec638d3da97e" -dependencies = [ - "log", - "once_cell", - "ring", - "rustls-pki-types", - "rustls-webpki 0.102.3", - "subtle", - "zeroize", -] - [[package]] name = "rustls-native-certs" version = "0.6.3" @@ -4353,30 +4067,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "schemars" -version = "0.8.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f55c82c700538496bdc329bb4918a81f87cc8888811bd123cf325a0f2f8d309" -dependencies = [ - "dyn-clone", - "schemars_derive", - "serde", - "serde_json", -] - -[[package]] -name = "schemars_derive" -version = "0.8.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83263746fe5e32097f06356968a077f96089739c927a61450efa069905eec108" -dependencies = [ - "proc-macro2", - "quote", - "serde_derive_internals", - "syn 2.0.60", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -4432,16 +4122,6 @@ dependencies = [ "cc", ] -[[package]] -name = "secrecy" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bd1c54ea06cfd2f6b63219704de0b9b4f72dcc2b8fdef820be6cd799780e91e" -dependencies = [ - "serde", - "zeroize", -] - [[package]] name = "security-framework" version = "2.10.0" @@ -4612,16 +4292,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde-value" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c" -dependencies = [ - "ordered-float 2.10.1", - "serde", -] - [[package]] name = "serde_derive" version = "1.0.199" @@ -4630,18 +4300,7 @@ checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", -] - -[[package]] -name = "serde_derive_internals" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "330f01ce65a3a5fe59a60c82f3c9a024b573b8a6e875bd233fe5f934e71d54e3" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -4717,20 +4376,7 @@ dependencies = [ "darling 0.20.8", "proc-macro2", "quote", - "syn 2.0.60", -] - -[[package]] -name = "serde_yaml" -version = "0.9.34+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" -dependencies = [ - "indexmap 2.2.6", - "itoa", - "ryu", - "serde", - "unsafe-libyaml", + "syn 2.0.58", ] [[package]] @@ -4849,74 +4495,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "slog" -version = "2.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8347046d4ebd943127157b94d63abb990fcf729dc4e9978927fdf4ac3c998d06" - -[[package]] -name = "slog-async" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72c8038f898a2c79507940990f05386455b3a317d8f18d4caea7cbc3d5096b84" -dependencies = [ - "crossbeam-channel", - "slog", - "take_mut", - "thread_local", -] - -[[package]] -name = "slog-envlogger" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "906a1a0bc43fed692df4b82a5e2fbfc3733db8dad8bb514ab27a4f23ad04f5c0" -dependencies = [ - "log", - "regex", - "slog", - "slog-async", - "slog-scope", - "slog-stdlog", - "slog-term", -] - -[[package]] -name = "slog-scope" -version = "4.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f95a4b4c3274cd2869549da82b57ccc930859bdbf5bcea0424bc5f140b3c786" -dependencies = [ - "arc-swap", - "lazy_static", - "slog", -] - -[[package]] -name = "slog-stdlog" -version = "4.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6706b2ace5bbae7291d3f8d2473e2bfab073ccd7d03670946197aec98471fa3e" -dependencies = [ - "log", - "slog", - "slog-scope", -] - -[[package]] -name = "slog-term" -version = "2.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6e022d0b998abfe5c3782c1f03551a596269450ccd677ea51c56f8b214610e8" -dependencies = [ - "is-terminal", - "slog", - "term", - "thread_local", - "time", -] - [[package]] name = "smallvec" version = "1.13.2" @@ -5201,7 +4779,7 @@ dependencies = [ "async-trait", "binary_macros", "bincode", - "byte-unit", + "byte-unit 5.1.4", "chrono", "clap", "const-hex", @@ -5225,14 +4803,13 @@ dependencies = [ "indexmap 2.2.6", "itertools 0.12.1", "jsonrpsee", - "k8s-openapi", "keccak-hasher", - "kube", "metrics", "metrics-exporter-prometheus", "nom", "nonempty", "num-traits", + "openraft", "opentelemetry", "opentelemetry-otlp", "opentelemetry_sdk", @@ -5240,8 +4817,9 @@ dependencies = [ "phf", "phf_codegen", "pin-project", + "prost", + "prost-types", "quote", - "raft", "rand", "reqwest", "revm", @@ -5251,9 +4829,6 @@ dependencies = [ "serde", "serde_json", "serde_with 3.8.1", - "slog", - "slog-async", - "slog-term", "sqlx", "stringreader", "strum", @@ -5262,6 +4837,8 @@ dependencies = [ "thiserror", "tokio", "tokio-util", + "tonic", + "tonic-build", "tower", "tracing", "tracing-opentelemetry", @@ -5318,7 +4895,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -5353,9 +4930,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.60" +version = "2.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" dependencies = [ "proc-macro2", "quote", @@ -5371,7 +4948,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -5401,12 +4978,6 @@ dependencies = [ "libc", ] -[[package]] -name = "take_mut" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" - [[package]] name = "tap" version = "1.0.1" @@ -5425,17 +4996,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "term" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" -dependencies = [ - "dirs-next", - "rustversion", - "winapi", -] - [[package]] name = "testcontainers" version = "0.15.0" @@ -5479,7 +5039,7 @@ checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -5592,7 +5152,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -5626,17 +5186,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-rustls" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" -dependencies = [ - "rustls 0.23.5", - "rustls-pki-types", - "tokio", -] - [[package]] name = "tokio-stream" version = "0.1.15" @@ -5660,7 +5209,6 @@ dependencies = [ "futures-io", "futures-sink", "pin-project-lite", - "slab", "tokio", "tracing", ] @@ -5719,7 +5267,7 @@ dependencies = [ "http 0.2.12", "http-body 0.4.6", "hyper 0.14.28", - "hyper-timeout 0.4.1", + "hyper-timeout", "percent-encoding", "pin-project", "prost", @@ -5731,6 +5279,19 @@ dependencies = [ "tracing", ] +[[package]] +name = "tonic-build" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4ef6dd70a610078cb4e338a0f79d06bc759ff1b22d2120c2ff02ae264ba9c2" +dependencies = [ + "prettyplease", + "proc-macro2", + "prost-build", + "quote", + "syn 2.0.58", +] + [[package]] name = "tower" version = "0.4.13" @@ -5751,25 +5312,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "tower-http" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5" -dependencies = [ - "base64 0.21.7", - "bitflags 2.5.0", - "bytes", - "http 1.1.0", - "http-body 1.0.0", - "http-body-util", - "mime", - "pin-project-lite", - "tower-layer", - "tower-service", - "tracing", -] - [[package]] name = "tower-layer" version = "0.3.2" @@ -5802,7 +5344,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -5815,6 +5357,16 @@ dependencies = [ "valuable", ] +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + [[package]] name = "tracing-log" version = "0.2.0" @@ -5875,15 +5427,6 @@ dependencies = [ "tracing-serde", ] -[[package]] -name = "treediff" -version = "4.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d127780145176e2b5d16611cc25a900150e86e9fd79d3bde6ff3a37359c9cb5" -dependencies = [ - "serde_json", -] - [[package]] name = "triehash" version = "0.8.4" @@ -5978,12 +5521,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" -[[package]] -name = "unsafe-libyaml" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" - [[package]] name = "untrusted" version = "0.9.0" @@ -6042,6 +5579,15 @@ dependencies = [ "serde", ] +[[package]] +name = "validit" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1fad49f3eae9c160c06b4d49700a99e75817f127cf856e494b56d5e23170020" +dependencies = [ + "anyerror", +] + [[package]] name = "valuable" version = "0.1.0" @@ -6111,7 +5657,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", "wasm-bindgen-shared", ] @@ -6145,7 +5691,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -6420,7 +5966,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] @@ -6440,7 +5986,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.58", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index b7eb0dd59..9697043e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,12 +84,10 @@ opentelemetry_sdk = { version = "=0.22.1", features = ["rt-tokio"] } sqlx = { version = "=0.7.4", features = ["runtime-tokio", "postgres", "bigdecimal", "time"] } num-traits = "=0.2.18" rocksdb = { version = "=0.22.0", features = ["multi-threaded-cf"], optional = true } -raft = { version = "=0.7.0", optional = true } -slog = "2.7" -slog-term = "2.8" -slog-async = "2.7" -kube = { version = "=0.90.0", optional = true, features = ["runtime", "derive"] } -k8s-openapi = { version = "=0.21.1", optional = true, features = ["v1_27"] } +tonic = "=0.11.0" +prost = "=0.12.4" +prost-types = "=0.12.4" +openraft = "=0.9.8" bincode = { version = "=1.3.3", optional = true } @@ -110,6 +108,7 @@ const-hex = "=1.10.0" glob = "=0.3.1" nom = "=7.1.3" phf_codegen = "=0.11.2" +tonic-build = "=0.11.0" # ------------------------------------------------------------------------------ # Binaries @@ -152,7 +151,7 @@ perf = [] metrics = ["dep:metrics", "dep:metrics-exporter-prometheus"] # Enable RocksDB dependencies. -rocks = ["rocksdb", "bincode", "raft"] +rocks = ["rocksdb", "bincode"] # XXX: Enable external transaction parallel execution. executor-parallel = [] diff --git a/build.rs b/build.rs index 1395e4559..98854d5d5 100644 --- a/build.rs +++ b/build.rs @@ -14,6 +14,7 @@ use nom::IResult; fn main() { generate_signature_maps(); + tonic_build::compile_protos("proto/management.proto").unwrap(); } // ----------------------------------------------------------------------------- diff --git a/proto/management.proto b/proto/management.proto new file mode 100644 index 000000000..dccfafe4f --- /dev/null +++ b/proto/management.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; + +package management; + +message Node { + uint64 id = 1; + string address = 2; +} + +message AddLearnerRequest { + Node node = 1; +} + +message ChangeMembershipRequest { + repeated uint64 nodes = 1; +} + +message ResultResponse { + bool success = 1; + string message = 2; +} + +service ClusterManagement { + rpc InitCluster(Node) returns (ResultResponse); + rpc AddLearner(AddLearnerRequest) returns (ResultResponse); + rpc ChangeMembership(ChangeMembershipRequest) returns (ResultResponse); +} diff --git a/src/bin/run_with_importer.rs b/src/bin/run_with_importer.rs index 92580c645..e24fa7040 100644 --- a/src/bin/run_with_importer.rs +++ b/src/bin/run_with_importer.rs @@ -14,8 +14,6 @@ fn main() -> anyhow::Result<()> { } async fn run(config: RunWithImporterConfig) -> anyhow::Result<()> { - #[cfg(feature = "rocks")] - stratus::eth::storage::rocks::consensus::gather_clients().await.unwrap(); let stratus_config = config.as_stratus(); let importer_config = config.as_importer(); @@ -23,12 +21,21 @@ async fn run(config: RunWithImporterConfig) -> anyhow::Result<()> { let executor = stratus_config.executor.init(Arc::clone(&storage)).await; + #[cfg(feature = "rocks")] + let consensus_task = tokio::spawn(stratus::eth::storage::rocks::consensus::run_server()); let rpc_task = tokio::spawn(serve_rpc(Arc::clone(&executor), Arc::clone(&storage), stratus_config)); let importer_task = tokio::spawn(run_importer_online(importer_config, Arc::clone(&executor), storage)); + #[cfg(feature = "rocks")] + let join_result = try_join!(rpc_task, importer_task, consensus_task)?; + + #[cfg(not(feature = "rocks"))] let join_result = try_join!(rpc_task, importer_task)?; join_result.0?; join_result.1?; + #[cfg(feature = "rocks")] + join_result.2?; + Ok(()) } diff --git a/src/eth/storage/rocks/consensus.rs b/src/eth/storage/rocks/consensus.rs index 80c28df13..7dfaa50d7 100644 --- a/src/eth/storage/rocks/consensus.rs +++ b/src/eth/storage/rocks/consensus.rs @@ -1,133 +1,67 @@ //TODO move this onto temporary storage, it will be called from a channel -use std::collections::HashMap; - use anyhow::Result; -use raft::raw_node::RawNode; -use raft::storage::MemStorage; -use raft::Config; -use slog::o; -use slog::Drain; -use slog::Logger; -use tokio::sync::Mutex; -use tokio::time::Duration; -use tokio::time::{self}; -use tracing::info; - -use crate::infra::BlockchainClient; - -fn setup_logger() -> Logger { - let decorator = slog_term::TermDecorator::new().build(); - let drain = slog_term::CompactFormat::new(decorator).build().fuse(); - let drain = slog_async::Async::new(drain).build().fuse(); - Logger::root(drain, o!()) -} pub async fn gather_clients() -> Result<()> { // Initialize a HashMap to store pod IPs and roles - let pods_list = [ + let _pods_list = [ "http://stratus-api-0.stratus-api.stratus-staging.svc.cluster.local:3000", "http://stratus-api-1.stratus-api.stratus-staging.svc.cluster.local:3000", "http://stratus-api-2.stratus-api.stratus-staging.svc.cluster.local:3000", ]; - for pod_ip in pods_list.iter() { - let chain = match BlockchainClient::new(pod_ip).await { - Ok(chain) => chain, - Err(e) => { - println!("Error: {}", e); - continue; - } - }; - let block_number = match chain.get_current_block_number().await { - Ok(block_number) => block_number, - Err(e) => { - println!("Error: {}", e); - continue; - } - }; - - println!("block number: {}", block_number); - } - - let urls = pods_list.iter().map(|s| s.to_string()).collect(); - - let raft_node = RaftNode::new(1, urls).await?; - raft_node.run().await; - Ok(()) } -struct RaftNode { - node: Mutex>, - peers: HashMap, // Maps node index to URLs for simplicity -} - -impl RaftNode { - /// Initializes a new Raft node using URLs for peers. Assigns IDs based on order. - pub async fn new(my_id: u64, urls: Vec) -> Result { - let mut peers = HashMap::new(); - for (id, url) in urls.iter().enumerate() { - peers.insert(id as u64 + 1, url.clone()); // Node IDs are 1-indexed - } +use tonic::transport::Server; +use tonic::Request; +use tonic::Response; +use tonic::Status; - let config = Config { - id: my_id, - election_tick: 10, - heartbeat_tick: 3, - ..Default::default() - }; - config.validate()?; - let storage = MemStorage::new_with_conf_state((peers.keys().cloned().collect::>(), vec![])); +pub mod management { + tonic::include_proto!("management"); // Make sure this path is correct as per your setup +} - let logger = setup_logger(); - let node = RawNode::new(&config, storage, &logger)?; +use management::cluster_management_server::ClusterManagement; +use management::cluster_management_server::ClusterManagementServer; +use management::AddLearnerRequest; +use management::ChangeMembershipRequest; +use management::Node; +use management::ResultResponse; + +pub struct ClusterManagementService; + +#[tonic::async_trait] +impl ClusterManagement for ClusterManagementService { + async fn init_cluster(&self, _request: Request) -> Result, Status> { + // Mocked response for initializing a cluster + Ok(Response::new(ResultResponse { + success: true, + message: "Cluster initialized (mocked).".to_string(), + })) + } - Ok(Self { node: Mutex::new(node), peers }) + async fn add_learner(&self, _request: Request) -> Result, Status> { + // Mocked response for adding a learner + Ok(Response::new(ResultResponse { + success: true, + message: "Learner added (mocked).".to_string(), + })) } - pub async fn run(&self) { - let timeout = Duration::from_millis(100); - let mut interval = time::interval(timeout); - loop { - interval.tick().await; - let mut node = self.node.lock().await; - node.tick(); - if node.has_ready() { - self.handle_ready(&mut node).await; - } - } + async fn change_membership(&self, _request: Request) -> Result, Status> { + // Mocked response for changing membership + Ok(Response::new(ResultResponse { + success: true, + message: "Membership changed (mocked).".to_string(), + })) } +} - async fn handle_ready(&self, node: &mut RawNode) { - let ready = node.ready(); - if let Some(hs) = ready.hs() { - if hs.get_term() != node.raft.term { - info!("Term changed to {}", hs.get_term()); - let node_id = { - let node_guard = self.node.lock().await; // Lock the mutex asynchronously - node_guard.raft.id // Access the id of the Raft node - }; - if hs.get_vote() == node_id { - info!("Node {} became leader in term {}", node_id, hs.get_term()); - } else { - info!("Node {} observed new leader {} in term {}", node_id, hs.get_vote(), hs.get_term()); - } - } - } +pub async fn run_server() -> Result<()> { + let addr = "[::1]:50051".parse()?; + let svc = ClusterManagementServer::new(ClusterManagementService); - for msg in ready.messages() { - if let Some(_url) = self.peers.get(&msg.to) { - // Serialize the message manually to JSON - //XXX let msg_json = to_string(&msg).unwrap_or_else(|_| "{}".to_string()); // Handle error more gracefully in production - //XXX let send_future = self.http_client.post(url) - //XXX .header("Content-Type", "application/json") - //XXX .body(msg_json) - //XXX .send(); - //XXX if let Err(e) = send_future.await { - //XXX error!("Failed to send Raft message: {:?}", e); - //XXX } - } - } - node.advance(ready); - } + Server::builder().add_service(svc).serve(addr).await?; + + Ok(()) }