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

add logs to relay chain selection #3990

Merged
3 commits merged into from
Oct 1, 2021
Merged
Changes from 2 commits
Commits
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
34 changes: 33 additions & 1 deletion node/service/src/relay_chain_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ where
/// Create a new [`SelectRelayChain`] wrapping the given chain backend
/// and a handle to the overseer.
pub fn new(backend: Arc<B>, overseer: Handle, is_relay_chain: bool, metrics: Metrics) -> Self {
tracing::debug!(
target: LOG_TARGET,
"Using {} as chain selection algorithm",
if is_relay_chain { "dispute aware relay" } else { "longest" }
);
SelectRelayChain {
longest_chain: sc_consensus::LongestChain::new(backend.clone()),
selection: SelectRelayChainInner::new(backend, overseer, metrics),
Expand Down Expand Up @@ -335,12 +340,15 @@ where
.map_err(Error::OverseerDisconnected)
.map_err(|e| ConsensusError::Other(Box::new(e)))?;

tracing::trace!(target: LOG_TARGET, ?best, "Best leaf containing");

match best {
// No viable leaves containing the block.
None => return Ok(target_hash),
Some(best) => best,
}
} else {
tracing::trace!(target: LOG_TARGET, ?best_leaf, "Dummy disputes active");
if best_leaf == target_hash {
return Ok(target_hash)
} else {
Expand Down Expand Up @@ -369,6 +377,7 @@ where
let subchain_header = self.block_header(subchain_head)?;

if subchain_header.number <= max {
tracing::trace!(target: LOG_TARGET, ?best_leaf, "Constrained sub-chain head",);
subchain_head
} else {
let (ancestor_hash, _) =
Expand All @@ -378,7 +387,11 @@ where
&subchain_header,
)
.map_err(|e| ConsensusError::ChainLookup(format!("{:?}", e)))?;

tracing::trace!(
target: LOG_TARGET,
?ancestor_hash,
"Grandpa walk backwards sub-chain head"
);
ancestor_hash
}
},
Expand Down Expand Up @@ -409,6 +422,12 @@ where
}
};

tracing::trace!(
target: LOG_TARGET,
?subchain_head,
"Ancestor approval restriction applied",
);

let lag = initial_leaf_number.saturating_sub(subchain_number);
self.metrics.note_approval_checking_finality_lag(lag);

Expand Down Expand Up @@ -451,13 +470,20 @@ where
(lag, subchain_head)
};

tracing::trace!(
target: LOG_TARGET,
?subchain_head,
"Disputed blocks in ancestry restriction applied",
);

// 4. Apply the maximum safeguard to the finality lag.
if lag > MAX_FINALITY_LAG {
// We need to constrain our vote as a safety net to
// ensure the network continues to finalize.
let safe_target = initial_leaf_number - MAX_FINALITY_LAG;

if safe_target <= target_number {
tracing::warn!(target: LOG_TARGET, ?target_hash, "Safeguard enforced finalization");
// Minimal vote needs to be on the target number.
Ok(target_hash)
} else {
Expand All @@ -470,6 +496,12 @@ where
)
.map_err(|e| ConsensusError::ChainLookup(format!("{:?}", e)))?;

tracing::warn!(
target: LOG_TARGET,
?forced_target,
"Safeguard enforced finalization of child"
);

Ok(forced_target)
}
} else {
Expand Down