From 10b90f827a1f2f426c22b0e108f73f0a167d52ea Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Fri, 3 Jan 2025 10:51:02 -0300 Subject: [PATCH] fix: handle rewarding give out reward to finalized blocks with gaps of unfinalized blocks --- x/finality/keeper/rewarding.go | 5 ++--- x/finality/keeper/rewarding_test.go | 7 ++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/x/finality/keeper/rewarding.go b/x/finality/keeper/rewarding.go index 3b6b3a32..ade20944 100644 --- a/x/finality/keeper/rewarding.go +++ b/x/finality/keeper/rewarding.go @@ -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 } diff --git a/x/finality/keeper/rewarding_test.go b/x/finality/keeper/rewarding_test.go index 3e644af4..b3a281a0 100644 --- a/x/finality/keeper/rewarding_test.go +++ b/x/finality/keeper/rewarding_test.go @@ -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) }