Skip to content

Commit

Permalink
feat: tally bundle proposal on timeout (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
shifty11 authored May 3, 2024
1 parent 7358839 commit 99e96af
Show file tree
Hide file tree
Showing 3 changed files with 270 additions and 38 deletions.
2 changes: 1 addition & 1 deletion x/bundles/keeper/logic_bundles.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ func (k Keeper) GetVoteDistribution(ctx sdk.Context, poolId uint64) (voteDistrib
}

// tallyBundleProposal evaluates the votes of a bundle proposal and determines the outcome
func (k msgServer) tallyBundleProposal(ctx sdk.Context, bundleProposal types.BundleProposal, poolId uint64) (types.TallyResult, error) {
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 necessary.
// The protocol requires everybody to stay always active.
k.handleNonVoters(ctx, poolId)
Expand Down
54 changes: 45 additions & 9 deletions x/bundles/keeper/logic_end_block_handle_upload_timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,52 @@ func (k Keeper) HandleUploadTimeout(goCtx context.Context) {

// We now know that the pool is active and the upload timeout has been reached.

// Now we increase the points of the valaccount
// (if he is still participating in the pool) and select a new one.
if k.stakerKeeper.DoesValaccountExist(ctx, pool.Id, bundleProposal.NextUploader) {
k.addPoint(ctx, pool.Id, bundleProposal.NextUploader)
}
timedoutUploader := bundleProposal.NextUploader

// Update bundle proposal and choose next uploader
bundleProposal.NextUploader = k.chooseNextUploader(ctx, pool.Id)
bundleProposal.UpdatedAt = uint64(ctx.BlockTime().Unix())
// Check if we have a bundle proposal to validate.
if bundleProposal.StorageId != "" {
// Previous round contains a bundle which needs to be validated now.
result, err := k.tallyBundleProposal(ctx, bundleProposal, pool.Id)
if err != nil {
// If we have an error here we might have an inconsistent state.
continue
}

switch result.Status {
case types.TallyResultValid:
// Get next uploader from stakers who voted `valid`
nextUploader := k.chooseNextUploaderFromList(ctx, pool.Id, bundleProposal.VotersValid)

// Finalize bundle by adding it to the store
k.finalizeCurrentBundleProposal(ctx, pool.Id, result.VoteDistribution, result.FundersPayout, result.InflationPayout, result.BundleReward, nextUploader)

// Register empty bundle with next uploader
bundleProposal = types.BundleProposal{
PoolId: pool.Id,
NextUploader: nextUploader,
UpdatedAt: uint64(ctx.BlockTime().Unix()),
}
k.SetBundleProposal(ctx, bundleProposal)
default:
// In every other case the bundle is dropped.

k.SetBundleProposal(ctx, bundleProposal)
// Get next uploader from all pool stakers
nextUploader := k.chooseNextUploader(ctx, pool.Id)

// Drop current bundle and set next uploader
k.dropCurrentBundleProposal(ctx, pool.Id, result.VoteDistribution, nextUploader)
}
} else {
// Update bundle proposal and choose next uploader
bundleProposal.NextUploader = k.chooseNextUploader(ctx, pool.Id)
bundleProposal.UpdatedAt = uint64(ctx.BlockTime().Unix())
k.SetBundleProposal(ctx, bundleProposal)
}

// Now we increase the points of the valaccount
// (if he is still participating in the pool)
if k.stakerKeeper.DoesValaccountExist(ctx, pool.Id, timedoutUploader) {
k.addPoint(ctx, pool.Id, timedoutUploader)
}
}
}
Loading

0 comments on commit 99e96af

Please sign in to comment.