Skip to content

Commit

Permalink
Merge branch 'main' into rp/upgrade-test-blobstream
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp authored Apr 30, 2024
2 parents cc86f51 + 05b3d9e commit 5e8a96b
Show file tree
Hide file tree
Showing 44 changed files with 1,956 additions and 34 deletions.
22 changes: 20 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,17 +326,22 @@ func New(
)
// transfer stack contains (from top to bottom):
// - Token Filter
// - Packet Forwarding Middleware
// - Transfer
var transferStack ibcporttypes.IBCModule
transferStack = transfer.NewIBCModule(app.TransferKeeper)
transferStack = tokenfilter.NewIBCMiddleware(transferStack)
transferStack = packetforward.NewIBCMiddleware(
packetForwardMiddleware := packetforward.NewIBCMiddleware(
transferStack,
app.PacketForwardKeeper,
0, // retries on timeout
packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp, // forward timeout
packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp, // refund timeout
)
// packetForwardMiddleware is used only for version 2
transferStack = module.NewVersionedIBCModule(packetForwardMiddleware, transferStack, v2, v2)
// token filter wraps packet forward middleware and is thus the first module in the transfer stack
tokenFilterMiddelware := tokenfilter.NewIBCMiddleware(transferStack)
transferStack = module.NewVersionedIBCModule(tokenFilterMiddelware, transferStack, v1, v2)

app.EvidenceKeeper = *evidencekeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -498,6 +503,19 @@ func (app *App) migrateModules(ctx sdk.Context, fromVersion, toVersion uint64) e
// We wrap Info around baseapp so we can take the app version and
// setup the multicommit store.
func (app *App) Info(req abci.RequestInfo) abci.ResponseInfo {
if height := app.LastBlockHeight(); height > 0 {
ctx, err := app.CreateQueryContext(height, false)
if err != nil {
panic(err)
}
appVersion := app.GetAppVersionFromParamStore(ctx)
if appVersion > 0 {
app.SetAppVersion(ctx, appVersion)
} else {
app.SetAppVersion(ctx, v1)
}
}

resp := app.BaseApp.Info(req)
// mount the stores for the provided app version
if resp.AppVersion > 0 && !app.IsSealed() {
Expand Down
149 changes: 149 additions & 0 deletions app/module/ibc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package module

import (
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types"
exported "github.com/cosmos/ibc-go/v6/modules/core/exported"
)

func NewVersionedIBCModule(
wrappedModule, nextModule porttypes.IBCModule,
fromVersion, toVersion uint64,
) porttypes.IBCModule {
return &VersionedIBCModule{
wrappedModule: wrappedModule,
nextModule: nextModule,
fromVersion: fromVersion,
toVersion: toVersion,
}
}

var _ porttypes.IBCModule = (*VersionedIBCModule)(nil)

type VersionedIBCModule struct {
wrappedModule, nextModule porttypes.IBCModule
fromVersion, toVersion uint64
}

func (v *VersionedIBCModule) OnChanOpenInit(
ctx sdk.Context,
order channeltypes.Order,
connectionHops []string,
portID string,
channelID string,
channelCap *capabilitytypes.Capability,
counterparty channeltypes.Counterparty,
version string,
) (string, error) {
currentAppVersion := ctx.BlockHeader().Version.App
if currentAppVersion >= v.fromVersion && currentAppVersion <= v.toVersion {
return v.wrappedModule.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, channelCap, counterparty, version)
}
return v.nextModule.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, channelCap, counterparty, version)
}

func (v *VersionedIBCModule) OnChanOpenTry(
ctx sdk.Context,
order channeltypes.Order,
connectionHops []string,
portID,
channelID string,
channelCap *capabilitytypes.Capability,
counterparty channeltypes.Counterparty,
counterpartyVersion string,
) (version string, err error) {
currentAppVersion := ctx.BlockHeader().Version.App
if currentAppVersion >= v.fromVersion && currentAppVersion <= v.toVersion {
return v.wrappedModule.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, channelCap, counterparty, counterpartyVersion)
}
return v.nextModule.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, channelCap, counterparty, counterpartyVersion)
}

func (v *VersionedIBCModule) OnChanOpenAck(
ctx sdk.Context,
portID,
channelID string,
counterpartyChannelID string,
counterpartyVersion string,
) error {
currentAppVersion := ctx.BlockHeader().Version.App
if currentAppVersion >= v.fromVersion && currentAppVersion <= v.toVersion {
return v.wrappedModule.OnChanOpenAck(ctx, portID, channelID, counterpartyChannelID, counterpartyVersion)
}
return v.nextModule.OnChanOpenAck(ctx, portID, channelID, counterpartyChannelID, counterpartyVersion)
}

func (v *VersionedIBCModule) OnChanOpenConfirm(
ctx sdk.Context,
portID,
channelID string,
) error {
currentAppVersion := ctx.BlockHeader().Version.App
if currentAppVersion >= v.fromVersion && currentAppVersion <= v.toVersion {
return v.wrappedModule.OnChanOpenConfirm(ctx, portID, channelID)
}
return v.nextModule.OnChanOpenConfirm(ctx, portID, channelID)
}

