Skip to content

Commit

Permalink
SDK & IBC Base
Browse files Browse the repository at this point in the history
  • Loading branch information
glnro committed May 25, 2023
1 parent 42a66c9 commit 8b64e45
Show file tree
Hide file tree
Showing 171 changed files with 9,609 additions and 15,947 deletions.
37 changes: 25 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ endif
PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
LEDGER_ENABLED ?= true
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')
TM_VERSION := $(shell go list -m github.com/tendermint/tendermint | sed 's:.* ::') # grab everything after the space in "github.com/tendermint/tendermint v0.34.7"
DOCKER := $(shell which docker)
BUILDDIR ?= $(CURDIR)/build
TEST_DOCKER_REPO=cosmos/contrib-gaiatest
Expand Down Expand Up @@ -69,7 +68,6 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=gaia \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \
-X github.com/tendermint/tendermint/version.TMCoreSemVer=$(TM_VERSION)

ifeq (cleveldb,$(findstring cleveldb,$(GAIA_BUILD_OPTIONS)))
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
Expand Down Expand Up @@ -248,9 +246,9 @@ start-localnet-ci: build
./build/gaiad config chain-id liveness --home ~/.gaiad-liveness
./build/gaiad config keyring-backend test --home ~/.gaiad-liveness
./build/gaiad keys add val --home ~/.gaiad-liveness
./build/gaiad add-genesis-account val 10000000000000000000000000stake --home ~/.gaiad-liveness --keyring-backend test
./build/gaiad gentx val 1000000000stake --home ~/.gaiad-liveness --chain-id liveness
./build/gaiad collect-gentxs --home ~/.gaiad-liveness
./build/gaiad genesis add-genesis-account val 10000000000000000000000000stake --home ~/.gaiad-liveness --keyring-backend test
./build/gaiad genesis gentx val 1000000000stake --home ~/.gaiad-liveness --chain-id liveness
./build/gaiad genesis collect-gentxs --home ~/.gaiad-liveness
sed -i.bak'' 's/minimum-gas-prices = ""/minimum-gas-prices = "0uatom"/' ~/.gaiad-liveness/config/app.toml
./build/gaiad start --home ~/.gaiad-liveness --x-crisis-skip-assert-invariants

Expand All @@ -277,16 +275,31 @@ test-docker-push: test-docker
###############################################################################
### Protobuf ###
###############################################################################
protoVer=0.13.0
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)

proto-all: proto-format proto-lint proto-gen

proto-gen:
@echo "Generating Protobuf files"
@sh ./proto/scripts/protocgen.sh

proto-doc:
@echo "Generating Protoc docs"
@sh ./proto/scripts/protoc-doc-gen.sh
@$(protoImage) sh ./proto/scripts/protocgen.sh

proto-swagger-gen:
@echo "Generating Protobuf Swagger"
@sh ./proto/scripts/protoc-swagger-gen.sh
@$(protoImage) sh ./proto/scripts/protoc-swagger-gen.sh

proto-format:
@$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \;

proto-lint:
@$(protoImage) buf lint --error-format=json

proto-check-breaking:
@$(protoImage) buf breaking --against $(HTTPS_GIT)#branch=main

proto-update-deps:
@echo "Updating Protobuf dependencies"
$(DOCKER) run --rm -v $(CURDIR)/proto:/workspace --workdir /workspace $(protoImageName) buf mod update

.PHONY: proto-gen proto-doc proto-swagger-gen
.PHONY: proto-all proto-gen proto-gen-any proto-swagger-gen proto-format proto-lint proto-check-breaking proto-update-deps
22 changes: 11 additions & 11 deletions ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/ante"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
ibcante "github.com/cosmos/ibc-go/v4/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper"

