From e72625554a10706bef3b9b8dee5c4d0a2fbf2184 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Thu, 8 Feb 2024 09:00:34 -0500 Subject: [PATCH] Update CI (#143) * Update CI * FAILURE * Revert "FAILURE" This reverts commit a3b0828492e5d92296f55a77d5f496d33919887b. * Docs * Clippy * Cache jobs separately * Clippy fixes * Add protoc back to ci jobs * Fix docs * Last clippy fix * Speed up Free Space * Optimize CI * Turn on the rest of the jobs --- .github/workflows/byzantine.yml | 45 ------ .github/workflows/ci.yml | 152 ++++++++++++++++++ .github/workflows/conformance.yml | 45 ------ .github/workflows/docs.yml | 45 ------ .github/workflows/e2e.yml | 45 ------ .github/workflows/lint.yml | 66 -------- .github/workflows/unit.yml | 41 ----- core/network/src/cert_manager/x509.rs | 2 +- .../scripts/protobuf_codegen.sh | 2 +- .../avalanche-types/src/jsonrpc/client/mod.rs | 10 +- crates/avalanche-types/src/proto/mod.rs | 1 + .../subnet/rpc/database/corruptabledb/mod.rs | 2 +- .../src/subnet/rpc/database/memdb/iterator.rs | 6 +- .../src/subnet/rpc/database/memdb/mod.rs | 16 +- .../src/subnet/rpc/database/mod.rs | 2 +- .../src/subnet/rpc/database/nodb.rs | 2 +- .../rpc/database/rpcdb/client/iterator.rs | 6 +- .../subnet/rpc/database/rpcdb/client/mod.rs | 10 +- .../subnet/rpc/database/rpcdb/server/mod.rs | 2 +- .../subnet/rpc/database/versiondb/iterator.rs | 2 +- .../src/subnet/rpc/database/versiondb/mod.rs | 4 +- .../src/subnet/rpc/http/client.rs | 2 +- .../src/subnet/rpc/http/server.rs | 2 +- .../snow/engine/common/appsender/server.rs | 4 +- .../src/subnet/rpc/snow/engine/common/vm.rs | 1 + .../src/subnet/rpc/snowman/block.rs | 4 +- .../src/subnet/rpc/vm/server.rs | 2 +- .../tests/rpc/database/batch.rs | 12 +- .../tests/rpc/database/concurrency.rs | 6 +- .../tests/rpc/database/iterator.rs | 20 +-- .../avalanche-types/tests/rpc/database/mod.rs | 27 ++-- crates/avalanche-types/tests/rpc/shutdown.rs | 6 +- 32 files changed, 230 insertions(+), 362 deletions(-) delete mode 100644 .github/workflows/byzantine.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/conformance.yml delete mode 100644 .github/workflows/docs.yml delete mode 100644 .github/workflows/e2e.yml delete mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/unit.yml diff --git a/.github/workflows/byzantine.yml b/.github/workflows/byzantine.yml deleted file mode 100644 index 8fab3cc..0000000 --- a/.github/workflows/byzantine.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: ci-byzantine-tests - -on: - push: - branches: - - main - tags: - - "*" - pull_request: - -permissions: - contents: write - -jobs: - e2e: - name: avalanchego byzantine tests - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Remove unnecessary files - run: | - sudo rm -rf /usr/share/dotnet - sudo rm -rf "$AGENT_TOOLSDIRECTORY" - - name: Install linker - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - gcc-multilib - - name: Install protoc - uses: arduino/setup-protoc@v1 - with: - version: "3.x" - repo-token: ${{ secrets.GITHUB_TOKEN }} - - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - - - name: Install Go - uses: actions/setup-go@v4 - with: - go-version: '1.19' - - - name: Run e2e tests - run: scripts/tests.avalanchego-byzantine.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c31483e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,152 @@ +name: ci + +on: + push: + branches: + - main + tags: + - '*' + pull_request: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} + cancel-in-progress: true + +permissions: + contents: write + +jobs: + fmt: + runs-on: ubuntu-latest + steps: + - run: 'echo hello world' + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + - name: Checkout + uses: actions/checkout@v3 + - name: Run static analysis tests + shell: bash + run: cargo fmt --all --check + + docs: + runs-on: ubuntu-latest + steps: + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + - name: Checkout + uses: actions/checkout@v3 + - uses: Swatinem/rust-cache@v2 + - name: Run doc tests + run: RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --document-private-items -p avalanche-consensus -p avalanche-types + + clippy: + runs-on: ubuntu-latest + steps: + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + - name: Install protoc + uses: arduino/setup-protoc@v1 + with: + version: '3.x' + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Checkout + uses: actions/checkout@v3 + - uses: Swatinem/rust-cache@v2 + - name: Run static analysis tests + shell: bash + run: cargo clippy --all --all-features --tests --benches --examples -- -D warnings + + unit: + name: unit tests + runs-on: ubuntu-latest + steps: + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + with: + large-packages: false + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + - name: Install protoc + uses: arduino/setup-protoc@v1 + with: + version: '3.x' + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Checkout + uses: actions/checkout@v3 + - uses: Swatinem/rust-cache@v2 + - name: Run unit tests + run: cargo test --all-features -p avalanche-types -p avalanche-consensus + + avalanchego-integration-tests: + runs-on: ubuntu-latest + steps: + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + with: + large-packages: false + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + - name: Install protoc + uses: arduino/setup-protoc@v1 + with: + version: '3.x' + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Checkout + uses: actions/checkout@v3 + - uses: Swatinem/rust-cache@v2 + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: '1.19' + - name: Run e2e tests + run: scripts/tests.avalanchego-e2e.sh + + avalanchego-conformance-tests: + runs-on: ubuntu-latest + steps: + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + with: + large-packages: false + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + - name: Install protoc + uses: arduino/setup-protoc@v1 + with: + version: '3.x' + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Checkout + uses: actions/checkout@v3 + - uses: Swatinem/rust-cache@v2 + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: '1.19' + - name: Run e2e tests + run: scripts/tests.avalanchego-conformance.sh + + avalanchego-byzantine-tests: + runs-on: ubuntu-latest + steps: + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + with: + large-packages: false + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + - name: Install protoc + uses: arduino/setup-protoc@v1 + with: + version: '3.x' + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Checkout + uses: actions/checkout@v3 + - uses: Swatinem/rust-cache@v2 + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: '1.19' + - name: Run e2e tests + run: scripts/tests.avalanchego-byzantine.sh diff --git a/.github/workflows/conformance.yml b/.github/workflows/conformance.yml deleted file mode 100644 index bc92df9..0000000 --- a/.github/workflows/conformance.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: ci-conformance-tests - -on: - push: - branches: - - main - tags: - - "*" - pull_request: - -permissions: - contents: write - -jobs: - e2e: - name: avalanchego conformance tests - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Remove unnecessary files - run: | - sudo rm -rf /usr/share/dotnet - sudo rm -rf "$AGENT_TOOLSDIRECTORY" - - name: Install linker - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - gcc-multilib - - name: Install protoc - uses: arduino/setup-protoc@v1 - with: - version: "3.x" - repo-token: ${{ secrets.GITHUB_TOKEN }} - - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - - - name: Install Go - uses: actions/setup-go@v4 - with: - go-version: '1.19' - - - name: Run e2e tests - run: scripts/tests.avalanchego-conformance.sh diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml deleted file mode 100644 index 1be5791..0000000 --- a/.github/workflows/docs.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: ci-doc-tests - -on: - push: - branches: - - main - tags: - - "*" - pull_request: - -permissions: - contents: write - -jobs: - docs: - name: docs - runs-on: ubuntu-latest - steps: - - name: Remove unnecessary files - run: | - sudo rm -rf /usr/share/dotnet - sudo rm -rf "$AGENT_TOOLSDIRECTORY" - - name: Install linker - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - gcc-multilib - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - - name: Check Rust version - run: rustc --version - - name: Install protoc - uses: arduino/setup-protoc@v1 - with: - version: "3.x" - repo-token: ${{ secrets.GITHUB_TOKEN }} - - name: Checkout - uses: actions/checkout@v3 - - name: Set env var - shell: bash - run: export 'RUSTFLAGS=-D warnings' - # Fails the CI build if there are documentation warnings. - - name: Run doc tests - shell: bash - run: cargo doc --no-deps --all-features -p avalanche-consensus -p avalanche-types diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml deleted file mode 100644 index 50a385c..0000000 --- a/.github/workflows/e2e.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: ci-e2e-tests - -on: - push: - branches: - - main - tags: - - "*" - pull_request: - -permissions: - contents: write - -jobs: - e2e: - name: avalanchego integration tests - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Remove unnecessary files - run: | - sudo rm -rf /usr/share/dotnet - sudo rm -rf "$AGENT_TOOLSDIRECTORY" - - name: Install linker - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - gcc-multilib - - name: Install protoc - uses: arduino/setup-protoc@v1 - with: - version: "3.x" - repo-token: ${{ secrets.GITHUB_TOKEN }} - - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - - - name: Install Go - uses: actions/setup-go@v4 - with: - go-version: '1.19' - - - name: Run e2e tests - run: scripts/tests.avalanchego-e2e.sh diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index bbe3772..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: ci-clippy - -on: - push: - branches: - - main - tags: - - "*" - pull_request: - -permissions: - contents: write - -jobs: - fmt: - runs-on: ubuntu-latest - steps: - - name: Remove unnecessary files - run: | - sudo rm -rf /usr/share/dotnet - sudo rm -rf "$AGENT_TOOLSDIRECTORY" - - name: Install linker - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - gcc-multilib - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - - name: Check Rust version - run: rustc --version - - name: Install protoc - uses: arduino/setup-protoc@v1 - with: - version: "3.x" - repo-token: ${{ secrets.GITHUB_TOKEN }} - - name: Checkout - uses: actions/checkout@v3 - - name: Run static analysis tests - shell: bash - run: cargo fmt --all --check - clippy: - runs-on: ubuntu-latest - steps: - - name: Remove unnecessary files - run: | - sudo rm -rf /usr/share/dotnet - sudo rm -rf "$AGENT_TOOLSDIRECTORY" - - name: Install linker - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - gcc-multilib - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - - name: Check Rust version - run: rustc --version - - name: Install protoc - uses: arduino/setup-protoc@v1 - with: - version: "3.x" - repo-token: ${{ secrets.GITHUB_TOKEN }} - - name: Checkout - uses: actions/checkout@v3 - - name: Run static analysis tests - shell: bash - run: cargo clippy --all --all-features --tests --benches --examples diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml deleted file mode 100644 index e832614..0000000 --- a/.github/workflows/unit.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: ci-unit-tests - -on: - push: - branches: - - main - tags: - - "*" - pull_request: - -permissions: - contents: write - -jobs: - unit: - name: unit tests - runs-on: ubuntu-latest - steps: - - name: Remove unnecessary files - run: | - sudo rm -rf /usr/share/dotnet - sudo rm -rf "$AGENT_TOOLSDIRECTORY" - - name: Install linker - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - gcc-multilib - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - - name: Check Rust version - run: rustc --version - - name: Install protoc - uses: arduino/setup-protoc@v1 - with: - version: "3.x" - repo-token: ${{ secrets.GITHUB_TOKEN }} - - name: Checkout - uses: actions/checkout@v3 - - name: Run unit tests - shell: bash - run: scripts/tests.unit.sh diff --git a/core/network/src/cert_manager/x509.rs b/core/network/src/cert_manager/x509.rs index 0898b43..17f45cb 100644 --- a/core/network/src/cert_manager/x509.rs +++ b/core/network/src/cert_manager/x509.rs @@ -355,7 +355,7 @@ fn test_csr() { } } - fs::remove_file(&ca_key_path).unwrap(); + fs::remove_file(ca_key_path).unwrap(); fs::remove_file(&ca_cert_path).unwrap(); fs::remove_file(&csr_key_path).unwrap(); diff --git a/crates/avalanche-types/scripts/protobuf_codegen.sh b/crates/avalanche-types/scripts/protobuf_codegen.sh index fe63026..2b9bf93 100755 --- a/crates/avalanche-types/scripts/protobuf_codegen.sh +++ b/crates/avalanche-types/scripts/protobuf_codegen.sh @@ -14,7 +14,7 @@ if ! [[ "$0" =~ scripts/protobuf_codegen.sh ]]; then fi # ref. https://docs.buf.build/installation -BUF_VERSION='1.26.1' +BUF_VERSION='1.29.0' if [[ $(buf --version | cut -f2 -d' ') != "${BUF_VERSION}" ]]; then echo "could not find buf ${BUF_VERSION}, is it installed + in PATH?" exit 255 diff --git a/crates/avalanche-types/src/jsonrpc/client/mod.rs b/crates/avalanche-types/src/jsonrpc/client/mod.rs index 7e2acc8..a91b4cf 100644 --- a/crates/avalanche-types/src/jsonrpc/client/mod.rs +++ b/crates/avalanche-types/src/jsonrpc/client/mod.rs @@ -1,13 +1,5 @@ //! JSON-RPC client methods and URL utilities. -//! -//! Includes the following modules: -//! - [admin](crate::jsonrpc::client::admin) -//! - [evm](crate::jsonrpc::client::evm) -//! - [health](crate::jsonrpc::client::health) -//! - [info](crate::jsonrpc::client::info) -//! - [p](crate::jsonrpc::client::p) -//! - [url](crate::jsonrpc::client::url) -//! - [x](crate::jsonrpc::client::x) + pub mod admin; pub mod evm; pub mod health; diff --git a/crates/avalanche-types/src/proto/mod.rs b/crates/avalanche-types/src/proto/mod.rs index 10473ce..c52ed80 100644 --- a/crates/avalanche-types/src/proto/mod.rs +++ b/crates/avalanche-types/src/proto/mod.rs @@ -1,6 +1,7 @@ //! Generated protobuf stubs and helpers for Avalanche. //! //! ref. +#[allow(clippy::all)] pub mod pb; #[doc(hidden)] diff --git a/crates/avalanche-types/src/subnet/rpc/database/corruptabledb/mod.rs b/crates/avalanche-types/src/subnet/rpc/database/corruptabledb/mod.rs index fd140fb..9f7fb18 100644 --- a/crates/avalanche-types/src/subnet/rpc/database/corruptabledb/mod.rs +++ b/crates/avalanche-types/src/subnet/rpc/database/corruptabledb/mod.rs @@ -17,7 +17,7 @@ pub struct Database { } impl Database { - pub fn new(db: BoxedDatabase) -> BoxedDatabase { + pub fn new_boxed(db: BoxedDatabase) -> BoxedDatabase { Box::new(Self { db, corrupted: Arc::new(Mutex::new(utils::Errors::new())), diff --git a/crates/avalanche-types/src/subnet/rpc/database/memdb/iterator.rs b/crates/avalanche-types/src/subnet/rpc/database/memdb/iterator.rs index 28ef066..562615e 100644 --- a/crates/avalanche-types/src/subnet/rpc/database/memdb/iterator.rs +++ b/crates/avalanche-types/src/subnet/rpc/database/memdb/iterator.rs @@ -21,7 +21,11 @@ pub struct Iterator { } impl Iterator { - pub fn new(keys: Vec>, values: Vec>, closed: Arc) -> BoxedIterator { + pub fn new_boxed( + keys: Vec>, + values: Vec>, + closed: Arc, + ) -> BoxedIterator { Box::new(Self { keys, values, diff --git a/crates/avalanche-types/src/subnet/rpc/database/memdb/mod.rs b/crates/avalanche-types/src/subnet/rpc/database/memdb/mod.rs index f1e55f3..7f331c4 100644 --- a/crates/avalanche-types/src/subnet/rpc/database/memdb/mod.rs +++ b/crates/avalanche-types/src/subnet/rpc/database/memdb/mod.rs @@ -34,7 +34,7 @@ pub struct Database { } impl Database { - pub fn new() -> BoxedDatabase { + pub fn new_boxed() -> BoxedDatabase { Box::new(Self { state: Arc::new(RwLock::new(HashMap::new())), closed: Arc::new(AtomicBool::new(false)), @@ -157,7 +157,7 @@ impl super::iterator::Iteratee for Database { } } - Ok(iterator::Iterator::new( + Ok(iterator::Iterator::new_boxed( keys, values, Arc::clone(&self.closed), @@ -180,39 +180,39 @@ impl crate::subnet::rpc::database::Database for Database {} #[tokio::test] async fn test_memdb() { - let mut db = Database::new(); + let mut db = Database::new_boxed(); let _ = db.put("foo".as_bytes(), "bar".as_bytes()).await; let resp = db.get("notfound".as_bytes()).await; assert!(resp.is_err()); assert_eq!(resp.err().unwrap().kind(), io::ErrorKind::NotFound); - let mut db = Database::new(); + let mut db = Database::new_boxed(); let _ = db.close().await; let resp = db.put("foo".as_bytes(), "bar".as_bytes()).await; assert!(resp.is_err()); assert_eq!(resp.err().unwrap().to_string(), "database closed"); - let db = Database::new(); + let db = Database::new_boxed(); let _ = db.close().await; let resp = db.get("foo".as_bytes()).await; print!("found {:?}", resp); assert!(resp.is_err()); assert_eq!(resp.err().unwrap().to_string(), "database closed"); - let mut db = Database::new(); + let mut db = Database::new_boxed(); let _ = db.put("foo".as_bytes(), "bar".as_bytes()).await; let resp = db.has("foo".as_bytes()).await; assert!(resp.is_ok()); assert!(resp.unwrap()); - let mut db = Database::new(); + let mut db = Database::new_boxed(); let _ = db.put("foo".as_bytes(), "bar".as_bytes()).await; let _ = db.delete("foo".as_bytes()).await; let resp = db.has("foo".as_bytes()).await; assert!(resp.is_ok()); assert!(!resp.unwrap()); - let db = Database::new(); + let db = Database::new_boxed(); let resp = db.health_check().await; assert!(resp.is_ok()); let _ = db.close().await; diff --git a/crates/avalanche-types/src/subnet/rpc/database/mod.rs b/crates/avalanche-types/src/subnet/rpc/database/mod.rs index 143690e..b529f70 100644 --- a/crates/avalanche-types/src/subnet/rpc/database/mod.rs +++ b/crates/avalanche-types/src/subnet/rpc/database/mod.rs @@ -81,7 +81,7 @@ pub trait VersionedDatabase { #[tokio::test] async fn clone_box_test() { // create box and mutate underlying hashmap - let mut db = memdb::Database::new(); + let mut db = memdb::Database::new_boxed(); let resp = db.put("foo".as_bytes(), "bar".as_bytes()).await; assert!(resp.is_ok()); diff --git a/crates/avalanche-types/src/subnet/rpc/database/nodb.rs b/crates/avalanche-types/src/subnet/rpc/database/nodb.rs index f61cb89..3d65aff 100644 --- a/crates/avalanche-types/src/subnet/rpc/database/nodb.rs +++ b/crates/avalanche-types/src/subnet/rpc/database/nodb.rs @@ -10,7 +10,7 @@ pub struct Iterator { /// /// ref. impl Iterator { - pub fn new(err: Option) -> BoxedIterator { + pub fn new_boxed(err: Option) -> BoxedIterator { Box::new(Iterator { err }) } } diff --git a/crates/avalanche-types/src/subnet/rpc/database/rpcdb/client/iterator.rs b/crates/avalanche-types/src/subnet/rpc/database/rpcdb/client/iterator.rs index 7cd9c1d..24f3b1a 100644 --- a/crates/avalanche-types/src/subnet/rpc/database/rpcdb/client/iterator.rs +++ b/crates/avalanche-types/src/subnet/rpc/database/rpcdb/client/iterator.rs @@ -36,7 +36,11 @@ pub struct Iterator { } impl Iterator { - pub fn new(db: DatabaseClient, id: u64, closed: Arc) -> BoxedIterator { + pub fn new_boxed( + db: DatabaseClient, + id: u64, + closed: Arc, + ) -> BoxedIterator { Box::new(Self { id, data: vec![], diff --git a/crates/avalanche-types/src/subnet/rpc/database/rpcdb/client/mod.rs b/crates/avalanche-types/src/subnet/rpc/database/rpcdb/client/mod.rs index 6ac689e..89958d8 100644 --- a/crates/avalanche-types/src/subnet/rpc/database/rpcdb/client/mod.rs +++ b/crates/avalanche-types/src/subnet/rpc/database/rpcdb/client/mod.rs @@ -41,7 +41,7 @@ pub struct DatabaseClient { } impl DatabaseClient { - pub fn new(client_conn: Channel) -> BoxedDatabase { + pub fn new_boxed(client_conn: Channel) -> BoxedDatabase { Box::new(Self { inner: RpcDbDatabaseClient::new(client_conn) .max_decoding_message_size(usize::MAX) @@ -186,14 +186,14 @@ impl database::iterator::Iteratee for DatabaseClient { }) .await { - Ok(resp) => Ok(iterator::Iterator::new( + Ok(resp) => Ok(iterator::Iterator::new_boxed( self.inner.clone(), resp.into_inner().id, Arc::clone(&self.closed), )), - Err(s) => Ok(crate::subnet::rpc::database::nodb::Iterator::new(Some( - errors::from_status(s), - ))), + Err(s) => Ok(crate::subnet::rpc::database::nodb::Iterator::new_boxed( + Some(errors::from_status(s)), + )), } } } diff --git a/crates/avalanche-types/src/subnet/rpc/database/rpcdb/server/mod.rs b/crates/avalanche-types/src/subnet/rpc/database/rpcdb/server/mod.rs index 4222c21..65cc5c8 100644 --- a/crates/avalanche-types/src/subnet/rpc/database/rpcdb/server/mod.rs +++ b/crates/avalanche-types/src/subnet/rpc/database/rpcdb/server/mod.rs @@ -39,7 +39,7 @@ pub struct Server { } impl Server { - pub fn new(db: BoxedDatabase) -> impl pb::rpcdb::database_server::Database { + pub fn new_boxed(db: BoxedDatabase) -> impl pb::rpcdb::database_server::Database { Self { inner: Arc::new(RwLock::new(db)), iterators: Arc::new(RwLock::new(HashMap::new())), diff --git a/crates/avalanche-types/src/subnet/rpc/database/versiondb/iterator.rs b/crates/avalanche-types/src/subnet/rpc/database/versiondb/iterator.rs index 285c761..7b2e9f3 100644 --- a/crates/avalanche-types/src/subnet/rpc/database/versiondb/iterator.rs +++ b/crates/avalanche-types/src/subnet/rpc/database/versiondb/iterator.rs @@ -34,7 +34,7 @@ pub struct ValueDelete { } impl Iterator { - pub fn new( + pub fn new_boxed( keys: Vec>, values: Vec, closed: Arc, diff --git a/crates/avalanche-types/src/subnet/rpc/database/versiondb/mod.rs b/crates/avalanche-types/src/subnet/rpc/database/versiondb/mod.rs index 4e8932e..2c442b4 100644 --- a/crates/avalanche-types/src/subnet/rpc/database/versiondb/mod.rs +++ b/crates/avalanche-types/src/subnet/rpc/database/versiondb/mod.rs @@ -184,7 +184,7 @@ impl database::iterator::Iteratee for Database { } } - Ok(iterator::Iterator::new( + Ok(iterator::Iterator::new_boxed( keys, values, Arc::clone(&self.closed), @@ -252,7 +252,7 @@ async fn iterate_test() { iterator::Iteratee, memdb, Commitable, KeyValueReaderWriterDeleter, }; - let base_db = memdb::Database::new(); + let base_db = memdb::Database::new_boxed(); let batch = base_db.new_batch().await.unwrap(); let mut db = Database::new(base_db, batch); diff --git a/crates/avalanche-types/src/subnet/rpc/http/client.rs b/crates/avalanche-types/src/subnet/rpc/http/client.rs index 06172f7..ee48c1e 100644 --- a/crates/avalanche-types/src/subnet/rpc/http/client.rs +++ b/crates/avalanche-types/src/subnet/rpc/http/client.rs @@ -10,7 +10,7 @@ pub struct Client { } impl Client { - pub fn new(client_conn: Channel) -> Box { + pub fn new_handler(client_conn: Channel) -> Box { Box::new(Client { inner: pb::http::http_client::HttpClient::new(client_conn) .max_decoding_message_size(usize::MAX) diff --git a/crates/avalanche-types/src/subnet/rpc/http/server.rs b/crates/avalanche-types/src/subnet/rpc/http/server.rs index 6d14d6f..7cbc513 100644 --- a/crates/avalanche-types/src/subnet/rpc/http/server.rs +++ b/crates/avalanche-types/src/subnet/rpc/http/server.rs @@ -20,7 +20,7 @@ impl Server where T: Handle + Send + Sync + 'static, { - pub fn new(handler: T) -> impl pb::http::http_server::Http { + pub fn new(handler: T) -> Self { Server { handle: Arc::new(handler), } diff --git a/crates/avalanche-types/src/subnet/rpc/snow/engine/common/appsender/server.rs b/crates/avalanche-types/src/subnet/rpc/snow/engine/common/appsender/server.rs index c2296fc..57442b8 100644 --- a/crates/avalanche-types/src/subnet/rpc/snow/engine/common/appsender/server.rs +++ b/crates/avalanche-types/src/subnet/rpc/snow/engine/common/appsender/server.rs @@ -24,9 +24,7 @@ pub struct Server { /// A gRPC server which wraps a subnet::rpc::database::Database impl allowing client control over over RPC. impl Server { - pub fn new( - appsender: Box, - ) -> impl pb::appsender::app_sender_server::AppSender { + pub fn new(appsender: Box) -> Self { Server { inner: Arc::new(RwLock::new(appsender)), } diff --git a/crates/avalanche-types/src/subnet/rpc/snow/engine/common/vm.rs b/crates/avalanche-types/src/subnet/rpc/snow/engine/common/vm.rs index cb061dd..5aaa395 100644 --- a/crates/avalanche-types/src/subnet/rpc/snow/engine/common/vm.rs +++ b/crates/avalanche-types/src/subnet/rpc/snow/engine/common/vm.rs @@ -30,6 +30,7 @@ pub trait CommonVm: AppHandler + Connector + Checkable { type StaticHandler: Handle; type ValidatorState: validators::State; + #[allow(clippy::too_many_arguments)] async fn initialize( &mut self, ctx: Option>, diff --git a/crates/avalanche-types/src/subnet/rpc/snowman/block.rs b/crates/avalanche-types/src/subnet/rpc/snowman/block.rs index 7d3693b..1eb3f9b 100644 --- a/crates/avalanche-types/src/subnet/rpc/snowman/block.rs +++ b/crates/avalanche-types/src/subnet/rpc/snowman/block.rs @@ -31,8 +31,8 @@ pub trait ChainVm: CommonVm + BatchedChainVm + Getter + Parser { /// TODO: Remove after v1.11.x activates. async fn verify_height_index(&self) -> Result<()>; - /// Returns the ID of the block that was accepted with [height]. - /// Returns ErrNotFound if the [height] index is unknown. + /// Returns the ID of the block that was accepted with `height`. + /// Returns ErrNotFound if the `height` index is unknown. async fn get_block_id_at_height(&self, height: u64) -> Result; /// Returns whether state sync is enabled. diff --git a/crates/avalanche-types/src/subnet/rpc/vm/server.rs b/crates/avalanche-types/src/subnet/rpc/vm/server.rs index ec7e9ee..efaaf47 100644 --- a/crates/avalanche-types/src/subnet/rpc/vm/server.rs +++ b/crates/avalanche-types/src/subnet/rpc/vm/server.rs @@ -157,7 +157,7 @@ where })?; let vdb = versioned_database::VersionedDatabase::new( - corruptabledb::Database::new(DatabaseClient::new(client_conn)), + corruptabledb::Database::new_boxed(DatabaseClient::new_boxed(client_conn)), version, ); versioned_dbs.push(vdb); diff --git a/crates/avalanche-types/tests/rpc/database/batch.rs b/crates/avalanche-types/tests/rpc/database/batch.rs index 04a2e01..a611df7 100644 --- a/crates/avalanche-types/tests/rpc/database/batch.rs +++ b/crates/avalanche-types/tests/rpc/database/batch.rs @@ -16,7 +16,7 @@ use tonic::transport::Channel; // Ensure batched writes work as expected. #[tokio::test] async fn batch_put_test() { - let server = RpcDb::new(MemDb::new()); + let server = RpcDb::new_boxed(MemDb::new_boxed()); let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = listener.local_addr().unwrap(); @@ -30,7 +30,7 @@ async fn batch_put_test() { .await .unwrap(); - let mut db = CorruptableDb::new(DatabaseClient::new(client_conn)); + let mut db = CorruptableDb::new_boxed(DatabaseClient::new_boxed(client_conn)); let key = "hello".as_bytes(); let value = "world".as_bytes(); @@ -66,7 +66,7 @@ async fn batch_put_test() { #[tokio::test] async fn batch_delete_test() { - let server = RpcDb::new(MemDb::new()); + let server = RpcDb::new_boxed(MemDb::new_boxed()); let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = listener.local_addr().unwrap(); @@ -80,7 +80,7 @@ async fn batch_delete_test() { .await .unwrap(); - let mut db = CorruptableDb::new(DatabaseClient::new(client_conn)); + let mut db = CorruptableDb::new_boxed(DatabaseClient::new_boxed(client_conn)); let key = "hello".as_bytes(); let value = "world".as_bytes(); @@ -111,7 +111,7 @@ async fn batch_delete_test() { // when it is reset. #[tokio::test] async fn batch_reset_test() { - let server = RpcDb::new(MemDb::new()); + let server = RpcDb::new_boxed(MemDb::new_boxed()); let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = listener.local_addr().unwrap(); @@ -125,7 +125,7 @@ async fn batch_reset_test() { .await .unwrap(); - let mut db = CorruptableDb::new(DatabaseClient::new(client_conn)); + let mut db = CorruptableDb::new_boxed(DatabaseClient::new_boxed(client_conn)); let key = "hello".as_bytes(); let value = "world".as_bytes(); diff --git a/crates/avalanche-types/tests/rpc/database/concurrency.rs b/crates/avalanche-types/tests/rpc/database/concurrency.rs index 525fab3..e0f0993 100644 --- a/crates/avalanche-types/tests/rpc/database/concurrency.rs +++ b/crates/avalanche-types/tests/rpc/database/concurrency.rs @@ -11,8 +11,8 @@ use tonic::transport::Channel; #[tokio::test(flavor = "multi_thread")] async fn rpcdb_mutation_test() { - let db = MemDb::new(); - let server = RpcDb::new(db); + let db = MemDb::new_boxed(); + let server = RpcDb::new_boxed(db); let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = listener.local_addr().unwrap(); @@ -26,7 +26,7 @@ async fn rpcdb_mutation_test() { .await .unwrap(); - let client = DatabaseClient::new(client_conn); + let client = DatabaseClient::new_boxed(client_conn); let mut futures = FuturesUnordered::new(); // 1000 requests for i in 0..1000_i32 { diff --git a/crates/avalanche-types/tests/rpc/database/iterator.rs b/crates/avalanche-types/tests/rpc/database/iterator.rs index 3ad576b..ce918a1 100644 --- a/crates/avalanche-types/tests/rpc/database/iterator.rs +++ b/crates/avalanche-types/tests/rpc/database/iterator.rs @@ -14,7 +14,7 @@ use tonic::transport::Channel; // contents lexicographically. #[tokio::test] async fn iterator_test() { - let server = RpcDb::new(MemDb::new()); + let server = RpcDb::new_boxed(MemDb::new_boxed()); let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = listener.local_addr().unwrap(); @@ -28,7 +28,7 @@ async fn iterator_test() { .await .unwrap(); - let mut db = CorruptableDb::new(DatabaseClient::new(client_conn)); + let mut db = CorruptableDb::new_boxed(DatabaseClient::new_boxed(client_conn)); let key1 = "hello1".as_bytes(); let value1 = "world1".as_bytes(); @@ -63,7 +63,7 @@ async fn iterator_test() { // start mid way through the database. #[tokio::test] async fn iterator_start_test() { - let server = RpcDb::new(MemDb::new()); + let server = RpcDb::new_boxed(MemDb::new_boxed()); let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = listener.local_addr().unwrap(); @@ -77,7 +77,7 @@ async fn iterator_start_test() { .await .unwrap(); - let mut db = CorruptableDb::new(DatabaseClient::new(client_conn)); + let mut db = CorruptableDb::new_boxed(DatabaseClient::new_boxed(client_conn)); let key1 = "hello1".as_bytes(); let value1 = "world1".as_bytes(); @@ -104,7 +104,7 @@ async fn iterator_start_test() { // keys missing the provided prefix. #[tokio::test] async fn iterator_prefix_test() { - let server = RpcDb::new(MemDb::new()); + let server = RpcDb::new_boxed(MemDb::new_boxed()); let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = listener.local_addr().unwrap(); @@ -118,7 +118,7 @@ async fn iterator_prefix_test() { .await .unwrap(); - let mut db = CorruptableDb::new(DatabaseClient::new(client_conn)); + let mut db = CorruptableDb::new_boxed(DatabaseClient::new_boxed(client_conn)); let key1 = "hello1".as_bytes(); let value1 = "world1".as_bytes(); @@ -152,7 +152,7 @@ async fn iterator_prefix_test() { // next() can still serve its current value after the underlying DB was closed. #[tokio::test] async fn iterator_error_test() { - let server = RpcDb::new(MemDb::new()); + let server = RpcDb::new_boxed(MemDb::new_boxed()); let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = listener.local_addr().unwrap(); @@ -166,7 +166,7 @@ async fn iterator_error_test() { .await .unwrap(); - let mut db = CorruptableDb::new(DatabaseClient::new(client_conn)); + let mut db = CorruptableDb::new_boxed(DatabaseClient::new_boxed(client_conn)); let key1 = "hello1".as_bytes(); let value1 = "world1".as_bytes(); @@ -200,7 +200,7 @@ async fn iterator_error_test() { // released still reports the error correctly. #[tokio::test] async fn iterator_error_after_release_test() { - let server = RpcDb::new(MemDb::new()); + let server = RpcDb::new_boxed(MemDb::new_boxed()); let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = listener.local_addr().unwrap(); @@ -214,7 +214,7 @@ async fn iterator_error_after_release_test() { .await .unwrap(); - let mut db = CorruptableDb::new(DatabaseClient::new(client_conn)); + let mut db = CorruptableDb::new_boxed(DatabaseClient::new_boxed(client_conn)); let key1 = "hello1".as_bytes(); let value1 = "world1".as_bytes(); diff --git a/crates/avalanche-types/tests/rpc/database/mod.rs b/crates/avalanche-types/tests/rpc/database/mod.rs index 6f9979b..982338c 100644 --- a/crates/avalanche-types/tests/rpc/database/mod.rs +++ b/crates/avalanche-types/tests/rpc/database/mod.rs @@ -25,8 +25,8 @@ async fn rpcdb_mutation_test() { let bar_value = "bar".as_bytes().to_vec(); let baz_value = "baz".as_bytes().to_vec(); - let db = MemDb::new(); - let server = RpcDb::new(db); + let db = MemDb::new_boxed(); + let server = RpcDb::new_boxed(db); let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = listener.local_addr().unwrap(); @@ -40,7 +40,7 @@ async fn rpcdb_mutation_test() { .await .unwrap(); - let mut client = DatabaseClient::new(client_conn); + let mut client = DatabaseClient::new_boxed(client_conn); log::info!("put foo:bar"); let resp = client.put("foo".as_bytes(), "bar".as_bytes()).await; @@ -97,8 +97,8 @@ async fn corruptibledb_mutation_test() { let bar_value = "bar".as_bytes().to_vec(); - let memdb = MemDb::new(); - let mut corruptible = CorruptableDb::new(memdb); + let memdb = MemDb::new_boxed(); + let mut corruptible = CorruptableDb::new_boxed(memdb); log::info!("put foo:bar"); let resp = corruptible.put("foo".as_bytes(), "bar".as_bytes()).await; @@ -148,8 +148,8 @@ async fn test_rpcdb_corruptible() { let bar_value = "bar".as_bytes().to_vec(); let baz_value = "baz".as_bytes().to_vec(); - let memdb = MemDb::new(); - let rpc_server = RpcDb::new(memdb); + let memdb = MemDb::new_boxed(); + let rpc_server = RpcDb::new_boxed(memdb); let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = listener.local_addr().unwrap(); @@ -163,8 +163,8 @@ async fn test_rpcdb_corruptible() { .await .unwrap(); - let db = DatabaseClient::new(client_conn); - let mut client = CorruptableDb::new(db); + let db = DatabaseClient::new_boxed(client_conn); + let mut client = CorruptableDb::new_boxed(db); log::info!("put foo:bar"); let resp = client.put("foo".as_bytes(), "bar".as_bytes()).await; @@ -223,8 +223,8 @@ async fn test_db_manager() { let bar_value = "bar".as_bytes().to_vec(); let baz_value = "baz".as_bytes().to_vec(); - let memdb = MemDb::new(); - let rpc_server = RpcDb::new(memdb); + let memdb = MemDb::new_boxed(); + let rpc_server = RpcDb::new_boxed(memdb); let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = listener.local_addr().unwrap(); @@ -238,7 +238,10 @@ async fn test_db_manager() { .await .unwrap(); - let vdb = VersionedDatabase::new(DatabaseClient::new(client_conn), Version::new(0, 0, 1)); + let vdb = VersionedDatabase::new( + DatabaseClient::new_boxed(client_conn), + Version::new(0, 0, 1), + ); let databases: Vec = vec![vdb]; diff --git a/crates/avalanche-types/tests/rpc/shutdown.rs b/crates/avalanche-types/tests/rpc/shutdown.rs index a015ce8..48ab913 100644 --- a/crates/avalanche-types/tests/rpc/shutdown.rs +++ b/crates/avalanche-types/tests/rpc/shutdown.rs @@ -19,8 +19,8 @@ async fn test_shutdown() { let (tx, _rx): (Sender<()>, Receiver<()>) = tokio::sync::broadcast::channel(1); // setup rpcdb service - let memdb = MemDb::new(); - let server = RpcDb::new(memdb); + let memdb = MemDb::new_boxed(); + let server = RpcDb::new_boxed(memdb); let svc = DatabaseServer::new(server); let addr = utils::new_socket_addr(); @@ -35,7 +35,7 @@ async fn test_shutdown() { .connect() .await .unwrap(); - let mut client = DatabaseClient::new(client_conn); + let mut client = DatabaseClient::new_boxed(client_conn); // client request ok let resp = client.put("foo".as_bytes(), "bar".as_bytes()).await;