Skip to content

Commit

Permalink
chore: make format
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasArrachea committed Mar 5, 2025
1 parent 1bc8dd2 commit 440bf9a
Show file tree
Hide file tree
Showing 51 changed files with 122 additions and 115 deletions.
12 changes: 6 additions & 6 deletions bin/faucet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ use std::path::PathBuf;

use anyhow::Context;
use axum::{
routing::{get, post},
Router,
routing::{get, post},
};
use clap::{Parser, Subcommand};
use client::initialize_faucet_client;
use handlers::{get_background, get_favicon, get_index_css, get_index_html, get_index_js};
use http::HeaderValue;
use miden_lib::{account::faucets::create_basic_fungible_faucet, AuthScheme};
use miden_lib::{AuthScheme, account::faucets::create_basic_fungible_faucet};
use miden_node_utils::{
config::load_config, crypto::get_rpo_random_coin, logging::OpenTelemetry, version::LongVersion,
};
use miden_objects::{
Felt,
account::{AccountFile, AccountStorageMode, AuthSecretKey},
asset::TokenSymbol,
crypto::dsa::rpo_falcon512::SecretKey,
Felt,
};
use rand::{Rng, SeedableRng};
use rand_chacha::ChaCha20Rng;
Expand All @@ -38,7 +38,7 @@ use tower_http::{cors::CorsLayer, set_header::SetResponseHeaderLayer, trace::Tra
use tracing::info;

use crate::{
config::{FaucetConfig, DEFAULT_FAUCET_ACCOUNT_PATH},
config::{DEFAULT_FAUCET_ACCOUNT_PATH, FaucetConfig},
handlers::{get_metadata, get_tokens},
};

Expand Down Expand Up @@ -249,10 +249,10 @@ mod test {
};

use fantoccini::ClientBuilder;
use serde_json::{json, Map};
use serde_json::{Map, json};
use url::Url;

use crate::{config::FaucetConfig, run_faucet_command, stub_rpc_api::serve_stub, Cli};
use crate::{Cli, config::FaucetConfig, run_faucet_command, stub_rpc_api::serve_stub};

/// This test starts a stub node, a faucet connected to the stub node, and a chromedriver
/// to test the faucet website. It then loads the website and checks that all the requests
Expand Down
16 changes: 11 additions & 5 deletions bin/node/src/commands/genesis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ use std::{
path::{Path, PathBuf},
};

use anyhow::{anyhow, bail, Context, Result};
use anyhow::{Context, Result, anyhow, bail};
pub use inputs::{AccountInput, AuthSchemeInput, GenesisInput};
use miden_lib::{account::faucets::create_basic_fungible_faucet, AuthScheme};
use miden_lib::{AuthScheme, account::faucets::create_basic_fungible_faucet};
use miden_node_store::genesis::GenesisState;
use miden_node_utils::{config::load_config, crypto::get_rpo_random_coin};
use miden_objects::{
Felt, ONE,
account::{Account, AccountFile, AccountIdAnchor, AuthSecretKey},
asset::TokenSymbol,
crypto::{dsa::rpo_falcon512::SecretKey, utils::Serializable},
Felt, ONE,
};
use rand::{Rng, SeedableRng};
use rand_chacha::ChaCha20Rng;
Expand Down Expand Up @@ -45,7 +45,10 @@ pub fn make_genesis(inputs_path: &PathBuf, output_path: &PathBuf, force: bool) -
if !force {
if let Ok(file_exists) = output_path.try_exists() {
if file_exists {
return Err(anyhow!("Failed to generate new genesis file {} because it already exists. Use the --force flag to overwrite.", output_path.display()));
return Err(anyhow!(
"Failed to generate new genesis file {} because it already exists. Use the --force flag to overwrite.",
output_path.display()
));
}
} else {
return Err(anyhow!("Failed to open {} file.", output_path.display()));
Expand Down Expand Up @@ -142,7 +145,10 @@ fn create_accounts(
let path = accounts_path.as_ref().join(format!("{name}.mac"));

if !force && matches!(path.try_exists(), Ok(true)) {
bail!("Failed to generate account file {} because it already exists. Use the --force flag to overwrite.", path.display());
bail!(
"Failed to generate account file {} because it already exists. Use the --force flag to overwrite.",
path.display()
);
}

account_data.account.set_nonce(ONE)?;
Expand Down
2 changes: 1 addition & 1 deletion bin/node/src/commands/init.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fs::File, io::Write, path::Path};

use anyhow::{anyhow, Result};
use anyhow::{Result, anyhow};

use crate::{commands::genesis::GenesisInput, config::NodeConfig};

Expand Down
2 changes: 1 addition & 1 deletion bin/node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ mod tests {

use super::NodeConfig;
use crate::{
config::{NormalizedBlockProducerConfig, NormalizedRpcConfig},
NODE_CONFIG_FILE_PATH,
config::{NormalizedBlockProducerConfig, NormalizedRpcConfig},
};

#[test]
Expand Down
2 changes: 1 addition & 1 deletion bin/node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::path::PathBuf;

use anyhow::{anyhow, Context};
use anyhow::{Context, anyhow};
use clap::{Parser, Subcommand};
use commands::{init::init_config_files, start::start_node};
use miden_node_block_producer::server::BlockProducer;
Expand Down
8 changes: 4 additions & 4 deletions crates/block-producer/src/batch_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ use std::{num::NonZeroUsize, ops::Range, time::Duration};
use miden_node_proto::domain::batch::BatchInputs;
use miden_node_utils::formatting::format_array;
use miden_objects::{
batch::{BatchId, ProposedBatch, ProvenBatch},
MIN_PROOF_SECURITY_LEVEL,
batch::{BatchId, ProposedBatch, ProvenBatch},
};
use miden_tx_batch_prover::LocalBatchProver;
use rand::Rng;
use tokio::{task::JoinSet, time};
use tracing::{debug, info, instrument, Span};
use tracing::{Span, debug, info, instrument};

use crate::{
domain::transaction::AuthenticatedTransaction, errors::BuildBatchError, mempool::SharedMempool,
store::StoreClient, COMPONENT, SERVER_BUILD_BATCH_FREQUENCY,
COMPONENT, SERVER_BUILD_BATCH_FREQUENCY, domain::transaction::AuthenticatedTransaction,
errors::BuildBatchError, mempool::SharedMempool, store::StoreClient,
};

// BATCH BUILDER
Expand Down
8 changes: 4 additions & 4 deletions crates/block-producer/src/block_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ use futures::FutureExt;
use miden_block_prover::LocalBlockProver;
use miden_node_utils::tracing::OpenTelemetrySpanExt;
use miden_objects::{
MIN_PROOF_SECURITY_LEVEL,
batch::ProvenBatch,
block::{BlockInputs, BlockNumber, ProposedBlock, ProvenBlock},
note::NoteHeader,
MIN_PROOF_SECURITY_LEVEL,
};
use rand::Rng;
use tokio::time::Duration;
use tracing::{instrument, Span};
use tracing::{Span, instrument};

use crate::{
errors::BuildBlockError, mempool::SharedMempool, store::StoreClient, COMPONENT,
SERVER_BLOCK_FREQUENCY,
COMPONENT, SERVER_BLOCK_FREQUENCY, errors::BuildBlockError, mempool::SharedMempool,
store::StoreClient,
};

// BLOCK BUILDER
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/domain/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::{collections::BTreeSet, sync::Arc};

use miden_objects::{
Digest,
account::AccountId,
block::BlockNumber,
note::{NoteId, Nullifier},
transaction::{ProvenTransaction, TransactionId, TxAccountUpdate},
Digest,
};

use crate::{errors::VerifyTxError, store::TransactionInputs};
Expand Down
6 changes: 4 additions & 2 deletions crates/block-producer/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use miden_block_prover::ProvenBlockError;
use miden_node_proto::errors::ConversionError;
use miden_node_utils::formatting::format_opt;
use miden_objects::{
Digest, ProposedBatchError, ProposedBlockError,
block::BlockNumber,
note::{NoteId, Nullifier},
transaction::TransactionId,
Digest, ProposedBatchError, ProposedBlockError,
};
use miden_tx_batch_prover::errors::ProvenBatchError;
use thiserror::Error;
Expand Down Expand Up @@ -80,7 +80,9 @@ pub enum AddTransactionError {
#[error("transaction verification failed")]
VerificationFailed(#[from] VerifyTxError),

#[error("transaction input data from block {input_block} is rejected as stale because it is older than the limit of {stale_limit}")]
#[error(
"transaction input data from block {input_block} is rejected as stale because it is older than the limit of {stale_limit}"
)]
StaleInputs {
input_block: BlockNumber,
stale_limit: BlockNumber,
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/mempool/batch_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use miden_objects::{
};

use super::{
graph::{DependencyGraph, GraphError},
BlockBudget, BudgetStatus,
graph::{DependencyGraph, GraphError},
};

// BATCH GRAPH
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::VecDeque;

use miden_objects::{transaction::TransactionId, Digest};
use miden_objects::{Digest, transaction::TransactionId};

// IN-FLIGHT ACCOUNT STATE
// ================================================================================================
Expand Down Expand Up @@ -55,7 +55,8 @@ impl InflightAccountState {
pub fn revert(&mut self, n: usize) -> AccountStatus {
let uncommitted = self.uncommitted_count();
assert!(
uncommitted >= n, "Attempted to revert {n} transactions which is more than the {uncommitted} which are uncommitted.",
uncommitted >= n,
"Attempted to revert {n} transactions which is more than the {uncommitted} which are uncommitted.",
);

self.states.drain(self.states.len() - n..);
Expand All @@ -71,7 +72,8 @@ impl InflightAccountState {
pub fn commit(&mut self, n: usize) {
let uncommitted = self.uncommitted_count();
assert!(
uncommitted >= n, "Attempted to revert {n} transactions which is more than the {uncommitted} which are uncommitted."
uncommitted >= n,
"Attempted to revert {n} transactions which is more than the {uncommitted} which are uncommitted."
);

self.committed += n;
Expand Down
9 changes: 2 additions & 7 deletions crates/block-producer/src/mempool/inflight_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,7 @@ impl OutputNoteState {

/// Returns the source transaction ID if the output note is not yet committed.
fn transaction(&self) -> Option<&TransactionId> {
if let Self::Inflight(tx) = self {
Some(tx)
} else {
None
}
if let Self::Inflight(tx) = self { Some(tx) } else { None }
}
}

Expand All @@ -371,9 +367,8 @@ mod tests {

use super::*;
use crate::test_utils::{
mock_account_id,
MockProvenTxBuilder, mock_account_id,
note::{mock_note, mock_output_note},
MockProvenTxBuilder,
};

#[test]
Expand Down
6 changes: 3 additions & 3 deletions crates/block-producer/src/mempool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ use batch_graph::BatchGraph;
use graph::GraphError;
use inflight_state::InflightState;
use miden_objects::{
MAX_ACCOUNTS_PER_BATCH, MAX_INPUT_NOTES_PER_BATCH, MAX_OUTPUT_NOTES_PER_BATCH,
batch::{BatchId, ProvenBatch},
block::BlockNumber,
transaction::TransactionId,
MAX_ACCOUNTS_PER_BATCH, MAX_INPUT_NOTES_PER_BATCH, MAX_OUTPUT_NOTES_PER_BATCH,
};
use tokio::sync::{Mutex, MutexGuard};
use tracing::instrument;
use transaction_expiration::TransactionExpirations;
use transaction_graph::TransactionGraph;

use crate::{
domain::transaction::AuthenticatedTransaction, errors::AddTransactionError, COMPONENT,
SERVER_MAX_BATCHES_PER_BLOCK, SERVER_MAX_TXS_PER_BATCH,
COMPONENT, SERVER_MAX_BATCHES_PER_BLOCK, SERVER_MAX_TXS_PER_BATCH,
domain::transaction::AuthenticatedTransaction, errors::AddTransactionError,
};

mod batch_graph;
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/mempool/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use miden_objects::block::BlockNumber;
use pretty_assertions::assert_eq;

use super::*;
use crate::test_utils::{batch::TransactionBatchConstructor, MockProvenTxBuilder};
use crate::test_utils::{MockProvenTxBuilder, batch::TransactionBatchConstructor};

impl Mempool {
fn for_tests() -> Self {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{btree_map::Entry, BTreeMap, BTreeSet};
use std::collections::{BTreeMap, BTreeSet, btree_map::Entry};

use miden_objects::{block::BlockNumber, transaction::TransactionId};

Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/mempool/transaction_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::collections::BTreeSet;
use miden_objects::transaction::TransactionId;

use super::{
graph::{DependencyGraph, GraphError},
BatchBudget, BudgetStatus,
graph::{DependencyGraph, GraphError},
};
use crate::domain::transaction::AuthenticatedTransaction;

Expand Down
4 changes: 2 additions & 2 deletions crates/block-producer/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use miden_node_proto::generated::{
use miden_node_utils::{
errors::ApiError,
formatting::{format_input_notes, format_output_notes},
tracing::grpc::{block_producer_trace_fn, OtelInterceptor},
tracing::grpc::{OtelInterceptor, block_producer_trace_fn},
};
use miden_objects::{
block::BlockNumber, transaction::ProvenTransaction, utils::serde::Deserializable,
Expand All @@ -19,14 +19,14 @@ use tower_http::trace::TraceLayer;
use tracing::{debug, info, instrument};

use crate::{
COMPONENT, SERVER_MEMPOOL_EXPIRATION_SLACK, SERVER_MEMPOOL_STATE_RETENTION,
batch_builder::BatchBuilder,
block_builder::BlockBuilder,
config::BlockProducerConfig,
domain::transaction::AuthenticatedTransaction,
errors::{AddTransactionError, BlockProducerError, VerifyTxError},
mempool::{BatchBudget, BlockBudget, Mempool, SharedMempool},
store::StoreClient,
COMPONENT, SERVER_MEMPOOL_EXPIRATION_SLACK, SERVER_MEMPOOL_STATE_RETENTION,
};

/// Represents an initialized block-producer component where the RPC connection is open,
Expand Down
6 changes: 3 additions & 3 deletions crates/block-producer/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{

use itertools::Itertools;
use miden_node_proto::{
AccountState,
domain::batch::BatchInputs,
errors::{ConversionError, MissingFieldHelper},
generated::{
Expand All @@ -17,22 +18,21 @@ use miden_node_proto::{
responses::{GetTransactionInputsResponse, NullifierTransactionInputRecord},
store::api_client as store_client,
},
AccountState,
};
use miden_node_utils::{formatting::format_opt, tracing::grpc::OtelInterceptor};
use miden_objects::{
Digest,
account::AccountId,
block::{BlockHeader, BlockInputs, BlockNumber, ProvenBlock},
note::{NoteId, Nullifier},
transaction::ProvenTransaction,
utils::Serializable,
Digest,
};
use miden_processor::crypto::RpoDigest;
use tonic::{service::interceptor::InterceptedService, transport::Channel};
use tracing::{debug, info, instrument};

use crate::{errors::StoreError, COMPONENT};
use crate::{COMPONENT, errors::StoreError};

// TRANSACTION INPUTS
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/test_utils/account.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{collections::HashMap, ops::Not, sync::LazyLock};

use miden_objects::{
account::{AccountIdAnchor, AccountIdVersion, AccountStorageMode, AccountType},
Hasher,
account::{AccountIdAnchor, AccountIdVersion, AccountStorageMode, AccountType},
};

use super::*;
Expand Down
4 changes: 2 additions & 2 deletions crates/block-producer/src/test_utils/batch.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::collections::BTreeMap;

use miden_objects::{
Digest,
batch::{BatchAccountUpdate, BatchId, ProvenBatch},
block::BlockNumber,
transaction::{InputNotes, ProvenTransaction},
Digest,
};

use crate::test_utils::MockProvenTxBuilder;
Expand All @@ -19,7 +19,7 @@ pub trait TransactionBatchConstructor {
/// [`ProposedBatch`](miden_objects::batch::ProposedBatch) first and convert (without proving)
/// or prove it into a [`ProvenBatch`].
fn mocked_from_transactions<'tx>(txs: impl IntoIterator<Item = &'tx ProvenTransaction>)
-> Self;
-> Self;

/// Returns a `TransactionBatch` with `notes_per_tx.len()` transactions, where the i'th
/// transaction has `notes_per_tx[i]` notes created
Expand Down
Loading

0 comments on commit 440bf9a

Please sign in to comment.