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

refactor(x/**): rewrite ante handlers as tx validators #20488

Merged
merged 11 commits into from
Jun 3, 2024
5 changes: 5 additions & 0 deletions contrib/images/simd-env/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ COPY x/bank/go.mod x/bank/go.sum /work/x/bank/
COPY x/mint/go.mod x/mint/go.sum /work/x/mint/
COPY x/consensus/go.mod x/consensus/go.sum /work/x/consensus/
COPY x/accounts/go.mod x/accounts/go.sum /work/x/accounts/
COPY runtime/v2/go.mod runtime/v2/go.sum /work/runtime/v2/
COPY server/v2/appmanager/go.mod server/v2/appmanager/go.sum /work/server/v2/appmanager/
COPY server/v2/core/go.mod server/v2/core/go.sum /work/server/v2/core/
COPY server/v2/stf/go.mod server/v2/stf/go.sum /work/server/v2/stf/

RUN go mod download

COPY ./ /work
Expand Down
2 changes: 1 addition & 1 deletion runtime/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require (
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cosmos/cosmos-db v1.0.2 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
github.com/cosmos/iavl v1.1.4 // indirect
github.com/cosmos/iavl v1.2.0 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/dot v1.6.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions runtime/v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ github.com/cosmos/cosmos-proto v1.0.0-beta.5 h1:eNcayDLpip+zVLRLYafhzLvQlSmyab+R
github.com/cosmos/cosmos-proto v1.0.0-beta.5/go.mod h1:hQGLpiIUloJBMdQMMWb/4wRApmI9hjHH05nefC0Ojec=
github.com/cosmos/gogoproto v1.4.12 h1:vB6Lbe/rtnYGjQuFxkPiPYiCybqFT8QvLipDZP8JpFE=
github.com/cosmos/gogoproto v1.4.12/go.mod h1:LnZob1bXRdUoqMMtwYlcR3wjiElmlC+FkjaZRv1/eLY=
github.com/cosmos/iavl v1.1.4 h1:Z0cVVjeQqOUp78/nWt/uhQy83vYluWlAMGQ4zbH9G34=
github.com/cosmos/iavl v1.1.4/go.mod h1:vCYmRQUJU1wwj0oRD3wMEtOM9sJNDP+GFMaXmIxZ/rU=
github.com/cosmos/iavl v1.2.0 h1:kVxTmjTh4k0Dh1VNL046v6BXqKziqMDzxo93oh3kOfM=
github.com/cosmos/iavl v1.2.0/go.mod h1:HidWWLVAtODJqFD6Hbne2Y0q3SdxByJepHUOeoH4LiI=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down
20 changes: 18 additions & 2 deletions server/mock/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"bytes"
"fmt"

"google.golang.org/protobuf/reflect/protoreflect"

bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1"
"cosmossdk.io/core/transaction"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/x/auth/signing"
"google.golang.org/protobuf/reflect/protoreflect"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -95,6 +95,22 @@ func NewTx(key, value string, accAddress sdk.AccAddress) *KVStoreTx {
}
}

func (msg *KVStoreTx) Hash() [32]byte {
return [32]byte{}
}

func (msg *KVStoreTx) GetGasLimit() (uint64, error) {
return 0, nil
}

func (msg *KVStoreTx) GetMessages() ([]transaction.Msg, error) {
return nil, nil
}

func (msg *KVStoreTx) GetSenders() ([][]byte, error) {
return nil, nil
}

func (msg *KVStoreTx) Type() string {
return "kvstore_tx"
}
Expand Down
3 changes: 3 additions & 0 deletions server/v2/stf/mock/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ func (t Tx) Hash() [32]byte {
}

func (t Tx) GetMessages() ([]transaction.Msg, error) {
if t.Msg == nil {
return nil, errors.New("messages not available or are nil")
}
return []transaction.Msg{t.Msg}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion simapp/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
circuitante.NewCircuitBreakerDecorator(options.CircuitKeeper),
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(options.Environment),
ante.NewTxTimeoutHeightDecorator(),
ante.NewTxTimeoutHeightDecorator(options.Environment),
ante.NewUnorderedTxDecorator(unorderedtx.DefaultMaxUnOrderedTTL, options.TxManager, options.Environment),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
Expand Down
41 changes: 41 additions & 0 deletions types/mempool/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
_ "cosmossdk.io/api/cosmos/counter/v1"
_ "cosmossdk.io/api/cosmos/crypto/secp256k1"
"cosmossdk.io/core/log"
"cosmossdk.io/core/transaction"
"cosmossdk.io/x/auth/signing"

codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
Expand Down Expand Up @@ -75,6 +76,26 @@ var (
_ cryptotypes.PubKey = (*testPubKey)(nil)
)

func (tx testTx) Bytes() []byte {
return []byte{}
}

func (tx testTx) Hash() [32]byte {
return [32]byte{}
}

func (tx testTx) GetGasLimit() (uint64, error) {
return 0, nil
}

func (tx testTx) GetMessages() ([]transaction.Msg, error) {
return nil, nil
}

func (tx testTx) GetSenders() ([][]byte, error) {
return nil, nil
}

func (tx testTx) GetMsgs() []sdk.Msg { return nil }

func (tx testTx) GetReflectMessages() ([]protoreflect.Message, error) { return nil, nil }
Expand All @@ -89,6 +110,26 @@ type sigErrTx struct {
getSigs func() ([]txsigning.SignatureV2, error)
}

func (sigErrTx) Bytes() []byte {
return []byte{}
}

func (sigErrTx) Hash() [32]byte {
return [32]byte{}
}

func (sigErrTx) GetGasLimit() (uint64, error) {
return 0, nil
}

func (sigErrTx) GetMessages() ([]transaction.Msg, error) {
return nil, nil
}

func (sigErrTx) GetSenders() ([][]byte, error) {
return nil, nil
}

func (sigErrTx) Size() int64 { return 0 }

func (sigErrTx) GetMsgs() []sdk.Msg { return nil }
Expand Down
21 changes: 21 additions & 0 deletions types/mempool/signer_extraction_adapater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math/rand"
"testing"

"cosmossdk.io/core/transaction"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/reflect/protoreflect"

Expand All @@ -24,6 +25,26 @@ func (n nonVerifiableTx) GetReflectMessages() ([]protoreflect.Message, error) {
panic("not implemented")
}

func (n nonVerifiableTx) Bytes() []byte {
return []byte{}
}

func (n nonVerifiableTx) Hash() [32]byte {
return [32]byte{}
}

func (n nonVerifiableTx) GetGasLimit() (uint64, error) {
return 0, nil
}

func (n nonVerifiableTx) GetMessages() ([]transaction.Msg, error) {
return nil, nil
}

func (n nonVerifiableTx) GetSenders() ([][]byte, error) {
return nil, nil
}

func TestDefaultSignerExtractor(t *testing.T) {
accounts := simtypes.RandomAccounts(rand.New(rand.NewSource(0)), 1)
sa := accounts[0].Address
Expand Down
3 changes: 3 additions & 0 deletions types/tx_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"google.golang.org/protobuf/reflect/protoreflect"

"cosmossdk.io/core/transaction"
coretransaction "cosmossdk.io/core/transaction"

"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -51,6 +52,8 @@ type (

// Tx defines an interface a transaction must fulfill.
Tx interface {
transaction.Tx

HasMsgs

// GetReflectMessages gets a reflected version of the transaction's messages
Expand Down
2 changes: 1 addition & 1 deletion x/auth/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
NewSetUpContextDecorator(options.Environment), // outermost AnteDecorator. SetUpContext must be called first
NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
NewValidateBasicDecorator(options.Environment),
NewTxTimeoutHeightDecorator(),
NewTxTimeoutHeightDecorator(options.Environment),
NewValidateMemoDecorator(options.AccountKeeper),
NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
Expand Down
Loading
Loading