Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove ApiClient from rpc crate #723

Draft
wants to merge 1 commit into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- [BREAKING] Update `GetBlockInputs` RPC (#709).
- [BREAKING] `CheckNullifiersByPrefix` now takes a starting block number (#707).
- [BREAKING] Removed nullifiers from `SyncState` endpoint (#708).
- [BREAKING] Removed rpc api client from `proto` crate.

### Enhancements

Expand Down
2 changes: 1 addition & 1 deletion bin/faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ clap = { version = "4.5", features = ["derive", "string"] }
http = "1.1"
http-body-util = "0.1"
miden-lib = { workspace = true }
miden-node-proto = { workspace = true }
miden-node-proto = { workspace = true, features = ["rpc-client"] }
miden-node-utils = { workspace = true }
miden-objects = { workspace = true }
miden-tx = { workspace = true, features = ["concurrent"] }
Expand Down
3 changes: 3 additions & 0 deletions crates/proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ repository.workspace = true
rust-version.workspace = true
version.workspace = true

[features]
rpc-client = []

[lints]
workspace = true

Expand Down
44 changes: 29 additions & 15 deletions crates/proto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,45 @@ fn main() -> anyhow::Result<()> {
let out = env::var("OUT_DIR").context("env::OUT_DIR not set")?;
let file_descriptor_path = PathBuf::from(out).join("file_descriptor_set.bin");

// Compile the proto file for all servers APIs
let protos = &[
proto_dir.join("block_producer.proto"),
proto_dir.join("store.proto"),
proto_dir.join("rpc.proto"),
];
// Compile the proto file for block_producer and store
let protos = &[proto_dir.join("block_producer.proto"), proto_dir.join("store.proto")];
compile_proto_files(protos, true, proto_dir.clone(), &file_descriptor_path, &dst_dir)?;

// Compile the proto file for rpc
let protos = &[proto_dir.join("rpc.proto")];
#[cfg(feature = "rpc-client")]
let generate_rpc_server = true;
#[cfg(not(feature = "rpc-client"))]
let generate_rpc_server = false;
compile_proto_files(protos, generate_rpc_server, proto_dir, &file_descriptor_path, &dst_dir)?;

generate_mod_rs(&dst_dir).context("generating mod.rs")?;

Ok(())
}

fn compile_proto_files(
protos: &[PathBuf],
with_client: bool,
proto_dir: PathBuf,
file_descriptor_path: &PathBuf,
dst_dir: &PathBuf,
) -> anyhow::Result<()> {
let includes = &[proto_dir];
let file_descriptors = protox::compile(protos, includes)?;
fs::write(&file_descriptor_path, file_descriptors.encode_to_vec())
fs::write(file_descriptor_path, file_descriptors.encode_to_vec())
.context("writing file descriptors")?;

let mut prost_config = prost_build::Config::new();
prost_config.skip_debug(["AccountId", "Digest"]);

// Generate the stub of the user facing server from its proto file
tonic_build::configure()
.file_descriptor_set_path(&file_descriptor_path)
.build_client(with_client)
.file_descriptor_set_path(file_descriptor_path)
.skip_protoc_run()
.out_dir(&dst_dir)
.out_dir(dst_dir)
.compile_protos_with_config(prost_config, protos, includes)
.context("compiling protobufs")?;

generate_mod_rs(&dst_dir).context("generating mod.rs")?;

Ok(())
.context("compiling protobufs")
}

/// Generate `mod.rs` which includes all files in the folder as submodules.
Expand Down
Loading