diff --git a/finality-provider/config/config.go b/finality-provider/config/config.go index fabce0b1..12c17ed1 100644 --- a/finality-provider/config/config.go +++ b/finality-provider/config/config.go @@ -69,6 +69,7 @@ type Config struct { FastSyncGap uint64 `long:"fastsyncgap" description:"The block gap that will trigger the fast sync"` EOTSManagerAddress string `long:"eotsmanageraddress" description:"The address of the remote EOTS manager; Empty if the EOTS manager is running locally"` MaxNumFinalityProviders uint32 `long:"maxnumfinalityproviders" description:"The maximum number of finality-provider instances running concurrently within the daemon"` + MinutesToWaitForConsumer uint32 `long:"minuteswaitforconsumer" description:"The number of minutes it should wait for the consumer chain to be available, before stop the app"` BitcoinNetwork string `long:"bitcoinnetwork" description:"Bitcoin network to run on" choise:"mainnet" choice:"regtest" choice:"testnet" choice:"simnet" choice:"signet"` @@ -112,6 +113,7 @@ func DefaultConfigWithHome(homePath string) Config { RpcListener: DefaultRpcListener, MaxNumFinalityProviders: defaultMaxNumFinalityProviders, Metrics: metrics.DefaultFpConfig(), + MinutesToWaitForConsumer: 60 * 24 * 7, // one week in minutes } if err := cfg.Validate(); err != nil { diff --git a/finality-provider/service/app.go b/finality-provider/service/app.go index 4b8e0b91..d86ccfea 100644 --- a/finality-provider/service/app.go +++ b/finality-provider/service/app.go @@ -7,6 +7,7 @@ import ( "time" sdkmath "cosmossdk.io/math" + "github.com/avast/retry-go/v4" bbntypes "github.com/babylonlabs-io/babylon/types" bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types" "github.com/btcsuite/btcd/btcec/v2" @@ -238,7 +239,29 @@ func (app *FinalityProviderApp) getFpPrivKey(fpPk []byte) (*btcec.PrivateKey, er // SyncFinalityProviderStatus syncs the status of the finality-providers func (app *FinalityProviderApp) SyncFinalityProviderStatus() error { - latestBlock, err := app.cc.QueryBestBlock() + var ( + latestBlock *types.BlockInfo + err error + ) + + attempts := uint(app.config.MinutesToWaitForConsumer) + err = retry.Do(func() error { + latestBlock, err = app.cc.QueryBestBlock() + if err != nil { + return err + } + return nil + }, retry.OnRetry(func(n uint, err error) { + app.logger.Debug( + "failed to query the consumer chain for the latest block", + zap.Uint("attempt", n+1), + zap.Uint("max_attempts", attempts), + zap.Error(err), + ) + // waits for consumer chain to become online for one week + // usefull to turn fpd on before the consumer chain node is available + // and waiting for the consumer node to become available to start. + }), retry.Attempts(attempts), retry.Delay(time.Minute), RtyErr) if err != nil { return err }