Skip to content

Commit

Permalink
Txmv2 (#15467)
Browse files Browse the repository at this point in the history
* TXMv2 alpha version

* TXM fixes

* Fix

* Update orchestrator

* Add builder

* Add txmv2 tests

* Update retry logic

* Add backoff mechanism

* Add multi address support

* Add backoff mechanism for broadcasting and backfilling

* Minor fix

* Add check to dummy keystore

* Fix inmemory store logging per address

* Remove unnecessary const

* Fix txm to work with enabled addresses from keystore

* AttemptBuilder fixes

* Add AttemptBuilder close

* Minor updates

* Make purgable attempts empty

* Fix Idempotency in Store Manager

* Update trigger

* Fix lint

* Fix more lint

* Fix lint

* Fix lint

* More lint fixes

* Fix lint

* Fix lint final

* Fix races

* Update logs

* Fix lint

* Start documentation

* Update DummyKeystore Add method

* Txmv2 stuck tx detection (#15436)

* Stuck tx detector alpha

* Update stuck tx detection

* Add stuck_tx_detection and dual broadcast client

* Add support for TXMv2

* Fix orchestrator's monitoring call

* Fix AttemptBuilder

* Enable DualBroadcast client

* Switch DualBroadcast params to pointers

* Add context to client

* Fix lint

* Fix DualBroadcast client

* More lint fixes

* Fix lint

* Make nonce nullable

* Update configs

* Add prom metrics

* Add transaction confirmation metric

* Improve logs

* Address feedback

* Update tests

* Fix orchestrator log

* Fix Nonce log

* Improvements

* Update tests

* Add fixes

* Improvements

* Improve logs

* Move initialization of nonce

* Add Beholder metrics

* Improve InMemoryStorage

* Support different priceMax per key

* Upgrades

* Fix config tests

* Fix docs

* Fix config test lint

* Update configs

* Reuse transaction states

* Fix docs

* Deprecate DualBroadcastDetection

* Add health report

* Fix configs

* Bump mockery

* Update testfiles

* Update docs

* Address feedback

* Add backfill tests

* Update docs
  • Loading branch information
dimriou authored Jan 17, 2025
1 parent 0796288 commit 436b684
Show file tree
Hide file tree
Showing 47 changed files with 4,982 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ packages:
BalanceMonitor:
config:
dir: "{{ .InterfaceDir }}/../mocks"
github.com/smartcontractkit/chainlink/v2/core/chains/evm/txm:
interfaces:
Client:
TxStore:
AttemptBuilder:
Keystore:
github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr:
interfaces:
ChainConfig:
Expand Down
25 changes: 25 additions & 0 deletions core/chains/evm/config/chain_scoped_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ func (t *transactionsConfig) MaxQueued() uint64 {
return uint64(*t.c.MaxQueued)
}

func (t *transactionsConfig) TransactionManagerV2() TransactionManagerV2 {
return &transactionManagerV2Config{c: t.c.TransactionManagerV2}
}

type transactionManagerV2Config struct {
c toml.TransactionManagerV2Config
}

func (t *transactionManagerV2Config) Enabled() bool {
return *t.c.Enabled
}

func (t *transactionManagerV2Config) BlockTime() *time.Duration {
d := t.c.BlockTime.Duration()
return &d
}

func (t *transactionManagerV2Config) CustomURL() *url.URL {
return t.c.CustomURL.URL()
}

func (t *transactionManagerV2Config) DualBroadcast() *bool {
return t.c.DualBroadcast
}

func (t *transactionsConfig) AutoPurge() AutoPurgeConfig {
return &autoPurgeConfig{c: t.c.AutoPurge}
}
Expand Down
8 changes: 8 additions & 0 deletions core/chains/evm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type Transactions interface {
MaxInFlight() uint32
MaxQueued() uint64
AutoPurge() AutoPurgeConfig
TransactionManagerV2() TransactionManagerV2
}

type AutoPurgeConfig interface {
Expand All @@ -120,6 +121,13 @@ type AutoPurgeConfig interface {
DetectionApiUrl() *url.URL
}

type TransactionManagerV2 interface {
Enabled() bool
BlockTime() *time.Duration
CustomURL() *url.URL
DualBroadcast() *bool
}

type GasEstimator interface {
BlockHistory() BlockHistory
FeeHistory() FeeHistory
Expand Down
61 changes: 60 additions & 1 deletion core/chains/evm/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/url"
"slices"
"strconv"
"time"

"github.com/ethereum/go-ethereum/core/txpool/legacypool"
"github.com/pelletier/go-toml/v2"
Expand Down Expand Up @@ -471,6 +472,27 @@ func (c *Chain) ValidateConfig() (err error) {
return
}

func (c *Transactions) ValidateConfig() (err error) {
if c.TransactionManagerV2.Enabled != nil && *c.TransactionManagerV2.Enabled &&
c.TransactionManagerV2.DualBroadcast != nil && *c.TransactionManagerV2.DualBroadcast {
if c.TransactionManagerV2.CustomURL == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "TransactionManagerV2.CustomURL", Msg: "must be set if DualBroadcast is enabled"})
}
if c.AutoPurge.Enabled != nil && !*c.AutoPurge.Enabled {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "AutoPurge.Enabled", Value: false, Msg: "cannot be false if DualBroadcast is enabled"})
}
if c.AutoPurge.DetectionApiUrl == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "AutoPurge.DetectionApiUrl", Msg: "must be set if DualBroadcast is enabled"})
}
if c.AutoPurge.Threshold == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "AutoPurge.Threshold", Msg: "needs to be set if auto-purge feature is enabled"})
} else if *c.AutoPurge.Threshold == 0 {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "AutoPurge.Threshold", Value: 0, Msg: "cannot be 0 if auto-purge feature is enabled"})
}
}
return
}

