diff --git a/clientcontroller/babylon.go b/clientcontroller/babylon.go index ed0916e0..ee722962 100644 --- a/clientcontroller/babylon.go +++ b/clientcontroller/babylon.go @@ -3,6 +3,7 @@ package clientcontroller import ( "context" "fmt" + coretypes "github.com/cometbft/cometbft/rpc/core/types" "strings" "time" @@ -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) diff --git a/clientcontroller/interface.go b/clientcontroller/interface.go index 8aaf29d9..bd3f58a7 100644 --- a/clientcontroller/interface.go +++ b/clientcontroller/interface.go @@ -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" @@ -89,6 +90,8 @@ type ClientController interface { // the value zero should be returned. QueryFinalityActivationBlockHeight() (uint64, error) + NodeStatus() (*coretypes.ResultStatus, error) + Close() error } diff --git a/finality-provider/service/fp_instance.go b/finality-provider/service/fp_instance.go index 725d3e72..4b32c1b2 100644 --- a/finality-provider/service/fp_instance.go +++ b/finality-provider/service/fp_instance.go @@ -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())) @@ -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 +} diff --git a/testutil/mocks/babylon.go b/testutil/mocks/babylon.go index 404463a7..72e7e061 100644 --- a/testutil/mocks/babylon.go +++ b/testutil/mocks/babylon.go @@ -13,6 +13,7 @@ import ( types1 "github.com/babylonlabs-io/finality-provider/types" btcec "github.com/btcsuite/btcd/btcec/v2" schnorr "github.com/btcsuite/btcd/btcec/v2/schnorr" + coretypes "github.com/cometbft/cometbft/rpc/core/types" gomock "github.com/golang/mock/gomock" ) @@ -83,6 +84,21 @@ func (mr *MockClientControllerMockRecorder) EditFinalityProvider(fpPk, commissio return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EditFinalityProvider", reflect.TypeOf((*MockClientController)(nil).EditFinalityProvider), fpPk, commission, description) } +// NodeStatus mocks base method. +func (m *MockClientController) NodeStatus() (*coretypes.ResultStatus, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NodeStatus") + ret0, _ := ret[0].(*coretypes.ResultStatus) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// NodeStatus indicates an expected call of NodeStatus. +func (mr *MockClientControllerMockRecorder) NodeStatus() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeStatus", reflect.TypeOf((*MockClientController)(nil).NodeStatus)) +} + // QueryActivatedHeight mocks base method. func (m *MockClientController) QueryActivatedHeight() (uint64, error) { m.ctrl.T.Helper()