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
3d632f70
Unverified
Commit
3d632f70
authored
Apr 18, 2023
by
Michael de Hoog
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove concurrent resets from txmgr
parent
6a2d3381
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
50 deletions
+12
-50
txmgr.go
op-service/txmgr/txmgr.go
+12
-50
No files found.
op-service/txmgr/txmgr.go
View file @
3d632f70
...
@@ -4,8 +4,6 @@ import (
...
@@ -4,8 +4,6 @@ import (
"context"
"context"
"errors"
"errors"
"fmt"
"fmt"
"sync/atomic"
"math/big"
"math/big"
"strings"
"strings"
"sync"
"sync"
...
@@ -89,11 +87,7 @@ type SimpleTxManager struct {
...
@@ -89,11 +87,7 @@ type SimpleTxManager struct {
metr
metrics
.
TxMetricer
metr
metrics
.
TxMetricer
nonce
*
uint64
nonce
*
uint64
lock
sync
.
RWMutex
nonceLock
sync
.
RWMutex
wg
sync
.
WaitGroup
resetC
chan
struct
{}
resetWG
sync
.
WaitGroup
resetting
atomic
.
Bool
}
}
// NewSimpleTxManager initializes a new SimpleTxManager with the passed Config.
// NewSimpleTxManager initializes a new SimpleTxManager with the passed Config.
...
@@ -110,7 +104,6 @@ func NewSimpleTxManager(name string, l log.Logger, m metrics.TxMetricer, cfg CLI
...
@@ -110,7 +104,6 @@ func NewSimpleTxManager(name string, l log.Logger, m metrics.TxMetricer, cfg CLI
backend
:
conf
.
Backend
,
backend
:
conf
.
Backend
,
l
:
l
.
New
(
"service"
,
name
),
l
:
l
.
New
(
"service"
,
name
),
metr
:
m
,
metr
:
m
,
resetC
:
make
(
chan
struct
{}),
},
nil
},
nil
}
}
...
@@ -139,50 +132,15 @@ type TxCandidate struct {
...
@@ -139,50 +132,15 @@ type TxCandidate struct {
//
//
// NOTE: Send can be called concurrently, the nonce will be managed internally.
// NOTE: Send can be called concurrently, the nonce will be managed internally.
func
(
m
*
SimpleTxManager
)
Send
(
ctx
context
.
Context
,
candidate
TxCandidate
)
(
*
types
.
Receipt
,
error
)
{
func
(
m
*
SimpleTxManager
)
Send
(
ctx
context
.
Context
,
candidate
TxCandidate
)
(
*
types
.
Receipt
,
error
)
{
m
.
resetWG
.
Wait
()
// wait for any current resets
receipt
,
err
:=
m
.
send
(
ctx
,
candidate
)
receipt
,
err
:=
m
.
send
(
ctx
,
candidate
)
if
err
!=
nil
{
if
err
!=
nil
{
m
.
reset
()
m
.
reset
Nonce
()
}
}
return
receipt
,
err
return
receipt
,
err
}
}
// reset the transaction manager. All currently pending transactions will receive
// a ResetErr error. This is called if any pending send returns an error.
func
(
m
*
SimpleTxManager
)
reset
()
{
m
.
resetWG
.
Add
(
1
)
defer
m
.
resetWG
.
Done
()
if
m
.
resetting
.
Swap
(
true
)
{
// already resetting
return
}
close
(
m
.
getResetChannel
())
m
.
wg
.
Wait
()
m
.
lock
.
Lock
()
defer
m
.
lock
.
Unlock
()
m
.
nonce
=
nil
m
.
resetC
=
make
(
chan
struct
{})
m
.
resetting
.
Store
(
false
)
}
// getResetChannel is a thread-safe getter for the channel that is closed upon
// transaction manager resets.
func
(
m
*
SimpleTxManager
)
getResetChannel
()
chan
struct
{}
{
m
.
lock
.
RLock
()
defer
m
.
lock
.
RUnlock
()
return
m
.
resetC
}
// send performs the actual transaction creation and sending.
// send performs the actual transaction creation and sending.
func
(
m
*
SimpleTxManager
)
send
(
ctx
context
.
Context
,
candidate
TxCandidate
)
(
*
types
.
Receipt
,
error
)
{
func
(
m
*
SimpleTxManager
)
send
(
ctx
context
.
Context
,
candidate
TxCandidate
)
(
*
types
.
Receipt
,
error
)
{
m
.
wg
.
Add
(
1
)
defer
m
.
wg
.
Done
()
if
m
.
cfg
.
TxSendTimeout
!=
0
{
if
m
.
cfg
.
TxSendTimeout
!=
0
{
var
cancel
context
.
CancelFunc
var
cancel
context
.
CancelFunc
ctx
,
cancel
=
context
.
WithTimeout
(
ctx
,
m
.
cfg
.
TxSendTimeout
)
ctx
,
cancel
=
context
.
WithTimeout
(
ctx
,
m
.
cfg
.
TxSendTimeout
)
...
@@ -252,8 +210,8 @@ func (m *SimpleTxManager) craftTx(ctx context.Context, candidate TxCandidate) (*
...
@@ -252,8 +210,8 @@ func (m *SimpleTxManager) craftTx(ctx context.Context, candidate TxCandidate) (*
// increment this number. If the transaction manager is reset, it will query the
// increment this number. If the transaction manager is reset, it will query the
// eth_getTransactionCount nonce again.
// eth_getTransactionCount nonce again.
func
(
m
*
SimpleTxManager
)
nextNonce
(
ctx
context
.
Context
)
(
uint64
,
error
)
{
func
(
m
*
SimpleTxManager
)
nextNonce
(
ctx
context
.
Context
)
(
uint64
,
error
)
{
m
.
l
ock
.
Lock
()
m
.
nonceL
ock
.
Lock
()
defer
m
.
l
ock
.
Unlock
()
defer
m
.
nonceL
ock
.
Unlock
()
if
m
.
nonce
==
nil
{
if
m
.
nonce
==
nil
{
// Fetch the sender's nonce from the latest known block (nil `blockNumber`)
// Fetch the sender's nonce from the latest known block (nil `blockNumber`)
...
@@ -273,6 +231,14 @@ func (m *SimpleTxManager) nextNonce(ctx context.Context) (uint64, error) {
...
@@ -273,6 +231,14 @@ func (m *SimpleTxManager) nextNonce(ctx context.Context) (uint64, error) {
return
*
m
.
nonce
,
nil
return
*
m
.
nonce
,
nil
}
}
// resetNonce resets the internal nonce tracking. This is called if any pending send
// returns an error.
func
(
m
*
SimpleTxManager
)
resetNonce
()
{
m
.
nonceLock
.
Lock
()
defer
m
.
nonceLock
.
Unlock
()
m
.
nonce
=
nil
}
// send submits the same transaction several times with increasing gas prices as necessary.
// send submits the same transaction several times with increasing gas prices as necessary.
// It waits for the transaction to be confirmed on chain.
// It waits for the transaction to be confirmed on chain.
func
(
m
*
SimpleTxManager
)
sendTx
(
ctx
context
.
Context
,
tx
*
types
.
Transaction
)
(
*
types
.
Receipt
,
error
)
{
func
(
m
*
SimpleTxManager
)
sendTx
(
ctx
context
.
Context
,
tx
*
types
.
Transaction
)
(
*
types
.
Receipt
,
error
)
{
...
@@ -294,7 +260,6 @@ func (m *SimpleTxManager) sendTx(ctx context.Context, tx *types.Transaction) (*t
...
@@ -294,7 +260,6 @@ func (m *SimpleTxManager) sendTx(ctx context.Context, tx *types.Transaction) (*t
ticker
:=
time
.
NewTicker
(
m
.
cfg
.
ResubmissionTimeout
)
ticker
:=
time
.
NewTicker
(
m
.
cfg
.
ResubmissionTimeout
)
defer
ticker
.
Stop
()
defer
ticker
.
Stop
()
resetChan
:=
m
.
getResetChannel
()
bumpCounter
:=
0
bumpCounter
:=
0
for
{
for
{
...
@@ -318,9 +283,6 @@ func (m *SimpleTxManager) sendTx(ctx context.Context, tx *types.Transaction) (*t
...
@@ -318,9 +283,6 @@ func (m *SimpleTxManager) sendTx(ctx context.Context, tx *types.Transaction) (*t
case
<-
ctx
.
Done
()
:
case
<-
ctx
.
Done
()
:
return
nil
,
ctx
.
Err
()
return
nil
,
ctx
.
Err
()
case
<-
resetChan
:
return
nil
,
ResetErr
case
receipt
:=
<-
receiptChan
:
case
receipt
:=
<-
receiptChan
:
m
.
metr
.
RecordGasBumpCount
(
bumpCounter
)
m
.
metr
.
RecordGasBumpCount
(
bumpCounter
)
m
.
metr
.
TxConfirmed
(
receipt
)
m
.
metr
.
TxConfirmed
(
receipt
)
...
...
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