diff --git a/bridge/setu/listener/heimdall.go b/bridge/setu/listener/heimdall.go index 64a19e43..e7dcff4c 100644 --- a/bridge/setu/listener/heimdall.go +++ b/bridge/setu/listener/heimdall.go @@ -50,8 +50,11 @@ func (hl *HeimdallListener) Start() error { checkpointPollInterval := helper.GetConfig().CheckpointerPollInterval - // fetch initial checkpoint params (will retry up to 10 times or exit service) - checkpointParams := util.GetCheckpointParamsWithRetry(hl.cliCtx) + checkpointParams, err := util.GetCheckpointParamsWithRetry(hl.cliCtx) + if err != nil { + hl.Logger.Error("Failed to fetch checkpoint params", "error", err) + return err + } if checkpointParams.CheckpointPollInterval > 0 { checkpointPollInterval = checkpointParams.CheckpointPollInterval } diff --git a/bridge/setu/listener/maticchain.go b/bridge/setu/listener/maticchain.go index 3fbed7a5..5e3cdc35 100644 --- a/bridge/setu/listener/maticchain.go +++ b/bridge/setu/listener/maticchain.go @@ -35,7 +35,11 @@ func (ml *MaticChainListener) Start() error { go ml.StartHeaderProcess(headerCtx) pollInterval := helper.GetConfig().CheckpointerPollInterval - params := util.GetCheckpointParamsWithRetry(ml.cliCtx) + params, err := util.GetCheckpointParamsWithRetry(ml.cliCtx) + if err != nil { + ml.Logger.Error("Failed to fetch checkpoint params", "error", err) + return err + } if params.CheckpointPollInterval > 0 { pollInterval = params.CheckpointPollInterval } diff --git a/bridge/setu/processor/checkpoint.go b/bridge/setu/processor/checkpoint.go index e5d7353a..979cfab3 100644 --- a/bridge/setu/processor/checkpoint.go +++ b/bridge/setu/processor/checkpoint.go @@ -65,10 +65,17 @@ func NewCheckpointProcessor(rootchainAbi, stakingInfoAbi *abi.ABI) *CheckpointPr // Start - consumes messages from checkpoint queue and call processMsg func (cp *CheckpointProcessor) Start() error { cp.Logger.Info("Starting") + + checkpointParams, err := util.GetCheckpointParamsWithRetry(cp.cliCtx) + if err != nil { + cp.Logger.Error("Failed to fetch checkpoint params", "error", err) + return err + } + // no-ack ackCtx, cancelNoACKPolling := context.WithCancel(context.Background()) cp.cancelNoACKPolling = cancelNoACKPolling - go cp.startPolling(ackCtx) + go cp.startPolling(ackCtx, checkpointParams) return nil } @@ -95,14 +102,12 @@ func (cp *CheckpointProcessor) RegisterTasks() { } } -func (cp *CheckpointProcessor) startPolling(ctx context.Context) { +func (cp *CheckpointProcessor) startPolling(ctx context.Context, checkpointParams *checkpointTypes.Params) { now := time.Now() baseTime := time.Unix(0, 0) // no-ack ticker interval keep same with checkpoint interval checkpointPollInterval := helper.GetConfig().CheckpointerPollInterval - // fetch initial checkpoint params (will retry up to 10 times or exit service) - checkpointParams := util.GetCheckpointParamsWithRetry(cp.cliCtx) if checkpointParams.CheckpointPollInterval > 0 { checkpointPollInterval = checkpointParams.CheckpointPollInterval } diff --git a/bridge/setu/util/common.go b/bridge/setu/util/common.go index 2c82a96f..a419de42 100644 --- a/bridge/setu/util/common.go +++ b/bridge/setu/util/common.go @@ -427,26 +427,21 @@ func GetCheckpointParams(cliCtx cliContext.CLIContext) (*checkpointTypes.Params, } // GetCheckpointParamsWithRetry guarantees successful retrieval of checkpoint parameters -// by retrying up to 10 times. If it fails after 10 attempts, the service will exit. -func GetCheckpointParamsWithRetry(cliCtx cliContext.CLIContext) *checkpointTypes.Params { +// by retrying up to 10 times. If it fails after 10 attempts, returns an error. +// The caller should handle the error appropriately (e.g., return error to trigger graceful shutdown). +func GetCheckpointParamsWithRetry(cliCtx cliContext.CLIContext) (*checkpointTypes.Params, error) { const maxRetries = 10 retryDelay := 1 * time.Second maxRetryDelay := 30 * time.Second for attempt := 1; attempt <= maxRetries; attempt++ { params, err := GetCheckpointParams(cliCtx) - if err == nil { + if err == nil && params != nil { logger.Info("Successfully fetched checkpoint params", "attempt", attempt) - return params + return params, nil } - if attempt == maxRetries { - logger.Error("Failed to fetch checkpoint params after maximum retries, exiting service", - "err", err, "maxRetries", maxRetries) - os.Exit(1) - } - - logger.Error("Failed to fetch checkpoint params, retrying...", + logger.Warn("Failed to fetch checkpoint params, retrying...", "err", err, "attempt", attempt, "maxRetries", maxRetries, "retryAfter", retryDelay) time.Sleep(retryDelay) @@ -457,10 +452,8 @@ func GetCheckpointParamsWithRetry(cliCtx cliContext.CLIContext) *checkpointTypes } } - // This line should never be reached, but added for completeness - logger.Error("Unexpected: exceeded retry loop without returning or exiting") - os.Exit(1) - return nil + logger.Error("Failed to fetch checkpoint params after maximum retries", "maxRetries", maxRetries) + return nil, errors.New("failed to fetch checkpoint params after maximum retries") } // GetBufferedCheckpoint return checkpoint from bueffer