Skip to content

Commit

Permalink
fix(genesis bridge): get rollapp by light client ID rather than chain…
Browse files Browse the repository at this point in the history
… ID in transfer enabled check (#1339)
  • Loading branch information
danwt authored Oct 22, 2024
1 parent 8fb2d25 commit c9dae97
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
4 changes: 2 additions & 2 deletions app/ante/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func newLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
delayedack.NewIBCProofHeightDecorator(),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),
genesisbridge.NewTransferEnabledDecorator(options.RollappKeeper.GetRollapp, options.IBCKeeper.ChannelKeeper),
genesisbridge.NewTransferEnabledDecorator(options.RollappKeeper, options.IBCKeeper.ChannelKeeper),
)
}

Expand Down Expand Up @@ -111,6 +111,6 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
lightclientante.NewIBCMessagesDecorator(*options.LightClientKeeper, options.IBCKeeper.ClientKeeper, options.IBCKeeper.ChannelKeeper, options.RollappKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),
genesisbridge.NewTransferEnabledDecorator(options.RollappKeeper.GetRollapp, options.IBCKeeper.ChannelKeeper),
genesisbridge.NewTransferEnabledDecorator(options.RollappKeeper, options.IBCKeeper.ChannelKeeper),
)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/decred/dcrd/dcrec/edwards v1.0.0
github.com/dustin/go-humanize v1.0.1
github.com/dymensionxyz/gerr-cosmos v1.1.0
github.com/dymensionxyz/sdk-utils v0.2.9
github.com/dymensionxyz/sdk-utils v0.2.10
github.com/ethereum/go-ethereum v1.10.26
github.com/evmos/ethermint v0.22.0
github.com/gogo/protobuf v1.3.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ github.com/dymensionxyz/osmosis/osmomath v0.0.6-dymension-v0.1.0.20240820121212-
github.com/dymensionxyz/osmosis/osmomath v0.0.6-dymension-v0.1.0.20240820121212-c0e21fa21e43/go.mod h1:SdGCL9CZb14twRAJUSzb7bRE0OoopRpF2Hnd1UhJpFU=
github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20240820121212-c0e21fa21e43 h1:ugbpHwwlckB4W/aNXUTEsxaakPFgXi+LAsCtvfJ200Q=
github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20240820121212-c0e21fa21e43/go.mod h1:2rsnXAdjYfXtyEw0mNwAdOiAccALYjAPvINGUf9Qg7Y=
github.com/dymensionxyz/sdk-utils v0.2.9 h1:uokHmBjaygJKXQMI0EBhvjsIIYRCIa4Ndpq8tmMwoH8=
github.com/dymensionxyz/sdk-utils v0.2.9/go.mod h1:it9owYOpnIe17+ftTATQNDN4z+mBQx20/2Jm8SK15Rk=
github.com/dymensionxyz/sdk-utils v0.2.10 h1:dvUVzIpsdWGr5Ex+ltl/x1Abi+7sliwsGM1xAx/0p0k=
github.com/dymensionxyz/sdk-utils v0.2.10/go.mod h1:it9owYOpnIe17+ftTATQNDN4z+mBQx20/2Jm8SK15Rk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
Expand Down
3 changes: 3 additions & 0 deletions ibctesting/transfers_enabled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ func (s *transfersEnabledSuite) SetupTest() {
s.path = path

// manually set the rollapp to have transfers disabled by default
// (rollapp is setup correctly, meaning transfer channel is canonical)
ra := s.hubApp().RollappKeeper.MustGetRollapp(s.hubCtx(), rollappChainID())
ra.GenesisState.TransfersEnabled = false
ra.ChannelId = s.path.EndpointA.ChannelID
s.hubApp().RollappKeeper.SetRollapp(s.hubCtx(), ra)
s.hubApp().LightClientKeeper.SetCanonicalClient(s.hubCtx(), rollappChainID(), s.path.EndpointA.ClientID)
}

// Regular (non genesis) transfers (RA->Hub) and Hub->RA should both be blocked when the bridge is not open
Expand Down
32 changes: 17 additions & 15 deletions x/rollapp/genesisbridge/ante_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,48 @@ package genesisbridge
import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
"github.com/dymensionxyz/sdk-utils/utils/uibc"

transferTypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"

"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
)

