Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
18d87e2a
Unverified
Commit
18d87e2a
authored
Oct 21, 2023
by
Michael de Hoog
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid incrementing the txmgr nonce if tx signing fails
parent
bc8a1da1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
18 deletions
+18
-18
txmgr.go
op-service/txmgr/txmgr.go
+18
-18
No files found.
op-service/txmgr/txmgr.go
View file @
18d87e2a
...
...
@@ -238,23 +238,15 @@ func (m *SimpleTxManager) craftTx(ctx context.Context, candidate TxCandidate) (*
rawTx
.
Gas
=
gas
}
// Avoid bumping the nonce if the gas estimation fails.
nonce
,
err
:=
m
.
nextNonce
(
ctx
)
if
err
!=
nil
{
return
nil
,
err
}
rawTx
.
Nonce
=
nonce
ctx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
m
.
cfg
.
NetworkTimeout
)
defer
cancel
()
return
m
.
cfg
.
Signer
(
ctx
,
m
.
cfg
.
From
,
types
.
NewTx
(
rawTx
))
return
m
.
signWithNextNonce
(
ctx
,
rawTx
)
}
// nextNonce returns a nonce to use for the next transaction. It uses
// eth_getTransactionCount with "latest" once, and then subsequent calls simply
// increment this number. If the transaction manager is reset, it will query the
// eth_getTransactionCount nonce again.
func
(
m
*
SimpleTxManager
)
nextNonce
(
ctx
context
.
Context
)
(
uint64
,
error
)
{
// signWithNextNonce returns a signed transaction with the next available nonce.
// The nonce is fetched once using eth_getTransactionCount with "latest", and
// then subsequent calls simply increment this number. If the transaction manager
// is reset, it will query the eth_getTransactionCount nonce again. If signing
// fails, the nonce is not incremented.
func
(
m
*
SimpleTxManager
)
signWithNextNonce
(
ctx
context
.
Context
,
rawTx
*
types
.
DynamicFeeTx
)
(
*
types
.
Transaction
,
error
)
{
m
.
nonceLock
.
Lock
()
defer
m
.
nonceLock
.
Unlock
()
...
...
@@ -265,15 +257,23 @@ func (m *SimpleTxManager) nextNonce(ctx context.Context) (uint64, error) {
nonce
,
err
:=
m
.
backend
.
NonceAt
(
childCtx
,
m
.
cfg
.
From
,
nil
)
if
err
!=
nil
{
m
.
metr
.
RPCError
()
return
0
,
fmt
.
Errorf
(
"failed to get nonce: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to get nonce: %w"
,
err
)
}
m
.
nonce
=
&
nonce
}
else
{
*
m
.
nonce
++
}
m
.
metr
.
RecordNonce
(
*
m
.
nonce
)
return
*
m
.
nonce
,
nil
rawTx
.
Nonce
=
*
m
.
nonce
tx
,
err
:=
m
.
cfg
.
Signer
(
ctx
,
m
.
cfg
.
From
,
types
.
NewTx
(
rawTx
))
if
err
!=
nil
{
// decrement the nonce, so we can retry signing with the same nonce next time
// signWithNextNonce is called
*
m
.
nonce
--
}
else
{
m
.
metr
.
RecordNonce
(
*
m
.
nonce
)
}
return
tx
,
err
}
// resetNonce resets the internal nonce tracking. This is called if any pending send
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment