Skip to content

Commit

Permalink
Merge branch 'next' into tomasarrachea-stress-test
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasArrachea committed Jan 17, 2025
2 parents 63916b8 + 61ea4e9 commit 5c39a4c
Show file tree
Hide file tree
Showing 105 changed files with 1,314 additions and 487 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ jobs:
- name: check rust versions
run: ./scripts/check-rust-version.sh

unused_deps:
name: check for unused dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- name: machete
uses: bnjbvr/cargo-machete@main

proto:
name: proto check
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Support Https in endpoint configuration (#556).
- Upgrade `block-producer` from FIFO queue to mempool dependency graph (#562).
- Support transaction expiration (#582).
- Improved RPC endpoints doc comments (#620).

### Changes

Expand Down
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,17 @@ tokio-stream = { version = "0.1" }
tonic = { version = "0.12" }
tracing = { version = "0.1" }
tracing-subscriber = { version = "0.3", features = ["fmt", "json", "env-filter"] }

# Lints are set to warn for development, which are promoted to errors in CI.
[workspace.lints.clippy]
# Pedantic lints are set to a lower priority which allows lints in the group to be selectively enabled.
pedantic = { level = "warn", priority = -1 }
cast_possible_truncation = "allow" # Overly many instances especially regarding indices.
ignored_unit_patterns = "allow" # Stylistic choice.
large_types_passed_by_value = "allow" # Triggered by BlockHeader being Copy + 334 bytes.
missing_errors_doc = "allow" # TODO: fixup and enable this.
missing_panics_doc = "allow" # TODO: fixup and enable this.
module_name_repetitions = "allow" # Many triggers, and is a stylistic choice.
must_use_candidate = "allow" # This marks many fn's which isn't helpful.
should_panic_without_expect = "allow" # We don't care about the specific panic message.
# End of pedantic lints.
4 changes: 3 additions & 1 deletion bin/faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ authors.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[dependencies]
anyhow = "1.0"
axum = { version = "0.7", features = ["tokio"] }
clap = { version = "4.5", features = ["derive", "string"] }
figment = { version = "0.10", features = ["toml", "env"] }
http = "1.1"
http-body-util = "0.1"
miden-lib = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions bin/faucet/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl FaucetClient {
let coin_seed: [u64; 4] = random();
let rng = RpoRandomCoin::new(coin_seed.map(Felt::new));

Ok(Self { data_store, rpc_api, executor, id, rng })
Ok(Self { rpc_api, executor, data_store, id, rng })
}

/// Executes a mint transaction for the target account.
Expand All @@ -137,7 +137,7 @@ impl FaucetClient {
target_account_id,
vec![asset.into()],
note_type,
Default::default(),
Felt::default(),
&mut self.rng,
)
.context("Failed to create P2ID note")?;
Expand Down
2 changes: 1 addition & 1 deletion bin/faucet/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub async fn get_tokens(
let block_height = client.prove_and_submit_transaction(executed_tx).await?;

// Update data store with the new faucet state
client.data_store().update_faucet_state(faucet_account).await?;
client.data_store().update_faucet_state(faucet_account);

let note_id: NoteId = created_note.id();
let note_details =
Expand Down
2 changes: 1 addition & 1 deletion bin/faucet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ mod static_resources {
include!(concat!(env!("OUT_DIR"), "/generated.rs"));
}

/// Generates [LongVersion] using the metadata generated by build.rs.
/// Generates [`LongVersion`] using the metadata generated by build.rs.
fn long_version() -> LongVersion {
// Use optional to allow for build script embedding failure.
LongVersion {
Expand Down
2 changes: 1 addition & 1 deletion bin/faucet/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ impl FaucetState {

info!(target: COMPONENT, account_id = %id, "Faucet initialization successful");

Ok(FaucetState { client, id, config, static_files })
Ok(FaucetState { id, client, config, static_files })
}
}
6 changes: 1 addition & 5 deletions bin/faucet/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use miden_objects::{
};
use miden_tx::{DataStore, DataStoreError};

use crate::errors::HandlerError;

pub struct FaucetDataStore {
faucet_account: Mutex<Account>,
/// Optional initial seed used for faucet account creation.
Expand Down Expand Up @@ -42,10 +40,8 @@ impl FaucetDataStore {
}

/// Updates the stored faucet account with the new one.
pub async fn update_faucet_state(&self, new_faucet_state: Account) -> Result<(), HandlerError> {
pub fn update_faucet_state(&self, new_faucet_state: Account) {
*self.faucet_account.lock().expect("Poisoned lock") = new_faucet_state;

Ok(())
}
}

Expand Down
4 changes: 3 additions & 1 deletion bin/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ authors.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[features]
tracing-forest = ["miden-node-block-producer/tracing-forest"]

Expand All @@ -29,7 +32,6 @@ serde = { version = "1.0", features = ["derive"] }
tokio = { workspace = true, features = ["rt-multi-thread", "net", "macros"] }
toml = { version = "0.8" }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }

[dev-dependencies]
figment = { version = "0.10", features = ["toml", "env", "test"] }
Expand Down
2 changes: 1 addition & 1 deletion bin/node/src/commands/genesis/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Default for GenesisInput {
auth_scheme: AuthSchemeInput::RpoFalcon512,
token_symbol: "POL".to_string(),
decimals: 12,
max_supply: 1000000,
max_supply: 1_000_000,
storage_mode: "public".to_string(),
})]),
}
Expand Down
26 changes: 10 additions & 16 deletions bin/node/src/commands/genesis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const DEFAULT_ACCOUNTS_DIR: &str = "accounts/";
/// This function returns a `Result` type. On successful creation of the genesis file, it returns
/// `Ok(())`. If it fails at any point, due to issues like file existence checks or read/write
/// operations, it returns an `Err` with a detailed error message.
pub fn make_genesis(inputs_path: &PathBuf, output_path: &PathBuf, force: &bool) -> Result<()> {
pub fn make_genesis(inputs_path: &PathBuf, output_path: &PathBuf, force: bool) -> Result<()> {
let inputs_path = Path::new(inputs_path);
let output_path = Path::new(output_path);

Expand All @@ -63,14 +63,8 @@ pub fn make_genesis(inputs_path: &PathBuf, output_path: &PathBuf, force: &bool)
return Err(anyhow!("Failed to open {} file.", inputs_path.display()));
}

let parent_path = match output_path.parent() {
Some(path) => path,
None => {
return Err(anyhow!(
"There has been an error processing output_path: {}",
output_path.display()
))
},
let Some(parent_path) = output_path.parent() else {
anyhow::bail!("There has been an error processing output_path: {}", output_path.display());
};

let genesis_input: GenesisInput = load_config(inputs_path).map_err(|err| {
Expand All @@ -97,7 +91,7 @@ pub fn make_genesis(inputs_path: &PathBuf, output_path: &PathBuf, force: &bool)
fn create_accounts(
accounts: &[AccountInput],
accounts_path: impl AsRef<Path>,
force: &bool,
force: bool,
) -> Result<Vec<Account>> {
if accounts_path.as_ref().try_exists()? {
if !force {
Expand All @@ -120,7 +114,7 @@ fn create_accounts(
let (mut account_data, name) = match account {
AccountInput::BasicFungibleFaucet(inputs) => {
info!("Creating fungible faucet account...");
let (auth_scheme, auth_secret_key) = gen_auth_keys(inputs.auth_scheme, &mut rng)?;
let (auth_scheme, auth_secret_key) = gen_auth_keys(inputs.auth_scheme, &mut rng);

let storage_mode = inputs.storage_mode.as_str().try_into()?;
let (account, account_seed) = create_basic_fungible_faucet(
Expand Down Expand Up @@ -166,15 +160,15 @@ fn create_accounts(
fn gen_auth_keys(
auth_scheme_input: AuthSchemeInput,
rng: &mut ChaCha20Rng,
) -> Result<(AuthScheme, AuthSecretKey)> {
) -> (AuthScheme, AuthSecretKey) {
match auth_scheme_input {
AuthSchemeInput::RpoFalcon512 => {
let secret = SecretKey::with_rng(&mut get_rpo_random_coin(rng));

Ok((
(
AuthScheme::RpoFalcon512 { pub_key: secret.public_key() },
AuthSecretKey::RpoFalcon512(secret),
))
)
},
}
}
Expand Down Expand Up @@ -217,7 +211,7 @@ mod tests {
let genesis_dat_file_path = PathBuf::from(DEFAULT_GENESIS_FILE_PATH);

// run make_genesis to generate genesis.dat and accounts folder and files
super::make_genesis(&genesis_inputs_file_path, &genesis_dat_file_path, &true).unwrap();
super::make_genesis(&genesis_inputs_file_path, &genesis_dat_file_path, true).unwrap();

let a0_file_path = PathBuf::from("accounts/faucet.mac");

Expand All @@ -235,7 +229,7 @@ mod tests {
let genesis_state = GenesisState::read_from_bytes(&genesis_file_contents).unwrap();

// build supposed genesis_state
let supposed_genesis_state = GenesisState::new(vec![a0.account], 1, 1672531200);
let supposed_genesis_state = GenesisState::new(vec![a0.account], 1, 1_672_531_200);

// assert that both genesis_state(s) are eq
assert_eq!(genesis_state, supposed_genesis_state);
Expand Down
14 changes: 7 additions & 7 deletions bin/node/src/commands/init.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fs::File, io::Write, path::PathBuf};
use std::{fs::File, io::Write, path::Path};

use anyhow::{anyhow, Result};

Expand All @@ -7,27 +7,27 @@ use crate::{commands::genesis::GenesisInput, config::NodeConfig};
// INIT
// ===================================================================================================

pub fn init_config_files(config_file_path: PathBuf, genesis_file_path: PathBuf) -> Result<()> {
pub fn init_config_files(config_file_path: &Path, genesis_file_path: &Path) -> Result<()> {
let config = NodeConfig::default();
let config_as_toml_string = toml::to_string(&config)
.map_err(|err| anyhow!("Failed to serialize default config: {}", err))?;

write_string_in_file(config_as_toml_string, &config_file_path)?;
write_string_in_file(&config_as_toml_string, config_file_path)?;

println!("Config file successfully created at: {:?}", config_file_path);
println!("Config file successfully created at: {config_file_path:?}");

let genesis = GenesisInput::default();
let genesis_as_toml_string = toml::to_string(&genesis)
.map_err(|err| anyhow!("Failed to serialize default config: {}", err))?;

write_string_in_file(genesis_as_toml_string, &genesis_file_path)?;
write_string_in_file(&genesis_as_toml_string, genesis_file_path)?;

println!("Genesis config file successfully created at: {:?}", genesis_file_path);
println!("Genesis config file successfully created at: {genesis_file_path:?}");

Ok(())
}

fn write_string_in_file(content: String, path: &PathBuf) -> Result<()> {
fn write_string_in_file(content: &str, path: &Path) -> Result<()> {
let mut file_handle = File::options()
.write(true)
.create_new(true)
Expand Down
4 changes: 2 additions & 2 deletions bin/node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ pub struct NodeConfig {
store: StoreConfig,
}

/// A specialized variant of [RpcConfig] with redundant fields within [NodeConfig] removed.
/// A specialized variant of [`RpcConfig`] with redundant fields within [`NodeConfig`] removed.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
struct NormalizedRpcConfig {
endpoint: Endpoint,
}

/// A specialized variant of [BlockProducerConfig] with redundant fields within [NodeConfig]
/// A specialized variant of [`BlockProducerConfig`] with redundant fields within [`NodeConfig`]
/// removed.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
Expand Down
6 changes: 3 additions & 3 deletions bin/node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async fn main() -> anyhow::Result<()> {
},
},
Command::MakeGenesis { output_path, force, inputs_path } => {
commands::make_genesis(inputs_path, output_path, force)
commands::make_genesis(inputs_path, output_path, *force)
},
Command::Init { config_path, genesis_path } => {
let current_dir = std::env::current_dir()
Expand All @@ -130,12 +130,12 @@ async fn main() -> anyhow::Result<()> {
let config = current_dir.join(config_path);
let genesis = current_dir.join(genesis_path);

init_config_files(config, genesis)
init_config_files(&config, &genesis)
},
}
}

/// Generates [LongVersion] using the metadata generated by build.rs.
/// Generates [`LongVersion`] using the metadata generated by build.rs.
fn long_version() -> LongVersion {
LongVersion {
version: env!("CARGO_PKG_VERSION"),
Expand Down
3 changes: 3 additions & 0 deletions crates/block-producer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ authors.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[features]
tracing-forest = ["miden-node-utils/tracing-forest"]
testing = []
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Submits proven transaction to the Miden network.

**Parameters**

* `transaction`: `bytes` - transaction encoded using Miden's native format.
* `transaction`: `bytes` - transaction encoded using [winter_utils::Serializable](https://github.com/facebook/winterfell/blob/main/utils/core/src/serde/mod.rs#L26) implementation for [miden_objects::transaction::proven_tx::ProvenTransaction](https://github.com/0xPolygonMiden/miden-base/blob/main/objects/src/transaction/proven_tx.rs#L22).

**Returns**

Expand Down
Loading

0 comments on commit 5c39a4c

Please sign in to comment.