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

feat: add v2.1 upgrade handler #121

Merged
merged 11 commits into from
Aug 18, 2023
28 changes: 13 additions & 15 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
name: Lint
# Lint runs golangci-lint over the entire passage3d repository
# This workflow is run on every pull request and push to master
# The `golangci` will pass without running if no *.{go, mod, sum} files have been changed.
on:
pull_request:
push:
tags:
- v*
branches:
- master
- main
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: technote-space/[email protected]
- uses: actions/setup-go@v3
with:
PATTERNS: |
**/**.go
go.mod
go.sum
go-version: 1.19
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: latest
skip-go-installation: true
if: env.GIT_DIFF
version: 1.49.0
3 changes: 3 additions & 0 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/ante"
ibcante "github.com/cosmos/ibc-go/v4/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper"

passageante "github.com/envadiv/Passage3D/app/ante"
)

// HandlerOptions are the options required for constructing a default SDK AnteHandler.
Expand Down Expand Up @@ -50,6 +52,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper),
passageante.NewBlockAccountDecorator(),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
Expand Down
60 changes: 60 additions & 0 deletions app/ante/block.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package ante

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authztypes "github.com/cosmos/cosmos-sdk/x/authz"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
)

const blockedMultisigAddr = "pasg105488mw9t3qtp62jhllde28v40xqxpjksjqmvx"

// BlockAccountDecorator restricts the community pool multisig account's transactions, except for the community fund.
// Call next AnteHandler if the message is allowed
type BlockAccountDecorator struct{}

func NewBlockAccountDecorator() BlockAccountDecorator {
return BlockAccountDecorator{}
}

func (bad BlockAccountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
if simulate {
return next(ctx, tx, simulate)
}

msgs := tx.GetMsgs()
// handle msg based on type
if err := handleMessages(msgs); err != nil {
return ctx, err
}

return next(ctx, tx, simulate)
}

// handleMessages check and handle each msg with rules
func handleMessages(msgs []sdk.Msg) error {
for _, msg := range msgs {

if msgExec, ok := msg.(*authztypes.MsgExec); ok {
msgs, err := msgExec.GetMessages()
if err != nil {
return err
}

if err := handleMessages(msgs); err != nil {
return err
}
} else if _, ok := msg.(*distributiontypes.MsgFundCommunityPool); ok {
return nil
}

signers := msg.GetSigners()
for _, signer := range signers {
if signer.String() == blockedMultisigAddr {
return sdkerrors.ErrUnauthorized.Wrapf("%s is not allowed to perform this transaction", blockedMultisigAddr)
}
}
}

return nil
}
21 changes: 21 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"strings"

appparams "github.com/envadiv/Passage3D/app/params"
"github.com/envadiv/Passage3D/app/upgrades"
v1 "github.com/envadiv/Passage3D/app/upgrades/v1"

"github.com/envadiv/Passage3D/x/claim"

Expand Down Expand Up @@ -185,6 +187,8 @@ var (
claimtypes.ModuleName: {authtypes.Minter},
wasm.ModuleName: {authtypes.Burner},
}

Upgrades = []upgrades.Upgrade{v1.Upgrade}
)

var (
Expand Down Expand Up @@ -574,6 +578,8 @@ func NewPassageApp(
// add test gRPC service for testing gRPC queries in isolation
testdata.RegisterQueryServer(app.GRPCQueryRouter(), testdata.QueryImpl{})

app.setupUpgradeHandlers()

// create the simulation manager and define the order of the modules for deterministic simulations
//
// NOTE: this is not required apps that don't use the simulator for fuzz testing
Expand Down Expand Up @@ -638,6 +644,21 @@ func NewPassageApp(
return app
}

func (app *PassageApp) setupUpgradeHandlers() {
for _, upgrade := range Upgrades {
app.UpgradeKeeper.SetUpgradeHandler(
upgrade.UpgradeName,
upgrade.CreateUpgradeHandler(
app.mm,
app.configurator,
app.DistrKeeper,
app.BankKeeper,
app.AccountKeeper,
),
)
}
}

// Name returns the name of the App
func (app *PassageApp) Name() string { return app.BaseApp.Name() }

Expand Down
25 changes: 25 additions & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package upgrades

import (
store "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/types/module"
auth "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bank "github.com/cosmos/cosmos-sdk/x/bank/keeper"
distribution "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
anilcse marked this conversation as resolved.
Show resolved Hide resolved
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal
// must have written, in order for the state migration to go smoothly.
// An upgrade must implement this struct, and then set it in the app.go.
// The app.go will then define the handler.
type Upgrade struct {
// Upgrade version name, for the upgrade handler, e.g. `v1`
UpgradeName string

// CreateUpgradeHandler defines the function that creates an upgrade handler
CreateUpgradeHandler func(*module.Manager, module.Configurator, distribution.Keeper, bank.Keeper, auth.AccountKeeper) upgradetypes.UpgradeHandler

// Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed.
StoreUpgrades store.StoreUpgrades
}
77 changes: 77 additions & 0 deletions app/upgrades/v1/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package v1

import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
auth "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
bank "github.com/cosmos/cosmos-sdk/x/bank/keeper"
distribution "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/envadiv/Passage3D/app/upgrades"
)

const Name = "v2.1"
const upasgDenom = "upasg"

// 150,000,000 $PASG tokens
var amount = sdk.NewCoins(sdk.NewCoin(upasgDenom, sdk.NewInt(150000000000000)))
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved

var Upgrade = upgrades.Upgrade{
UpgradeName: Name,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: storetypes.StoreUpgrades{},
}

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
dk distribution.Keeper,
bk bank.Keeper,
ak auth.AccountKeeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
if err := ExecuteProposal(ctx, dk, bk, ak); err != nil {
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved
return nil, err
}

return fromVM, nil
}
}

// ExecuteProposal moves community pool funds to a multisig vesting account
func ExecuteProposal(ctx sdk.Context, dk distribution.Keeper, bk bank.Keeper, ak auth.AccountKeeper) error {
vestingAcc, err := sdk.AccAddressFromBech32("pasg105488mw9t3qtp62jhllde28v40xqxpjksjqmvx")
if err != nil {
return err
}

// 3 year lock-up from relaunch and thereafter weekly vesting until end of year 5 from relaunch
pva := vestingtypes.NewPeriodicVestingAccount(authtypes.NewBaseAccount(vestingAcc, nil, ak.GetNextAccountNumber(ctx), 0),
amount,
1784905200,
genVestingPeriods(),
)
ak.SetAccount(ctx, pva)

return dk.DistributeFromFeePool(ctx, amount, vestingAcc)
}

func genVestingPeriods() []vestingtypes.Period {
var periods []vestingtypes.Period
periods = append(periods, vestingtypes.Period{
Length: 0,
Amount: sdk.NewCoins(sdk.NewCoin(upasgDenom, sdk.NewInt(1442307692379))),
})

for i := 0; i < 103; i++ {
periods = append(periods, vestingtypes.Period{
Length: 604800,
Amount: sdk.NewCoins(sdk.NewCoin(upasgDenom, sdk.NewInt(1442307692307))),
})
}

return periods
}
Loading