From f74c2439c6fca39f65408cb40fa60e69f0fc0e91 Mon Sep 17 00:00:00 2001 From: Ignacio Amigo Date: Tue, 25 Jun 2024 12:36:38 -0300 Subject: [PATCH 01/13] feat: Distribute protobuf files through a new crate --- Cargo.lock | 17 ++++++++++ Cargo.toml | 1 + crates/miden-rpc-proto/Cargo.toml | 30 ++++++++++++++++ crates/miden-rpc-proto/README.md | 9 +++++ crates/miden-rpc-proto/build.rs | 34 +++++++++++++++++++ crates/miden-rpc-proto/src/lib.rs | 22 ++++++++++++ crates/miden-rpc-proto/src/proto_files.rs | 15 ++++++++ crates/proto/Cargo.toml | 2 +- crates/proto/build.rs | 6 ++++ {crates/proto/proto => proto}/account.proto | 0 .../proto/proto => proto}/block_header.proto | 0 .../proto => proto}/block_producer.proto | 0 {crates/proto/proto => proto}/digest.proto | 0 {crates/proto/proto => proto}/merkle.proto | 0 {crates/proto/proto => proto}/mmr.proto | 0 {crates/proto/proto => proto}/note.proto | 0 {crates/proto/proto => proto}/requests.proto | 0 {crates/proto/proto => proto}/responses.proto | 0 {crates/proto/proto => proto}/rpc.proto | 0 {crates/proto/proto => proto}/smt.proto | 0 {crates/proto/proto => proto}/store.proto | 0 .../proto/proto => proto}/transaction.proto | 0 22 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 crates/miden-rpc-proto/Cargo.toml create mode 100644 crates/miden-rpc-proto/README.md create mode 100644 crates/miden-rpc-proto/build.rs create mode 100644 crates/miden-rpc-proto/src/lib.rs create mode 100644 crates/miden-rpc-proto/src/proto_files.rs rename {crates/proto/proto => proto}/account.proto (100%) rename {crates/proto/proto => proto}/block_header.proto (100%) rename {crates/proto/proto => proto}/block_producer.proto (100%) rename {crates/proto/proto => proto}/digest.proto (100%) rename {crates/proto/proto => proto}/merkle.proto (100%) rename {crates/proto/proto => proto}/mmr.proto (100%) rename {crates/proto/proto => proto}/note.proto (100%) rename {crates/proto/proto => proto}/requests.proto (100%) rename {crates/proto/proto => proto}/responses.proto (100%) rename {crates/proto/proto => proto}/rpc.proto (100%) rename {crates/proto/proto => proto}/smt.proto (100%) rename {crates/proto/proto => proto}/store.proto (100%) rename {crates/proto/proto => proto}/transaction.proto (100%) diff --git a/Cargo.lock b/Cargo.lock index ee7665985..6a7cfc350 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1879,6 +1879,23 @@ dependencies = [ "winter-prover", ] +[[package]] +name = "miden-rpc-proto" +version = "0.3.0" +dependencies = [ + "hex", + "miden-node-utils", + "miden-objects", + "miette", + "proptest", + "prost", + "prost-build", + "protox", + "thiserror", + "tonic", + "tonic-build", +] + [[package]] name = "miden-stdlib" version = "0.9.2" diff --git a/Cargo.toml b/Cargo.toml index 4d8f2be7d..04f114854 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ members = [ "bin/node", "bin/faucet", "crates/block-producer", + "crates/miden-rpc-proto", "crates/proto", "crates/rpc", "crates/store", diff --git a/crates/miden-rpc-proto/Cargo.toml b/crates/miden-rpc-proto/Cargo.toml new file mode 100644 index 000000000..a8013c2e7 --- /dev/null +++ b/crates/miden-rpc-proto/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "miden-rpc-proto" +version = "0.3.0" +description = "Miden RPC message definitions" +readme = "README.md" +keywords = ["miden", "node", "protobuf", "rpc"] +edition.workspace = true +rust-version.workspace = true +license.workspace = true +authors.workspace = true +homepage.workspace = true +repository.workspace = true + +[dependencies] +hex = { version = "0.4" } +miden-node-utils = { workspace = true } +miden-objects = { workspace = true } +prost = { version = "0.12" } +thiserror = { workspace = true } +tonic = { workspace = true } + +[dev-dependencies] +proptest = { version = "1.2" } + +[build-dependencies] +miette = { version = "7.0", features = ["fancy"] } +prost = { version = "0.12" } +prost-build = { version = "0.12" } +protox = { version = "0.6" } +tonic-build = { version = "0.11" } diff --git a/crates/miden-rpc-proto/README.md b/crates/miden-rpc-proto/README.md new file mode 100644 index 000000000..53f77bb4c --- /dev/null +++ b/crates/miden-rpc-proto/README.md @@ -0,0 +1,9 @@ +# Miden node utils + +This crate contains the RPC protobuf message definitions. +It consists of a map of `(filename, file contents)` where each entry refers to a protobuf file. + +Additionally, the crate exposes a `write_proto(target_dir)` function that writes the files into `target_dir`. + +## License +This project is [MIT licensed](../../LICENSE). diff --git a/crates/miden-rpc-proto/build.rs b/crates/miden-rpc-proto/build.rs new file mode 100644 index 000000000..938a0d08f --- /dev/null +++ b/crates/miden-rpc-proto/build.rs @@ -0,0 +1,34 @@ +use std::env; +use std::fs::File; +use std::io::{self, Read, Write}; +use std::path::Path; + +fn main() -> io::Result<()> { + let out_dir = env::current_dir().expect("Error getting cwd"); + let dest_path = Path::new(&out_dir).join("./src/proto_files.rs"); + let mut file = File::create(&dest_path)?; + + let proto_dir = Path::new("../../proto"); + + writeln!(file, "pub const PROTO_FILES: &[(&str, &str)] = &[")?; + + for entry in std::fs::read_dir(proto_dir)? { + let entry = entry?; + let path = entry.path(); + if path.is_file() { + let mut file_content = String::new(); + let file_name = path.file_name().and_then(|f| f.to_str()).expect("Could not get file name"); + + File::open(&path)?.read_to_string(&mut file_content)?; + writeln!( + file, + " (\"{}\", include_str!(\"../../../proto/{}\")),", + file_name, file_name + )?; + } + } + + writeln!(file, "];")?; + + Ok(()) +} diff --git a/crates/miden-rpc-proto/src/lib.rs b/crates/miden-rpc-proto/src/lib.rs new file mode 100644 index 000000000..6d1a195c9 --- /dev/null +++ b/crates/miden-rpc-proto/src/lib.rs @@ -0,0 +1,22 @@ +use std::{fs::{self, File}, io::Write, path::Path}; + +mod proto_files; +pub use proto_files::PROTO_FILES; + +/// Writes the RPC protobuf file into `target_dir`. +pub fn write_proto(target_dir: &Path) -> Result<(), String> { + if !target_dir.exists() { + fs::create_dir_all(target_dir).unwrap(); + } else if !target_dir.is_dir() { + return Err("The target path exists but is not a directory".to_string()); + } + + for (file_name, file_content) in PROTO_FILES { + let mut file_path = target_dir.to_path_buf(); + file_path.push(file_name); + let mut file = File::create(&file_path).unwrap(); + file.write_all(file_content.as_bytes()).unwrap(); + } + + Ok(()) +} diff --git a/crates/miden-rpc-proto/src/proto_files.rs b/crates/miden-rpc-proto/src/proto_files.rs new file mode 100644 index 000000000..9d56ac633 --- /dev/null +++ b/crates/miden-rpc-proto/src/proto_files.rs @@ -0,0 +1,15 @@ +pub const PROTO_FILES: &[(&str, &str)] = &[ + ("note.proto", include_str!("../../../proto/note.proto")), + ("smt.proto", include_str!("../../../proto/smt.proto")), + ("responses.proto", include_str!("../../../proto/responses.proto")), + ("rpc.proto", include_str!("../../../proto/rpc.proto")), + ("store.proto", include_str!("../../../proto/store.proto")), + ("transaction.proto", include_str!("../../../proto/transaction.proto")), + ("mmr.proto", include_str!("../../../proto/mmr.proto")), + ("account.proto", include_str!("../../../proto/account.proto")), + ("block_header.proto", include_str!("../../../proto/block_header.proto")), + ("digest.proto", include_str!("../../../proto/digest.proto")), + ("block_producer.proto", include_str!("../../../proto/block_producer.proto")), + ("merkle.proto", include_str!("../../../proto/merkle.proto")), + ("requests.proto", include_str!("../../../proto/requests.proto")), +]; diff --git a/crates/proto/Cargo.toml b/crates/proto/Cargo.toml index d07de7364..06adeaa77 100644 --- a/crates/proto/Cargo.toml +++ b/crates/proto/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "miden-node-proto" version = "0.3.0" -description = "Miden RPC message definitions" +description = "Miden node message definitions (Store, Block Producer and RPC)" readme = "README.md" keywords = ["miden", "node", "protobuf", "rpc"] edition.workspace = true diff --git a/crates/proto/build.rs b/crates/proto/build.rs index 016c35e74..cdb054007 100644 --- a/crates/proto/build.rs +++ b/crates/proto/build.rs @@ -6,6 +6,12 @@ use prost::Message; fn main() -> miette::Result<()> { // Compute the directory of the `proto` definitions let cwd: PathBuf = env::current_dir().into_diagnostic()?; + + let cwd = cwd + .parent() + .and_then(|p| p.parent()) + .ok_or_else(|| miette::miette!("Failed to navigate two directories up"))?; + let proto_dir: PathBuf = cwd.join("proto"); // Compute the compiler's target file path. diff --git a/crates/proto/proto/account.proto b/proto/account.proto similarity index 100% rename from crates/proto/proto/account.proto rename to proto/account.proto diff --git a/crates/proto/proto/block_header.proto b/proto/block_header.proto similarity index 100% rename from crates/proto/proto/block_header.proto rename to proto/block_header.proto diff --git a/crates/proto/proto/block_producer.proto b/proto/block_producer.proto similarity index 100% rename from crates/proto/proto/block_producer.proto rename to proto/block_producer.proto diff --git a/crates/proto/proto/digest.proto b/proto/digest.proto similarity index 100% rename from crates/proto/proto/digest.proto rename to proto/digest.proto diff --git a/crates/proto/proto/merkle.proto b/proto/merkle.proto similarity index 100% rename from crates/proto/proto/merkle.proto rename to proto/merkle.proto diff --git a/crates/proto/proto/mmr.proto b/proto/mmr.proto similarity index 100% rename from crates/proto/proto/mmr.proto rename to proto/mmr.proto diff --git a/crates/proto/proto/note.proto b/proto/note.proto similarity index 100% rename from crates/proto/proto/note.proto rename to proto/note.proto diff --git a/crates/proto/proto/requests.proto b/proto/requests.proto similarity index 100% rename from crates/proto/proto/requests.proto rename to proto/requests.proto diff --git a/crates/proto/proto/responses.proto b/proto/responses.proto similarity index 100% rename from crates/proto/proto/responses.proto rename to proto/responses.proto diff --git a/crates/proto/proto/rpc.proto b/proto/rpc.proto similarity index 100% rename from crates/proto/proto/rpc.proto rename to proto/rpc.proto diff --git a/crates/proto/proto/smt.proto b/proto/smt.proto similarity index 100% rename from crates/proto/proto/smt.proto rename to proto/smt.proto diff --git a/crates/proto/proto/store.proto b/proto/store.proto similarity index 100% rename from crates/proto/proto/store.proto rename to proto/store.proto diff --git a/crates/proto/proto/transaction.proto b/proto/transaction.proto similarity index 100% rename from crates/proto/proto/transaction.proto rename to proto/transaction.proto From fd7be8f59dc07b45ea1938f3abf6c4af0601bdee Mon Sep 17 00:00:00 2001 From: Ignacio Amigo Date: Tue, 25 Jun 2024 13:57:37 -0300 Subject: [PATCH 02/13] Address reviews --- Cargo.toml | 2 +- crates/{miden-rpc-proto => rpc-proto}/Cargo.toml | 0 crates/{miden-rpc-proto => rpc-proto}/README.md | 4 ++-- crates/{miden-rpc-proto => rpc-proto}/build.rs | 0 crates/{miden-rpc-proto => rpc-proto}/src/lib.rs | 6 +++--- crates/{miden-rpc-proto => rpc-proto}/src/proto_files.rs | 0 6 files changed, 6 insertions(+), 6 deletions(-) rename crates/{miden-rpc-proto => rpc-proto}/Cargo.toml (100%) rename crates/{miden-rpc-proto => rpc-proto}/README.md (71%) rename crates/{miden-rpc-proto => rpc-proto}/build.rs (100%) rename crates/{miden-rpc-proto => rpc-proto}/src/lib.rs (61%) rename crates/{miden-rpc-proto => rpc-proto}/src/proto_files.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 04f114854..7d66f6a2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,8 +3,8 @@ members = [ "bin/node", "bin/faucet", "crates/block-producer", - "crates/miden-rpc-proto", "crates/proto", + "crates/rpc-proto", "crates/rpc", "crates/store", "crates/utils", diff --git a/crates/miden-rpc-proto/Cargo.toml b/crates/rpc-proto/Cargo.toml similarity index 100% rename from crates/miden-rpc-proto/Cargo.toml rename to crates/rpc-proto/Cargo.toml diff --git a/crates/miden-rpc-proto/README.md b/crates/rpc-proto/README.md similarity index 71% rename from crates/miden-rpc-proto/README.md rename to crates/rpc-proto/README.md index 53f77bb4c..eec9897ed 100644 --- a/crates/miden-rpc-proto/README.md +++ b/crates/rpc-proto/README.md @@ -1,6 +1,6 @@ -# Miden node utils +# Miden RPC proto -This crate contains the RPC protobuf message definitions. +This crate contains protobuf message definitions of the RPC component of the Miden node. It consists of a map of `(filename, file contents)` where each entry refers to a protobuf file. Additionally, the crate exposes a `write_proto(target_dir)` function that writes the files into `target_dir`. diff --git a/crates/miden-rpc-proto/build.rs b/crates/rpc-proto/build.rs similarity index 100% rename from crates/miden-rpc-proto/build.rs rename to crates/rpc-proto/build.rs diff --git a/crates/miden-rpc-proto/src/lib.rs b/crates/rpc-proto/src/lib.rs similarity index 61% rename from crates/miden-rpc-proto/src/lib.rs rename to crates/rpc-proto/src/lib.rs index 6d1a195c9..b726dde77 100644 --- a/crates/miden-rpc-proto/src/lib.rs +++ b/crates/rpc-proto/src/lib.rs @@ -6,7 +6,7 @@ pub use proto_files::PROTO_FILES; /// Writes the RPC protobuf file into `target_dir`. pub fn write_proto(target_dir: &Path) -> Result<(), String> { if !target_dir.exists() { - fs::create_dir_all(target_dir).unwrap(); + fs::create_dir_all(target_dir).map_err(|e| format!("Error creating directory: {}" e.to_string()))?; } else if !target_dir.is_dir() { return Err("The target path exists but is not a directory".to_string()); } @@ -14,8 +14,8 @@ pub fn write_proto(target_dir: &Path) -> Result<(), String> { for (file_name, file_content) in PROTO_FILES { let mut file_path = target_dir.to_path_buf(); file_path.push(file_name); - let mut file = File::create(&file_path).unwrap(); - file.write_all(file_content.as_bytes()).unwrap(); + let mut file = File::create(&file_path).map_err(|e| format!("Error creating file: {}" e.to_string()))?; + file.write_all(file_content.as_bytes()).map_err(|e| format!("Error writing file: {}" e.to_string()))?; } Ok(()) diff --git a/crates/miden-rpc-proto/src/proto_files.rs b/crates/rpc-proto/src/proto_files.rs similarity index 100% rename from crates/miden-rpc-proto/src/proto_files.rs rename to crates/rpc-proto/src/proto_files.rs From ca904143e691952c8e96d5a7bac8ea14a2fe41ff Mon Sep 17 00:00:00 2001 From: Ignacio Amigo Date: Tue, 25 Jun 2024 13:58:28 -0300 Subject: [PATCH 03/13] Cargo fmt --- crates/proto/build.rs | 2 +- crates/rpc-proto/build.rs | 13 ++++++++----- crates/rpc-proto/src/lib.rs | 15 +++++++++++---- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/crates/proto/build.rs b/crates/proto/build.rs index cdb054007..51be01989 100644 --- a/crates/proto/build.rs +++ b/crates/proto/build.rs @@ -9,7 +9,7 @@ fn main() -> miette::Result<()> { let cwd = cwd .parent() - .and_then(|p| p.parent()) + .and_then(|p| p.parent()) .ok_or_else(|| miette::miette!("Failed to navigate two directories up"))?; let proto_dir: PathBuf = cwd.join("proto"); diff --git a/crates/rpc-proto/build.rs b/crates/rpc-proto/build.rs index 938a0d08f..2c8abc90a 100644 --- a/crates/rpc-proto/build.rs +++ b/crates/rpc-proto/build.rs @@ -1,7 +1,9 @@ -use std::env; -use std::fs::File; -use std::io::{self, Read, Write}; -use std::path::Path; +use std::{ + env, + fs::File, + io::{self, Read, Write}, + path::Path, +}; fn main() -> io::Result<()> { let out_dir = env::current_dir().expect("Error getting cwd"); @@ -17,7 +19,8 @@ fn main() -> io::Result<()> { let path = entry.path(); if path.is_file() { let mut file_content = String::new(); - let file_name = path.file_name().and_then(|f| f.to_str()).expect("Could not get file name"); + let file_name = + path.file_name().and_then(|f| f.to_str()).expect("Could not get file name"); File::open(&path)?.read_to_string(&mut file_content)?; writeln!( diff --git a/crates/rpc-proto/src/lib.rs b/crates/rpc-proto/src/lib.rs index b726dde77..743fcf9b1 100644 --- a/crates/rpc-proto/src/lib.rs +++ b/crates/rpc-proto/src/lib.rs @@ -1,4 +1,8 @@ -use std::{fs::{self, File}, io::Write, path::Path}; +use std::{ + fs::{self, File}, + io::Write, + path::Path, +}; mod proto_files; pub use proto_files::PROTO_FILES; @@ -6,7 +10,8 @@ pub use proto_files::PROTO_FILES; /// Writes the RPC protobuf file into `target_dir`. pub fn write_proto(target_dir: &Path) -> Result<(), String> { if !target_dir.exists() { - fs::create_dir_all(target_dir).map_err(|e| format!("Error creating directory: {}" e.to_string()))?; + fs::create_dir_all(target_dir) + .map_err(|e| format!("Error creating directory: {}" e.to_string()))?; } else if !target_dir.is_dir() { return Err("The target path exists but is not a directory".to_string()); } @@ -14,8 +19,10 @@ pub fn write_proto(target_dir: &Path) -> Result<(), String> { for (file_name, file_content) in PROTO_FILES { let mut file_path = target_dir.to_path_buf(); file_path.push(file_name); - let mut file = File::create(&file_path).map_err(|e| format!("Error creating file: {}" e.to_string()))?; - file.write_all(file_content.as_bytes()).map_err(|e| format!("Error writing file: {}" e.to_string()))?; + let mut file = File::create(&file_path) + .map_err(|e| format!("Error creating file: {}" e.to_string()))?; + file.write_all(file_content.as_bytes()) + .map_err(|e| format!("Error writing file: {}" e.to_string()))?; } Ok(()) From 62d6abf182776bf20b6ea54c760b642d1c1c3ff5 Mon Sep 17 00:00:00 2001 From: Ignacio Amigo Date: Tue, 25 Jun 2024 14:00:37 -0300 Subject: [PATCH 04/13] Better errors --- crates/rpc-proto/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/rpc-proto/src/lib.rs b/crates/rpc-proto/src/lib.rs index 743fcf9b1..934a22a3e 100644 --- a/crates/rpc-proto/src/lib.rs +++ b/crates/rpc-proto/src/lib.rs @@ -11,7 +11,7 @@ pub use proto_files::PROTO_FILES; pub fn write_proto(target_dir: &Path) -> Result<(), String> { if !target_dir.exists() { fs::create_dir_all(target_dir) - .map_err(|e| format!("Error creating directory: {}" e.to_string()))?; + .map_err(|e| format!("Error creating directory: {}", e.to_string()))?; } else if !target_dir.is_dir() { return Err("The target path exists but is not a directory".to_string()); } @@ -20,9 +20,9 @@ pub fn write_proto(target_dir: &Path) -> Result<(), String> { let mut file_path = target_dir.to_path_buf(); file_path.push(file_name); let mut file = File::create(&file_path) - .map_err(|e| format!("Error creating file: {}" e.to_string()))?; + .map_err(|e| format!("Error creating {}: {}", file_name, e.to_string()))?; file.write_all(file_content.as_bytes()) - .map_err(|e| format!("Error writing file: {}" e.to_string()))?; + .map_err(|e| format!("Error writing {}: {}", file_name, e.to_string()))?; } Ok(()) From ba3af88379b44eb4fa3bbbdebf9c53a917905fa7 Mon Sep 17 00:00:00 2001 From: Ignacio Amigo Date: Tue, 25 Jun 2024 14:03:22 -0300 Subject: [PATCH 05/13] Clippy warnings --- crates/rpc-proto/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/rpc-proto/src/lib.rs b/crates/rpc-proto/src/lib.rs index 934a22a3e..582d4773c 100644 --- a/crates/rpc-proto/src/lib.rs +++ b/crates/rpc-proto/src/lib.rs @@ -11,7 +11,7 @@ pub use proto_files::PROTO_FILES; pub fn write_proto(target_dir: &Path) -> Result<(), String> { if !target_dir.exists() { fs::create_dir_all(target_dir) - .map_err(|e| format!("Error creating directory: {}", e.to_string()))?; + .map_err(|err| format!("Error creating directory: {}", err))?; } else if !target_dir.is_dir() { return Err("The target path exists but is not a directory".to_string()); } @@ -20,9 +20,9 @@ pub fn write_proto(target_dir: &Path) -> Result<(), String> { let mut file_path = target_dir.to_path_buf(); file_path.push(file_name); let mut file = File::create(&file_path) - .map_err(|e| format!("Error creating {}: {}", file_name, e.to_string()))?; + .map_err(|err| format!("Error creating {}: {}", file_name, err))?; file.write_all(file_content.as_bytes()) - .map_err(|e| format!("Error writing {}: {}", file_name, e.to_string()))?; + .map_err(|err| format!("Error writing {}: {}", file_name, err))?; } Ok(()) From 4d86028fd757d4d5c3b78879f1ddce85641ea1fc Mon Sep 17 00:00:00 2001 From: Ignacio Amigo Date: Tue, 25 Jun 2024 15:24:46 -0300 Subject: [PATCH 06/13] Make crate no_std compatible --- crates/rpc-proto/Cargo.toml | 4 ++++ crates/rpc-proto/build.rs | 4 ++++ crates/rpc-proto/src/lib.rs | 14 +++++++------- crates/rpc-proto/src/proto_files.rs | 1 + 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/crates/rpc-proto/Cargo.toml b/crates/rpc-proto/Cargo.toml index a8013c2e7..fd44a5ac0 100644 --- a/crates/rpc-proto/Cargo.toml +++ b/crates/rpc-proto/Cargo.toml @@ -11,6 +11,10 @@ authors.workspace = true homepage.workspace = true repository.workspace = true +[features] +default = ["std"] +std = [] + [dependencies] hex = { version = "0.4" } miden-node-utils = { workspace = true } diff --git a/crates/rpc-proto/build.rs b/crates/rpc-proto/build.rs index 2c8abc90a..23a86396f 100644 --- a/crates/rpc-proto/build.rs +++ b/crates/rpc-proto/build.rs @@ -5,6 +5,9 @@ use std::{ path::Path, }; +const DOC_COMMENT: &'static str = + "A mapping of filenames to file contents of the node protobuf files."; + fn main() -> io::Result<()> { let out_dir = env::current_dir().expect("Error getting cwd"); let dest_path = Path::new(&out_dir).join("./src/proto_files.rs"); @@ -12,6 +15,7 @@ fn main() -> io::Result<()> { let proto_dir = Path::new("../../proto"); + writeln!(file, "/// {DOC_COMMENT}")?; writeln!(file, "pub const PROTO_FILES: &[(&str, &str)] = &[")?; for entry in std::fs::read_dir(proto_dir)? { diff --git a/crates/rpc-proto/src/lib.rs b/crates/rpc-proto/src/lib.rs index 582d4773c..e21d46933 100644 --- a/crates/rpc-proto/src/lib.rs +++ b/crates/rpc-proto/src/lib.rs @@ -1,14 +1,14 @@ -use std::{ - fs::{self, File}, - io::Write, - path::Path, -}; - mod proto_files; pub use proto_files::PROTO_FILES; /// Writes the RPC protobuf file into `target_dir`. -pub fn write_proto(target_dir: &Path) -> Result<(), String> { +#[cfg(feature = "std")] +pub fn write_proto(target_dir: &std::path::Path) -> Result<(), String> { + use std::{ + fs::{self, File}, + io::Write, + }; + if !target_dir.exists() { fs::create_dir_all(target_dir) .map_err(|err| format!("Error creating directory: {}", err))?; diff --git a/crates/rpc-proto/src/proto_files.rs b/crates/rpc-proto/src/proto_files.rs index 9d56ac633..72ba435cf 100644 --- a/crates/rpc-proto/src/proto_files.rs +++ b/crates/rpc-proto/src/proto_files.rs @@ -1,3 +1,4 @@ +/// A mapping of filenames to file contents of the node protobuf files. pub const PROTO_FILES: &[(&str, &str)] = &[ ("note.proto", include_str!("../../../proto/note.proto")), ("smt.proto", include_str!("../../../proto/smt.proto")), From 690c5a4c6f44dbcd83d184f2e2d0d48cdb235bad Mon Sep 17 00:00:00 2001 From: Ignacio Amigo Date: Tue, 25 Jun 2024 15:26:34 -0300 Subject: [PATCH 07/13] Better doc comment --- crates/rpc-proto/build.rs | 2 +- crates/rpc-proto/src/proto_files.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/rpc-proto/build.rs b/crates/rpc-proto/build.rs index 23a86396f..61e141717 100644 --- a/crates/rpc-proto/build.rs +++ b/crates/rpc-proto/build.rs @@ -6,7 +6,7 @@ use std::{ }; const DOC_COMMENT: &'static str = - "A mapping of filenames to file contents of the node protobuf files."; + "A list of tuples containing the names and contents of various protobuf files."; fn main() -> io::Result<()> { let out_dir = env::current_dir().expect("Error getting cwd"); diff --git a/crates/rpc-proto/src/proto_files.rs b/crates/rpc-proto/src/proto_files.rs index 72ba435cf..8e7e5c506 100644 --- a/crates/rpc-proto/src/proto_files.rs +++ b/crates/rpc-proto/src/proto_files.rs @@ -1,4 +1,4 @@ -/// A mapping of filenames to file contents of the node protobuf files. +/// A list of tuples containing the names and contents of various protobuf files. pub const PROTO_FILES: &[(&str, &str)] = &[ ("note.proto", include_str!("../../../proto/note.proto")), ("smt.proto", include_str!("../../../proto/smt.proto")), From 213b737d195e5b37a6f26cad71bac47241a16c78 Mon Sep 17 00:00:00 2001 From: Ignacio Amigo Date: Tue, 25 Jun 2024 15:33:23 -0300 Subject: [PATCH 08/13] Fix --- crates/rpc-proto/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rpc-proto/build.rs b/crates/rpc-proto/build.rs index 61e141717..1d7d1d178 100644 --- a/crates/rpc-proto/build.rs +++ b/crates/rpc-proto/build.rs @@ -5,7 +5,7 @@ use std::{ path::Path, }; -const DOC_COMMENT: &'static str = +const DOC_COMMENT: &str = "A list of tuples containing the names and contents of various protobuf files."; fn main() -> io::Result<()> { From f13b8a9ac150d728ec9fe345acfaaa3e1f67a09c Mon Sep 17 00:00:00 2001 From: igamigo Date: Tue, 25 Jun 2024 16:15:25 -0300 Subject: [PATCH 09/13] Remove proptest --- crates/rpc-proto/Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/rpc-proto/Cargo.toml b/crates/rpc-proto/Cargo.toml index fd44a5ac0..e6c27cb22 100644 --- a/crates/rpc-proto/Cargo.toml +++ b/crates/rpc-proto/Cargo.toml @@ -23,9 +23,6 @@ prost = { version = "0.12" } thiserror = { workspace = true } tonic = { workspace = true } -[dev-dependencies] -proptest = { version = "1.2" } - [build-dependencies] miette = { version = "7.0", features = ["fancy"] } prost = { version = "0.12" } From d2218c8a36b8566ac6a9d9719774937824a86176 Mon Sep 17 00:00:00 2001 From: Ignacio Amigo Date: Tue, 25 Jun 2024 17:41:01 -0300 Subject: [PATCH 10/13] Dependencies --- Cargo.lock | 10 ---------- crates/rpc-proto/Cargo.toml | 18 ++---------------- crates/rpc-proto/build.rs | 2 +- 3 files changed, 3 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6a7cfc350..afaaaf257 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1883,17 +1883,7 @@ dependencies = [ name = "miden-rpc-proto" version = "0.3.0" dependencies = [ - "hex", - "miden-node-utils", - "miden-objects", - "miette", - "proptest", "prost", - "prost-build", - "protox", - "thiserror", - "tonic", - "tonic-build", ] [[package]] diff --git a/crates/rpc-proto/Cargo.toml b/crates/rpc-proto/Cargo.toml index fd44a5ac0..b99682d89 100644 --- a/crates/rpc-proto/Cargo.toml +++ b/crates/rpc-proto/Cargo.toml @@ -1,9 +1,10 @@ [package] name = "miden-rpc-proto" version = "0.3.0" -description = "Miden RPC message definitions" +description = "Miden node RPC message definitions" readme = "README.md" keywords = ["miden", "node", "protobuf", "rpc"] +categories = ["no-std"] edition.workspace = true rust-version.workspace = true license.workspace = true @@ -16,19 +17,4 @@ default = ["std"] std = [] [dependencies] -hex = { version = "0.4" } -miden-node-utils = { workspace = true } -miden-objects = { workspace = true } prost = { version = "0.12" } -thiserror = { workspace = true } -tonic = { workspace = true } - -[dev-dependencies] -proptest = { version = "1.2" } - -[build-dependencies] -miette = { version = "7.0", features = ["fancy"] } -prost = { version = "0.12" } -prost-build = { version = "0.12" } -protox = { version = "0.6" } -tonic-build = { version = "0.11" } diff --git a/crates/rpc-proto/build.rs b/crates/rpc-proto/build.rs index 1d7d1d178..f93c05369 100644 --- a/crates/rpc-proto/build.rs +++ b/crates/rpc-proto/build.rs @@ -11,7 +11,7 @@ const DOC_COMMENT: &str = fn main() -> io::Result<()> { let out_dir = env::current_dir().expect("Error getting cwd"); let dest_path = Path::new(&out_dir).join("./src/proto_files.rs"); - let mut file = File::create(&dest_path)?; + let mut file = File::create(dest_path)?; let proto_dir = Path::new("../../proto"); From abb808abc491b7290832d8040e8f46752f803f98 Mon Sep 17 00:00:00 2001 From: Ignacio Amigo Date: Tue, 25 Jun 2024 17:48:52 -0300 Subject: [PATCH 11/13] Remove dependencies --- Cargo.lock | 3 --- crates/rpc-proto/Cargo.toml | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index afaaaf257..d0241ae62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1882,9 +1882,6 @@ dependencies = [ [[package]] name = "miden-rpc-proto" version = "0.3.0" -dependencies = [ - "prost", -] [[package]] name = "miden-stdlib" diff --git a/crates/rpc-proto/Cargo.toml b/crates/rpc-proto/Cargo.toml index b99682d89..b607a593d 100644 --- a/crates/rpc-proto/Cargo.toml +++ b/crates/rpc-proto/Cargo.toml @@ -4,7 +4,7 @@ version = "0.3.0" description = "Miden node RPC message definitions" readme = "README.md" keywords = ["miden", "node", "protobuf", "rpc"] -categories = ["no-std"] +categories = ["no-std::no-alloc"] edition.workspace = true rust-version.workspace = true license.workspace = true @@ -15,6 +15,3 @@ repository.workspace = true [features] default = ["std"] std = [] - -[dependencies] -prost = { version = "0.12" } From f1a9660591fc830acfc35a023572962c4a256b6e Mon Sep 17 00:00:00 2001 From: Ignacio Amigo Date: Tue, 25 Jun 2024 18:33:09 -0300 Subject: [PATCH 12/13] no_std --- crates/rpc-proto/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/rpc-proto/src/lib.rs b/crates/rpc-proto/src/lib.rs index e21d46933..e861badc7 100644 --- a/crates/rpc-proto/src/lib.rs +++ b/crates/rpc-proto/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(not(feature = "std"), no_std)] + mod proto_files; pub use proto_files::PROTO_FILES; From c300232454e080c910394094e69411579f81eed1 Mon Sep 17 00:00:00 2001 From: Ignacio Amigo Date: Tue, 25 Jun 2024 19:07:43 -0300 Subject: [PATCH 13/13] Invert no_std guard --- crates/rpc-proto/src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/rpc-proto/src/lib.rs b/crates/rpc-proto/src/lib.rs index e861badc7..17711f2bc 100644 --- a/crates/rpc-proto/src/lib.rs +++ b/crates/rpc-proto/src/lib.rs @@ -1,14 +1,19 @@ -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] + +#[cfg(feature = "std")] +extern crate std; mod proto_files; pub use proto_files::PROTO_FILES; /// Writes the RPC protobuf file into `target_dir`. #[cfg(feature = "std")] -pub fn write_proto(target_dir: &std::path::Path) -> Result<(), String> { +pub fn write_proto(target_dir: &std::path::Path) -> Result<(), std::string::String> { use std::{ + format, fs::{self, File}, io::Write, + string::ToString, }; if !target_dir.exists() {