Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add retry for consumer chain to become available #50

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions finality-provider/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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 {
Expand Down
25 changes: 24 additions & 1 deletion finality-provider/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
Loading