Skip to content

Commit

Permalink
add attemps to all programs
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Sep 4, 2024
1 parent ba3699e commit f7c96e3
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 5 deletions.
3 changes: 2 additions & 1 deletion btcstaking-tracker/atomicslasher/atomic_slasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ func New(
parentLogger *zap.Logger,
retrySleepTime time.Duration,
maxRetrySleepTime time.Duration,
maxRetryTimes uint,
btcClient btcclient.BTCClient,
btcNotifier notifier.ChainNotifier,
bbnClient BabylonClient,
slashedFPSKChan chan *btcec.PrivateKey,
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,
Expand Down
5 changes: 5 additions & 0 deletions btcstaking-tracker/atomicslasher/babylon_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type BabylonAdapter struct {
cfg *config.BTCStakingTrackerConfig
retrySleepTime time.Duration
maxRetrySleepTime time.Duration
maxRetryTimes uint
bbnClient BabylonClient
}

Expand All @@ -28,13 +29,15 @@ func NewBabylonAdapter(
cfg *config.BTCStakingTrackerConfig,
retrySleepTime time.Duration,
maxRetrySleepTime time.Duration,
maxRetryTimes uint,
bbnClient BabylonClient,
) *BabylonAdapter {
return &BabylonAdapter{
logger: logger,
cfg: cfg,
retrySleepTime: retrySleepTime,
maxRetrySleepTime: maxRetrySleepTime,
maxRetryTimes: maxRetryTimes,
bbnClient: bbnClient,
}
}
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion btcstaking-tracker/btcslasher/bootstrapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion btcstaking-tracker/btcslasher/slasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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{}),
Expand Down
12 changes: 11 additions & 1 deletion btcstaking-tracker/btcslasher/slasher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions btcstaking-tracker/btcslasher/slasher_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 2 additions & 0 deletions btcstaking-tracker/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func NewBTCSTakingTracker(
btcParams,
commonCfg.RetrySleepTime,
commonCfg.MaxRetrySleepTime,
commonCfg.MaxRetryTimes,
slashedFPSKChan,
metrics.SlasherMetrics,
)
Expand All @@ -100,6 +101,7 @@ func NewBTCSTakingTracker(
logger,
commonCfg.RetrySleepTime,
commonCfg.MaxRetrySleepTime,
commonCfg.MaxRetryTimes,
btcClient,
btcNotifier,
bbnClient,
Expand Down
1 change: 1 addition & 0 deletions cmd/vigilante/cmd/submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func GetSubmitterCmd() *cobra.Command {
submitterAddr,
cfg.Common.RetrySleepTime,
cfg.Common.MaxRetrySleepTime,
cfg.Common.MaxRetryTimes,
submitterMetrics,
)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions e2etest/submitter_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func TestSubmitterSubmission(t *testing.T) {
subAddr,
tm.Config.Common.RetrySleepTime,
tm.Config.Common.MaxRetrySleepTime,
tm.Config.Common.MaxRetryTimes,
metrics.NewSubmitterMetrics(),
)

Expand Down Expand Up @@ -135,6 +136,7 @@ func TestSubmitterSubmissionReplace(t *testing.T) {
subAddr,
tm.Config.Common.RetrySleepTime,
tm.Config.Common.MaxRetrySleepTime,
tm.Config.Common.MaxRetryTimes,
metrics.NewSubmitterMetrics(),
)

Expand Down
3 changes: 2 additions & 1 deletion submitter/submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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)
Expand Down

0 comments on commit f7c96e3

Please sign in to comment.