diff --git a/CONFIG.md b/CONFIG.md index 3058987a92..36101b145b 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -357,6 +357,27 @@ ResendAfterThreshold = '1m' # Default ``` ResendAfterThreshold controls how long to wait before re-broadcasting a transaction that has not yet been confirmed. +## Transactions.HederaBroadcastValidation +```toml +[Transactions.HederaBroadcastValidation] +SequencePollTimeout = '30s' # Example +SequencePollInterval = '2s' # Example +``` + + +### SequencePollTimeout +```toml +SequencePollTimeout = '30s' # Example +``` +SequencePollTimeout is the total time to poll the mined nonce after a successful Hedera send. +Unset keeps legacy single-check behavior. When set, TXM polls until the nonce advances or the timeout elapses. + +### SequencePollInterval +```toml +SequencePollInterval = '2s' # Example +``` +SequencePollInterval is the delay between mined nonce checks while polling. Defaults to 2s in TXM when unset. + ## Transactions.AutoPurge ```toml [Transactions.AutoPurge] diff --git a/pkg/config/chain_scoped_transactions.go b/pkg/config/chain_scoped_transactions.go index 5b20480932..9323e362a5 100644 --- a/pkg/config/chain_scoped_transactions.go +++ b/pkg/config/chain_scoped_transactions.go @@ -101,6 +101,22 @@ func (t *transactionsConfig) AutoPurge() AutoPurgeConfig { return &autoPurgeConfig{c: t.c.AutoPurge} } +func (t *transactionsConfig) HederaSequencePollTimeout() *time.Duration { + if t.c.HederaBroadcastValidation.SequencePollTimeout == nil { + return nil + } + d := t.c.HederaBroadcastValidation.SequencePollTimeout.Duration() + return &d +} + +func (t *transactionsConfig) HederaSequencePollInterval() *time.Duration { + if t.c.HederaBroadcastValidation.SequencePollInterval == nil { + return nil + } + d := t.c.HederaBroadcastValidation.SequencePollInterval.Duration() + return &d +} + type autoPurgeConfig struct { c toml.AutoPurgeConfig } diff --git a/pkg/config/chain_scoped_transactions_hedera_test.go b/pkg/config/chain_scoped_transactions_hedera_test.go new file mode 100644 index 0000000000..713b1b4ccc --- /dev/null +++ b/pkg/config/chain_scoped_transactions_hedera_test.go @@ -0,0 +1,67 @@ +package config + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config" + "github.com/smartcontractkit/chainlink-evm/pkg/config/toml" +) + +func TestTransactionsConfig_HederaBroadcastValidation(t *testing.T) { + t.Parallel() + + t.Run("returns nil when unset", func(t *testing.T) { + t.Parallel() + + cfg := &transactionsConfig{c: toml.Transactions{}} + assert.Nil(t, cfg.HederaSequencePollTimeout()) + assert.Nil(t, cfg.HederaSequencePollInterval()) + }) + + t.Run("returns configured values", func(t *testing.T) { + t.Parallel() + + timeout := commonconfig.MustNewDuration(30 * time.Second) + interval := commonconfig.MustNewDuration(2 * time.Second) + cfg := &transactionsConfig{c: toml.Transactions{ + HederaBroadcastValidation: toml.HederaBroadcastValidationConfig{ + SequencePollTimeout: timeout, + SequencePollInterval: interval, + }, + }} + + gotTimeout := cfg.HederaSequencePollTimeout() + require.NotNil(t, gotTimeout) + assert.Equal(t, 30*time.Second, *gotTimeout) + + gotInterval := cfg.HederaSequencePollInterval() + require.NotNil(t, gotInterval) + assert.Equal(t, 2*time.Second, *gotInterval) + }) +} + +func TestHederaBroadcastValidationConfig_ValidateConfig(t *testing.T) { + t.Parallel() + + t.Run("accepts valid config", func(t *testing.T) { + t.Parallel() + + cfg := toml.HederaBroadcastValidationConfig{ + SequencePollTimeout: commonconfig.MustNewDuration(time.Second), + } + require.NoError(t, cfg.ValidateConfig()) + }) + + t.Run("rejects interval without timeout", func(t *testing.T) { + t.Parallel() + + cfg := toml.HederaBroadcastValidationConfig{ + SequencePollInterval: commonconfig.MustNewDuration(time.Second), + } + require.Error(t, cfg.ValidateConfig()) + }) +} diff --git a/pkg/config/toml/config.go b/pkg/config/toml/config.go index 2a651dc7a7..9a434919d6 100644 --- a/pkg/config/toml/config.go +++ b/pkg/config/toml/config.go @@ -532,6 +532,9 @@ func (c *Transactions) ValidateConfig() (err error) { err = multierr.Append(err, commonconfig.ErrInvalid{Name: "AutoPurge.Threshold", Value: 0, Msg: "cannot be 0 if auto-purge feature is enabled"}) } } + if err2 := c.HederaBroadcastValidation.ValidateConfig(); err2 != nil { + err = multierr.Append(err, err2) + } return } @@ -545,8 +548,9 @@ type Transactions struct { ResendAfterThreshold *commonconfig.Duration ConfirmationTimeout *commonconfig.Duration - AutoPurge AutoPurgeConfig `toml:",omitempty"` - TransactionManagerV2 TransactionManagerV2Config `toml:",omitempty"` + AutoPurge AutoPurgeConfig `toml:",omitempty"` + HederaBroadcastValidation HederaBroadcastValidationConfig `toml:",omitempty"` + TransactionManagerV2 TransactionManagerV2Config `toml:",omitempty"` } func (t *Transactions) setFrom(f *Transactions) { @@ -575,6 +579,7 @@ func (t *Transactions) setFrom(f *Transactions) { t.ConfirmationTimeout = v } t.AutoPurge.setFrom(&f.AutoPurge) + t.HederaBroadcastValidation.setFrom(&f.HederaBroadcastValidation) t.TransactionManagerV2.setFrom(&f.TransactionManagerV2) } @@ -600,6 +605,35 @@ func (a *AutoPurgeConfig) setFrom(f *AutoPurgeConfig) { } } +// HederaBroadcastValidationConfig controls optional post-send mined-nonce polling on Hedera. +// Unset or zero SequencePollTimeout keeps legacy single-check behavior. +type HederaBroadcastValidationConfig struct { + SequencePollTimeout *commonconfig.Duration `toml:",omitempty"` + SequencePollInterval *commonconfig.Duration `toml:",omitempty"` +} + +func (h *HederaBroadcastValidationConfig) setFrom(f *HederaBroadcastValidationConfig) { + if v := f.SequencePollTimeout; v != nil { + h.SequencePollTimeout = v + } + if v := f.SequencePollInterval; v != nil { + h.SequencePollInterval = v + } +} + +func (h *HederaBroadcastValidationConfig) ValidateConfig() (err error) { + if h.SequencePollTimeout != nil && h.SequencePollTimeout.Duration() <= 0 { + err = multierr.Append(err, commonconfig.ErrInvalid{Name: "HederaBroadcastValidation.SequencePollTimeout", Value: h.SequencePollTimeout, Msg: "must be greater than zero when set"}) + } + if h.SequencePollInterval != nil && h.SequencePollInterval.Duration() <= 0 { + err = multierr.Append(err, commonconfig.ErrInvalid{Name: "HederaBroadcastValidation.SequencePollInterval", Value: h.SequencePollInterval, Msg: "must be greater than zero when set"}) + } + if h.SequencePollInterval != nil && (h.SequencePollTimeout == nil || h.SequencePollTimeout.Duration() <= 0) { + err = multierr.Append(err, commonconfig.ErrMissing{Name: "HederaBroadcastValidation.SequencePollTimeout", Msg: "must be set when SequencePollInterval is set"}) + } + return +} + type TransactionManagerV2Config struct { Enabled *bool `toml:",omitempty"` BlockTime *commonconfig.Duration `toml:",omitempty"` diff --git a/pkg/config/toml/config_test.go b/pkg/config/toml/config_test.go index d4cdf94abd..8417789cd4 100644 --- a/pkg/config/toml/config_test.go +++ b/pkg/config/toml/config_test.go @@ -116,6 +116,8 @@ func TestDefaults_fieldsNotNil(t *testing.T) { unknown.Transactions.AutoPurge.Threshold = ptr(uint32(0)) unknown.Transactions.AutoPurge.MinAttempts = ptr(uint32(0)) unknown.Transactions.AutoPurge.DetectionApiUrl = new(config.URL) + unknown.Transactions.HederaBroadcastValidation.SequencePollTimeout = new(config.Duration) + unknown.Transactions.HederaBroadcastValidation.SequencePollInterval = new(config.Duration) unknown.GasEstimator.BlockHistory.EIP1559FeeCapBufferBlocks = ptr[uint16](10) unknown.GasEstimator.SenderAddress = asEIP55Address(t, "0xae4E781a6218A8031764928E88d457937A954fC3") oracleType := DAOracleOPStack @@ -217,6 +219,9 @@ func TestDocs(t *testing.T) { docDefaults.Transactions.TransactionManagerV2.FastlaneAuctionRequestTimeout = nil docDefaults.Transactions.TransactionManagerV2.FeeBoost = nil + // HederaBroadcastValidation configs are optional and only documented as examples + docDefaults.Transactions.HederaBroadcastValidation = HederaBroadcastValidationConfig{} + // Fallback DA oracle is not set docDefaults.GasEstimator.DAOracle = DAOracle{} @@ -342,6 +347,10 @@ var fullConfig = EVMConfig{ MinAttempts: ptr[uint32](13), DetectionApiUrl: config.MustParseURL("http://example.net"), }, + HederaBroadcastValidation: HederaBroadcastValidationConfig{ + SequencePollTimeout: config.MustNewDuration(30 * time.Second), + SequencePollInterval: config.MustNewDuration(2 * time.Second), + }, TransactionManagerV2: TransactionManagerV2Config{ Enabled: ptr(false), DualBroadcast: ptr(true), diff --git a/pkg/config/toml/defaults/Hedera_Mainnet.toml b/pkg/config/toml/defaults/Hedera_Mainnet.toml index 98015b39da..e28e862bfe 100644 --- a/pkg/config/toml/defaults/Hedera_Mainnet.toml +++ b/pkg/config/toml/defaults/Hedera_Mainnet.toml @@ -30,6 +30,11 @@ EstimateLimit = true # Accounting for Node syncs & avoid re-sending txns before fetching the receipt, setting to 2m ResendAfterThreshold = '2m' +# Optional: wait for mined nonce to advance after a successful send before gas-bumping. +# Omit to keep legacy single-check behavior. CCIP example: 30s timeout, 2s poll interval. +# [Transactions.HederaBroadcastValidation] +# SequencePollTimeout = '30s' +# SequencePollInterval = '2s' [NodePool] SyncThreshold = 10 \ No newline at end of file diff --git a/pkg/config/toml/defaults/Hedera_Testnet.toml b/pkg/config/toml/defaults/Hedera_Testnet.toml index c266d3187c..0b2e1dc5ec 100644 --- a/pkg/config/toml/defaults/Hedera_Testnet.toml +++ b/pkg/config/toml/defaults/Hedera_Testnet.toml @@ -30,6 +30,11 @@ EstimateLimit = true # Accounting for Node syncs & avoid re-sending txns before fetching the receipt, setting to 2m ResendAfterThreshold = '2m' +# Optional: wait for mined nonce to advance after a successful send before gas-bumping. +# Omit to keep legacy single-check behavior. CCIP example: 30s timeout, 2s poll interval. +# [Transactions.HederaBroadcastValidation] +# SequencePollTimeout = '30s' +# SequencePollInterval = '2s' [NodePool] SyncThreshold = 10 \ No newline at end of file diff --git a/pkg/config/toml/docs.toml b/pkg/config/toml/docs.toml index ee8ae0b953..8880388046 100644 --- a/pkg/config/toml/docs.toml +++ b/pkg/config/toml/docs.toml @@ -155,6 +155,13 @@ ReaperThreshold = '168h' # Default # ResendAfterThreshold controls how long to wait before re-broadcasting a transaction that has not yet been confirmed. ResendAfterThreshold = '1m' # Default +[Transactions.HederaBroadcastValidation] +# SequencePollTimeout is the total time to poll the mined nonce after a successful Hedera send. +# Unset keeps legacy single-check behavior. When set, TXM polls until the nonce advances or the timeout elapses. +SequencePollTimeout = '30s' # Example +# SequencePollInterval is the delay between mined nonce checks while polling. Defaults to 2s in TXM when unset. +SequencePollInterval = '2s' # Example + [Transactions.AutoPurge] # Enabled enables or disables automatically purging transactions that have been idenitified as terminally stuck (will never be included on-chain). This feature is only expected to be used by ZK chains. Enabled = false # Default diff --git a/pkg/config/toml/testdata/config-full.toml b/pkg/config/toml/testdata/config-full.toml index 20854c4ed4..271e03ea96 100644 --- a/pkg/config/toml/testdata/config-full.toml +++ b/pkg/config/toml/testdata/config-full.toml @@ -43,6 +43,10 @@ Threshold = 42 MinAttempts = 13 DetectionApiUrl = 'http://example.net' +[Transactions.HederaBroadcastValidation] +SequencePollTimeout = '30s' +SequencePollInterval = '2s' + [Transactions.TransactionManagerV2] Enabled = false BlockTime = '42s' diff --git a/pkg/txmgr/test_helpers.go b/pkg/txmgr/test_helpers.go index a30fce697a..bf72e1af02 100644 --- a/pkg/txmgr/test_helpers.go +++ b/pkg/txmgr/test_helpers.go @@ -171,6 +171,9 @@ func (t *transactionsConfig) ReaperThreshold() time.Duration { return t.e. func (t *transactionsConfig) ResendAfterThreshold() time.Duration { return t.e.ResendAfterThreshold } func (t *transactionsConfig) AutoPurge() evmconfig.AutoPurgeConfig { return t.autoPurge } +func (t *transactionsConfig) HederaSequencePollTimeout() *time.Duration { return nil } +func (t *transactionsConfig) HederaSequencePollInterval() *time.Duration { return nil } + type autoPurgeConfig struct { evmconfig.AutoPurgeConfig }