diff --git a/btcstaking-tracker/atomicslasher/atomic_slasher.go b/btcstaking-tracker/atomicslasher/atomic_slasher.go index 3a17e96b..95108251 100644 --- a/btcstaking-tracker/atomicslasher/atomic_slasher.go +++ b/btcstaking-tracker/atomicslasher/atomic_slasher.go @@ -47,6 +47,7 @@ func New( parentLogger *zap.Logger, retrySleepTime time.Duration, maxRetrySleepTime time.Duration, + maxRetryTimes uint, btcClient btcclient.BTCClient, btcNotifier notifier.ChainNotifier, bbnClient BabylonClient, @@ -54,7 +55,7 @@ func New( metrics *metrics.AtomicSlasherMetrics, ) *AtomicSlasher { logger := parentLogger.With(zap.String("module", "atomic_slasher")) - bbnAdapter := NewBabylonAdapter(logger, cfg, retrySleepTime, maxRetrySleepTime, bbnClient) + bbnAdapter := NewBabylonAdapter(logger, cfg, retrySleepTime, maxRetrySleepTime, maxRetryTimes, bbnClient) return &AtomicSlasher{ quit: make(chan struct{}), cfg: cfg, diff --git a/btcstaking-tracker/atomicslasher/babylon_adapter.go b/btcstaking-tracker/atomicslasher/babylon_adapter.go index 50bd341c..0365c408 100644 --- a/btcstaking-tracker/atomicslasher/babylon_adapter.go +++ b/btcstaking-tracker/atomicslasher/babylon_adapter.go @@ -20,6 +20,7 @@ type BabylonAdapter struct { cfg *config.BTCStakingTrackerConfig retrySleepTime time.Duration maxRetrySleepTime time.Duration + maxRetryTimes uint bbnClient BabylonClient } @@ -28,6 +29,7 @@ func NewBabylonAdapter( cfg *config.BTCStakingTrackerConfig, retrySleepTime time.Duration, maxRetrySleepTime time.Duration, + maxRetryTimes uint, bbnClient BabylonClient, ) *BabylonAdapter { return &BabylonAdapter{ @@ -35,6 +37,7 @@ func NewBabylonAdapter( cfg: cfg, retrySleepTime: retrySleepTime, maxRetrySleepTime: maxRetrySleepTime, + maxRetryTimes: maxRetryTimes, bbnClient: bbnClient, } } @@ -53,6 +56,7 @@ func (ba *BabylonAdapter) BTCStakingParams(ctx context.Context, version uint32) retry.Context(ctx), retry.Delay(ba.retrySleepTime), retry.MaxDelay(ba.maxRetrySleepTime), + retry.Attempts(ba.maxRetryTimes), ) return bsParams, err @@ -72,6 +76,7 @@ func (ba *BabylonAdapter) BTCDelegation(ctx context.Context, stakingTxHashHex st retry.Context(ctx), retry.Delay(ba.retrySleepTime), retry.MaxDelay(ba.maxRetrySleepTime), + retry.Attempts(ba.maxRetryTimes), ) return resp, err diff --git a/btcstaking-tracker/btcslasher/bootstrapping_test.go b/btcstaking-tracker/btcslasher/bootstrapping_test.go index 57eb7ff2..0ff2acf2 100644 --- a/btcstaking-tracker/btcslasher/bootstrapping_test.go +++ b/btcstaking-tracker/btcslasher/bootstrapping_test.go @@ -61,7 +61,17 @@ func FuzzSlasher_Bootstrapping(f *testing.F) { logger, err := config.NewRootLogger("auto", "debug") require.NoError(t, err) slashedFPSKChan := make(chan *btcec.PrivateKey, 100) - btcSlasher, err := btcslasher.New(logger, mockBTCClient, mockBabylonQuerier, &chaincfg.SimNetParams, commonCfg.RetrySleepTime, commonCfg.MaxRetrySleepTime, slashedFPSKChan, metrics.NewBTCStakingTrackerMetrics().SlasherMetrics) + btcSlasher, err := btcslasher.New( + logger, + mockBTCClient, + mockBabylonQuerier, + &chaincfg.SimNetParams, + commonCfg.RetrySleepTime, + commonCfg.MaxRetrySleepTime, + commonCfg.MaxRetryTimes, + slashedFPSKChan, + metrics.NewBTCStakingTrackerMetrics().SlasherMetrics, + ) require.NoError(t, err) // slashing address diff --git a/btcstaking-tracker/btcslasher/slasher.go b/btcstaking-tracker/btcslasher/slasher.go index 0ba37bf3..a68b13ed 100644 --- a/btcstaking-tracker/btcslasher/slasher.go +++ b/btcstaking-tracker/btcslasher/slasher.go @@ -35,7 +35,7 @@ type BTCSlasher struct { btcFinalizationTimeout uint64 retrySleepTime time.Duration maxRetrySleepTime time.Duration - + maxRetryTimes uint // channel for finality signature messages, which might include // equivocation evidences finalitySigChan <-chan coretypes.ResultEvent @@ -59,6 +59,7 @@ func New( netParams *chaincfg.Params, retrySleepTime time.Duration, maxRetrySleepTime time.Duration, + maxRetryTimes uint, slashedFPSKChan chan *btcec.PrivateKey, metrics *metrics.SlasherMetrics, ) (*BTCSlasher, error) { @@ -71,6 +72,7 @@ func New( netParams: netParams, retrySleepTime: retrySleepTime, maxRetrySleepTime: maxRetrySleepTime, + maxRetryTimes: maxRetryTimes, slashedFPSKChan: slashedFPSKChan, slashResultChan: make(chan *SlashResult, 1000), quit: make(chan struct{}), diff --git a/btcstaking-tracker/btcslasher/slasher_test.go b/btcstaking-tracker/btcslasher/slasher_test.go index 9debfe61..d5cc1347 100644 --- a/btcstaking-tracker/btcslasher/slasher_test.go +++ b/btcstaking-tracker/btcslasher/slasher_test.go @@ -71,7 +71,17 @@ func FuzzSlasher(f *testing.F) { logger, err := config.NewRootLogger("auto", "debug") require.NoError(t, err) slashedFPSKChan := make(chan *btcec.PrivateKey, 100) - btcSlasher, err := btcslasher.New(logger, mockBTCClient, mockBabylonQuerier, &chaincfg.SimNetParams, commonCfg.RetrySleepTime, commonCfg.MaxRetrySleepTime, slashedFPSKChan, metrics.NewBTCStakingTrackerMetrics().SlasherMetrics) + btcSlasher, err := btcslasher.New( + logger, + mockBTCClient, + mockBabylonQuerier, + &chaincfg.SimNetParams, + commonCfg.RetrySleepTime, + commonCfg.MaxRetrySleepTime, + commonCfg.MaxRetryTimes, + slashedFPSKChan, + metrics.NewBTCStakingTrackerMetrics().SlasherMetrics, + ) require.NoError(t, err) err = btcSlasher.LoadParams() require.NoError(t, err) diff --git a/btcstaking-tracker/btcslasher/slasher_utils.go b/btcstaking-tracker/btcslasher/slasher_utils.go index 08e77bab..e8a38827 100644 --- a/btcstaking-tracker/btcslasher/slasher_utils.go +++ b/btcstaking-tracker/btcslasher/slasher_utils.go @@ -66,6 +66,7 @@ func (bs *BTCSlasher) slashBTCDelegation( retry.Context(ctx), retry.Delay(bs.retrySleepTime), retry.MaxDelay(bs.maxRetrySleepTime), + retry.Attempts(bs.maxRetryTimes), ) slashRes := &SlashResult{ diff --git a/btcstaking-tracker/tracker.go b/btcstaking-tracker/tracker.go index 0894619f..ca6a696b 100644 --- a/btcstaking-tracker/tracker.go +++ b/btcstaking-tracker/tracker.go @@ -87,6 +87,7 @@ func NewBTCSTakingTracker( btcParams, commonCfg.RetrySleepTime, commonCfg.MaxRetrySleepTime, + commonCfg.MaxRetryTimes, slashedFPSKChan, metrics.SlasherMetrics, ) @@ -100,6 +101,7 @@ func NewBTCSTakingTracker( logger, commonCfg.RetrySleepTime, commonCfg.MaxRetrySleepTime, + commonCfg.MaxRetryTimes, btcClient, btcNotifier, bbnClient, diff --git a/cmd/vigilante/cmd/submitter.go b/cmd/vigilante/cmd/submitter.go index c0be7412..f0a34d3a 100644 --- a/cmd/vigilante/cmd/submitter.go +++ b/cmd/vigilante/cmd/submitter.go @@ -71,6 +71,7 @@ func GetSubmitterCmd() *cobra.Command { submitterAddr, cfg.Common.RetrySleepTime, cfg.Common.MaxRetrySleepTime, + cfg.Common.MaxRetryTimes, submitterMetrics, ) if err != nil { diff --git a/e2etest/submitter_e2e_test.go b/e2etest/submitter_e2e_test.go index 55284a8f..0968e806 100644 --- a/e2etest/submitter_e2e_test.go +++ b/e2etest/submitter_e2e_test.go @@ -62,6 +62,7 @@ func TestSubmitterSubmission(t *testing.T) { subAddr, tm.Config.Common.RetrySleepTime, tm.Config.Common.MaxRetrySleepTime, + tm.Config.Common.MaxRetryTimes, metrics.NewSubmitterMetrics(), ) @@ -135,6 +136,7 @@ func TestSubmitterSubmissionReplace(t *testing.T) { subAddr, tm.Config.Common.RetrySleepTime, tm.Config.Common.MaxRetrySleepTime, + tm.Config.Common.MaxRetryTimes, metrics.NewSubmitterMetrics(), ) diff --git a/submitter/submitter.go b/submitter/submitter.go index 98747a44..82f467fb 100644 --- a/submitter/submitter.go +++ b/submitter/submitter.go @@ -41,7 +41,7 @@ func New( btcWallet btcclient.BTCWallet, queryClient BabylonQueryClient, submitterAddr sdk.AccAddress, - retrySleepTime, maxRetrySleepTime time.Duration, + retrySleepTime, maxRetrySleepTime time.Duration, maxRetryTimes uint, submitterMetrics *metrics.SubmitterMetrics, ) (*Submitter, error) { logger := parentLogger.With(zap.String("module", "submitter")) @@ -55,6 +55,7 @@ func New( }, retry.Delay(retrySleepTime), retry.MaxDelay(maxRetrySleepTime), + retry.Attempts(maxRetryTimes), ) if err != nil { return nil, fmt.Errorf("failed to get checkpoint params: %w", err)