diff --git a/Cargo.lock b/Cargo.lock index a335850..0d6a3d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -856,6 +856,7 @@ dependencies = [ "serde", "serde_json", "thiserror", + "tokio", "tracing", ] diff --git a/crates/wallet/Cargo.toml b/crates/wallet/Cargo.toml index 43c7cfd..ebc922a 100644 --- a/crates/wallet/Cargo.toml +++ b/crates/wallet/Cargo.toml @@ -23,6 +23,7 @@ jsonrpsee = { workspace = true, features = ["server", "macros"] } serde = { workspace = true, features = ["derive"] } thiserror.workspace = true tracing.workspace = true +tokio = { workspace = true, features = ["sync"] } [dev-dependencies] serde_json.workspace = true diff --git a/crates/wallet/src/lib.rs b/crates/wallet/src/lib.rs index 6e79399..3deddd2 100644 --- a/crates/wallet/src/lib.rs +++ b/crates/wallet/src/lib.rs @@ -34,6 +34,7 @@ use std::sync::Arc; use tracing::{trace, warn}; use reth_revm as _; +use tokio::sync::Mutex; /// The capability to perform [EIP-7702][eip-7702] delegations, sponsored by the sequencer. /// @@ -175,6 +176,7 @@ impl AlphaNetWallet { chain_id, Capabilities { delegation: DelegationCapability { addresses: valid_designations } }, )])), + permit: Default::default(), }; Self { inner: Arc::new(inner) } } @@ -244,6 +246,9 @@ where _ => return Err(AlphaNetWalletError::IllegalDestination.into()), } + // we acquire the permit here so that all following operations are performed exclusively + let _permit = self.inner.permit.lock().await; + // set nonce let tx_count = EthState::transaction_count( &self.inner.eth_api, @@ -295,10 +300,12 @@ where /// Implementation of the AlphaNet `wallet_` namespace. struct AlphaNetWalletInner { provider: Provider, + eth_api: Eth, wallet: EthereumWallet, chain_id: ChainId, capabilities: WalletCapabilities, - eth_api: Eth, + /// Used to guard tx signing + permit: Mutex<()>, } fn validate_tx_request(request: &TransactionRequest) -> Result<(), AlphaNetWalletError> {