mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 15:11:03 +00:00
Add stale branches heads to finality notifications (#10639)
* Add stale branches heads to finality notifications Warning. Previous implementation was sending a notification for each block between the previous (explicitly) finalized block and the new finalized one (with an hardcoded limit of 256). Now finality notification is sent only for the new finalized head and it contains the hash of the new finalized head, new finalized head header, a list of all the implicitly finalized blocks and a list of stale branches heads (i.e. the branches heads that are not part of the canonical chain anymore). * Add implicitly finalized blocks list to `ChainEvent::Finalized` message The list contains all the blocks between the previously finalized block up to the parent of the currently finalized one, sorted by block number. `Finalized` messages handler, part of the `MaintainedTransactionPool` implementation for `BasicPool`, still propagate full set of finalized blocks to the txpool by iterating over implicitly finalized blocks list. * Rust fmt * Greedy evaluation of `stale_heads` during finalization * Fix outdated assumption in a comment * Removed a test optimization that is no more relevant The loop was there to prevent sending to `peer.network.on_block_finalized` the full list of finalized blocks. Now only the finalized heads are received. * Last finalized block lookup not required anymore * Tests for block finality notifications payloads * Document a bit tricky condition to avoid duplicate finalization notifications * More idiomatic way to skip an iterator entry Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Cargo fmt iteration * Typo fix Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Fix potential failure when a finalized orphan block is imported * Apply suggestions from code review Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -34,10 +34,10 @@ mod client;
|
||||
mod metrics;
|
||||
mod task_manager;
|
||||
|
||||
use std::{collections::HashMap, io, net::SocketAddr, pin::Pin, task::Poll};
|
||||
use std::{collections::HashMap, io, net::SocketAddr, pin::Pin};
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use futures::{stream, Future, FutureExt, Stream, StreamExt};
|
||||
use futures::{Future, FutureExt, StreamExt};
|
||||
use log::{debug, error, warn};
|
||||
use sc_network::PeerId;
|
||||
use sc_utils::mpsc::TracingUnboundedReceiver;
|
||||
@@ -152,26 +152,7 @@ async fn build_network_future<
|
||||
let starting_block = client.info().best_number;
|
||||
|
||||
// Stream of finalized blocks reported by the client.
|
||||
let mut finality_notification_stream = {
|
||||
let mut finality_notification_stream = client.finality_notification_stream().fuse();
|
||||
|
||||
// We tweak the `Stream` in order to merge together multiple items if they happen to be
|
||||
// ready. This way, we only get the latest finalized block.
|
||||
stream::poll_fn(move |cx| {
|
||||
let mut last = None;
|
||||
while let Poll::Ready(Some(item)) =
|
||||
Pin::new(&mut finality_notification_stream).poll_next(cx)
|
||||
{
|
||||
last = Some(item);
|
||||
}
|
||||
if let Some(last) = last {
|
||||
Poll::Ready(Some(last))
|
||||
} else {
|
||||
Poll::Pending
|
||||
}
|
||||
})
|
||||
.fuse()
|
||||
};
|
||||
let mut finality_notification_stream = client.finality_notification_stream().fuse();
|
||||
|
||||
loop {
|
||||
futures::select! {
|
||||
|
||||
Reference in New Issue
Block a user