Skip to content

Commit

Permalink
Merge branch 'grarco/sdk-async-traits-send' (#1894)
Browse files Browse the repository at this point in the history
* origin/grarco/sdk-async-traits-send:
  changelog: add #1894
  Conditionally requires async traits `Send`ness
  Makes async traits in the SDK be `Send`
  • Loading branch information
Fraccaman committed Sep 25, 2023
2 parents 65bd62a + d89c660 commit b0c3660
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .changelog/unreleased/SDK/1894-sdk-async-traits-send.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Added the `Send` bound to the `Client` and `ShieldedUtils` `async_trait`s'.
This allows the SDK to be used in environments which are both asynchronous and
multithread. ([\#1894](https://github.com/anoma/namada/pull/1894))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Forced the `async_trait`s' futures in the SDK to be `Send`.
([\#1894](https://github.com/anoma/namada/pull/1894))
4 changes: 2 additions & 2 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
use std::path::PathBuf;

use async_trait::async_trait;
use borsh::{BorshDeserialize, BorshSerialize};
use masp_proofs::prover::LocalTxProver;
use namada::core::ledger::governance::cli::offline::{
Expand Down Expand Up @@ -643,7 +642,8 @@ impl Default for CLIShieldedUtils {
}
}

#[async_trait(?Send)]
#[cfg_attr(feature = "async-send", async_trait::async_trait)]
#[cfg_attr(not(feature = "async-send"), async_trait::async_trait(?Send))]
impl masp::ShieldedUtils for CLIShieldedUtils {
fn local_tx_prover(&self) -> LocalTxProver {
if let Ok(params_dir) = env::var(masp::ENV_VAR_MASP_PARAMS_DIR) {
Expand Down
3 changes: 2 additions & 1 deletion apps/src/lib/node/ledger/shell/testing/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ impl MockNode {
}
}

#[async_trait::async_trait(?Send)]
#[cfg_attr(feature = "async-send", async_trait::async_trait)]
#[cfg_attr(not(feature = "async-send"), async_trait::async_trait(?Send))]
impl<'a> Client for &'a MockNode {
type Error = Report;

Expand Down
6 changes: 4 additions & 2 deletions benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,8 @@ pub struct BenchShieldedUtils {
context_dir: WrapperTempDir,
}

#[async_trait::async_trait(?Send)]
#[cfg_attr(feature = "async-send", async_trait::async_trait)]
#[cfg_attr(not(feature = "async-send"), async_trait::async_trait(?Send))]
impl ShieldedUtils for BenchShieldedUtils {
fn local_tx_prover(&self) -> LocalTxProver {
if let Ok(params_dir) = std::env::var(masp::ENV_VAR_MASP_PARAMS_DIR) {
Expand Down Expand Up @@ -611,7 +612,8 @@ impl ShieldedUtils for BenchShieldedUtils {
}
}

#[async_trait::async_trait(?Send)]
#[cfg_attr(feature = "async-send", async_trait::async_trait)]
#[cfg_attr(not(feature = "async-send"), async_trait::async_trait(?Send))]
impl Client for BenchShell {
type Error = std::io::Error;

Expand Down
4 changes: 4 additions & 0 deletions shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ wasm-runtime = [
async-client = [
"async-trait",
]

# Requires async traits to be safe to send across threads
async-send = []

# tendermint-rpc support
tendermint-rpc = [
"async-client",
Expand Down
3 changes: 2 additions & 1 deletion shared/src/ledger/queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ mod testing {
}
}

#[async_trait::async_trait(?Send)]
#[cfg_attr(feature = "async-send", async_trait::async_trait)]
#[cfg_attr(not(feature = "async-send"), async_trait::async_trait(?Send))]
impl<RPC> Client for TestClient<RPC>
where
RPC: Router + Sync,
Expand Down
4 changes: 2 additions & 2 deletions shared/src/sdk/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::fmt::Debug;
use std::ops::Deref;
use std::path::PathBuf;

use async_trait::async_trait;
// use async_std::io::prelude::WriteExt;
// use async_std::io::{self};
use borsh::{BorshDeserialize, BorshSerialize};
Expand Down Expand Up @@ -388,7 +387,8 @@ impl<P1, R1, N1>

/// Abstracts platform specific details away from the logic of shielded pool
/// operations.
#[async_trait(? Send)]
#[cfg_attr(feature = "async-send", async_trait::async_trait)]
#[cfg_attr(not(feature = "async-send"), async_trait::async_trait(?Send))]
pub trait ShieldedUtils:
Sized + BorshDeserialize + BorshSerialize + Default + Clone
{
Expand Down

0 comments on commit b0c3660

Please sign in to comment.