Skip to content

Commit

Permalink
Democracy gov whitelist - added logs and event
Browse files Browse the repository at this point in the history
  • Loading branch information
stana-miric committed Sep 26, 2022
1 parent fbed89d commit afc8848
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions x/ccv/democracy/governance/module.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package governance

import (
"fmt"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand All @@ -11,6 +13,10 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
)

const (
AttributeValueProposalForbidden = "proposal_forbidden"
)

var (
_ module.AppModule = AppModule{}
_ module.AppModuleSimulation = AppModule{}
Expand Down Expand Up @@ -39,31 +45,49 @@ func (am AppModule) EndBlock(ctx sdk.Context, request abci.RequestEndBlock) []ab

am.keeper.IterateInactiveProposalsQueue(ctx, ctx.BlockHeader().Time, func(proposal govtypes.Proposal) bool {
//if there are forbidden proposals in inactive proposals queue, refund deposit and delete proposal from all storages
deleteProposalAndRefundDeposit(ctx, am, proposal, false)
deleteForbiddenProposal(ctx, am, proposal, false)
return false
})

am.keeper.IterateActiveProposalsQueue(ctx, ctx.BlockHeader().Time, func(proposal govtypes.Proposal) bool {
//if there are forbidden proposals in active proposals queue, refund deposit, delete votes for that proposal
//and delete proposal from all storages
deleteProposalAndRefundDeposit(ctx, am, proposal, true)
deleteForbiddenProposal(ctx, am, proposal, true)
return false
})

return am.AppModule.EndBlock(ctx, request)
}

func deleteProposalAndRefundDeposit(ctx sdk.Context, am AppModule, proposal govtypes.Proposal, isActive bool) {
if !am.isProposalWhitelisted(proposal.GetContent()) {
//if the proposal is active, delete the votes related to it
if isActive {
//Tally's return result won't be used in decision if the tokens will be burned or refunded (they are always refunded), but
//this function needs to be called to delete the votes related to the given proposal, since the deleteVote function is
// private and cannot be called directly from the overridden app module

am.keeper.Tally(ctx, proposal)
}
am.keeper.DeleteProposal(ctx, proposal.ProposalId)
am.keeper.RefundDeposits(ctx, proposal.ProposalId)
func deleteForbiddenProposal(ctx sdk.Context, am AppModule, proposal govtypes.Proposal, isActive bool) {
if am.isProposalWhitelisted(proposal.GetContent()) {
return
}

eventType := govtypes.EventTypeInactiveProposal
//if the proposal is active, delete the votes related to it
if isActive {
//Tally's return result won't be used in decision if the tokens will be burned or refunded (they are always refunded), but
//this function needs to be called to delete the votes related to the given proposal, since the deleteVote function is
// private and cannot be called directly from the overridden app module
eventType = govtypes.EventTypeActiveProposal
am.keeper.Tally(ctx, proposal)
}
am.keeper.DeleteProposal(ctx, proposal.ProposalId)
am.keeper.RefundDeposits(ctx, proposal.ProposalId)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
eventType,
sdk.NewAttribute(govtypes.AttributeKeyProposalID, fmt.Sprintf("%d", proposal.ProposalId)),
sdk.NewAttribute(govtypes.AttributeKeyProposalResult, AttributeValueProposalForbidden),
),
)

logger := am.keeper.Logger(ctx)
logger.Info(
"proposal is not whitelisted; deleted",
"proposal", proposal.ProposalId,
"title", proposal.GetTitle(),
"total_deposit", proposal.TotalDeposit.String())
}

0 comments on commit afc8848

Please sign in to comment.