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: make Client send and sync #659

Closed
wants to merge 1 commit into from
Closed
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
26 changes: 22 additions & 4 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ repository = "https://github.com/0xPolygonMiden/miden-client"

[workspace.dependencies]
async-trait = "0.1"
miden-lib = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", default-features = false }
miden-objects = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", default-features = false }
miden-tx = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", default-features = false, features = ["async"] }
miden-tx-prover = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", features = ["async"] }
miden-lib = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "tomyrd-send-sync-traits", default-features = false }
miden-objects = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "tomyrd-send-sync-traits", default-features = false }
miden-tx = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "tomyrd-send-sync-traits", default-features = false, features = ["async"] }
miden-tx-prover = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "tomyrd-send-sync-traits", features = ["async"] }
rand = { version = "0.8" }
serde = { version = "1.0", features = ["derive"] }
thiserror = { version = "2.0", default-features = false }
Expand Down
6 changes: 3 additions & 3 deletions crates/rust-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub struct Client<R: FeltRng> {
rng: R,
/// An instance of [NodeRpcClient] which provides a way for the client to connect to the
/// Miden node.
rpc_api: Box<dyn NodeRpcClient + Send>,
rpc_api: Box<dyn NodeRpcClient + Send + Sync>,
/// An instance of a [LocalTransactionProver] which will be the default prover for the client.
tx_prover: Arc<LocalTransactionProver>,
tx_executor: TransactionExecutor,
Expand Down Expand Up @@ -147,7 +147,7 @@ impl<R: FeltRng> Client<R> {
///
/// Returns an error if the client couldn't be instantiated.
pub fn new(
rpc_api: Box<dyn NodeRpcClient + Send>,
rpc_api: Box<dyn NodeRpcClient + Send + Sync>,
rng: R,
store: Arc<dyn Store>,
authenticator: Arc<dyn TransactionAuthenticator>,
Expand Down Expand Up @@ -182,7 +182,7 @@ impl<R: FeltRng> Client<R> {
// --------------------------------------------------------------------------------------------

#[cfg(any(test, feature = "testing"))]
pub fn test_rpc_api(&mut self) -> &mut Box<dyn NodeRpcClient + Send> {
pub fn test_rpc_api(&mut self) -> &mut Box<dyn NodeRpcClient + Send + Sync> {
&mut self.rpc_api
}

Expand Down
6 changes: 3 additions & 3 deletions crates/rust-client/src/store/authenticator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ use rand::Rng;
use super::Store;

/// Represents an authenticator based on a [Store].
pub struct StoreAuthenticator<R> {
pub struct StoreAuthenticator<R: Send + Sync> {
store: Arc<dyn Store>,
rng: Arc<RwLock<R>>,
}

impl<R: Rng> StoreAuthenticator<R> {
impl<R: Rng + Send + Sync> StoreAuthenticator<R> {
pub fn new_with_rng(store: Arc<dyn Store>, rng: R) -> Self {
StoreAuthenticator { store, rng: Arc::new(RwLock::new(rng)) }
}
}

impl<R: Rng> TransactionAuthenticator for StoreAuthenticator<R> {
impl<R: Rng + Send + Sync> TransactionAuthenticator for StoreAuthenticator<R> {
/// Gets a signature over a message, given a public key.
///
/// The pub key should correspond to one of the keys tracked by the authenticator's store.
Expand Down
3 changes: 3 additions & 0 deletions crates/rust-client/src/store/web_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,6 @@ impl Store for WebStore {
self.get_unspent_input_note_nullifiers().await
}
}

unsafe impl Send for WebStore {}
unsafe impl Sync for WebStore {}
11 changes: 4 additions & 7 deletions crates/rust-client/src/transactions/request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,21 +340,18 @@ mod tests {

#[test]
fn transaction_request_serialization() {
let sender_id = AccountId::new_dummy(
let sender_id = AccountId::dummy(
[0u8; 15],
AccountType::RegularAccountImmutableCode,
AccountStorageMode::Private,
);
let target_id = AccountId::new_dummy(
let target_id = AccountId::dummy(
[1u8; 15],
AccountType::RegularAccountImmutableCode,
AccountStorageMode::Public,
);
let faucet_id = AccountId::new_dummy(
[2u8; 15],
AccountType::FungibleFaucet,
AccountStorageMode::Private,
);
let faucet_id =
AccountId::dummy([2u8; 15], AccountType::FungibleFaucet, AccountStorageMode::Private);
let mut rng = RpoRandomCoin::new(Default::default());

let mut notes = vec![];
Expand Down
2 changes: 1 addition & 1 deletion crates/web-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ testing = ["miden-client/testing", "miden-tx-prover/testing"]
miden-client = { version = "0.6", path = "../rust-client", default-features = false, features = ["idxdb", "web-tonic"] }
miden-lib = { workspace = true }
miden-objects = { workspace = true }
miden-tx-prover = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", default-features = false, features = ["async"] }
miden-tx-prover = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "tomyrd-send-sync-traits", default-features = false, features = ["async"] }
rand = { workspace = true }
serde = { workspace = true }
serde-wasm-bindgen = { version = "0.6" }
Expand Down
Loading