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

Relay basic single-bit message dispatch results back to the source chain #935

Merged
merged 10 commits into from
Jun 21, 2021

Conversation

svyatonik
Copy link
Contributor

@svyatonik svyatonik commented Apr 27, 2021

closes #547
on top of #911 => draft

This PR introduces basic mechanism to solve #547 that Tomek has recently suggested. So for every delivered message confirmation would contain single-bit which will mean (in our configuration) whether message (in ur config: call) has been successfully dispatched or not. At the source chain the MessagesDelivered event would contain these dispatch results. So the message sender may check events (also see TODOs below) to check result of their messages.

More sophisticated applications may introduce their own relays to relay extended dispatch results, but for simplest bridge apps single bit should be enough && I agree that it isn't super-heavy to maintain.

TODOs left for doing in this PR:

TODOs left for future PRs:

  • instead of examining events (=> additional overload in on_block_finalize()) we need to introduce trait OnMessagesDelivered { fn on_messages_delivered(messages: &DeliveredMessages) {} }. The method will be called only on blocks with confirmation transactions, so it must be easier to use done;
  • example pallet (built into Rialto or Millau) that will send its messages (from time to time on or demand) and will do perform some actions if dispatch result has been successful.

/// Called when we receive confirmation that our messages have been delivered to the
/// target chain. The confirmation aso has single bit dispatch result for every
/// confirmed message (see `DeliveredMessages` for details).
fn on_messages_delivered(_lane: &LaneId, _messages: &DeliveredMessages) {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This'll need to do something with weights - I'm not yet sure how to deal with this. Change benchmarks to worst-case result and then refund? But what is worst case when there are e.g. multiple apps using different lanes for their purposes. And because of refund policy we'll need to decrease max number of messages in the confirmation tx. Probably just reserve single read and single write for the every registered callback? I'm not yet sure - will leave it for future PRs as well

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think the general sentiment about these kind of handlers is that they should be as simple as possible. Having one read + one write seems reasonable. In future we can prepare some tooling to kind of "subscribe" to interesting messages and for instance have them processed in on_initialize of the pallet or some manual trigger (extrinsic).

Might be good to add this assumption to the docs though, so that implementers are aware of that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@svyatonik svyatonik force-pushed the relay-basic-dispatch-results branch from 86d92dc to 2110b9a Compare June 18, 2021 09:58
@svyatonik svyatonik marked this pull request as ready for review June 18, 2021 10:03
@svyatonik svyatonik marked this pull request as draft June 18, 2021 10:10
@svyatonik svyatonik marked this pull request as ready for review June 18, 2021 10:53
Copy link
Contributor

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

lgtm!

primitives/messages/src/source_chain.rs Outdated Show resolved Hide resolved
/// Called when we receive confirmation that our messages have been delivered to the
/// target chain. The confirmation aso has single bit dispatch result for every
/// confirmed message (see `DeliveredMessages` for details).
fn on_messages_delivered(_lane: &LaneId, _messages: &DeliveredMessages) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think the general sentiment about these kind of handlers is that they should be as simple as possible. Having one read + one write seems reasonable. In future we can prepare some tooling to kind of "subscribe" to interesting messages and for instance have them processed in on_initialize of the pallet or some manual trigger (extrinsic).

Might be good to add this assumption to the docs though, so that implementers are aware of that.

/// the target chain to the message submitter at the source chain. If you're using immediate
/// call dispatcher, then it'll be result of the dispatch - `true` if dispatch has succeeded
/// and `false` otherwise.
pub dispatch_result: bool,
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
pub dispatch_result: bool,
pub dispatched: bool,

I find it a bit confusing to have dispatch_result and bool - it kind of signifies that there is some extra result embedded in case that's true.

I'd call this simply dispatched: true/false cause it's part of MessageDispatchResult struct already. It's just a personal preference, there is nothing wrong really with dispatch_result, so if you don't find my arguments convincing feel free to leave as-is.

primitives/messages/src/source_chain.rs Outdated Show resolved Hide resolved
.saturating_add(RocksDbWeight::get().reads(5 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
}
fn receive_message_proofs_with_large_leaf(i: u32) -> Weight {
(175_300_000 as Weight)
.saturating_add((6_000 as Weight).saturating_mul(i as Weight))
(178_139_000 as Weight)
Copy link
Contributor

Choose a reason for hiding this comment

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

Which machine did you use to generate the weights? They are surprisingly similar to the previous ones :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My laptop. Previous weights were also generated here, so it's expected

@svyatonik svyatonik merged commit 604eb1c into master Jun 21, 2021
@svyatonik svyatonik deleted the relay-basic-dispatch-results branch June 21, 2021 08:41
serban300 pushed a commit to serban300/parity-bridges-common that referenced this pull request Mar 27, 2024
…ain (paritytech#935)

* relay dispatch result flags back to the source chain

* OnMessagesDelivered callback

* add lane id to OnDeliveredMessages callback

* fix benchmarks && upate weights

* clippy

* clippy

* clipy another try

* OnMessagesDelivered -> OnDeliveryConfirmed

* Update primitives/messages/src/source_chain.rs

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
serban300 pushed a commit to serban300/parity-bridges-common that referenced this pull request Apr 8, 2024
…ain (paritytech#935)

* relay dispatch result flags back to the source chain

* OnMessagesDelivered callback

* add lane id to OnDeliveredMessages callback

* fix benchmarks && upate weights

* clippy

* clippy

* clipy another try

* OnMessagesDelivered -> OnDeliveryConfirmed

* Update primitives/messages/src/source_chain.rs

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-Message Delivery P-Message Dispatch PR-audit-needed A PR has to be audited before going live.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Delivery confirmation should contain dispatch result as well.
2 participants