-
Notifications
You must be signed in to change notification settings - Fork 240
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
backend(fix): Remove only finalized blocks from the event window #1356
Conversation
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
shared | ||
.block_events_for_new_subscriptions | ||
.retain(|ev| match ev { | ||
FollowEvent::NewBlock(new_block_ev) => { |
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.
Can you add a comment here why on NewBlock
and BestBlockChanged
are removed here if it's pruned or finalized?
The last finalized block will be reported as Initialized by our driver, therefore there is no need to report NewBlock and BestBlock events for it. If the Finalized event reported multiple finalized hashes, we only care about the state at the head of the chain, therefore it is correct to remove those as well. Idem for the pruned hashes; they will never be reported again and we remove them from the window of events.
@@ -251,7 +250,7 @@ impl<Hash: BlockHash> Shared<Hash> { | |||
// New subscriptions will be given this init message: | |||
shared.current_init_message = Some(ev.clone()); | |||
// Clear block cache (since a new finalized block hash is seen): | |||
shared.block_events_from_last_finalized.clear(); | |||
shared.block_events_for_new_subscriptions.clear(); |
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.
yeah, alright when Initialized
event is generated we can conclude that no messages regarding the next block are missed.
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.
I could only review on my phone but this looks like a good approach to me; good job!
Signed-off-by: Alexandru Vasile <[email protected]>
Thanks for the review guys! I'll keep my eyes on the CI for a couple of days to make sure no other errors appear 🙏 |
This PR ensures that the window of events we feed to every new subscription contains the appropriate
NewBlock
andBestBlock
events.Before this PR, the
block_events_from_last_finalized
window of events was cleared out on everyFinalized
event.However, this approach could miss reporting
NewBlocks
that will later becomeFinalized
. Therefore, the unstable driver could report a block asFinalized
and never report it asNewBlock
first.Considering the following edge case:
Initialized
eventblock_events_from_last_finalized
contains: 0x2 0x3 0x4 asNewBlocks
Finalized
block_events_from_last_finalized
is cleared our entirelyIf a new subscription is started after T1; it will receive an
Initialized
event with the 0x2 block. However, it will never receive0x3
and0x4
asNewBlocks
. After around 6 seconds, the0x3
is reported in aFinalized
event. This breaks the expectations of the rpc-v2 spec.To mitigate this behavior, the window of events is not entirely cleaned out. Instead, only blocks reported as
Finalized
or pruned are removed from the window.The last finalized block will be reported as
Initialized
by our driver, therefore there is no need to reportNewBlock
andBestBlock
events for it. If theFinalized
event reported multiple finalized hashes, we only care about the state at the head of the chain, therefore it is correct to remove those as well. Idem for the pruned hashes; they will never be reported again and we remove them from the window of events.Testing Done
decode_signed_extensions_from_blocks
with thepanic
patch is passing after this PR