diff --git a/Cargo.lock b/Cargo.lock index f340ec6d0a60..55ddaa6b1a29 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6823,6 +6823,7 @@ dependencies = [ "polkadot-overseer", "polkadot-primitives", "polkadot-primitives-test-helpers", + "sp-consensus", "sp-core", "sp-keyring", "thiserror", diff --git a/node/core/av-store/Cargo.toml b/node/core/av-store/Cargo.toml index ee6bfd7359b8..2f1637cd6ec3 100644 --- a/node/core/av-store/Cargo.toml +++ b/node/core/av-store/Cargo.toml @@ -19,6 +19,7 @@ polkadot-node-subsystem-util = { path = "../../subsystem-util" } polkadot-overseer = { path = "../../overseer" } polkadot-primitives = { path = "../../../primitives" } polkadot-node-primitives = { path = "../../primitives" } +sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } [dev-dependencies] log = "0.4.17" diff --git a/node/core/av-store/src/lib.rs b/node/core/av-store/src/lib.rs index 4509c5712188..d43dc0657d18 100644 --- a/node/core/av-store/src/lib.rs +++ b/node/core/av-store/src/lib.rs @@ -30,6 +30,7 @@ use futures::{channel::oneshot, future, select, FutureExt}; use futures_timer::Delay; use parity_scale_codec::{Decode, Encode, Error as CodecError, Input}; use polkadot_node_subsystem_util::database::{DBTransaction, Database}; +use sp_consensus::SyncOracle; use bitvec::{order::Lsb0 as BitOrderLsb0, vec::BitVec}; use polkadot_node_primitives::{AvailableData, ErasureChunk}; @@ -451,16 +452,23 @@ pub struct AvailabilityStoreSubsystem { finalized_number: Option, metrics: Metrics, clock: Box, + sync_oracle: Box, } impl AvailabilityStoreSubsystem { /// Create a new `AvailabilityStoreSubsystem` with a given config on disk. - pub fn new(db: Arc, config: Config, metrics: Metrics) -> Self { + pub fn new( + db: Arc, + config: Config, + sync_oracle: Box, + metrics: Metrics, + ) -> Self { Self::with_pruning_config_and_clock( db, config, PruningConfig::default(), Box::new(SystemClock), + sync_oracle, metrics, ) } @@ -471,6 +479,7 @@ impl AvailabilityStoreSubsystem { config: Config, pruning_config: PruningConfig, clock: Box, + sync_oracle: Box, metrics: Metrics, ) -> Self { Self { @@ -480,6 +489,7 @@ impl AvailabilityStoreSubsystem { metrics, clock, known_blocks: KnownUnfinalizedBlocks::default(), + sync_oracle, finalized_number: None, } } @@ -576,7 +586,12 @@ async fn run_iteration( // candidates backed in this finalized block. // Otherwise, we won't be able to store our chunk // for these candidates. - process_block_activated(ctx, subsystem, hash).await?; + if !subsystem.sync_oracle.is_major_syncing() { + // If we're major syncing, processing finalized + // blocks might take quite a very long time + // and make the subsystem unresponsive. + process_block_activated(ctx, subsystem, hash).await?; + } } subsystem.finalized_number = Some(number); subsystem.known_blocks.prune_finalized(number); diff --git a/node/core/av-store/src/tests.rs b/node/core/av-store/src/tests.rs index 9efd410ebac2..e26a3507480b 100644 --- a/node/core/av-store/src/tests.rs +++ b/node/core/av-store/src/tests.rs @@ -103,6 +103,18 @@ impl Default for TestState { } } +struct NoSyncOracle; + +impl sp_consensus::SyncOracle for NoSyncOracle { + fn is_major_syncing(&self) -> bool { + false + } + + fn is_offline(&self) -> bool { + unimplemented!("not used") + } +} + fn test_harness>( state: TestState, store: Arc, @@ -122,6 +134,7 @@ fn test_harness>( TEST_CONFIG, state.pruning_config.clone(), Box::new(state.clock), + Box::new(NoSyncOracle), Metrics::default(), ); diff --git a/node/service/src/overseer.rs b/node/service/src/overseer.rs index 7dff86693827..5b1c728724ab 100644 --- a/node/service/src/overseer.rs +++ b/node/service/src/overseer.rs @@ -231,6 +231,7 @@ where .availability_store(AvailabilityStoreSubsystem::new( parachains_db.clone(), availability_config, + Box::new(network_service.clone()), Metrics::register(registry)?, )) .bitfield_distribution(BitfieldDistributionSubsystem::new(Metrics::register(registry)?))