diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index f8ef3b2b..b01ab1f8 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -6,7 +6,7 @@ env: CARGO_TERM_COLOR: always RUST_BACKTRACE: 1 # https://releases.rs/docs/1.83.0/ release date - NIGHTLY_TOOLCHAIN: nightly-2024-11-28 + NIGHTLY_TOOLCHAIN: nightly-2025-02-20 # Cancel in progress workflows on pull_requests. # https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value @@ -15,46 +15,6 @@ concurrency: cancel-in-progress: true jobs: - # TODO move to a release ci - # build: - # runs-on: ubuntu-latest - - # steps: - # - name: Checkout - # uses: actions/checkout@v4 - # with: - # path: snarkos-test - - # - name: Checkout snarkOS - # uses: actions/checkout@v4 - # with: - # repository: AleoNet/snarkOS - # path: snarkos - - # - name: Checkout snarkVM - # uses: actions/checkout@v4 - # with: - # repository: AleoNet/snarkVM - # path: snarkvm - - # - name: Use mold linker - # uses: rui314/setup-mold@v1 - - # - name: Install nightly and cranelift - # uses: dtolnay/rust-toolchain@nightly - # with: - # toolchain: nightly - # components: rustc-codegen-cranelift-preview - - # - uses: Swatinem/rust-cache@v2 - # with: - # key: cache-v1 - - # - name: Build - # env: - # RUSTFLAGS: -Zcodegen-backend=cranelift -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort - # run: cargo +${{ env.NIGHTLY_TOOLCHAIN }} build --verbose - fmt: runs-on: ubuntu-latest @@ -71,12 +31,63 @@ jobs: - name: ๐Ÿ“‹ Format Check run: cargo +${{ env.NIGHTLY_TOOLCHAIN }} fmt -- --check - test: + filter: runs-on: ubuntu-latest - permissions: read-all - # env: - # RUSTFLAGS: -Zcodegen-backend=cranelift + outputs: + top_toml: ${{ steps.filter.outputs.top_toml }} + aot: ${{ steps.filter.outputs.aot }} + checkpoint: ${{ steps.filter.outputs.checkpoint }} + common: ${{ steps.filter.outputs.common }} + snops: ${{ steps.filter.outputs.snops }} + agent: ${{ steps.filter.outputs.agent }} + scli: ${{ steps.filter.outputs.scli }} + steps: + - uses: actions/checkout@v4 + - id: filter + uses: dorny/paths-filter@v3 + with: + base: ${{ github.ref_name }} + filters: | + top_toml: + - 'Cargo.toml' + aot: + - 'crates/aot/**/*' + checkpoint: + - 'crates/checkpoint/**/*' + snops: + - 'crates/controlplane/**/*' + agent: + - 'crates/agent/**/*' + scli: + - 'crates/cli/**/*' + common: + - 'crates/common/**/*' + crate-checks: + runs-on: ubuntu-latest + needs: [filter] + env: + TOP_TOML: ${{ needs.filter.outputs.top_toml }} + AOT: ${{ needs.filter.outputs.aot }} + CHECKPOINT: ${{ needs.filter.outputs.checkpoint }} + COMMON: ${{ needs.filter.outputs.common }} + SNOPS: ${{ needs.filter.outputs.snops }} + AGENT: ${{ needs.filter.outputs.agent }} + SCLI: ${{ needs.filter.outputs.scli }} + strategy: + fail-fast: false + matrix: + crate: + - { name: "aot", package: "snarkos-aot", dir: "crates/aot" } + - { + name: "checkpoint", + package: "snops-checkpoint", + dir: "crates/checkpoint", + } + - { name: "common", package: "snops-common", dir: "crates/common" } + - { name: "snops", package: "snops", dir: "crates/controlplane" } + - { name: "agent", package: "snops-agent", dir: "crates/agent" } + - { name: "snops-cli", package: "snops-cli", dir: "crates/cli" } steps: - name: ๐Ÿ“ฅ Checkout uses: actions/checkout@v4 @@ -99,74 +110,42 @@ jobs: - name: โ˜๏ธ Install Nextest uses: taiki-e/install-action@nextest - # - name: โ˜๏ธ Install cargo-machete - # run: cargo install cargo-machete + - name: โ˜๏ธ Install cargo-machete + uses: taiki-e/install-action@cargo-machete - # - name: ๐Ÿ“‹ Clippy Check - # env: - # RUSTFLAGS: -Zcodegen-backend=cranelift - # run: cargo +${{ env.NIGHTLY_TOOLCHAIN }} clippy --all --all-targets -- -D warnings + - name: โ˜๏ธ Install cargo-binstall + uses: taiki-e/install-action@cargo-binstall - # - name: ๐Ÿ“‹ Check Unused Deps - # if: always() - # env: - # RUSTFLAGS: -Zcodegen-backend=cranelift - # run: cargo machete + - name: โ˜๏ธ Install cargo-msrv + run: cargo binstall --version 0.18.1 --no-confirm cargo-msrv --force - - uses: dorny/paths-filter@v3 - id: changes - with: - base: ${{ github.ref_name }} - filters: | - top_toml: - - 'Cargo.toml' - aot: - - 'crates/aot/**/*' - checkpoint: - - 'crates/checkpoint/**/*' - control_plane: - - 'crates/controlplane/**/*' - agent: - - 'crates/agent/**/*' - scli: - - 'crates/cli/**/*' - common: - - 'crates/common/**/*' + - name: โ˜๏ธ Install cargo-hack + uses: taiki-e/install-action@cargo-hack + + - name: โ˜๏ธ Install cargo-minimal-versions + uses: taiki-e/install-action@cargo-minimal-versions + + - name: ๐Ÿงช Test ${{ matrix.crate.name }} + if: always() && ${{ env.TOP_TOML == 'true' || (matrix.crate.name == 'aot' && env.AOT == 'true') || (matrix.crate.name == 'checkpoint' && env.CHECKPOINT == 'true') || (matrix.crate.name == 'common' && env.COMMON == 'true') || (matrix.crate.name == 'snops' && env.CONTROL_PLANE == 'true') || (matrix.crate.name == 'agent' && env.AGENT == 'true') || (matrix.crate.name == 'scli' && env.SCLI == 'true') }} + env: + RUSTFLAGS: ${{ (matrix.crate.name == 'aot' || matrix.crate.name == 'checkpoint' || matrix.crate.name == 'common' || matrix.crate.name == 'snops') && '-Zcodegen-backend=cranelift' || '' }} + run: cargo +${{ env.NIGHTLY_TOOLCHAIN }} nextest run -p ${{ matrix.crate.package }} --verbose --fail-fast --all-features --no-tests=warn + + - name: ๐Ÿšฏ Unused Deps ${{ matrix.crate.name }} + if: always() && ${{ env.TOP_TOML == 'true' || (matrix.crate.name == 'aot' && env.AOT == 'true') || (matrix.crate.name == 'checkpoint' && env.CHECKPOINT == 'true') || (matrix.crate.name == 'common' && env.COMMON == 'true') || (matrix.crate.name == 'snops' && env.CONTROL_PLANE == 'true') || (matrix.crate.name == 'agent' && env.AGENT == 'true') || (matrix.crate.name == 'scli' && env.SCLI == 'true') }} + run: cd ${{ matrix.crate.dir }} && cargo +${{ env.NIGHTLY_TOOLCHAIN }} machete + + - name: ๐Ÿฆ€ MSRV ${{ matrix.crate.name }} + if: always() && ${{ env.TOP_TOML == 'true' || (matrix.crate.name == 'aot' && env.AOT == 'true') || (matrix.crate.name == 'checkpoint' && env.CHECKPOINT == 'true') || (matrix.crate.name == 'common' && env.COMMON == 'true') || (matrix.crate.name == 'snops' && env.CONTROL_PLANE == 'true') || (matrix.crate.name == 'agent' && env.AGENT == 'true') || (matrix.crate.name == 'scli' && env.SCLI == 'true') }} + run: cargo msrv --manifest-path ${{ matrix.crate.dir }}/Cargo.toml verify --output-format minimal + + - name: ๐Ÿ•ต๏ธ Minimal Versions ${{ matrix.crate.name }} + if: always() && ${{ env.TOP_TOML == 'true' || (matrix.crate.name == 'aot' && env.AOT == 'true') || (matrix.crate.name == 'checkpoint' && env.CHECKPOINT == 'true') || (matrix.crate.name == 'common' && env.COMMON == 'true') || (matrix.crate.name == 'snops' && env.CONTROL_PLANE == 'true') || (matrix.crate.name == 'agent' && env.AGENT == 'true') || (matrix.crate.name == 'scli' && env.SCLI == 'true') }} + continue-on-error: true + run: cargo +${{ env.NIGHTLY_TOOLCHAIN }} minimal-versions check -p ${{ matrix.crate.package }} - - name: ๐Ÿงช Test All - if: steps.changes.outputs.top_toml == 'true' - run: cargo +${{ env.NIGHTLY_TOOLCHAIN }} nextest run --all --verbose --fail-fast --all-features --exclude snops-agent --exclude xtask --no-tests=warn - - - name: ๐Ÿงช Test Aot - if: steps.changes.outputs.aot == 'true' && steps.changes.outputs.top_toml == 'false' - run: cargo +${{ env.NIGHTLY_TOOLCHAIN }} nextest run -p snarkos-aot --verbose --fail-fast --all-features --no-tests=warn - - - name: ๐Ÿงช Test Checkpoint - # env: - # RUSTFLAGS: -Zcodegen-backend=cranelift - if: steps.changes.outputs.checkpoint == 'true' && steps.changes.outputs.top_toml == 'false' - run: cargo +${{ env.NIGHTLY_TOOLCHAIN }} nextest run -p snops-checkpoint --verbose --fail-fast --all-features --no-tests=warn - - - name: ๐Ÿงช Test Common - # env: - # RUSTFLAGS: -Zcodegen-backend=cranelift - if: steps.changes.outputs.common == 'true' && steps.changes.outputs.top_toml == 'false' - run: cargo +${{ env.NIGHTLY_TOOLCHAIN }} nextest run -p snops-common --verbose --fail-fast --all-features --no-tests=warn - - - name: ๐Ÿงช Test Control Plane - # env: - # RUSTFLAGS: -Zcodegen-backend=cranelift - if: (steps.changes.outputs.control_plane == 'true' || steps.changes.outputs.common == 'true') && steps.changes.outputs.top_toml == 'false' - run: cargo +${{ env.NIGHTLY_TOOLCHAIN }} nextest run -p snops --verbose --fail-fast --all-features --no-tests=warn - - - name: ๐Ÿงช Test Agent - # env: - # RUSTFLAGS: "" - if: (steps.changes.outputs.agent == 'true' || steps.changes.outputs.common == 'true') - run: cargo +${{ env.NIGHTLY_TOOLCHAIN }} nextest run -p snops-agent --verbose --fail-fast --all-features --no-tests=warn - - - name: ๐Ÿงช Test Scli - # env: - # RUSTFLAGS: -Zcodegen-backend=cranelift - if: (steps.changes.outputs.scli == 'true' || steps.changes.outputs.common == 'true') && steps.changes.outputs.top_toml == 'false' - run: cargo +${{ env.NIGHTLY_TOOLCHAIN }} nextest run -p snops-cli --verbose --fail-fast --all-features --no-tests=warn + - name: ๐Ÿ“‹ Clippy ${{ matrix.crate.name }} + if: always() && ${{ env.TOP_TOML == 'true' || (matrix.crate.name == 'aot' && env.AOT == 'true') || (matrix.crate.name == 'checkpoint' && env.CHECKPOINT == 'true') || (matrix.crate.name == 'common' && env.COMMON == 'true') || (matrix.crate.name == 'snops' && env.CONTROL_PLANE == 'true') || (matrix.crate.name == 'agent' && env.AGENT == 'true') || (matrix.crate.name == 'scli' && env.SCLI == 'true') }} + env: + RUSTFLAGS: ${{ (matrix.crate.name == 'aot' || matrix.crate.name == 'checkpoint' || matrix.crate.name == 'common' || matrix.crate.name == 'snops') && '-Zcodegen-backend=cranelift' || '' }} + run: cargo +${{ env.NIGHTLY_TOOLCHAIN }} clippy -p ${{ matrix.crate.package }} --all-targets --locked -- -D warnings diff --git a/Cargo.lock b/Cargo.lock index 8bc6b8e4..7e17a5e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5905,18 +5905,18 @@ dependencies = [ [[package]] name = "xshell" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db0ab86eae739efd1b054a8d3d16041914030ac4e01cd1dca0cf252fd8b6437" +checksum = "9e7290c623014758632efe00737145b6867b66292c42167f2ec381eb566a373d" dependencies = [ "xshell-macros", ] [[package]] name = "xshell-macros" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d422e8e38ec76e2f06ee439ccc765e9c6a9638b9e7c9f2e8255e4d41e8bd852" +checksum = "32ac00cd3f8ec9c1d33fb3e7958a82df6989c42d747bd326c822b1d625283547" [[package]] name = "xtask" diff --git a/Cargo.toml b/Cargo.toml index 2f65753e..8ab1a15d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,13 @@ members = [ ] resolver = "2" +[workspace.package] +authors = [] +edition = "2024" +homepage = "https://github.com/monadicus/snarkops" +license = "MIT" +rust-version = "1.85.0" + [profile.dev] codegen-units = 512 opt-level = 1 diff --git a/crates/agent/Cargo.toml b/crates/agent/Cargo.toml index faa84dd1..30be4c2b 100644 --- a/crates/agent/Cargo.toml +++ b/crates/agent/Cargo.toml @@ -1,9 +1,13 @@ [package] name = "snops-agent" version = "0.2.0" -edition = "2021" -license = "MIT" + description = "A snarkops agent for communicating with snarkos nodes and the control plane" +authors.workspace = true +edition.workspace = true +homepage.workspace = true +license.workspace = true +rust-version.workspace = true [features] default = [] diff --git a/crates/agent/src/client.rs b/crates/agent/src/client.rs index ea94b9c4..e28bdf39 100644 --- a/crates/agent/src/client.rs +++ b/crates/agent/src/client.rs @@ -8,8 +8,8 @@ use http::{HeaderValue, StatusCode, Uri}; use snops_common::{ constant::{ENV_AGENT_KEY, HEADER_AGENT_KEY}, rpc::{ - control::{agent::AgentService, ControlServiceClient, PING_HEADER}, - RpcTransport, PING_INTERVAL_SEC, PING_LENGTH, + PING_INTERVAL_SEC, PING_LENGTH, RpcTransport, + control::{ControlServiceClient, PING_HEADER, agent::AgentService}, }, }; use tarpc::server::Channel; @@ -56,7 +56,7 @@ pub async fn ws_connection(ws_req: Request, state: Arc) { // Ignore connection refused errors, we only care if something interesting is // causing the connection to fail. tungstenite::Error::Io(e) if e.kind() == std::io::ErrorKind::ConnectionRefused => { - return + return; } // Shutdown the agent if the control plane requires an upgrade tungstenite::Error::Http(e) if e.status() == StatusCode::UPGRADE_REQUIRED => { diff --git a/crates/agent/src/db.rs b/crates/agent/src/db.rs index c432d483..852226ad 100644 --- a/crates/agent/src/db.rs +++ b/crates/agent/src/db.rs @@ -9,9 +9,9 @@ use indexmap::IndexMap; use snops_common::{ api::AgentEnvInfo, db::{ + Database as DatabaseTrait, error::DatabaseError, tree::{DbRecords, DbTree}, - Database as DatabaseTrait, }, format::{DataFormat, DataReadError, DataWriteError, PackedUint}, state::{AgentId, AgentState, EnvId, HeightRequest}, @@ -123,9 +123,7 @@ impl Database { } pub fn env_info(&self) -> Result)>, DatabaseError> { - self.documents - .restore(&AgentDbString::EnvInfo) - .map_err(DatabaseError::from) + self.documents.restore(&AgentDbString::EnvInfo) } pub fn set_env_info( diff --git a/crates/agent/src/log.rs b/crates/agent/src/log.rs index 9d87492b..10fac0f8 100644 --- a/crates/agent/src/log.rs +++ b/crates/agent/src/log.rs @@ -1,6 +1,6 @@ use tracing::level_filters::LevelFilter; use tracing_appender::non_blocking::WorkerGuard; -use tracing_subscriber::{layer::SubscriberExt, reload, util::SubscriberInitExt, EnvFilter}; +use tracing_subscriber::{EnvFilter, layer::SubscriberExt, reload, util::SubscriberInitExt}; pub type ReloadHandler = reload::Handle; diff --git a/crates/agent/src/main.rs b/crates/agent/src/main.rs index e8d7d8d0..62b716ad 100644 --- a/crates/agent/src/main.rs +++ b/crates/agent/src/main.rs @@ -24,8 +24,8 @@ use reconcile::agent::{AgentStateReconciler, AgentStateReconcilerContext}; use snops_common::{db::Database, util::OpaqueDebug}; use tokio::{ select, - signal::unix::{signal, Signal, SignalKind}, - sync::{mpsc, RwLock}, + signal::unix::{Signal, SignalKind, signal}, + sync::{RwLock, mpsc}, }; use tracing::{error, info}; diff --git a/crates/agent/src/metrics/tps.rs b/crates/agent/src/metrics/tps.rs index 67b7a1af..22607d85 100644 --- a/crates/agent/src/metrics/tps.rs +++ b/crates/agent/src/metrics/tps.rs @@ -1,4 +1,4 @@ -use simple_moving_average::{SingleSumSMA, SMA}; +use simple_moving_average::{SMA, SingleSumSMA}; use super::*; diff --git a/crates/agent/src/reconcile/address.rs b/crates/agent/src/reconcile/address.rs index 9c73ceb6..694b39b1 100644 --- a/crates/agent/src/reconcile/address.rs +++ b/crates/agent/src/reconcile/address.rs @@ -47,7 +47,10 @@ impl Reconcile<(), ReconcileError> for AddressResolveReconciler { } let Some(client) = state.client.read().await.clone() else { - warn!("Agent state contains {} addresses that need to be resolved, but client is not connected", unresolved_addrs.len()); + warn!( + "Agent state contains {} addresses that need to be resolved, but client is not connected", + unresolved_addrs.len() + ); // Client is offline so new addrs cannot be requested return Ok(ReconcileStatus::default()); diff --git a/crates/agent/src/reconcile/agent.rs b/crates/agent/src/reconcile/agent.rs index d645028d..a41038e5 100644 --- a/crates/agent/src/reconcile/agent.rs +++ b/crates/agent/src/reconcile/agent.rs @@ -14,18 +14,18 @@ use snops_common::{ use tarpc::context; use tokio::{ select, - sync::{mpsc::Receiver, Mutex}, + sync::{Mutex, mpsc::Receiver}, task::AbortHandle, time::sleep_until, }; use tracing::{error, info, trace}; use super::{ + Reconcile, ReconcileStatus, command::NodeCommand, process::ProcessContext, state::EnvState, storage::{BinaryReconciler, GenesisReconciler, LedgerModifyResult, StorageVersionReconciler}, - Reconcile, ReconcileStatus, }; use crate::{ db::Database, @@ -103,10 +103,10 @@ impl AgentStateReconcilerContext { /// added to the scope when a requeue is needed to provide more context when /// monitoring the agent. macro_rules! reconcile { - ($id:ident, $e:expr) => { + ($id:ident, $e:expr_2021) => { reconcile!($id, $e, res => {}) }; - ($id:ident, $e:expr, $v:ident => $rest:expr) => { + ($id:ident, $e:expr_2021, $v:ident => $rest:expr_2021) => { let $v = $e.reconcile().await?; if $v.is_requeue() { trace!("Requeue needed for {} ({:?}) {:?}", stringify!($id), $v.scopes, $v.conditions); diff --git a/crates/agent/src/reconcile/command.rs b/crates/agent/src/reconcile/command.rs index 9a5e376c..35c6ba00 100644 --- a/crates/agent/src/reconcile/command.rs +++ b/crates/agent/src/reconcile/command.rs @@ -90,24 +90,22 @@ impl NodeCommand { agent_rpc_port: state.agent_rpc_port, bind_addr: state.cli.bind_addr, ports: state.cli.ports, - private_key: if let KeyState::Literal(pk) = &node.private_key { - Some(pk.clone()) - } else { - None + private_key: match &node.private_key { + KeyState::Literal(pk) => Some(pk.clone()), + _ => None, }, // Ensure the private key file can be resolved. // This is only reachable when an agent is referred to by its // id in an environment spec. - private_key_file: if let KeyState::Local = &node.private_key { - Some( + private_key_file: match &node.private_key { + KeyState::Local => Some( state .cli .private_key_file .clone() .ok_or(ReconcileError::MissingLocalPrivateKey)?, - ) - } else { - None + ), + _ => None, }, peers: state.agentpeers_to_cli(&node.peers).await, validators: state.agentpeers_to_cli(&node.validators).await, diff --git a/crates/agent/src/reconcile/files.rs b/crates/agent/src/reconcile/files.rs index d470b01a..72b4e49f 100644 --- a/crates/agent/src/reconcile/files.rs +++ b/crates/agent/src/reconcile/files.rs @@ -42,7 +42,7 @@ pub fn get_genesis_route(endpoint: &str, network: NetworkId, storage_id: Storage /// This reconciler creates a directory if it does not exist pub struct DirectoryReconciler<'a>(pub &'a Path); -impl<'a> Reconcile<(), ReconcileError> for DirectoryReconciler<'a> { +impl Reconcile<(), ReconcileError> for DirectoryReconciler<'_> { async fn reconcile(&mut self) -> Result, ReconcileError> { std::fs::create_dir_all(self.0) .map(ReconcileStatus::with) diff --git a/crates/agent/src/reconcile/process.rs b/crates/agent/src/reconcile/process.rs index b75bd15d..b0e392cd 100644 --- a/crates/agent/src/reconcile/process.rs +++ b/crates/agent/src/reconcile/process.rs @@ -8,7 +8,7 @@ use snops_common::{ use tokio::{process::Child, select}; use tracing::{error, info}; -use super::{command::NodeCommand, Reconcile}; +use super::{Reconcile, command::NodeCommand}; use crate::state::NODE_GRACEFUL_SHUTDOWN_TIMEOUT; /// Information about the current process @@ -135,7 +135,7 @@ impl ProcessContext { /// before sending a SIGKILL (if the childi process has not exited), pub struct EndProcessReconciler<'a>(pub &'a mut ProcessContext); -impl<'a> Reconcile<(), ReconcileError> for EndProcessReconciler<'a> { +impl Reconcile<(), ReconcileError> for EndProcessReconciler<'_> { async fn reconcile(&mut self) -> Result, ReconcileError> { if !self.0.is_running() { return Ok(ReconcileStatus::default()); diff --git a/crates/agent/src/reconcile/storage.rs b/crates/agent/src/reconcile/storage.rs index a28ce7f7..afab87f6 100644 --- a/crates/agent/src/reconcile/storage.rs +++ b/crates/agent/src/reconcile/storage.rs @@ -19,7 +19,7 @@ use tokio::{process::Command, sync::Mutex, task::AbortHandle}; use tracing::{error, info, trace}; use url::Url; -use super::{default_binary, get_genesis_route, DirectoryReconciler, FileReconciler, Reconcile}; +use super::{DirectoryReconciler, FileReconciler, Reconcile, default_binary, get_genesis_route}; use crate::state::GlobalState; /// Download a specific binary file needed to run the node @@ -33,7 +33,7 @@ pub struct BinaryReconciler<'a> { pub ok_at: &'a mut Option, } -impl<'a> Reconcile<(), ReconcileError> for BinaryReconciler<'a> { +impl Reconcile<(), ReconcileError> for BinaryReconciler<'_> { async fn reconcile(&mut self) -> Result, ReconcileError> { let BinaryReconciler { state, @@ -123,7 +123,7 @@ pub struct GenesisReconciler<'a> { pub ok_at: &'a mut Option, } -impl<'a> Reconcile<(), ReconcileError> for GenesisReconciler<'a> { +impl Reconcile<(), ReconcileError> for GenesisReconciler<'_> { async fn reconcile(&mut self) -> Result, ReconcileError> { let GenesisReconciler { state, @@ -324,7 +324,7 @@ impl LedgerReconciler<'_> { } } -impl<'a> Reconcile<(), ReconcileError> for LedgerReconciler<'a> { +impl Reconcile<(), ReconcileError> for LedgerReconciler<'_> { async fn reconcile(&mut self) -> Result, ReconcileError> { let env_info = self.env_info.clone(); let target_height = self.target_height; @@ -474,7 +474,7 @@ impl<'a> Reconcile<(), ReconcileError> for LedgerReconciler<'a> { pub struct StorageVersionReconciler<'a>(pub &'a Path, pub u16); -impl<'a> Reconcile<(), ReconcileError> for StorageVersionReconciler<'a> { +impl Reconcile<(), ReconcileError> for StorageVersionReconciler<'_> { async fn reconcile(&mut self) -> Result, ReconcileError> { let StorageVersionReconciler(path, version) = self; @@ -493,7 +493,9 @@ impl<'a> Reconcile<(), ReconcileError> for StorageVersionReconciler<'a> { if path.exists() { // wipe old storage when the version changes if version_file_data != Some(*version) { - info!("Removing storage directory for version mismatch: local {version_file_data:?} != remote {version:?}"); + info!( + "Removing storage directory for version mismatch: local {version_file_data:?} != remote {version:?}" + ); let _ = tokio::fs::remove_dir_all(&path).await; } else { // return an empty status if the version is the same diff --git a/crates/agent/src/rpc/agent.rs b/crates/agent/src/rpc/agent.rs index e2ab05f8..60e0ab3f 100644 --- a/crates/agent/src/rpc/agent.rs +++ b/crates/agent/src/rpc/agent.rs @@ -3,8 +3,8 @@ use snops_common::{ define_rpc_mux, rpc::agent::{ - node::{NodeServiceRequest, NodeServiceResponse}, AgentNodeService, AgentNodeServiceRequest, AgentNodeServiceResponse, + node::{NodeServiceRequest, NodeServiceResponse}, }, state::snarkos_status::{SnarkOSBlockInfo, SnarkOSStatus}, }; diff --git a/crates/agent/src/rpc/control.rs b/crates/agent/src/rpc/control.rs index 85cd181f..89e30326 100644 --- a/crates/agent/src/rpc/control.rs +++ b/crates/agent/src/rpc/control.rs @@ -8,11 +8,11 @@ use snops_common::{ prelude::snarkos_status::SnarkOSLiteBlock, rpc::{ control::{ + ControlServiceClient, ControlServiceRequest, ControlServiceResponse, agent::{ AgentMetric, AgentService, AgentServiceRequest, AgentServiceResponse, AgentStatus, Handshake, }, - ControlServiceClient, ControlServiceRequest, ControlServiceResponse, }, error::{AgentError, SnarkosRequestError}, }, @@ -352,10 +352,9 @@ impl AgentService for AgentRpcServer { } async fn get_status(self, ctx: Context) -> Result { - let aot_online = if let Some(c) = self.state.get_node_client().await { - c.status(ctx).await.is_ok() - } else { - false + let aot_online = match self.state.get_node_client().await { + Some(c) => c.status(ctx).await.is_ok(), + _ => false, }; Ok(AgentStatus { diff --git a/crates/agent/src/server.rs b/crates/agent/src/server.rs index f10ab506..f047f40e 100644 --- a/crates/agent/src/server.rs +++ b/crates/agent/src/server.rs @@ -2,18 +2,18 @@ use std::sync::Arc; use anyhow::Result; use axum::{ + Router, extract::{ - ws::{Message, WebSocket}, State, WebSocketUpgrade, + ws::{Message, WebSocket}, }, response::{IntoResponse, Response}, routing::get, - Router, }; use futures::StreamExt; use snops_common::rpc::{ - agent::{node::NodeServiceClient, AgentNodeService}, RpcTransport, + agent::{AgentNodeService, node::NodeServiceClient}, }; use tarpc::server::Channel; use tokio::select; diff --git a/crates/agent/src/state.rs b/crates/agent/src/state.rs index 06361a80..55b337be 100644 --- a/crates/agent/src/state.rs +++ b/crates/agent/src/state.rs @@ -12,13 +12,13 @@ use snops_common::{ api::AgentEnvInfo, rpc::{agent::node::NodeServiceClient, control::ControlServiceClient, error::ReconcileError}, state::{ - snarkos_status::SnarkOSStatus, AgentId, AgentPeer, AgentState, EnvId, ReconcileOptions, - TransferId, TransferStatus, + AgentId, AgentPeer, AgentState, EnvId, ReconcileOptions, TransferId, TransferStatus, + snarkos_status::SnarkOSStatus, }, util::OpaqueDebug, }; use tarpc::context; -use tokio::sync::{mpsc::Sender, oneshot, RwLock}; +use tokio::sync::{RwLock, mpsc::Sender, oneshot}; use tracing::{error, info}; use crate::{cli::Cli, db::Database, log::ReloadHandler, metrics::Metrics, transfers::TransferTx}; diff --git a/crates/agent/src/transfers.rs b/crates/agent/src/transfers.rs index 77d35cc1..433e3e4d 100644 --- a/crates/agent/src/transfers.rs +++ b/crates/agent/src/transfers.rs @@ -1,10 +1,10 @@ use std::sync::{ - atomic::{AtomicU32, Ordering}, Arc, + atomic::{AtomicU32, Ordering}, }; use chrono::{TimeDelta, Utc}; -use dashmap::{mapref::entry::Entry, DashMap}; +use dashmap::{DashMap, mapref::entry::Entry}; use snops_common::state::{TransferId, TransferStatus, TransferStatusUpdate}; use tarpc::context; use tokio::{select, sync::mpsc}; diff --git a/crates/aot/Cargo.toml b/crates/aot/Cargo.toml index 4cdc3d28..7d1c7436 100644 --- a/crates/aot/Cargo.toml +++ b/crates/aot/Cargo.toml @@ -1,9 +1,12 @@ [package] -edition = "2021" name = "snarkos-aot" version = "0.1.1" -license = "MIT" description = "Ahead of time utilities for SnarkVM, and a wrapper around the SnarkOS node for more options" +authors.workspace = true +edition.workspace = true +homepage.workspace = true +license.workspace = true +rust-version.workspace = true [features] default = ["node"] diff --git a/crates/aot/src/accounts.rs b/crates/aot/src/accounts.rs index 02497dbd..58153d65 100644 --- a/crates/aot/src/accounts.rs +++ b/crates/aot/src/accounts.rs @@ -1,6 +1,6 @@ use std::{collections::HashSet, fs, path::PathBuf}; -use anyhow::{ensure, Result}; +use anyhow::{Result, ensure}; use bech32::ToBase32; use clap::Parser; use colored::Colorize; diff --git a/crates/aot/src/auth/auth_fee.rs b/crates/aot/src/auth/auth_fee.rs index a05edfa9..b496b2f5 100644 --- a/crates/aot/src/auth/auth_fee.rs +++ b/crates/aot/src/auth/auth_fee.rs @@ -1,13 +1,13 @@ -use anyhow::{anyhow, bail, Ok, Result}; +use anyhow::{Ok, Result, anyhow, bail}; use clap::Args; use clap_stdin::MaybeStdin; use rand::{CryptoRng, Rng}; use snarkvm::{ ledger::Deployment, - prelude::{cost_in_microcredits_v1, Field}, + prelude::{Field, cost_in_microcredits_v1}, synthesizer::{ - process::{cost_in_microcredits_v2, deployment_cost}, Process, + process::{cost_in_microcredits_v2, deployment_cost}, }, utilities::ToBytes, }; @@ -112,23 +112,22 @@ pub fn fee_auth( let process = N::process(); // Authorize the fee. - let fee = if let Some(record) = record { - process.authorize_fee_private::( + let fee = match record { + Some(record) => process.authorize_fee_private::( &private_key, record, base_fee_in_microcredits, priority_fee_in_microcredits, execution_id, rng, - )? - } else { - process.authorize_fee_public::( + )?, + _ => process.authorize_fee_public::( &private_key, base_fee_in_microcredits, priority_fee_in_microcredits, execution_id, rng, - )? + )?, }; Ok(Some(fee)) diff --git a/crates/aot/src/auth/auth_id.rs b/crates/aot/src/auth/auth_id.rs index dbb3ec3a..5d94c01b 100644 --- a/crates/aot/src/auth/auth_id.rs +++ b/crates/aot/src/auth/auth_id.rs @@ -1,4 +1,4 @@ -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use snarkvm::{console::types::Field, ledger::block::Transaction}; use crate::{Authorization, Network}; diff --git a/crates/aot/src/auth/auth_program.rs b/crates/aot/src/auth/auth_program.rs index d15477eb..d883a295 100644 --- a/crates/aot/src/auth/auth_program.rs +++ b/crates/aot/src/auth/auth_program.rs @@ -1,4 +1,4 @@ -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use clap::Args; use snarkvm::{console::program::Locator, synthesizer::Process}; diff --git a/crates/aot/src/auth/execute.rs b/crates/aot/src/auth/execute.rs index 26f57a49..c2b4807c 100644 --- a/crates/aot/src/auth/execute.rs +++ b/crates/aot/src/auth/execute.rs @@ -1,15 +1,15 @@ -use anyhow::{anyhow, bail, Result}; +use anyhow::{Result, anyhow, bail}; use clap::{Args, ValueEnum}; use rand::{CryptoRng, Rng}; use snarkvm::ledger::{ query::Query, - store::{helpers::memory::ConsensusMemory, ConsensusStore}, + store::{ConsensusStore, helpers::memory::ConsensusMemory}, }; use tracing::error; use super::{args::AuthArgs, query}; use crate::{ - auth::args::AuthBlob, Authorization, DbLedger, MemVM, Network, NetworkId, Transaction, + Authorization, DbLedger, MemVM, Network, NetworkId, Transaction, auth::args::AuthBlob, }; #[derive(Debug, Clone, ValueEnum)] diff --git a/crates/aot/src/auth/mod.rs b/crates/aot/src/auth/mod.rs index ee270d3a..0b7fd0e7 100644 --- a/crates/aot/src/auth/mod.rs +++ b/crates/aot/src/auth/mod.rs @@ -4,7 +4,7 @@ use auth_fee::estimate_cost; use clap::{Args, Subcommand}; use rand::SeedableRng; use rand_chacha::ChaChaRng; -use snarkvm::synthesizer::{process::deployment_cost, Process}; +use snarkvm::synthesizer::{Process, process::deployment_cost}; use crate::{Key, Network}; diff --git a/crates/aot/src/auth/query.rs b/crates/aot/src/auth/query.rs index 0fb266f9..c1732a6c 100644 --- a/crates/aot/src/auth/query.rs +++ b/crates/aot/src/auth/query.rs @@ -1,6 +1,6 @@ use std::collections::{HashMap, VecDeque}; -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use snarkvm::{ prelude::ProgramID, synthesizer::{Authorization, Process, Program, Stack}, diff --git a/crates/aot/src/cli.rs b/crates/aot/src/cli.rs index db19c30a..ca664f16 100644 --- a/crates/aot/src/cli.rs +++ b/crates/aot/src/cli.rs @@ -10,11 +10,11 @@ use clap::CommandFactory; use clap::Parser; use tracing::level_filters::LevelFilter; use tracing_appender::non_blocking::WorkerGuard; -use tracing_subscriber::{layer::SubscriberExt, reload, util::SubscriberInitExt, EnvFilter, Layer}; +use tracing_subscriber::{EnvFilter, Layer, layer::SubscriberExt, reload, util::SubscriberInitExt}; use crate::{ - accounts::GenAccounts, auth::AuthCommand, genesis::Genesis, ledger::Ledger, - program::ProgramCommand, Network, + Network, accounts::GenAccounts, auth::AuthCommand, genesis::Genesis, ledger::Ledger, + program::ProgramCommand, }; #[derive(Debug, Parser)] @@ -155,7 +155,7 @@ impl Cli { let mut guards = vec![]; macro_rules! non_blocking_appender { - ($name:ident = ( $args:expr )) => { + ($name:ident = ( $args:expr_2021 )) => { let ($name, guard) = tracing_appender::non_blocking($args); guards.push(guard); }; diff --git a/crates/aot/src/genesis.rs b/crates/aot/src/genesis.rs index bd4b5c4b..8153019c 100644 --- a/crates/aot/src/genesis.rs +++ b/crates/aot/src/genesis.rs @@ -1,26 +1,26 @@ use std::{fs, path::PathBuf, str::FromStr}; use aleo_std::StorageMode; -use anyhow::{anyhow, ensure, Result}; +use anyhow::{Result, anyhow, ensure}; use clap::Parser; use colored::Colorize; use indexmap::IndexMap; use rand::{CryptoRng, Rng, SeedableRng}; use rand_chacha::ChaChaRng; -use serde::{de::DeserializeOwned, Serialize}; +use serde::{Serialize, de::DeserializeOwned}; use snarkvm::{ ledger::{ - committee::MIN_VALIDATOR_STAKE, - store::{helpers::memory::ConsensusMemory, ConsensusStore}, Header, Ratify, Solutions, + committee::MIN_VALIDATOR_STAKE, + store::{ConsensusStore, helpers::memory::ConsensusMemory}, }, synthesizer::program::FinalizeGlobalState, utilities::ToBytes, }; use crate::{ - ledger::util::public_transaction, Address, Block, CTRecord, Committee, DbLedger, MemVM, - Network, NetworkId, PTRecord, PrivateKey, Transaction, ViewKey, + Address, Block, CTRecord, Committee, DbLedger, MemVM, Network, NetworkId, PTRecord, PrivateKey, + Transaction, ViewKey, ledger::util::public_transaction, }; #[derive(Clone, Debug, PartialEq, Eq, Serialize)] diff --git a/crates/aot/src/key.rs b/crates/aot/src/key.rs index b4e8bc7b..e3eb7232 100644 --- a/crates/aot/src/key.rs +++ b/crates/aot/src/key.rs @@ -1,6 +1,6 @@ use std::{path::PathBuf, str::FromStr}; -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use clap::Args; use crate::{Network, PrivateKey}; diff --git a/crates/aot/src/ledger/checkpoint.rs b/crates/aot/src/ledger/checkpoint.rs index 70058868..d1332f51 100644 --- a/crates/aot/src/ledger/checkpoint.rs +++ b/crates/aot/src/ledger/checkpoint.rs @@ -3,11 +3,11 @@ use std::path::PathBuf; use anyhow::Result; use clap::Parser; use snarkvm::{console::program::Network, ledger::Block, utilities::ToBytes}; -use snops_checkpoint::{path_from_height, Checkpoint, CheckpointManager, RetentionPolicy}; +use snops_checkpoint::{Checkpoint, CheckpointManager, RetentionPolicy, path_from_height}; use tracing::{info, trace}; use super::truncate::Truncate; -use crate::{ledger::util, DbLedger}; +use crate::{DbLedger, ledger::util}; /// A command to interact with checkpoints. #[derive(Debug, Parser)] diff --git a/crates/aot/src/ledger/hash.rs b/crates/aot/src/ledger/hash.rs index a31c626d..0deb4202 100644 --- a/crates/aot/src/ledger/hash.rs +++ b/crates/aot/src/ledger/hash.rs @@ -1,5 +1,5 @@ use std::{ - collections::{hash_map::DefaultHasher, HashMap}, + collections::{HashMap, hash_map::DefaultHasher}, hash::Hasher, path::PathBuf, }; @@ -12,8 +12,8 @@ use snarkvm::{ ledger::{ narwhal::{Transmission, TransmissionID}, store::helpers::rocksdb::{ - BFTMap, BlockMap, CommitteeMap, DeploymentMap, ExecutionMap, FeeMap, MapID, ProgramMap, - TransactionMap, TransitionInputMap, TransitionMap, TransitionOutputMap, PREFIX_LEN, + BFTMap, BlockMap, CommitteeMap, DeploymentMap, ExecutionMap, FeeMap, MapID, PREFIX_LEN, + ProgramMap, TransactionMap, TransitionInputMap, TransitionMap, TransitionOutputMap, }, }, }; diff --git a/crates/aot/src/ledger/mod.rs b/crates/aot/src/ledger/mod.rs index 1e0b9fe1..12851a1c 100644 --- a/crates/aot/src/ledger/mod.rs +++ b/crates/aot/src/ledger/mod.rs @@ -7,9 +7,9 @@ use snarkvm::{ledger::Block, utilities::FromBytes}; use self::checkpoint::CheckpointCommand; use crate::{ - auth::execute::{execute_local, Execute}, - cli::ReloadHandler, Network, + auth::execute::{Execute, execute_local}, + cli::ReloadHandler, }; pub mod checkpoint; diff --git a/crates/aot/src/ledger/query.rs b/crates/aot/src/ledger/query.rs index bdf9cc6c..4e3794f0 100644 --- a/crates/aot/src/ledger/query.rs +++ b/crates/aot/src/ledger/query.rs @@ -9,10 +9,10 @@ use std::{ use anyhow::Result; use axum::{ + Json, Router, extract::{self, Query, State}, response::IntoResponse, routing::{get, post}, - Json, Router, }; use clap::Args; use reqwest::StatusCode; @@ -20,8 +20,8 @@ use serde_json::json; use tracing_appender::non_blocking::NonBlocking; use crate::{ - cli::{make_env_filter, ReloadHandler}, Block, DbLedger, Network, Transaction, + cli::{ReloadHandler, make_env_filter}, }; /// Receive inquiries on `//latest/stateRoot`. @@ -140,14 +140,15 @@ impl LedgerQuery { return StatusCode::BAD_REQUEST; }; - if let Some(mut a) = state.appender.clone() { - match write!(a, "{}", tx_json) { + match state.appender.clone() { + Some(mut a) => match write!(a, "{}", tx_json) { Ok(_) => StatusCode::OK, Err(_) => StatusCode::INTERNAL_SERVER_ERROR, + }, + _ => { + println!("{}", tx_json); + StatusCode::OK } - } else { - println!("{}", tx_json); - StatusCode::OK } } diff --git a/crates/aot/src/ledger/truncate.rs b/crates/aot/src/ledger/truncate.rs index e243568f..056cd644 100644 --- a/crates/aot/src/ledger/truncate.rs +++ b/crates/aot/src/ledger/truncate.rs @@ -1,7 +1,7 @@ use std::{os::fd::AsRawFd, path::PathBuf}; use aleo_std::StorageMode; -use anyhow::{bail, ensure, Result}; +use anyhow::{Result, bail, ensure}; use clap::{Args, Parser}; use nix::{ sys::wait::waitpid, @@ -15,7 +15,7 @@ use snarkvm::{ use snops_checkpoint::{Checkpoint, CheckpointManager, RetentionPolicy}; use tracing::info; -use crate::{ledger::util, DbLedger}; +use crate::{DbLedger, ledger::util}; /// Replays blocks from a ledger to a specific height or amount to rollback to. #[derive(Debug, Args)] diff --git a/crates/aot/src/ledger/util.rs b/crates/aot/src/ledger/util.rs index 1529d725..e55ce0f5 100644 --- a/crates/aot/src/ledger/util.rs +++ b/crates/aot/src/ledger/util.rs @@ -1,6 +1,6 @@ use aleo_std::StorageMode; use anyhow::bail; -use rand::{thread_rng, SeedableRng}; +use rand::{SeedableRng, thread_rng}; use rand_chacha::ChaChaRng; use snarkvm::{ circuit::Aleo, @@ -9,8 +9,8 @@ use snarkvm::{ program::{Ciphertext, Identifier, Literal, Plaintext, ProgramID, Record, Value}, types::{Address, Field, U64}, }, - ledger::{query::Query, store::ConsensusStorage, Block, Execution, Fee, Ledger, Transaction}, - prelude::{execution_cost_v2, Network}, + ledger::{Block, Execution, Fee, Ledger, Transaction, query::Query, store::ConsensusStorage}, + prelude::{Network, execution_cost_v2}, synthesizer::VM, }; diff --git a/crates/aot/src/ledger/view.rs b/crates/aot/src/ledger/view.rs index 2d08d756..ec0e6184 100644 --- a/crates/aot/src/ledger/view.rs +++ b/crates/aot/src/ledger/view.rs @@ -8,7 +8,7 @@ use snarkvm::{ prelude::Zero, }; -use crate::{ledger::util, Address, DbLedger, PrivateKey, ViewKey}; +use crate::{Address, DbLedger, PrivateKey, ViewKey, ledger::util}; /// Used to view information about the ledger. #[derive(Debug, Subcommand)] diff --git a/crates/aot/src/lib.rs b/crates/aot/src/lib.rs index e8fc71b9..99b060f2 100644 --- a/crates/aot/src/lib.rs +++ b/crates/aot/src/lib.rs @@ -21,8 +21,8 @@ use snarkvm::{ program::Network as NetworkTrait, }, ledger::{ - store::helpers::{memory::ConsensusMemory, rocksdb::ConsensusDB}, Ledger, + store::helpers::{memory::ConsensusMemory, rocksdb::ConsensusDB}, }, prelude::ProgramID, synthesizer::Process, diff --git a/crates/aot/src/main.rs b/crates/aot/src/main.rs index 036f2ff1..ebf79e57 100644 --- a/crates/aot/src/main.rs +++ b/crates/aot/src/main.rs @@ -2,7 +2,7 @@ use std::{env, process::exit}; use anyhow::Result; use clap::Parser; -use snarkos_aot::{cli::Cli, Network, NetworkId}; +use snarkos_aot::{Network, NetworkId, cli::Cli}; use snarkvm::console::network::{CanaryV0, MainnetV0, TestnetV0}; #[cfg(all(target_os = "linux", target_arch = "x86_64"))] diff --git a/crates/aot/src/program/cost.rs b/crates/aot/src/program/cost.rs index c372a33f..d8510494 100644 --- a/crates/aot/src/program/cost.rs +++ b/crates/aot/src/program/cost.rs @@ -1,14 +1,14 @@ -use anyhow::{ensure, Result}; +use anyhow::{Result, ensure}; use clap::Args; use clap_stdin::FileOrStdin; use snarkvm::{ prelude::{Identifier, Value}, - synthesizer::{process::deployment_cost, Process, Program}, + synthesizer::{Process, Program, process::deployment_cost}, }; use crate::{ - auth::{auth_fee::estimate_cost, query}, Network, PrivateKey, + auth::{auth_fee::estimate_cost, query}, }; /// Compute the cost to execute a function in a given program. diff --git a/crates/aot/src/runner/mod.rs b/crates/aot/src/runner/mod.rs index fd3dd59d..5a1ff1d4 100644 --- a/crates/aot/src/runner/mod.rs +++ b/crates/aot/src/runner/mod.rs @@ -1,29 +1,29 @@ use std::{ net::{IpAddr, Ipv4Addr, SocketAddr}, path::PathBuf, - sync::{atomic::AtomicBool, Arc}, + sync::{Arc, atomic::AtomicBool}, }; use aleo_std::StorageMode; -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use clap::Args; use rpc::RpcClient; use snarkos_node::{ - bft::helpers::{proposal_cache_path, ProposalCache}, Node, + bft::helpers::{ProposalCache, proposal_cache_path}, }; use snarkvm::{ ledger::store::{ - helpers::rocksdb::{BlockDB, CommitteeDB}, BlockStorage, CommitteeStorage, + helpers::rocksdb::{BlockDB, CommitteeDB}, }, prelude::Block, utilities::FromBytes, }; use snops_checkpoint::{CheckpointManager, RetentionPolicy}; -use snops_common::state::{snarkos_status::SnarkOSStatus, NodeType}; +use snops_common::state::{NodeType, snarkos_status::SnarkOSStatus}; -use crate::{cli::ReloadHandler, Account, Address, DbLedger, Key, Network}; +use crate::{Account, Address, DbLedger, Key, Network, cli::ReloadHandler}; mod metrics; mod rpc; diff --git a/crates/aot/src/runner/rpc/mod.rs b/crates/aot/src/runner/rpc/mod.rs index 3722caf7..935d3533 100644 --- a/crates/aot/src/runner/rpc/mod.rs +++ b/crates/aot/src/runner/rpc/mod.rs @@ -7,11 +7,11 @@ use std::{ use futures_util::{SinkExt, StreamExt}; use http::Uri; use node::{MuxedMessageIncoming, MuxedMessageOutgoing, NodeRpcServer}; -use snarkvm::ledger::store::{helpers::rocksdb::BlockDB, BlockStorage}; +use snarkvm::ledger::store::{BlockStorage, helpers::rocksdb::BlockDB}; use snops_common::{ rpc::{ - agent::{node::NodeService, AgentNodeServiceClient, PING_HEADER}, - RpcTransport, PING_INTERVAL_SEC, PING_LENGTH, + PING_INTERVAL_SEC, PING_LENGTH, RpcTransport, + agent::{AgentNodeServiceClient, PING_HEADER, node::NodeService}, }, state::snarkos_status::{SnarkOSBlockInfo, SnarkOSStatus}, }; @@ -20,7 +20,7 @@ use tokio::select; use tokio_tungstenite::{connect_async, tungstenite, tungstenite::client::IntoClientRequest}; use tracing::{error, info, warn}; -use crate::{cli::ReloadHandler, Network}; +use crate::{Network, cli::ReloadHandler}; pub mod node; diff --git a/crates/aot/src/runner/rpc/node.rs b/crates/aot/src/runner/rpc/node.rs index 451705ee..53721f58 100644 --- a/crates/aot/src/runner/rpc/node.rs +++ b/crates/aot/src/runner/rpc/node.rs @@ -2,13 +2,13 @@ use std::sync::{Arc, RwLock}; -use snarkvm::ledger::store::{helpers::rocksdb::BlockDB, BlockStorage}; +use snarkvm::ledger::store::{BlockStorage, helpers::rocksdb::BlockDB}; use snops_common::{ define_rpc_mux, rpc::{ agent::{ - node::{NodeService, NodeServiceRequest, NodeServiceResponse}, AgentNodeServiceRequest, AgentNodeServiceResponse, + node::{NodeService, NodeServiceRequest, NodeServiceResponse}, }, error::AgentError, }, @@ -17,9 +17,9 @@ use snops_common::{ use tarpc::context; use crate::{ - cli::{make_env_filter, ReloadHandler}, - runner::rpc::get_block_info_for_height, Network, + cli::{ReloadHandler, make_env_filter}, + runner::rpc::get_block_info_for_height, }; define_rpc_mux!(child; diff --git a/crates/checkpoint/Cargo.toml b/crates/checkpoint/Cargo.toml index 1526b4a3..a8bd5da0 100644 --- a/crates/checkpoint/Cargo.toml +++ b/crates/checkpoint/Cargo.toml @@ -1,9 +1,13 @@ [package] -edition = "2021" + name = "snops-checkpoint" version = "0.1.0" -license = "MIT" description = "Ledger checkpointing for SnarkOS" +authors.workspace = true +edition.workspace = true +homepage.workspace = true +license.workspace = true +rust-version.workspace = true [features] default = [] diff --git a/crates/checkpoint/src/aleo.rs b/crates/checkpoint/src/aleo.rs index 0a110da5..82c2e70d 100644 --- a/crates/checkpoint/src/aleo.rs +++ b/crates/checkpoint/src/aleo.rs @@ -5,17 +5,16 @@ pub use snarkos_node::bft::{ pub use snarkvm::prelude::Network; use snarkvm::{ console::program, - ledger::{store::helpers::rocksdb, Ledger}, + ledger::{Ledger, store::helpers::rocksdb}, }; pub use snarkvm::{ ledger::{ authority::Authority, store::{ - self, cow_to_cloned, cow_to_copied, - helpers::{Map, MapRead}, - BlockStorage, CommitteeStorage, DeploymentStorage, ExecutionStorage, FeeStorage, + self, BlockStorage, CommitteeStorage, DeploymentStorage, ExecutionStorage, FeeStorage, FinalizeStorage, InputStorage, OutputStorage, TransactionStorage, TransactionType, - TransitionStorage, + TransitionStorage, cow_to_cloned, cow_to_copied, + helpers::{Map, MapRead}, }, }, utilities::{FromBytes, ToBytes}, diff --git a/crates/checkpoint/src/checkpoint.rs b/crates/checkpoint/src/checkpoint.rs index 0f6b12e9..2012016f 100644 --- a/crates/checkpoint/src/checkpoint.rs +++ b/crates/checkpoint/src/checkpoint.rs @@ -3,9 +3,10 @@ use std::{io, path::PathBuf, sync::Arc}; use rayon::iter::{IntoParallelIterator, ParallelIterator}; use crate::{ + CheckpointContent, CheckpointHeader, ROUND_KEY, aleo::*, errors::{CheckpointCheckError, CheckpointReadError, CheckpointRewindError}, - ledger, CheckpointContent, CheckpointHeader, ROUND_KEY, + ledger, }; pub struct Checkpoint { diff --git a/crates/checkpoint/src/ledger.rs b/crates/checkpoint/src/ledger.rs index 1abb4d86..f53cb66d 100644 --- a/crates/checkpoint/src/ledger.rs +++ b/crates/checkpoint/src/ledger.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use snarkvm::console::program::Network; use crate::aleo::*; @@ -63,13 +63,17 @@ impl Stores { // Retrieve the transaction IDs. let transaction_ids = match db.transactions_map().get_confirmed(&block_hash)? { Some(transaction_ids) => transaction_ids, - None => bail!("Failed to remove block: missing transactions for block '{block_height}' ('{block_hash}')"), + None => bail!( + "Failed to remove block: missing transactions for block '{block_height}' ('{block_hash}')" + ), }; // Retrieve the solutions. let solutions = match db.solutions_map().get_confirmed(&block_hash)? { Some(solutions) => cow_to_cloned!(solutions), None => { - bail!("Failed to remove block: missing solutions for block '{block_height}' ('{block_hash}')") + bail!( + "Failed to remove block: missing solutions for block '{block_height}' ('{block_hash}')" + ) } }; @@ -94,18 +98,13 @@ impl Stores { // Determine the certificate IDs to remove. let certificate_ids_to_remove = match db.authority_map().get_confirmed(&block_hash)? { - Some(authority) => match authority { - Cow::Owned(Authority::Beacon(_)) | Cow::Borrowed(Authority::Beacon(_)) => { - Vec::new() - } - Cow::Owned(Authority::Quorum(ref subdag)) - | Cow::Borrowed(Authority::Quorum(ref subdag)) => { - subdag.values().flatten().map(|c| c.id()).collect() - } + Some(authority) => match &*authority { + Authority::Beacon(_) => Vec::new(), + Authority::Quorum(subdag) => subdag.values().flatten().map(|c| c.id()).collect(), }, None => bail!( - "Failed to remove block: missing authority for block '{block_height}' ('{block_hash}')" - ), + "Failed to remove block: missing authority for block '{block_height}' ('{block_hash}')" + ), }; // Remove the (block height, state root) pair. diff --git a/crates/checkpoint/src/manager.rs b/crates/checkpoint/src/manager.rs index d06d32c7..4c9d0ee4 100644 --- a/crates/checkpoint/src/manager.rs +++ b/crates/checkpoint/src/manager.rs @@ -8,7 +8,7 @@ use tracing::{error, trace}; #[cfg(feature = "write")] use crate::errors::{ManagerCullError, ManagerInsertError, ManagerPollError}; use crate::{ - errors::ManagerLoadError, path_from_height, CheckpointHeader, RetentionPolicy, RetentionSpan, + CheckpointHeader, RetentionPolicy, RetentionSpan, errors::ManagerLoadError, path_from_height, }; #[derive(Debug, Clone)] diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index ce3bf359..69f8038c 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -1,9 +1,13 @@ [package] name = "snops-cli" version = "0.1.0" -edition = "2021" -license = "MIT" + description = "CLI for interacting with snarkops control plane API" +authors.workspace = true +edition.workspace = true +homepage.workspace = true +license.workspace = true +rust-version.workspace = true [features] default = [] diff --git a/crates/cli/src/commands/agent.rs b/crates/cli/src/commands/agent.rs index 5eb5fa84..e229511c 100644 --- a/crates/cli/src/commands/agent.rs +++ b/crates/cli/src/commands/agent.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use anyhow::Result; -use clap::{error::ErrorKind, ArgGroup, CommandFactory, Parser, ValueHint}; +use clap::{ArgGroup, CommandFactory, Parser, ValueHint, error::ErrorKind}; use reqwest::{Client, Response}; use serde_json::json; use snops_common::state::AgentId; diff --git a/crates/cli/src/commands/env/action/mod.rs b/crates/cli/src/commands/env/action/mod.rs index 4a29e0f7..59cda42f 100644 --- a/crates/cli/src/commands/env/action/mod.rs +++ b/crates/cli/src/commands/env/action/mod.rs @@ -4,7 +4,7 @@ use anyhow::Result; use clap::Parser; use clap_stdin::FileOrStdin; use reqwest::{Client, RequestBuilder, Response}; -use serde_json::{json, Value}; +use serde_json::{Value, json}; use snops_cli::events::EventsClient; use snops_common::{ action_models::{AleoValue, WithTargets}, @@ -356,10 +356,11 @@ impl Action { json["private_key"] = json!(private_key); } if let Some(env) = env { - json["set_env"] = json!(env - .into_iter() - .map(KeyEqValue::pair) - .collect::>()) + json["set_env"] = json!( + env.into_iter() + .map(KeyEqValue::pair) + .collect::>() + ) } if let Some(del_env) = del_env { json["del_env"] = json!(del_env) @@ -391,7 +392,7 @@ pub async fn post_and_wait_tx(url: &str, req: RequestBuilder) -> Result<()> { } _ => { let text = res.text().await?; - serde_json::from_str(&text).unwrap_or_else(|_| Value::String(text)) + serde_json::from_str(&text).unwrap_or(Value::String(text)) } }; println!("{}", serde_json::to_string_pretty(&value)?); diff --git a/crates/cli/src/commands/env/mod.rs b/crates/cli/src/commands/env/mod.rs index 179e170a..f7cd511a 100644 --- a/crates/cli/src/commands/env/mod.rs +++ b/crates/cli/src/commands/env/mod.rs @@ -295,7 +295,7 @@ pub async fn post_and_wait(url: &str, req: RequestBuilder, env_id: EnvId) -> Res } _ => { let text = res.text().await?; - serde_json::from_str(&text).unwrap_or_else(|_| Value::String(text)) + serde_json::from_str(&text).unwrap_or(Value::String(text)) } }; println!("{}", serde_json::to_string_pretty(&value)?); diff --git a/crates/cli/src/commands/mod.rs b/crates/cli/src/commands/mod.rs index 9821d1ca..0f951868 100644 --- a/crates/cli/src/commands/mod.rs +++ b/crates/cli/src/commands/mod.rs @@ -3,7 +3,7 @@ use clap::{CommandFactory, Parser}; use serde_json::Value; use snops_common::events::EventFilter; -use crate::{events::EventsClient, Cli}; +use crate::{Cli, events::EventsClient}; /// The dummy value for the ids to hack around the missing required argument. pub(crate) static DUMMY_ID: &str = "dummy_value___"; @@ -95,7 +95,7 @@ impl Commands { } _ => { let text = response.text().await?; - serde_json::from_str(&text).unwrap_or_else(|_| Value::String(text)) + serde_json::from_str(&text).unwrap_or(Value::String(text)) } }; diff --git a/crates/cli/src/events.rs b/crates/cli/src/events.rs index a99bd797..fe9da2ed 100644 --- a/crates/cli/src/events.rs +++ b/crates/cli/src/events.rs @@ -3,15 +3,14 @@ use std::{collections::HashSet, str::FromStr, time::Duration}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use futures_util::{SinkExt, StreamExt}; use http::Uri; use snops_common::events::{Event, EventFilter, EventWsRequest}; use tokio::{net::TcpStream, select}; use tokio_tungstenite::{ - connect_async, + MaybeTlsStream, WebSocketStream, connect_async, tungstenite::{self, client::IntoClientRequest}, - MaybeTlsStream, WebSocketStream, }; pub struct EventsClient { diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index 8e76c368..eb22f282 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -1,9 +1,13 @@ [package] name = "snops-common" version = "0.2.0" -edition = "2021" -license = "MIT" + description = "Common types and utilities for snops" +authors.workspace = true +edition.workspace = true +homepage.workspace = true +license.workspace = true +rust-version.workspace = true [features] default = [] diff --git a/crates/common/src/aot_cmds/error.rs b/crates/common/src/aot_cmds/error.rs index 20fa26de..b8c169b2 100644 --- a/crates/common/src/aot_cmds/error.rs +++ b/crates/common/src/aot_cmds/error.rs @@ -1,7 +1,7 @@ use std::process::ExitStatus; use http::StatusCode; -use serde::{ser::SerializeStruct, Serialize, Serializer}; +use serde::{Serialize, Serializer, ser::SerializeStruct}; use strum_macros::AsRefStr; use thiserror::Error; diff --git a/crates/common/src/db/tree.rs b/crates/common/src/db/tree.rs index 113742b2..c9aadf24 100644 --- a/crates/common/src/db/tree.rs +++ b/crates/common/src/db/tree.rs @@ -1,7 +1,7 @@ use bytes::Buf; use super::error::DatabaseError; -use crate::format::{read_dataformat, write_dataformat, DataFormat}; +use crate::format::{DataFormat, read_dataformat, write_dataformat}; pub struct DbTree { tree: sled::Tree, @@ -16,7 +16,7 @@ impl DbTree { } } - pub fn read_all(&self) -> impl Iterator { + pub fn read_all(&self) -> impl Iterator + use { self.tree.iter().filter_map(|row| { let (key_bytes, value_bytes) = match row { Ok((key, value)) => (key, value), @@ -49,7 +49,7 @@ impl DbTree { pub fn read_with_prefix( &self, prefix: &Prefix, - ) -> Result, DatabaseError> { + ) -> Result + use, DatabaseError> { Ok(self .tree .scan_prefix(prefix.to_byte_vec()?) diff --git a/crates/common/src/events/filter_parse.rs b/crates/common/src/events/filter_parse.rs index 252926e3..ccef9f0a 100644 --- a/crates/common/src/events/filter_parse.rs +++ b/crates/common/src/events/filter_parse.rs @@ -275,7 +275,7 @@ impl<'a> FilterParser<'a> { return Err(ExpectedToken( CommaOrCloseParen, self.tokens.peek().unwrap().label().to_string(), - )) + )); } None => return Err(ExpectedToken(CommaOrCloseParen, "EOF".to_string())), } diff --git a/crates/common/src/events/test_filter.rs b/crates/common/src/events/test_filter.rs index 9ec2e81c..9ca990c6 100644 --- a/crates/common/src/events/test_filter.rs +++ b/crates/common/src/events/test_filter.rs @@ -20,33 +20,43 @@ lazy_static! { #[test] fn test_unfiltered() { - assert!(Connected { - version: "0.0.0".to_string() - } - .event() - .matches(&Unfiltered)); + assert!( + Connected { + version: "0.0.0".to_string() + } + .event() + .matches(&Unfiltered) + ); assert!(HandshakeComplete.event().matches(&Unfiltered)); assert!(Disconnected.event().matches(&Unfiltered)); assert!(ReconcileComplete.event().matches(&Unfiltered)); - assert!(Reconcile(ReconcileStatus::empty()) - .event() - .matches(&Unfiltered)); - assert!(ReconcileError(ReconcileError::Offline) - .event() - .matches(&Unfiltered)); + assert!( + Reconcile(ReconcileStatus::empty()) + .event() + .matches(&Unfiltered) + ); + assert!( + ReconcileError(ReconcileError::Offline) + .event() + .matches(&Unfiltered) + ); assert!(NodeStatus(NodeStatus::Unknown).event().matches(&Unfiltered)); - assert!(BlockInfo(LatestBlockInfo::default()) - .event() - .matches(&Unfiltered)); + assert!( + BlockInfo(LatestBlockInfo::default()) + .event() + .matches(&Unfiltered) + ); } #[test] fn test_all_of() { - assert!(Connected { - version: "0.0.0".to_string() - } - .event() - .matches(&AllOf(vec![EventIs(AgentConnected)]))); + assert!( + Connected { + version: "0.0.0".to_string() + } + .event() + .matches(&AllOf(vec![EventIs(AgentConnected)])) + ); let e = Event { created_at: Utc::now(), @@ -73,11 +83,13 @@ fn test_all_of() { #[test] fn test_any_of() { - assert!(Connected { - version: "0.0.0".to_string() - } - .event() - .matches(&AnyOf(vec![EventIs(AgentConnected)]))); + assert!( + Connected { + version: "0.0.0".to_string() + } + .event() + .matches(&AnyOf(vec![EventIs(AgentConnected)])) + ); let e = Event { created_at: Utc::now(), @@ -108,11 +120,13 @@ fn test_any_of() { #[test] fn test_one_of() { - assert!(Connected { - version: "0.0.0".to_string() - } - .event() - .matches(&OneOf(vec![EventIs(AgentConnected)]))); + assert!( + Connected { + version: "0.0.0".to_string() + } + .event() + .matches(&OneOf(vec![EventIs(AgentConnected)])) + ); let e = Event { created_at: Utc::now(), diff --git a/crates/common/src/events/test_filter_parse.rs b/crates/common/src/events/test_filter_parse.rs index e5069fab..4ccedf32 100644 --- a/crates/common/src/events/test_filter_parse.rs +++ b/crates/common/src/events/test_filter_parse.rs @@ -1,21 +1,21 @@ use std::sync::Arc; use super::{ - filter_parse::EventFilterParseError, EventFilter::{self, *}, EventKindFilter::*, + filter_parse::EventFilterParseError, }; use crate::events::filter_parse::EventFilterParsable; use crate::{node_targets::NodeTargets, state::InternedId}; macro_rules! eq { - ($s:expr, $f:expr) => { + ($s:expr_2021, $f:expr_2021) => { assert_eq!($s.parse::()?, $f); }; } macro_rules! err { - ($s:expr, $pattern:pat $(if $guard:expr)?) => { + ($s:expr_2021, $pattern:pat $(if $guard:expr_2021)?) => { assert!(match $s.parse::() { $pattern $(if $guard)? => true, other => { @@ -178,7 +178,7 @@ fn test_failed_agent_parse() { #[test] fn test_str() { macro_rules! test { - ($s:expr) => { + ($s:expr_2021) => { assert_eq!($s.parse::().unwrap().to_string(), $s); }; } diff --git a/crates/common/src/format/impl_checkpoint.rs b/crates/common/src/format/impl_checkpoint.rs index 1bdc88cc..7f711335 100644 --- a/crates/common/src/format/impl_checkpoint.rs +++ b/crates/common/src/format/impl_checkpoint.rs @@ -103,7 +103,7 @@ mod test { macro_rules! case { - ($name:ident, $ty:ty, $a:expr, $b:expr) => { + ($name:ident, $ty:ty, $a:expr_2021, $b:expr_2021) => { #[test] fn $name() { let mut data = Vec::new(); diff --git a/crates/common/src/format/impl_collections.rs b/crates/common/src/format/impl_collections.rs index 0ba87e34..377173c8 100644 --- a/crates/common/src/format/impl_collections.rs +++ b/crates/common/src/format/impl_collections.rs @@ -6,8 +6,8 @@ use std::{ use indexmap::{IndexMap, IndexSet}; use super::{ - packed_int::PackedUint, DataFormat, DataFormatReader, DataFormatWriter, DataReadError, - DataWriteError, + DataFormat, DataFormatReader, DataFormatWriter, DataReadError, DataWriteError, + packed_int::PackedUint, }; /// BytesFormat is a simple wrapper around a Vec that implements DataFormat @@ -190,7 +190,7 @@ mod test { use crate::format::{BytesFormat, DataFormat}; macro_rules! case { - ($name:ident, $ty:ty, $a:expr, $b:expr) => { + ($name:ident, $ty:ty, $a:expr_2021, $b:expr_2021) => { #[test] fn $name() { let mut data = Vec::new(); diff --git a/crates/common/src/format/impl_containers.rs b/crates/common/src/format/impl_containers.rs index de567668..5f7acc1c 100644 --- a/crates/common/src/format/impl_containers.rs +++ b/crates/common/src/format/impl_containers.rs @@ -59,7 +59,7 @@ mod test { use crate::format::DataFormat; macro_rules! case { - ($name:ident, $ty:ty, $a:expr, $b:expr) => { + ($name:ident, $ty:ty, $a:expr_2021, $b:expr_2021) => { #[test] fn $name() { let mut data = Vec::new(); diff --git a/crates/common/src/format/impl_ints.rs b/crates/common/src/format/impl_ints.rs index 0785414d..62f00c6c 100644 --- a/crates/common/src/format/impl_ints.rs +++ b/crates/common/src/format/impl_ints.rs @@ -3,7 +3,7 @@ use std::{ num::NonZeroU8, }; -use super::{packed_int::PackedUint, DataFormat, DataReadError, DataWriteError}; +use super::{DataFormat, DataReadError, DataWriteError, packed_int::PackedUint}; macro_rules! impl_integer_dataformat { ($ty:ty) => { @@ -87,7 +87,7 @@ mod test { use crate::format::DataFormat; macro_rules! case { - ($ty:ty, $a:expr, $b:expr) => { + ($ty:ty, $a:expr_2021, $b:expr_2021) => { paste::paste! { #[test] fn []() { diff --git a/crates/common/src/format/impl_json.rs b/crates/common/src/format/impl_json.rs index cc6ac539..7b30a63a 100644 --- a/crates/common/src/format/impl_json.rs +++ b/crates/common/src/format/impl_json.rs @@ -36,7 +36,7 @@ mod test { use crate::format::PackedUint; macro_rules! case { - ($name:ident, $ty:ty, $a:expr) => { + ($name:ident, $ty:ty, $a:expr_2021) => { #[test] fn $name() { let mut data = Vec::new(); diff --git a/crates/common/src/format/impl_net.rs b/crates/common/src/format/impl_net.rs index a53a84eb..ec61c4f7 100644 --- a/crates/common/src/format/impl_net.rs +++ b/crates/common/src/format/impl_net.rs @@ -120,7 +120,7 @@ mod test { use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; macro_rules! case { - ($name:ident, $ty:ty, $a:expr, $b:expr) => { + ($name:ident, $ty:ty, $a:expr_2021, $b:expr_2021) => { #[test] fn $name() { let mut data = Vec::new(); diff --git a/crates/common/src/format/impl_strings.rs b/crates/common/src/format/impl_strings.rs index 4e83a5c9..6934b33c 100644 --- a/crates/common/src/format/impl_strings.rs +++ b/crates/common/src/format/impl_strings.rs @@ -2,7 +2,7 @@ use std::io::{Read, Write}; use lasso::Spur; -use super::{packed_int::PackedUint, DataFormat, DataReadError, DataWriteError}; +use super::{DataFormat, DataReadError, DataWriteError, packed_int::PackedUint}; use crate::INTERN; impl DataFormat for String { @@ -58,7 +58,7 @@ mod test { use crate::{format::DataFormat, INTERN}; macro_rules! case { - ($name:ident, $ty:ty, $a:expr, $b:expr) => { + ($name:ident, $ty:ty, $a:expr_2021, $b:expr_2021) => { #[test] fn $name() { let mut data = Vec::new(); diff --git a/crates/common/src/format/impl_tuples.rs b/crates/common/src/format/impl_tuples.rs index 0591d066..19b06cdf 100644 --- a/crates/common/src/format/impl_tuples.rs +++ b/crates/common/src/format/impl_tuples.rs @@ -68,7 +68,7 @@ mod test { use crate::format::DataFormat; macro_rules! case { - ($name:ident, $ty:ty, $a:expr, $b:expr) => { + ($name:ident, $ty:ty, $a:expr_2021, $b:expr_2021) => { #[test] fn $name() { let mut data = Vec::new(); diff --git a/crates/common/src/format/mod.rs b/crates/common/src/format/mod.rs index ed079221..80ecd3ad 100644 --- a/crates/common/src/format/mod.rs +++ b/crates/common/src/format/mod.rs @@ -141,7 +141,7 @@ impl DataFormatReader for R { #[macro_export] macro_rules! dataformat_test { - ($name:ident, $( $others:expr),* ) => { + ($name:ident, $( $others:expr_2021),* ) => { #[test] fn $name() -> Result<(), Box> { use snops_common::format::{write_dataformat, read_dataformat}; @@ -162,7 +162,7 @@ macro_rules! dataformat_test { #[cfg(test)] mod test { - use super::{read_dataformat, write_dataformat, DataFormat, DataReadError, DataWriteError}; + use super::{DataFormat, DataReadError, DataWriteError, read_dataformat, write_dataformat}; #[test] fn test_read_write() -> Result<(), Box> { diff --git a/crates/common/src/format/packed_int.rs b/crates/common/src/format/packed_int.rs index 2e0e10ca..b87c1b71 100644 --- a/crates/common/src/format/packed_int.rs +++ b/crates/common/src/format/packed_int.rs @@ -59,7 +59,7 @@ mod test { use super::*; macro_rules! case { - ($a:expr, $b:expr) => { + ($a:expr_2021, $b:expr_2021) => { paste::paste! { #[test] fn []() { diff --git a/crates/common/src/key_source.rs b/crates/common/src/key_source.rs index ecd2e044..9f39d4e8 100644 --- a/crates/common/src/key_source.rs +++ b/crates/common/src/key_source.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use http::StatusCode; use lazy_static::lazy_static; -use serde::{de::Visitor, Deserialize, Deserializer, Serialize}; +use serde::{Deserialize, Deserializer, Serialize, de::Visitor}; use strum_macros::AsRefStr; use thiserror::Error; diff --git a/crates/common/src/node_targets.rs b/crates/common/src/node_targets.rs index 4191137d..298eb073 100644 --- a/crates/common/src/node_targets.rs +++ b/crates/common/src/node_targets.rs @@ -5,9 +5,9 @@ use http::StatusCode; use lazy_static::lazy_static; use regex::Regex; use serde::{ + Deserialize, Serialize, de::{Error, Visitor}, ser::SerializeSeq, - Deserialize, Serialize, }; use thiserror::Error; use wildmatch::WildMatch; @@ -311,7 +311,7 @@ impl DataFormat for NodeTarget { n => { return Err(DataReadError::Custom(format!( "invalid NodeTarget type discriminant: {n}" - ))) + ))); } }; @@ -325,7 +325,7 @@ impl DataFormat for NodeTarget { n => { return Err(DataReadError::Custom(format!( "invalid NodeTarget ID discriminant: {n}" - ))) + ))); } }; @@ -336,7 +336,7 @@ impl DataFormat for NodeTarget { n => { return Err(DataReadError::Custom(format!( "invalid NodeTarget namespace discriminant: {n}" - ))) + ))); } }; @@ -426,8 +426,7 @@ impl NodeTarget { NodeTargetNamespace::All => true, NodeTargetNamespace::Local => key.ns.is_none() || key.ns == Some("local".into()), NodeTargetNamespace::Literal(ns) => { - ns == "local" && key.ns.is_none() - || key.ns.as_ref().map_or(false, |key_ns| key_ns == ns) + ns == "local" && key.ns.is_none() || (key.ns.as_ref() == Some(ns)) } }) } diff --git a/crates/common/src/rpc/error.rs b/crates/common/src/rpc/error.rs index 4977c33a..5ccec8bb 100644 --- a/crates/common/src/rpc/error.rs +++ b/crates/common/src/rpc/error.rs @@ -16,7 +16,7 @@ macro_rules! impl_into_type_str { } }; - ($name:path, |_| $body:expr) => { + ($name:path, |_| $body:expr_2021) => { impl From<&$name> for String { fn from(_: &$name) -> Self { $body @@ -24,7 +24,7 @@ macro_rules! impl_into_type_str { } }; - ($name:path, |$from_var:ident| $body:expr) => { + ($name:path, |$from_var:ident| $body:expr_2021) => { impl From<&$name> for String { fn from($from_var: &$name) -> Self { use $name::*; @@ -45,7 +45,7 @@ macro_rules! impl_into_status_code { } }; - ($name:path, |_| $body:expr) => { + ($name:path, |_| $body:expr_2021) => { impl From<&$name> for ::http::status::StatusCode { fn from(_: &$name) -> Self { $body @@ -53,7 +53,7 @@ macro_rules! impl_into_status_code { } }; - ($name:path, |$from_var:ident| $body:expr) => { + ($name:path, |$from_var:ident| $body:expr_2021) => { impl From<&$name> for ::http::status::StatusCode { fn from($from_var: &$name) -> Self { use $name::*; diff --git a/crates/common/src/state/agent_mode.rs b/crates/common/src/state/agent_mode.rs index 90de519a..3f0b6006 100644 --- a/crates/common/src/state/agent_mode.rs +++ b/crates/common/src/state/agent_mode.rs @@ -24,9 +24,9 @@ pub struct AgentModeOptions { impl From for u8 { fn from(mode: AgentModeOptions) -> u8 { (mode.validator as u8) - | (mode.prover as u8) << 1 - | (mode.client as u8) << 2 - | (mode.compute as u8) << 3 + | ((mode.prover as u8) << 1) + | ((mode.client as u8) << 2) + | ((mode.compute as u8) << 3) } } @@ -34,9 +34,9 @@ impl From for AgentModeOptions { fn from(mode: u8) -> Self { Self { validator: mode & 1 != 0, - prover: mode & 1 << 1 != 0, - client: mode & 1 << 2 != 0, - compute: mode & 1 << 3 != 0, + prover: mode & (1 << 1) != 0, + client: mode & (1 << 2) != 0, + compute: mode & (1 << 3) != 0, } } } diff --git a/crates/common/src/state/agent_status.rs b/crates/common/src/state/agent_status.rs index a882b66f..c2d15677 100644 --- a/crates/common/src/state/agent_status.rs +++ b/crates/common/src/state/agent_status.rs @@ -5,7 +5,7 @@ use indexmap::IndexMap; use serde::{Deserialize, Serialize}; use tokio::task::AbortHandle; -use super::{snarkos_status::SnarkOSStatus, ReconcileStatus}; +use super::{ReconcileStatus, snarkos_status::SnarkOSStatus}; use crate::{format::DataFormat, rpc::error::ReconcileError}; #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/crates/common/src/state/authorization.rs b/crates/common/src/state/authorization.rs index 9fb0e2ee..fcf1e9fe 100644 --- a/crates/common/src/state/authorization.rs +++ b/crates/common/src/state/authorization.rs @@ -104,7 +104,7 @@ mod test { use crate::format::DataFormat; macro_rules! case { - ($name:ident, $ty:ty, $a:expr) => { + ($name:ident, $ty:ty, $a:expr_2021) => { #[test] fn $name() { let mut data = Vec::new(); diff --git a/crates/common/src/state/id.rs b/crates/common/src/state/id.rs index 810ddb82..99b630eb 100644 --- a/crates/common/src/state/id.rs +++ b/crates/common/src/state/id.rs @@ -4,7 +4,7 @@ use rand::RngCore; use serde::de::Error; use super::INTERNED_ID_REGEX; -use crate::{format::DataFormat, INTERN}; +use crate::{INTERN, format::DataFormat}; #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct InternedId(lasso::Spur); diff --git a/crates/common/src/state/node_key.rs b/crates/common/src/state/node_key.rs index 102539f6..bf966c73 100644 --- a/crates/common/src/state/node_key.rs +++ b/crates/common/src/state/node_key.rs @@ -2,7 +2,7 @@ use std::{fmt::Write, str::FromStr}; use serde::de::Error; -use super::{NodeType, NODE_KEY_REGEX}; +use super::{NODE_KEY_REGEX, NodeType}; use crate::format::{DataFormat, DataFormatReader, DataFormatWriter, DataHeaderOf}; #[derive(Debug, Clone, Hash, PartialEq, Eq)] diff --git a/crates/common/src/state/node_state.rs b/crates/common/src/state/node_state.rs index 424e280f..4de768f8 100644 --- a/crates/common/src/state/node_state.rs +++ b/crates/common/src/state/node_state.rs @@ -259,12 +259,12 @@ impl DataFormat for AgentPeer { mod tests { use crate::{ - format::{read_dataformat, write_dataformat, DataFormat}, + format::{DataFormat, read_dataformat, write_dataformat}, prelude::{HeightRequest, KeyState, NodeState, NodeStateFormatHeader}, }; macro_rules! case { - ($name:ident, $ty:ty, $a:expr, $b:expr) => { + ($name:ident, $ty:ty, $a:expr_2021, $b:expr_2021) => { #[test] fn $name() -> Result<(), Box> { let mut data = Vec::new(); diff --git a/crates/common/src/state/port_config.rs b/crates/common/src/state/port_config.rs index 675dbd8c..0793a73d 100644 --- a/crates/common/src/state/port_config.rs +++ b/crates/common/src/state/port_config.rs @@ -72,7 +72,7 @@ mod test { use crate::state::PortConfig; macro_rules! case { - ($name:ident, $ty:ty, $a:expr, $b:expr) => { + ($name:ident, $ty:ty, $a:expr_2021, $b:expr_2021) => { #[test] fn $name() -> Result<(), Box> { let mut data = Vec::new(); diff --git a/crates/common/src/state/transaction_status.rs b/crates/common/src/state/transaction_status.rs index 8e9e5ec0..49121ed4 100644 --- a/crates/common/src/state/transaction_status.rs +++ b/crates/common/src/state/transaction_status.rs @@ -86,7 +86,7 @@ impl DataFormat for TransactionSendState { _ => { return Err(crate::format::DataReadError::Custom( "Invalid CannonTransactionStatus tag".to_string(), - )) + )); } }) } @@ -100,7 +100,7 @@ mod test { use crate::format::DataFormat; macro_rules! case { - ($name:ident, $ty:ty, $a:expr, $b:expr) => { + ($name:ident, $ty:ty, $a:expr_2021, $b:expr_2021) => { #[test] fn $name() { let mut data = Vec::new(); diff --git a/crates/controlplane/Cargo.toml b/crates/controlplane/Cargo.toml index f32a3481..dae18b0a 100644 --- a/crates/controlplane/Cargo.toml +++ b/crates/controlplane/Cargo.toml @@ -1,9 +1,12 @@ [package] name = "snops" version = "0.2.0" -edition = "2021" -license = "MIT" description = "The snarkops control plane responsible for managing environments and agents" +authors.workspace = true +edition.workspace = true +homepage.workspace = true +license.workspace = true +rust-version.workspace = true [features] default = [] diff --git a/crates/controlplane/src/cannon/context.rs b/crates/controlplane/src/cannon/context.rs index 33e89014..26d72210 100644 --- a/crates/controlplane/src/cannon/context.rs +++ b/crates/controlplane/src/cannon/context.rs @@ -1,8 +1,8 @@ -use std::sync::{atomic::AtomicUsize, Arc}; +use std::sync::{Arc, atomic::AtomicUsize}; use chrono::Utc; use dashmap::DashMap; -use futures_util::{stream::FuturesUnordered, StreamExt}; +use futures_util::{StreamExt, stream::FuturesUnordered}; use lazysort::SortedBy; use snops_common::{ events::{Event, TransactionAbortReason, TransactionEvent}, @@ -11,12 +11,12 @@ use snops_common::{ use tracing::{error, trace, warn}; use super::{ + CannonReceivers, error::{CannonError, ExecutionContextError, SourceError}, file::TransactionSink, sink::TxSink, source::TxSource, tracker::TransactionTracker, - CannonReceivers, }; use crate::{ cannon::source::ComputeTarget, @@ -308,7 +308,9 @@ impl ExecutionContext { }; if let Err(e) = client.broadcast_tx(tx_str.clone()).await { - warn!("cannon {env_id}.{cannon_id} failed to broadcast transaction to agent {id}: {e:?}"); + warn!( + "cannon {env_id}.{cannon_id} failed to broadcast transaction to agent {id}: {e:?}" + ); continue; } @@ -326,13 +328,17 @@ impl ExecutionContext { let Ok(res) = tokio::time::timeout(std::time::Duration::from_secs(5), req).await else { - warn!("cannon {env_id}.{cannon_id} failed to broadcast transaction to {addr}: timeout"); + warn!( + "cannon {env_id}.{cannon_id} failed to broadcast transaction to {addr}: timeout" + ); continue; }; match res { Err(e) => { - warn!("cannon {env_id}.{cannon_id} failed to broadcast transaction to {addr}: {e:?}"); + warn!( + "cannon {env_id}.{cannon_id} failed to broadcast transaction to {addr}: {e:?}" + ); continue; } Ok(req) => { @@ -350,7 +356,9 @@ impl ExecutionContext { return Ok(tx_id); } - warn!("cannon {env_id}.{cannon_id} failed to broadcast transaction to {addr}: {status}"); + warn!( + "cannon {env_id}.{cannon_id} failed to broadcast transaction to {addr}: {status}" + ); continue; } } diff --git a/crates/controlplane/src/cannon/error.rs b/crates/controlplane/src/cannon/error.rs index a86f3297..47c56ab4 100644 --- a/crates/controlplane/src/cannon/error.rs +++ b/crates/controlplane/src/cannon/error.rs @@ -1,9 +1,9 @@ use std::{path::PathBuf, sync::Arc}; use axum::http::StatusCode; -use serde::{ser::SerializeStruct, Serialize, Serializer}; +use serde::{Serialize, Serializer, ser::SerializeStruct}; use snops_common::{ - aot_cmds::{error::CommandError, AotCmdError}, + aot_cmds::{AotCmdError, error::CommandError}, db::error::DatabaseError, impl_into_status_code, impl_into_type_str, node_targets::NodeTargets, diff --git a/crates/controlplane/src/cannon/mod.rs b/crates/controlplane/src/cannon/mod.rs index f70b04ee..0b7aee3a 100644 --- a/crates/controlplane/src/cannon/mod.rs +++ b/crates/controlplane/src/cannon/mod.rs @@ -10,8 +10,8 @@ pub mod tracker; use std::{ path::PathBuf, sync::{ - atomic::{AtomicU64, AtomicUsize}, Arc, + atomic::{AtomicU64, AtomicUsize}, }, }; @@ -24,8 +24,8 @@ use snops_common::{ }; use tokio::{ sync::{ - mpsc::{UnboundedReceiver, UnboundedSender}, Semaphore, + mpsc::{UnboundedReceiver, UnboundedSender}, }, task::AbortHandle, }; @@ -173,7 +173,8 @@ impl CannonInstance { Ok(Some(index)) => index.0, Ok(None) => { warn!( - "cannon {env_id}.{cannon_id} failed to restore index for transaction {} (missing index)", key.2 + "cannon {env_id}.{cannon_id} failed to restore index for transaction {} (missing index)", + key.2 ); continue; } @@ -389,42 +390,44 @@ impl CannonInstance { } // prevent already queued transactions from being re-broadcasted - let tracker = if let Some(mut tx) = self.transactions.get(&tx_id).as_deref().cloned() { - // if we receive a transaction that is not executing, it is a duplicate - if !matches!(tx.status, TransactionSendState::Executing(_)) { - return Err(CannonError::TransactionAlreadyExists( - self.id, - tx_id.to_string(), - )); - } + let tracker = match self.transactions.get(&tx_id).as_deref().cloned() { + Some(mut tx) => { + // if we receive a transaction that is not executing, it is a duplicate + if !matches!(tx.status, TransactionSendState::Executing(_)) { + return Err(CannonError::TransactionAlreadyExists( + self.id, + tx_id.to_string(), + )); + } - // clear attempts (as this was a successful execute) - if let Err(e) = TransactionTracker::clear_attempts(&self.global_state, &key) { - error!( - "cannon {}.{} failed to clear attempts for {tx_id} (in proxy_broadcast): {e:?}", + // clear attempts (as this was a successful execute) + if let Err(e) = TransactionTracker::clear_attempts(&self.global_state, &key) { + error!( + "cannon {}.{} failed to clear attempts for {tx_id} (in proxy_broadcast): {e:?}", + self.env_id, self.id + ); + } + // update the status to pending broadcast, and write the transaction + tx.status = TransactionSendState::Unsent; + tx.transaction = Some(Arc::new(body)); + tx + } + _ => { + trace!( + "cannon {}.{} received broadcast {tx_id}", self.env_id, self.id ); - } - // update the status to pending broadcast, and write the transaction - tx.status = TransactionSendState::Unsent; - tx.transaction = Some(Arc::new(body)); - tx - } else { - trace!( - "cannon {}.{} received broadcast {tx_id}", - self.env_id, - self.id - ); - TransactionTracker { - index: Self::inc_received_txs( - &self.global_state, - self.env_id, - self.id, - &self.received_txs, - ), - authorization: None, - transaction: Some(Arc::new(body)), - status: TransactionSendState::Unsent, + TransactionTracker { + index: Self::inc_received_txs( + &self.global_state, + self.env_id, + self.id, + &self.received_txs, + ), + authorization: None, + transaction: Some(Arc::new(body)), + status: TransactionSendState::Unsent, + } } }; diff --git a/crates/controlplane/src/cannon/router.rs b/crates/controlplane/src/cannon/router.rs index 14cf8e96..5dcb7f72 100644 --- a/crates/controlplane/src/cannon/router.rs +++ b/crates/controlplane/src/cannon/router.rs @@ -1,17 +1,17 @@ use std::{str::FromStr, sync::Arc, time::Duration}; use axum::{ + Json, Router, extract::{Path, Query, State}, response::{IntoResponse, Response}, routing::{get, post}, - Json, Router, }; use reqwest::StatusCode; use serde::Deserialize; use serde_json::json; use snops_common::{ key_source::KeySource, - state::{id_or_none, Authorization, KeyState, NetworkId}, + state::{Authorization, KeyState, NetworkId, id_or_none}, }; use super::source::QueryTarget; @@ -75,7 +75,7 @@ async fn state_root( StatusCode::REQUEST_TIMEOUT, Json(json!({ "error": "non-responsive query node", "inner": format!("{e}") })), ) - .into_response() + .into_response(); } _ => attempts += 1, @@ -261,7 +261,7 @@ async fn get_mapping_json( StatusCode::UNPROCESSABLE_ENTITY, Json(json!({ "error": format!("invalid keysource: {e}") })), ) - .into_response() + .into_response(); } }; diff --git a/crates/controlplane/src/cannon/source.rs b/crates/controlplane/src/cannon/source.rs index 21878b0a..32ea7459 100644 --- a/crates/controlplane/src/cannon/source.rs +++ b/crates/controlplane/src/cannon/source.rs @@ -2,18 +2,18 @@ use std::sync::Arc; use chrono::Utc; use serde::{Deserialize, Serialize}; -use serde_json::{json, Value}; +use serde_json::{Value, json}; use snops_common::events::{EventHelpers, TransactionEvent}; use snops_common::state::{Authorization, TransactionSendState}; -use snops_common::{lasso::Spur, node_targets::NodeTargets, state::NetworkId, INTERN}; +use snops_common::{INTERN, lasso::Spur, node_targets::NodeTargets, state::NetworkId}; use tracing::error; use super::context::CtxEventHelper; use super::{ + ExecutionContext, error::{CannonError, SourceError}, net::get_available_port, tracker::TransactionTracker, - ExecutionContext, }; use crate::env::set::find_compute_agent; use crate::state::EmitEvent; diff --git a/crates/controlplane/src/db.rs b/crates/controlplane/src/db.rs index b9600c17..2919b8ac 100644 --- a/crates/controlplane/src/db.rs +++ b/crates/controlplane/src/db.rs @@ -1,7 +1,7 @@ use std::{path::Path, sync::Arc}; use snops_common::{ - db::{error::DatabaseError, tree::DbTree, Database as DatabaseTrait}, + db::{Database as DatabaseTrait, error::DatabaseError, tree::DbTree}, format::PackedUint, state::{AgentId, Authorization, CannonId, EnvId, NetworkId, StorageId, TransactionSendState}, }; diff --git a/crates/controlplane/src/env/cache.rs b/crates/controlplane/src/env/cache.rs index 3a954837..126ede3c 100644 --- a/crates/controlplane/src/env/cache.rs +++ b/crates/controlplane/src/env/cache.rs @@ -1,6 +1,6 @@ use std::{ collections::HashMap, - sync::{atomic::AtomicU64, Arc}, + sync::{Arc, atomic::AtomicU64}, time::Duration, }; @@ -108,7 +108,7 @@ impl NetworkCache { pub fn is_peer_penalized(&self, key: &NodeKey) -> bool { self.external_peer_record .get(key) - .map_or(false, ResponsiveRecord::has_penalty) + .is_some_and(ResponsiveRecord::has_penalty) } /// Update a peer's node info if the provided block hash exists in the cache diff --git a/crates/controlplane/src/env/error.rs b/crates/controlplane/src/env/error.rs index d8cd4497..7f817d75 100644 --- a/crates/controlplane/src/env/error.rs +++ b/crates/controlplane/src/env/error.rs @@ -1,5 +1,5 @@ use axum::http::StatusCode; -use serde::{ser::SerializeStruct, Serialize, Serializer}; +use serde::{Serialize, Serializer, ser::SerializeStruct}; use snops_common::{ aot_cmds::AotCmdError, impl_into_status_code, impl_into_type_str, diff --git a/crates/controlplane/src/env/mod.rs b/crates/controlplane/src/env/mod.rs index 3da59028..20fb6e9a 100644 --- a/crates/controlplane/src/env/mod.rs +++ b/crates/controlplane/src/env/mod.rs @@ -7,7 +7,7 @@ use std::{ use bimap::BiMap; use dashmap::DashMap; use futures_util::future::join_all; -use indexmap::{map::Entry, IndexMap, IndexSet}; +use indexmap::{IndexMap, IndexSet, map::Entry}; use serde::{Deserialize, Serialize}; use snops_common::{ api::{AgentEnvInfo, EnvInfo}, @@ -23,18 +23,18 @@ use tracing::{error, info, trace, warn}; use self::error::*; use crate::{ cannon::{ + CannonInstance, CannonInstanceMeta, file::TransactionSink, sink::TxSink, source::{ComputeTarget, QueryTarget, TxSource}, - CannonInstance, CannonInstanceMeta, }, - env::set::{get_agent_mappings, labels_from_nodes, pair_with_nodes, AgentMapping, BusyMode}, + env::set::{AgentMapping, BusyMode, get_agent_mappings, labels_from_nodes, pair_with_nodes}, error::DeserializeError, persist::PersistEnv, schema::{ + ItemDocument, nodes::{ExternalNode, Node}, storage::LoadedStorage, - ItemDocument, }, state::{Agent, GlobalState}, }; @@ -123,12 +123,13 @@ impl Environment { let mut storage_doc = None; - let (mut node_peers, mut node_states) = if let Some(ref env) = prev_env { - // reuse certain elements from the previous environment with the same - // name - (env.node_peers.clone(), env.node_states.clone()) - } else { - (Default::default(), Default::default()) + let (mut node_peers, mut node_states) = match prev_env { + Some(ref env) => { + // reuse certain elements from the previous environment with the same + // name + (env.node_peers.clone(), env.node_states.clone()) + } + _ => (Default::default(), Default::default()), }; let mut network = NetworkId::default(); @@ -251,14 +252,9 @@ impl Environment { // going to be part of the environment let mut removed_agents = node_peers .iter() - .filter_map(|(key, mode)| { - if let (EnvPeer::Internal(agent), false) = - (mode, agent_keys.contains(key)) - { - Some(*agent) - } else { - None - } + .filter_map(|(key, mode)| match (mode, agent_keys.contains(key)) { + (EnvPeer::Internal(agent), false) => Some(*agent), + _ => None, }) .collect::>(); diff --git a/crates/controlplane/src/env/set.rs b/crates/controlplane/src/env/set.rs index 8f8ffe3e..db1fc765 100644 --- a/crates/controlplane/src/env/set.rs +++ b/crates/controlplane/src/env/set.rs @@ -1,6 +1,6 @@ use std::{ collections::{HashMap, HashSet}, - sync::{mpsc, Arc, Weak}, + sync::{Arc, Weak, mpsc}, }; use fixedbitset::FixedBitSet; @@ -169,7 +169,7 @@ pub fn pair_with_nodes( agents: Vec, nodes: &IndexMap, labels: &[Spur], -) -> Result)>, Vec> { +) -> Result)> + use<>, Vec> { // errors that occurred while pairing nodes with agents let (errors_tx, errors_rx) = mpsc::channel(); // nodes that were successfully claimed. dropping this will automatically @@ -237,13 +237,16 @@ pub fn pair_with_nodes( // pair them with an agent that has the matching mask want_labels.into_par_iter().for_each(|(key, mask)| { // find the first agent that can be claimed that fits the mask - if let Some((id, claim)) = agents + match agents .iter() .find_map(|a| a.claim_if_subset(&mask).map(|c| (a.id, c))) { - let _ = claimed_tx.send((key.clone(), id, claim)); - } else { - let _ = errors_tx.send(DelegationError::NoAvailableAgents(key.clone())); + Some((id, claim)) => { + let _ = claimed_tx.send((key.clone(), id, claim)); + } + _ => { + let _ = errors_tx.send(DelegationError::NoAvailableAgents(key.clone())); + } } }); diff --git a/crates/controlplane/src/error.rs b/crates/controlplane/src/error.rs index 89ad73f2..5dacc2f2 100644 --- a/crates/controlplane/src/error.rs +++ b/crates/controlplane/src/error.rs @@ -1,4 +1,4 @@ -use serde::{ser::SerializeStruct, Serialize, Serializer}; +use serde::{Serialize, Serializer, ser::SerializeStruct}; use snops_common::state::AgentId; use snops_common::{impl_into_status_code, impl_into_type_str}; use strum_macros::AsRefStr; diff --git a/crates/controlplane/src/logging.rs b/crates/controlplane/src/logging.rs index 3e38cbdf..1b1f7f13 100644 --- a/crates/controlplane/src/logging.rs +++ b/crates/controlplane/src/logging.rs @@ -1,7 +1,7 @@ use axum::{ async_trait, extract::{FromRequestParts, Request}, - http::{request::Parts, Method, StatusCode, Uri}, + http::{Method, StatusCode, Uri, request::Parts}, middleware::Next, response::Response, }; diff --git a/crates/controlplane/src/main.rs b/crates/controlplane/src/main.rs index 6f4a65ba..c0ac3f17 100644 --- a/crates/controlplane/src/main.rs +++ b/crates/controlplane/src/main.rs @@ -8,7 +8,7 @@ use snops_common::db::Database; use state::GlobalState; use tokio::select; use tracing::{error, info, level_filters::LevelFilter, trace}; -use tracing_subscriber::{prelude::*, reload, EnvFilter}; +use tracing_subscriber::{EnvFilter, prelude::*, reload}; pub mod agent_version; pub mod cannon; diff --git a/crates/controlplane/src/persist/agent.rs b/crates/controlplane/src/persist/agent.rs index ff42da21..6ddb5990 100644 --- a/crates/controlplane/src/persist/agent.rs +++ b/crates/controlplane/src/persist/agent.rs @@ -101,7 +101,7 @@ impl DataFormat for Agent { n => { return Err(DataReadError::Custom(format!( "invalid AgentState discriminant: {n}" - ))) + ))); } }; let flags = reader.read_data(&header.flags)?; @@ -179,7 +179,7 @@ mod test { use std::net::{IpAddr, Ipv4Addr}; macro_rules! case { - ($name:ident, $ty:ty, $a:expr, $b:expr) => { + ($name:ident, $ty:ty, $a:expr_2021, $b:expr_2021) => { #[test] fn $name() -> Result<(), Box>{ let mut data = Vec::new(); diff --git a/crates/controlplane/src/persist/env.rs b/crates/controlplane/src/persist/env.rs index 4c85889c..37f0cf30 100644 --- a/crates/controlplane/src/persist/env.rs +++ b/crates/controlplane/src/persist/env.rs @@ -6,13 +6,14 @@ use snops_common::state::TransactionSendState; use snops_common::state::{CannonId, EnvId, NetworkId, NodeKey, StorageId}; use tokio::sync::Semaphore; -use super::prelude::*; use super::PersistNode; +use super::prelude::*; use crate::{ cannon::{sink::TxSink, source::TxSource, tracker::TransactionTracker}, env::{ + EnvNodeState, EnvPeer, Environment, error::{EnvError, PrepareError}, - prepare_cannons, EnvNodeState, EnvPeer, Environment, + prepare_cannons, }, state::GlobalState, }; @@ -248,7 +249,7 @@ mod tests { use std::str::FromStr; use snops_common::{ - format::{read_dataformat, write_dataformat, DataFormat}, + format::{DataFormat, read_dataformat, write_dataformat}, state::{InternedId, NetworkId}, }; @@ -261,7 +262,7 @@ mod tests { }; macro_rules! case { - ($name:ident, $ty:ty, $a:expr, $b:expr) => { + ($name:ident, $ty:ty, $a:expr_2021, $b:expr_2021) => { #[test] fn $name() -> Result<(), Box> { let mut data = Vec::new(); diff --git a/crates/controlplane/src/persist/mod.rs b/crates/controlplane/src/persist/mod.rs index 0b2d2db9..105144b1 100644 --- a/crates/controlplane/src/persist/mod.rs +++ b/crates/controlplane/src/persist/mod.rs @@ -16,7 +16,7 @@ pub(crate) mod prelude { pub use std::io::{Read, Write}; pub use snops_common::format::{ - read_dataformat, write_dataformat, DataFormat, DataFormatReader, DataFormatWriter, - DataHeaderOf, DataReadError, DataWriteError, + DataFormat, DataFormatReader, DataFormatWriter, DataHeaderOf, DataReadError, + DataWriteError, read_dataformat, write_dataformat, }; } diff --git a/crates/controlplane/src/persist/node.rs b/crates/controlplane/src/persist/node.rs index 5cd638bc..c50df6db 100644 --- a/crates/controlplane/src/persist/node.rs +++ b/crates/controlplane/src/persist/node.rs @@ -99,7 +99,7 @@ mod tests { }; macro_rules! case { - ($name:ident, $ty:ty, $a:expr, $b:expr) => { + ($name:ident, $ty:ty, $a:expr_2021, $b:expr_2021) => { #[test] fn $name() -> Result<(), Box> { let mut data = Vec::new(); diff --git a/crates/controlplane/src/persist/source.rs b/crates/controlplane/src/persist/source.rs index b88b0931..58939813 100644 --- a/crates/controlplane/src/persist/source.rs +++ b/crates/controlplane/src/persist/source.rs @@ -112,15 +112,15 @@ impl DataFormat for TxSource { #[cfg(test)] mod tests { - use snops_common::{node_targets::NodeTargets, INTERN}; + use snops_common::{INTERN, node_targets::NodeTargets}; use crate::{ cannon::source::{ComputeTarget, LocalService, QueryTarget, TxSource}, - persist::{prelude::*, TxSourceFormatHeader}, + persist::{TxSourceFormatHeader, prelude::*}, }; macro_rules! case { - ($name:ident, $ty:ty, $a:expr, $b:expr) => { + ($name:ident, $ty:ty, $a:expr_2021, $b:expr_2021) => { #[test] fn $name() -> Result<(), Box> { let mut data = Vec::new(); diff --git a/crates/controlplane/src/persist/storage.rs b/crates/controlplane/src/persist/storage.rs index a3df3f37..ea804ec3 100644 --- a/crates/controlplane/src/persist/storage.rs +++ b/crates/controlplane/src/persist/storage.rs @@ -13,8 +13,8 @@ use crate::{ schema::{ error::StorageError, storage::{ - pick_account_addr, pick_additional_addr, pick_commitee_addr, read_to_addrs, - LoadedStorage, STORAGE_DIR, + LoadedStorage, STORAGE_DIR, pick_account_addr, pick_additional_addr, + pick_commitee_addr, read_to_addrs, }, }, }; @@ -198,14 +198,14 @@ mod tests { use snops_checkpoint::RetentionPolicy; use snops_common::{ binaries::BinaryEntry, - format::{read_dataformat, write_dataformat, DataFormat}, + format::{DataFormat, read_dataformat, write_dataformat}, state::{InternedId, NetworkId}, }; use crate::persist::{PersistStorage, PersistStorageFormatHeader}; macro_rules! case { - ($name:ident, $ty:ty, $a:expr, $b:expr) => { + ($name:ident, $ty:ty, $a:expr_2021, $b:expr_2021) => { #[test] fn $name() -> Result<(), Box> { let mut data = Vec::new(); diff --git a/crates/controlplane/src/schema/error.rs b/crates/controlplane/src/schema/error.rs index f13af3d6..257dcca1 100644 --- a/crates/controlplane/src/schema/error.rs +++ b/crates/controlplane/src/schema/error.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use axum::http::StatusCode; -use serde::{ser::SerializeStruct, Serialize, Serializer}; +use serde::{Serialize, Serializer, ser::SerializeStruct}; use snops_common::{ aot_cmds::error::CommandError, impl_into_status_code, impl_into_type_str, diff --git a/crates/controlplane/src/schema/nodes.rs b/crates/controlplane/src/schema/nodes.rs index da16b984..8491572b 100644 --- a/crates/controlplane/src/schema/nodes.rs +++ b/crates/controlplane/src/schema/nodes.rs @@ -2,14 +2,14 @@ use std::net::{IpAddr, SocketAddr}; use fixedbitset::FixedBitSet; use indexmap::{IndexMap, IndexSet}; -use serde::{de::Visitor, Deserialize, Deserializer, Serialize}; +use serde::{Deserialize, Deserializer, Serialize, de::Visitor}; use snops_common::{ + INTERN, key_source::KeySource, lasso::Spur, node_targets::NodeTargets, - set::{MaskBit, MASK_PREFIX_LEN}, + set::{MASK_PREFIX_LEN, MaskBit}, state::{AgentId, HeightRequest, InternedId, NetworkId, NodeState}, - INTERN, }; use super::NodeKey; diff --git a/crates/controlplane/src/schema/outcomes.rs b/crates/controlplane/src/schema/outcomes.rs index 0c98093a..c109398b 100644 --- a/crates/controlplane/src/schema/outcomes.rs +++ b/crates/controlplane/src/schema/outcomes.rs @@ -3,7 +3,7 @@ use std::{collections::HashMap, fmt::Display}; use indexmap::IndexMap; use lazy_static::lazy_static; use promql_parser::{label::Matcher, parser::ast::Expr as PromExpr}; -use serde::{de::Visitor, Deserialize}; +use serde::{Deserialize, de::Visitor}; use super::error::SchemaError; @@ -149,10 +149,10 @@ impl PromQuery { fn inject_matchers(expr: &mut PromExpr, matchers: &[Matcher]) { macro_rules! inject { - ($into:expr) => { + ($into:expr_2021) => { Self::inject_matchers(&mut $into, matchers) }; - ($into:expr, $($into2:expr),+) => { + ($into:expr_2021, $($into2:expr_2021),+) => { { inject!($into); inject!($($into2),+); @@ -196,7 +196,7 @@ impl<'de> Deserialize<'de> for PromQuery { { struct PromQueryVisitor; - impl<'de> Visitor<'de> for PromQueryVisitor { + impl Visitor<'_> for PromQueryVisitor { type Value = PromQuery; fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { diff --git a/crates/controlplane/src/schema/storage/accounts.rs b/crates/controlplane/src/schema/storage/accounts.rs index bc787ed3..18c5717f 100644 --- a/crates/controlplane/src/schema/storage/accounts.rs +++ b/crates/controlplane/src/schema/storage/accounts.rs @@ -1,4 +1,4 @@ -use serde::{de::Visitor, Deserialize, Deserializer, Serialize}; +use serde::{Deserialize, Deserializer, Serialize, de::Visitor}; #[derive(Debug, Clone, Serialize)] pub struct Accounts { diff --git a/crates/controlplane/src/server/actions/config.rs b/crates/controlplane/src/server/actions/config.rs index bb7bfc6d..cd959c53 100644 --- a/crates/controlplane/src/server/actions/config.rs +++ b/crates/controlplane/src/server/actions/config.rs @@ -1,19 +1,19 @@ -use std::collections::{hash_map::Entry, HashMap}; +use std::collections::{HashMap, hash_map::Entry}; use axum::{ - response::{IntoResponse, Response}, Json, + response::{IntoResponse, Response}, }; use snops_common::{ action_models::{Reconfig, WithTargets}, - state::{id_or_none, AgentId, AgentState, InternedId}, + state::{AgentId, AgentState, InternedId, id_or_none}, }; use super::Env; use crate::{ env::PortType, server::error::ServerError, - state::{pending_reconcile_node_map, PendingAgentReconcile}, + state::{PendingAgentReconcile, pending_reconcile_node_map}, unwrap_or_not_found, }; @@ -24,7 +24,7 @@ pub async fn config( let mut pending: HashMap = HashMap::new(); macro_rules! set_node_field { - ($agent:ident , $($key:ident = $val:expr),* ) => { + ($agent:ident , $($key:ident = $val:expr_2021),* ) => { #[allow(unused_variables)] match pending.entry($agent.id()) { Entry::Occupied(mut ent) => { @@ -55,10 +55,9 @@ pub async fn config( } for WithTargets { nodes, data } in configs { - let binary = if let Some(b) = data.binary.as_ref() { - Some(unwrap_or_not_found!("unknown binary id", id_or_none(b))) - } else { - None + let binary = match data.binary.as_ref() { + Some(b) => Some(unwrap_or_not_found!("unknown binary id", id_or_none(b))), + _ => None, }; for agent in env.matching_agents(&nodes, &state.pool) { diff --git a/crates/controlplane/src/server/actions/deploy.rs b/crates/controlplane/src/server/actions/deploy.rs index 97067447..39b935e8 100644 --- a/crates/controlplane/src/server/actions/deploy.rs +++ b/crates/controlplane/src/server/actions/deploy.rs @@ -1,21 +1,21 @@ use std::sync::Arc; use axum::{ + Json, extract::{Query, State}, response::{IntoResponse, Response}, - Json, }; use http::StatusCode; use snops_common::{ action_models::DeployAction, aot_cmds::AotCmd, - state::{id_or_none, Authorization, KeyState}, + state::{Authorization, KeyState, id_or_none}, }; -use super::{execute::execute_status, Env}; +use super::{Env, execute::execute_status}; use crate::{ cannon::{error::AuthorizeError, router::AuthQuery}, - env::{error::ExecutionError, Environment}, + env::{Environment, error::ExecutionError}, server::error::ServerError, state::GlobalState, unwrap_or_not_found, diff --git a/crates/controlplane/src/server/actions/execute.rs b/crates/controlplane/src/server/actions/execute.rs index c7faccba..199bb302 100644 --- a/crates/controlplane/src/server/actions/execute.rs +++ b/crates/controlplane/src/server/actions/execute.rs @@ -1,9 +1,9 @@ use std::sync::Arc; use axum::{ + Json, extract::{Query, State}, response::{IntoResponse, Response}, - Json, }; use http::StatusCode; use serde_json::json; @@ -11,14 +11,14 @@ use snops_common::{ action_models::{AleoValue, ExecuteAction}, aot_cmds::AotCmd, events::{Event, EventKind}, - state::{id_or_none, Authorization, KeyState}, + state::{Authorization, KeyState, id_or_none}, }; use tokio::select; use super::Env; use crate::{ cannon::{error::AuthorizeError, router::AuthQuery}, - env::{error::ExecutionError, Environment}, + env::{Environment, error::ExecutionError}, events::EventSubscriber, server::error::{ActionError, ServerError}, state::GlobalState, diff --git a/crates/controlplane/src/server/actions/mod.rs b/crates/controlplane/src/server/actions/mod.rs index d269e173..9c1d298a 100644 --- a/crates/controlplane/src/server/actions/mod.rs +++ b/crates/controlplane/src/server/actions/mod.rs @@ -1,13 +1,13 @@ use std::sync::Arc; use axum::{ + Router, extract::{Extension, FromRequestParts, Path}, response::{IntoResponse, Response}, routing::post, - Router, }; use http::request::Parts; -use snops_common::state::{id_or_none, EnvId}; +use snops_common::state::{EnvId, id_or_none}; use super::error::ServerError; use crate::{env::Environment, state::AppState}; diff --git a/crates/controlplane/src/server/actions/power.rs b/crates/controlplane/src/server/actions/power.rs index 1cc79f97..66d5fbaa 100644 --- a/crates/controlplane/src/server/actions/power.rs +++ b/crates/controlplane/src/server/actions/power.rs @@ -1,8 +1,8 @@ use std::collections::{HashMap, HashSet}; use axum::{ - response::{IntoResponse, Response}, Json, + response::{IntoResponse, Response}, }; use snops_common::{ action_models::WithTargets, @@ -12,7 +12,7 @@ use snops_common::{ use tracing::info; use super::Env; -use crate::state::{pending_reconcile_node_map, GlobalState}; +use crate::state::{GlobalState, pending_reconcile_node_map}; async fn wait_for_nodes( state: &GlobalState, diff --git a/crates/controlplane/src/server/agent_ws.rs b/crates/controlplane/src/server/agent_ws.rs index e249c82b..2b5234b5 100644 --- a/crates/controlplane/src/server/agent_ws.rs +++ b/crates/controlplane/src/server/agent_ws.rs @@ -3,8 +3,8 @@ use std::sync::Arc; use ::jwt::VerifyWithKey; use axum::{ extract::{ - ws::{Message, WebSocket}, Query, State, WebSocketUpgrade, + ws::{Message, WebSocket}, }, http::HeaderMap, response::{IntoResponse, Response}, @@ -18,8 +18,8 @@ use snops_common::{ constant::HEADER_AGENT_KEY, prelude::*, rpc::control::{ - agent::{AgentServiceClient, Handshake}, ControlService, + agent::{AgentServiceClient, Handshake}, }, }; use tarpc::{context, server::Channel}; diff --git a/crates/controlplane/src/server/api.rs b/crates/controlplane/src/server/api.rs index 18f50821..50c16888 100644 --- a/crates/controlplane/src/server/api.rs +++ b/crates/controlplane/src/server/api.rs @@ -1,11 +1,11 @@ use std::{collections::HashMap, str::FromStr}; use axum::{ + Json, Router, extract::{self, Path, Query, State}, http::StatusCode, response::{IntoResponse, Response}, routing::{delete, get, post}, - Json, Router, }; use indexmap::IndexSet; use serde::Deserialize; @@ -15,7 +15,7 @@ use snops_common::{ lasso::Spur, node_targets::NodeTargets, rpc::control::agent::AgentMetric, - state::{id_or_none, AgentModeOptions, AgentState, CannonId, EnvId, KeyState, NodeKey}, + state::{AgentModeOptions, AgentState, CannonId, EnvId, KeyState, NodeKey, id_or_none}, }; use tarpc::context; @@ -32,7 +32,7 @@ use crate::{ #[macro_export] macro_rules! unwrap_or_not_found { - ($s:expr, $e:expr) => { + ($s:expr_2021, $e:expr_2021) => { match $e { Some(v) => v, None => return ServerError::NotFound($s.to_owned()).into_response(), @@ -42,7 +42,7 @@ macro_rules! unwrap_or_not_found { #[macro_export] macro_rules! unwrap_or_bad_request { - ($s:expr, $e:expr) => { + ($s:expr_2021, $e:expr_2021) => { match $e { Some(v) => v, None => return ServerError::BadRequest($s.to_owned()).into_response(), @@ -447,7 +447,7 @@ async fn get_mapping_value( } _ => { return ServerError::BadRequest("either key or key_source must be provided".to_owned()) - .into_response() + .into_response(); } }; @@ -522,12 +522,17 @@ async fn find_agents( let env_matches = if payload.all { // if we ask for all env we just say true true - } else if let Some(env) = payload.env { - // otherwise if the env is specified we check it matches - agent.env().map_or(false, |a_env| env == a_env) } else { - // if no env is specified - agent.state() == &AgentState::Inventory + match payload.env { + Some(env) => { + // otherwise if the env is specified we check it matches + agent.env() == Some(env) + } + _ => { + // if no env is specified + agent.state() == &AgentState::Inventory + } + } }; // if all is specified we don't care about whether an agent's connection diff --git a/crates/controlplane/src/server/content.rs b/crates/controlplane/src/server/content.rs index 5c4699f0..f2cc0437 100644 --- a/crates/controlplane/src/server/content.rs +++ b/crates/controlplane/src/server/content.rs @@ -1,16 +1,16 @@ use std::str::FromStr; use axum::{ + Router, extract::{Path, Request, State}, middleware, response::{IntoResponse, Redirect, Response}, routing::get, - Router, }; use http::{StatusCode, Uri}; use snops_common::{ binaries::{BinaryEntry, BinarySource}, - state::{id_or_none, InternedId, NetworkId}, + state::{InternedId, NetworkId, id_or_none}, }; use tower::Service; use tower_http::services::ServeFile; @@ -29,7 +29,7 @@ async fn not_found(uri: Uri, res: Response) -> Response { match res.status() { StatusCode::NOT_FOUND => { let path = uri.path(); - let content = path.split('/').last().unwrap(); + let content = path.split('/').next_back().unwrap(); ServerError::ContentNotFound(content.to_owned()).into_response() } _ => res, diff --git a/crates/controlplane/src/server/error.rs b/crates/controlplane/src/server/error.rs index 8c37c1ee..bffca103 100644 --- a/crates/controlplane/src/server/error.rs +++ b/crates/controlplane/src/server/error.rs @@ -1,6 +1,6 @@ -use axum::{response::IntoResponse, Json}; +use axum::{Json, response::IntoResponse}; use http::StatusCode; -use serde::{ser::SerializeStruct, Serialize, Serializer}; +use serde::{Serialize, Serializer, ser::SerializeStruct}; use serde_json::json; use snops_common::{ aot_cmds::AotCmdError, db::error::DatabaseError, events::TransactionAbortReason, diff --git a/crates/controlplane/src/server/event_ws.rs b/crates/controlplane/src/server/event_ws.rs index b0af7513..a291fc63 100644 --- a/crates/controlplane/src/server/event_ws.rs +++ b/crates/controlplane/src/server/event_ws.rs @@ -2,8 +2,8 @@ use std::collections::HashMap; use axum::{ extract::{ - ws::{Message, WebSocket}, Query, State, WebSocketUpgrade, + ws::{Message, WebSocket}, }, response::Response, }; diff --git a/crates/controlplane/src/server/mod.rs b/crates/controlplane/src/server/mod.rs index 277cceaf..972c6322 100644 --- a/crates/controlplane/src/server/mod.rs +++ b/crates/controlplane/src/server/mod.rs @@ -1,6 +1,6 @@ use std::{net::SocketAddr, sync::Arc}; -use axum::{middleware, routing::get, Extension, Router}; +use axum::{Extension, Router, middleware, routing::get}; use self::error::StartError; use crate::{ diff --git a/crates/controlplane/src/server/prometheus.rs b/crates/controlplane/src/server/prometheus.rs index af76bb53..14070b14 100644 --- a/crates/controlplane/src/server/prometheus.rs +++ b/crates/controlplane/src/server/prometheus.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use axum::{extract::State, response::IntoResponse, routing::get, Json, Router}; +use axum::{Json, Router, extract::State, response::IntoResponse, routing::get}; use rayon::iter::{ParallelBridge, ParallelIterator}; use serde::Serialize; use snops_common::state::AgentState; diff --git a/crates/controlplane/src/server/rpc.rs b/crates/controlplane/src/server/rpc.rs index 367a12b5..e3c8b94e 100644 --- a/crates/controlplane/src/server/rpc.rs +++ b/crates/controlplane/src/server/rpc.rs @@ -5,11 +5,11 @@ use snops_common::events::AgentEvent; use snops_common::{ api::AgentEnvInfo, define_rpc_mux, - prelude::{error::ReconcileError, ReconcileStatus}, + prelude::{ReconcileStatus, error::ReconcileError}, rpc::{ control::{ - agent::{AgentServiceRequest, AgentServiceResponse}, ControlService, ControlServiceRequest, ControlServiceResponse, + agent::{AgentServiceRequest, AgentServiceResponse}, }, error::ResolveError, }, diff --git a/crates/controlplane/src/state/agent.rs b/crates/controlplane/src/state/agent.rs index 7e25f87b..28c8f173 100644 --- a/crates/controlplane/src/state/agent.rs +++ b/crates/controlplane/src/state/agent.rs @@ -11,13 +11,13 @@ use rand::{Rng, SeedableRng}; use rand_chacha::ChaChaRng; use serde::{Deserialize, Serialize}; use snops_common::{ + INTERN, events::Event, lasso::Spur, rpc::control::agent::AgentServiceClient, state::{ AgentId, AgentModeOptions, AgentState, AgentStatus, EnvId, NodeKey, NodeState, PortConfig, }, - INTERN, }; use super::{AgentClient, AgentFlags, PendingAgentReconcile}; @@ -58,7 +58,7 @@ impl Agent { env_claim: Arc::new(Busy), claims: Claims { id, - nonce: ChaChaRng::from_entropy().gen(), + nonce: ChaChaRng::from_entropy().r#gen(), }, connection: AgentConnection::Online(rpc), state: Default::default(), @@ -121,7 +121,7 @@ impl Agent { pub fn has_label_str(&self, label: &str) -> bool { INTERN .get(label) - .map_or(false, |label| self.flags.labels.contains(&label)) + .is_some_and(|label| self.flags.labels.contains(&label)) } pub fn str_labels(&self) -> IndexSet<&str> { diff --git a/crates/controlplane/src/state/agent_flags.rs b/crates/controlplane/src/state/agent_flags.rs index d3eecf95..00e37cf2 100644 --- a/crates/controlplane/src/state/agent_flags.rs +++ b/crates/controlplane/src/state/agent_flags.rs @@ -2,10 +2,10 @@ use fixedbitset::FixedBitSet; use indexmap::IndexSet; use serde::{Deserialize, Serialize}; use snops_common::{ + INTERN, lasso::Spur, - set::{MaskBit, MASK_PREFIX_LEN}, + set::{MASK_PREFIX_LEN, MaskBit}, state::AgentModeOptions, - INTERN, }; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] diff --git a/crates/controlplane/src/state/external_peers.rs b/crates/controlplane/src/state/external_peers.rs index df360bfb..923116f4 100644 --- a/crates/controlplane/src/state/external_peers.rs +++ b/crates/controlplane/src/state/external_peers.rs @@ -6,11 +6,11 @@ use serde_json::Value; use snops_common::state::{EnvId, LatestBlockInfo, NetworkId, NodeKey}; use tokio::{sync::mpsc, time::timeout}; -use super::{snarkos_request, AgentClient, GlobalState}; +use super::{AgentClient, GlobalState, snarkos_request}; use crate::{ env::{ - cache::{ABlockHash, ATransactionId, MAX_BLOCK_RANGE}, EnvNodeState, EnvPeer, + cache::{ABlockHash, ATransactionId, MAX_BLOCK_RANGE}, }, schema::nodes::ExternalNode, }; diff --git a/crates/controlplane/src/state/global.rs b/crates/controlplane/src/state/global.rs index f945bc71..a87162e1 100644 --- a/crates/controlplane/src/state/global.rs +++ b/crates/controlplane/src/state/global.rs @@ -18,18 +18,18 @@ use tokio::sync::Semaphore; use tracing::info; use super::{ - snarkos_request::{self, reparse_json_env}, AddrMap, AgentClient, AgentPool, EnvMap, StorageMap, + snarkos_request::{self, reparse_json_env}, }; use crate::{ + ReloadHandler, cli::Cli, db::Database, - env::{cache::NetworkCache, error::EnvRequestError, Environment, PortType}, + env::{Environment, PortType, cache::NetworkCache, error::EnvRequestError}, error::StateError, events::Events, schema::storage::{LoadedStorage, STORAGE_DIR}, server::error::StartError, - ReloadHandler, }; lazy_static::lazy_static! { diff --git a/crates/controlplane/src/state/rpc.rs b/crates/controlplane/src/state/rpc.rs index f55f82ae..6cc306aa 100644 --- a/crates/controlplane/src/state/rpc.rs +++ b/crates/controlplane/src/state/rpc.rs @@ -4,7 +4,7 @@ use serde::de::DeserializeOwned; use snops_common::{ rpc::{control::agent::AgentServiceClient, error::SnarkosRequestError}, state::{ - snarkos_status::SnarkOSLiteBlock, AgentId, AgentState, EnvId, NetworkId, ReconcileOptions, + AgentId, AgentState, EnvId, NetworkId, ReconcileOptions, snarkos_status::SnarkOSLiteBlock, }, }; use tarpc::{client::RpcError, context}; diff --git a/crates/controlplane/src/state/snarkos_request.rs b/crates/controlplane/src/state/snarkos_request.rs index ee42cb98..b6f44f66 100644 --- a/crates/controlplane/src/state/snarkos_request.rs +++ b/crates/controlplane/src/state/snarkos_request.rs @@ -1,6 +1,6 @@ use std::net::SocketAddr; -use serde::{de::DeserializeOwned, Serialize}; +use serde::{Serialize, de::DeserializeOwned}; use serde_json::json; use snops_common::{rpc::error::SnarkosRequestError, state::NetworkId}; diff --git a/crates/controlplane/src/state/transactions.rs b/crates/controlplane/src/state/transactions.rs index 6f54d1a1..dc0c45c5 100644 --- a/crates/controlplane/src/state/transactions.rs +++ b/crates/controlplane/src/state/transactions.rs @@ -57,13 +57,10 @@ pub async fn tracking_task(state: Arc) { let state = state.clone(); let cannon_target = cannon.sink.target.as_ref(); async move { - let (tx_id, hash) = if let Some(hash) = state.env_network_cache.get(&env_id).and_then(|cache| cache.find_transaction(&tx_id).cloned()) { + let (tx_id, hash) = match state.env_network_cache.get(&env_id).and_then(|cache| cache.find_transaction(&tx_id).cloned()) { Some(hash) => { trace!("cannon {env_id}.{cannon_id} confirmed transaction {tx_id} (cache hit)"); (tx_id, hash.to_string()) - } - - // check if the transaction not is in the cache, then check the peers - else if let Some(target) = cannon_target { + } _ => if let Some(target) = cannon_target { match timeout(Duration::from_secs(1), state.snarkos_get::>(env_id, format!("/find/blockHash/{tx_id}"), target)).await { Ok(Ok(Some(hash))) => { @@ -75,7 +72,7 @@ pub async fn tracking_task(state: Arc) { } } else { return None; - }; + }}; // Emit a confirmed event TransactionEvent::Confirmed { hash } @@ -140,7 +137,9 @@ fn get_pending_transactions(state: &GlobalState) -> Vec<((EnvId, CannonId), Pend // any authorized transaction that is not started should be queued TransactionSendState::Authorized => { if cannon.sink.authorize_attempts.is_some_and(|a| attempts > a) { - info!("cannon {env_id}.{cannon_id} removed auth {tx_id} (too many attempts)"); + info!( + "cannon {env_id}.{cannon_id} removed auth {tx_id} (too many attempts)" + ); to_remove.push(tx_id); ev.replace_content(TransactionEvent::ExecuteExceeded { attempts }) .emit(state); @@ -154,7 +153,9 @@ fn get_pending_transactions(state: &GlobalState) -> Vec<((EnvId, CannonId), Pend > TimeDelta::seconds(cannon.sink.authorize_timeout as i64) => { if cannon.sink.authorize_attempts.is_some_and(|a| attempts > a) { - info!("cannon {env_id}.{cannon_id} removed auth {tx_id} (too many attempts)"); + info!( + "cannon {env_id}.{cannon_id} removed auth {tx_id} (too many attempts)" + ); ev.replace_content(TransactionEvent::ExecuteExceeded { attempts }) .emit(state); to_remove.push(tx_id); @@ -165,7 +166,9 @@ fn get_pending_transactions(state: &GlobalState) -> Vec<((EnvId, CannonId), Pend // any unbroadcasted transaction that is not started should be queued TransactionSendState::Unsent => { if cannon.sink.broadcast_attempts.is_some_and(|a| attempts > a) { - info!("cannon {env_id}.{cannon_id} removed broadcast {tx_id} (too many attempts)"); + info!( + "cannon {env_id}.{cannon_id} removed broadcast {tx_id} (too many attempts)" + ); ev.replace_content(TransactionEvent::BroadcastExceeded { attempts }) .emit(state); to_remove.push(tx_id); @@ -203,7 +206,9 @@ fn get_pending_transactions(state: &GlobalState) -> Vec<((EnvId, CannonId), Pend > TimeDelta::seconds(cannon.sink.broadcast_timeout as i64) { if cannon.sink.broadcast_attempts.is_some_and(|a| attempts > a) { - info!("cannon {env_id}.{cannon_id} removed broadcast {tx_id} (too many attempts)"); + info!( + "cannon {env_id}.{cannon_id} removed broadcast {tx_id} (too many attempts)" + ); ev.replace_content(TransactionEvent::BroadcastExceeded { attempts, }) diff --git a/crates/xtask/Cargo.toml b/crates/xtask/Cargo.toml index 1afeccbc..959129c3 100644 --- a/crates/xtask/Cargo.toml +++ b/crates/xtask/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "xtask" version = "0.1.0" -edition = "2021" +edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/crates/xtask/src/main.rs b/crates/xtask/src/main.rs index 6b395844..2f9e7b3b 100644 --- a/crates/xtask/src/main.rs +++ b/crates/xtask/src/main.rs @@ -1,8 +1,8 @@ #![allow(dead_code)] -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use clap::{Parser, Subcommand, ValueEnum}; -use xshell::{cmd, Shell}; +use xshell::{Shell, cmd}; #[derive(Parser)] struct Args {