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
c861fa43
Unverified
Commit
c861fa43
authored
Nov 22, 2021
by
Conner Fromknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: enchance txmgr logging
parent
2d192f51
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
6 deletions
+19
-6
txmgr.go
go/batch-submitter/txmgr/txmgr.go
+18
-5
txmgr_test.go
go/batch-submitter/txmgr/txmgr_test.go
+1
-1
No files found.
go/batch-submitter/txmgr/txmgr.go
View file @
c861fa43
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"context"
"context"
"errors"
"errors"
"math/big"
"math/big"
"strings"
"sync"
"sync"
"time"
"time"
...
@@ -25,6 +26,8 @@ type SendTxFunc = func(
...
@@ -25,6 +26,8 @@ type SendTxFunc = func(
// Config houses parameters for altering the behavior of a SimpleTxManager.
// Config houses parameters for altering the behavior of a SimpleTxManager.
type
Config
struct
{
type
Config
struct
{
Name
string
// MinGasPrice is the minimum gas price (in gwei). This is used as the
// MinGasPrice is the minimum gas price (in gwei). This is used as the
// initial publication attempt.
// initial publication attempt.
MinGasPrice
*
big
.
Int
MinGasPrice
*
big
.
Int
...
@@ -78,13 +81,17 @@ type ReceiptSource interface {
...
@@ -78,13 +81,17 @@ type ReceiptSource interface {
// SimpleTxManager is a implementation of TxManager that performs linear fee
// SimpleTxManager is a implementation of TxManager that performs linear fee
// bumping of a tx until it confirms.
// bumping of a tx until it confirms.
type
SimpleTxManager
struct
{
type
SimpleTxManager
struct
{
name
string
cfg
Config
cfg
Config
backend
ReceiptSource
backend
ReceiptSource
}
}
// NewSimpleTxManager initializes a new SimpleTxManager with the passed Config.
// NewSimpleTxManager initializes a new SimpleTxManager with the passed Config.
func
NewSimpleTxManager
(
cfg
Config
,
backend
ReceiptSource
)
*
SimpleTxManager
{
func
NewSimpleTxManager
(
name
string
,
cfg
Config
,
backend
ReceiptSource
)
*
SimpleTxManager
{
return
&
SimpleTxManager
{
return
&
SimpleTxManager
{
name
:
name
,
cfg
:
cfg
,
cfg
:
cfg
,
backend
:
backend
,
backend
:
backend
,
}
}
...
@@ -99,6 +106,8 @@ func NewSimpleTxManager(cfg Config, backend ReceiptSource) *SimpleTxManager {
...
@@ -99,6 +106,8 @@ func NewSimpleTxManager(cfg Config, backend ReceiptSource) *SimpleTxManager {
func
(
m
*
SimpleTxManager
)
Send
(
func
(
m
*
SimpleTxManager
)
Send
(
ctx
context
.
Context
,
sendTx
SendTxFunc
)
(
*
types
.
Receipt
,
error
)
{
ctx
context
.
Context
,
sendTx
SendTxFunc
)
(
*
types
.
Receipt
,
error
)
{
name
:=
m
.
name
// Initialize a wait group to track any spawned goroutines, and ensure
// Initialize a wait group to track any spawned goroutines, and ensure
// we properly clean up any dangling resources this method generates.
// we properly clean up any dangling resources this method generates.
// We assert that this is the case thoroughly in our unit tests.
// We assert that this is the case thoroughly in our unit tests.
...
@@ -121,14 +130,18 @@ func (m *SimpleTxManager) Send(
...
@@ -121,14 +130,18 @@ func (m *SimpleTxManager) Send(
// Sign and publish transaction with current gas price.
// Sign and publish transaction with current gas price.
tx
,
err
:=
sendTx
(
ctxc
,
gasPrice
)
tx
,
err
:=
sendTx
(
ctxc
,
gasPrice
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
"Unable to publish transaction"
,
if
err
==
context
.
Canceled
||
strings
.
Contains
(
err
.
Error
(),
"context canceled"
)
{
return
}
log
.
Error
(
name
+
" unable to publish transaction"
,
"gas_price"
,
gasPrice
,
"err"
,
err
)
"gas_price"
,
gasPrice
,
"err"
,
err
)
// TODO(conner): add retry?
// TODO(conner): add retry?
return
return
}
}
txHash
:=
tx
.
Hash
()
txHash
:=
tx
.
Hash
()
log
.
Info
(
"T
ransaction published successfully"
,
"hash"
,
txHash
,
log
.
Info
(
name
+
" t
ransaction published successfully"
,
"hash"
,
txHash
,
"gas_price"
,
gasPrice
)
"gas_price"
,
gasPrice
)
// Wait for the transaction to be mined, reporting the receipt
// Wait for the transaction to be mined, reporting the receipt
...
@@ -137,7 +150,7 @@ func (m *SimpleTxManager) Send(
...
@@ -137,7 +150,7 @@ func (m *SimpleTxManager) Send(
ctxc
,
m
.
backend
,
tx
,
m
.
cfg
.
ReceiptQueryInterval
,
ctxc
,
m
.
backend
,
tx
,
m
.
cfg
.
ReceiptQueryInterval
,
)
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Trace
(
"S
end tx failed"
,
"hash"
,
txHash
,
log
.
Debug
(
name
+
" s
end tx failed"
,
"hash"
,
txHash
,
"gas_price"
,
gasPrice
,
"err"
,
err
)
"gas_price"
,
gasPrice
,
"err"
,
err
)
}
}
if
receipt
!=
nil
{
if
receipt
!=
nil
{
...
@@ -145,7 +158,7 @@ func (m *SimpleTxManager) Send(
...
@@ -145,7 +158,7 @@ func (m *SimpleTxManager) Send(
// if more than one receipt is discovered.
// if more than one receipt is discovered.
select
{
select
{
case
receiptChan
<-
receipt
:
case
receiptChan
<-
receipt
:
log
.
Trace
(
"S
end tx succeeded"
,
"hash"
,
txHash
,
log
.
Trace
(
name
+
" s
end tx succeeded"
,
"hash"
,
txHash
,
"gas_price"
,
gasPrice
)
"gas_price"
,
gasPrice
)
default
:
default
:
}
}
...
...
go/batch-submitter/txmgr/txmgr_test.go
View file @
c861fa43
...
@@ -83,7 +83,7 @@ type testHarness struct {
...
@@ -83,7 +83,7 @@ type testHarness struct {
// configuration.
// configuration.
func
newTestHarnessWithConfig
(
cfg
txmgr
.
Config
)
*
testHarness
{
func
newTestHarnessWithConfig
(
cfg
txmgr
.
Config
)
*
testHarness
{
backend
:=
newMockBackend
()
backend
:=
newMockBackend
()
mgr
:=
txmgr
.
NewSimpleTxManager
(
cfg
,
backend
)
mgr
:=
txmgr
.
NewSimpleTxManager
(
"TEST"
,
cfg
,
backend
)
return
&
testHarness
{
return
&
testHarness
{
cfg
:
cfg
,
cfg
:
cfg
,
...
...
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