Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: removed code duplication in delayed ack middleware #559

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
5c2fd20
Extended rollapp packet with type of msg (e.g onRecv, onAck, onTimeout)
omritoptix Jan 12, 2024
4455fbf
Updated delayack ibc middleware and hooks to support delayed OnAck.
omritoptix Jan 12, 2024
6911281
Added delayack support also for OnTimeoutPacket.
omritoptix Jan 12, 2024
f0287cf
Create eibc module template from ignite.
omritoptix Jan 18, 2024
c1a7ca7
Added initial proto files for demand order and fulfill order tx.
omritoptix Jan 21, 2024
e58b814
Updated .gitignore.
omritoptix Jan 21, 2024
60aea6c
Added eibc basic types and common types.
omritoptix Jan 21, 2024
c0e14b6
Added functionallity in eibc module to fulfill order.
omritoptix Jan 21, 2024
c7563de
Added eibc hooks for relevant subscribers.
omritoptix Jan 21, 2024
87815c7
Added delayed ack hooks for relevant subscribers.
omritoptix Jan 21, 2024
19622f2
Created eibc hook listener on delayedAck hook to update the demand or…
omritoptix Jan 21, 2024
9fa5075
Updated delayedack middleware to create eibc demand order when the re…
omritoptix Jan 21, 2024
7f1cd0d
Created hook listener on delayedAck to update recipeint of underlying…
omritoptix Jan 21, 2024
2bf05bd
Update function name in delayedAck hooks.
omritoptix Jan 21, 2024
e03bc69
Created wiring for the new eibc module and relevant hooks in app.go
omritoptix Jan 21, 2024
20ad5bc
Created unitests for eibc middleware and updated ibc utils suite.
omritoptix Jan 21, 2024
f113c2f
Fixed markdown lint errors.
omritoptix Jan 21, 2024
3d460d3
Fixed rollap packet test.
omritoptix Jan 21, 2024
b3c6dab
Added an upgrade handler for eibc.
omritoptix Jan 21, 2024
a8b3cbd
Added cli command for fulfilling demand orders.
omritoptix Jan 21, 2024
1afddd3
Updated genesis config params to have -1 as max gas per block.
omritoptix Jan 21, 2024
2e2fe53
Added a fix to check for Ack and Timeout with cache context to preven…
omritoptix Jan 23, 2024
5e41560
Added a fix to run FinalizeRollappPackets loop funcs in cachedContext…
omritoptix Feb 3, 2024
8e5a8be
Merged with main.
omritoptix Feb 3, 2024
3da0ebf
Merged with omritoptix/393-delay-ack-and-timeout branch.
omritoptix Feb 3, 2024
ed1d715
Added export genesis function for eibc to export all demand orders.
omritoptix Feb 3, 2024
a907f4a
Added ability to fetch demand orders by status and fixed bug with upd…
omritoptix Feb 3, 2024
8fd6c0c
Added deletion of demand order with finalized status upon epoch as de…
omritoptix Feb 4, 2024
11da83a
Fixed bug where OnRecvPacket in delayedack hooks didn't run in a wrap…
omritoptix Feb 4, 2024
90b5e4c
Removed redundant isTimeout field from rollapp_packet proto.
omritoptix Feb 4, 2024
f176fc9
Added init and export genesis functions.
omritoptix Feb 4, 2024
07a2df0
Changed redundant switch case for if.
omritoptix Feb 4, 2024
825fb5a
Fixed bug with SetRollappPacket which ignored the packet status.
omritoptix Feb 4, 2024
83a5445
Merged with omritoptix/393-delay-ack-and-timeout branch - take 2.
omritoptix Feb 4, 2024
be93411
Fixed PR comments - replaced panic with returning err
omritoptix Feb 4, 2024
44864db
Merged from main.
omritoptix Feb 4, 2024
a029444
Registered MsfFulfillOrder amino codec.
omritoptix Feb 5, 2024
9b74581
Added validation for eibc packet metadata.
omritoptix Feb 5, 2024
f21f794
Moved eibc middleware logic to a seperate module.
omritoptix Feb 5, 2024
bcc29cb
Added missing init genesis with demand orders for eibc
omritoptix Feb 5, 2024
15a0223
Added test line for testing the init genesis.
omritoptix Feb 5, 2024
7e4585b
Changed eibc to use sdk coin types.
omritoptix Feb 5, 2024
f2b5009
Removed redundant keeper and added unique error msg upon demand order…
omritoptix Feb 5, 2024
f197c03
Changed to err instead of panic in hook code and changed common util …
omritoptix Feb 5, 2024
1011962
Changed that FinalizeRollappPackets hook will fail upon update failur…
omritoptix Feb 6, 2024
befd98a
Fixed genesis intialization where if err would return it would skip i…
omritoptix Feb 6, 2024
b1accec
Fixed linter configuration for errcheck.
omritoptix Feb 6, 2024
412313f
test: delayed ack timeout test (#541)
omritoptix Feb 11, 2024
3c1dc00
Merged with omritoptix/490-eibc-v1.
omritoptix Feb 11, 2024
1bfc91c
Fixed eibc deletion hook to not fail all packets deletion upon speci…
omritoptix Feb 11, 2024
422be93
removed duplicate code to it's own functions.
omritoptix Feb 11, 2024
c74c052
Added missing error handling for SaveDemandOrder
omritoptix Feb 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ I have...
- [ ] All CI checks have passed
- [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code)

---
---;

For Reviewer:

- [ ] Confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] Reviewers assigned
- [ ] Confirmed all author checklist items have been addressed

