diff --git a/.github/workflows/_setup-e2e.yml b/.github/workflows/_setup-e2e.yml index 800829692..4355be647 100644 --- a/.github/workflows/_setup-e2e.yml +++ b/.github/workflows/_setup-e2e.yml @@ -42,9 +42,6 @@ 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 @@ -68,4 +65,4 @@ jobs: env: CARGO_PROFILE_RELEASE_DEBUG: 0 RUST_LOG: off - RELEASE: 1 + RELEASE: 1 \ No newline at end of file diff --git a/.github/workflows/comment-tag-report.yml b/.github/workflows/comment-tag-report.yml index c05120ca7..828776375 100644 --- a/.github/workflows/comment-tag-report.yml +++ b/.github/workflows/comment-tag-report.yml @@ -20,9 +20,6 @@ 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: @@ -42,3 +39,4 @@ 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 79d76f869..55e982149 100644 --- a/.github/workflows/doc-test.yml +++ b/.github/workflows/doc-test.yml @@ -47,11 +47,8 @@ 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 + run: just test-doc \ No newline at end of file diff --git a/.github/workflows/e2e-contracts-postgres.yml b/.github/workflows/e2e-contracts-postgres.yml index 8bfda24cc..2d43681c7 100644 --- a/.github/workflows/e2e-contracts-postgres.yml +++ b/.github/workflows/e2e-contracts-postgres.yml @@ -59,9 +59,6 @@ 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 3e7832b1e..bd0d0e0f2 100644 --- a/.github/workflows/e2e-contracts-rocks.yml +++ b/.github/workflows/e2e-contracts-rocks.yml @@ -60,9 +60,6 @@ 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 2a33ce7f6..4bbac338b 100644 --- a/.github/workflows/e2e-contracts.yml +++ b/.github/workflows/e2e-contracts.yml @@ -59,9 +59,6 @@ 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 b7de5f3f0..735d0a9a0 100644 --- a/.github/workflows/int-test.yml +++ b/.github/workflows/int-test.yml @@ -55,9 +55,6 @@ 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 7c1b88348..f52233283 100644 --- a/.github/workflows/lint-check.yml +++ b/.github/workflows/lint-check.yml @@ -53,11 +53,8 @@ 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 + run: just lint-check -2024-01-01 \ No newline at end of file diff --git a/.github/workflows/outdated.yml b/.github/workflows/outdated.yml index 73c4b0b86..2b2cc6586 100644 --- a/.github/workflows/outdated.yml +++ b/.github/workflows/outdated.yml @@ -18,11 +18,8 @@ jobs: uses: actions/checkout@v2 - 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 - + run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + - name: Set up Just uses: extractions/setup-just@v1 @@ -39,3 +36,4 @@ 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 4d9d85c6e..0ddffda45 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -54,11 +54,8 @@ 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 + run: just test-unit \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 7ccb64e02..094faca45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -151,21 +151,18 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "anyerror" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcd04a72664a65fb9adeae7ced0c98efd68a2b7a45adda8319b3bb36538404b8" -dependencies = [ - "serde", -] - [[package]] name = "anyhow" version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" +[[package]] +name = "arc-swap" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" + [[package]] name = "ark-ff" version = "0.3.0" @@ -315,7 +312,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -326,7 +323,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -356,7 +353,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -410,6 +407,17 @@ 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" @@ -522,7 +530,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -627,7 +635,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", "syn_derive", ] @@ -643,16 +651,6 @@ 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" @@ -815,7 +813,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -1042,7 +1040,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -1064,7 +1062,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ "darling_core 0.20.8", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -1123,7 +1121,7 @@ checksum = "d150dea618e920167e5973d70ae6ece4385b7164e0d799fe7c122dd0a5d912ad" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -1166,6 +1164,27 @@ 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" @@ -1187,7 +1206,7 @@ dependencies = [ "darling 0.20.8", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -1255,7 +1274,7 @@ checksum = "6fd000fd6988e73bbe993ea3db9b1aa64906ab88766d654973924340c8cddb42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -1465,12 +1484,6 @@ 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" @@ -1585,7 +1598,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -1628,6 +1641,15 @@ 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" @@ -1650,6 +1672,18 @@ 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" @@ -2008,6 +2042,25 @@ 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" @@ -2020,6 +2073,19 @@ 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" @@ -2161,12 +2227,32 @@ 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" @@ -2209,6 +2295,33 @@ 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" @@ -2283,7 +2396,7 @@ checksum = "ac13bc1e44cd00448a5ff485824a128629c945f02077804cb659c07a0ba41395" dependencies = [ "async-trait", "hyper 0.14.28", - "hyper-rustls", + "hyper-rustls 0.24.2", "jsonrpsee-core", "jsonrpsee-types", "serde", @@ -2369,6 +2482,19 @@ 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" @@ -2399,6 +2525,112 @@ 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" @@ -2436,6 +2668,16 @@ 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" @@ -2515,12 +2757,6 @@ 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" @@ -2589,7 +2825,7 @@ checksum = "38b4faf00617defe497754acde3024865bc143d44a86799b24e191ecff91354f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -2639,12 +2875,6 @@ 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" @@ -2819,7 +3049,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -2868,40 +3098,6 @@ 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" @@ -2925,7 +3121,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -3012,7 +3208,7 @@ dependencies = [ "glob", "once_cell", "opentelemetry", - "ordered-float", + "ordered-float 4.2.0", "percent-encoding", "rand", "thiserror", @@ -3020,6 +3216,15 @@ 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" @@ -3101,6 +3306,16 @@ 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" @@ -3128,13 +3343,37 @@ dependencies = [ ] [[package]] -name = "petgraph" -version = "0.6.4" +name = "pest_derive" +version = "2.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" +checksum = "f73541b156d32197eecda1a4014d7f868fd2bcb3c550d5386087cfba442bf69c" dependencies = [ - "fixedbitset", - "indexmap 2.2.6", + "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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2adbf29bb9776f28caece835398781ab24435585fe0d4dc1374a61db5accedca" +dependencies = [ + "once_cell", + "pest", + "sha2", ] [[package]] @@ -3192,7 +3431,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -3252,16 +3491,6 @@ 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" @@ -3313,6 +3542,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", + "syn 1.0.109", "version_check", ] @@ -3335,9 +3565,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" dependencies = [ "unicode-ident", ] @@ -3372,27 +3602,6 @@ dependencies = [ "prost-derive", ] -[[package]] -name = "prost-build" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -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 = "prost-derive" version = "0.12.4" @@ -3403,16 +3612,37 @@ dependencies = [ "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] -name = "prost-types" -version = "0.12.4" +name = "protobuf" +version = "2.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3235c33eb02c1f1e212abdbe34c78b264b038fb58ca612664343271e36e55ffe" +checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" dependencies = [ - "prost", + "bytes", +] + +[[package]] +name = "protobuf-build" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2df9942df2981178a930a72d442de47e2f0df18ad68e50a30f816f1848215ad0" +dependencies = [ + "bitflags 1.3.2", + "protobuf", + "protobuf-codegen", + "regex", +] + +[[package]] +name = "protobuf-codegen" +version = "2.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "033460afb75cf755fcfc16dfaed20b86468082a2ea24e05ac35ab4a099a017d6" +dependencies = [ + "protobuf", ] [[package]] @@ -3472,6 +3702,36 @@ 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" @@ -3538,6 +3798,17 @@ 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" @@ -3939,6 +4210,21 @@ 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" @@ -4067,6 +4353,30 @@ 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" @@ -4122,6 +4432,16 @@ 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" @@ -4292,6 +4612,16 @@ 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" @@ -4300,7 +4630,18 @@ checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "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", ] [[package]] @@ -4376,7 +4717,20 @@ dependencies = [ "darling 0.20.8", "proc-macro2", "quote", - "syn 2.0.58", + "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", ] [[package]] @@ -4495,6 +4849,74 @@ 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" @@ -4779,7 +5201,7 @@ dependencies = [ "async-trait", "binary_macros", "bincode", - "byte-unit 5.1.4", + "byte-unit", "chrono", "clap", "const-hex", @@ -4803,13 +5225,14 @@ 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", @@ -4817,9 +5240,8 @@ dependencies = [ "phf", "phf_codegen", "pin-project", - "prost", - "prost-types", "quote", + "raft", "rand", "reqwest", "revm", @@ -4829,6 +5251,9 @@ dependencies = [ "serde", "serde_json", "serde_with 3.8.1", + "slog", + "slog-async", + "slog-term", "sqlx", "stringreader", "strum", @@ -4837,8 +5262,6 @@ dependencies = [ "thiserror", "tokio", "tokio-util", - "tonic", - "tonic-build", "tower", "tracing", "tracing-opentelemetry", @@ -4895,7 +5318,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -4930,9 +5353,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.58" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ "proc-macro2", "quote", @@ -4948,7 +5371,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -4978,6 +5401,12 @@ 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" @@ -4996,6 +5425,17 @@ 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" @@ -5039,7 +5479,7 @@ checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -5152,7 +5592,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -5186,6 +5626,17 @@ 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" @@ -5209,6 +5660,7 @@ dependencies = [ "futures-io", "futures-sink", "pin-project-lite", + "slab", "tokio", "tracing", ] @@ -5267,7 +5719,7 @@ dependencies = [ "http 0.2.12", "http-body 0.4.6", "hyper 0.14.28", - "hyper-timeout", + "hyper-timeout 0.4.1", "percent-encoding", "pin-project", "prost", @@ -5279,19 +5731,6 @@ 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" @@ -5312,6 +5751,25 @@ 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" @@ -5344,7 +5802,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -5357,16 +5815,6 @@ 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" @@ -5427,6 +5875,15 @@ 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" @@ -5521,6 +5978,12 @@ 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" @@ -5579,15 +6042,6 @@ 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" @@ -5657,7 +6111,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", "wasm-bindgen-shared", ] @@ -5691,7 +6145,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5966,7 +6420,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -5986,7 +6440,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 9697043e1..b7eb0dd59 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,10 +84,12 @@ 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 } -tonic = "=0.11.0" -prost = "=0.12.4" -prost-types = "=0.12.4" -openraft = "=0.9.8" +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"] } bincode = { version = "=1.3.3", optional = true } @@ -108,7 +110,6 @@ const-hex = "=1.10.0" glob = "=0.3.1" nom = "=7.1.3" phf_codegen = "=0.11.2" -tonic-build = "=0.11.0" # ------------------------------------------------------------------------------ # Binaries @@ -151,7 +152,7 @@ perf = [] metrics = ["dep:metrics", "dep:metrics-exporter-prometheus"] # Enable RocksDB dependencies. -rocks = ["rocksdb", "bincode"] +rocks = ["rocksdb", "bincode", "raft"] # XXX: Enable external transaction parallel execution. executor-parallel = [] diff --git a/build.rs b/build.rs index 98854d5d5..1395e4559 100644 --- a/build.rs +++ b/build.rs @@ -14,7 +14,6 @@ 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 deleted file mode 100644 index dccfafe4f..000000000 --- a/proto/management.proto +++ /dev/null @@ -1,27 +0,0 @@ -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 e24fa7040..92580c645 100644 --- a/src/bin/run_with_importer.rs +++ b/src/bin/run_with_importer.rs @@ -14,6 +14,8 @@ 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(); @@ -21,21 +23,12 @@ 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 7dfaa50d7..80c28df13 100644 --- a/src/eth/storage/rocks/consensus.rs +++ b/src/eth/storage/rocks/consensus.rs @@ -1,67 +1,133 @@ //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(()) } -use tonic::transport::Server; -use tonic::Request; -use tonic::Response; -use tonic::Status; - -pub mod management { - tonic::include_proto!("management"); // Make sure this path is correct as per your setup +struct RaftNode { + node: Mutex>, + peers: HashMap, // Maps node index to URLs for simplicity } -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(), - })) - } +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 + } - 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(), - })) - } + 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![])); + + let logger = setup_logger(); + let node = RawNode::new(&config, storage, &logger)?; - 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(), - })) + Ok(Self { node: Mutex::new(node), peers }) } -} -pub async fn run_server() -> Result<()> { - let addr = "[::1]:50051".parse()?; - let svc = ClusterManagementServer::new(ClusterManagementService); + 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; + } + } + } - Server::builder().add_service(svc).serve(addr).await?; + 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()); + } + } + } - Ok(()) + 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); + } }