-
Notifications
You must be signed in to change notification settings - Fork 740
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
Unexpected behaviour of block import_notification_stream
#5596
Comments
Maybe you want to make the comment more clear to you. However,
means to me that the notification is either send when you are at the tip of the chain (for every block) or there is a re-org (which is only relevant when you are not at the tip of the chain).
The first one not being true and the second one being true because we notify for every imported block. |
Thank you for the clarification @bkchr ! Of course this is based on my interpretation of the comment, so yes, the comment wasn't clear at least to me. I'm curious to understand the reasoning behind this. Why would a re-org only be relevant when you're not synced to the tip? My thinking was that, if you don't care about being notified of blocks before syncing to the tip, why would you be only interested in blocks during that sync that cause a re-org? |
A colleague helped me find the reasoning in this PR. |
If you like you can open a pr to make the comment more clear to you and others. |
@bkchr I just did that. No rush at all in reviewing it or anything, but hope this helps. Thanks again for your clarification. |
# Description Updates the doc comment on the `import_notification_stream` to make its behaviour clearer. Closes [Unexpected behaviour of block `import_notification_stream`](#5596). ## Integration Doesn't apply. ## Review Notes The old comment docs caused some confusion to myself and some members of my team, on when this notification stream is triggered. This is reflected in the linked [issue](#5596), and as discussed there, this PR aims to prevent this confusion in future devs looking to make use of this functionality. # Checklist * [x] My PR includes a detailed description as outlined in the "Description" and its two subsections above. * [ ] My PR follows the [labeling requirements]( https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CONTRIBUTING.md#Process ) of this project (at minimum one label for `T` required) * External contributors: ask maintainers to put the right label on your PR. * [x] I have made corresponding changes to the documentation (if applicable) * [x] I have added tests that prove my fix is effective or that my feature works (if applicable) You can remove the "Checklist" section once all have been checked. Thank you for your contribution! --------- Co-authored-by: Michal Kucharczyk <[email protected]> Co-authored-by: Bastian Köcher <[email protected]>
# Description Updates the doc comment on the `import_notification_stream` to make its behaviour clearer. Closes [Unexpected behaviour of block `import_notification_stream`](#5596). ## Integration Doesn't apply. ## Review Notes The old comment docs caused some confusion to myself and some members of my team, on when this notification stream is triggered. This is reflected in the linked [issue](#5596), and as discussed there, this PR aims to prevent this confusion in future devs looking to make use of this functionality. # Checklist * [x] My PR includes a detailed description as outlined in the "Description" and its two subsections above. * [ ] My PR follows the [labeling requirements]( https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CONTRIBUTING.md#Process ) of this project (at minimum one label for `T` required) * External contributors: ask maintainers to put the right label on your PR. * [x] I have made corresponding changes to the documentation (if applicable) * [x] I have added tests that prove my fix is effective or that my feature works (if applicable) You can remove the "Checklist" section once all have been checked. Thank you for your contribution! --------- Co-authored-by: Michal Kucharczyk <[email protected]> Co-authored-by: Bastian Köcher <[email protected]>
Is there an existing issue?
Experiencing problems? Have you tried our Stack Exchange first?
Description of bug
From my understanding, there seems to be a misalignment between the commented (expected) behaviour of the
import_notification_stream
fromBlockchainEvents
(code here), and the actual code. I'm going to explain my understanding of what the code should do according to the comment, and what it actually does. Please correct me if I'm wrong.The Code
This code snippet is where the notifications are sent through the streams:
So depending on the value of
import_notification_action
, both notification streams (import_notification_stream
andevery_import_notification_stream
) are used, or just one of them.The value of
import_notification_action
is defined here:should_notify_recent_block
is responsible for determining ifimport_notification_stream
should be triggered, and its value is determined in this line:The second operand of the logical OR (
tree_route
) is what one would expect:In other words, if there is a new best block which belongs to a fork branch that is not the current one, this is a re-org, so
tree_route
will beSome
.The first operand though (
make_notifications
), is defined here:This means that
make_notifications
will only befalse
iff theorigin
of the block is one ofBlockOrigin::Genesis | BlockOrigin::NetworkInitialSync | BlockOrigin::File
. Which means that, for example,make_notifications
will still betrue
if a block is imported from the network, and that block belongs to a fork branch that is not the current best branch, and is not the new best (doesn't cause a re-org). Given thatshould_notify_recent_block
is determined by an OR, regardless oftree_route
,should_notify_recent_block
will still be true for this non-reorging block.Behaviour from the Code
My interpretation from this analysis is that:
make_notifications
will be false, soshould_notify_recent_block
will betrue
if somehow there is a re-org during the syncing process.make_notifications
will essentially always betrue
, soshould_notify_recent_block
will always be true regardless of whether the block is the new best of the current branch, a non-new best from another fork branch, or a new best from another branch that causes a re-org.This means that the
tree_route
condition is relevant only to notify about re-orgs during a syncing process.Commented Behaviour of
import_notification_stream
This is the comment on
import_notification_stream
in the code:Based on this comment, my intuition for the behaviour of
import_notification_stream
is:Conclusion
Either the behaviour interpreted from the code is the expected one, and the comment is not clear about it, or the comment reflects the intended behaviour, but the code doesn't.
Personally, I feel it is counterintuitive if the expected behaviour is to notify every block after the initial sync (re-org or not), but during the initial sync, notify only of re-orgs. So I'm inclined to believe that the comment reflects the intended behaviour, and the code is wrong. But of course, there are use cases that I might not be considering.
Whatever the case, I'm open to open a PR and help make this behaviour clearer. Either by updating the comment on
import_notification_stream
, or fixing the code.Thank you for your time!
Steps to reproduce
Not needed
The text was updated successfully, but these errors were encountered: