Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Jan 13, 2025
1 parent 9c5bad1 commit 730439f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
6 changes: 3 additions & 3 deletions clientcontroller/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,13 @@ func (bc *BabylonController) QueryLastCommittedPublicRand(fpPk *btcec.PublicKey,
return res.PubRandCommitMap, nil
}

func (bc *BabylonController) QueryBlocks(startHeight, endHeight uint64, limit uint32) ([]*types.BlockInfo, error) {
func (bc *BabylonController) QueryBlocks(startHeight, endHeight uint64, limit uint64) ([]*types.BlockInfo, error) {
if endHeight < startHeight {
return nil, fmt.Errorf("the startHeight %v should not be higher than the endHeight %v", startHeight, endHeight)
}
count := endHeight - startHeight + 1
if count > uint64(limit) {
count = uint64(limit)
if count > limit {
count = limit
}

return bc.queryLatestBlocks(sdk.Uint64ToBigEndian(startHeight), count, finalitytypes.QueriedBlockStatus_ANY, false)
Expand Down
2 changes: 1 addition & 1 deletion clientcontroller/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type ClientController interface {
QueryBlock(height uint64) (*types.BlockInfo, error)

// QueryBlocks returns a list of blocks from startHeight to endHeight
QueryBlocks(startHeight, endHeight uint64, limit uint32) ([]*types.BlockInfo, error)
QueryBlocks(startHeight, endHeight uint64, limit uint64) ([]*types.BlockInfo, error)

// QueryBestBlock queries the tip block of the consumer chain
QueryBestBlock() (*types.BlockInfo, error)
Expand Down
8 changes: 4 additions & 4 deletions finality-provider/service/chain_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (cp *ChainPoller) blockWithRetry(height uint64) (*types.BlockInfo, error) {
return block, nil
}

func (cp *ChainPoller) blocksWithRetry(start, end uint64, limit uint32) ([]*types.BlockInfo, error) {
func (cp *ChainPoller) blocksWithRetry(start, end, limit uint64) ([]*types.BlockInfo, error) {
var (
block []*types.BlockInfo
err error
Expand All @@ -163,7 +163,7 @@ func (cp *ChainPoller) blocksWithRetry(start, end uint64, limit uint32) ([]*type
zap.Uint("max_attempts", RtyAttNum),
zap.Uint64("start_height", start),
zap.Uint64("end_height", end),
zap.Uint32("limit", limit),
zap.Uint64("limit", limit),
zap.Error(err),
)
})); err != nil {
Expand Down Expand Up @@ -243,7 +243,7 @@ func (cp *ChainPoller) pollChain() {
// start polling in the first iteration
blockToRetrieve := cp.nextHeight

blocks, err := cp.blocksWithRetry(blockToRetrieve, latestBlock.Height, uint32(latestBlock.Height))
blocks, err := cp.blocksWithRetry(blockToRetrieve, latestBlock.Height, latestBlock.Height)
if err != nil {
failedCycles++
cp.logger.Debug(
Expand Down Expand Up @@ -289,8 +289,8 @@ func (cp *ChainPoller) pollChain() {
// no need to skip heights if the target height is not higher
// than the next height to retrieve
targetHeight := req.height
fmt.Printf("target height %d, next height %d\n", targetHeight, cp.nextHeight)
if targetHeight <= cp.nextHeight {
fmt.Printf("target height %d, next height %d\n", targetHeight, cp.nextHeight)
resp := &skipHeightResponse{
err: fmt.Errorf(
"the target height %d is not higher than the next height %d to retrieve",
Expand Down
36 changes: 21 additions & 15 deletions finality-provider/service/chain_poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ func FuzzChainPoller_SkipHeight(f *testing.F) {
currentHeight := uint64(r.Int63n(100) + 1)
startHeight := currentHeight + 1
endHeight := startHeight + uint64(r.Int63n(10)+2)
skipHeight := endHeight + uint64(r.Int63n(10)+1)

t.Log(startHeight, endHeight, skipHeight)
skipHeight := endHeight + uint64(r.Int63n(10)+2)

t.Log(startHeight, endHeight, skipHeight)

Expand All @@ -101,13 +99,19 @@ func FuzzChainPoller_SkipHeight(f *testing.F) {
}
resBlocks = append(resBlocks, resBlock)
}
mockClientController.EXPECT().QueryBlocks(gomock.Any(), gomock.Any(), gomock.Any()).Return(resBlocks, nil).AnyTimes()
//mockClientController.EXPECT().QueryBlocks(gomock.Any(), gomock.Any(), gomock.Any()).Return(resBlocks, nil).AnyTimes()

Check failure on line 102 in finality-provider/service/chain_poller_test.go

View workflow job for this annotation

GitHub Actions / lint_test / lint

commentFormatting: put a space between `//` and comment text (gocritic)
mockClientController.EXPECT().QueryBlocks(startHeight, endHeight, endHeight).Return(resBlocks, nil).AnyTimes()
mockClientController.EXPECT().QueryBlocks(endHeight+1, endHeight, endHeight).Return(resBlocks, nil).AnyTimes()

resBlocks = append(resBlocks, &types.BlockInfo{
Height: skipHeight,
})
mockClientController.EXPECT().QueryBlocks(startHeight, skipHeight, skipHeight).Return(resBlocks, nil).AnyTimes()
mockClientController.EXPECT().QueryBlocks(skipHeight+1, skipHeight, skipHeight).Return(resBlocks, nil).AnyTimes()
mockClientController.EXPECT().QueryBlocks(skipHeight, endHeight, endHeight).Return(resBlocks, nil).AnyTimes()
mockClientController.EXPECT().QueryBlocks(skipHeight+1, skipHeight, skipHeight).Return(resBlocks, nil).AnyTimes()

//
//mockClientController.EXPECT().QueryBlocks(startHeight, skipHeight, uint32(skipHeight)).Return(resBlocks, nil).AnyTimes()
//mockClientController.EXPECT().QueryBlocks(skipHeight, skipHeight, uint32(skipHeight)).Return(resBlocks, nil).AnyTimes()

Check failure on line 114 in finality-provider/service/chain_poller_test.go

View workflow job for this annotation

GitHub Actions / lint_test / lint

commentFormatting: put a space between `//` and comment text (gocritic)
//mockClientController.EXPECT().QueryBlocks(skipHeight+1, skipHeight, uint32(skipHeight)).Return(resBlocks, nil).AnyTimes()
//mockClientController.EXPECT().QueryBlocks(startHeight, endHeight, uint32(endHeight)).Return(resBlocks, nil).AnyTimes()

m := metrics.NewFpMetrics()
pollerCfg := fpcfg.DefaultChainPollerConfig()
Expand All @@ -118,13 +122,13 @@ func FuzzChainPoller_SkipHeight(f *testing.F) {
require.Error(t, err)
err = poller.Start(startHeight)
require.NoError(t, err)
//defer func() {
// err := poller.Stop()
// require.NoError(t, err)
// // should expect error if the poller is stopped
// err = poller.SkipToHeight(skipHeight)
// require.Error(t, err)
//}()
defer func() {
err := poller.Stop()
require.NoError(t, err)
// should expect error if the poller is stopped
err = poller.SkipToHeight(skipHeight)
require.Error(t, err)
}()

var wg sync.WaitGroup
wg.Add(1)
Expand Down Expand Up @@ -153,6 +157,7 @@ func FuzzChainPoller_SkipHeight(f *testing.F) {
if info.Height == skipHeight {
skipped = true
} else {
t.Log(i, info.Height)
require.Equal(t, i, info.Height)
}
case <-time.After(10 * time.Second):
Expand All @@ -161,6 +166,7 @@ func FuzzChainPoller_SkipHeight(f *testing.F) {
}

wg.Wait()
t.Log(skipHeight+1, poller.NextHeight())
require.Equal(t, skipHeight+1, poller.NextHeight())
})
}
2 changes: 1 addition & 1 deletion 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 730439f

Please sign in to comment.