---
---;

After reviewer approval:

Expand Down
5 changes: 4 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ linters-settings:
rules:
- name: exported
severity: warning
disabled: true
disabled: true
errcheck:
check-type-assertions: true

69 changes: 69 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -128,6 +129,10 @@ import (
delayedackkeeper "github.com/dymensionxyz/dymension/v3/x/delayedack/keeper"
delayedacktypes "github.com/dymensionxyz/dymension/v3/x/delayedack/types"

eibcmodule "github.com/dymensionxyz/dymension/v3/x/eibc"
eibckeeper "github.com/dymensionxyz/dymension/v3/x/eibc/keeper"
eibcmoduletypes "github.com/dymensionxyz/dymension/v3/x/eibc/types"

packetforwardmiddleware "github.com/strangelove-ventures/packet-forward-middleware/v6/router"
packetforwardkeeper "github.com/strangelove-ventures/packet-forward-middleware/v6/router/keeper"
packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v6/router/types"
Expand Down Expand Up @@ -168,6 +173,10 @@ import (
txfees "github.com/osmosis-labs/osmosis/v15/x/txfees"
txfeeskeeper "github.com/osmosis-labs/osmosis/v15/x/txfees/keeper"
txfeestypes "github.com/osmosis-labs/osmosis/v15/x/txfees/types"

/* ---------------------------- upgrade handlers ---------------------------- */

v3upgrade "github.com/dymensionxyz/dymension/v3/app/upgrades/v3"
)

var (
Expand Down Expand Up @@ -229,6 +238,7 @@ var (
streamermodule.AppModuleBasic{},
packetforwardmiddleware.AppModuleBasic{},
delayedackmodule.AppModuleBasic{},
eibcmodule.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic

// Ethermint modules
Expand Down Expand Up @@ -337,6 +347,7 @@ type App struct {
RollappKeeper rollappmodulekeeper.Keeper
SequencerKeeper sequencermodulekeeper.Keeper
StreamerKeeper streamermodulekeeper.Keeper
EIBCKeeper eibckeeper.Keeper

// this line is used by starport scaffolding # stargate/app/keeperDeclaration
DelayedAckKeeper delayedackkeeper.Keeper
Expand Down Expand Up @@ -387,6 +398,7 @@ func New(
streamermoduletypes.StoreKey,
packetforwardtypes.StoreKey,
delayedacktypes.StoreKey,
eibcmoduletypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey

// ethermint keys
Expand Down Expand Up @@ -580,6 +592,15 @@ func New(
app.IncentivesKeeper,
)

app.EIBCKeeper = *eibckeeper.NewKeeper(
appCodec,
keys[eibcmoduletypes.StoreKey],
keys[eibcmoduletypes.MemStoreKey],
app.GetSubspace(eibcmoduletypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
)

app.DelayedAckKeeper = *delayedackkeeper.NewKeeper(
appCodec,
keys[delayedacktypes.StoreKey],
Expand All @@ -589,6 +610,8 @@ func New(
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.ConnectionKeeper,
app.IBCKeeper.ClientKeeper,
app.EIBCKeeper,
app.BankKeeper,
)

/* -------------------------------- set hooks ------------------------------- */
Expand All @@ -615,6 +638,16 @@ func New(
),
)

app.DelayedAckKeeper.SetHooks(delayedacktypes.NewMultiDelayedAckHooks(
// insert delayedAck hooks receivers here
app.EIBCKeeper.GetDelayedAckHooks(),
))

app.EIBCKeeper.SetHooks(eibcmoduletypes.NewMultiEIBCHooks(
// insert eibc hooks receivers here
app.DelayedAckKeeper.GetEIBCHooks(),
))

sequencerModule := sequencermodule.NewAppModule(appCodec, app.SequencerKeeper, app.AccountKeeper, app.BankKeeper)
rollappModule := rollappmodule.NewAppModule(appCodec, &app.RollappKeeper, app.AccountKeeper, app.BankKeeper)
streamerModule := streamermodule.NewAppModule(app.StreamerKeeper, app.AccountKeeper, app.BankKeeper, app.EpochsKeeper)
Expand Down Expand Up @@ -726,6 +759,7 @@ func New(
sequencerModule,
streamerModule,
delayedackModule,
eibcmodule.NewAppModule(appCodec, app.EIBCKeeper, app.AccountKeeper, app.BankKeeper),
// this line is used by starport scaffolding # stargate/app/appModule

// Ethermint app modules
Expand Down Expand Up @@ -772,6 +806,7 @@ func New(
sequencermoduletypes.ModuleName,
streamermoduletypes.ModuleName,
delayedacktypes.ModuleName,
eibcmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
lockuptypes.ModuleName,
gammtypes.ModuleName,
Expand Down Expand Up @@ -806,6 +841,7 @@ func New(
sequencermoduletypes.ModuleName,
streamermoduletypes.ModuleName,
delayedacktypes.ModuleName,
eibcmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/endBlockers
epochstypes.ModuleName,
lockuptypes.ModuleName,
Expand Down Expand Up @@ -846,6 +882,7 @@ func New(
sequencermoduletypes.ModuleName,
streamermoduletypes.ModuleName,
delayedacktypes.ModuleName,
eibcmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis

epochstypes.ModuleName,
Expand Down Expand Up @@ -889,6 +926,7 @@ func New(

app.SetAnteHandler(anteHandler)
app.SetEndBlocker(app.EndBlocker)
app.setupUpgradeHandlers()

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
Expand Down Expand Up @@ -1076,6 +1114,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(rollappmoduletypes.ModuleName)
paramsKeeper.Subspace(sequencermoduletypes.ModuleName)
paramsKeeper.Subspace(streamermoduletypes.ModuleName)
paramsKeeper.Subspace(eibcmoduletypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace

// ethermint subspaces
Expand Down Expand Up @@ -1120,3 +1159,33 @@ func (app *App) GetTxConfig() client.TxConfig {
func (app *App) ExportState(ctx sdk.Context) map[string]json.RawMessage {
return app.mm.ExportGenesis(ctx, app.AppCodec())
}

// TODO: Create upgrade interface and setup generic upgrades handling a la osmosis
func (app *App) setupUpgradeHandlers() {
UpgradeName := "v3"

app.UpgradeKeeper.SetUpgradeHandler(
UpgradeName,
v3upgrade.CreateUpgradeHandler(
app.mm, app.configurator,
),
)

// When a planned update height is reached, the old binary will panic
// writing on disk the height and name of the update that triggered it
// This will read that value, and execute the preparations for the upgrade.
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Errorf("failed to read upgrade info from disk: %w", err))
}

// Pre upgrade handler
switch upgradeInfo.Name {
// do nothing
}

if upgradeInfo.Name == "v3" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
// configure store loader with the store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, v3upgrade.GetStoreUpgrades()))
}
}
5 changes: 5 additions & 0 deletions app/upgrades/v3/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package v3

const (
UpgradeName = "v3"
)
33 changes: 33 additions & 0 deletions app/upgrades/v3/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package v3

import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

func GetStoreUpgrades() *storetypes.StoreUpgrades {
storeUpgrades := storetypes.StoreUpgrades{
// Set migrations for all new modules
Added: []string{"eibc"},
}
return &storeUpgrades
}

// CreateUpgradeHandler creates an SDK upgrade handler for v3
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,

) upgradetypes.UpgradeHandler {

return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {

logger := ctx.Logger().With("upgrade", UpgradeName)

// Start running the module migrations
logger.Debug("running module migrations ...")
return mm.RunMigrations(ctx, configurator, vm)
}
}
1 change: 1 addition & 0 deletions contrib/githooks/pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ repos:
rev: v1.53.3
hooks:
- id: golangci-lint
args: [--config=./.golangci.yml]
#
# # Invoking Custom Go Tools
# # - Configured *entirely* through the `args` attribute, ie:
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/cosmos/cosmos-sdk v0.46.15
github.com/cosmos/ibc-go/v6 v6.2.1
github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac
github.com/dymensionxyz/dymension v1.0.0-rc1.0.20231219114210-d548bc8ea087
github.com/ethereum/go-ethereum v1.10.26
github.com/evmos/ethermint v0.22.0
github.com/gogo/protobuf v1.3.3
Expand Down Expand Up @@ -89,7 +90,6 @@ require (
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-playground/validator/v10 v10.4.1 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
Expand Down Expand Up @@ -143,7 +143,6 @@ require (
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/osmosis-labs/osmosis/osmomath v0.0.4 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac h1:opbrjaN/L8
github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dvsekhvalnov/jose2go v1.5.0 h1:3j8ya4Z4kMCwT5nXIKFSV84YS+HdqSSO0VsTQxaLAeM=
github.com/dvsekhvalnov/jose2go v1.5.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
github.com/dymensionxyz/dymension v1.0.0-rc1.0.20231219114210-d548bc8ea087 h1:fAmkTkcGW8sLDYMSFAupVD7BsFtIi3KRITS5DIiHMDQ=
github.com/dymensionxyz/dymension v1.0.0-rc1.0.20231219114210-d548bc8ea087/go.mod h1:gdszhnhMNx1MTUQp1BzlrMHY9CcSra0hNxTVoio32Gs=
github.com/dymensionxyz/ethermint v0.22.0-dymension-v0.3 h1:iAtAivMtJh2Ublnq2KasC7EIa5/gfsff5EJ7kUlnd9A=
github.com/dymensionxyz/ethermint v0.22.0-dymension-v0.3/go.mod h1:O2J61ZwM0Vdms6pRa1fb43pwmCuNRctro3AB90WlOc0=
github.com/dymensionxyz/osmosis/osmomath v0.0.6-dym-v0.0.1 h1:59ZE3Ocrn04MUpb5VJgfi24eDcnQ9VBfCSw0Mx1n7OI=
Expand Down Expand Up @@ -541,7 +543,6 @@ github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD87
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU=
github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
Expand Down Expand Up @@ -952,7 +953,6 @@ github.com/neilotoole/errgroup v0.1.6/go.mod h1:Q2nLGf+594h0CLBs/Mbg6qOr7GtqDK7C
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
Expand Down
Loading
Loading