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
e354d5e7
Commit
e354d5e7
authored
Mar 23, 2023
by
Joshua Gutow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
txmgr: Change API to use TxCandidate in send
parent
0446d83b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
55 deletions
+32
-55
TxManager.go
op-service/txmgr/mocks/TxManager.go
+7
-33
txmgr.go
op-service/txmgr/txmgr.go
+16
-13
txmgr_test.go
op-service/txmgr/txmgr_test.go
+9
-9
No files found.
op-service/txmgr/mocks/TxManager.go
View file @
e354d5e7
// Code generated by mockery v2.2
2
.1. DO NOT EDIT.
// Code generated by mockery v2.2
3
.1. DO NOT EDIT.
package
mocks
...
...
@@ -16,20 +16,20 @@ type TxManager struct {
mock
.
Mock
}
//
CraftTx
provides a mock function with given fields: ctx, candidate
func
(
_m
*
TxManager
)
CraftTx
(
ctx
context
.
Context
,
candidate
txmgr
.
TxCandidate
)
(
*
types
.
Transaction
,
error
)
{
//
Send
provides a mock function with given fields: ctx, candidate
func
(
_m
*
TxManager
)
Send
(
ctx
context
.
Context
,
candidate
txmgr
.
TxCandidate
)
(
*
types
.
Receipt
,
error
)
{
ret
:=
_m
.
Called
(
ctx
,
candidate
)
var
r0
*
types
.
Transaction
var
r0
*
types
.
Receipt
var
r1
error
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
context
.
Context
,
txmgr
.
TxCandidate
)
(
*
types
.
Transaction
,
error
));
ok
{
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
context
.
Context
,
txmgr
.
TxCandidate
)
(
*
types
.
Receipt
,
error
));
ok
{
return
rf
(
ctx
,
candidate
)
}
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
context
.
Context
,
txmgr
.
TxCandidate
)
*
types
.
Transaction
);
ok
{
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
context
.
Context
,
txmgr
.
TxCandidate
)
*
types
.
Receipt
);
ok
{
r0
=
rf
(
ctx
,
candidate
)
}
else
{
if
ret
.
Get
(
0
)
!=
nil
{
r0
=
ret
.
Get
(
0
)
.
(
*
types
.
Transaction
)
r0
=
ret
.
Get
(
0
)
.
(
*
types
.
Receipt
)
}
}
...
...
@@ -42,32 +42,6 @@ func (_m *TxManager) CraftTx(ctx context.Context, candidate txmgr.TxCandidate) (
return
r0
,
r1
}
// Send provides a mock function with given fields: ctx, tx
func
(
_m
*
TxManager
)
Send
(
ctx
context
.
Context
,
tx
*
types
.
Transaction
)
(
*
types
.
Receipt
,
error
)
{
ret
:=
_m
.
Called
(
ctx
,
tx
)
var
r0
*
types
.
Receipt
var
r1
error
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
context
.
Context
,
*
types
.
Transaction
)
(
*
types
.
Receipt
,
error
));
ok
{
return
rf
(
ctx
,
tx
)
}
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
context
.
Context
,
*
types
.
Transaction
)
*
types
.
Receipt
);
ok
{
r0
=
rf
(
ctx
,
tx
)
}
else
{
if
ret
.
Get
(
0
)
!=
nil
{
r0
=
ret
.
Get
(
0
)
.
(
*
types
.
Receipt
)
}
}
if
rf
,
ok
:=
ret
.
Get
(
1
)
.
(
func
(
context
.
Context
,
*
types
.
Transaction
)
error
);
ok
{
r1
=
rf
(
ctx
,
tx
)
}
else
{
r1
=
ret
.
Error
(
1
)
}
return
r0
,
r1
}
type
mockConstructorTestingTNewTxManager
interface
{
mock
.
TestingT
Cleanup
(
func
())
...
...
op-service/txmgr/txmgr.go
View file @
e354d5e7
...
...
@@ -74,18 +74,13 @@ type Config struct {
//
//go:generate mockery --name TxManager --output ./mocks
type
TxManager
interface
{
// Send is used to publish a transaction with incrementally higher gas
// prices until the transaction eventually confirms. This method blocks
// until an invocation of sendTx returns (called with differing gas
// prices). The method may be canceled using the passed context.
//
// The initial transaction MUST be signed & ready to submit.
// Send is used to create & send a transaction. It will handle increasing
// the gas price & ensuring that the transaction remains in the transaction pool.
// It can be stopped by cancelling the provided context; however, the transaction
// may be included on L1 even if the context is cancelled.
//
// NOTE: Send should be called by AT MOST one caller at a time.
Send
(
ctx
context
.
Context
,
tx
*
types
.
Transaction
)
(
*
types
.
Receipt
,
error
)
// CraftTx is used to craft a transaction using a [TxCandidate].
CraftTx
(
ctx
context
.
Context
,
candidate
TxCandidate
)
(
*
types
.
Transaction
,
error
)
Send
(
ctx
context
.
Context
,
candidate
TxCandidate
)
(
*
types
.
Receipt
,
error
)
}
// ETHBackend is the set of methods that the transaction manager uses to resubmit gas & determine
...
...
@@ -166,12 +161,12 @@ func (m *SimpleTxManager) calcGasTipAndFeeCap(ctx context.Context) (gasTipCap *b
return
gasTipCap
,
gasFeeCap
,
nil
}
//
CraftTx creates the signed transaction to the batchInboxAddress.
//
craftTx creates the signed transaction
// It queries L1 for the current fee market conditions as well as for the nonce.
// NOTE: This method SHOULD NOT publish the resulting transaction.
// NOTE: If the [TxCandidate.GasLimit] is non-zero, it will be used as the transaction's gas.
// NOTE: Otherwise, the [SimpleTxManager] will query the specified backend for an estimate.
func
(
m
*
SimpleTxManager
)
C
raftTx
(
ctx
context
.
Context
,
candidate
TxCandidate
)
(
*
types
.
Transaction
,
error
)
{
func
(
m
*
SimpleTxManager
)
c
raftTx
(
ctx
context
.
Context
,
candidate
TxCandidate
)
(
*
types
.
Transaction
,
error
)
{
gasTipCap
,
gasFeeCap
,
err
:=
m
.
calcGasTipAndFeeCap
(
ctx
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -337,8 +332,16 @@ func NewSimpleTxManager(name string, l log.Logger, cfg Config, backend ETHBacken
// but retain the gas used, the nonce, and the data.
//
// NOTE: Send should be called by AT MOST one caller at a time.
func
(
m
*
SimpleTxManager
)
Send
(
ctx
context
.
Context
,
tx
*
types
.
Transaction
)
(
*
types
.
Receipt
,
error
)
{
func
(
m
*
SimpleTxManager
)
Send
(
ctx
context
.
Context
,
candidate
TxCandidate
)
(
*
types
.
Receipt
,
error
)
{
tx
,
err
:=
m
.
craftTx
(
ctx
,
candidate
)
if
err
!=
nil
{
m
.
l
.
Error
(
"Failed to create the transaction"
,
"err"
,
err
)
return
nil
,
err
}
return
m
.
send
(
ctx
,
tx
)
}
func
(
m
*
SimpleTxManager
)
send
(
ctx
context
.
Context
,
tx
*
types
.
Transaction
)
(
*
types
.
Receipt
,
error
)
{
// Initialize a wait group to track any spawned goroutines, and ensure
// we properly clean up any dangling resources this method generates.
// We assert that this is the case thoroughly in our unit tests.
...
...
op-service/txmgr/txmgr_test.go
View file @
e354d5e7
...
...
@@ -261,7 +261,7 @@ func TestTxMgrConfirmAtMinGasPrice(t *testing.T) {
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
defer
cancel
()
receipt
,
err
:=
h
.
mgr
.
S
end
(
ctx
,
tx
)
receipt
,
err
:=
h
.
mgr
.
s
end
(
ctx
,
tx
)
require
.
Nil
(
t
,
err
)
require
.
NotNil
(
t
,
receipt
)
require
.
Equal
(
t
,
gasPricer
.
expGasFeeCap
()
.
Uint64
(),
receipt
.
GasUsed
)
...
...
@@ -289,7 +289,7 @@ func TestTxMgrNeverConfirmCancel(t *testing.T) {
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
defer
cancel
()
receipt
,
err
:=
h
.
mgr
.
S
end
(
ctx
,
tx
)
receipt
,
err
:=
h
.
mgr
.
s
end
(
ctx
,
tx
)
require
.
Equal
(
t
,
err
,
context
.
DeadlineExceeded
)
require
.
Nil
(
t
,
receipt
)
}
...
...
@@ -318,7 +318,7 @@ func TestTxMgrConfirmsAtHigherGasPrice(t *testing.T) {
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
defer
cancel
()
receipt
,
err
:=
h
.
mgr
.
S
end
(
ctx
,
tx
)
receipt
,
err
:=
h
.
mgr
.
s
end
(
ctx
,
tx
)
require
.
Nil
(
t
,
err
)
require
.
NotNil
(
t
,
receipt
)
require
.
Equal
(
t
,
h
.
gasPricer
.
expGasFeeCap
()
.
Uint64
(),
receipt
.
GasUsed
)
...
...
@@ -349,7 +349,7 @@ func TestTxMgrBlocksOnFailingRpcCalls(t *testing.T) {
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
defer
cancel
()
receipt
,
err
:=
h
.
mgr
.
S
end
(
ctx
,
tx
)
receipt
,
err
:=
h
.
mgr
.
s
end
(
ctx
,
tx
)
require
.
Equal
(
t
,
err
,
context
.
DeadlineExceeded
)
require
.
Nil
(
t
,
receipt
)
}
...
...
@@ -362,7 +362,7 @@ func TestTxMgr_CraftTx(t *testing.T) {
// Craft the transaction.
gasTipCap
,
gasFeeCap
:=
h
.
gasPricer
.
feesForEpoch
(
h
.
gasPricer
.
epoch
+
1
)
tx
,
err
:=
h
.
mgr
.
C
raftTx
(
context
.
Background
(),
candidate
)
tx
,
err
:=
h
.
mgr
.
c
raftTx
(
context
.
Background
(),
candidate
)
require
.
Nil
(
t
,
err
)
require
.
NotNil
(
t
,
tx
)
...
...
@@ -391,7 +391,7 @@ func TestTxMgr_EstimateGas(t *testing.T) {
gasEstimate
:=
h
.
gasPricer
.
baseBaseFee
.
Uint64
()
// Craft the transaction.
tx
,
err
:=
h
.
mgr
.
C
raftTx
(
context
.
Background
(),
candidate
)
tx
,
err
:=
h
.
mgr
.
c
raftTx
(
context
.
Background
(),
candidate
)
require
.
Nil
(
t
,
err
)
require
.
NotNil
(
t
,
tx
)
...
...
@@ -427,7 +427,7 @@ func TestTxMgrOnlyOnePublicationSucceeds(t *testing.T) {
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
defer
cancel
()
receipt
,
err
:=
h
.
mgr
.
S
end
(
ctx
,
tx
)
receipt
,
err
:=
h
.
mgr
.
s
end
(
ctx
,
tx
)
require
.
Nil
(
t
,
err
)
require
.
NotNil
(
t
,
receipt
)
...
...
@@ -462,7 +462,7 @@ func TestTxMgrConfirmsMinGasPriceAfterBumping(t *testing.T) {
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
defer
cancel
()
receipt
,
err
:=
h
.
mgr
.
S
end
(
ctx
,
tx
)
receipt
,
err
:=
h
.
mgr
.
s
end
(
ctx
,
tx
)
require
.
Nil
(
t
,
err
)
require
.
NotNil
(
t
,
receipt
)
require
.
Equal
(
t
,
h
.
gasPricer
.
expGasFeeCap
()
.
Uint64
(),
receipt
.
GasUsed
)
...
...
@@ -507,7 +507,7 @@ func TestTxMgrDoesntAbortNonceTooLowAfterMiningTx(t *testing.T) {
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
defer
cancel
()
receipt
,
err
:=
h
.
mgr
.
S
end
(
ctx
,
tx
)
receipt
,
err
:=
h
.
mgr
.
s
end
(
ctx
,
tx
)
require
.
Nil
(
t
,
err
)
require
.
NotNil
(
t
,
receipt
)
require
.
Equal
(
t
,
h
.
gasPricer
.
expGasFeeCap
()
.
Uint64
(),
receipt
.
GasUsed
)
...
...
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