integrate dispute finality (#3484)

* finality_target adjustments

* fn finality_target

* partially address review comments

* fixins

* more rustic if condition

* fix tests

* fixins

* Update node/core/approval-voting/src/lib.rs

Co-authored-by: Andronik Ordian <write@reusable.software>

* Update node/core/approval-voting/src/lib.rs

Co-authored-by: Robert Habermeier <rphmeier@gmail.com>

* review comments part one

* rename candidates -> block_descriptions

* testing outline (incomplete, WIP)

* test foo

* split RelayChainSelection into RelayChainSelection{,WithFallback}, introduce HeaderProvider{,Provider}

* make some stuff public (revert this soon™)

* some test improvements

* slips of pens

* test fixins

* add another trait abstraction

* pending edge case tests + warnings fixes

* more test cases

* fin

* chore fmt

* fix cargo.lock

* Undo obsolete changes

* // comments

* make mod pub(crate)

* fix

* minimize static bounds

* resolve number() as before

* fmt

* post merge fix

* address some nits

Co-authored-by: Andronik Ordian <write@reusable.software>
Co-authored-by: Robert Habermeier <rphmeier@gmail.com>
This commit is contained in:
Bernhard Schuster
2021-07-26 11:54:50 -04:00
committed by GitHub
parent bd9b743872
commit 6519ba987c
11 changed files with 1090 additions and 100 deletions
+23 -3
View File
@@ -27,7 +27,7 @@ use polkadot_node_subsystem::{
ApprovalVotingMessage, RuntimeApiMessage, RuntimeApiRequest, ChainApiMessage,
ApprovalDistributionMessage, CandidateValidationMessage,
AvailabilityRecoveryMessage, ChainSelectionMessage, DisputeCoordinatorMessage,
ImportStatementsResult,
ImportStatementsResult, HighestApprovedAncestorBlock, BlockDescription,
},
errors::RecoveryError,
overseer::{self, SubsystemSender as _}, SubsystemContext, SubsystemError, SubsystemResult, SpawnedSubsystem,
@@ -1180,7 +1180,7 @@ async fn handle_approved_ancestor(
target: Hash,
lower_bound: BlockNumber,
wakeups: &Wakeups,
) -> SubsystemResult<Option<(Hash, BlockNumber)>> {
) -> SubsystemResult<Option<HighestApprovedAncestorBlock>> {
const MAX_TRACING_WINDOW: usize = 200;
const ABNORMAL_DEPTH_THRESHOLD: usize = 5;
@@ -1228,6 +1228,8 @@ async fn handle_approved_ancestor(
Vec::new()
};
let mut block_descriptions = Vec::new();
let mut bits: BitVec<Lsb0, u8> = Default::default();
for (i, block_hash) in std::iter::once(target).chain(ancestry).enumerate() {
// Block entries should be present as the assumption is that
@@ -1259,8 +1261,10 @@ async fn handle_approved_ancestor(
}
} else if bits.len() <= ABNORMAL_DEPTH_THRESHOLD {
all_approved_max = None;
block_descriptions.clear();
} else {
all_approved_max = None;
block_descriptions.clear();
let unapproved: Vec<_> = entry.unapproved_candidates().collect();
tracing::debug!(
@@ -1338,6 +1342,11 @@ async fn handle_approved_ancestor(
}
}
}
block_descriptions.push(BlockDescription {
block_hash,
session: entry.session(),
candidates: entry.candidates().iter().map(|(_idx, candidate_hash)| *candidate_hash ).collect(),
});
}
tracing::trace!(
@@ -1366,8 +1375,19 @@ async fn handle_approved_ancestor(
},
);
// `reverse()` to obtain the ascending order from lowest to highest
// block within the candidates, which is the expected order
block_descriptions.reverse();
let all_approved_max = all_approved_max.map(|(hash, block_number)| {
HighestApprovedAncestorBlock{
hash,
number: block_number,
descriptions: block_descriptions,
}
});
match all_approved_max {
Some((ref hash, ref number)) => {
Some(HighestApprovedAncestorBlock { ref hash, ref number, .. }) => {
span.add_uint_tag("approved-number", *number as u64);
span.add_string_fmt_debug_tag("approved-hash", hash);
}
@@ -26,7 +26,7 @@ use polkadot_node_primitives::approval::{
RELAY_VRF_MODULO_CONTEXT, DelayTranche,
};
use polkadot_node_subsystem_test_helpers::make_subsystem_context;
use polkadot_node_subsystem::messages::AllMessages;
use polkadot_node_subsystem::messages::{AllMessages, HighestApprovedAncestorBlock};
use sp_core::testing::TaskExecutor;
use parking_lot::Mutex;
@@ -1612,10 +1612,12 @@ fn approved_ancestor_all_approved() {
let test_fut = Box::pin(async move {
let overlay_db = OverlayedBackend::new(&db);
assert_eq!(
assert_matches!(
handle_approved_ancestor(&mut ctx, &overlay_db, block_hash_4, 0, &Default::default())
.await.unwrap(),
Some((block_hash_4, 4)),
.await,
Ok(Some(HighestApprovedAncestorBlock { hash, number, .. } )) => {
assert_eq!((block_hash_4, 4), (hash, number));
}
)
});
@@ -1686,10 +1688,12 @@ fn approved_ancestor_missing_approval() {
let test_fut = Box::pin(async move {
let overlay_db = OverlayedBackend::new(&db);
assert_eq!(
assert_matches!(
handle_approved_ancestor(&mut ctx, &overlay_db, block_hash_4, 0, &Default::default())
.await.unwrap(),
Some((block_hash_2, 2)),
.await,
Ok(Some(HighestApprovedAncestorBlock { hash, number, .. })) => {
assert_eq!((block_hash_2, 2), (hash, number));
}
)
});