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

Commit

Permalink
node/approval-voting: Add load_all_blocks to overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
Lldenaurois committed Jun 24, 2021
1 parent a7a612a commit 5bf68b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
12 changes: 11 additions & 1 deletion node/core/approval-voting/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub(super) trait Backend {
/// converted into a set of write operations which will, when written to
/// the underlying backend, give the same view as the state of the overlay.
pub(super) struct OverlayedBackend<'a, B: 'a> {
pub(super) inner: &'a B,
inner: &'a B,

// `None` means unchanged
stored_block_range: Option<StoredBlockRange>,
Expand All @@ -184,6 +184,16 @@ impl<'a, B: 'a + Backend> OverlayedBackend<'a, B> {
self.block_entries.is_empty() || self.candidate_entries.is_empty()
}

pub(super) fn load_all_blocks(&self) -> SubsystemResult<Vec<Hash>> {
let mut hashes = Vec::new();
if let Some(stored_blocks) = self.load_stored_blocks()? {
for height in stored_blocks.0..stored_blocks.1 {
hashes.extend(self.load_blocks_at_height(&height)?);
}
}
Ok(hashes)
}

pub(super) fn load_stored_blocks(&self) -> SubsystemResult<Option<StoredBlockRange>> {
if let Some(val) = self.stored_block_range.clone() {
Ok(Some(val))
Expand Down
14 changes: 6 additions & 8 deletions node/core/approval-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,10 +791,10 @@ async fn run<B, C>(
// https://github.com/paritytech/polkadot/issues/3311
//
// returns `true` if any of the actions was a `Conclude` command.
async fn handle_actions<'a>(
async fn handle_actions(
ctx: &mut impl SubsystemContext,
state: &mut State,
overlayed_db: &mut OverlayedBackend<'a, impl Backend>,
overlayed_db: &mut OverlayedBackend<'_, impl Backend>,
metrics: &Metrics,
wakeups: &mut Wakeups,
currently_checking_set: &mut CurrentlyCheckingSet,
Expand All @@ -812,9 +812,7 @@ async fn handle_actions<'a>(
block_number,
candidate_hash,
tick,
} => {
wakeups.schedule(block_hash, block_number, candidate_hash, tick)
},
} => wakeups.schedule(block_hash, block_number, candidate_hash, tick),
Action::IssueApproval(candidate_hash, approval_request) => {
let mut sender = ctx.sender().clone();
// Note that the IssueApproval action will create additional
Expand Down Expand Up @@ -901,7 +899,7 @@ async fn handle_actions<'a>(
Action::BecomeActive => {
*mode = Mode::Active;

let messages = distribution_messages_for_activation(overlayed_db.inner)?;
let messages = distribution_messages_for_activation(overlayed_db)?;

ctx.send_messages(messages.into_iter().map(Into::into)).await;
}
Expand All @@ -912,8 +910,8 @@ async fn handle_actions<'a>(
Ok(conclude)
}

fn distribution_messages_for_activation<'a>(
db: &(impl Backend + 'a),
fn distribution_messages_for_activation(
db: &OverlayedBackend<'_, impl Backend>,
) -> SubsystemResult<Vec<ApprovalDistributionMessage>> {
let all_blocks: Vec<Hash> = db.load_all_blocks()?;

Expand Down

0 comments on commit 5bf68b0

Please sign in to comment.