// TODO: refactor this to use ICS4 wrapper similar to the RDK
// (https://github.com/dymensionxyz/dymension/issues/957)

type GetRollapp func(ctx sdk.Context, rollappId string) (val types.Rollapp, found bool)

type ChannelKeeper interface {
GetChannelClientState(ctx sdk.Context, portID, channelID string) (string, exported.ClientState, error) // implemented by ibc channel keeper
}

// TransferEnabledDecorator only allows ibc transfers to a rollapp if that rollapp has finished
// the genesis bridge protocol.
type TransferEnabledDecorator struct {
getRollapp GetRollapp
rollappK RollappKeeperMinimal
getChannelClientState ChannelKeeper
}

func NewTransferEnabledDecorator(getRollapp GetRollapp, getChannelClientState ChannelKeeper) *TransferEnabledDecorator {
func NewTransferEnabledDecorator(rollappK RollappKeeperMinimal, getChannelClientState ChannelKeeper) *TransferEnabledDecorator {
return &TransferEnabledDecorator{
getRollapp: getRollapp,
rollappK: rollappK,
getChannelClientState: getChannelClientState,
}
}

func (h TransferEnabledDecorator) transfersEnabled(ctx sdk.Context, transfer *transferTypes.MsgTransfer) (bool, error) {
chainID, err := uibc.ChainIDFromPortChannel(ctx, h.getChannelClientState, transfer.SourcePort, transfer.SourceChannel)
ra, err := h.rollappK.GetRollappByPortChan(ctx, transfer.SourcePort, transfer.SourceChannel)
if err != nil {
return false, errorsmod.Wrap(err, "chain id from port channel")
}
ra, ok := h.getRollapp(ctx, chainID)
if !ok {
return true, nil
if errorsmod.IsOf(err, types.ErrRollappNotFound) {
// Two cases
// 1. Non rollapp
// Transfers are enabled
// 2. It is for rollapp but the light client of this transfer is not yet canonical or will never
// be marked canonical: for a correct rollapp the transfer channel is only created after it's
// marked canonical, so this transfer corresponds to a not-relevant channel.
// Note: IBC prevents sending to a channel which is not OPEN, which prevents making the transfer
// for a channel before it is marked canonical in the onOpenAck hook.
return true, nil
}
return false, errorsmod.Wrap(err, "rollapp by port chan")
}
return ra.GenesisState.TransfersEnabled, nil
}
Expand Down
6 changes: 5 additions & 1 deletion x/rollapp/genesisbridge/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import (
)

type RollappKeeper interface {
GetRollappByPortChan(ctx sdk.Context, raPortOnHub, raChanOnHub string) (*rollapptypes.Rollapp, error)
RollappKeeperMinimal
SetRollapp(ctx sdk.Context, rollapp rollapptypes.Rollapp)
GetHooks() rollapptypes.MultiRollappHooks
}

type RollappKeeperMinimal interface {
GetRollappByPortChan(ctx sdk.Context, raPortOnHub, raChanOnHub string) (*rollapptypes.Rollapp, error)
}

type DenomMetadataKeeper interface {
CreateDenomMetadata(ctx sdk.Context, metadata banktypes.Metadata) error
HasDenomMetadata(ctx sdk.Context, base string) bool
Expand Down
3 changes: 1 addition & 2 deletions x/rollapp/genesisbridge/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)

// GenesisBridge IBC module is responsible for handling the genesis bridge protocol.
// IBCModule GenesisBridge is responsible for handling the genesis bridge protocol.
// (ADR: https://www.notion.so/dymension/ADR-x-Genesis-Bridge-109a4a51f86a80ba8b50db454bee04a7?pvs=4)
//
// It validated the genesis info registered on the hub, is the same as the rollapp's genesis info.
Expand Down Expand Up @@ -74,7 +74,6 @@ func (w IBCModule) logger(
// - validated the genesis info registered on the hub, is the same as the rollapp's genesis info.
// - registers the denom metadata for the native denom.
// - handles the genesis transfer.

// On success, it will mark the IBC channel for this rollapp as enabled. This marks the end of the genesis phase.
//
// NOTE: we assume that by this point the canonical channel ID has already been set for the rollapp, in a secure way.
Expand Down

0 comments on commit c9dae97

Please sign in to comment.