Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion node/collation-generation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl CollationGenerationSubsystem {
}
false
}
Ok(Signal(BlockFinalized(_))) => false,
Ok(Signal(BlockFinalized(..))) => false,
Err(err) => {
tracing::error!(
target: LOG_TARGET,
Expand Down
18 changes: 6 additions & 12 deletions node/core/av-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,8 @@ where
process_block_activated(ctx, &subsystem.inner, activated, &subsystem.metrics).await?;
}
}
FromOverseer::Signal(OverseerSignal::BlockFinalized(hash)) => {
process_block_finalized(subsystem, ctx, &subsystem.inner, hash).await?;
FromOverseer::Signal(OverseerSignal::BlockFinalized(_hash, number)) => {
process_block_finalized(subsystem, &subsystem.inner, number).await?;
}
FromOverseer::Communication { msg } => {
process_message(subsystem, ctx, msg).await?;
Expand All @@ -564,20 +564,14 @@ where
/// The state of data has to be changed from
/// `CandidateState::Included` to `CandidateState::Finalized` and their pruning times have
/// to be updated to `now` + keep_finalized_{block, chunk}_for`.
#[tracing::instrument(level = "trace", skip(subsystem, ctx, db), fields(subsystem = LOG_TARGET))]
async fn process_block_finalized<Context>(
#[tracing::instrument(level = "trace", skip(subsystem, db), fields(subsystem = LOG_TARGET))]
async fn process_block_finalized(
subsystem: &AvailabilityStoreSubsystem,
ctx: &mut Context,
db: &Arc<dyn KeyValueDB>,
hash: Hash,
) -> Result<(), Error>
where
Context: SubsystemContext<Message=AvailabilityStoreMessage>
{
block_number: BlockNumber,
) -> Result<(), Error> {
let _timer = subsystem.metrics.time_process_block_finalized();

let block_number = get_block_number(ctx, hash).await?;

if let Some(mut pov_pruning) = pov_pruning(db) {
// Since the records are sorted by time in which they need to be pruned and not by block
// numbers we have to iterate through the whole collection here.
Expand Down
44 changes: 5 additions & 39 deletions node/core/av-store/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ fn store_block_works() {
let test_state = TestState::default();
test_harness(test_state.pruning_config.clone(), store.clone(), |test_harness| async move {
let TestHarness { mut virtual_overseer } = test_harness;
let candidate_hash = CandidateHash(Hash::from([1; 32]));
let candidate_hash = CandidateHash(Hash::repeat_byte(1));
let validator_index = 5;
let n_validators = 10;

Expand Down Expand Up @@ -328,7 +328,7 @@ fn store_pov_and_query_chunk_works() {

test_harness(test_state.pruning_config.clone(), store.clone(), |test_harness| async move {
let TestHarness { mut virtual_overseer } = test_harness;
let candidate_hash = CandidateHash(Hash::from([1; 32]));
let candidate_hash = CandidateHash(Hash::repeat_byte(1));
let n_validators = 10;

let pov = PoV {
Expand Down Expand Up @@ -543,20 +543,9 @@ fn stored_data_kept_until_finalized() {

overseer_signal(
&mut virtual_overseer,
OverseerSignal::BlockFinalized(new_leaf)
OverseerSignal::BlockFinalized(new_leaf, 10)
).await;

assert_matches!(
overseer_recv(&mut virtual_overseer).await,
AllMessages::ChainApi(ChainApiMessage::BlockNumber(
hash,
tx,
)) => {
assert_eq!(hash, new_leaf);
tx.send(Ok(Some(10))).unwrap();
}
);

// Wait for a half of the time finalized data should be available for
Delay::new(test_state.pruning_config.keep_finalized_block_for / 2).await;

Expand Down Expand Up @@ -658,20 +647,9 @@ fn stored_chunk_kept_until_finalized() {

overseer_signal(
&mut virtual_overseer,
OverseerSignal::BlockFinalized(new_leaf)
OverseerSignal::BlockFinalized(new_leaf, 10)
).await;

assert_matches!(
overseer_recv(&mut virtual_overseer).await,
AllMessages::ChainApi(ChainApiMessage::BlockNumber(
hash,
tx,
)) => {
assert_eq!(hash, new_leaf);
tx.send(Ok(Some(10))).unwrap();
}
);

// Wait for a half of the time finalized data should be available for
Delay::new(test_state.pruning_config.keep_finalized_block_for / 2).await;

Expand Down Expand Up @@ -812,21 +790,9 @@ fn forkfullness_works() {

overseer_signal(
&mut virtual_overseer,
OverseerSignal::BlockFinalized(new_leaf_1)
OverseerSignal::BlockFinalized(new_leaf_1, 5)
).await;

assert_matches!(
overseer_recv(&mut virtual_overseer).await,
AllMessages::ChainApi(ChainApiMessage::BlockNumber(
hash,
tx,
)) => {
assert_eq!(hash, new_leaf_1);
tx.send(Ok(Some(5))).unwrap();
}
);


// Data of both candidates should be still present in the DB.
assert_eq!(
query_available_data(&mut virtual_overseer, candidate_1_hash).await.unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion node/core/backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ mod tests {
let mut head_data = HashMap::new();
head_data.insert(chain_a, HeadData(vec![4, 5, 6]));

let relay_parent = Hash::from([5; 32]);
let relay_parent = Hash::repeat_byte(5);

let signing_context = SigningContext {
session_index: 1,
Expand Down
2 changes: 1 addition & 1 deletion node/core/candidate-validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async fn run(
loop {
match ctx.recv().await? {
FromOverseer::Signal(OverseerSignal::ActiveLeaves(_)) => {}
FromOverseer::Signal(OverseerSignal::BlockFinalized(_)) => {}
FromOverseer::Signal(OverseerSignal::BlockFinalized(..)) => {}
FromOverseer::Signal(OverseerSignal::Conclude) => return Ok(()),
FromOverseer::Communication { msg } => match msg {
CandidateValidationMessage::ValidateFromChainState(
Expand Down
2 changes: 1 addition & 1 deletion node/core/chain-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ where
match ctx.recv().await? {
FromOverseer::Signal(OverseerSignal::Conclude) => return Ok(()),
FromOverseer::Signal(OverseerSignal::ActiveLeaves(_)) => {},
FromOverseer::Signal(OverseerSignal::BlockFinalized(_)) => {},
FromOverseer::Signal(OverseerSignal::BlockFinalized(..)) => {},
FromOverseer::Communication { msg } => match msg {
ChainApiMessage::BlockNumber(hash, response_channel) => {
let _timer = subsystem.metrics.time_block_number();
Expand Down
2 changes: 1 addition & 1 deletion node/core/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async fn run<Client>(
req = ctx.recv().fuse() => match req? {
FromOverseer::Signal(OverseerSignal::Conclude) => return Ok(()),
FromOverseer::Signal(OverseerSignal::ActiveLeaves(_)) => {},
FromOverseer::Signal(OverseerSignal::BlockFinalized(_)) => {},
FromOverseer::Signal(OverseerSignal::BlockFinalized(..)) => {},
FromOverseer::Communication { msg } => match msg {
RuntimeApiMessage::Request(relay_parent, request) => {
subsystem.spawn_request(relay_parent, request);
Expand Down
8 changes: 4 additions & 4 deletions node/network/availability-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ where
.filter(|(_peer, view)| {
// collect all direct interests of a peer w/o ancestors
state
.cached_live_candidates_unioned(view.0.iter())
.cached_live_candidates_unioned(view.heads.iter())
.contains_key(&candidate_hash)
})
.map(|(peer, _view)| peer.clone())
Expand Down Expand Up @@ -619,7 +619,7 @@ where
let _timer = metrics.time_process_incoming_peer_message();

// obtain the set of candidates we are interested in based on our current view
let live_candidates = state.cached_live_candidates_unioned(state.view.0.iter());
let live_candidates = state.cached_live_candidates_unioned(state.view.heads.iter());

// check if the candidate is of interest
let live_candidate = if let Some(live_candidate) = live_candidates.get(&message.candidate_hash) {
Expand Down Expand Up @@ -707,7 +707,7 @@ where
.filter(|(_peer, view)| {
// peers view must contain the candidate hash too
state
.cached_live_candidates_unioned(view.0.iter())
.cached_live_candidates_unioned(view.heads.iter())
.contains_key(&message_id.0)
})
.map(|(peer, _)| -> PeerId { peer.clone() })
Expand Down Expand Up @@ -781,7 +781,7 @@ impl AvailabilityDistributionSubsystem {
})) => {
// handled at view change
}
FromOverseer::Signal(OverseerSignal::BlockFinalized(_)) => {}
FromOverseer::Signal(OverseerSignal::BlockFinalized(..)) => {}
FromOverseer::Signal(OverseerSignal::Conclude) => {
return Ok(());
}
Expand Down
7 changes: 1 addition & 6 deletions node/network/availability-distribution/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use super::*;
use assert_matches::assert_matches;
use polkadot_erasure_coding::{branches, obtain_chunks_v1 as obtain_chunks};
use polkadot_node_network_protocol::ObservedRole;
use polkadot_node_network_protocol::{view, ObservedRole};
use polkadot_node_subsystem_util::TimeoutExt;
use polkadot_primitives::v1::{
AvailableData, BlockData, CandidateCommitments, CandidateDescriptor, GroupIndex,
Expand All @@ -33,11 +33,6 @@ use sp_application_crypto::AppKey;
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
use std::{sync::Arc, time::Duration};

macro_rules! view {
( $( $hash:expr ),* $(,)? ) => [
View(vec![ $( $hash.clone() ),* ])
];
}

macro_rules! delay {
($delay:expr) => {
Expand Down
14 changes: 4 additions & 10 deletions node/network/bitfield-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ impl BitfieldDistribution {
// defer the cleanup to the view change
}
}
FromOverseer::Signal(OverseerSignal::BlockFinalized(hash)) => {
tracing::trace!(target: LOG_TARGET, hash = %hash, "block finalized");
FromOverseer::Signal(OverseerSignal::BlockFinalized(hash, number)) => {
tracing::trace!(target: LOG_TARGET, hash = %hash, number = %number, "block finalized");
}
FromOverseer::Signal(OverseerSignal::Conclude) => {
tracing::trace!(target: LOG_TARGET, "Conclude");
Expand Down Expand Up @@ -770,13 +770,7 @@ mod test {
use std::sync::Arc;
use std::time::Duration;
use assert_matches::assert_matches;
use polkadot_node_network_protocol::ObservedRole;

macro_rules! view {
( $( $hash:expr ),* $(,)? ) => [
View(vec![ $( $hash.clone() ),* ])
];
}
use polkadot_node_network_protocol::{view, ObservedRole};

macro_rules! launch {
($fut:expr) => {
Expand Down Expand Up @@ -833,7 +827,7 @@ mod test {
let validator = SyncCryptoStore::sr25519_generate_new(&*keystore, ValidatorId::ID, None)
.expect("generating sr25519 key not to fail");

state.per_relay_parent = view.0.iter().map(|relay_parent| {(
state.per_relay_parent = view.heads.iter().map(|relay_parent| {(
relay_parent.clone(),
PerRelayParentData {
signing_context: signing_context.clone(),
Expand Down
Loading