Skip to content

Commit

Permalink
feat: add packet forward middelware
Browse files Browse the repository at this point in the history
  • Loading branch information
ninabarbakadze committed Apr 2, 2024
1 parent 9376f20 commit ba897a6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 963 deletions.
39 changes: 38 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ import (
blobstreamkeeper "github.com/celestiaorg/celestia-app/x/blobstream/keeper"
blobstreamtypes "github.com/celestiaorg/celestia-app/x/blobstream/types"
ibctestingtypes "github.com/cosmos/ibc-go/v6/testing/types"

packetforward "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/router"
packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/router/keeper"

Check failure on line 103 in app/app.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

File is not `gofumpt`-ed (gofumpt)
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/router/types"
)

var (
Expand Down Expand Up @@ -126,6 +130,7 @@ var (
blobstream.AppModuleBasic{},
upgrade.AppModuleBasic{},
minfee.AppModuleBasic{},
packetforward.AppModuleBasic{},
)

// ModuleEncodingRegisters keeps track of all the module methods needed to
Expand Down Expand Up @@ -201,6 +206,8 @@ type App struct {
upgradeHeight int64
// used to define what messages are accepted for a given app version
MsgGateKeeper *ante.MsgVersioningGateKeeper

PacketForwardKeeper *packetforwardkeeper.Keeper
}

// New returns a reference to an initialized celestia app.
Expand Down Expand Up @@ -236,6 +243,7 @@ func New(
blobstreamtypes.StoreKey,
ibctransfertypes.StoreKey,
ibchost.StoreKey,
packetforwardtypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -332,9 +340,21 @@ func New(

// Create Transfer Keepers
tokenFilterKeeper := tokenfilter.NewKeeper(app.IBCKeeper.ChannelKeeper)

app.PacketForwardKeeper = packetforwardkeeper.NewKeeper(

Check failure on line 344 in app/app.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

File is not `gofumpt`-ed (gofumpt)
appCodec,
keys[packetforwardtypes.StoreKey],
app.GetSubspace(packetforwardtypes.ModuleName),
app.TransferKeeper, // will be zero-value here, reference is set later on with SetTransferKeeper.
app.IBCKeeper.ChannelKeeper,
app.DistrKeeper,
app.BankKeeper,
tokenFilterKeeper,
)

app.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName),
tokenFilterKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.PacketForwardKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.AccountKeeper, app.BankKeeper, app.ScopedTransferKeeper,
)
// transfer stack contains (from top to bottom):
Expand All @@ -343,6 +363,13 @@ func New(
var transferStack ibcporttypes.IBCModule
transferStack = transfer.NewIBCModule(app.TransferKeeper)
transferStack = tokenfilter.NewIBCMiddleware(transferStack)
transferStack = packetforward.NewIBCMiddleware(
transferStack,

Check failure on line 367 in app/app.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

File is not `gofumpt`-ed (gofumpt)
app.PacketForwardKeeper,
0, // retries on timeout
packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp, // forward timeout
packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp, // refund timeout
)

// Create evidence Keeper for to register the IBC light client misbehaviour evidence route
evidenceKeeper := evidencekeeper.NewKeeper(
Expand All @@ -363,6 +390,8 @@ func New(
app.GetSubspace(blobtypes.ModuleName),
)

app.PacketForwardKeeper.SetTransferKeeper(app.TransferKeeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := ibcporttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack)
Expand Down Expand Up @@ -462,6 +491,10 @@ func New(
Module: minfee.NewAppModule(app.ParamsKeeper),
FromVersion: v2, ToVersion: v2,
},
{
Module: packetforward.NewAppModule(app.PacketForwardKeeper),
FromVersion: v2, ToVersion: v2,
},
})
if err != nil {
panic(err)
Expand Down Expand Up @@ -493,6 +526,7 @@ func New(
vestingtypes.ModuleName,
upgradetypes.ModuleName,
minfee.ModuleName,
packetforwardtypes.ModuleName,
)

app.mm.SetOrderEndBlockers(
Expand All @@ -517,6 +551,7 @@ func New(
vestingtypes.ModuleName,
upgradetypes.ModuleName,
minfee.ModuleName,
packetforwardtypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -548,6 +583,7 @@ func New(
paramstypes.ModuleName,
authz.ModuleName,
upgradetypes.ModuleName,
packetforwardtypes.ModuleName,
)

app.QueryRouter().AddRoute(proof.TxInclusionQueryPath, proof.QueryTxInclusionProof)
Expand Down Expand Up @@ -814,6 +850,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(blobtypes.ModuleName)
paramsKeeper.Subspace(blobstreamtypes.ModuleName)
paramsKeeper.Subspace(minfee.ModuleName)
paramsKeeper.Subspace(packetforwardtypes.ModuleName)

return paramsKeeper
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/cosmos/cosmos-proto v1.0.0-beta.4
github.com/cosmos/cosmos-sdk v0.46.16
github.com/cosmos/gogoproto v1.4.12
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6 v6.1.1
github.com/cosmos/ibc-go/v6 v6.2.1
github.com/ethereum/go-ethereum v1.13.14
github.com/gogo/protobuf v1.3.3
Expand Down Expand Up @@ -137,6 +138,7 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hdevalence/ed25519consensus v0.0.0-20220222234857-c00d1f31bab3 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/iancoleman/orderedmap v0.2.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4
github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw=
github.com/cosmos/iavl v0.19.6 h1:XY78yEeNPrEYyNCKlqr9chrwoeSDJ0bV2VjocTk//OU=
github.com/cosmos/iavl v0.19.6/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw=
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6 v6.1.1 h1:2geCtV4PoNPeRnVc0HMAcRcv+7W3Mvk2nmASkGkOdzE=
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6 v6.1.1/go.mod h1:ovYRGX7P7Vq0D54JIVlIm/47STEKgWJfw9frvL0AWGQ=
github.com/cosmos/ibc-go/v6 v6.2.1 h1:NiaDXTRhKwf3n9kELD4VRIe5zby1yk1jBvaz9tXTQ6k=
github.com/cosmos/ibc-go/v6 v6.2.1/go.mod h1:XLsARy4Y7+GtAqzMcxNdlQf6lx+ti1e8KcMGv5NIK7A=
github.com/cosmos/ledger-cosmos-go v0.12.4 h1:drvWt+GJP7Aiw550yeb3ON/zsrgW0jgh5saFCr7pDnw=
Expand Down Expand Up @@ -862,6 +864,8 @@ github.com/huin/goupnp v1.0.3-0.20220313090229-ca81a64b4204/go.mod h1:ZxNlw5WqJj
github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o=
github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6jq8pNA=
github.com/iancoleman/orderedmap v0.2.0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
Expand Down
Loading

0 comments on commit ba897a6

Please sign in to comment.