diff --git a/app/ante.go b/app/ante.go index 36e6149..228858f 100644 --- a/app/ante.go +++ b/app/ante.go @@ -14,15 +14,15 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/ante" conntypes "github.com/cosmos/ibc-go/v6/modules/core/03-connection/types" ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper" + rdkante "github.com/dymensionxyz/dymension-rdk/server/ante" distrkeeper "github.com/dymensionxyz/dymension-rdk/x/dist/keeper" + "github.com/dymensionxyz/dymension-rdk/x/gasless" + gaslesskeeper "github.com/dymensionxyz/dymension-rdk/x/gasless/keeper" seqkeeper "github.com/dymensionxyz/dymension-rdk/x/sequencers/keeper" cosmosante "github.com/evmos/evmos/v12/app/ante/cosmos" evmostypes "github.com/evmos/evmos/v12/types" evmtypes "github.com/evmos/evmos/v12/x/evm/types" tmlog "github.com/tendermint/tendermint/libs/log" - - "github.com/dymensionxyz/dymension-rdk/x/gasless" - gaslesskeeper "github.com/dymensionxyz/dymension-rdk/x/gasless/keeper" ) // HandlerOptions are the options required for constructing a default SDK AnteHandler. @@ -121,7 +121,7 @@ func cosmosHandler(options HandlerOptions, sigChecker sdk.AnteDecorator) sdk.Ant ante.NewValidateMemoDecorator(options.AccountKeeper), NewCreateAccountDecorator(options.AccountKeeper.(accountKeeper)), ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), - NewBypassIBCFeeDecorator( + rdkante.NewBypassIBCFeeDecorator( gasless.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker, options.GaslessKeeper), options.DistrKeeper, options.SequencersKeeper, diff --git a/app/app.go b/app/app.go index 953cea2..128c606 100644 --- a/app/app.go +++ b/app/app.go @@ -12,6 +12,7 @@ import ( authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" evmosante "github.com/evmos/evmos/v12/app/ante" + "github.com/gogo/protobuf/proto" "github.com/gorilla/mux" "github.com/rakyll/statik/fs" abci "github.com/tendermint/tendermint/abci/types" @@ -472,7 +473,10 @@ func NewRollapp( ) app.SequencersKeeper = *seqkeeper.NewKeeper( - appCodec, keys[seqtypes.StoreKey], app.GetSubspace(seqtypes.ModuleName), + appCodec, + keys[seqtypes.StoreKey], + app.GetSubspace(seqtypes.ModuleName), + authtypes.NewModuleAddress(seqtypes.ModuleName).String(), ) app.IBCKeeper = ibckeeper.NewKeeper( @@ -840,7 +844,7 @@ func NewRollapp( // Admission handler for consensus messages app.setAdmissionHandler(consensus.AllowedMessagesHandler([]string{ - // proto.MessageName(&banktypes.MsgSend{}), // Example of message allowed as consensus message + proto.MessageName(new(seqtypes.ConsensusMsgUpsertSequencer)), })) if loadLatest { diff --git a/app/bypass_ibc_fee_decorator.go b/app/bypass_ibc_fee_decorator.go deleted file mode 100644 index cfb7897..0000000 --- a/app/bypass_ibc_fee_decorator.go +++ /dev/null @@ -1,118 +0,0 @@ -package app - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" - conntypes "github.com/cosmos/ibc-go/v6/modules/core/03-connection/types" - channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types" - distrkeeper "github.com/dymensionxyz/dymension-rdk/x/dist/keeper" - seqkeeper "github.com/dymensionxyz/dymension-rdk/x/sequencers/keeper" -) - -type anteHandler interface { - AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) -} - -type BypassIBCFeeDecorator struct { - nextAnte anteHandler - dk distrkeeper.Keeper - sk seqkeeper.Keeper -} - -func NewBypassIBCFeeDecorator(nextAnte anteHandler, dk distrkeeper.Keeper, sk seqkeeper.Keeper) BypassIBCFeeDecorator { - return BypassIBCFeeDecorator{ - nextAnte: nextAnte, - dk: dk, - sk: sk, - } -} - -// SKIP FEE DEDUCT and MIN GAS PRICE Ante handlers for IBC relayer messages -func (n BypassIBCFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { - // ================ HACK ================ - whitelisted, err := n.isWhitelistedRelayer(ctx, tx.GetMsgs()) - if err != nil { - return ctx, fmt.Errorf("is whitelisted relayer: %w", err) - } - if whitelisted { - return next(ctx, tx, simulate) - } - // ====================================== - - // If it's not an IBC Relayer transfer, proceed with the default fee handling - return n.nextAnte.AnteHandle(ctx, tx, simulate, next) -} - -// isIBCRelayerMsg checks if all the messages in the transaction are IBC relayer messages -func isIBCRelayerMsg(msgs []sdk.Msg) bool { - for _, msg := range msgs { - switch msg.(type) { - // IBC Client Messages - case *clienttypes.MsgCreateClient, *clienttypes.MsgUpdateClient, - *clienttypes.MsgUpgradeClient, *clienttypes.MsgSubmitMisbehaviour: - // IBC Connection Messages - case *conntypes.MsgConnectionOpenInit, *conntypes.MsgConnectionOpenTry, - *conntypes.MsgConnectionOpenAck, *conntypes.MsgConnectionOpenConfirm: - // IBC Channel Messages - case *channeltypes.MsgChannelOpenInit, *channeltypes.MsgChannelOpenTry, - *channeltypes.MsgChannelOpenAck, *channeltypes.MsgChannelOpenConfirm, - *channeltypes.MsgChannelCloseInit, *channeltypes.MsgChannelCloseConfirm: - // IBC Packet Messages - case *channeltypes.MsgRecvPacket, *channeltypes.MsgAcknowledgement, - *channeltypes.MsgTimeout, *channeltypes.MsgTimeoutOnClose: - default: - return false - } - } - - return true -} - -// isWhitelistedRelayer checks if all the messages in the transaction are from whitelisted IBC relayer -func (n BypassIBCFeeDecorator) isWhitelistedRelayer(ctx sdk.Context, msgs []sdk.Msg) (bool, error) { - consAddr := n.dk.GetPreviousProposerConsAddr(ctx) - wlRelayers, err := n.sk.GetWhitelistedRelayersByConsAddr(ctx, consAddr) - if err != nil { - return false, fmt.Errorf("get whitelisted relayers by consensus addr: %w", err) - } - wlRelayersMap := make(map[string]struct{}, len(msgs)) - for _, relayerAddr := range wlRelayers.Relayers { - wlRelayersMap[relayerAddr] = struct{}{} - } - - for _, msg := range msgs { - switch msg.(type) { - // IBC Client Messages - case *clienttypes.MsgCreateClient, *clienttypes.MsgUpdateClient, - *clienttypes.MsgUpgradeClient, *clienttypes.MsgSubmitMisbehaviour: - - // IBC Connection Messages - case *conntypes.MsgConnectionOpenInit, *conntypes.MsgConnectionOpenTry, - *conntypes.MsgConnectionOpenAck, *conntypes.MsgConnectionOpenConfirm: - - // IBC Channel Messages - case *channeltypes.MsgChannelOpenInit, *channeltypes.MsgChannelOpenTry, - *channeltypes.MsgChannelOpenAck, *channeltypes.MsgChannelOpenConfirm, - *channeltypes.MsgChannelCloseInit, *channeltypes.MsgChannelCloseConfirm: - - // IBC Packet Messages - case *channeltypes.MsgRecvPacket, *channeltypes.MsgAcknowledgement, - *channeltypes.MsgTimeout, *channeltypes.MsgTimeoutOnClose: - - default: - return false, nil - } - - signers := msg.GetSigners() - for _, signer := range signers { - _, ok := wlRelayersMap[signer.String()] - if !ok { - return false, nil - } - } - } - - return true, nil -} diff --git a/app/create_account_decorator.go b/app/create_account_decorator.go index 8e0f43f..242d97d 100644 --- a/app/create_account_decorator.go +++ b/app/create_account_decorator.go @@ -7,6 +7,7 @@ import ( authante "github.com/cosmos/cosmos-sdk/x/auth/ante" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" "github.com/cosmos/cosmos-sdk/x/auth/types" + rdkante "github.com/dymensionxyz/dymension-rdk/server/ante" ) type createAccountDecorator struct { @@ -39,7 +40,7 @@ func (cad createAccountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat return ctx, err } - ibcRelayerMsg := isIBCRelayerMsg(tx.GetMsgs()) + ibcRelayerMsg := rdkante.IsIBCRelayerMsg(tx.GetMsgs()) for i, pk := range pubkeys { if pk == nil { diff --git a/app/sigcheck_decorator.go b/app/sigcheck_decorator.go index 92f1321..e2f044e 100644 --- a/app/sigcheck_decorator.go +++ b/app/sigcheck_decorator.go @@ -8,6 +8,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authante "github.com/cosmos/cosmos-sdk/x/auth/ante" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" + rdkante "github.com/dymensionxyz/dymension-rdk/server/ante" ) type sigCheckDecorator struct { @@ -41,7 +42,7 @@ func (svd sigCheckDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate boo return ctx, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "invalid number of signer; expected: %d, got %d", len(signerAddrs), len(sigs)) } - ibcRelayerMsg := isIBCRelayerMsg(tx.GetMsgs()) + ibcRelayerMsg := rdkante.IsIBCRelayerMsg(tx.GetMsgs()) for i, sig := range sigs { acc, err := authante.GetSignerAcc(ctx, svd.ak, signerAddrs[i]) diff --git a/go.mod b/go.mod index ce61f2c..4a0c5ca 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/cosmos/ibc-go/v6 v6.3.0 github.com/dvsekhvalnov/jose2go v1.5.0 github.com/dymensionxyz/dymension-rdk v1.6.1-0.20241020152926-b250db7af580 - github.com/dymensionxyz/dymint v1.2.0-rc01.0.20241015102238-a827c3784461 + github.com/dymensionxyz/dymint v1.2.0-rc01.0.20241024144934-db109b2859b4 github.com/ethereum/go-ethereum v1.12.0 github.com/evmos/evmos/v12 v12.1.6 github.com/gogo/protobuf v1.3.3 @@ -349,6 +349,7 @@ replace ( github.com/CosmWasm/wasmd => github.com/decentrio/wasmd v0.33.0-sdk46.2 github.com/centrifuge/go-substrate-rpc-client/v4 => github.com/availproject/go-substrate-rpc-client/v4 v4.0.12-avail-1.4.0-rc1-5e286e3 github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0 + github.com/dymensionxyz/dymension-rdk => ../dymension-rdk // use Evmos geth fork github.com/ethereum/go-ethereum => github.com/evmos/go-ethereum v1.10.26 github.com/evmos/evmos/v12 => github.com/dymensionxyz/evmos/v12 v12.1.6-dymension-v0.4.2 @@ -361,5 +362,4 @@ replace ( github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // use cometbft github.com/tendermint/tendermint => github.com/dymensionxyz/cometbft v0.34.29-0.20241008141942-63af9d24107f - github.com/dymensionxyz/dymension-rdk => ../dymension-rdk ) diff --git a/go.sum b/go.sum index 73660bb..6965be0 100644 --- a/go.sum +++ b/go.sum @@ -573,10 +573,8 @@ github.com/dymensionxyz/cometbft v0.34.29-0.20241008141942-63af9d24107f h1:CclWJ github.com/dymensionxyz/cometbft v0.34.29-0.20241008141942-63af9d24107f/go.mod h1:L9shMfbkZ8B+7JlwANEr+NZbBcn+hBpwdbeYvA5rLCw= github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20240821081230-b4018b2bac13 h1:u5yeve5jZR6TdRjjR+vYT/8PWKbhwCZxUmAu+/Tnxyg= github.com/dymensionxyz/cosmosclient v0.4.2-beta.0.20240821081230-b4018b2bac13/go.mod h1:jabDQYXrccscSE0fXkh7eQFYPWJCRiuWKonFGObVq6s= -github.com/dymensionxyz/dymension-rdk v1.6.1-0.20241020152926-b250db7af580 h1:bgECFCjc/8lVq9/UQ4qCTdD/znUgKEX7a0QBOcGuuNg= -github.com/dymensionxyz/dymension-rdk v1.6.1-0.20241020152926-b250db7af580/go.mod h1:m9D/CACMkMAXKFeuU+1lkUIPWpMFb0EvGl7M5vV0HoA= -github.com/dymensionxyz/dymint v1.2.0-rc01.0.20241015102238-a827c3784461 h1:ZNh5s2dmfcgPE9g6OlhHBFtygiAxCRr+wPKSgpSo/Bw= -github.com/dymensionxyz/dymint v1.2.0-rc01.0.20241015102238-a827c3784461/go.mod h1:FNVdsvVhveAOeL0Mj9VIfGkAUKhGskEr0iRnoM+MAkU= +github.com/dymensionxyz/dymint v1.2.0-rc01.0.20241024144934-db109b2859b4 h1:DpfHfiqNJ0QgnPNq/nx2fAUDWwLlWORQ605uQyPPODU= +github.com/dymensionxyz/dymint v1.2.0-rc01.0.20241024144934-db109b2859b4/go.mod h1:FNVdsvVhveAOeL0Mj9VIfGkAUKhGskEr0iRnoM+MAkU= github.com/dymensionxyz/evmos/v12 v12.1.6-dymension-v0.4.2 h1:aVP3off7u2vsvRH7lHAUPTLdf9/AfnzC/rvvi0wC/co= github.com/dymensionxyz/evmos/v12 v12.1.6-dymension-v0.4.2/go.mod h1:CI6D89pkoiIm4BjoMFNnEaCLdKBEobLuwvhS0c1zh7Y= github.com/dymensionxyz/gerr-cosmos v1.0.0 h1:oi91rgOkpJWr41oX9JOyjvvBnhGY54tj513x8VlDAEc=