From 4ce92d746def19e8de8ce206c4005ec608e0fb60 Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Mon, 21 Oct 2024 17:39:49 +1100 Subject: [PATCH] remove lastSeenNonce Internal nonce tracking is no longer needed since populate/sendTransaction is now locked. Even if cancelled midway, the nonce will get a refreshed value from the number of transactions from chain. --- ethers/contract.nim | 2 +- ethers/providers/jsonrpc.nim | 2 -- ethers/signer.nim | 25 ++----------------------- ethers/signers/wallet.nim | 2 -- 4 files changed, 3 insertions(+), 28 deletions(-) diff --git a/ethers/contract.nim b/ethers/contract.nim index 4cd0028..09f180e 100644 --- a/ethers/contract.nim +++ b/ethers/contract.nim @@ -125,7 +125,7 @@ proc send(contract: Contract, function: string, parameters: tuple, overrides = TransactionOverrides()): - Future[?TransactionResponse] {.async.} = + Future[?TransactionResponse] {.async: (raises: [AsyncLockError]).} = if signer =? contract.signer: var params: seq[string] = @[] diff --git a/ethers/providers/jsonrpc.nim b/ethers/providers/jsonrpc.nim index 33442f8..b1e653e 100644 --- a/ethers/providers/jsonrpc.nim +++ b/ethers/providers/jsonrpc.nim @@ -327,8 +327,6 @@ method sendTransaction*( {.async: (raises:[SignerError, ProviderError]).} = convertError: - if nonce =? transaction.nonce: - signer.updateNonce(nonce) let client = await signer.provider.client hash = await client.eth_sendTransaction(transaction) diff --git a/ethers/signer.nim b/ethers/signer.nim index 2e54dcb..86e9093 100644 --- a/ethers/signer.nim +++ b/ethers/signer.nim @@ -8,7 +8,6 @@ export basics type Signer* = ref object of RootObj - lastSeenNonce: ?UInt256 populateLock: AsyncLock SignerError* = object of EthersError @@ -93,28 +92,10 @@ template withLock*(signer: Signer, body: untyped) = finally: signer.populateLock.release() - - -method updateNonce*( - signer: Signer, - nonce: UInt256 -) {.base, gcsafe.} = - - without lastSeen =? signer.lastSeenNonce: - signer.lastSeenNonce = some nonce - return - - if nonce > lastSeen: - signer.lastSeenNonce = some nonce - -method decreaseNonce*(signer: Signer) {.base, gcsafe.} = - if lastSeen =? signer.lastSeenNonce and lastSeen > 0: - signer.lastSeenNonce = some lastSeen - 1 - method populateTransaction*( signer: Signer, transaction: Transaction): Future[Transaction] - {.base, async: (raises: [CancelledError, AsyncLockError, ProviderError, SignerError]).} = + {.base, async: (raises: [CancelledError, ProviderError, SignerError]).} = ## Populates a transaction with sender, chainId, gasPrice, nonce, and gasLimit. ## NOTE: to avoid async concurrency issues, this routine should be called with ## a lock if it is followed by sendTransaction. For reference, see the `send` @@ -147,10 +128,8 @@ method populateTransaction*( try: populated.gasLimit = some(await signer.estimateGas(populated, BlockTag.pending)) except EstimateGasError as e: - signer.decreaseNonce() raise e except ProviderError as e: - signer.decreaseNonce() raiseSignerError(e.msg) else: @@ -165,7 +144,7 @@ method populateTransaction*( method cancelTransaction*( signer: Signer, tx: Transaction -): Future[TransactionResponse] {.base, async: (raises: [SignerError, ProviderError]).} = +): Future[TransactionResponse] {.base, async: (raises: [SignerError, CancelledError, AsyncLockError, ProviderError]).} = # cancels a transaction by sending with a 0-valued transaction to ourselves # with the failed tx's nonce diff --git a/ethers/signers/wallet.nim b/ethers/signers/wallet.nim index edc2254..752ae25 100644 --- a/ethers/signers/wallet.nim +++ b/ethers/signers/wallet.nim @@ -86,6 +86,4 @@ method sendTransaction*( {.async: (raises:[SignerError, ProviderError]).} = let signed = await signTransaction(wallet, transaction) - if nonce =? transaction.nonce: - wallet.updateNonce(nonce) return await provider(wallet).sendTransaction(signed)