From 7c128ab65f7c7ab0ff81cbe3b1d261dc635346f4 Mon Sep 17 00:00:00 2001 From: Cirrus Gai Date: Tue, 26 Nov 2024 14:40:11 +0800 Subject: [PATCH] fix: Remove start height validation (#158) Closes #157 by removing the validation that the start height should be higher than the current tip height of the consumer chain. The validation can be removed as the poller will start until btc staking starts (at least one finality provider has voting power) --- CHANGELOG.md | 4 ++ finality-provider/service/chain_poller.go | 58 ----------------------- 2 files changed, 4 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a076d1c..1afd2f3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## Unreleased +### Bug Fixes + +* [#158](https://github.com/babylonlabs-io/finality-provider/pull/158) Remove start height validation + ## v0.12.0 ### Bug Fixes diff --git a/finality-provider/service/chain_poller.go b/finality-provider/service/chain_poller.go index 6494da15..c3bc874e 100644 --- a/finality-provider/service/chain_poller.go +++ b/finality-provider/service/chain_poller.go @@ -76,11 +76,6 @@ func (cp *ChainPoller) Start(startHeight uint64) error { cp.logger.Info("starting the chain poller") - err := cp.validateStartHeight(startHeight) - if err != nil { - return fmt.Errorf("invalid starting height %d: %w", startHeight, err) - } - cp.nextHeight = startHeight cp.wg.Add(1) @@ -122,31 +117,6 @@ func (cp *ChainPoller) GetBlockInfoChan() <-chan *types.BlockInfo { return cp.blockInfoChan } -func (cp *ChainPoller) latestBlockWithRetry() (*types.BlockInfo, error) { - var ( - latestBlock *types.BlockInfo - err error - ) - - if err := retry.Do(func() error { - latestBlock, err = cp.cc.QueryBestBlock() - if err != nil { - return err - } - return nil - }, RtyAtt, RtyDel, RtyErr, retry.OnRetry(func(n uint, err error) { - cp.logger.Debug( - "failed to query the consumer chain for the latest block", - zap.Uint("attempt", n+1), - zap.Uint("max_attempts", RtyAttNum), - zap.Error(err), - ) - })); err != nil { - return nil, err - } - return latestBlock, nil -} - func (cp *ChainPoller) blockWithRetry(height uint64) (*types.BlockInfo, error) { var ( block *types.BlockInfo @@ -173,34 +143,6 @@ func (cp *ChainPoller) blockWithRetry(height uint64) (*types.BlockInfo, error) { return block, nil } -func (cp *ChainPoller) validateStartHeight(startHeight uint64) error { - // Infinite retry to get initial latest height - // TODO: Add possible cancellation or timeout for starting node - - if startHeight == 0 { - return fmt.Errorf("start height can't be 0") - } - - var currentBestChainHeight uint64 - for { - lastestBlock, err := cp.latestBlockWithRetry() - if err != nil { - cp.logger.Debug("failed to query babylon for the latest status", zap.Error(err)) - continue - } - - currentBestChainHeight = lastestBlock.Height - break - } - - // Allow the start height to be the next chain height - if startHeight > currentBestChainHeight+1 { - return fmt.Errorf("start height %d is more than the next chain tip height %d", startHeight, currentBestChainHeight+1) - } - - return nil -} - // waitForActivation waits until BTC staking is activated func (cp *ChainPoller) waitForActivation() { // ensure that the startHeight is no lower than the activated height