diff --git a/CHANGELOG.md b/CHANGELOG.md index ed4c12a1..ccb6505c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Enhancements - Added `GetAccountProofs` endpoint (#506). +- Support Https in endpoint configuration (#556). ### Changes diff --git a/Cargo.lock b/Cargo.lock index 2dc59f74..d18f90e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -129,6 +129,12 @@ dependencies = [ "term", ] +[[package]] +name = "assert_matches" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" + [[package]] name = "async-stream" version = "0.3.6" @@ -390,7 +396,7 @@ dependencies = [ "semver 1.0.23", "serde", "serde_json", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -619,9 +625,9 @@ dependencies = [ [[package]] name = "deadpool-sqlite" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f9cc6210316f8b7ced394e2a5d2833ce7097fb28afb5881299c61bc18e8e0e9" +checksum = "656f14fc1ab819c65f332045ea7cb38841bbe551f3b2bc7e3abefb559af4155c" dependencies = [ "deadpool", "deadpool-sync", @@ -693,15 +699,6 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "directories" -version = "5.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a49173b84e034382284f27f1af4dcbbd231ffa358c0fe316541a7337f376a35" -dependencies = [ - "dirs-sys", -] - [[package]] name = "dirs-next" version = "2.0.0" @@ -712,18 +709,6 @@ dependencies = [ "dirs-sys-next", ] -[[package]] -name = "dirs-sys" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" -dependencies = [ - "libc", - "option-ext", - "redox_users", - "windows-sys 0.48.0", -] - [[package]] name = "dirs-sys-next" version = "0.1.2" @@ -1308,9 +1293,9 @@ dependencies = [ [[package]] name = "libsqlite3-sys" -version = "0.28.0" +version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c10584274047cb335c23d3e61bcef8e323adae7c5c8c760540f73610177fc3f" +checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" dependencies = [ "bindgen", "cc", @@ -1496,7 +1481,7 @@ dependencies = [ "rand_chacha", "serde", "static-files", - "thiserror", + "thiserror 2.0.3", "tokio", "toml", "tonic", @@ -1516,14 +1501,14 @@ dependencies = [ [[package]] name = "miden-lib" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "816404c10b0799f12d3b53b3a9baa9af99fa340fe1a579e0919bba57718fa97a" +version = "0.7.0" +source = "git+https://github.com/0xPolygonMiden/miden-base.git?branch=next#bc91c604862e2c6013b21eb989a3640d30cce25b" dependencies = [ "miden-assembly", "miden-objects", "miden-stdlib", "regex", + "walkdir", ] [[package]] @@ -1594,8 +1579,8 @@ dependencies = [ name = "miden-node-block-producer" version = "0.6.0" dependencies = [ + "assert_matches", "async-trait", - "figment", "itertools 0.13.0", "miden-air", "miden-lib", @@ -1610,13 +1595,11 @@ dependencies = [ "rand", "rand_chacha", "serde", - "thiserror", + "thiserror 2.0.3", "tokio", "tokio-stream", - "toml", "tonic", "tracing", - "tracing-subscriber", "winterfell", ] @@ -1632,7 +1615,7 @@ dependencies = [ "prost", "prost-build", "protox", - "thiserror", + "thiserror 2.0.3", "tonic", "tonic-build", ] @@ -1641,49 +1624,37 @@ dependencies = [ name = "miden-node-rpc" version = "0.6.0" dependencies = [ - "directories", - "figment", - "hex", - "miden-node-block-producer", "miden-node-proto", - "miden-node-store", "miden-node-utils", "miden-objects", "miden-tx", - "prost", "serde", "tokio", "tokio-stream", - "toml", "tonic", "tonic-web", "tracing", - "tracing-subscriber", ] [[package]] name = "miden-node-store" version = "0.6.0" dependencies = [ + "assert_matches", "deadpool-sqlite", - "directories", - "figment", "hex", "miden-lib", "miden-node-proto", "miden-node-utils", "miden-objects", - "prost", "rusqlite", "rusqlite_migration", "serde", - "thiserror", + "thiserror 2.0.3", "tokio", "tokio-stream", - "toml", "tonic", "tracing", - "tracing-subscriber", ] [[package]] @@ -1704,7 +1675,7 @@ dependencies = [ "miden-objects", "rand", "serde", - "thiserror", + "thiserror 2.0.3", "tonic", "tracing", "tracing-forest", @@ -1715,9 +1686,8 @@ dependencies = [ [[package]] name = "miden-objects" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a6f54dde939928e438488b36651485a0e80057025b7e30343d4340a524a1651" +version = "0.7.0" +source = "git+https://github.com/0xPolygonMiden/miden-base.git?branch=next#bc91c604862e2c6013b21eb989a3640d30cce25b" dependencies = [ "getrandom", "miden-assembly", @@ -1726,6 +1696,7 @@ dependencies = [ "miden-processor", "miden-verifier", "rand", + "thiserror 2.0.3", "winter-rand-utils", ] @@ -1789,12 +1760,10 @@ dependencies = [ [[package]] name = "miden-tx" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d433744a3f02233ec53b151bfe88b7a008b4eae5dfd41bb38a9889eb67efaf7" +version = "0.7.0" +source = "git+https://github.com/0xPolygonMiden/miden-base.git?branch=next#bc91c604862e2c6013b21eb989a3640d30cce25b" dependencies = [ "async-trait", - "miden-assembly", "miden-lib", "miden-objects", "miden-processor", @@ -1802,8 +1771,6 @@ dependencies = [ "miden-verifier", "rand", "rand_chacha", - "regex", - "walkdir", "winter-maybe-async", ] @@ -1835,7 +1802,7 @@ dependencies = [ "supports-unicode", "terminal_size", "textwrap", - "thiserror", + "thiserror 1.0.68", "unicode-width 0.1.14", ] @@ -2050,12 +2017,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "option-ext" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" - [[package]] name = "overload" version = "0.1.1" @@ -2353,7 +2314,7 @@ dependencies = [ "prost-reflect", "prost-types", "protox-parse", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -2365,7 +2326,7 @@ dependencies = [ "logos", "miette", "prost-types", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -2459,7 +2420,7 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ "getrandom", "libredox", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -2508,9 +2469,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "rusqlite" -version = "0.31.0" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b838eba278d213a8beaf485bd313fd580ca4505a00d5871caeb1457c55322cae" +checksum = "7753b721174eb8ff87a9a0e799e2d7bc3749323e773db92e0984debb00019d6e" dependencies = [ "bitflags", "fallible-iterator", @@ -2522,9 +2483,9 @@ dependencies = [ [[package]] name = "rusqlite_migration" -version = "1.2.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55709bc01054c69e2f1cefdc886642b5e6376a8db3c86f761be0c423eebf178b" +checksum = "923b42e802f7dc20a0a6b5e097ba7c83fe4289da07e49156fecf6af08aa9cd1c" dependencies = [ "log", "rusqlite", @@ -2922,7 +2883,16 @@ version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.68", +] + +[[package]] +name = "thiserror" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" +dependencies = [ + "thiserror-impl 2.0.3", ] [[package]] @@ -2936,6 +2906,17 @@ dependencies = [ "syn", ] +[[package]] +name = "thiserror-impl" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thread_local" version = "1.1.8" @@ -3258,7 +3239,7 @@ checksum = "ee40835db14ddd1e3ba414292272eddde9dad04d3d4b65509656414d1c42592f" dependencies = [ "chrono", "smallvec", - "thiserror", + "thiserror 1.0.68", "tracing", "tracing-subscriber", ] @@ -3900,9 +3881,9 @@ dependencies = [ [[package]] name = "winter-utils" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76b116c8ade0172506f8bda32dc674cf6b230adc8516e5138a0173ae69158a4f" +checksum = "1f948e71ffd482aa13d0ec3349047f81ecdb89f3b3287577973dcbf092a25fb4" dependencies = [ "rayon", ] @@ -3922,9 +3903,9 @@ dependencies = [ [[package]] name = "winterfell" -version = "0.10.1" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39c8336dc6a035698780b8cc624f875e479bd6bf6e1846670f3ef4485c125882" +checksum = "bbf1ab01d2781f7d3f1bd5c12800905c5bbf62e06778672498be798006ac463a" dependencies = [ "winter-air", "winter-prover", diff --git a/Cargo.toml b/Cargo.toml index ce5eb685..eb13182a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,23 +25,22 @@ exclude = [".github/"] readme = "README.md" [workspace.dependencies] +assert_matches = { version = "1.5" } miden-air = { version = "0.11" } -miden-lib = { version = "0.6" } +miden-lib = { git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "next" } miden-node-block-producer = { path = "crates/block-producer", version = "0.6" } -miden-node-faucet = { path = "bin/faucet", version = "0.6" } miden-node-proto = { path = "crates/proto", version = "0.6" } miden-node-rpc = { path = "crates/rpc", version = "0.6" } -miden-node-rpc-proto = { path = "crates/rpc-proto", version = "0.6" } miden-node-store = { path = "crates/store", version = "0.6" } miden-node-test-macro = { path = "crates/test-macro" } miden-node-utils = { path = "crates/utils", version = "0.6" } -miden-objects = { version = "0.6"} +miden-objects = { git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "next" } miden-processor = { version = "0.11" } miden-stdlib = { version = "0.11", default-features = false } -miden-tx = { version = "0.6"} +miden-tx = { git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "next" } prost = { version = "0.13" } rand = { version = "0.8" } -thiserror = { version = "1.0" } +thiserror = { version = "2.0", default-features = false } tokio = { version = "1.40", features = ["rt-multi-thread"] } tokio-stream = { version = "0.1" } tonic = { version = "0.12" } diff --git a/bin/node/src/config.rs b/bin/node/src/config.rs index 17349676..8e44ad06 100644 --- a/bin/node/src/config.rs +++ b/bin/node/src/config.rs @@ -74,7 +74,7 @@ impl NodeConfig { mod tests { use figment::Jail; use miden_node_store::config::StoreConfig; - use miden_node_utils::config::{load_config, Endpoint}; + use miden_node_utils::config::{load_config, Endpoint, Protocol}; use super::NodeConfig; use crate::{ @@ -93,10 +93,10 @@ mod tests { verify_tx_proofs = true [rpc] - endpoint = { host = "127.0.0.1", port = 8080 } + endpoint = { host = "127.0.0.1", port = 8080, protocol = "Http" } [store] - endpoint = { host = "127.0.0.1", port = 8080 } + endpoint = { host = "127.0.0.1", port = 8080, protocol = "Https" } database_filepath = "local.sqlite3" genesis_filepath = "genesis.dat" blockstore_dir = "blocks" @@ -112,6 +112,7 @@ mod tests { endpoint: Endpoint { host: "127.0.0.1".to_string(), port: 8080, + protocol: Protocol::default() }, verify_tx_proofs: true }, @@ -119,12 +120,14 @@ mod tests { endpoint: Endpoint { host: "127.0.0.1".to_string(), port: 8080, + protocol: Protocol::Http }, }, store: StoreConfig { endpoint: Endpoint { host: "127.0.0.1".to_string(), port: 8080, + protocol: Protocol::Https }, database_filepath: "local.sqlite3".into(), genesis_filepath: "genesis.dat".into(), diff --git a/crates/block-producer/Cargo.toml b/crates/block-producer/Cargo.toml index ad317358..4a93628b 100644 --- a/crates/block-producer/Cargo.toml +++ b/crates/block-producer/Cargo.toml @@ -16,7 +16,6 @@ tracing-forest = ["miden-node-utils/tracing-forest"] [dependencies] async-trait = { version = "0.1" } -figment = { version = "0.10", features = ["toml", "env"] } itertools = { version = "0.13" } miden-lib = { workspace = true } miden-node-proto = { workspace = true } @@ -30,13 +29,11 @@ serde = { version = "1.0", features = ["derive"] } thiserror = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread", "net", "macros", "sync", "time"] } tokio-stream = { workspace = true, features = ["net"] } -toml = { version = "0.8" } tonic = { workspace = true } tracing = { workspace = true } -tracing-subscriber = { workspace = true } [dev-dependencies] -figment = { version = "0.10", features = ["toml", "env", "test"] } +assert_matches = { workspace = true} miden-air = { workspace = true } miden-lib = { workspace = true, features = ["testing"] } miden-node-test-macro = { path = "../test-macro" } diff --git a/crates/block-producer/src/batch_builder/tests/mod.rs b/crates/block-producer/src/batch_builder/tests/mod.rs index 1e0012f1..46b63f70 100644 --- a/crates/block-producer/src/batch_builder/tests/mod.rs +++ b/crates/block-producer/src/batch_builder/tests/mod.rs @@ -1,5 +1,6 @@ use std::iter; +use assert_matches::assert_matches; use miden_objects::{crypto::merkle::Mmr, Digest}; use tokio::sync::RwLock; @@ -254,7 +255,7 @@ async fn test_block_builder_no_missing_notes() { .block_builder .build_block(&batch_builder.ready_batches.read().await) .await; - assert_eq!(build_block_result, Ok(())); + assert_matches!(build_block_result, Ok(())); } #[tokio::test] @@ -307,9 +308,11 @@ async fn test_block_builder_fails_if_notes_are_missing() { let mut expected_missing_notes = vec![notes[4].id(), notes[5].id()]; expected_missing_notes.sort(); - assert_eq!( + assert_matches!( build_block_result, - Err(BuildBlockError::UnauthenticatedNotesNotFound(expected_missing_notes)) + Err(BuildBlockError::UnauthenticatedNotesNotFound(actual_missing_notes)) => { + assert_eq!(actual_missing_notes, expected_missing_notes); + } ); } diff --git a/crates/block-producer/src/block_builder/prover/tests.rs b/crates/block-producer/src/block_builder/prover/tests.rs index a28f86f9..28d011cf 100644 --- a/crates/block-producer/src/block_builder/prover/tests.rs +++ b/crates/block-producer/src/block_builder/prover/tests.rs @@ -1,5 +1,6 @@ use std::{collections::BTreeMap, iter}; +use assert_matches::assert_matches; use miden_objects::{ accounts::{ account_id::testing::{ @@ -157,13 +158,17 @@ fn test_block_witness_validation_inconsistent_account_hashes() { let block_witness_result = BlockWitness::new(block_inputs_from_store, &batches); - assert_eq!( + assert_matches!( block_witness_result, Err(BuildBlockError::InconsistentAccountStateTransition( - account_id_1, - account_1_hash_store, - vec![account_1_hash_batches] - )) + account_id, + account_hash_store, + account_hash_batches + )) => { + assert_eq!(account_id, account_id_1); + assert_eq!(account_hash_store, account_1_hash_store); + assert_eq!(account_hash_batches, vec![account_1_hash_batches]); + } ); } @@ -668,9 +673,11 @@ fn test_block_witness_validation_inconsistent_nullifiers() { let block_witness_result = BlockWitness::new(block_inputs_from_store, &batches); - assert_eq!( + assert_matches!( block_witness_result, - Err(BuildBlockError::InconsistentNullifiers(vec![nullifier_1, nullifier_3])) + Err(BuildBlockError::InconsistentNullifiers(nullifiers)) => { + assert_eq!(nullifiers, vec![nullifier_1, nullifier_3]); + } ); } diff --git a/crates/block-producer/src/block_builder/tests.rs b/crates/block-producer/src/block_builder/tests.rs index c7c82629..d8fbc356 100644 --- a/crates/block-producer/src/block_builder/tests.rs +++ b/crates/block-producer/src/block_builder/tests.rs @@ -3,6 +3,7 @@ use std::sync::Arc; +use assert_matches::assert_matches; use miden_objects::{ accounts::{account_id::testing::ACCOUNT_ID_OFF_CHAIN_SENDER, AccountId}, Digest, Felt, @@ -78,5 +79,5 @@ async fn test_build_block_failure() { let result = block_builder.build_block(&Vec::new()).await; // Ensure that the store's `apply_block()` was called - assert!(matches!(result, Err(BuildBlockError::GetBlockInputsFailed(_)))); + assert_matches!(result, Err(BuildBlockError::GetBlockInputsFailed(_))); } diff --git a/crates/block-producer/src/errors.rs b/crates/block-producer/src/errors.rs index 9ff3a76b..937bbefe 100644 --- a/crates/block-producer/src/errors.rs +++ b/crates/block-producer/src/errors.rs @@ -30,7 +30,7 @@ pub enum BlockProducerError { // Transaction verification errors // ================================================================================================= -#[derive(Debug, PartialEq, Eq, Error)] +#[derive(Debug, Error)] pub enum VerifyTxError { /// Another transaction already consumed the notes with given nullifiers #[error("Input notes with given nullifiers were already consumed by another transaction")] @@ -71,7 +71,7 @@ pub enum VerifyTxError { // Transaction adding errors // ================================================================================================= -#[derive(Debug, PartialEq, Eq, Error)] +#[derive(Debug, Error)] pub enum AddTransactionError { #[error("Transaction verification failed: {0}")] VerificationFailed(#[from] VerifyTxError), @@ -109,7 +109,7 @@ impl From for tonic::Status { // ================================================================================================= /// Error encountered while building a batch. -#[derive(Debug, PartialEq, Eq, Error)] +#[derive(Debug, Error)] pub enum BuildBatchError { #[error("Duplicated unauthenticated transaction input note ID in the batch: {0}")] DuplicateUnauthenticatedNote(NoteId), @@ -137,7 +137,7 @@ pub enum BuildBatchError { // Block prover errors // ================================================================================================= -#[derive(Debug, PartialEq, Eq, Error)] +#[derive(Debug, Error)] pub enum BlockProverError { #[error("Received invalid merkle path")] InvalidMerklePaths(MerkleError), @@ -151,7 +151,7 @@ pub enum BlockProverError { // ================================================================================================= #[allow(clippy::enum_variant_names)] -#[derive(Debug, PartialEq, Eq, Error)] +#[derive(Debug, Error)] pub enum BlockInputsError { #[error("failed to parse protobuf message: {0}")] ConversionError(#[from] ConversionError), @@ -164,7 +164,7 @@ pub enum BlockInputsError { // Block applying errors // ================================================================================================= -#[derive(Debug, PartialEq, Eq, Error)] +#[derive(Debug, Error)] pub enum ApplyBlockError { #[error("gRPC client failed with error: {0}")] GrpcClientError(String), @@ -173,7 +173,7 @@ pub enum ApplyBlockError { // Block building errors // ================================================================================================= -#[derive(Debug, PartialEq, Eq, Error)] +#[derive(Debug, Error)] pub enum BuildBlockError { #[error("failed to compute new block: {0}")] BlockProverFailed(#[from] BlockProverError), @@ -203,7 +203,7 @@ pub enum BuildBlockError { // Transaction inputs errors // ================================================================================================= -#[derive(Debug, PartialEq, Eq, Error)] +#[derive(Debug, Error)] pub enum TxInputsError { #[error("gRPC client failed with error: {0}")] GrpcClientError(String), diff --git a/crates/block-producer/src/mempool/inflight_state/mod.rs b/crates/block-producer/src/mempool/inflight_state/mod.rs index e26c1b73..2f483662 100644 --- a/crates/block-producer/src/mempool/inflight_state/mod.rs +++ b/crates/block-producer/src/mempool/inflight_state/mod.rs @@ -352,6 +352,7 @@ impl OutputNoteState { #[cfg(test)] mod tests { + use assert_matches::assert_matches; use miden_objects::Digest; use super::*; @@ -384,9 +385,11 @@ mod tests { let err = uut.add_transaction(&AuthenticatedTransaction::from_inner(tx2)).unwrap_err(); - assert_eq!( + assert_matches!( err, - VerifyTxError::InputNotesAlreadyConsumed(vec![mock_note(note_seed).nullifier()]).into() + AddTransactionError::VerificationFailed(VerifyTxError::InputNotesAlreadyConsumed( + notes + )) if notes == vec![mock_note(note_seed).nullifier()] ); } @@ -408,7 +411,12 @@ mod tests { let err = uut.add_transaction(&AuthenticatedTransaction::from_inner(tx1)).unwrap_err(); - assert_eq!(err, VerifyTxError::OutputNotesAlreadyExist(vec![note.id()]).into()); + assert_matches!( + err, + AddTransactionError::VerificationFailed(VerifyTxError::OutputNotesAlreadyExist( + notes + )) if notes == vec![note.id()] + ); } #[test] @@ -423,13 +431,12 @@ mod tests { .add_transaction(&AuthenticatedTransaction::from_inner(tx).with_store_state(states[2])) .unwrap_err(); - assert_eq!( + assert_matches!( err, - VerifyTxError::IncorrectAccountInitialHash { - tx_initial_account_hash: states[0], - current_account_hash: states[2].into() - } - .into() + AddTransactionError::VerificationFailed(VerifyTxError::IncorrectAccountInitialHash { + tx_initial_account_hash: init_state, + current_account_hash: current_state, + }) if init_state == states[0] && current_state == states[2].into() ); } diff --git a/crates/proto/src/errors.rs b/crates/proto/src/errors.rs index 7f06c701..bf596701 100644 --- a/crates/proto/src/errors.rs +++ b/crates/proto/src/errors.rs @@ -3,7 +3,7 @@ use std::{any::type_name, num::TryFromIntError}; use miden_objects::crypto::merkle::{SmtLeafError, SmtProofError}; use thiserror::Error; -#[derive(Debug, Clone, PartialEq, Error)] +#[derive(Debug, Error)] pub enum ConversionError { #[error("Hex error: {0}")] HexError(#[from] hex::FromHexError), @@ -28,8 +28,6 @@ pub enum ConversionError { }, } -impl Eq for ConversionError {} - pub trait MissingFieldHelper { fn missing_field(field_name: &'static str) -> ConversionError; } diff --git a/crates/rpc/Cargo.toml b/crates/rpc/Cargo.toml index 9ebf2cbc..c8e8ab16 100644 --- a/crates/rpc/Cargo.toml +++ b/crates/rpc/Cargo.toml @@ -12,25 +12,16 @@ homepage.workspace = true repository.workspace = true [dependencies] -directories = { version = "5.0" } -figment = { version = "0.10", features = ["toml", "env"] } -hex = { version = "0.4" } -miden-node-block-producer = { workspace = true } miden-node-proto = { workspace = true } -miden-node-store = { workspace = true } miden-node-utils = { workspace = true } miden-objects = { workspace = true } miden-tx = { workspace = true } -prost = { workspace = true } serde = { version = "1.0", features = ["derive"] } tokio = { workspace = true, features = ["rt-multi-thread", "net", "macros"] } tokio-stream = { workspace = true, features = ["net"] } -toml = { version = "0.8" } tonic = { workspace = true } tonic-web = { version = "0.12" } tracing = { workspace = true } -tracing-subscriber = { workspace = true } [dev-dependencies] -figment = { version = "0.10", features = ["toml", "env", "test"] } miden-node-utils = { workspace = true, features = ["tracing-forest"] } diff --git a/crates/rpc/src/config.rs b/crates/rpc/src/config.rs index 7cd6e644..07dac077 100644 --- a/crates/rpc/src/config.rs +++ b/crates/rpc/src/config.rs @@ -1,7 +1,7 @@ use std::fmt::{Display, Formatter}; use miden_node_utils::config::{ - Endpoint, DEFAULT_BLOCK_PRODUCER_PORT, DEFAULT_NODE_RPC_PORT, DEFAULT_STORE_PORT, + Endpoint, Protocol, DEFAULT_BLOCK_PRODUCER_PORT, DEFAULT_NODE_RPC_PORT, DEFAULT_STORE_PORT, }; use serde::{Deserialize, Serialize}; @@ -39,6 +39,7 @@ impl Default for RpcConfig { endpoint: Endpoint { host: "0.0.0.0".to_string(), port: DEFAULT_NODE_RPC_PORT, + protocol: Protocol::default(), }, store_url: Endpoint::localhost(DEFAULT_STORE_PORT).to_string(), block_producer_url: Endpoint::localhost(DEFAULT_BLOCK_PRODUCER_PORT).to_string(), diff --git a/crates/store/Cargo.toml b/crates/store/Cargo.toml index bb9a6310..6ca51bb4 100644 --- a/crates/store/Cargo.toml +++ b/crates/store/Cargo.toml @@ -12,27 +12,22 @@ homepage.workspace = true repository.workspace = true [dependencies] -deadpool-sqlite = { version = "0.8", features = ["rt_tokio_1"] } -directories = { version = "5.0" } -figment = { version = "0.10", features = ["toml", "env"] } +deadpool-sqlite = { version = "0.9.0", features = ["rt_tokio_1"] } hex = { version = "0.4" } miden-lib = { workspace = true } miden-node-proto = { workspace = true } miden-node-utils = { workspace = true } miden-objects = { workspace = true } -prost = { workspace = true } -rusqlite = { version = "0.31", features = ["array", "buildtime_bindgen", "bundled"] } -rusqlite_migration = { version = "1.0" } +rusqlite = { version = "0.32.1", features = ["array", "buildtime_bindgen", "bundled"] } +rusqlite_migration = { version = "1.3" } serde = { version = "1.0", features = ["derive"] } thiserror = { workspace = true } tokio = { workspace = true, features = ["fs", "net", "macros", "rt-multi-thread"] } tokio-stream = { workspace = true, features = ["net"] } -toml = { version = "0.8" } tonic = { workspace = true } tracing = { workspace = true } -tracing-subscriber = { workspace = true } [dev-dependencies] -figment = { version = "0.10", features = ["toml", "env", "test"] } +assert_matches = { workspace = true} miden-node-utils = { workspace = true, features = ["tracing-forest"] } miden-objects = { workspace = true, features = ["testing"] } diff --git a/crates/store/src/db/tests.rs b/crates/store/src/db/tests.rs index a63f982f..9a4e3141 100644 --- a/crates/store/src/db/tests.rs +++ b/crates/store/src/db/tests.rs @@ -1,21 +1,21 @@ +use assert_matches::assert_matches; use miden_lib::transaction::TransactionKernel; use miden_node_proto::domain::accounts::AccountSummary; use miden_objects::{ accounts::{ account_id::testing::{ ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN, ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN, - ACCOUNT_ID_OFF_CHAIN_SENDER, ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN, - ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, + ACCOUNT_ID_OFF_CHAIN_SENDER, ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_OFF_CHAIN, }, delta::AccountUpdateDetails, - Account, AccountCode, AccountComponent, AccountDelta, AccountId, AccountStorage, - AccountStorageDelta, AccountType, AccountVaultDelta, StorageSlot, + Account, AccountBuilder, AccountComponent, AccountDelta, AccountId, AccountStorageDelta, + AccountStorageMode, AccountType, AccountVaultDelta, StorageSlot, }, - assets::{Asset, AssetVault, FungibleAsset, NonFungibleAsset, NonFungibleAssetDetails}, + assets::{Asset, FungibleAsset, NonFungibleAsset, NonFungibleAssetDetails}, block::{BlockAccountUpdate, BlockNoteIndex, BlockNoteTree}, crypto::{hash::rpo::RpoDigest, merkle::MerklePath}, notes::{NoteExecutionHint, NoteId, NoteMetadata, NoteType, Nullifier}, - BlockHeader, Felt, FieldElement, Word, ONE, ZERO, + BlockHeader, Felt, FieldElement, Word, ZERO, }; use rusqlite::{vtab::array, Connection}; @@ -328,8 +328,6 @@ fn test_sql_public_account_details() { let block_num = 1; create_block(&mut conn, block_num); - let account_id = - AccountId::try_from(ACCOUNT_ID_REGULAR_ACCOUNT_IMMUTABLE_CODE_ON_CHAIN).unwrap(); let fungible_faucet_id = AccountId::try_from(ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN).unwrap(); let non_fungible_faucet_id = AccountId::try_from(ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN).unwrap(); @@ -341,18 +339,10 @@ fn test_sql_public_account_details() { .unwrap(), ); - let (code, storage) = mock_account_code_and_storage(account_id.account_type()); - - let mut account = Account::from_parts( - account_id, - AssetVault::new(&[ - Asset::Fungible(FungibleAsset::new(fungible_faucet_id, 150).unwrap()), - nft1, - ]) - .unwrap(), - storage, - code, - ZERO, + let mut account = mock_account_code_and_storage( + AccountType::RegularAccountImmutableCode, + AccountStorageMode::Public, + [Asset::Fungible(FungibleAsset::new(fungible_faucet_id, 150).unwrap()), nft1], ); // test querying empty table @@ -363,7 +353,7 @@ fn test_sql_public_account_details() { let inserted = sql::upsert_accounts( &transaction, &[BlockAccountUpdate::new( - account_id, + account.id(), account.hash(), AccountUpdateDetails::New(account.clone()), vec![], @@ -395,7 +385,7 @@ fn test_sql_public_account_details() { let vault_delta = AccountVaultDelta::from_iters([nft2], [nft1]); - let delta = AccountDelta::new(storage_delta, vault_delta, Some(ONE)).unwrap(); + let delta = AccountDelta::new(storage_delta, vault_delta, Some(Felt::new(2))).unwrap(); account.apply_delta(&delta).unwrap(); @@ -403,7 +393,7 @@ fn test_sql_public_account_details() { let inserted = sql::upsert_accounts( &transaction, &[BlockAccountUpdate::new( - account_id, + account.id(), account.hash(), AccountUpdateDetails::Delta(delta.clone()), vec![], @@ -427,12 +417,14 @@ fn test_sql_public_account_details() { assert_eq!(account_read.nonce(), account.nonce()); // Cleared item was not serialized, check it and apply delta only with clear item second time: - assert_eq!(account_read.storage().get_item(3), Ok(RpoDigest::default())); + assert_matches!(account_read.storage().get_item(3), Ok(digest) => { + assert_eq!(digest, RpoDigest::default()); + }); let storage_delta = AccountStorageDelta::from_iters([3], [], []); account_read .apply_delta( - &AccountDelta::new(storage_delta, AccountVaultDelta::default(), Some(Felt::new(2))) + &AccountDelta::new(storage_delta, AccountVaultDelta::default(), Some(Felt::new(3))) .unwrap(), ) .unwrap(); @@ -456,7 +448,7 @@ fn test_sql_public_account_details() { let inserted = sql::upsert_accounts( &transaction, &[BlockAccountUpdate::new( - account_id, + account.id(), account.hash(), AccountUpdateDetails::Delta(delta2.clone()), vec![], @@ -480,7 +472,7 @@ fn test_sql_public_account_details() { assert_eq!(account_read.nonce(), account.nonce()); let read_deltas = - sql::select_account_deltas(&mut conn, account_id.into(), 0, block_num + 1).unwrap(); + sql::select_account_deltas(&mut conn, account.id().into(), 0, block_num + 1).unwrap(); assert_eq!(read_deltas, vec![delta, delta2]); } @@ -977,7 +969,11 @@ fn insert_transactions(conn: &mut Connection) -> usize { count } -fn mock_account_code_and_storage(account_type: AccountType) -> (AccountCode, AccountStorage) { +fn mock_account_code_and_storage( + account_type: AccountType, + storage_mode: AccountStorageMode, + assets: impl IntoIterator, +) -> Account { let component_code = "\ export.account_procedure_1 push.1.2 @@ -1002,5 +998,12 @@ fn mock_account_code_and_storage(account_type: AccountType) -> (AccountCode, Acc .unwrap() .with_supported_type(account_type); - Account::initialize_from_components(account_type, &[component]).unwrap() + AccountBuilder::new() + .init_seed([0; 32]) + .account_type(account_type) + .storage_mode(storage_mode) + .with_assets(assets) + .with_component(component) + .build_existing() + .unwrap() } diff --git a/crates/utils/src/config.rs b/crates/utils/src/config.rs index c350fd36..5c70315d 100644 --- a/crates/utils/src/config.rs +++ b/crates/utils/src/config.rs @@ -17,6 +17,12 @@ pub const DEFAULT_BLOCK_PRODUCER_PORT: u16 = 48046; pub const DEFAULT_STORE_PORT: u16 = 28943; pub const DEFAULT_FAUCET_SERVER_PORT: u16 = 8080; +#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize, Default)] +pub enum Protocol { + #[default] + Http, + Https, +} /// The `(host, port)` pair for the server's listening socket. #[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)] pub struct Endpoint { @@ -24,11 +30,18 @@ pub struct Endpoint { pub host: String, /// Port number used by the store. pub port: u16, + /// Protocol type: http or https. + #[serde(default)] + pub protocol: Protocol, } impl Endpoint { pub fn localhost(port: u16) -> Self { - Endpoint { host: "localhost".to_string(), port } + Endpoint { + host: "localhost".to_string(), + port, + protocol: Protocol::default(), + } } } @@ -41,7 +54,17 @@ impl ToSocketAddrs for Endpoint { impl Display for Endpoint { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("http://{}:{}", self.host, self.port)) + let Endpoint { protocol, host, port } = self; + f.write_fmt(format_args!("{protocol}://{host}:{port}")) + } +} + +impl Display for Protocol { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + Protocol::Http => f.write_str("http"), + Protocol::Https => f.write_str("https"), + } } }