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

Commit ed3a397

Browse files
committed
finality_target adjustments
1 parent 0c670d8 commit ed3a397

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ async fn handle_approved_ancestor(
11801180
target: Hash,
11811181
lower_bound: BlockNumber,
11821182
wakeups: &Wakeups,
1183-
) -> SubsystemResult<Option<(Hash, BlockNumber)>> {
1183+
) -> SubsystemResult<Option<(Hash, BlockNumber, Vec<(Hash, SessionIndex, Vec<CandidateHash>)>)>> {
11841184
const MAX_TRACING_WINDOW: usize = 200;
11851185
const ABNORMAL_DEPTH_THRESHOLD: usize = 5;
11861186

@@ -1228,6 +1228,8 @@ async fn handle_approved_ancestor(
12281228
Vec::new()
12291229
};
12301230

1231+
let mut candidates: Vec<_> = Vec::new();
1232+
12311233
let mut bits: BitVec<Lsb0, u8> = Default::default();
12321234
for (i, block_hash) in std::iter::once(target).chain(ancestry).enumerate() {
12331235
// Block entries should be present as the assumption is that
@@ -1248,6 +1250,8 @@ async fn handle_approved_ancestor(
12481250
Some(b) => b,
12491251
};
12501252

1253+
candidates.push((block_hash, entry.session(), entry.candidates().iter().map(|(_idx, candidate_hash)| *candidate_hash ).collect::<Vec<_>>()));
1254+
12511255
// even if traversing millions of blocks this is fairly cheap and always dwarfed by the
12521256
// disk lookups.
12531257
bits.push(entry.is_fully_approved());
@@ -1366,8 +1370,11 @@ async fn handle_approved_ancestor(
13661370
},
13671371
);
13681372

1373+
let all_approved_max = all_approved_max.map(|(hash, block_number)| {
1374+
(hash, block_number, candidates)
1375+
});
13691376
match all_approved_max {
1370-
Some((ref hash, ref number)) => {
1377+
Some((ref hash, ref number, _)) => {
13711378
span.add_uint_tag("approved-number", *number as u64);
13721379
span.add_string_fmt_debug_tag("approved-hash", hash);
13731380
}

node/service/src/grandpa_support.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<B> grandpa::VotingRule<PolkadotBlock, B> for ApprovalCheckingVotingRule
155155
let diff = best_number.saturating_sub(base_number);
156156
if diff >= MAX_APPROVAL_CHECKING_FINALITY_LAG {
157157
// Catch up to the best, with some extra lag.
158-
let target_number = best_number - MAX_APPROVAL_CHECKING_FINALITY_LAG;
158+
let target_number = best_number.saturating_sub(MAX_APPROVAL_CHECKING_FINALITY_LAG);
159159
if target_number >= current_number {
160160
Some((current_hash, current_number))
161161
} else {

node/service/src/relay_chain_selection.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use {
3939
polkadot_primitives::v1::{
4040
Hash, BlockNumber, Block as PolkadotBlock, Header as PolkadotHeader,
4141
},
42-
polkadot_subsystem::messages::{ApprovalVotingMessage, ChainSelectionMessage},
42+
polkadot_subsystem::messages::{ApprovalVotingMessage, ChainSelectionMessage, DisputeCoordinatorMessage},
4343
polkadot_node_subsystem_util::metrics::{self, prometheus},
4444
polkadot_overseer::Handle,
4545
futures::channel::oneshot,
@@ -321,7 +321,7 @@ impl<B> SelectChain<PolkadotBlock> for SelectRelayChain<B>
321321
let initial_leaf_number = self.block_number(initial_leaf)?;
322322

323323
// 2. Constrain according to `ApprovedAncestor`.
324-
let (subchain_head, subchain_number) = {
324+
let (subchain_head, subchain_number, subchain_block_descriptions) = {
325325

326326
let (tx, rx) = oneshot::channel();
327327
overseer.send_msg(
@@ -338,8 +338,8 @@ impl<B> SelectChain<PolkadotBlock> for SelectRelayChain<B>
338338
.map_err(|e| ConsensusError::Other(Box::new(e)))?
339339
{
340340
// No approved ancestors means target hash is maximal vote.
341-
None => (target_hash, target_number),
342-
Some((s_h, s_n)) => (s_h, s_n),
341+
None => (target_hash, target_number, Vec::new()),
342+
Some((s_h, s_n, s_bd)) => (s_h, s_n, s_bd),
343343
}
344344
};
345345

@@ -348,6 +348,17 @@ impl<B> SelectChain<PolkadotBlock> for SelectRelayChain<B>
348348

349349
// 3. Constrain according to disputes:
350350
// TODO: https://github.com/paritytech/polkadot/issues/3164
351+
let (tx, rx) = oneshot::channel();
352+
overseer.send_msg(DisputeCoordinatorMessage::DetermineUndisputedChain{
353+
base_number: subchain_number,
354+
block_descriptions: subchain_block_descriptions,
355+
tx,
356+
}).await;
357+
let (subchain_numbner, subchain_head) = rx.await
358+
.map_err(Error::OverseerDisconnected)
359+
.map_err(|e| ConsensusError::Other(Box::new(e)))?
360+
.unwrap_or_else(|| (subchain_number, subchain_head));
361+
351362
self.metrics.note_disputes_finality_lag(0);
352363

353364
// 4. Apply the maximum safeguard to the finality lag.

node/subsystem-types/src/messages.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ pub enum ApprovalVotingMessage {
814814
///
815815
/// It can also return the same block hash, if that is acceptable to vote upon.
816816
/// Return `None` if the input hash is unrecognized.
817-
ApprovedAncestor(Hash, BlockNumber, oneshot::Sender<Option<(Hash, BlockNumber)>>),
817+
ApprovedAncestor(Hash, BlockNumber, oneshot::Sender<Option<(Hash, BlockNumber, Vec<(Hash, SessionIndex, Vec<CandidateHash>)>)>>),
818818
}
819819

820820
/// Message to the Approval Distribution subsystem.

0 commit comments

Comments
 (0)