Skip to content

Commit

Permalink
fix: handle rewarding give out reward to finalized blocks with gaps o…
Browse files Browse the repository at this point in the history
…f unfinalized blocks
  • Loading branch information
RafilxTenfen committed Jan 3, 2025
1 parent a6ebbf9 commit 10b90f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 2 additions & 3 deletions x/finality/keeper/rewarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ func (k Keeper) HandleRewarding(ctx context.Context, targetHeight int64) {
if err != nil {
panic(err)
}
if !block.Finalized {
break
if block.Finalized {
k.rewardBTCStaking(ctx, height)
}
k.rewardBTCStaking(ctx, height)
nextHeightToReward = height + 1
}

Expand Down
7 changes: 6 additions & 1 deletion x/finality/keeper/rewarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,13 @@ func TestHandleRewardingWithGapsOfUnfinalizedBlocks(t *testing.T) {
})
fKeeper.SetVotingPowerDistCache(ctx, 3, dc)

iKeeper.EXPECT().
RewardBTCStaking(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return().
Times(1) // number of finalized blocks processed

fKeeper.HandleRewarding(ctx, 3)

actNextBlockToBeRewarded := fKeeper.GetNextHeightToReward(ctx)
require.Equal(t, 4, actNextBlockToBeRewarded)
require.Equal(t, uint64(4), actNextBlockToBeRewarded)
}

0 comments on commit 10b90f8

Please sign in to comment.