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
a2b595c3
Unverified
Commit
a2b595c3
authored
Aug 30, 2023
by
Adrian Sutton
Committed by
GitHub
Aug 30, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7022 from conduitxyz/txmgr-reuse
Allow passing Config and Value to TxMgr
parents
efa6313d
60c3439b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
1 deletion
+52
-1
cli.go
op-service/txmgr/cli.go
+31
-0
txmgr.go
op-service/txmgr/txmgr.go
+11
-0
txmgr_test.go
op-service/txmgr/txmgr_test.go
+10
-1
No files found.
op-service/txmgr/cli.go
View file @
a2b595c3
...
...
@@ -290,3 +290,34 @@ type Config struct {
Signer
opcrypto
.
SignerFn
From
common
.
Address
}
func
(
m
Config
)
Check
()
error
{
if
m
.
Backend
==
nil
{
return
errors
.
New
(
"must provide the Backend"
)
}
if
m
.
NumConfirmations
==
0
{
return
errors
.
New
(
"NumConfirmations must not be 0"
)
}
if
m
.
NetworkTimeout
==
0
{
return
errors
.
New
(
"must provide NetworkTimeout"
)
}
if
m
.
ResubmissionTimeout
==
0
{
return
errors
.
New
(
"must provide ResubmissionTimeout"
)
}
if
m
.
ReceiptQueryInterval
==
0
{
return
errors
.
New
(
"must provide ReceiptQueryInterval"
)
}
if
m
.
TxNotInMempoolTimeout
==
0
{
return
errors
.
New
(
"must provide TxNotInMempoolTimeout"
)
}
if
m
.
SafeAbortNonceTooLowCount
==
0
{
return
errors
.
New
(
"SafeAbortNonceTooLowCount must not be 0"
)
}
if
m
.
Signer
==
nil
{
return
errors
.
New
(
"must provide the Signer"
)
}
if
m
.
ChainID
==
nil
{
return
errors
.
New
(
"must provide the ChainID"
)
}
return
nil
}
op-service/txmgr/txmgr.go
View file @
a2b595c3
...
...
@@ -112,7 +112,14 @@ func NewSimpleTxManager(name string, l log.Logger, m metrics.TxMetricer, cfg CLI
if
err
!=
nil
{
return
nil
,
err
}
return
NewSimpleTxManagerFromConfig
(
name
,
l
,
m
,
conf
)
}
// NewSimpleTxManager initializes a new SimpleTxManager with the passed Config.
func
NewSimpleTxManagerFromConfig
(
name
string
,
l
log
.
Logger
,
m
metrics
.
TxMetricer
,
conf
Config
)
(
*
SimpleTxManager
,
error
)
{
if
err
:=
conf
.
Check
();
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid config: %w"
,
err
)
}
return
&
SimpleTxManager
{
chainID
:
conf
.
ChainID
,
name
:
name
,
...
...
@@ -140,6 +147,8 @@ type TxCandidate struct {
To
*
common
.
Address
// GasLimit is the gas limit to be used in the constructed tx.
GasLimit
uint64
// Value is the value to be used in the constructed tx.
Value
*
big
.
Int
}
// Send is used to publish a transaction with incrementally higher gas prices
...
...
@@ -214,6 +223,7 @@ func (m *SimpleTxManager) craftTx(ctx context.Context, candidate TxCandidate) (*
GasTipCap
:
gasTipCap
,
GasFeeCap
:
gasFeeCap
,
Data
:
candidate
.
TxData
,
Value
:
candidate
.
Value
,
}
m
.
l
.
Info
(
"Creating tx"
,
"to"
,
rawTx
.
To
,
"from"
,
m
.
cfg
.
From
)
...
...
@@ -229,6 +239,7 @@ func (m *SimpleTxManager) craftTx(ctx context.Context, candidate TxCandidate) (*
GasFeeCap
:
gasFeeCap
,
GasTipCap
:
gasTipCap
,
Data
:
rawTx
.
Data
,
Value
:
rawTx
.
Value
,
})
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to estimate gas: %w"
,
err
)
...
...
op-service/txmgr/txmgr_test.go
View file @
a2b595c3
...
...
@@ -603,12 +603,21 @@ func TestWaitMinedMultipleConfs(t *testing.T) {
require
.
Equal
(
t
,
txHash
,
receipt
.
TxHash
)
}
// TestManagerErrsOnZeroCLIConfs ensures that the NewSimpleTxManager will error
// when attempting to configure with NumConfirmations set to zero.
func
TestManagerErrsOnZeroCLIConfs
(
t
*
testing
.
T
)
{
t
.
Parallel
()
_
,
err
:=
NewSimpleTxManager
(
"TEST"
,
testlog
.
Logger
(
t
,
log
.
LvlCrit
),
&
metrics
.
NoopTxMetrics
{},
CLIConfig
{})
require
.
Error
(
t
,
err
)
}
// TestManagerErrsOnZeroConfs ensures that the NewSimpleTxManager will error
// when attempting to configure with NumConfirmations set to zero.
func
TestManagerErrsOnZeroConfs
(
t
*
testing
.
T
)
{
t
.
Parallel
()
_
,
err
:=
NewSimpleTxManager
(
"TEST"
,
testlog
.
Logger
(
t
,
log
.
LvlCrit
),
&
metrics
.
NoopTxMetrics
{},
CLI
Config
{})
_
,
err
:=
NewSimpleTxManager
FromConfig
(
"TEST"
,
testlog
.
Logger
(
t
,
log
.
LvlCrit
),
&
metrics
.
NoopTxMetrics
{},
Config
{})
require
.
Error
(
t
,
err
)
}
...
...
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