Skip to content

Commit

Permalink
check if tx index enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Jan 24, 2025
1 parent 46c75a4 commit 93cd96e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions clientcontroller/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package clientcontroller
import (
"context"
"fmt"
coretypes "github.com/cometbft/cometbft/rpc/core/types"
"strings"
"time"

Expand Down Expand Up @@ -415,6 +416,10 @@ func (bc *BabylonController) QueryBestBlock() (*types.BlockInfo, error) {
return blocks[0], nil
}

func (bc *BabylonController) NodeStatus() (*coretypes.ResultStatus, error) {
return bc.bbnClient.GetStatus()
}

func (bc *BabylonController) queryCometBestBlock() (*types.BlockInfo, error) {
ctx, cancel := getContextWithCancel(bc.cfg.Timeout)
// this will return 20 items at max in the descending order (highest first)
Expand Down
3 changes: 3 additions & 0 deletions clientcontroller/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package clientcontroller

import (
"fmt"
coretypes "github.com/cometbft/cometbft/rpc/core/types"

"cosmossdk.io/math"
btcstakingtypes "github.com/babylonlabs-io/babylon/x/btcstaking/types"
Expand Down Expand Up @@ -89,6 +90,8 @@ type ClientController interface {
// the value zero should be returned.
QueryFinalityActivationBlockHeight() (uint64, error)

NodeStatus() (*coretypes.ResultStatus, error)

Close() error
}

Expand Down
17 changes: 17 additions & 0 deletions finality-provider/service/fp_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func (fp *FinalityProviderInstance) Start() error {
return fmt.Errorf("the finality-provider instance %s is already started", fp.GetBtcPkHex())
}

if err := fp.txIndexEnabled(); err != nil {
return err
}

if fp.IsJailed() {
fp.logger.Warn("the finality provider is jailed",
zap.String("pk", fp.GetBtcPkHex()))
Expand Down Expand Up @@ -1035,3 +1039,16 @@ func (fp *FinalityProviderInstance) GetFinalityProviderSlashedOrJailedWithRetry(

return slashed, jailed, nil
}

func (fp *FinalityProviderInstance) txIndexEnabled() error {
res, err := fp.cc.NodeStatus()
if err != nil {
return fmt.Errorf("failed to query node status: %w", err)
}

if !res.TxIndexEnabled() {
return fmt.Errorf("tx indexing in the babylon node must be enabled")
}

return nil
}
16 changes: 16 additions & 0 deletions testutil/mocks/babylon.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 93cd96e

Please sign in to comment.