Skip to content

Commit

Permalink
chore(upgrade): remove deprecated gov proposals (incentives) (#2196)
Browse files Browse the repository at this point in the history
* wip - add remove proposal logic

* add incentives code

* keep only incentives types

* update tests

* update upgrade logic

* remove unnecessary types

* update upgrade logic

* update comments

* make format

* fix lint issues

* add changelog entry

* update upgrade logic

(cherry picked from commit 7dfc497)

# Conflicts:
#	app/app.go
#	app/upgrades/v16/proposals.go
#	app/upgrades/v16/upgrades.go
#	app/upgrades/v16/upgrades_test.go
  • Loading branch information
GAtom22 authored and mergify[bot] committed Dec 18, 2023
1 parent 5d51d37 commit b21ed82
Show file tree
Hide file tree
Showing 13 changed files with 2,737 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,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
7 changes: 7 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,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 @@ -238,6 +239,7 @@ var (
epochs.AppModuleBasic{},
revenue.AppModuleBasic{},
consensus.AppModuleBasic{},
incentives.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -1257,6 +1259,11 @@ func (app *Evmos) setupUpgradeHandlers() {
app.mm, app.configurator,
app.EvmKeeper,
app.InflationKeeper,
<<<<<<< HEAD

Check failure on line 1262 in app/app.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

expected operand, found '<<' (typecheck)
=======
app.AccountKeeper,
app.GovKeeper,
>>>>>>> 7dfc497e (chore(upgrade): remove deprecated gov proposals (incentives) (#2196))
),
)

Expand Down
45 changes: 45 additions & 0 deletions app/upgrades/v16/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package v16

<<<<<<< HEAD

Check failure on line 6 in app/upgrades/v16/proposals.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

expected declaration, found '<<' (typecheck)

Check failure on line 6 in app/upgrades/v16/proposals.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected declaration, found '<<'

Check failure on line 6 in app/upgrades/v16/proposals.go

View workflow job for this annotation

GitHub Actions / format-go-code

expected declaration, found '<<'
// DeleteRegisterIncentivesProposals deletes the RegisterIncentives proposals from the store
// func DeleteRegisterIncentivesProposals(ctx sdk.Context, gk govkeeper.Keeper, logger log.Logger) {
// // Delete the only RegisterIncentives proposal
Expand All @@ -29,3 +30,47 @@ package v16
// return true
// })
// }
=======
import (

Check failure on line 34 in app/upgrades/v16/proposals.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

imports must appear before other declarations (typecheck)

Check failure on line 34 in app/upgrades/v16/proposals.go

View workflow job for this annotation

GitHub Actions / dependency-review

imports must appear before other declarations

Check failure on line 34 in app/upgrades/v16/proposals.go

View workflow job for this annotation

GitHub Actions / format-go-code

imports must appear before other declarations
"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
})
}
>>>>>>> 7dfc497e (chore(upgrade): remove deprecated gov proposals (incentives) (#2196))

Check failure on line 76 in app/upgrades/v16/proposals.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

expected declaration, found '>>' (typecheck)

Check failure on line 76 in app/upgrades/v16/proposals.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected declaration, found '>>'

Check failure on line 76 in app/upgrades/v16/proposals.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal character U+0023 '#'

Check failure on line 76 in app/upgrades/v16/proposals.go

View workflow job for this annotation

GitHub Actions / format-go-code

expected declaration, found '>>'

Check failure on line 76 in app/upgrades/v16/proposals.go

View workflow job for this annotation

GitHub Actions / format-go-code

illegal character U+0023 '#'
28 changes: 28 additions & 0 deletions app/upgrades/v16/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
<<<<<<< HEAD

Check failure on line 9 in app/upgrades/v16/upgrades.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

missing import path (typecheck)

Check failure on line 9 in app/upgrades/v16/upgrades.go

View workflow job for this annotation

GitHub Actions / test-unit-cover

missing import path

Check failure on line 9 in app/upgrades/v16/upgrades.go

View workflow job for this annotation

GitHub Actions / test-solidity

missing import path

Check failure on line 9 in app/upgrades/v16/upgrades.go

View workflow job for this annotation

GitHub Actions / test-solidity

missing import path

Check failure on line 9 in app/upgrades/v16/upgrades.go

View workflow job for this annotation

GitHub Actions / dependency-review

missing import path

Check failure on line 9 in app/upgrades/v16/upgrades.go

View workflow job for this annotation

GitHub Actions / dependency-review

missing import path

Check failure on line 9 in app/upgrades/v16/upgrades.go

View workflow job for this annotation

GitHub Actions / format-go-code

missing import path
=======

Check failure on line 10 in app/upgrades/v16/upgrades.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

missing import path (typecheck)

Check failure on line 10 in app/upgrades/v16/upgrades.go

View workflow job for this annotation

GitHub Actions / dependency-review

missing import path
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
>>>>>>> 7dfc497e (chore(upgrade): remove deprecated gov proposals (incentives) (#2196))

Check failure on line 13 in app/upgrades/v16/upgrades.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

missing import path (typecheck)

Check failure on line 13 in app/upgrades/v16/upgrades.go

View workflow job for this annotation

GitHub Actions / dependency-review

missing import path

Check failure on line 13 in app/upgrades/v16/upgrades.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected ';', found ':'

Check failure on line 13 in app/upgrades/v16/upgrades.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal character U+0023 '#'
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 @@ -22,6 +27,11 @@ func CreateUpgradeHandler(
configurator module.Configurator,
ek *evmkeeper.Keeper,
inflationKeeper inflationkeeper.Keeper,
<<<<<<< HEAD
=======
ak authkeeper.AccountKeeper,
gk govkeeper.Keeper,
>>>>>>> 7dfc497e (chore(upgrade): remove deprecated gov proposals (incentives) (#2196))

Check failure on line 34 in app/upgrades/v16/upgrades.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

illegal character U+0023 '#' (typecheck)
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {

Check failure on line 36 in app/upgrades/v16/upgrades.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

expected declaration, found 'return' (typecheck)
logger := ctx.Logger().With("upgrade", UpgradeName)
Expand All @@ -42,10 +52,28 @@ func CreateUpgradeHandler(
logger.Error("failed to enable outposts", "error", err.Error())
}

<<<<<<< HEAD
=======
// Migrate the FeeCollector module account to include the Burner permission.
// 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())
// }

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

Check failure on line 68 in app/upgrades/v16/upgrades.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

illegal character U+0023 '#' (typecheck)
if err := UpdateInflationParams(ctx, inflationKeeper); err != nil {
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
79 changes: 79 additions & 0 deletions app/upgrades/v16/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,26 @@
package v16_test

import (
"time"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
<<<<<<< HEAD

Check failure on line 11 in app/upgrades/v16/upgrades_test.go

View workflow job for this annotation

GitHub Actions / format-go-code

missing import path
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
=======

Check failure on line 13 in app/upgrades/v16/upgrades_test.go

View workflow job for this annotation

GitHub Actions / format-go-code

missing import path
"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"

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

Check failure on line 19 in app/upgrades/v16/upgrades_test.go

View workflow job for this annotation

GitHub Actions / format-go-code

missing import path

Check failure on line 19 in app/upgrades/v16/upgrades_test.go

View workflow job for this annotation

GitHub Actions / format-go-code

illegal character U+0023 '#'
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"
)

// TODO: Uncomment this test when RegisterIncentives is re-enabled
Expand Down Expand Up @@ -113,3 +127,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} {

Check failure on line 164 in app/upgrades/v16/upgrades_test.go

View workflow job for this annotation

GitHub Actions / format-go-code

expected declaration, found 'for'
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;
}

0 comments on commit b21ed82

Please sign in to comment.