type Transactions struct {
Enabled *bool
ForwardersEnabled *bool
Expand All @@ -480,7 +502,8 @@ type Transactions struct {
ReaperThreshold *commonconfig.Duration
ResendAfterThreshold *commonconfig.Duration

AutoPurge AutoPurgeConfig `toml:",omitempty"`
AutoPurge AutoPurgeConfig `toml:",omitempty"`
TransactionManagerV2 TransactionManagerV2Config `toml:",omitempty"`
}

func (t *Transactions) setFrom(f *Transactions) {
Expand All @@ -506,6 +529,7 @@ func (t *Transactions) setFrom(f *Transactions) {
t.ResendAfterThreshold = v
}
t.AutoPurge.setFrom(&f.AutoPurge)
t.TransactionManagerV2.setFrom(&f.TransactionManagerV2)
}

type AutoPurgeConfig struct {
Expand All @@ -530,6 +554,41 @@ func (a *AutoPurgeConfig) setFrom(f *AutoPurgeConfig) {
}
}

type TransactionManagerV2Config struct {
Enabled *bool `toml:",omitempty"`
BlockTime *commonconfig.Duration `toml:",omitempty"`
CustomURL *commonconfig.URL `toml:",omitempty"`
DualBroadcast *bool `toml:",omitempty"`
}

func (t *TransactionManagerV2Config) setFrom(f *TransactionManagerV2Config) {
if v := f.Enabled; v != nil {
t.Enabled = f.Enabled
}
if v := f.BlockTime; v != nil {
t.BlockTime = f.BlockTime
}
if v := f.CustomURL; v != nil {
t.CustomURL = f.CustomURL
}
if v := f.DualBroadcast; v != nil {
t.DualBroadcast = f.DualBroadcast
}
}

func (t *TransactionManagerV2Config) ValidateConfig() (err error) {
if t.Enabled != nil && *t.Enabled {
if t.BlockTime == nil {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "BlockTime", Msg: "must be set if TransactionManagerV2 feature is enabled"})
return
}
if t.BlockTime.Duration() < 2*time.Second {
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "BlockTime", Msg: "must be equal to or greater than 2 seconds"})
}
}
return
}

type OCR2 struct {
Automation Automation `toml:",omitempty"`
}
Expand Down
3 changes: 3 additions & 0 deletions core/chains/evm/config/toml/defaults/fallback.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ ResendAfterThreshold = '1m'
[Transactions.AutoPurge]
Enabled = false

[Transactions.TransactionManagerV2]
Enabled = false

[BalanceMonitor]
Enabled = true

Expand Down
1 change: 1 addition & 0 deletions core/chains/evm/keystore/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ type Eth interface {
CheckEnabled(ctx context.Context, address common.Address, chainID *big.Int) error
EnabledAddressesForChain(ctx context.Context, chainID *big.Int) (addresses []common.Address, err error)
SignTx(ctx context.Context, fromAddress common.Address, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)
SignMessage(ctx context.Context, address common.Address, message []byte) ([]byte, error)
SubscribeToKeyChanges(ctx context.Context) (ch chan struct{}, unsub func())
}
60 changes: 60 additions & 0 deletions core/chains/evm/keystore/mocks/eth.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 436b684

Please sign in to comment.