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(app): Upgrading to v50 #1736

Open
wants to merge 56 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
7cf53ae
bumped ibc to v8
mtsitrin Jan 14, 2025
53ea151
go mod tidy passes
mtsitrin Jan 14, 2025
f9a7c2f
more deps. log and db
mtsitrin Jan 14, 2025
0439798
updating math dep
mtsitrin Jan 14, 2025
9d3eb5f
updating keepers
mtsitrin Jan 15, 2025
85d051e
updated expected keepers
mtsitrin Jan 17, 2025
2553c17
cleared some codecs
mtsitrin Jan 21, 2025
98026ba
updated math
mtsitrin Jan 21, 2025
cdf62d7
updated dymns
mtsitrin Jan 21, 2025
278cbb1
semi handled eibc
mtsitrin Jan 21, 2025
82e6f4d
updated module.go files
mtsitrin Jan 21, 2025
e08f28c
more support
mtsitrin Jan 21, 2025
14c25a6
done with streamer
mtsitrin Jan 21, 2025
e8dc18a
sponsorship
mtsitrin Jan 21, 2025
fc6a13b
cleaned legacyTx
mtsitrin Jan 21, 2025
c139df4
rollapp cleanup
mtsitrin Jan 21, 2025
3babcfd
cleanip
mtsitrin Jan 21, 2025
a7f6e52
removed unneeded deps
mtsitrin Jan 23, 2025
7f5ba05
disabled eth ante handlers
mtsitrin Jan 26, 2025
4b53251
fixed modules setup
mtsitrin Jan 26, 2025
5881dbf
app WIP
mtsitrin Jan 26, 2025
5fe77f7
keepers pass
mtsitrin Jan 26, 2025
2526ed1
app pass
mtsitrin Jan 26, 2025
36df3fe
updated proto files
mtsitrin Jan 26, 2025
4700e6c
generated proto files
mtsitrin Jan 26, 2025
a1a656e
updated half modules
mtsitrin Jan 27, 2025
6a0bde1
updated modules part 2
mtsitrin Jan 27, 2025
639d88e
handled dymd command:
mtsitrin Jan 27, 2025
e994396
ante handler WIP
mtsitrin Jan 27, 2025
fcb16a0
fixed minor in modules
mtsitrin Feb 11, 2025
cb7e81f
ante handler
mtsitrin Feb 11, 2025
48447a2
fixed config
mtsitrin Feb 12, 2025
fc2d1db
fixed account prefix
mtsitrin Feb 12, 2025
5891387
its alive
mtsitrin Feb 12, 2025
c4af894
fixed sponserhip ut
mtsitrin Feb 13, 2025
00925e2
fixing UT WIP
mtsitrin Feb 16, 2025
2dd8710
cleanup
mtsitrin Feb 16, 2025
daad521
cleanup
mtsitrin Feb 16, 2025
d0cc9bc
go.mod
mtsitrin Feb 16, 2025
82c8e94
fixed IBC light client initialization
mtsitrin Feb 16, 2025
e62c6ae
fixed coinbase bug
mtsitrin Feb 17, 2025
dddaa60
ibcetesting pass
mtsitrin Feb 17, 2025
12c2b5b
fixing modules UT
mtsitrin Feb 17, 2025
9f7ce56
fixing tests
mtsitrin Feb 18, 2025
2390a85
fixing more UT
mtsitrin Feb 18, 2025
c2947e5
fixed dymns UT
mtsitrin Feb 18, 2025
bb71530
fixed dym to adym denom
mtsitrin Feb 18, 2025
6e1f9e7
wip
mtsitrin Feb 18, 2025
90e409a
wip streamer UT
mtsitrin Feb 18, 2025
429095b
disabled broken tests
mtsitrin Feb 19, 2025
aa4b23a
Merge branch 'main' into upgrading_to_v50
mtsitrin Feb 19, 2025
df6d2e8
cleanup
mtsitrin Feb 19, 2025
1b191f5
more cleanup
mtsitrin Feb 19, 2025
8099a3f
minor fix
mtsitrin Feb 19, 2025
d7fbcb9
linter
mtsitrin Feb 19, 2025
f28df2f
linter fix
mtsitrin Feb 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,9 @@ release:
# NOTE: Link to the tendermintdev/sdk-proto-gen docker images:
# https://hub.docker.com/r/tendermintdev/sdk-proto-gen/tags
#
protoVer=v0.7
protoImageName=tendermintdev/sdk-proto-gen:$(protoVer)
containerProtoGen=cosmos-sdk-proto-gen-$(protoVer)
containerProtoFmt=cosmos-sdk-proto-fmt-$(protoVer)
protoVer=0.14.0
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)
# ------
# NOTE: cosmos/proto-builder image is needed because clang-format is not installed
# on the tendermintdev/sdk-proto-gen docker image.
Expand All @@ -175,7 +174,7 @@ protoCosmosImage=$(DOCKER) run --network host --rm -v $(CURDIR):/workspace --wor

