forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR cosmos#3567: x/gov peer review
- Loading branch information
Showing
14 changed files
with
160 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package gov | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/gov/tags" | ||
) | ||
|
||
// Called every block, process inflation, update validator set | ||
func EndBlocker(ctx sdk.Context, keeper Keeper) sdk.Tags { | ||
logger := ctx.Logger().With("module", "x/gov") | ||
resTags := sdk.NewTags() | ||
|
||
inactiveIterator := keeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) | ||
defer inactiveIterator.Close() | ||
for ; inactiveIterator.Valid(); inactiveIterator.Next() { | ||
var proposalID uint64 | ||
|
||
keeper.cdc.MustUnmarshalBinaryLengthPrefixed(inactiveIterator.Value(), &proposalID) | ||
inactiveProposal := keeper.GetProposal(ctx, proposalID) | ||
|
||
keeper.DeleteProposal(ctx, proposalID) | ||
keeper.DeleteDeposits(ctx, proposalID) // delete any associated deposits (burned) | ||
|
||
resTags = resTags.AppendTag(tags.ProposalID, fmt.Sprintf("%d", proposalID)) | ||
resTags = resTags.AppendTag(tags.ProposalResult, tags.ActionProposalDropped) | ||
|
||
logger.Info( | ||
fmt.Sprintf("proposal %d (%s) didn't meet minimum deposit of %s (had only %s); deleted", | ||
inactiveProposal.GetProposalID(), | ||
inactiveProposal.GetTitle(), | ||
keeper.GetDepositParams(ctx).MinDeposit, | ||
inactiveProposal.GetTotalDeposit(), | ||
), | ||
) | ||
} | ||
|
||
// fetch active proposals whose voting periods have ended (are passed the block time) | ||
activeIterator := keeper.ActiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) | ||
defer activeIterator.Close() | ||
for ; activeIterator.Valid(); activeIterator.Next() { | ||
var proposalID uint64 | ||
|
||
keeper.cdc.MustUnmarshalBinaryLengthPrefixed(activeIterator.Value(), &proposalID) | ||
activeProposal := keeper.GetProposal(ctx, proposalID) | ||
passes, tallyResults := tally(ctx, keeper, activeProposal) | ||
|
||
var tagValue string | ||
if passes { | ||
keeper.RefundDeposits(ctx, activeProposal.GetProposalID()) | ||
activeProposal.SetStatus(StatusPassed) | ||
tagValue = tags.ActionProposalPassed | ||
} else { | ||
keeper.DeleteDeposits(ctx, activeProposal.GetProposalID()) | ||
activeProposal.SetStatus(StatusRejected) | ||
tagValue = tags.ActionProposalRejected | ||
} | ||
|
||
activeProposal.SetFinalTallyResult(tallyResults) | ||
keeper.SetProposal(ctx, activeProposal) | ||
keeper.RemoveFromActiveProposalQueue(ctx, activeProposal.GetVotingEndTime(), activeProposal.GetProposalID()) | ||
|
||
logger.Info( | ||
fmt.Sprintf( | ||
"proposal %d (%s) tallied; passed: %v", | ||
activeProposal.GetProposalID(), activeProposal.GetTitle(), passes, | ||
), | ||
) | ||
|
||
resTags = resTags.AppendTag(tags.ProposalID, fmt.Sprintf("%d", proposalID)) | ||
resTags = resTags.AppendTag(tags.ProposalResult, tagValue) | ||
} | ||
|
||
return resTags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.