Skip to content

Commit

Permalink
v2.2.0 upgrade (#129)
Browse files Browse the repository at this point in the history
* feat: add v2.1 upgrade handler (#121)

* feat: add upgrade handler

* chore: fix bech32 error

* chore: fix typo

* feat: add ante handler to block account

* chore: fix vesting unlock time

* Update app/upgrades/v1/upgrade.go

Co-authored-by: Anil K <[email protected]>

* Update app/upgrades/v1/upgrade.go

Co-authored-by: Anil K <[email protected]>

* chore: add depgaurd config

* chore: update linter

* chore: try fixing linter

---------

Co-authored-by: Anil K <[email protected]>

* CV FIX: wasm snapshot (#124)

* Add Wasm to Snapshot

* Update app/app.go

---------

Co-authored-by: Anil K <[email protected]>

* fix keyring deprecated issue for mac (#123)

Co-authored-by: Anil K <[email protected]>

* chore: update docker to support wasmvm (#120)

Co-authored-by: Anil K <[email protected]>

* feat: add upgrade handler `v2.2.0` (#128)

* chore: add upgrade handler `v2.2.0`

* fix claim records

* update time

* fix panic

* changes

* add claim records from snapshots

* suggestions

* review changes

* review changes

* Update app/upgrades/v2.2.0/upgrade.go

* fix amount sim bug

* add logs

* log

* log

* Fix airdrop amounts

* fix build

* fix

* review changes

* Update x/claim/keeper/claim.go

* test calc

* small fix

* another handle

* handle more coin errors

* revert

* add snapshot1 data directly

* update data

* sub original claim allocation

* review changes

* Update app/upgrades/v2.2.0/upgrade.go

* update go.mod

---------

Co-authored-by: Anil K <[email protected]>
Co-authored-by: Anil K <[email protected]>

* Update .github/workflows/lint.yml

---------

Co-authored-by: MD Aleem <[email protected]>
Co-authored-by: Chill Validation <[email protected]>
Co-authored-by: Bala Murali Krishna Komatireddy <[email protected]>
Co-authored-by: Jay Namsayin <[email protected]>
Co-authored-by: atheeshp <[email protected]>
Co-authored-by: Anil K <[email protected]>
  • Loading branch information
7 people authored Oct 16, 2023
1 parent 1cdb42d commit d3e462a
Show file tree
Hide file tree
Showing 12 changed files with 6,027 additions and 69 deletions.
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.20
- 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
47 changes: 15 additions & 32 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,42 +1,25 @@
# Simple usage with a mounted data directory:
# > docker build -t simapp .
#
# Server:
# > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simapp:/root/.simapp simapp simd init test-chain
# TODO: need to set validator in genesis so start runs
# > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simapp:/root/.simapp simapp simd start
#
# Client: (Note the simapp binary always looks at ~/.simapp we can bind to different local storage)
# > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simappcli:/root/.simapp simapp simd keys add foo
# > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simappcli:/root/.simapp simapp simd keys list
# TODO: demo connecting rest-server (or is this in server now?)
FROM golang:alpine AS build-env

# Install minimum necessary dependencies,
ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3
RUN apk add --no-cache $PACKAGES

# Set working directory for the build
WORKDIR /go/src/github.com/cosmos/cosmos-sdk

# Add source files
FROM golang:1.20.5-alpine AS build-env

# Set up dependencies
ENV PACKAGES bash curl make git libc-dev gcc linux-headers eudev-dev python3

# ADD . /code
WORKDIR /code

COPY . .

# install simapp, remove packages
RUN make build-linux
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.2.1/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.a

RUN apk add --no-cache $PACKAGES && \
BUILD_TAGS=muslc LINK_STATICALLY=true make install && \
rm -rf /var/cache/apk/*

# Final image
FROM alpine:edge

# Install ca-certificates
RUN apk add --update ca-certificates
WORKDIR /root

# Copy over binaries from the build-env
COPY --from=build-env /go/src/github.com/cosmos/cosmos-sdk/build/simd /usr/bin/simd
WORKDIR /code

EXPOSE 26656 26657 1317 9090
COPY --from=build-env /go/bin/passage /usr/local/bin/passage

# Run simd by default, omit entrypoint to ease using container with simcli
CMD ["simd"]
CMD ["passage"]
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

ifeq ($(LINK_STATICALLY),true)
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))

Expand Down
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
}
33 changes: 33 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"
"github.com/envadiv/Passage3D/app/upgrades/v2.2.0"

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

Expand Down Expand Up @@ -103,6 +105,7 @@ import (

"github.com/CosmWasm/wasmd/x/wasm"
wasmclient "github.com/CosmWasm/wasmd/x/wasm/client"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
Expand Down Expand Up @@ -185,6 +188,8 @@ var (
claimtypes.ModuleName: {authtypes.Minter},
wasm.ModuleName: {authtypes.Burner},
}

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

var (
Expand Down Expand Up @@ -574,6 +579,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 @@ -629,6 +636,16 @@ func NewPassageApp(
app.SetAnteHandler(anteHandler)
app.SetEndBlocker(app.EndBlocker)

// Register snapshot extensions to enable state-sync for wasm.
if manager := app.SnapshotManager(); manager != nil {
err = manager.RegisterExtensions(
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.WasmKeeper),
)
if err != nil {
panic("failed to register snapshot extension: " + err.Error())
}
}

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
Expand All @@ -638,6 +655,22 @@ 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,
app.ClaimKeeper,
),
)
}
}

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

Expand Down
26 changes: 26 additions & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
claim "github.com/envadiv/Passage3D/x/claim/keeper"
)

// 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, claim.Keeper) upgradetypes.UpgradeHandler

// Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed.
StoreUpgrades store.StoreUpgrades
}
Loading

0 comments on commit d3e462a

Please sign in to comment.