Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: HandleRewarding gaps of unfinalized blocks #378

Merged
merged 5 commits into from
Jan 3, 2025

Conversation

RafilxTenfen
Copy link
Contributor

@RafilxTenfen RafilxTenfen commented Jan 3, 2025

Prior to this fix, if we had an unfinalized block it would stuck to it as a next block to be rewarded

By using continue instead of break, if there is any finalized block in the interval (nextBlockToBeRewarded and targetHeight) it will give out rewards and update the next block to be rewarded

@RafilxTenfen RafilxTenfen self-assigned this Jan 3, 2025
@RafilxTenfen RafilxTenfen changed the title chore: add test that breaks handle rewarding with gaps of unfinalized… fix: HandleRewarding gaps of unfinalized blocks Jan 3, 2025
@RafilxTenfen RafilxTenfen marked this pull request as ready for review January 3, 2025 13:51
gitferry
gitferry previously approved these changes Jan 3, 2025
@gitferry gitferry dismissed their stale review January 3, 2025 14:04

need more thinking

@RafilxTenfen RafilxTenfen requested a review from gitferry January 3, 2025 14:11
Copy link
Member

@gitferry gitferry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm!

x/finality/keeper/rewarding_test.go Outdated Show resolved Hide resolved
@@ -30,7 +31,7 @@ func (k Keeper) HandleRewarding(ctx context.Context, targetHeight int64) {
panic(err)
}
if !block.Finalized {
break
continue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm the only concern I would have is that in case finality lags behind many blocks, this operation would be quite expensive i.e if we have 100 unfinalized blocks this will iterate over all of them.

This can be a bit expensive. Of course if we are lagging 100 blocks it means something is happening already so maybe this non issue?

In our case of all jailed fps, where there was no finalization for 5k blocks , this would iterate over all of them.

Wdyt @RafilxTenfen @gitferry ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeap, that is true

but it would be updated to the closest finalized block height once we have it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. It would mitigate the issue if we increase nextHeightToReward regardless block finalization (see commit 10b90f8). If we do so, it means that we will never reward blocks back if they are not finalized. I think it also make sense to not reward those late votes rewardless block finalization

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. It would mitigate the issue if we increase nextHeightToReward regardless block finalization (see commit 10b90f8). If we do so, it means that we will never reward blocks back if they are not finalized. I think it also make sense to not reward those late votes rewardless block finalization

Hmm this seems like protocol change (not rewarding those late votes) it definitely should not be done in this bug fix pr.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Let's merge this pr first and record this as an issue. Then bring it to the team for better visibility. Imo, we should make decision/implementation quick as it would cause breaking change

@RafilxTenfen RafilxTenfen merged commit 372e67b into main Jan 3, 2025
21 checks passed
@RafilxTenfen RafilxTenfen deleted the rafilx/fix-reward-blocks branch January 3, 2025 15:26
RafilxTenfen added a commit that referenced this pull request Jan 3, 2025
Prior to this fix, if we had an unfinalized block it would stuck to it
as a next block to be rewarded


By using `continue` instead of `break`, if there is any finalized block
in the interval (`nextBlockToBeRewarded` and `targetHeight`) it will
give out rewards and update the next block to be rewarded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants