Skip to content

Commit 56620a8

Browse files
committed
chores
1 parent 6459600 commit 56620a8

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ secp256k1 = { version = "0.27.0", default-features = false, features = [
5050
"alloc",
5151
] }
5252

53-
near-account-id = { version = "2.0.0", features = ["serde", "borsh", "abi"] }
53+
near-account-id = { version = "2.0.0", features = ["serde", "borsh"] }
5454
near-gas = { version = "0.3", features = ["serde", "borsh"] }
5555
near-token = { version = "0.3", features = ["serde", "borsh"] }
5656
near-abi = "0.4.2"

api/src/signer/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub mod keystore;
141141
#[cfg(feature = "ledger")]
142142
pub mod ledger;
143143
pub mod secret_key;
144-
pub mod sequential;
144+
mod sequential;
145145

146146
const SIGNER_TARGET: &str = "near_api::signer";
147147
/// Default HD path for seed phrases and secret keys generation
@@ -407,8 +407,8 @@ pub type TransactionGroupKey = (String, AccountId, PublicKey);
407407
/// adding more keys to the signer pool
408408
pub struct Signer {
409409
pool: tokio::sync::RwLock<HashMap<PublicKey, Box<dyn SignerTrait + Send + Sync + 'static>>>,
410+
nonce_cache: Mutex<HashMap<TransactionGroupKey, Arc<Mutex<u64>>>>,
410411
current_public_key: AtomicUsize,
411-
sequential_nonces: Mutex<HashMap<TransactionGroupKey, Arc<Mutex<u64>>>>,
412412
}
413413

414414
impl Signer {
@@ -423,8 +423,8 @@ impl Signer {
423423
public_key,
424424
Box::new(signer) as Box<dyn SignerTrait + Send + Sync + 'static>,
425425
)])),
426+
nonce_cache: Mutex::new(HashMap::new()),
426427
current_public_key: AtomicUsize::new(0),
427-
sequential_nonces: Mutex::new(HashMap::new()),
428428
}))
429429
}
430430

api/src/signer/sequential.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ impl Signer {
3939
))
4040
}
4141

42-
async fn get_sequential_nonce(&self, key: TransactionGroupKey) -> Arc<Mutex<u64>> {
43-
self.sequential_nonces
42+
async fn get_nonce_cache(&self, key: TransactionGroupKey) -> Arc<Mutex<u64>> {
43+
self.nonce_cache
4444
.lock()
4545
.await
4646
.entry(key)
@@ -67,14 +67,14 @@ impl Signer {
6767
debug!(target: SIGNER_TARGET, "Fetching transaction nonce");
6868

6969
let key = (network.network_name.clone(), account_id.clone(), public_key);
70-
let lock = self.get_sequential_nonce(key).await;
70+
let lock = self.get_nonce_cache(key).await;
7171
let mut nonce = lock.lock().await;
7272

7373
// It is important to fetch the nonce data after lock to get fresh block hash
74-
let (cached_nonce, block_hash, block_height) =
74+
let (fetched_nonce, block_hash, block_height) =
7575
Self::fetch_nonce_data(account_id, public_key, network).await?;
7676

77-
*nonce = (*nonce).max(cached_nonce) + 1;
77+
*nonce = (*nonce).max(fetched_nonce) + 1;
7878

7979
Ok((*nonce, block_hash, block_height))
8080
}
@@ -109,7 +109,7 @@ impl Signer {
109109
.await?;
110110

111111
match wait_until {
112-
TxExecutionStatus::Included => Ok(result),
112+
TxExecutionStatus::None | TxExecutionStatus::Included => Ok(result),
113113
_ => {
114114
ExecuteSignedTransaction::fetch_tx(
115115
network,
@@ -163,15 +163,16 @@ impl Signer {
163163

164164
// Locking until the transaction is sent
165165
let key = (network.network_name.clone(), account_id.clone(), public_key);
166-
let lock = self.get_sequential_nonce(key).await;
166+
let lock = self.get_nonce_cache(key).await;
167167
let mut nonce = lock.lock().await;
168168

169169
// It is important to fetch the nonce data after lock to get fresh block hash
170-
let (cached_nonce, block_hash, _) = Self::fetch_nonce_data(account_id, public_key, network)
171-
.await
172-
.map_err(MetaSignError::from)?;
170+
let (fetched_nonce, block_hash, _) =
171+
Self::fetch_nonce_data(account_id, public_key, network)
172+
.await
173+
.map_err(MetaSignError::from)?;
173174

174-
*nonce = (*nonce).max(cached_nonce) + 1;
175+
*nonce = (*nonce).max(fetched_nonce) + 1;
175176

176177
let signed = self
177178
.sign(transaction, public_key, *nonce, block_hash)
@@ -198,16 +199,16 @@ impl Signer {
198199

199200
// Locking until the transaction is sent
200201
let key = (network.network_name.clone(), account_id.clone(), public_key);
201-
let lock = self.get_sequential_nonce(key).await;
202+
let lock = self.get_nonce_cache(key).await;
202203
let mut nonce = lock.lock().await;
203204

204205
// It is important to fetch the nonce data after lock to get fresh block hash
205-
let (cached_nonce, block_hash, block_height) =
206+
let (fetched_nonce, block_hash, block_height) =
206207
Self::fetch_nonce_data(account_id, public_key, network)
207208
.await
208209
.map_err(MetaSignError::from)?;
209210

210-
*nonce = (*nonce).max(cached_nonce) + 1;
211+
*nonce = (*nonce).max(fetched_nonce) + 1;
211212

212213
let signed = self
213214
.sign_meta(

0 commit comments

Comments
 (0)