proto-gen:
@echo "Generating Protobuf files"
$(protoCosmosImage) sh ./scripts/protocgen.sh
$(protoImage) sh ./scripts/protocgen.sh
@go mod tidy

proto-swagger-gen:
Expand Down
5 changes: 1 addition & 4 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

cometbftlog "github.com/cometbft/cometbft/libs/log"
cometbftlog "cosmossdk.io/log"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"

errorsmod "cosmossdk.io/errors"
Expand Down Expand Up @@ -37,9 +37,6 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
case "/ethermint.evm.v1.ExtensionOptionsEthereumTx":
// handle as *evmtypes.MsgEthereumTx
anteHandler = newEthAnteHandler(options)
case "/ethermint.types.v1.ExtensionOptionsWeb3Tx":
// handle as normal Cosmos SDK tx, except signature is checked for EIP712 representation
anteHandler = newLegacyCosmosAnteHandlerEip712(options)
default:
return ctx, errorsmod.Wrapf(
errortypes.ErrUnknownExtensionOptions,
Expand Down
43 changes: 26 additions & 17 deletions app/ante/ante_options.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,50 @@
package ante

import (
storetypes "cosmossdk.io/store/types"
txsigning "cosmossdk.io/x/tx/signing"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ethante "github.com/evmos/ethermint/app/ante"

"github.com/dymensionxyz/dymension/v3/x/iro/types"
lightclientkeeper "github.com/dymensionxyz/dymension/v3/x/lightclient/keeper"
rollappkeeper "github.com/dymensionxyz/dymension/v3/x/rollapp/keeper"

errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx/signing"

feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
txfeeskeeper "github.com/osmosis-labs/osmosis/v15/x/txfees/keeper"
)

// FeeMarketKeeper defines the expected keeper interface used on the AnteHandler
type FeeMarketKeeper interface {
ethante.FeeMarketKeeper
GetMinGasPrice(ctx sdk.Context) (minGasPrice sdk.Dec)
GetParams(ctx sdk.Context) (params feemarkettypes.Params)
AddTransientGasWanted(ctx sdk.Context, gasWanted uint64) (uint64, error)
GetBaseFeeEnabled(ctx sdk.Context) bool
GetMinGasPrice(ctx sdk.Context) (minGasPrice math.LegacyDec)
}

type HandlerOptions struct {
AccountKeeper *authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
IBCKeeper *ibckeeper.Keeper
FeeMarketKeeper FeeMarketKeeper
EvmKeeper ethante.EVMKeeper
FeegrantKeeper ante.FeegrantKeeper
TxFeesKeeper *txfeeskeeper.Keeper
SignModeHandler authsigning.SignModeHandler
MaxTxGasWanted uint64
ExtensionOptionChecker ante.ExtensionOptionChecker
RollappKeeper rollappkeeper.Keeper
LightClientKeeper *lightclientkeeper.Keeper
FeegrantKeeper FeegrantKeeper
SignModeHandler *txsigning.HandlerMap
SigGasConsumer func(meter storetypes.GasMeter, sig signing.SignatureV2, params types.Params) error
TxFeeChecker ante.TxFeeChecker

AccountKeeper AccountKeeper
BankKeeper BankKeeper
IBCKeeper *ibckeeper.Keeper
FeeMarketKeeper FeeMarketKeeper
EvmKeeper ethante.EVMKeeper
TxFeesKeeper *txfeeskeeper.Keeper
MaxTxGasWanted uint64
RollappKeeper rollappkeeper.Keeper
LightClientKeeper *lightclientkeeper.Keeper
}

func (options HandlerOptions) validate() error {
Expand Down
57 changes: 22 additions & 35 deletions app/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ import (
"fmt"
"testing"

"cosmossdk.io/math"
signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/signer/core/apitypes"
"github.com/stretchr/testify/suite"

cometbftproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/client"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/evmos/ethermint/crypto/ethsecp256k1"
"github.com/evmos/ethermint/ethereum/eip712"
"github.com/evmos/ethermint/testutil"

ethermint "github.com/evmos/ethermint/types"

"github.com/dymensionxyz/dymension/v3/app"
Expand All @@ -47,9 +46,9 @@ func TestAnteTestSuite(t *testing.T) {
// SetupTest setups a new test, with new app, context, and anteHandler.
func (s *AnteTestSuite) SetupTestCheckTx(isCheckTx bool) {
s.app = apptesting.Setup(s.T())
s.ctx = s.app.BaseApp.NewContext(isCheckTx, cometbftproto.Header{}).WithBlockHeight(1).WithChainID(apptesting.TestChainID)
s.ctx = s.app.BaseApp.NewContext(isCheckTx).WithBlockHeight(1).WithChainID(apptesting.TestChainID)

txConfig := s.app.GetTxConfig()
txConfig := s.app.TxConfig()
s.clientCtx = client.Context{}.
WithTxConfig(txConfig).
WithCodec(s.app.AppCodec())
Expand Down Expand Up @@ -79,9 +78,9 @@ func (suite *AnteTestSuite) TestCosmosAnteHandlerEip712() {
suite.Require().NoError(err)
addr := crypto.PubkeyToAddress(key.PublicKey)

amt := sdk.NewInt(100)
err = testutil.FundAccount(
suite.app.BankKeeper,
amt := math.NewInt(100)
apptesting.FundAccount(
suite.app,
suite.ctx,
privkey.PubKey().Address().Bytes(),
sdk.NewCoins(sdk.NewCoin(params.DisplayDenom, amt)),
Expand All @@ -94,7 +93,7 @@ func (suite *AnteTestSuite) TestCosmosAnteHandlerEip712() {

from := acc.GetAddress()
recipient := sdk.AccAddress(common.Address{}.Bytes())
msgSend := banktypes.NewMsgSend(from, recipient, sdk.NewCoins(sdk.NewCoin(params.DisplayDenom, sdk.NewInt(1))))
msgSend := banktypes.NewMsgSend(from, recipient, sdk.NewCoins(sdk.NewCoin(params.DisplayDenom, math.NewInt(1))))

txBuilder := suite.CreateTestEIP712CosmosTxBuilder(privkey, []sdk.Msg{msgSend})
_, err = suite.anteHandler(suite.ctx, txBuilder.GetTx(), false)
Expand All @@ -106,7 +105,7 @@ func (suite *AnteTestSuite) CreateTestEIP712CosmosTxBuilder(
priv cryptotypes.PrivKey, msgs []sdk.Msg,
) client.TxBuilder {
txConfig := suite.clientCtx.TxConfig
coinAmount := sdk.NewCoin(params.DisplayDenom, sdk.NewInt(20))
coinAmount := sdk.NewCoin(params.DisplayDenom, math.NewInt(20))
fees := sdk.NewCoins(coinAmount)

pc, err := ethermint.ParseChainID(suite.ctx.ChainID())
Expand All @@ -120,12 +119,10 @@ func (suite *AnteTestSuite) CreateTestEIP712CosmosTxBuilder(
suite.Require().NoError(err)

suite.txBuilder = txConfig.NewTxBuilder()
builder, ok := suite.txBuilder.(authtx.ExtensionOptionsTxBuilder)
suite.Require().True(ok, "txBuilder could not be casted to authtx.ExtensionOptionsTxBuilder type")
builder.SetFeeAmount(fees)
builder.SetGasLimit(200000)
suite.txBuilder.SetFeeAmount(fees)
suite.txBuilder.SetGasLimit(200000)

err = builder.SetMsgs(msgs...)
err = suite.txBuilder.SetMsgs(msgs...)
suite.Require().NoError(err)

txBytes := legacytx.StdSignBytes(
Expand All @@ -137,7 +134,7 @@ func (suite *AnteTestSuite) CreateTestEIP712CosmosTxBuilder(
Amount: fees,
Gas: 200000,
},
msgs, "", nil,
msgs, "",
)

feeDelegation := &eip712.FeeDelegationOptions{
Expand All @@ -156,31 +153,21 @@ func (suite *AnteTestSuite) CreateTestEIP712CosmosTxBuilder(
suite.Require().NoError(err)

keyringSigner := NewSigner(priv)
signature, pubKey, err := keyringSigner.SignByAddress(from, sigHash)
signature, pubKey, err := keyringSigner.SignByAddress(from, sigHash, signingtypes.SignMode_SIGN_MODE_DIRECT)
suite.Require().NoError(err)

signature[crypto.RecoveryIDOffset] += 27

option, err := codectypes.NewAnyWithValue(&ethermint.ExtensionOptionsWeb3Tx{
FeePayer: from.String(),
TypedDataChainID: chainIDNum,
FeePayerSig: signature,
})
suite.Require().NoError(err)

builder.SetExtensionOptions(option)

sigsV2 := signing.SignatureV2{
PubKey: pubKey,
Data: &signing.SingleSignatureData{
SignMode: signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
SignMode: signing.SignMode_SIGN_MODE_DIRECT,
Signature: signature,
},
Sequence: nonce,
}
err = builder.SetSignatures(sigsV2)
err = suite.txBuilder.SetSignatures(sigsV2)
suite.Require().NoError(err)

return builder
return suite.txBuilder
}

// Signer defines a type that is used on testing for signing MsgEthereumTx
Expand All @@ -195,7 +182,7 @@ func NewSigner(sk cryptotypes.PrivKey) keyring.Signer {
}

// Sign signs the message using the underlying private key
func (s Signer) Sign(_ string, msg []byte) ([]byte, cryptotypes.PubKey, error) {
func (s Signer) Sign(uid string, msg []byte, signMode signing.SignMode) ([]byte, cryptotypes.PubKey, error) {
if s.privKey.Type() != ethsecp256k1.KeyType {
return nil, nil, fmt.Errorf(
"invalid private key type for signing ethereum tx; expected %s, got %s",
Expand All @@ -213,11 +200,11 @@ func (s Signer) Sign(_ string, msg []byte) ([]byte, cryptotypes.PubKey, error) {
}

// SignByAddress sign byte messages with a user key providing the address.
func (s Signer) SignByAddress(address sdk.Address, msg []byte) ([]byte, cryptotypes.PubKey, error) {
func (s Signer) SignByAddress(address sdk.Address, msg []byte, signMode signing.SignMode) ([]byte, cryptotypes.PubKey, error) {
signer := sdk.AccAddress(s.privKey.PubKey().Address())
if !signer.Equals(address) {
return nil, nil, fmt.Errorf("address mismatch: signer %s ≠ given address %s", signer, address)
}

return s.Sign("", msg)
return s.Sign("", msg, signMode)
}
58 changes: 58 additions & 0 deletions app/ante/cosmos_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package ante

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
"github.com/dymensionxyz/dymension/v3/x/common/types"
ethante "github.com/evmos/ethermint/app/ante"
txfeesante "github.com/osmosis-labs/osmosis/v15/x/txfees/ante"

vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"

lightclientante "github.com/dymensionxyz/dymension/v3/x/lightclient/ante"
)

func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
mempoolFeeDecorator := txfeesante.NewMempoolFeeDecorator(*options.TxFeesKeeper, options.FeeMarketKeeper)
deductFeeDecorator := txfeesante.NewDeductFeeDecorator(*options.TxFeesKeeper, options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper)

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
// reject MsgEthereumTxs and disable the Msg types that cannot be included on an authz.MsgExec msgs field
NewRejectMessagesDecorator().WithPredicate(
BlockTypeUrls(
1,
// Only blanket rejects depth greater than zero because we have our own custom logic for depth 0
// Note that there is never a genuine reason to pass both ibc update client and misbehaviour submission through gov or auth,
// it's always done by relayers directly.
sdk.MsgTypeURL(&ibcclienttypes.MsgUpdateClient{}))).
WithPredicate(BlockTypeUrls(
0,
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreateVestingAccount{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreatePeriodicVestingAccount{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreatePermanentLockedAccount{}))),
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
// Use Mempool Fee TransferEnabledDecorator from our txfees module instead of default one from auth
mempoolFeeDecorator,
deductFeeDecorator,
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, ethante.DefaultSigVerificationGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
types.NewIBCProofHeightDecorator(),
lightclientante.NewIBCMessagesDecorator(*options.LightClientKeeper, options.IBCKeeper.ClientKeeper, options.IBCKeeper.ChannelKeeper, options.RollappKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),
}

return sdk.ChainAnteDecorators(anteDecorators...)
}
Loading
Loading