mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 15:11:02 +00:00
av-store: skip processing finalized blocks while syncing (#6691)
This commit is contained in:
Generated
+1
@@ -6826,6 +6826,7 @@ dependencies = [
|
|||||||
"polkadot-overseer",
|
"polkadot-overseer",
|
||||||
"polkadot-primitives",
|
"polkadot-primitives",
|
||||||
"polkadot-primitives-test-helpers",
|
"polkadot-primitives-test-helpers",
|
||||||
|
"sp-consensus",
|
||||||
"sp-core",
|
"sp-core",
|
||||||
"sp-keyring",
|
"sp-keyring",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ polkadot-node-subsystem-util = { path = "../../subsystem-util" }
|
|||||||
polkadot-overseer = { path = "../../overseer" }
|
polkadot-overseer = { path = "../../overseer" }
|
||||||
polkadot-primitives = { path = "../../../primitives" }
|
polkadot-primitives = { path = "../../../primitives" }
|
||||||
polkadot-node-primitives = { path = "../../primitives" }
|
polkadot-node-primitives = { path = "../../primitives" }
|
||||||
|
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ use futures::{channel::oneshot, future, select, FutureExt};
|
|||||||
use futures_timer::Delay;
|
use futures_timer::Delay;
|
||||||
use parity_scale_codec::{Decode, Encode, Error as CodecError, Input};
|
use parity_scale_codec::{Decode, Encode, Error as CodecError, Input};
|
||||||
use polkadot_node_subsystem_util::database::{DBTransaction, Database};
|
use polkadot_node_subsystem_util::database::{DBTransaction, Database};
|
||||||
|
use sp_consensus::SyncOracle;
|
||||||
|
|
||||||
use bitvec::{order::Lsb0 as BitOrderLsb0, vec::BitVec};
|
use bitvec::{order::Lsb0 as BitOrderLsb0, vec::BitVec};
|
||||||
use polkadot_node_primitives::{AvailableData, ErasureChunk};
|
use polkadot_node_primitives::{AvailableData, ErasureChunk};
|
||||||
@@ -451,16 +452,23 @@ pub struct AvailabilityStoreSubsystem {
|
|||||||
finalized_number: Option<BlockNumber>,
|
finalized_number: Option<BlockNumber>,
|
||||||
metrics: Metrics,
|
metrics: Metrics,
|
||||||
clock: Box<dyn Clock>,
|
clock: Box<dyn Clock>,
|
||||||
|
sync_oracle: Box<dyn SyncOracle + Send + Sync>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AvailabilityStoreSubsystem {
|
impl AvailabilityStoreSubsystem {
|
||||||
/// Create a new `AvailabilityStoreSubsystem` with a given config on disk.
|
/// Create a new `AvailabilityStoreSubsystem` with a given config on disk.
|
||||||
pub fn new(db: Arc<dyn Database>, config: Config, metrics: Metrics) -> Self {
|
pub fn new(
|
||||||
|
db: Arc<dyn Database>,
|
||||||
|
config: Config,
|
||||||
|
sync_oracle: Box<dyn SyncOracle + Send + Sync>,
|
||||||
|
metrics: Metrics,
|
||||||
|
) -> Self {
|
||||||
Self::with_pruning_config_and_clock(
|
Self::with_pruning_config_and_clock(
|
||||||
db,
|
db,
|
||||||
config,
|
config,
|
||||||
PruningConfig::default(),
|
PruningConfig::default(),
|
||||||
Box::new(SystemClock),
|
Box::new(SystemClock),
|
||||||
|
sync_oracle,
|
||||||
metrics,
|
metrics,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -471,6 +479,7 @@ impl AvailabilityStoreSubsystem {
|
|||||||
config: Config,
|
config: Config,
|
||||||
pruning_config: PruningConfig,
|
pruning_config: PruningConfig,
|
||||||
clock: Box<dyn Clock>,
|
clock: Box<dyn Clock>,
|
||||||
|
sync_oracle: Box<dyn SyncOracle + Send + Sync>,
|
||||||
metrics: Metrics,
|
metrics: Metrics,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@@ -480,6 +489,7 @@ impl AvailabilityStoreSubsystem {
|
|||||||
metrics,
|
metrics,
|
||||||
clock,
|
clock,
|
||||||
known_blocks: KnownUnfinalizedBlocks::default(),
|
known_blocks: KnownUnfinalizedBlocks::default(),
|
||||||
|
sync_oracle,
|
||||||
finalized_number: None,
|
finalized_number: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -576,7 +586,12 @@ async fn run_iteration<Context>(
|
|||||||
// candidates backed in this finalized block.
|
// candidates backed in this finalized block.
|
||||||
// Otherwise, we won't be able to store our chunk
|
// Otherwise, we won't be able to store our chunk
|
||||||
// for these candidates.
|
// 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.finalized_number = Some(number);
|
||||||
subsystem.known_blocks.prune_finalized(number);
|
subsystem.known_blocks.prune_finalized(number);
|
||||||
|
|||||||
@@ -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<T: Future<Output = VirtualOverseer>>(
|
fn test_harness<T: Future<Output = VirtualOverseer>>(
|
||||||
state: TestState,
|
state: TestState,
|
||||||
store: Arc<dyn Database>,
|
store: Arc<dyn Database>,
|
||||||
@@ -122,6 +134,7 @@ fn test_harness<T: Future<Output = VirtualOverseer>>(
|
|||||||
TEST_CONFIG,
|
TEST_CONFIG,
|
||||||
state.pruning_config.clone(),
|
state.pruning_config.clone(),
|
||||||
Box::new(state.clock),
|
Box::new(state.clock),
|
||||||
|
Box::new(NoSyncOracle),
|
||||||
Metrics::default(),
|
Metrics::default(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -231,6 +231,7 @@ where
|
|||||||
.availability_store(AvailabilityStoreSubsystem::new(
|
.availability_store(AvailabilityStoreSubsystem::new(
|
||||||
parachains_db.clone(),
|
parachains_db.clone(),
|
||||||
availability_config,
|
availability_config,
|
||||||
|
Box::new(network_service.clone()),
|
||||||
Metrics::register(registry)?,
|
Metrics::register(registry)?,
|
||||||
))
|
))
|
||||||
.bitfield_distribution(BitfieldDistributionSubsystem::new(Metrics::register(registry)?))
|
.bitfield_distribution(BitfieldDistributionSubsystem::new(Metrics::register(registry)?))
|
||||||
|
|||||||
Reference in New Issue
Block a user