From dfd70e297c197402f00762b359053432d821b995 Mon Sep 17 00:00:00 2001 From: rapha Date: Wed, 31 Jul 2024 11:31:02 +0200 Subject: [PATCH] fix: return early for empty bundles in SkipUploaderRole --- x/bundles/keeper/logic_bundles.go | 6 ++---- .../keeper/msg_server_skip_uploader_role.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/x/bundles/keeper/logic_bundles.go b/x/bundles/keeper/logic_bundles.go index 764dd198..a9b30c71 100644 --- a/x/bundles/keeper/logic_bundles.go +++ b/x/bundles/keeper/logic_bundles.go @@ -565,11 +565,9 @@ func (k Keeper) GetVoteDistribution(ctx sdk.Context, poolId uint64) (voteDistrib // tallyBundleProposal evaluates the votes of a bundle proposal and determines the outcome func (k Keeper) tallyBundleProposal(ctx sdk.Context, bundleProposal types.BundleProposal, poolId uint64) (types.TallyResult, error) { - // Increase points of stakers who did not vote at all + slash + remove if there is a bundle proposal. + // Increase points of stakers who did not vote at all + slash + remove if necessary. // The protocol requires everybody to stay always active. - if bundleProposal.StorageId != "" { - k.handleNonVoters(ctx, poolId) - } + k.handleNonVoters(ctx, poolId) // evaluate all votes and determine status based on the votes weighted with stake + delegation voteDistribution := k.GetVoteDistribution(ctx, poolId) diff --git a/x/bundles/keeper/msg_server_skip_uploader_role.go b/x/bundles/keeper/msg_server_skip_uploader_role.go index bc5d41e1..66da8df7 100644 --- a/x/bundles/keeper/msg_server_skip_uploader_role.go +++ b/x/bundles/keeper/msg_server_skip_uploader_role.go @@ -20,6 +20,22 @@ func (k msgServer) SkipUploaderRole(goCtx context.Context, msg *types.MsgSkipUpl // reset points of uploader as node has proven to be active k.resetPoints(ctx, msg.PoolId, msg.Staker) + // If previous bundle was dropped just skip uploader role + // No previous round needs to be evaluated + if bundleProposal.StorageId == "" { + nextUploader := k.chooseNextUploader(ctx, msg.PoolId) + + // Register empty bundle with next uploader + bundleProposal = types.BundleProposal{ + PoolId: msg.PoolId, + NextUploader: nextUploader, + UpdatedAt: uint64(ctx.BlockTime().Unix()), + } + k.SetBundleProposal(ctx, bundleProposal) + + return &types.MsgSkipUploaderRoleResponse{}, nil + } + // Previous round contains a bundle which needs to be validated now result, err := k.tallyBundleProposal(ctx, bundleProposal, msg.PoolId) if err != nil {