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

Commit

Permalink
Onchain scraper in dispute-coordinator will scrape `SCRAPED_FINALIZ…
Browse files Browse the repository at this point in the history
…ED_BLOCKS_COUNT` blocks before finality

The purpose is to make the availability of a `CandidateReceipt` for finalized candidates more likely.

For details see:  #7009
  • Loading branch information
tdimitrov committed Apr 6, 2023
1 parent 00b80ec commit 1525ede
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
26 changes: 20 additions & 6 deletions node/core/dispute-coordinator/src/scraping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use std::{
collections::{BTreeMap, HashSet},
num::NonZeroUsize,
num::{NonZeroU32, NonZeroUsize},
};

use futures::channel::oneshot;
Expand Down Expand Up @@ -177,6 +177,17 @@ impl ChainScraper {
/// As long as we have `MAX_FINALITY_LAG` this makes sense as a value.
pub(crate) const ANCESTRY_SIZE_LIMIT: u32 = MAX_FINALITY_LAG;

/// How many finalized block the scraper should process.
///
/// Initialize this value with `DISPUTE_CANDIDATE_LIFETIME_AFTER_FINALIZATION`
/// If `SCRAPED_FINALIZED_BLOCKS_COUNT` > `DISPUTE_CANDIDATE_LIFETIME_AFTER_FINALIZATION`
/// scraper's job will be undone on pruning.
pub(crate) const SCRAPED_FINALIZED_BLOCKS_COUNT: NonZeroU32 =
match NonZeroU32::new(DISPUTE_CANDIDATE_LIFETIME_AFTER_FINALIZATION) {
Some(cap) => cap,
None => panic!("Scraped finalized blocks count must be non-zero"),
};

/// Create a properly initialized `OrderingProvider`.
///
/// Returns: `Self` and any scraped votes.
Expand Down Expand Up @@ -230,7 +241,7 @@ impl ChainScraper {

// Fetch ancestry up to last finalized block.
let ancestors = self
.get_unfinalized_block_ancestors(sender, activated.hash, activated.number)
.get_relevant_block_ancestors(sender, activated.hash, activated.number)
.await?;

// Ancestors block numbers are consecutive in the descending order.
Expand Down Expand Up @@ -330,10 +341,11 @@ impl ChainScraper {
}

/// Returns ancestors of `head` in the descending order, stopping
/// either at the block present in cache or at the last finalized block.
/// either at the block present in cache or at `SCRAPED_FINALIZED_BLOCKS_COUNT -1` blocks after
/// the last finalized one (called `target_ancestor`).
///
/// Both `head` and the latest finalized block are **not** included in the result.
async fn get_unfinalized_block_ancestors<Sender>(
/// Both `head` and the `target_ancestor` blocks are **not** included in the result.
async fn get_relevant_block_ancestors<Sender>(
&mut self,
sender: &mut Sender,
mut head: Hash,
Expand All @@ -342,7 +354,9 @@ impl ChainScraper {
where
Sender: overseer::DisputeCoordinatorSenderTrait,
{
let target_ancestor = get_finalized_block_number(sender).await?;
let target_ancestor = get_finalized_block_number(sender)
.await?
.saturating_sub(Self::SCRAPED_FINALIZED_BLOCKS_COUNT.get() - 1);

let mut ancestors = Vec::new();

Expand Down
4 changes: 3 additions & 1 deletion node/core/dispute-coordinator/src/scraping/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,9 @@ fn scraper_requests_candidates_of_non_finalized_ancestors() {
&mut virtual_overseer,
&chain,
finalized_block_number,
BLOCKS_TO_SKIP - finalized_block_number as usize, // Expect the provider not to go past finalized block.
BLOCKS_TO_SKIP -
(finalized_block_number - ChainScraper::SCRAPED_FINALIZED_BLOCKS_COUNT.get() + 1)
as usize, // Expect the provider not to go past finalized block.
get_backed_and_included_candidate_events,
);
join(process_active_leaves_update(ctx.sender(), &mut ordering, next_update), overseer_fut)
Expand Down

0 comments on commit 1525ede

Please sign in to comment.