func (v *VersionedIBCModule) OnChanCloseInit(
ctx sdk.Context,
portID,
channelID string,
) error {
currentVersion := ctx.BlockHeader().Version.App
if currentVersion >= v.fromVersion && currentVersion <= v.toVersion {
return v.wrappedModule.OnChanCloseInit(ctx, portID, channelID)
}
return v.nextModule.OnChanCloseInit(ctx, portID, channelID)
}

func (v *VersionedIBCModule) OnChanCloseConfirm(
ctx sdk.Context,
portID,
channelID string,
) error {
currentVersion := ctx.BlockHeader().Version.App
if currentVersion >= v.fromVersion && currentVersion <= v.toVersion {
return v.wrappedModule.OnChanCloseConfirm(ctx, portID, channelID)
}
return v.nextModule.OnChanCloseConfirm(ctx, portID, channelID)
}

func (v *VersionedIBCModule) OnRecvPacket(
ctx sdk.Context,
packet channeltypes.Packet,
relayer sdk.AccAddress,
) exported.Acknowledgement {
currentVersion := ctx.BlockHeader().Version.App
if currentVersion >= v.fromVersion && currentVersion <= v.toVersion {
return v.wrappedModule.OnRecvPacket(ctx, packet, relayer)
}
return v.nextModule.OnRecvPacket(ctx, packet, relayer)
}

func (v *VersionedIBCModule) OnAcknowledgementPacket(
ctx sdk.Context,
packet channeltypes.Packet,
acknowledgement []byte,
relayer sdk.AccAddress,
) error {
currentVersion := ctx.BlockHeader().Version.App
if currentVersion >= v.fromVersion && currentVersion <= v.toVersion {
return v.wrappedModule.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer)
}
return v.nextModule.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer)
}

func (v *VersionedIBCModule) OnTimeoutPacket(
ctx sdk.Context,
packet channeltypes.Packet,
relayer sdk.AccAddress,
) error {
currentVersion := ctx.BlockHeader().Version.App
if currentVersion >= v.fromVersion && currentVersion <= v.toVersion {
return v.wrappedModule.OnTimeoutPacket(ctx, packet, relayer)
}
return v.nextModule.OnTimeoutPacket(ctx, packet, relayer)
}
6 changes: 2 additions & 4 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (app *App) setupModuleManager(skipGenesisInvariants bool) error {
},
{
Module: blobstream.NewAppModule(app.appCodec, app.BlobstreamKeeper),
FromVersion: v1, ToVersion: v2,
FromVersion: v1, ToVersion: v1,
},
{
Module: signal.NewAppModule(app.SignalKeeper),
Expand Down Expand Up @@ -299,8 +299,7 @@ func allStoreKeys() []string {
}
}

// versionedStoreKeys returns the store keys for each app version
// ... I wish there was an easier way than this (like using the modules which are already versioned)
// versionedStoreKeys returns the store keys for each app version.
func versionedStoreKeys() map[uint64][]string {
return map[uint64][]string{
1: {
Expand All @@ -325,7 +324,6 @@ func versionedStoreKeys() map[uint64][]string {
authtypes.StoreKey,
authzkeeper.StoreKey,
banktypes.StoreKey,
blobstreamtypes.StoreKey,
capabilitytypes.StoreKey,
distrtypes.StoreKey,
evidencetypes.StoreKey,
Expand Down
4 changes: 3 additions & 1 deletion app/test/qgb_rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ func TestBlobstreamRPCQueries(t *testing.T) {
t.Skip("skipping blobstream integration test in short mode.")
}
ecfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)
cfg := testnode.DefaultConfig().WithModifiers(genesis.SetDataCommitmentWindow(ecfg.Codec, 100))
cfg := testnode.DefaultConfig().
WithModifiers(genesis.SetDataCommitmentWindow(ecfg.Codec, 100)).
WithConsensusParams(app.DefaultInitialConsensusParams())

cctx, _, _ := testnode.NewNetwork(t, cfg)

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de
google.golang.org/grpc v1.63.2
google.golang.org/protobuf v1.33.0
google.golang.org/protobuf v1.34.0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down Expand Up @@ -129,7 +129,7 @@ require (
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.7.0 // indirect
github.com/hashicorp/go-getter v1.7.4 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,8 @@ github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtng
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-getter v1.7.0 h1:bzrYP+qu/gMrL1au7/aDvkoOVGUJpeKBgbqRHACAFDY=
github.com/hashicorp/go-getter v1.7.0/go.mod h1:W7TalhMmbPmsSMdNjD0ZskARur/9GJ17cfHTRtXV744=
github.com/hashicorp/go-getter v1.7.4 h1:3yQjWuxICvSpYwqSayAdKRFcvBl1y/vogCxczWSmix0=
github.com/hashicorp/go-getter v1.7.4/go.mod h1:W7TalhMmbPmsSMdNjD0ZskARur/9GJ17cfHTRtXV744=
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc=
github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
Expand Down Expand Up @@ -2075,8 +2075,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4=
google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
Loading

0 comments on commit 5e8a96b

Please sign in to comment.