Skip to content

Commit

Permalink
feat: remove RemoteTxProver from miden-tx-prover crate
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiagoPittella committed Jan 2, 2025
1 parent 2072088 commit 600a532
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 392 deletions.
40 changes: 0 additions & 40 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ build: ## By default we should build in release mode

.PHONY: build-no-std
build-no-std: ## Build without the standard library
${BUILD_KERNEL_ERRORS} cargo build --no-default-features --target wasm32-unknown-unknown --workspace --lib
${BUILD_KERNEL_ERRORS} cargo build --no-default-features --target wasm32-unknown-unknown --workspace --lib --exclude miden-tx-prover


.PHONY: build-no-std-testing
Expand Down
37 changes: 13 additions & 24 deletions bin/tx-prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,44 @@ name = "miden-tx-prover"
path = "src/main.rs"
required-features = ["std"]

[lib]
crate-type = ["lib"]

[features]
async = ["miden-tx/async"]
default = ["std"]
std = ["miden-objects/std", "miden-tx/std", "dep:tokio", "dep:tonic-web", "dep:tokio-stream", "dep:axum", "dep:tracing", "dep:tracing-subscriber", "tonic/transport"]
testing = ["miden-objects/testing", "miden-lib/testing", "miden-tx/testing"]
concurrent = ["miden-lib/concurrent", "miden-objects/concurrent", "miden-tx/concurrent", "std"]

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
tonic-web-wasm-client = { version = "0.6", default-features = false }
tonic = { version = "0.12", default-features = false, features = ["prost", "codegen"] }
getrandom = { version = "0.2", features = ["js"], optional = true }

[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dependencies]
bytes = "1.0"
tonic = { version = "0.12", default-features = false, features = ["prost", "codegen", "transport"] }
once_cell = "1.19"
pingora = { version = "0.4", features = [ "lb" ] }
pingora-core = "0.4"
pingora-proxy = "0.4"
pingora-limits = "0.4"
opentelemetry = { version = "0.27", features = ["metrics", "trace"] }
opentelemetry-otlp = { version = "0.27", features = ["grpc-tonic"] }
opentelemetry_sdk = { version = "0.27", features = ["metrics", "rt-tokio"] }
opentelemetry-semantic-conventions = "0.27"
opentelemetry-jaeger = "0.22"
tracing-opentelemetry = "0.28"

[dependencies]
async-trait = "0.1"
axum = {version = "0.7", optional = true }
bytes = "1.0"
clap = { version = "4.5", features = ["derive"] }
figment = { version = "0.10", features = ["toml", "env"] }
miden-lib = { workspace = true, default-features = false }
miden-objects = { workspace = true, default-features = false }
miden-tx = { workspace = true, default-features = false }
once_cell = "1.19"
opentelemetry = { version = "0.27", features = ["metrics", "trace"] }
opentelemetry-otlp = { version = "0.27", features = ["grpc-tonic"] }
opentelemetry_sdk = { version = "0.27", features = ["metrics", "rt-tokio"] }
opentelemetry-semantic-conventions = "0.27"
opentelemetry-jaeger = "0.22"
prost = { version = "0.13", default-features = false, features = ["derive"] }
pingora = { version = "0.4", features = [ "lb" ] }
pingora-core = "0.4"
pingora-proxy = "0.4"
pingora-limits = "0.4"
reqwest = { version = "0.11" }
serde = { version = "1.0", features = ["derive"] }
serde_qs = { version = "0.13" }
tokio = { version = "1.38", optional = true, features = ["full"] }
tokio-stream = { version = "0.1", optional = true, features = [ "net" ]}
toml = { version = "0.8" }
thiserror = { workspace = true }
tonic = { version = "0.12", default-features = false, features = ["prost", "codegen", "transport"] }
tonic-health = { version = "0.12" }
tonic-web = { version = "0.12", optional = true }
tracing = { version = "0.1", optional = true }
tracing-opentelemetry = "0.28"
tracing-subscriber = { version = "0.3", features = ["fmt", "json", "env-filter"], optional = true }
uuid = { version = "1.11", features = ["v4"] }
winter-maybe-async = { version = "0.10" }
Expand Down
12 changes: 0 additions & 12 deletions bin/tx-prover/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ The worker is a gRPC service that can receive transaction witnesses and returns

