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

fix: Add support for delayedack middleware to also delay ack and timeout packets #480

Merged
merged 11 commits into from
Feb 4, 2024

Conversation

omritoptix
Copy link
Contributor

@omritoptix omritoptix commented Jan 12, 2024

Description


Closes #XXX

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow-up issues.

PR review checkboxes:

I have...

  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Targeted PR against the correct branch
  • included the correct type prefix in the PR title
  • Linked to the GitHub issue with discussion and accepted design
  • Targets only one GitHub issue
  • Wrote unit and integration tests
  • Wrote relevant migration scripts if necessary
  • All CI checks have passed
  • Added relevant godoc comments

For Reviewer:

  • Confirmed the correct type prefix in the PR title
  • Reviewers assigned
  • Confirmed all author checklist items have been addressed

After reviewer approval:

  • In case the PR targets the main branch, PR should not be squash merge in order to keep meaningful git history.
  • In case the PR targets a release branch, PR must be rebased.

@omritoptix omritoptix requested a review from a team as a code owner January 12, 2024 17:04
@omritoptix omritoptix linked an issue Jan 12, 2024 that may be closed by this pull request
2 tasks
Copy link

codecov bot commented Jan 12, 2024

Codecov Report

Attention: 285 lines in your changes are missing coverage. Please review.

Comparison is base (9c1be1f) 30.87% compared to head (825fb5a) 30.71%.

Files Patch % Lines
x/delayedack/types/rollapp_packet.pb.go 22.79% 95 Missing and 10 partials ⚠️
x/delayedack/ibc_middleware.go 13.54% 80 Missing and 3 partials ⚠️
x/delayedack/types/genesis.pb.go 0.00% 53 Missing ⚠️
x/delayedack/hooks.go 24.07% 38 Missing and 3 partials ⚠️
x/delayedack/genesis.go 50.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #480      +/-   ##
==========================================
- Coverage   30.87%   30.71%   -0.16%     
==========================================
  Files         166      166              
  Lines       25383    25719     +336     
==========================================
+ Hits         7836     7900      +64     
- Misses      16299    16552     +253     
- Partials     1248     1267      +19     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -32,24 +32,37 @@ func (im IBCMiddleware) FinalizeRollappPackets(ctx sdk.Context, rollappID string
// Get the packets for the rollapp until height
logger.Debug("Finalizing IBC rollapp packets", "rollappID", rollappID, "state end height", stateEndHeight, "num packets", len(rollappPendingPackets))
for _, rollappPacket := range rollappPendingPackets {
logger.Debug("Finalizing IBC rollapp packet", "rollappID", rollappID, "sequence", rollappPacket.Packet.GetSequence(), "destination channel", rollappPacket.Packet.GetDestChannel())
logger.Debug("Finalizing IBC rollapp packet", "rollappID", rollappID, "sequence", rollappPacket.Packet.GetSequence(), "destination channel", rollappPacket.Packet.GetDestChannel(), "type", rollappPacket.Type)
// Update the packet status
im.keeper.UpdateRollappPacketStatus(ctx, rollappID, rollappPacket, types.RollappPacket_ACCEPTED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to move it after the switch case, and set according to the error received

// Update the packet status
if err != nil {
	im.keeper.UpdateRollappPacketStatus(ctx, rollappID, rollappPacket, types.RollappPacket_REJECTED)
} else {
	im.keeper.UpdateRollappPacketStatus(ctx, rollappID, rollappPacket, types.RollappPacket_ACCEPTED)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are 3 different concepts here:

  1. Accepted means that its finalized (changed this name in the eibc PR for better name, i.e "FINALIZED").
  2. err means that there was an error running the underlying ibc method
  3. REJECTED means that there was a fraud and the packet was not finalized (changed it to REVERTED).

so err doesn't mean rejected as there was no fraud. it just means there an error running the underlying ibc module.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah but do u want to mark it as ACCEPTED?
In normal case, if the app would return err, the relayer would retry

in our case the packet will be marked as accepted and forgotten (which might be fine if by design, but probably need to be marked somehow)

Copy link
Contributor Author

@omritoptix omritoptix Feb 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it should be marked as FINALIZED - as it is finalized.
as I previously wrote I think ACCEPTED is confusing term here.
so as I see it, the packet is finalized, but it could have errors.

as for the relayer - if we're talking about application layer error which are not part of out-of-sync problem (e.g LC headers didn't yet arrive - which is not the case in our example) - by default the relayer will not retry (i.e if you simply run rly tx transfer command). It's true that if you restart it will try to get all non-relayed packets but if the packet itself is maleformed or it's data invalid - retry won't help unless the relayer code/blockchain code or the blockchain state changes.

My point is that as I see it mostly application layer errors, specifically for ics-20 which are mostly around malformed data or lack of balances wouldn't change with relayer retry (which eventually get exhausted and the packet transfer would fail and timeout) so I think it's better to say: "Hi, this packet is finalized, but we couldn't apply it as it was malformed/not enough balance".

re forgotten - I think our UI should reflect any errors in the packet by looking at the error field.

@omritoptix omritoptix changed the title fix: Add support for delayack middleware to also delay ack and timeout packets fix: Add support for delayedack middleware to also delay ack and timeout packets Feb 3, 2024
// Run the underlying app's OnAcknowledgementPacket callback
// with cache context to avoid state changes and report the acknowledgement result.
// Only save the packet if the underlying app's callback succeeds.
cacheCtx, _ := ctx.CacheContext()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why u need it? u already run it with cacheTx by the caller

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea but than the caller controls it.
after it succeeds with cache context, it will actually run it without - which will make the ack run before the packet is finalized.
I want to force it to always run with cache context by the caller and run it with non-cached context only from the hook.
Maybe there is a better way to do it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I see what u did here
what about the case err != nil?
we don't want to write the cacheCtx?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you elaborate? not sure what you mean by writing the cacheCtx.

@omritoptix omritoptix marked this pull request as draft February 4, 2024 12:42
@omritoptix omritoptix marked this pull request as ready for review February 4, 2024 12:45
@omritoptix omritoptix marked this pull request as draft February 4, 2024 12:50
@omritoptix
Copy link
Contributor Author

There is an upgrade hander required for FP because of the packet struct change. opened an issue: #529
Should be fine for blumbus though

@omritoptix omritoptix marked this pull request as ready for review February 4, 2024 15:32
@omritoptix omritoptix deleted the omritoptix/393-delay-ack-and-timeout branch February 4, 2024 20:14
omritoptix added a commit that referenced this pull request Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants