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

Update dispute participation on active leaves update #6303

Merged
merged 37 commits into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c039614
Passed candidate events from scraper to participation
BradleyOlson64 Nov 15, 2022
7666c67
First draft PR 5875
BradleyOlson64 Nov 16, 2022
3829bd7
Merge branch 'master' of https://github.com/paritytech/polkadot into …
BradleyOlson64 Nov 16, 2022
1cdc72d
Added support for timestamp in changes
BradleyOlson64 Nov 16, 2022
e9d1273
Some necessary refactoring
BradleyOlson64 Nov 18, 2022
4eebacd
Removed SessionIndex from unconfirmed_disputes key
BradleyOlson64 Nov 19, 2022
45477d2
Removed duplicate logic in import statements
BradleyOlson64 Nov 19, 2022
5b11951
Merge branch 'master' of https://github.com/paritytech/polkadot into …
BradleyOlson64 Nov 19, 2022
04b214c
Replaced queue_participation call with re-prio
BradleyOlson64 Nov 19, 2022
58f6371
Simplifying refactor. Backed were already handled
BradleyOlson64 Nov 21, 2022
efa2870
Removed unneeded spam slots logic
BradleyOlson64 Nov 21, 2022
c0ee1fe
Implementers guide edits
BradleyOlson64 Nov 22, 2022
8b27aef
Undid the spam slots refactor
BradleyOlson64 Nov 22, 2022
319ea05
Added comments and implementers guide edit
BradleyOlson64 Nov 22, 2022
26c9ebe
Added test for participation upon backing
BradleyOlson64 Nov 25, 2022
78cc97b
Merge branch 'master' of https://github.com/paritytech/polkadot into …
BradleyOlson64 Nov 25, 2022
16edc2b
Merge branch 'master' into brad-issue-5875
Dec 1, 2022
e1c356c
Round of fixes + ran fmt
BradleyOlson64 Dec 1, 2022
a7615e5
Round of changes + fmt
BradleyOlson64 Dec 1, 2022
9aea6c6
Merge branch 'brad-issue-5875' of https://github.com/paritytech/polka…
BradleyOlson64 Dec 1, 2022
87cb5a2
Error handling draft
BradleyOlson64 Dec 3, 2022
595fe63
Changed errors to bubble up from reprioritization
BradleyOlson64 Dec 5, 2022
38c6986
Starting to construct new test
BradleyOlson64 Dec 5, 2022
afd63f6
Clarifying participation function rename
BradleyOlson64 Dec 6, 2022
efd7088
Reprio test draft
BradleyOlson64 Dec 9, 2022
8382edb
Merge branch 'master' of https://github.com/paritytech/polkadot into …
BradleyOlson64 Dec 9, 2022
e9eb4e8
Very rough bump to priority queue test draft
BradleyOlson64 Dec 13, 2022
d49bd0b
Improving logging
BradleyOlson64 Dec 15, 2022
7546335
Most concise reproduction of error on third import
BradleyOlson64 Dec 15, 2022
16e35c8
Add `handle_approval_vote_request`
tdimitrov Dec 16, 2022
2954a96
Removing reprioritization on included event test
BradleyOlson64 Dec 16, 2022
b3b3d8a
Removing unneeded test config
BradleyOlson64 Dec 16, 2022
72ae47a
cargo fmt
BradleyOlson64 Dec 16, 2022
e38a933
Test works
tdimitrov Dec 21, 2022
b53035c
Fixing final nits
BradleyOlson64 Dec 22, 2022
dede25c
Merge branch 'brad-issue-5875-temp' of https://github.com/paritytech/…
BradleyOlson64 Dec 22, 2022
d7f0250
Tweaks to test Tsveto figured out
BradleyOlson64 Dec 22, 2022
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
Next Next commit
Passed candidate events from scraper to participation
  • Loading branch information
BradleyOlson64 committed Nov 15, 2022
commit c0396144469392874361ecfa5827521c0802b134
6 changes: 3 additions & 3 deletions node/core/dispute-coordinator/src/initialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl Initialized {
if let Some(first_leaf) = first_leaf.take() {
// Also provide first leaf to participation for good measure.
self.participation
.process_active_leaves_update(ctx, &ActiveLeavesUpdate::start_work(first_leaf))
.process_active_leaves_update(ctx, &ActiveLeavesUpdate::start_work(first_leaf), Vec::new())
.await?;
}

Expand Down Expand Up @@ -269,9 +269,9 @@ impl Initialized {
update: ActiveLeavesUpdate,
now: u64,
) -> Result<()> {
let on_chain_votes =
let (on_chain_votes, candidate_events) =
self.scraper.process_active_leaves_update(ctx.sender(), &update).await?;
self.participation.process_active_leaves_update(ctx, &update).await?;
self.participation.process_active_leaves_update(ctx, &update, candidate_events).await?;

if let Some(new_leaf) = update.activated {
match self
Expand Down
25 changes: 24 additions & 1 deletion node/core/dispute-coordinator/src/participation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use polkadot_node_subsystem::{
overseer, ActiveLeavesUpdate, RecoveryError,
};
use polkadot_node_subsystem_util::runtime::get_validation_code_by_hash;
use polkadot_primitives::v2::{BlockNumber, CandidateHash, CandidateReceipt, Hash, SessionIndex};
use polkadot_primitives::v2::{BlockNumber, CandidateHash, CandidateReceipt, Hash, SessionIndex, CandidateEvent};

use crate::LOG_TARGET;

Expand Down Expand Up @@ -195,6 +195,7 @@ impl Participation {
&mut self,
ctx: &mut Context,
update: &ActiveLeavesUpdate,
candidate_events: Vec<(Vec<CandidateEvent>, BlockNumber)>,
) -> FatalResult<()> {
if let Some(activated) = &update.activated {
match self.recent_block {
Expand All @@ -208,6 +209,8 @@ impl Participation {
},
Some(_) => {},
}

self.handle_candidate_events(candidate_events);
}
Ok(())
}
Expand Down Expand Up @@ -245,6 +248,26 @@ impl Participation {
}
Ok(())
}

/// Update priority queue and best effort queue to account for
/// freshly backed or included disputed candidates
fn handle_candidate_events(&mut self, candidate_events : Vec<(Vec<CandidateEvent>, BlockNumber)>) {
for (events_for_block, block_number) in candidate_events {
for event in events_for_block {
match event {
CandidateEvent::CandidateIncluded(receipt, _, _, _) => {
let candidate_hash = receipt.hash();
},
CandidateEvent::CandidateBacked(receipt, _, _, _) => {
let candidate_hash = receipt.hash();
},
_ => {
// skip the rest
},
}
}
}
}
}

async fn participate(
Expand Down
1 change: 1 addition & 0 deletions node/core/dispute-coordinator/src/participation/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ async fn activate_leaf<Context>(
number: block_number,
status: LeafStatus::Fresh,
}),
Vec::new(),
)
.await
}
Expand Down
19 changes: 11 additions & 8 deletions node/core/dispute-coordinator/src/scraping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl ChainScraper {
};
let update =
ActiveLeavesUpdate { activated: Some(initial_head), deactivated: Default::default() };
let votes = s.process_active_leaves_update(sender, &update).await?;
let (votes, _) = s.process_active_leaves_update(sender, &update).await?;
Ok((s, votes))
}

Expand All @@ -137,13 +137,13 @@ impl ChainScraper {
&mut self,
sender: &mut Sender,
update: &ActiveLeavesUpdate,
) -> Result<Vec<ScrapedOnChainVotes>>
) -> Result<(Vec<ScrapedOnChainVotes>, Vec<(Vec<CandidateEvent>, BlockNumber)>)>
where
Sender: overseer::DisputeCoordinatorSenderTrait,
{
let activated = match update.activated.as_ref() {
Some(activated) => activated,
None => return Ok(Vec::new()),
None => return Ok((Vec::new(), Vec::new())),
};

// Fetch ancestry up to last finalized block.
Expand All @@ -157,11 +157,13 @@ impl ChainScraper {

let block_hashes = std::iter::once(activated.hash).chain(ancestors);

let mut candidate_events: Vec<(Vec<CandidateEvent>, BlockNumber)> = Vec::new();
let mut on_chain_votes = Vec::new();
for (block_number, block_hash) in block_numbers.zip(block_hashes) {
gum::trace!(?block_number, ?block_hash, "In ancestor processing.");

self.process_candidate_events(sender, block_number, block_hash).await?;
let events_for_block = self.process_candidate_events(sender, block_number, block_hash).await?;
BradleyOlson64 marked this conversation as resolved.
Show resolved Hide resolved
candidate_events.push((events_for_block, block_number));

if let Some(votes) = get_on_chain_votes(sender, block_hash).await? {
on_chain_votes.push(votes);
Expand All @@ -170,7 +172,7 @@ impl ChainScraper {

self.last_observed_blocks.put(activated.hash, ());

Ok(on_chain_votes)
Ok((on_chain_votes, candidate_events))
}

/// Prune finalized candidates.
Expand Down Expand Up @@ -201,12 +203,13 @@ impl ChainScraper {
sender: &mut Sender,
block_number: BlockNumber,
block_hash: Hash,
) -> Result<()>
) -> Result<Vec<CandidateEvent>>
where
Sender: overseer::DisputeCoordinatorSenderTrait,
{
let events = get_candidate_events(sender, block_hash).await?;
// Get included and backed events:
for ev in get_candidate_events(sender, block_hash).await? {
for ev in &events {
BradleyOlson64 marked this conversation as resolved.
Show resolved Hide resolved
match ev {
CandidateEvent::CandidateIncluded(receipt, _, _, _) => {
let candidate_hash = receipt.hash();
Expand All @@ -233,7 +236,7 @@ impl ChainScraper {
},
}
}
Ok(())
Ok(events)
}

/// Returns ancestors of `head` in the descending order, stopping
Expand Down