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

Add error handling logic to relayer spec #236

Merged
merged 9 commits into from
Sep 29, 2020

Conversation

milosevic
Copy link
Contributor

@milosevic milosevic commented Sep 17, 2020

Fixes #234 and #237.

@codecov-commenter
Copy link

Codecov Report

Merging #236 into master will increase coverage by 23.9%.
The diff coverage is 54.5%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #236      +/-   ##
=========================================
+ Coverage    13.6%   37.6%   +23.9%     
=========================================
  Files          69      79      +10     
  Lines        3752    5652    +1900     
  Branches     1374    1870     +496     
=========================================
+ Hits          513    2127    +1614     
- Misses       2618    3318     +700     
+ Partials      621     207     -414     
Impacted Files Coverage Δ
modules/src/events.rs 0.0% <ø> (ø)
modules/src/ics02_client/events.rs 0.0% <ø> (ø)
modules/src/ics02_client/raw.rs 0.0% <0.0%> (ø)
modules/src/ics03_connection/error.rs 9.6% <0.0%> (-23.7%) ⬇️
modules/src/ics04_channel/error.rs 23.0% <0.0%> (-2.0%) ⬇️
modules/src/ics04_channel/packet.rs 0.0% <0.0%> (ø)
modules/src/ics07_tendermint/client_def.rs 0.0% <0.0%> (ø)
modules/src/ics07_tendermint/error.rs 30.0% <0.0%> (+30.0%) ⬆️
modules/src/ics07_tendermint/msgs/update_client.rs 0.0% <0.0%> (ø)
modules/src/mock_client/header.rs 0.0% <0.0%> (ø)
... and 134 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4877ee9...441e3bb. Read the comment docs.

docs/spec/relayer/Definitions.md Outdated Show resolved Hide resolved
docs/spec/relayer/Definitions.md Outdated Show resolved Hide resolved

if channel == nil OR channel.state != OPEN { (nil, Error.RETRY) }
// TODO: Maybe we shouldn't even enter handle loop for packets if the corresponding channel is not open!
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes but I think here is the first time when we can make that determination.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What I meant here is basically having supervisor logic that would decide when to call handleEvent based on event type, i.e., there would be some preconditions that are based on relayer state. For example, packet related events are preconditioned on channel and connections being open, all events are preconditioned on light client correctly installed, etc.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this assume that the relayer keeps state for channel and connections? And the supervisor does not perform any queries to determine that. Trying to save on the number of queries :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly. Supervisor will need anyway to keep some state (for example for pending packets so it can trigger timeouts), so why not keeping status of connections and channels, current block height and time, etc. It can save queries and potentially operates faster.

docs/spec/relayer/Relayer.md Outdated Show resolved Hide resolved
docs/spec/relayer/Relayer.md Outdated Show resolved Hide resolved
docs/spec/relayer/Relayer.md Outdated Show resolved Hide resolved
docs/spec/relayer/Relayer.md Outdated Show resolved Hide resolved
docs/spec/relayer/Definitions.md Outdated Show resolved Hide resolved
docs/spec/relayer/Relayer.md Outdated Show resolved Hide resolved
docs/spec/relayer/Packets.md Outdated Show resolved Hide resolved
1. Determine destination chain (`chainB`)
2. Updates (on `chainB`) the IBC client for `chainA` to a certain height `H` where `H >= h+1`.
3. Create IBC datagram at height `H-1`.
4. Submit the datagram from stage (2) to `chainB`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
4. Submit the datagram from stage (2) to `chainB`.
4. Submit the datagram from stage (3) to `chainB`.

docs/spec/relayer/Definitions.md Outdated Show resolved Hide resolved
docs/spec/relayer/Relayer.md Show resolved Hide resolved
Copy link
Collaborator

@ancazamfir ancazamfir left a comment

Choose a reason for hiding this comment

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

Looks great! A few comments looking for modularizing a bit the checks so the pseudocode is easier to read, if possible.


if channel == nil OR channel.state != OPEN { (nil, Error.RETRY) }
// TODO: Maybe we shouldn't even enter handle loop for packets if the corresponding channel is not open!
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this assume that the relayer keeps state for channel and connections? And the supervisor does not perform any queries to determine that. Trying to save on the number of queries :)

Comment on lines +142 to +152
// Fetch channelEnd from the chainA to be able to compute port and chain ids on destination chain
channelA, proof, error = GetChannel(chainA, ev.port, ev.channel, ev.height)
if error != nil { return (nil, error) }

channelB, proof, error =
GetChannel(chainB, channelA.counterpartyPortIdentifier, channelA.counterpartyChannelIdentifier, LATEST_HEIGHT)
if error != nil { return (nil, error) }

if channelB == nil OR channel.state != OPEN { (nil, Error.DROP) }
// Note that we checked implicitly above that counterparty identifiers match each other

Copy link
Collaborator

Choose a reason for hiding this comment

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

Are these channel retrievals and checks the same as for the SendPacket event above? If yes can we make a single function for this? If not maybe we cover the differences and why they are.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checks are similar, but error message is different. With recv packets we can retry on error (if connection and channel are not open) while for acks we should drop event in this case. We can make a function for this (and we should at the code level) but at the spec level maybe it's better making it more verbose so reading it is easier.

Comment on lines +153 to +157
connectionId = channelB.connectionHops[0]
connection, proof, error = GetConnection(chainB, connectionId, LATEST_HEIGHT)
if error != nil { return (nil, error) }

if connection == nil OR connection.state != OPEN { return (nil, Error.DROP) }
Copy link
Collaborator

Choose a reason for hiding this comment

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

same question here.

Comment on lines +160 to +170
packetCommitment, packetCommitmentProof, error =
GetPacketCommitment(chainB, channelA.counterpartyPortIdentifier,
channelA.counterpartyChannelIdentifier, ev.sequence, LATEST_HEIGHT)
if error != nil { return (nil, error) }

if packetCommitment == nil OR
packetCommitment != hash(concat(ev.data, ev.timeoutHeight, ev.timeoutTimestamp)) {
// invalid event; bad provider
return (nil, Error.BADPROVIDER)
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

same here

Copy link
Collaborator

@ancazamfir ancazamfir left a comment

Choose a reason for hiding this comment

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

Looks good, thanks Zarko!

@milosevic milosevic merged commit 0fa2b89 into master Sep 29, 2020
@romac romac deleted the zarko/add-error-handling-234 branch April 8, 2021 20:41
hu55a1n1 pushed a commit to hu55a1n1/hermes that referenced this pull request Sep 13, 2022
Add error handling and reorganise the spec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extend IBC packet event handling spec with error handling
4 participants