Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
av-store: write meta for unknown finalized blocks (#6452)
Browse files Browse the repository at this point in the history
* av-store: write meta for unknown finalized blocks

* fix test
  • Loading branch information
ordian committed Jan 5, 2023
1 parent 52e8606 commit 115ac12
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
8 changes: 8 additions & 0 deletions node/core/av-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,14 @@ async fn run_iteration<Context>(
FromOrchestra::Signal(OverseerSignal::BlockFinalized(hash, number)) => {
let _timer = subsystem.metrics.time_process_block_finalized();

if !subsystem.known_blocks.is_known(&hash) {
// If we haven't processed this block yet,
// make sure we write the metadata about the
// 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?;
}
subsystem.finalized_number = Some(number);
subsystem.known_blocks.prune_finalized(number);
process_block_finalized(
Expand Down
45 changes: 43 additions & 2 deletions node/core/av-store/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,49 @@ fn we_dont_miss_anything_if_import_notifications_are_missed() {
let test_state = TestState::default();

test_harness(test_state.clone(), store.clone(), |mut virtual_overseer| async move {
overseer_signal(&mut virtual_overseer, OverseerSignal::BlockFinalized(Hash::zero(), 1))
.await;
let block_hash = Hash::repeat_byte(1);
overseer_signal(&mut virtual_overseer, OverseerSignal::BlockFinalized(block_hash, 1)).await;

let header = Header {
parent_hash: Hash::repeat_byte(0),
number: 1,
state_root: Hash::zero(),
extrinsics_root: Hash::zero(),
digest: Default::default(),
};

assert_matches!(
overseer_recv(&mut virtual_overseer).await,
AllMessages::ChainApi(ChainApiMessage::BlockHeader(
relay_parent,
tx,
)) => {
assert_eq!(relay_parent, block_hash);
tx.send(Ok(Some(header))).unwrap();
}
);

assert_matches!(
overseer_recv(&mut virtual_overseer).await,
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
relay_parent,
RuntimeApiRequest::CandidateEvents(tx),
)) => {
assert_eq!(relay_parent, block_hash);
tx.send(Ok(Vec::new())).unwrap();
}
);

assert_matches!(
overseer_recv(&mut virtual_overseer).await,
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
relay_parent,
RuntimeApiRequest::Validators(tx),
)) => {
assert_eq!(relay_parent, Hash::zero());
tx.send(Ok(Vec::new())).unwrap();
}
);

let header = Header {
parent_hash: Hash::repeat_byte(3),
Expand Down

0 comments on commit 115ac12

Please sign in to comment.