Skip to content

Commit 1d4739e

Browse files
authored
Merge pull request #96 from cosmostation/update/babylon-fp-module
Compatible with babylon v3 finality-provider module
2 parents e28fd69 + 98ff49c commit 1d4739e

File tree

8 files changed

+16
-15
lines changed

8 files changed

+16
-15
lines changed

internal/common/api/babylon.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func GetFinalityVotesByHeight(c common.CommonClient, height int64) ([]string, er
5959
return votes.BTCPKs, nil
6060
}
6161

62-
func GetBabylonFinalityProviderInfos(c common.CommonClient) ([]types.FinalityProviderInfo, error) {
62+
func GetBabylonFinalityProviderInfos(c common.CommonClient, chainID string) ([]types.FinalityProviderInfo, error) {
6363
ctx, cancel := context.WithTimeout(context.Background(), common.Timeout)
6464
defer cancel()
6565

@@ -68,7 +68,7 @@ func GetBabylonFinalityProviderInfos(c common.CommonClient) ([]types.FinalityPro
6868
maxCnt := 10
6969
key := ""
7070
for cnt := 0; cnt <= maxCnt; cnt++ {
71-
resp, err := requester.Get(types.BabylonFinalityProviderInfosQueryPath(key))
71+
resp, err := requester.Get(types.BabylonFinalityProviderInfosQueryPath(key, chainID))
7272
if err != nil {
7373
return nil, errors.Errorf("rpc call is failed from %s: %s", resp.Request.URL, err)
7474
}
@@ -86,7 +86,7 @@ func GetBabylonFinalityProviderInfos(c common.CommonClient) ([]types.FinalityPro
8686

8787
if fpInfos.Pagination.NextKey != "" {
8888
key = url.QueryEscape(fpInfos.Pagination.NextKey)
89-
c.Debugf("there is next key, keep collecting finality providers by using this path: %s", types.BabylonFinalityProviderInfosQueryPath(key))
89+
c.Debugf("there is next key, keep collecting finality providers by using this path: %s", types.BabylonFinalityProviderInfosQueryPath(key, chainID))
9090
} else {
9191
// got all finality provider infos
9292
c.Debugf("collected all finality providers")

internal/common/api/babylon_api_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ func TestCheckGetBlockResultAndExtractFpVoting(t *testing.T) {
2828
func Test_Babylon_GetFP(t *testing.T) {
2929
commonApp := common.NewCommonApp(p)
3030
commonApp.SetAPIEndPoint("https://lcd-office.cosmostation.io/babylon-testnet")
31-
32-
fps, err := GetBabylonFinalityProviderInfos(commonApp.CommonClient)
31+
chainID := "bbn-testnet-5"
32+
fps, err := GetBabylonFinalityProviderInfos(commonApp.CommonClient, chainID)
3333
assert.NoError(t, err)
3434

3535
for _, fp := range fps {

internal/common/function/function.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ func GetStakingValidators(client common.CommonClient, chainName string, newStaki
229229
return nil
230230
}
231231

232-
func MakeFinalityProviderInfoList(c common.CommonClient, chainInfoID int64, newFinalityProviderMap map[string]bool) ([]indexermodel.FinalityProviderInfo, error) {
233-
fps, err := api.GetBabylonFinalityProviderInfos(c)
232+
func MakeFinalityProviderInfoList(c common.CommonClient, chainID string, chainInfoID int64, newFinalityProviderMap map[string]bool) ([]indexermodel.FinalityProviderInfo, error) {
233+
fps, err := api.GetBabylonFinalityProviderInfos(c, chainID)
234234
if err != nil {
235235
return nil, errors.Cause(err)
236236
}

internal/common/types/babylon.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ type FinalityVotesResponse struct {
4040
BTCPKs []string `json:"btc_pks"`
4141
}
4242

43-
var BabylonFinalityProviderInfosQueryPath = func(key string) string {
44-
return fmt.Sprintf("/babylon/btcstaking/v1/finality_providers?pagination.key=%s", key)
43+
var BabylonFinalityProviderInfosQueryPath = func(key, chainID string) string {
44+
return fmt.Sprintf("/babylon/btcstaking/v1/finality_providers/%s?pagination.key=%s", chainID, key)
4545
}
4646

4747
type FinalityProviderInfosResponse struct {

internal/packages/babylon/finality-provider/api/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const finalitySigTimeout = 3
1414

1515
func GetFinalityProviderUptime(exporter *common.Exporter) (types.BabylonFinalityProviderUptimeStatues, error) {
1616
// 1. get finality provider infos
17-
finalityProviderInfos, err := commonapi.GetBabylonFinalityProviderInfos(exporter.CommonClient)
17+
finalityProviderInfos, err := commonapi.GetBabylonFinalityProviderInfos(exporter.CommonClient, exporter.ChainID)
1818
if err != nil {
1919
return types.BabylonFinalityProviderUptimeStatues{}, errors.Wrap(err, "failed to get babylon finality provider infos")
2020
}

internal/packages/babylon/finality-provider/indexer/batch_sync.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const finalitySigTimeout = 3
1717

1818
// NOTE: in this package, the missed height means fp didn't broadcast the finality sig tx in height+1 block
1919
// for example, I didn't broadcast the tx at 100 block, that will make missed block for 99 height.
20-
func (idx *FinalityProviderIndexer) batchSync(lastIndexPointerHeight int64) (
20+
func (idx *FinalityProviderIndexer) batchSync(chainID string, lastIndexPointerHeight int64) (
2121
/* new index pointer */ int64,
2222
/* error */ error,
2323
) {
@@ -135,7 +135,7 @@ func (idx *FinalityProviderIndexer) batchSync(lastIndexPointerHeight int64) (
135135

136136
// this logic will be progressed only when there are new tendermint validators in this block
137137
if isNewFinalityProvider {
138-
newfpInfoList, err := function.MakeFinalityProviderInfoList(idx.CommonClient, idx.ChainInfoID, newFinalityProviderMap)
138+
newfpInfoList, err := function.MakeFinalityProviderInfoList(idx.CommonClient, chainID, idx.ChainInfoID, newFinalityProviderMap)
139139
if err != nil {
140140
errors.Wrap(err, "failed to make validator info list")
141141
}

internal/packages/babylon/finality-provider/indexer/indexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (idx *FinalityProviderIndexer) Loop(indexPoint int64) {
132132
}
133133

134134
// trying to sync with new index pointer height
135-
newIndexPointer, err := idx.batchSync(indexPoint)
135+
newIndexPointer, err := idx.batchSync(idx.ChainID, indexPoint)
136136
if err != nil {
137137
common.Health.With(idx.RootLabels).Set(0)
138138
common.Ops.With(idx.RootLabels).Inc()

internal/packages/babylon/finality-provider/indexer/indexer_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,16 @@ func TestBatchSync(t *testing.T) {
8484
err = idx.FetchValidatorInfoList()
8585
assert.NoError(t, err)
8686

87-
newIndexPointer, err := idx.batchSync(94810)
87+
newIndexPointer, err := idx.batchSync(idx.ChainID, 94810)
8888
assert.NoError(t, err)
8989
t.Logf("new index point: %d", newIndexPointer)
9090
}
9191

9292
func TestGetFinalityProvidersInfo(t *testing.T) {
9393
app := common.NewCommonApp(p)
9494
app.SetAPIEndPoint(BabylonBaseURL)
95-
fpInfoList, err := api.GetBabylonFinalityProviderInfos(app.CommonClient)
95+
chainID := "bbn-testnet-5"
96+
fpInfoList, err := api.GetBabylonFinalityProviderInfos(app.CommonClient, chainID)
9697
assert.NoError(t, err)
9798
t.Logf("new fp infos: %d", len(fpInfoList))
9899
for idx, fp := range fpInfoList {

0 commit comments

Comments
 (0)