gaiafeeante "github.com/cosmos/gaia/v10/x/globalfee/ante"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
Expand All @@ -37,9 +35,10 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
if opts.IBCkeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "IBC keeper is required for AnteHandler")
}
if opts.GlobalFeeSubspace.Name() == "" {
return nil, sdkerrors.Wrap(sdkerrors.ErrNotFound, "globalfee param store is required for AnteHandler")
}
// TODO: Enable with Globalfee
// if opts.GlobalFeeSubspace.Name() == "" {
// return nil, sdkerrors.Wrap(sdkerrors.ErrNotFound, "globalfee param store is required for AnteHandler")
//}
if opts.StakingSubspace.Name() == "" {
return nil, sdkerrors.Wrap(sdkerrors.ErrNotFound, "staking param store is required for AnteHandler")
}
Expand All @@ -54,20 +53,21 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
ante.NewRejectExtensionOptionsDecorator(),
ante.NewExtensionOptionsDecorator(opts.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(opts.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper),
NewGovPreventSpamDecorator(opts.Codec, opts.GovKeeper),
gaiafeeante.NewFeeDecorator(opts.GlobalFeeSubspace, opts.StakingSubspace),
ante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper),
// TODO: Enable with GlobalFee
// gaiafeeante.NewFeeDecorator(opts.GlobalFeeSubspace, opts.StakingSubspace),
ante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, opts.TxFeeChecker),
ante.NewSetPubKeyDecorator(opts.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(opts.AccountKeeper),
ante.NewSigGasConsumeDecorator(opts.AccountKeeper, sigGasConsumer),
ante.NewSigVerificationDecorator(opts.AccountKeeper, opts.SignModeHandler),
ante.NewIncrementSequenceDecorator(opts.AccountKeeper),
ibcante.NewAnteDecorator(opts.IBCkeeper),
ibcante.NewRedundantRelayDecorator(opts.IBCkeeper),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
Expand Down
8 changes: 4 additions & 4 deletions ante/gov_ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/authz"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

// initial deposit must be greater than or equal to 10% of the minimum deposit
Expand Down Expand Up @@ -44,10 +44,10 @@ func (g GovPreventSpamDecorator) AnteHandle(
// validateGovMsgs checks if the InitialDeposit amounts are greater than the minimum initial deposit amount
func (g GovPreventSpamDecorator) ValidateGovMsgs(ctx sdk.Context, msgs []sdk.Msg) error {
validMsg := func(m sdk.Msg) error {
if msg, ok := m.(*govtypes.MsgSubmitProposal); ok {
if msg, ok := m.(*govv1beta1.MsgSubmitProposal); ok {
// prevent messages with insufficient initial deposit amount
depositParams := g.govKeeper.GetDepositParams(ctx)
minInitialDeposit := g.calcMinInitialDeposit(depositParams.MinDeposit)
params := g.govKeeper.GetParams(ctx)
minInitialDeposit := g.calcMinInitialDeposit(params.MinDeposit)
if msg.InitialDeposit.IsAllLT(minInitialDeposit) {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "insufficient initial deposit amount - required: %v", minInitialDeposit)
}
Expand Down
89 changes: 44 additions & 45 deletions ante/gov_ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/stretchr/testify/suite"

tmrand "github.com/cometbft/cometbft/libs/rand"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/cosmos/gaia/v10/ante"
gaiahelpers "github.com/cosmos/gaia/v10/app/helpers"

gaiaapp "github.com/cosmos/gaia/v10/app"
Expand Down Expand Up @@ -41,53 +39,54 @@ func (s *GovAnteHandlerTestSuite) SetupTest() {
Height: 1,
})

encodingConfig := gaiaapp.MakeTestEncodingConfig()
encodingConfig.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil)
testdata.RegisterInterfaces(encodingConfig.InterfaceRegistry)
legacyAmino := app.LegacyAmino()
legacyAmino.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil)
testdata.RegisterInterfaces(app.InterfaceRegistry())

s.app = app
s.ctx = ctx
s.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig)
s.clientCtx = client.Context{}.WithTxConfig(app.GetTxConfig())
}

func TestGovSpamPreventionSuite(t *testing.T) {
suite.Run(t, new(GovAnteHandlerTestSuite))
}

func (s *GovAnteHandlerTestSuite) TestGlobalFeeMinimumGasFeeAnteHandler() {
// setup test
s.SetupTest()
tests := []struct {
title, description string
proposalType string
proposerAddr sdk.AccAddress
initialDeposit sdk.Coins
expectPass bool
}{
{"Passing proposal 1", "the purpose of this proposal is to pass", govtypes.ProposalTypeText, testAddr, minCoins, true},
{"Passing proposal 2", "the purpose of this proposal is to pass with more coins than minimum", govtypes.ProposalTypeText, testAddr, moreThanMinCoins, true},
{"Failing proposal", "the purpose of this proposal is to fail", govtypes.ProposalTypeText, testAddr, insufficientCoins, false},
}

decorator := ante.NewGovPreventSpamDecorator(s.app.AppCodec(), &s.app.GovKeeper)

for _, tc := range tests {
content := govtypes.ContentFromProposalType(tc.title, tc.description, tc.proposalType)
s.Require().NotNil(content)

msg, err := govtypes.NewMsgSubmitProposal(
content,
tc.initialDeposit,
tc.proposerAddr,
)

s.Require().NoError(err)

err = decorator.ValidateGovMsgs(s.ctx, []sdk.Msg{msg})
if tc.expectPass {
s.Require().NoError(err, "expected %v to pass", tc.title)
} else {
s.Require().Error(err, "expected %v to fail", tc.title)
}
}
}
// TODO: Enable with Global Fee
// func (s *GovAnteHandlerTestSuite) TestGlobalFeeMinimumGasFeeAnteHandler() {
// // setup test
// s.SetupTest()
// tests := []struct {
// title, description string
// proposalType string
// proposerAddr sdk.AccAddress
// initialDeposit sdk.Coins
// expectPass bool
// }{
// {"Passing proposal 1", "the purpose of this proposal is to pass", govv1beta1.ProposalTypeText, testAddr, minCoins, true},
// {"Passing proposal 2", "the purpose of this proposal is to pass with more coins than minimum", govv1beta1.ProposalTypeText, testAddr, moreThanMinCoins, true},
// {"Failing proposal", "the purpose of this proposal is to fail", govv1beta1.ProposalTypeText, testAddr, insufficientCoins, false},
// }
//
// decorator := ante.NewGovPreventSpamDecorator(s.app.AppCodec(), &s.app.GovKeeper)
//
// for _, tc := range tests {
// content, _ := govv1beta1.ContentFromProposalType(tc.title, tc.description, tc.proposalType)
// s.Require().NotNil(content)
//
// msg, err := govv1beta1.NewMsgSubmitProposal(
// content,
// tc.initialDeposit,
// tc.proposerAddr,
// )
//
// s.Require().NoError(err)
//
// err = decorator.ValidateGovMsgs(s.ctx, []sdk.Msg{msg})
// if tc.expectPass {
// s.Require().NoError(err, "expected %v to pass", tc.title)
// } else {
// s.Require().Error(err, "expected %v to fail", tc.title)
// }
// }
//}
Loading

0 comments on commit 8b64e45

Please sign in to comment.