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

Back port Releases/v2.x #159

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading