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

chore(upgrade): remove deprecated gov proposals (incentives) #2196

Merged
merged 15 commits into from
Dec 18, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (evm) [#1943](https://github.com/evmos/evmos/pull/1943) Fix gas estimation (`eth_estimateGas`) to be consistent with gas used in EVM extensions transactions.
- (test) [#1989](https://github.com/evmos/evmos/pull/1989) Fix the problem about deliverTxSimulate in test app/ante/cosmos/min_price_test.go
- (db) [#2072](https://github.com/evmos/evmos/pull/2072) Change VersionDb directory permission from 777 (insecure) to 750 (general)
- (api) [#2196](https://github.com/evmos/evmos/pull/2196) Remove governance proposals related to the deprecated `x/incentives` module to fix the governance proposals query.

## [v15.0.0] - 2023-10-31

Expand Down
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ import (
"github.com/evmos/evmos/v16/x/feemarket"
feemarketkeeper "github.com/evmos/evmos/v16/x/feemarket/keeper"
feemarkettypes "github.com/evmos/evmos/v16/x/feemarket/types"
"github.com/evmos/evmos/v16/x/incentives"
inflation "github.com/evmos/evmos/v16/x/inflation/v1"
inflationkeeper "github.com/evmos/evmos/v16/x/inflation/v1/keeper"
inflationtypes "github.com/evmos/evmos/v16/x/inflation/v1/types"
Expand Down Expand Up @@ -226,6 +227,7 @@ var (
epochs.AppModuleBasic{},
revenue.AppModuleBasic{},
consensus.AppModuleBasic{},
incentives.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -1136,6 +1138,7 @@ func (app *Evmos) setupUpgradeHandlers() {
app.BankKeeper,
app.InflationKeeper,
app.AccountKeeper,
app.GovKeeper,
),
)

Expand Down
47 changes: 47 additions & 0 deletions app/upgrades/v16/proposals.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright Tharsis Labs Ltd.(Evmos)
// SPDX-License-Identifier:ENCL-1.0(https://github.com/evmos/evmos/blob/main/LICENSE)

package v16

import (
"github.com/cometbft/cometbft/libs/log"

sdk "github.com/cosmos/cosmos-sdk/types"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
incentives "github.com/evmos/evmos/v16/x/incentives/types"
)

// DeleteIncentivesProposals deletes the RegisterIncentives & CancelIncentiveProposal proposals from the store
// because the module was deprecated
func DeleteIncentivesProposals(ctx sdk.Context, gk govkeeper.Keeper, logger log.Logger) {
// Delete the only incentives module proposals
gk.IterateProposals(ctx, func(proposal govtypes.Proposal) bool {
// Check if proposal is a RegisterIncentives or CancelIncentiveProposal proposal
msgs, err := proposal.GetMsgs()
if err != nil {
logger.Error("failed to get proposal messages", "error", err.Error())
return false
}

for _, msg := range msgs {
legacyContentMsg, ok := msg.(*govtypes.MsgExecLegacyContent)
if !ok {
continue
}

_, ok = legacyContentMsg.Content.GetCachedValue().(*incentives.RegisterIncentiveProposal)
if ok {
gk.DeleteProposal(ctx, proposal.Id)
continue
}

_, ok = legacyContentMsg.Content.GetCachedValue().(*incentives.CancelIncentiveProposal)
if ok {
gk.DeleteProposal(ctx, proposal.Id)
continue
}
}
return false
})
}
19 changes: 13 additions & 6 deletions app/upgrades/v16/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/evmos/evmos/v16/precompiles/bech32"
osmosisoutpost "github.com/evmos/evmos/v16/precompiles/outposts/osmosis"
Expand All @@ -24,7 +25,8 @@ func CreateUpgradeHandler(
ek *evmkeeper.Keeper,
_ bankkeeper.Keeper,
inflationKeeper inflationkeeper.Keeper,
_ authkeeper.AccountKeeper,
ak authkeeper.AccountKeeper,
gk govkeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
logger := ctx.Logger().With("upgrade", UpgradeName)
Expand All @@ -45,12 +47,13 @@ func CreateUpgradeHandler(
logger.Error("failed to enable outposts", "error", err.Error())
}

// TODO: uncomment when ready
// Migrate the FeeCollector module account to include the Burner permission.
// if err := MigrateFeeCollector(ak, ctx); err != nil {
// logger.Error("failed to migrate the fee collector", "error", err.Error())
// }
//
// This is required when including the postHandler to burn Cosmos Tx fees
if err := MigrateFeeCollector(ak, ctx); err != nil {
logger.Error("failed to migrate the fee collector", "error", err.Error())
}

// TODO: uncomment when ready
// if err := BurnUsageIncentivesPool(ctx, bankKeeper); err != nil {
// logger.Error("failed to burn inflation pool", "error", err.Error())
// }
Expand All @@ -59,6 +62,10 @@ func CreateUpgradeHandler(
logger.Error("failed to update inflation params", "error", err.Error())
}

// Remove the deprecated governance proposals from store
logger.Debug("deleting deprecated incentives module proposals...")
DeleteIncentivesProposals(ctx, gk, logger)

// recovery module is deprecated
logger.Debug("deleting recovery module from version map...")
delete(vm, "recovery")
Expand Down
74 changes: 74 additions & 0 deletions app/upgrades/v16/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@
package v16_test

import (
"time"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/types"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govtypesv1beta "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
upgrade "github.com/cosmos/cosmos-sdk/x/upgrade/types"

v16 "github.com/evmos/evmos/v16/app/upgrades/v16"
"github.com/evmos/evmos/v16/crypto/ethsecp256k1"
"github.com/evmos/evmos/v16/testutil"
testnetwork "github.com/evmos/evmos/v16/testutil/integration/evmos/network"
utiltx "github.com/evmos/evmos/v16/testutil/tx"
"github.com/evmos/evmos/v16/utils"
incentives "github.com/evmos/evmos/v16/x/incentives/types"
)

func (its *IntegrationTestSuite) TestMigrateFeeCollector() {
Expand Down Expand Up @@ -70,3 +79,68 @@ func (its *IntegrationTestSuite) TestUpdateInflationParams() {
finalParams := its.network.App.InflationKeeper.GetParams(its.network.GetContext())
its.Require().Equal(math.LegacyZeroDec(), finalParams.InflationDistribution.UsageIncentives) //nolint:staticcheck
}

func (its *IntegrationTestSuite) TestDeleteIncentivesProposals() {
its.SetupTest()

// Create 3 proposals. 2 will be deleted because correspond to the incentives module
expInitialProps := 3
expFinalProps := 1
prop1 := &incentives.RegisterIncentiveProposal{
Title: "Test",
Description: "Test Register Incentive Proposal",
Contract: utiltx.GenerateAddress().String(),
Allocations: sdk.DecCoins{sdk.NewDecCoinFromDec("aevmos", sdk.NewDecWithPrec(5, 2))},
Epochs: 100,
}

prop2 := &upgrade.SoftwareUpgradeProposal{ //nolint:staticcheck
Title: "Test",
Description: "Test Software Upgrade Proposal",
Plan: upgrade.Plan{},
}

prop3 := &incentives.CancelIncentiveProposal{
Title: "Test",
Description: "Test Cancel Incentive Proposal",
Contract: utiltx.GenerateAddress().String(),
}

privKey, _ := ethsecp256k1.GenerateKey()
addrBz := privKey.PubKey().Address().Bytes()
accAddr := sdk.AccAddress(addrBz)
coins := sdk.NewCoins(sdk.NewCoin(its.network.GetDenom(), math.NewInt(5e18)))
err := testutil.FundAccount(its.network.GetContext(), its.network.App.BankKeeper, accAddr, coins)
its.Require().NoError(err)

for _, prop := range []govtypesv1beta.Content{prop1, prop2, prop3} {
its.createProposal(prop, accAddr)
}

// check the creation of the 3 proposals was successful
allProposalsBefore := its.network.App.GovKeeper.GetProposals(its.network.GetContext())
its.Require().Len(allProposalsBefore, expInitialProps)

// Delete the corresponding proposals
logger := its.network.GetContext().Logger()
v16.DeleteIncentivesProposals(its.network.GetContext(), its.network.App.GovKeeper, logger)

allProposalsAfter := its.network.App.GovKeeper.GetProposals(its.network.GetContext())
its.Require().Len(allProposalsAfter, expFinalProps)
}

func (its *IntegrationTestSuite) createProposal(content govtypesv1beta.Content, acc sdk.AccAddress) {
allProposalsBefore := its.network.App.GovKeeper.GetProposals(its.network.GetContext())
propID := len(allProposalsBefore) + 1

legacyContent, err := govtypesv1.NewLegacyContent(
content,
sdk.MustBech32ifyAddressBytes(sdk.GetConfig().GetBech32AccountAddrPrefix(), acc),
)
its.Require().NoError(err)

proposalMsgs := []sdk.Msg{legacyContent}
newProposal, err := govtypesv1.NewProposal(proposalMsgs, uint64(propID), time.Now(), time.Now().Add(time.Hour*5), "", "Test", "Test", acc)
its.Require().NoError(err)
its.network.App.GovKeeper.SetProposal(its.network.GetContext(), newProposal)
}
33 changes: 33 additions & 0 deletions proto/evmos/incentives/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright Tharsis Labs Ltd.(Evmos)
// SPDX-License-Identifier:ENCL-1.0(https://github.com/evmos/evmos/blob/main/LICENSE)
syntax = "proto3";
package evmos.incentives.v1;
import "evmos/incentives/v1/incentives.proto";

import "gogoproto/gogo.proto";

option go_package = "github.com/evmos/evmos/v16/x/incentives/types";

// GenesisState defines the module's genesis state.
message GenesisState {
// params are the incentives module parameters
Params params = 1 [(gogoproto.nullable) = false];
// incentives is a slice of active incentives
repeated Incentive incentives = 2 [(gogoproto.nullable) = false];
// gas_meters is a slice of active Gasmeters
repeated GasMeter gas_meters = 3 [(gogoproto.nullable) = false];
}

// Params defines the incentives module params
message Params {
// enable_incentives is the parameter to enable incentives
bool enable_incentives = 1;
// allocation_limit is the maximum percentage an incentive can allocate per denomination
string allocation_limit = 2
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
// incentives_epoch_identifier for the epochs module hooks
string incentives_epoch_identifier = 3;
// reward_scaler is the scaling factor for capping rewards
string reward_scaler = 4
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
}
61 changes: 61 additions & 0 deletions proto/evmos/incentives/v1/incentives.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright Tharsis Labs Ltd.(Evmos)
// SPDX-License-Identifier:ENCL-1.0(https://github.com/evmos/evmos/blob/main/LICENSE)
syntax = "proto3";
package evmos.incentives.v1;

import "cosmos/base/v1beta1/coin.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
option go_package = "github.com/evmos/evmos/v16/x/incentives/types";

// Incentive defines an instance that organizes distribution conditions for a
// given smart contract
message Incentive {
// contract address of the smart contract to be incentivized
string contract = 1;
// allocations is a slice of denoms and percentages of rewards to be allocated
repeated cosmos.base.v1beta1.DecCoin allocations = 2
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins"];
// epochs defines the number of remaining epochs for the incentive
uint32 epochs = 3;
// start_time of the incentive distribution
google.protobuf.Timestamp start_time = 4 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
// total_gas is the cumulative gas spent by all gas meters of the incentive during the epoch
uint64 total_gas = 5;
}
// GasMeter tracks the cumulative gas spent per participant in one epoch
message GasMeter {
// contract is the hex address of the incentivized smart contract
string contract = 1;
// participant address that interacts with the incentive
string participant = 2;
// cumulative_gas spent during the epoch
uint64 cumulative_gas = 3;
}

// RegisterIncentiveProposal is a gov Content type to register an incentive
message RegisterIncentiveProposal {
option (gogoproto.equal) = false;
// title of the proposal
string title = 1;
// description of the proposal
string description = 2;
// contract address to be registered
string contract = 3;
// allocations defines the denoms and percentage of rewards to be allocated
repeated cosmos.base.v1beta1.DecCoin allocations = 4
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins"];
// epochs is the number of remaining epochs for the incentive
uint32 epochs = 5;
}

// CancelIncentiveProposal is a gov Content type to cancel an incentive
message CancelIncentiveProposal {
option (gogoproto.equal) = false;
// title of the proposal
string title = 1;
// description of the proposal
string description = 2;
// contract address of the incentivized smart contract
string contract = 3;
}