Skip to content

Commit bb14e83

Browse files
committed
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.
1 parent ba902eb commit bb14e83

File tree

4 files changed

+3
-28
lines changed

4 files changed

+3
-28
lines changed

ethers/contract.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ proc send(contract: Contract,
125125
function: string,
126126
parameters: tuple,
127127
overrides = TransactionOverrides()):
128-
Future[?TransactionResponse] {.async.} =
128+
Future[?TransactionResponse] {.async: (raises: [AsyncLockError]).} =
129129
if signer =? contract.signer:
130130

131131
var params: seq[string] = @[]

ethers/providers/jsonrpc.nim

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,6 @@ method sendTransaction*(
327327
{.async: (raises:[SignerError, ProviderError]).} =
328328

329329
convertError:
330-
if nonce =? transaction.nonce:
331-
signer.updateNonce(nonce)
332330
let
333331
client = await signer.provider.client
334332
hash = await client.eth_sendTransaction(transaction)

ethers/signer.nim

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export basics
88

99
type
1010
Signer* = ref object of RootObj
11-
lastSeenNonce: ?UInt256
1211
populateLock: AsyncLock
1312
SignerError* = object of EthersError
1413

@@ -93,28 +92,10 @@ template withLock*(signer: Signer, body: untyped) =
9392
finally:
9493
signer.populateLock.release()
9594

96-
97-
98-
method updateNonce*(
99-
signer: Signer,
100-
nonce: UInt256
101-
) {.base, gcsafe.} =
102-
103-
without lastSeen =? signer.lastSeenNonce:
104-
signer.lastSeenNonce = some nonce
105-
return
106-
107-
if nonce > lastSeen:
108-
signer.lastSeenNonce = some nonce
109-
110-
method decreaseNonce*(signer: Signer) {.base, gcsafe.} =
111-
if lastSeen =? signer.lastSeenNonce and lastSeen > 0:
112-
signer.lastSeenNonce = some lastSeen - 1
113-
11495
method populateTransaction*(
11596
signer: Signer,
11697
transaction: Transaction): Future[Transaction]
117-
{.base, async: (raises: [CancelledError, AsyncLockError, ProviderError, SignerError]).} =
98+
{.base, async: (raises: [CancelledError, ProviderError, SignerError]).} =
11899
## Populates a transaction with sender, chainId, gasPrice, nonce, and gasLimit.
119100
## NOTE: to avoid async concurrency issues, this routine should be called with
120101
## a lock if it is followed by sendTransaction. For reference, see the `send`
@@ -147,10 +128,8 @@ method populateTransaction*(
147128
try:
148129
populated.gasLimit = some(await signer.estimateGas(populated, BlockTag.pending))
149130
except EstimateGasError as e:
150-
signer.decreaseNonce()
151131
raise e
152132
except ProviderError as e:
153-
signer.decreaseNonce()
154133
raiseSignerError(e.msg)
155134

156135
else:
@@ -165,7 +144,7 @@ method populateTransaction*(
165144
method cancelTransaction*(
166145
signer: Signer,
167146
tx: Transaction
168-
): Future[TransactionResponse] {.base, async: (raises: [SignerError, ProviderError]).} =
147+
): Future[TransactionResponse] {.base, async: (raises: [SignerError, CancelledError, AsyncLockError, ProviderError]).} =
169148
# cancels a transaction by sending with a 0-valued transaction to ourselves
170149
# with the failed tx's nonce
171150

ethers/signers/wallet.nim

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,4 @@ method sendTransaction*(
8686
{.async: (raises:[SignerError, ProviderError]).} =
8787

8888
let signed = await signTransaction(wallet, transaction)
89-
if nonce =? transaction.nonce:
90-
wallet.updateNonce(nonce)
9189
return await provider(wallet).sendTransaction(signed)

0 commit comments

Comments
 (0)