Skip to content

Commit 5ca909c

Browse files
author
ordian
authored
polkadot: eradicate LeafStatus (#1565)
Fixes #768.
1 parent 9505243 commit 5ca909c

File tree

15 files changed

+21
-106
lines changed

15 files changed

+21
-106
lines changed

Cargo.lock

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cumulus/client/relay-chain-minimal-node/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ cumulus-relay-chain-rpc-interface = { path = "../relay-chain-rpc-interface" }
3737
cumulus-primitives-core = { path = "../../primitives/core" }
3838

3939
array-bytes = "6.1"
40-
schnellru = "0.2.1"
4140
tracing = "0.1.37"
4241
async-trait = "0.1.73"
4342
futures = "0.3.28"

cumulus/client/relay-chain-minimal-node/src/collator_overseer.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

1717
use futures::{select, StreamExt};
18-
use schnellru::{ByLength, LruMap};
1918
use std::sync::Arc;
2019

2120
use polkadot_availability_recovery::AvailabilityRecoverySubsystem;
@@ -36,7 +35,7 @@ use polkadot_node_network_protocol::{
3635
use polkadot_node_subsystem_util::metrics::{prometheus::Registry, Metrics};
3736
use polkadot_overseer::{
3837
BlockInfo, DummySubsystem, Handle, Overseer, OverseerConnector, OverseerHandle, SpawnGlue,
39-
UnpinHandle, KNOWN_LEAVES_CACHE_SIZE,
38+
UnpinHandle,
4039
};
4140
use polkadot_primitives::CollatorPair;
4241

@@ -156,7 +155,6 @@ fn build_overseer(
156155
.span_per_active_leaf(Default::default())
157156
.active_leaves(Default::default())
158157
.supports_parachains(runtime_client)
159-
.known_leaves(LruMap::new(ByLength::new(KNOWN_LEAVES_CACHE_SIZE)))
160158
.metrics(Metrics::register(registry)?)
161159
.spawner(spawner);
162160

polkadot/node/core/bitfield-signing/src/lib.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ use polkadot_node_subsystem::{
3232
messages::{
3333
AvailabilityStoreMessage, BitfieldDistributionMessage, RuntimeApiMessage, RuntimeApiRequest,
3434
},
35-
overseer, ActivatedLeaf, FromOrchestra, LeafStatus, OverseerSignal, PerLeafSpan,
36-
SpawnedSubsystem, SubsystemError, SubsystemResult, SubsystemSender,
35+
overseer, ActivatedLeaf, FromOrchestra, OverseerSignal, PerLeafSpan, SpawnedSubsystem,
36+
SubsystemError, SubsystemResult, SubsystemSender,
3737
};
3838
use polkadot_node_subsystem_util::{self as util, Validator};
3939
use polkadot_primitives::{AvailabilityBitfield, CoreState, Hash, ValidatorIndex};
@@ -257,16 +257,6 @@ async fn handle_active_leaves_update<Sender>(
257257
where
258258
Sender: overseer::BitfieldSigningSenderTrait,
259259
{
260-
if let LeafStatus::Stale = leaf.status {
261-
gum::debug!(
262-
target: LOG_TARGET,
263-
relay_parent = ?leaf.hash,
264-
block_number = ?leaf.number,
265-
"Skip bitfield signing for stale leaf"
266-
);
267-
return Ok(())
268-
}
269-
270260
let span = PerLeafSpan::new(leaf.span, "bitfield-signing");
271261
let span_delay = span.child("delay");
272262
let wait_until = Instant::now() + SPAWNED_TASK_DELAY;

polkadot/node/core/provisioner/src/lib.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ use polkadot_node_subsystem::{
3131
CandidateBackingMessage, ChainApiMessage, ProspectiveParachainsMessage, ProvisionableData,
3232
ProvisionerInherentData, ProvisionerMessage, RuntimeApiMessage, RuntimeApiRequest,
3333
},
34-
overseer, ActivatedLeaf, ActiveLeavesUpdate, FromOrchestra, LeafStatus, OverseerSignal,
35-
PerLeafSpan, RuntimeApiError, SpawnedSubsystem, SubsystemError,
34+
overseer, ActivatedLeaf, ActiveLeavesUpdate, FromOrchestra, OverseerSignal, PerLeafSpan,
35+
RuntimeApiError, SpawnedSubsystem, SubsystemError,
3636
};
3737
use polkadot_node_subsystem_util::{
3838
request_availability_cores, request_persisted_validation_data,
@@ -421,13 +421,7 @@ async fn send_inherent_data(
421421
"Selected disputes"
422422
);
423423

424-
// Only include bitfields on fresh leaves. On chain reversions, we want to make sure that
425-
// there will be at least one block, which cannot get disputed, so the chain can make progress.
426-
let bitfields = match leaf.status {
427-
LeafStatus::Fresh =>
428-
select_availability_bitfields(&availability_cores, bitfields, &leaf.hash),
429-
LeafStatus::Stale => Vec::new(),
430-
};
424+
let bitfields = select_availability_bitfields(&availability_cores, bitfields, &leaf.hash);
431425

432426
gum::trace!(
433427
target: LOG_TARGET,

polkadot/node/network/availability-distribution/src/requester/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use futures::{
3535
use polkadot_node_subsystem::{
3636
jaeger,
3737
messages::{ChainApiMessage, RuntimeApiMessage},
38-
overseer, ActivatedLeaf, ActiveLeavesUpdate, LeafStatus,
38+
overseer, ActivatedLeaf, ActiveLeavesUpdate,
3939
};
4040
use polkadot_node_subsystem_util::runtime::{get_occupied_cores, RuntimeInfo};
4141
use polkadot_primitives::{CandidateHash, Hash, OccupiedCore, SessionIndex};
@@ -105,8 +105,7 @@ impl Requester {
105105
) -> Result<()> {
106106
gum::trace!(target: LOG_TARGET, ?update, "Update fetching heads");
107107
let ActiveLeavesUpdate { activated, deactivated } = update;
108-
// Stale leaves happen after a reversion - we don't want to re-run availability there.
109-
if let Some(leaf) = activated.filter(|leaf| leaf.status == LeafStatus::Fresh) {
108+
if let Some(leaf) = activated {
110109
let span = spans
111110
.get(&leaf.hash)
112111
.map(|span| span.child("update-fetching-heads"))

polkadot/node/overseer/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ polkadot-node-metrics = { path = "../metrics" }
1818
polkadot-primitives = { path = "../../primitives" }
1919
orchestra = { version = "0.3.3", default-features = false, features=["futures_channel"] }
2020
gum = { package = "tracing-gum", path = "../gum" }
21-
schnellru = "0.2.1"
2221
sp-core = { path = "../../../substrate/primitives/core" }
2322
async-trait = "0.1.57"
2423
tikv-jemalloc-ctl = { version = "0.5.0", optional = true }

polkadot/node/overseer/src/dummy.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
use crate::{
1818
prometheus::Registry, HeadSupportsParachains, InitializedOverseerBuilder, MetricsTrait,
1919
Overseer, OverseerMetrics, OverseerSignal, OverseerSubsystemContext, SpawnGlue,
20-
KNOWN_LEAVES_CACHE_SIZE,
2120
};
2221
use orchestra::{FromOrchestra, SpawnedSubsystem, Subsystem, SubsystemContext};
2322
use polkadot_node_subsystem_types::{errors::SubsystemError, messages::*};
24-
use schnellru::{ByLength, LruMap};
2523
// Generated dummy messages
2624
use crate::messages::*;
2725

@@ -193,7 +191,6 @@ where
193191
.activation_external_listeners(Default::default())
194192
.span_per_active_leaf(Default::default())
195193
.active_leaves(Default::default())
196-
.known_leaves(LruMap::new(ByLength::new(KNOWN_LEAVES_CACHE_SIZE)))
197194
.spawner(SpawnGlue(spawner))
198195
.metrics(metrics)
199196
.supports_parachains(supports_parachains);

polkadot/node/overseer/src/lib.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ use std::{
7070
};
7171

7272
use futures::{channel::oneshot, future::BoxFuture, select, Future, FutureExt, StreamExt};
73-
use schnellru::LruMap;
7473

7574
use client::{BlockImportNotification, BlockchainEvents, FinalityNotification};
7675
use polkadot_primitives::{Block, BlockNumber, Hash};
@@ -88,8 +87,8 @@ use polkadot_node_subsystem_types::messages::{
8887

8988
pub use polkadot_node_subsystem_types::{
9089
errors::{SubsystemError, SubsystemResult},
91-
jaeger, ActivatedLeaf, ActiveLeavesUpdate, LeafStatus, OverseerSignal,
92-
RuntimeApiSubsystemClient, UnpinHandle,
90+
jaeger, ActivatedLeaf, ActiveLeavesUpdate, OverseerSignal, RuntimeApiSubsystemClient,
91+
UnpinHandle,
9392
};
9493

9594
pub mod metrics;
@@ -112,10 +111,6 @@ pub use orchestra::{
112111
SubsystemSender, TimeoutExt, ToOrchestra, TrySendError,
113112
};
114113

115-
/// Store 2 days worth of blocks, not accounting for forks,
116-
/// in the LRU cache. Assumes a 6-second block time.
117-
pub const KNOWN_LEAVES_CACHE_SIZE: u32 = 2 * 24 * 3600 / 6;
118-
119114
#[cfg(any(target_os = "linux", feature = "jemalloc-allocator"))]
120115
mod memory_stats;
121116
#[cfg(test)]
@@ -283,6 +278,11 @@ impl From<FinalityNotification<Block>> for BlockInfo {
283278
/// as the substrate framework or user interaction.
284279
pub enum Event {
285280
/// A new block was imported.
281+
///
282+
/// This event is not sent if the block was already known
283+
/// and we reorged to it e.g. due to a reversion.
284+
///
285+
/// Also, these events are not sent during a major sync.
286286
BlockImported(BlockInfo),
287287
/// A block was finalized with i.e. babe or another consensus algorithm.
288288
BlockFinalized(BlockInfo),
@@ -641,9 +641,6 @@ pub struct Overseer<SupportsParachains> {
641641
/// An implementation for checking whether a header supports parachain consensus.
642642
pub supports_parachains: SupportsParachains,
643643

644-
/// An LRU cache for keeping track of relay-chain heads that have already been seen.
645-
pub known_leaves: LruMap<Hash, ()>,
646-
647644
/// Various Prometheus metrics.
648645
pub metrics: OverseerMetrics,
649646
}
@@ -802,10 +799,9 @@ where
802799
};
803800

804801
let mut update = match self.on_head_activated(&block.hash, Some(block.parent_hash)).await {
805-
Some((span, status)) => ActiveLeavesUpdate::start_work(ActivatedLeaf {
802+
Some(span) => ActiveLeavesUpdate::start_work(ActivatedLeaf {
806803
hash: block.hash,
807804
number: block.number,
808-
status,
809805
unpin_handle: block.unpin_handle,
810806
span,
811807
}),
@@ -864,7 +860,7 @@ where
864860
&mut self,
865861
hash: &Hash,
866862
parent_hash: Option<Hash>,
867-
) -> Option<(Arc<jaeger::Span>, LeafStatus)> {
863+
) -> Option<Arc<jaeger::Span>> {
868864
if !self.supports_parachains.head_supports_parachains(hash).await {
869865
return None
870866
}
@@ -891,14 +887,7 @@ where
891887
let span = Arc::new(span);
892888
self.span_per_active_leaf.insert(*hash, span.clone());
893889

894-
let status = if self.known_leaves.get(hash).is_some() {
895-
LeafStatus::Stale
896-
} else {
897-
self.known_leaves.insert(*hash, ());
898-
LeafStatus::Fresh
899-
};
900-
901-
Some((span, status))
890+
Some(span)
902891
}
903892

904893
fn on_head_deactivated(&mut self, hash: &Hash) {

polkadot/node/service/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ parity-db = { version = "0.4.8", optional = true }
8686
codec = { package = "parity-scale-codec", version = "3.6.1" }
8787

8888
async-trait = "0.1.57"
89-
schnellru = "0.2.1"
9089
log = "0.4.17"
9190
is_executable = "1.0.1"
9291

0 commit comments

Comments
 (0)