polkadot: eradicate LeafStatus (#1565)

Fixes #768.
This commit is contained in:
ordian
2023-10-23 16:22:37 +02:00
committed by GitHub
parent 9505243780
commit 5ca909cc09
15 changed files with 21 additions and 106 deletions
-3
View File
@@ -17,11 +17,9 @@
use crate::{
prometheus::Registry, HeadSupportsParachains, InitializedOverseerBuilder, MetricsTrait,
Overseer, OverseerMetrics, OverseerSignal, OverseerSubsystemContext, SpawnGlue,
KNOWN_LEAVES_CACHE_SIZE,
};
use orchestra::{FromOrchestra, SpawnedSubsystem, Subsystem, SubsystemContext};
use polkadot_node_subsystem_types::{errors::SubsystemError, messages::*};
use schnellru::{ByLength, LruMap};
// Generated dummy messages
use crate::messages::*;
@@ -193,7 +191,6 @@ where
.activation_external_listeners(Default::default())
.span_per_active_leaf(Default::default())
.active_leaves(Default::default())
.known_leaves(LruMap::new(ByLength::new(KNOWN_LEAVES_CACHE_SIZE)))
.spawner(SpawnGlue(spawner))
.metrics(metrics)
.supports_parachains(supports_parachains);
+10 -21
View File
@@ -70,7 +70,6 @@ use std::{
};
use futures::{channel::oneshot, future::BoxFuture, select, Future, FutureExt, StreamExt};
use schnellru::LruMap;
use client::{BlockImportNotification, BlockchainEvents, FinalityNotification};
use polkadot_primitives::{Block, BlockNumber, Hash};
@@ -88,8 +87,8 @@ use polkadot_node_subsystem_types::messages::{
pub use polkadot_node_subsystem_types::{
errors::{SubsystemError, SubsystemResult},
jaeger, ActivatedLeaf, ActiveLeavesUpdate, LeafStatus, OverseerSignal,
RuntimeApiSubsystemClient, UnpinHandle,
jaeger, ActivatedLeaf, ActiveLeavesUpdate, OverseerSignal, RuntimeApiSubsystemClient,
UnpinHandle,
};
pub mod metrics;
@@ -112,10 +111,6 @@ pub use orchestra::{
SubsystemSender, TimeoutExt, ToOrchestra, TrySendError,
};
/// Store 2 days worth of blocks, not accounting for forks,
/// in the LRU cache. Assumes a 6-second block time.
pub const KNOWN_LEAVES_CACHE_SIZE: u32 = 2 * 24 * 3600 / 6;
#[cfg(any(target_os = "linux", feature = "jemalloc-allocator"))]
mod memory_stats;
#[cfg(test)]
@@ -283,6 +278,11 @@ impl From<FinalityNotification<Block>> for BlockInfo {
/// as the substrate framework or user interaction.
pub enum Event {
/// A new block was imported.
///
/// This event is not sent if the block was already known
/// and we reorged to it e.g. due to a reversion.
///
/// Also, these events are not sent during a major sync.
BlockImported(BlockInfo),
/// A block was finalized with i.e. babe or another consensus algorithm.
BlockFinalized(BlockInfo),
@@ -641,9 +641,6 @@ pub struct Overseer<SupportsParachains> {
/// An implementation for checking whether a header supports parachain consensus.
pub supports_parachains: SupportsParachains,
/// An LRU cache for keeping track of relay-chain heads that have already been seen.
pub known_leaves: LruMap<Hash, ()>,
/// Various Prometheus metrics.
pub metrics: OverseerMetrics,
}
@@ -802,10 +799,9 @@ where
};
let mut update = match self.on_head_activated(&block.hash, Some(block.parent_hash)).await {
Some((span, status)) => ActiveLeavesUpdate::start_work(ActivatedLeaf {
Some(span) => ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: block.hash,
number: block.number,
status,
unpin_handle: block.unpin_handle,
span,
}),
@@ -864,7 +860,7 @@ where
&mut self,
hash: &Hash,
parent_hash: Option<Hash>,
) -> Option<(Arc<jaeger::Span>, LeafStatus)> {
) -> Option<Arc<jaeger::Span>> {
if !self.supports_parachains.head_supports_parachains(hash).await {
return None
}
@@ -891,14 +887,7 @@ where
let span = Arc::new(span);
self.span_per_active_leaf.insert(*hash, span.clone());
let status = if self.known_leaves.get(hash).is_some() {
LeafStatus::Stale
} else {
self.known_leaves.insert(*hash, ());
LeafStatus::Fresh
};
Some((span, status))
Some(span)
}
fn on_head_deactivated(&mut self, hash: &Hash) {