Skip to content

Commit

Permalink
Added config to enable or disable the TXM
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-momin committed Dec 16, 2024
1 parent bd0296a commit 1a6a2ac
Show file tree
Hide file tree
Showing 21 changed files with 132 additions and 10 deletions.
4 changes: 4 additions & 0 deletions core/chains/evm/config/chain_scoped.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,7 @@ func (e *EVMConfig) FinalizedBlockOffset() uint32 {
func (e *EVMConfig) NoNewFinalizedHeadsThreshold() time.Duration {
return e.C.NoNewFinalizedHeadsThreshold.Duration()
}

func (e *EVMConfig) TXMEnabled() bool {
return *e.C.TXMEnabled
}
1 change: 1 addition & 0 deletions core/chains/evm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type EVM interface {
NodeNoNewHeadsThreshold() time.Duration
FinalizedBlockOffset() uint32
NoNewFinalizedHeadsThreshold() time.Duration
TXMEnabled() bool

IsEnabled() bool
TOMLString() (string, error)
Expand Down
13 changes: 12 additions & 1 deletion core/chains/evm/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,20 @@ func TestChainScopedConfig(t *testing.T) {

assert.Equal(t, false, cfg3.EVM().LogBroadcasterEnabled())
})
})

t.Run("TXMEnabled", func(t *testing.T) {
t.Run("turn on TXMEnabled by default", func(t *testing.T) {
assert.Equal(t, true, cfg.EVM().TXMEnabled())
})

t.Run("use Noop logBroadcaster when LogBroadcaster is disabled", func(t *testing.T) {
t.Run("verify TXMEnabled is set correctly", func(t *testing.T) {
val := false
cfg3 := testutils.NewTestChainScopedConfig(t, func(c *toml.EVMConfig) {
c.TXMEnabled = ptr(val)
})

assert.Equal(t, false, cfg3.EVM().TXMEnabled())
})
})
}
Expand Down
1 change: 1 addition & 0 deletions core/chains/evm/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ type Chain struct {
RPCBlockQueryDelay *uint16
FinalizedBlockOffset *uint32
NoNewFinalizedHeadsThreshold *commonconfig.Duration
TXMEnabled *bool

Transactions Transactions `toml:",omitempty"`
BalanceMonitor BalanceMonitor `toml:",omitempty"`
Expand Down
4 changes: 3 additions & 1 deletion core/chains/evm/config/toml/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,12 @@ func (c *Chain) SetFrom(f *Chain) {
if v := f.FinalizedBlockOffset; v != nil {
c.FinalizedBlockOffset = v
}

if v := f.NoNewFinalizedHeadsThreshold; v != nil {
c.NoNewFinalizedHeadsThreshold = v
}
if v := f.TXMEnabled; v != nil {
c.TXMEnabled = v
}

c.Transactions.setFrom(&f.Transactions)
c.BalanceMonitor.setFrom(&f.BalanceMonitor)
Expand Down
1 change: 1 addition & 0 deletions core/chains/evm/config/toml/defaults/fallback.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ RPCBlockQueryDelay = 1
FinalizedBlockOffset = 0
NoNewFinalizedHeadsThreshold = '0'
LogBroadcasterEnabled = true
TXMEnabled = true

[Transactions]
ForwardersEnabled = false
Expand Down
15 changes: 12 additions & 3 deletions core/chains/legacyevm/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,18 @@ func newChain(ctx context.Context, cfg *evmconfig.ChainScoped, nodes []*toml.Nod
}

// note: gas estimator is started as a part of the txm
txm, gasEstimator, err := newEvmTxm(opts.DS, cfg.EVM(), opts.AppConfig.EVMRPCEnabled(), opts.AppConfig.Database(), opts.AppConfig.Database().Listener(), client, l, logPoller, opts, headTracker, clientsByChainID)
if err != nil {
return nil, fmt.Errorf("failed to instantiate EvmTxm for chain with ID %s: %w", chainID.String(), err)
var txm txmgr.TxManager
var gasEstimator gas.EvmFeeEstimator
if !opts.AppConfig.EVMRPCEnabled() {
txm = &txmgr.NullTxManager{ErrMsg: fmt.Sprintf("Ethereum is disabled for chain %d", chainID)}
} else if !cfg.EVM().TXMEnabled() {
txm = &txmgr.NullTxManager{ErrMsg: fmt.Sprintf("TXM disabled for chain %d", chainID)}
} else {
var err error
txm, gasEstimator, err = newEvmTxm(opts.DS, cfg.EVM(), opts.AppConfig.Database(), opts.AppConfig.Database().Listener(), client, l, logPoller, opts, headTracker, clientsByChainID)
if err != nil {
return nil, fmt.Errorf("failed to instantiate EvmTxm for chain with ID %s: %w", chainID.String(), err)
}
}

headBroadcaster.Subscribe(txm)
Expand Down
5 changes: 0 additions & 5 deletions core/chains/legacyevm/evm_txm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
func newEvmTxm(
ds sqlutil.DataSource,
cfg evmconfig.EVM,
evmRPCEnabled bool,
databaseConfig txmgr.DatabaseConfig,
listenerConfig txmgr.ListenerConfig,
client evmclient.Client,
Expand All @@ -31,10 +30,6 @@ func newEvmTxm(
err error,
) {
chainID := cfg.ChainID()
if !evmRPCEnabled {
txm = &txmgr.NullTxManager{ErrMsg: fmt.Sprintf("Ethereum is disabled for chain %d", chainID)}
return txm, nil, nil
}

lggr = lggr.Named("Txm")
lggr.Infow("Initializing EVM transaction manager",
Expand Down
2 changes: 2 additions & 0 deletions core/config/docs/chains-evm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ LogBroadcasterEnabled = true # Default
#
# Set to zero to disable.
NoNewFinalizedHeadsThreshold = '0' # Default
# TXMEnabled is a feature flag for the Transaction Manager
TXMEnabled = true # Default

[EVM.Transactions]
# ForwardersEnabled enables or disables sending transactions through forwarder contracts.
Expand Down
1 change: 1 addition & 0 deletions core/services/chainlink/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ func TestConfig_Marshal(t *testing.T) {
FinalityTagEnabled: ptr[bool](true),
FlagsContractAddress: mustAddress("0xae4E781a6218A8031764928E88d457937A954fC3"),
FinalizedBlockOffset: ptr[uint32](16),
TXMEnabled: ptr(true),

GasEstimator: evmcfg.GasEstimator{
Mode: ptr("SuggestedPrice"),
Expand Down
1 change: 1 addition & 0 deletions core/services/chainlink/testdata/config-full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ RPCDefaultBatchSize = 17
RPCBlockQueryDelay = 10
FinalizedBlockOffset = 16
NoNewFinalizedHeadsThreshold = '1h0m0s'
TXMEnabled = true

[EVM.Transactions]
ForwardersEnabled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ RPCDefaultBatchSize = 250
RPCBlockQueryDelay = 1
FinalizedBlockOffset = 12
NoNewFinalizedHeadsThreshold = '9m0s'
TXMEnabled = true

[EVM.Transactions]
ForwardersEnabled = false
Expand Down Expand Up @@ -428,6 +429,7 @@ RPCDefaultBatchSize = 250
RPCBlockQueryDelay = 1
FinalizedBlockOffset = 0
NoNewFinalizedHeadsThreshold = '0s'
TXMEnabled = true

[EVM.Transactions]
ForwardersEnabled = false
Expand Down Expand Up @@ -532,6 +534,7 @@ RPCDefaultBatchSize = 100
RPCBlockQueryDelay = 10
FinalizedBlockOffset = 0
NoNewFinalizedHeadsThreshold = '6m0s'
TXMEnabled = true

[EVM.Transactions]
ForwardersEnabled = false
Expand Down
1 change: 1 addition & 0 deletions core/web/resolver/testdata/config-full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ RPCDefaultBatchSize = 17
RPCBlockQueryDelay = 10
FinalizedBlockOffset = 0
NoNewFinalizedHeadsThreshold = '15m0s'
TXMEnabled = true

[EVM.Transactions]
ForwardersEnabled = true
Expand Down
3 changes: 3 additions & 0 deletions core/web/resolver/testdata/config-multi-chain-effective.toml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ RPCDefaultBatchSize = 250
RPCBlockQueryDelay = 1
FinalizedBlockOffset = 0
NoNewFinalizedHeadsThreshold = '9m0s'
TXMEnabled = true

[EVM.Transactions]
ForwardersEnabled = false
Expand Down Expand Up @@ -428,6 +429,7 @@ RPCDefaultBatchSize = 250
RPCBlockQueryDelay = 1
FinalizedBlockOffset = 0
NoNewFinalizedHeadsThreshold = '0s'
TXMEnabled = true

[EVM.Transactions]
ForwardersEnabled = false
Expand Down Expand Up @@ -532,6 +534,7 @@ RPCDefaultBatchSize = 100
RPCBlockQueryDelay = 10
FinalizedBlockOffset = 0
NoNewFinalizedHeadsThreshold = '6m0s'
TXMEnabled = true

[EVM.Transactions]
ForwardersEnabled = false
Expand Down
Loading

0 comments on commit 1a6a2ac

Please sign in to comment.