Skip to content

Commit

Permalink
feat(genesis bridge): genesis transfers (#933)
Browse files Browse the repository at this point in the history
  • Loading branch information
danwt authored Jun 19, 2024
1 parent 0274850 commit 4565f34
Show file tree
Hide file tree
Showing 124 changed files with 3,604 additions and 5,281 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

- (genesisbridge) [#932](https://github.com/dymensionxyz/dymension/issues/932) Adds ibc module and ante handler to stop transfers to/from rollapp that has an incomplete genesis bridge (transfersEnabled)
- (genesisbridge) [#932](https://github.com/dymensionxyz/dymension/issues/932) Adds a new temporary ibc module to set the canonical channel id, since we no longer do that using a whitelisted addr
- (genesisbridge) [#932](https://github.com/dymensionxyz/dymension/issues/932) Adds a new ibc module to handle incoming 'genesis transfers'. It validates the special memo and registers a denom. It will not allow any regular transfers if transfers are not enabled
- (rollapp) [#932](https://github.com/dymensionxyz/dymension/issues/932) Renames is_genesis_event on the rollapp genesis state to 'transfers_enabled' this is backwards compatible
- (rollapp) [#932](https://github.com/dymensionxyz/dymension/issues/932) Removes concept of passing genesis accounts and denoms in the create rollapp message
- (rollapp) [#932](https://github.com/dymensionxyz/dymension/issues/932) Adds a transfersenabled flag to createRollapp (might be changed in future)
- (delayedack) [#932](https://github.com/dymensionxyz/dymension/issues/932) Adds the notion of skipctx, to skip it with a special sdk context value
- (code standards) [#932](https://github.com/dymensionxyz/dymension/issues/932) Adds a gerr (google error ) and derr (dymension error) packages for idiomatic error handling. (In future we will consolidate across dymint/rdk)
- (denommetadata) [#907](https://github.com/dymensionxyz/dymension/issues/907) Add IBC middleware to migrate denom metadata to rollappp, remove `CreateDenomMetadata` and `UpdateDenomMetadata` tx handlers
- (delayedack) [#849](https://github.com/dymensionxyz/dymension/issues/849) Add demand order filters: type, rollapp id and limit
- (delayedack) [#850](https://github.com/dymensionxyz/dymension/issues/850) Add type filter for delayedack
Expand Down Expand Up @@ -79,6 +87,11 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

- (code standards) [#932](https://github.com/dymensionxyz/dymension/issues/932) Dry out existing middlewares to make use of new .GetValidTransfer* functions which take care of parsing and validating the fungible packet, and querying and validating any associated rollapp and finalizations
- (code standards) [#932](https://github.com/dymensionxyz/dymension/issues/932) Removes the obsolete ValidateRollappId func and sub routines
- (code standards) [#932](https://github.com/dymensionxyz/dymension/issues/932) Simplify GetAllBlockHeightToFinalizationQueue
- (code standards) [#932](https://github.com/dymensionxyz/dymension/issues/932) Fixes naming for our 'middlewares' to make them clearly one of ibc module / ics4 wrapper / middleware
- (code standards) [#932](https://github.com/dymensionxyz/dymension/issues/932) Moves our various utils to properly namespaced packages under utils/
- (rollapp) [#839](https://github.com/dymensionxyz/dymension/issues/839) Remove rollapp deprecated fields
- (eibc) [#836](https://github.com/dymensionxyz/dymension/issues/836) Improve eibc memo error handling
- (eibc) [#830](https://github.com/dymensionxyz/dymension/issues/830) Invalid tx should return ackErr
Expand Down
2 changes: 2 additions & 0 deletions app/ante/ante_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper"
rollappkeeper "github.com/dymensionxyz/dymension/v3/x/rollapp/keeper"
ethante "github.com/evmos/ethermint/app/ante"

errorsmod "cosmossdk.io/errors"
Expand All @@ -24,6 +25,7 @@ type HandlerOptions struct {
SignModeHandler authsigning.SignModeHandler
MaxTxGasWanted uint64
ExtensionOptionChecker ante.ExtensionOptionChecker
RollappKeeper rollappkeeper.Keeper
}

func (options HandlerOptions) validate() error {
Expand Down
6 changes: 6 additions & 0 deletions app/ante/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
ante "github.com/cosmos/cosmos-sdk/x/auth/ante"
ibcante "github.com/cosmos/ibc-go/v6/modules/core/ante"
"github.com/dymensionxyz/dymension/v3/x/rollapp/transfersenabled"
ethante "github.com/evmos/ethermint/app/ante"
txfeesante "github.com/osmosis-labs/osmosis/v15/x/txfees/ante"

Expand Down Expand Up @@ -72,6 +73,8 @@ func newLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
delayedack.NewIBCProofHeightDecorator(),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),

transfersenabled.NewDecorator(options.RollappKeeper.GetRollapp, options.IBCKeeper.ChannelKeeper.GetChannelClientState),
)
}

Expand All @@ -80,6 +83,7 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
deductFeeDecorator := txfeesante.NewDeductFeeDecorator(*options.TxFeesKeeper, options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper)

return sdk.ChainAnteDecorators(

NewRejectMessagesDecorator(), // reject MsgEthereumTxs and vesting msgs
ethante.NewAuthzLimiterDecorator([]string{ // disable the Msg types that cannot be included on an authz.MsgExec msgs field
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
Expand All @@ -105,5 +109,7 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
delayedack.NewIBCProofHeightDecorator(),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),

transfersenabled.NewDecorator(options.RollappKeeper.GetRollapp, options.IBCKeeper.ChannelKeeper.GetChannelClientState),
)
}
57 changes: 20 additions & 37 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import (
"os"
"path/filepath"

"github.com/dymensionxyz/dymension/v3/x/bridging_fee"
"github.com/dymensionxyz/dymension/v3/x/rollapp/transfersenabled"

"github.com/dymensionxyz/dymension/v3/x/rollapp/transfergenesis"

"github.com/dymensionxyz/dymension/v3/x/bridgingfee"

vfchooks "github.com/dymensionxyz/dymension/v3/x/vfc/hooks"

"github.com/gorilla/mux"
Expand Down Expand Up @@ -279,7 +284,7 @@ var (
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
sequencermoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
rollappmoduletypes.ModuleName: {authtypes.Minter},
rollappmoduletypes.ModuleName: {},
streamermoduletypes.ModuleName: nil,
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and subtraction of balance using module account.
evmtypes.ModuleVirtualFrontierContractDeployerName: nil, // used for deploying virtual frontier bank contract.
Expand Down Expand Up @@ -546,7 +551,7 @@ func New(
app.AccountKeeper,
)

txfeeskeeper := txfeeskeeper.NewKeeper(
txFeesKeeper := txfeeskeeper.NewKeeper(
app.keys[txfeestypes.StoreKey],
app.GetSubspace(txfeestypes.ModuleName),
app.AccountKeeper,
Expand All @@ -555,7 +560,7 @@ func New(
app.PoolManagerKeeper,
app.GAMMKeeper,
)
app.TxFeesKeeper = &txfeeskeeper
app.TxFeesKeeper = &txFeesKeeper
app.GAMMKeeper.SetPoolManager(app.PoolManagerKeeper)
app.GAMMKeeper.SetTxFees(app.TxFeesKeeper)

Expand Down Expand Up @@ -609,32 +614,21 @@ func New(
),
)

app.RollappKeeper = *rollappmodulekeeper.NewKeeper(
appCodec,
keys[rollappmoduletypes.StoreKey],
keys[rollappmoduletypes.MemStoreKey],
app.GetSubspace(rollappmoduletypes.ModuleName),
app.IBCKeeper.ClientKeeper,
app.IBCKeeper.ChannelKeeper,
app.BankKeeper,
app.DenomMetadataKeeper,
)
app.RollappKeeper = *rollappmodulekeeper.NewKeeper(appCodec, keys[rollappmoduletypes.StoreKey], app.GetSubspace(rollappmoduletypes.ModuleName), app.IBCKeeper.ChannelKeeper)

// Create Transfer Keepers
app.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec,
keys[ibctransfertypes.StoreKey],
app.GetSubspace(ibctransfertypes.ModuleName),
transferinject.NewIBCSendMiddleware(app.IBCKeeper.ChannelKeeper, app.RollappKeeper, app.BankKeeper),
transferinject.NewICS4Wrapper(app.IBCKeeper.ChannelKeeper, app.RollappKeeper, app.BankKeeper),
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.AccountKeeper,
app.BankKeeper,
scopedTransferKeeper,
)

app.RollappKeeper.SetTransferKeeper(app.TransferKeeper)

app.SequencerKeeper = *sequencermodulekeeper.NewKeeper(
appCodec,
keys[sequencermoduletypes.StoreKey],
Expand All @@ -649,11 +643,8 @@ func New(
keys[delayedacktypes.StoreKey],
app.GetSubspace(delayedacktypes.ModuleName),
app.RollappKeeper,
app.SequencerKeeper,
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.ConnectionKeeper,
app.IBCKeeper.ClientKeeper,
&app.EIBCKeeper,
app.BankKeeper,
)
Expand Down Expand Up @@ -742,27 +733,18 @@ func New(
)

transferModule := ibctransfer.NewAppModule(app.TransferKeeper)
transferMiddleware := ibctransfer.NewIBCModule(app.TransferKeeper)

var transferStack ibcporttypes.IBCModule
transferStack = bridging_fee.NewIBCMiddleware(
transferMiddleware,
app.IBCKeeper.ChannelKeeper,
app.DelayedAckKeeper,
app.RollappKeeper,
app.TransferKeeper,
app.AccountKeeper.GetModuleAddress(txfeestypes.ModuleName),
)
transferStack = ibctransfer.NewIBCModule(app.TransferKeeper)
transferStack = bridgingfee.NewIBCModule(transferStack.(ibctransfer.IBCModule), app.DelayedAckKeeper, app.TransferKeeper, app.AccountKeeper.GetModuleAddress(txfeestypes.ModuleName), app.RollappKeeper)
transferStack = packetforwardmiddleware.NewIBCMiddleware(transferStack, app.PacketForwardMiddlewareKeeper, 0, packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp, packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp)

transferStack = packetforwardmiddleware.NewIBCMiddleware(
transferStack,
app.PacketForwardMiddlewareKeeper,
0,
packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp,
packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp,
)
delayedAckMiddleware := delayedackmodule.NewIBCMiddleware(transferStack, app.DelayedAckKeeper, app.RollappKeeper)
transferStack = transferinject.NewIBCAckMiddleware(delayedAckMiddleware, app.RollappKeeper)
transferStack = delayedAckMiddleware
transferStack = transferinject.NewIBCModule(transferStack, app.RollappKeeper)
transferStack = transfersenabled.NewIBCModule(transferStack, app.RollappKeeper, app.DelayedAckKeeper)
transferStack = transfergenesis.NewIBCModule(transferStack, app.DelayedAckKeeper, app.RollappKeeper, app.TransferKeeper, app.DenomMetadataKeeper)
transferStack = transfergenesis.NewIBCModuleCanonicalChannelHack(transferStack, app.RollappKeeper, app.IBCKeeper.ChannelKeeper.GetChannelClientState)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := ibcporttypes.NewRouter()
Expand Down Expand Up @@ -976,6 +958,7 @@ func New(
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
MaxTxGasWanted: maxGasWanted,
ExtensionOptionChecker: nil, // uses default
RollappKeeper: app.RollappKeeper,
})
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion app/apptesting/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ func (s *KeeperTestHelper) ExtractAttributes(event sdk.Event) map[string]string
func (s *KeeperTestHelper) AssertAttributes(event sdk.Event, eventAttributes []sdk.Attribute) {
attrs := s.ExtractAttributes(event)
for _, attr := range eventAttributes {
s.Assert().Equal(attr.Value, attrs[attr.Key])
s.Equal(attr.Value, attrs[attr.Key])
}
}
4 changes: 3 additions & 1 deletion app/apptesting/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"testing"
"time"

errorsmod "cosmossdk.io/errors"

"cosmossdk.io/math"

"github.com/dymensionxyz/dymension/v3/app/params"
Expand Down Expand Up @@ -453,7 +455,7 @@ func NewPubKeyFromHex(pk string) (res cryptotypes.PubKey) {
panic(err)
}
if len(pkBytes) != ed25519.PubKeySize {
panic(errors.Wrap(errors.ErrInvalidPubKey, "invalid pubkey size"))
panic(errorsmod.Wrap(errors.ErrInvalidPubKey, "invalid pubkey size"))
}
return &ed25519.PubKey{Key: pkBytes}
}
Expand Down
28 changes: 14 additions & 14 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,32 @@ type KeeperTestHelper struct {
Ctx sdk.Context
}

func (suite *KeeperTestHelper) CreateDefaultRollapp() string {
return suite.CreateRollappWithName(rand.Str(8))
func (s *KeeperTestHelper) CreateDefaultRollapp() string {
return s.CreateRollappWithName(rand.Str(8))
}

func (suite *KeeperTestHelper) CreateRollappWithName(name string) string {
func (s *KeeperTestHelper) CreateRollappWithName(name string) string {
msgCreateRollapp := rollapptypes.MsgCreateRollapp{
Creator: alice,
RollappId: name,
MaxSequencers: 5,
}

msgServer := rollappkeeper.NewMsgServerImpl(suite.App.RollappKeeper)
_, err := msgServer.CreateRollapp(suite.Ctx, &msgCreateRollapp)
suite.Require().NoError(err)
msgServer := rollappkeeper.NewMsgServerImpl(s.App.RollappKeeper)
_, err := msgServer.CreateRollapp(s.Ctx, &msgCreateRollapp)
s.Require().NoError(err)
return name
}

func (suite *KeeperTestHelper) CreateDefaultSequencer(ctx sdk.Context, rollappId string) string {
func (s *KeeperTestHelper) CreateDefaultSequencer(ctx sdk.Context, rollappId string) string {
pubkey1 := secp256k1.GenPrivKey().PubKey()
addr1 := sdk.AccAddress(pubkey1.Address())
pkAny1, err := codectypes.NewAnyWithValue(pubkey1)
suite.Require().Nil(err)
s.Require().Nil(err)

// fund account
err = bankutil.FundAccount(suite.App.BankKeeper, ctx, addr1, sdk.NewCoins(bond))
suite.Require().Nil(err)
err = bankutil.FundAccount(s.App.BankKeeper, ctx, addr1, sdk.NewCoins(bond))
s.Require().Nil(err)

sequencerMsg1 := sequencertypes.MsgCreateSequencer{
Creator: addr1.String(),
Expand All @@ -62,13 +62,13 @@ func (suite *KeeperTestHelper) CreateDefaultSequencer(ctx sdk.Context, rollappId
Description: sequencertypes.Description{},
}

msgServer := sequencerkeeper.NewMsgServerImpl(suite.App.SequencerKeeper)
msgServer := sequencerkeeper.NewMsgServerImpl(s.App.SequencerKeeper)
_, err = msgServer.CreateSequencer(ctx, &sequencerMsg1)
suite.Require().Nil(err)
s.Require().Nil(err)
return addr1.String()
}

func (suite *KeeperTestHelper) PostStateUpdate(ctx sdk.Context, rollappId, seqAddr string, startHeight, numOfBlocks uint64) (lastHeight uint64, err error) {
func (s *KeeperTestHelper) PostStateUpdate(ctx sdk.Context, rollappId, seqAddr string, startHeight, numOfBlocks uint64) (lastHeight uint64, err error) {
var bds rollapptypes.BlockDescriptors
bds.BD = make([]rollapptypes.BlockDescriptor, numOfBlocks)
for k := 0; k < int(numOfBlocks); k++ {
Expand All @@ -84,7 +84,7 @@ func (suite *KeeperTestHelper) PostStateUpdate(ctx sdk.Context, rollappId, seqAd
Version: 0,
BDs: bds,
}
msgServer := rollappkeeper.NewMsgServerImpl(suite.App.RollappKeeper)
msgServer := rollappkeeper.NewMsgServerImpl(s.App.RollappKeeper)
_, err = msgServer.UpdateState(ctx, &updateState)
return startHeight + numOfBlocks, err
}
7 changes: 4 additions & 3 deletions app/params/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package params

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -52,15 +53,15 @@ func SetAddressPrefixes() {

config.SetAddressVerifier(func(bytes []byte) error {
if len(bytes) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty")
return errorsmod.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty")
}

if len(bytes) > address.MaxAddrLen {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bytes))
return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bytes))
}

if len(bytes) != 20 && len(bytes) != 32 {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "address length must be 20 or 32 bytes, got %d", len(bytes))
return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "address length must be 20 or 32 bytes, got %d", len(bytes))
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/gorilla/mux v1.8.1
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/osmosis-labs/osmosis/v15 v15.2.0
github.com/pkg/errors v0.9.1
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
Expand Down Expand Up @@ -160,7 +161,6 @@ require (
github.com/osmosis-labs/osmosis/osmomath v0.0.4 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
Expand Down
Loading

0 comments on commit 4565f34

Please sign in to comment.