Commit c861fa43 authored by Conner Fromknecht's avatar Conner Fromknecht

feat: enchance txmgr logging

parent 2d192f51
...@@ -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("Transaction published successfully", "hash", txHash, log.Info(name+" transaction 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("Send tx failed", "hash", txHash, log.Debug(name+" send 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("Send tx succeeded", "hash", txHash, log.Trace(name+" send tx succeeded", "hash", txHash,
"gas_price", gasPrice) "gas_price", gasPrice)
default: default:
} }
......
...@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment