-
Notifications
You must be signed in to change notification settings - Fork 345
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
feat(hard_fork): part2 (Delyayed ack callback) #1355
Merged
mtsitrin
merged 9 commits into
mtsitrin/937-rollapp-hard-fork-hub-side
from
delyayedAck_callback
Oct 31, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bc97ab9
handle delayed ACK hard fork
mtsitrin 15265c9
DRY code
mtsitrin 98fdc67
updated invariants
mtsitrin 711ed12
removed reverted status
mtsitrin a876310
eibc allows deletion of pending orders
mtsitrin fe155de
disabled invariants. fixed UT
mtsitrin 92a67e0
Merge branch 'mtsitrin/937-rollapp-hard-fork-hub-side' into delyayedA…
mtsitrin 5da8f8d
PR comments
mtsitrin 5a5df7b
fixed deletion of packet receipts
mtsitrin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,16 @@ | |
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" | ||
host "github.com/cosmos/ibc-go/v7/modules/core/24-host" | ||
|
||
commontypes "github.com/dymensionxyz/dymension/v3/x/common/types" | ||
) | ||
|
||
func (k Keeper) HandleFraud(ctx sdk.Context, rollappID string, ibc porttypes.IBCModule) error { | ||
// Get all the pending packets | ||
rollappPendingPackets := k.ListRollappPackets(ctx, types.ByRollappIDByStatus(rollappID, commontypes.Status_PENDING)) | ||
if len(rollappPendingPackets) == 0 { | ||
return nil | ||
} | ||
func (k Keeper) HandleHardFork(ctx sdk.Context, rollappID string, height uint64, ibc porttypes.IBCModule) error { | ||
logger := ctx.Logger().With("module", "DelayedAckMiddleware") | ||
logger.Info("reverting IBC rollapp packets", "rollappID", rollappID) | ||
|
||
// Get all the pending packets from fork height inclusive | ||
rollappPendingPackets := k.ListRollappPackets(ctx, types.PendingByRollappIDFromHeight(rollappID, height)) | ||
|
||
// Iterate over all the pending packets and revert them | ||
for _, rollappPacket := range rollappPendingPackets { | ||
|
@@ -28,22 +26,31 @@ | |
"sequence", rollappPacket.Packet.Sequence, | ||
} | ||
|
||
// refund all pending outgoing packets | ||
if rollappPacket.Type == commontypes.RollappPacket_ON_ACK || rollappPacket.Type == commontypes.RollappPacket_ON_TIMEOUT { | ||
// refund all pending outgoing packets | ||
// we don't have access directly to `refundPacketToken` function, so we'll use the `OnTimeoutPacket` function | ||
err := ibc.OnTimeoutPacket(ctx, *rollappPacket.Packet, rollappPacket.Relayer) | ||
if err != nil { | ||
logger.Error("failed to refund reverted packet", append(logContext, "error", err.Error())...) | ||
} | ||
Comment on lines
+29
to
35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be changed to follow the ADR:
|
||
} | ||
// Update status to reverted | ||
_, err := k.UpdateRollappPacketWithStatus(ctx, rollappPacket, commontypes.Status_REVERTED) | ||
if err != nil { | ||
logger.Error("error reverting IBC rollapp packet", append(logContext, "error", err.Error())...) | ||
return err | ||
} else { | ||
// for incoming packets, we need to reset the packet receipt | ||
ibcPacket := rollappPacket.Packet | ||
k.deletePacketReceipt(ctx, ibcPacket.GetDestPort(), ibcPacket.GetDestChannel(), ibcPacket.GetSequence()) | ||
} | ||
|
||
// delete the packet | ||
k.DeleteRollappPacket(ctx, &rollappPacket) | ||
logger.Debug("reverted IBC rollapp packet", logContext...) | ||
} | ||
|
||
logger.Info("reverting IBC rollapp packets", "rollappID", rollappID, "numPackets", len(rollappPendingPackets)) | ||
|
||
return nil | ||
} | ||
|
||
// DeleteRollappPacket deletes a packet receipt from the store | ||
func (k Keeper) deletePacketReceipt(ctx sdk.Context, portID, channelID string, sequence uint64) { | ||
store := ctx.KVStore(k.channelKeeperStoreKey) | ||
store.Delete(host.PacketReceiptKey(portID, channelID, sequence)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably wont fix for now but I think possible DOS if a lot of packets and fraud is e.g few days ago.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls open research topic