The proxy uses [Cloudflare's Pingora crate](https://crates.io/crates/pingora), which provides features to create a modular proxy. It is meant to handle multiple workers with a queue, assigning a worker to each request and retrying if the worker is not available. Further information about Pingora and its features can be found in the [official GitHub repository](https://github.com/cloudflare/pingora).

Additionally, the library can be imported to utilize `RemoteTransactionProver`, a client struct that can be used to interact with the prover service from a Rust codebase.

## Installation

To build the service from a local version, from the root of the workspace you can run:
Expand Down Expand Up @@ -128,14 +126,4 @@ Description of this crate's feature:
| ------------ | ------------------------------------------------------------------------------------------------------------|
| `std` | Enable usage of Rust's `std`, use `--no-default-features` for `no-std` support. |
| `concurrent` | Enables concurrent code to speed up runtime execution. |
| `async` | Enables the `RemoteTransactionProver` struct, that implements an async version of `TransactionProver` trait.|
| `testing` | Enables testing utilities and reduces proof-of-work requirements to speed up tests' runtimes. |

### Using RemoteTransactionProver
To use the `RemoteTransactionProver` struct, enable `async`. Additionally, when compiling for `wasm32-unknown-unknown`, disable default features.

```
[dependencies]
miden-tx-prover = { version = "0.7", features = ["async"], default-features = false } # Uses tonic-web-wasm-client transport
miden-tx-prover = { version = "0.7", features = ["async"] } # Uses tonic's Channel transport
```
28 changes: 3 additions & 25 deletions bin/tx-prover/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{
env, fs,
io::Write,
path::{Path, PathBuf},
};

Expand Down Expand Up @@ -38,28 +37,8 @@ fn compile_tonic_server_proto() -> miette::Result<()> {
let file_descriptors = protox::compile(protos, includes)?;
fs::write(&file_descriptor_path, file_descriptors.encode_to_vec()).into_diagnostic()?;

// Codegen for wasm transport and std transport
let nostd_path = dst_dir.join("nostd");
let std_path = dst_dir.join("std");
build_tonic_server(&file_descriptor_path, &std_path, protos, includes, false)?;
build_tonic_server(&file_descriptor_path, &nostd_path, protos, includes, true)?;

// Replace `std` references with `core` and `alloc` in `api.rs`.
// (Only for nostd version)
let nostd_file_path = nostd_path.join("api.rs");
let file_content = fs::read_to_string(&nostd_file_path).into_diagnostic()?;
let updated_content = file_content
.replace("std::result", "core::result")
.replace("std::marker", "core::marker")
.replace("format!", "alloc::format!");

let mut file = fs::OpenOptions::new()
.write(true)
.truncate(true)
.open(&nostd_file_path)
.into_diagnostic()?;

file.write_all(updated_content.as_bytes()).into_diagnostic()?;
build_tonic_server(&file_descriptor_path, &std_path, protos, includes)?;

Ok(())
}
Expand All @@ -69,14 +48,13 @@ fn build_tonic_server(
out_dir: &Path,
protos: &[PathBuf],
includes: &[PathBuf],
for_no_std: bool,
) -> miette::Result<()> {
tonic_build::configure()
.file_descriptor_set_path(file_descriptor_path)
.skip_protoc_run()
.out_dir(out_dir)
.build_server(!for_no_std)
.build_transport(!for_no_std)
.build_server(true)
.build_transport(true)
.compile_protos_with_config(prost_build::Config::new(), protos, includes)
.into_diagnostic()
}
12 changes: 7 additions & 5 deletions bin/tx-prover/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ use miden_tx::{
utils::{Deserializable, Serializable},
LocalTransactionProver, TransactionProver,
};
use miden_tx_prover::generated::{
api_server::{Api as ProverApi, ApiServer},
ProveTransactionRequest, ProveTransactionResponse,
};
use tokio::{net::TcpListener, sync::Mutex};
use tonic::{Request, Response, Status};
use tracing::instrument;

use crate::utils::MIDEN_TX_PROVER;
use crate::{
generated::{
api_server::{Api as ProverApi, ApiServer},
ProveTransactionRequest, ProveTransactionResponse,
},
utils::MIDEN_TX_PROVER,
};

pub struct RpcListener {
pub api_service: ApiServer<ProverRpcApi>,
Expand Down
3 changes: 1 addition & 2 deletions bin/tx-prover/src/commands/init.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::{fs::File, io::Write};

use clap::Parser;
use miden_tx_prover::PROVER_SERVICE_CONFIG_FILE_NAME;

use crate::commands::ProxyConfig;
use crate::{commands::ProxyConfig, utils::PROVER_SERVICE_CONFIG_FILE_NAME};

/// Creates a config file for the proxy.
#[derive(Debug, Parser)]
Expand Down
3 changes: 1 addition & 2 deletions bin/tx-prover/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ use figment::{
Figment,
};
use init::Init;
use miden_tx_prover::PROVER_SERVICE_CONFIG_FILE_NAME;
use proxy::StartProxy;
use serde::{Deserialize, Serialize};
use tracing::instrument;
use update_workers::{AddWorkers, RemoveWorkers, UpdateWorkers};
use worker::StartWorker;

use crate::utils::MIDEN_TX_PROVER;
use crate::utils::{MIDEN_TX_PROVER, PROVER_SERVICE_CONFIG_FILE_NAME};

pub mod init;
pub mod proxy;
Expand Down
3 changes: 1 addition & 2 deletions bin/tx-prover/src/commands/worker.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use clap::Parser;
use miden_tx_prover::generated::api_server::ApiServer;
use tokio::net::TcpListener;
use tokio_stream::wrappers::TcpListenerStream;
use tonic_health::server::health_reporter;
use tracing::{info, instrument};

use crate::{api::RpcListener, utils::MIDEN_TX_PROVER};
use crate::{api::RpcListener, generated::api_server::ApiServer, utils::MIDEN_TX_PROVER};

/// Starts a worker.
#[derive(Debug, Parser)]
Expand Down
12 changes: 1 addition & 11 deletions bin/tx-prover/src/generated/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
use miden_objects::transaction::ProvenTransaction;
use miden_tx::utils::{Deserializable, DeserializationError, Serializable};

#[cfg(all(feature = "std", target_arch = "wasm32"))]
compile_error!("The `std` feature cannot be used when targeting `wasm32`.");

#[cfg(feature = "std")]
mod std;
#[cfg(feature = "std")]
pub mod std;
pub use std::api::*;

#[cfg(not(feature = "std"))]
mod nostd;
#[cfg(not(feature = "std"))]
pub use nostd::api::*;

// CONVERSIONS
// ================================================================================================

Expand Down
Loading

0 comments on commit 600a532

Please sign in to comment.