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

[backport] fix: Remove start height validation (#158) #159

Merged
merged 1 commit into from
Nov 26, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 0 additions & 58 deletions finality-provider/service/chain_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down