Tree-sync friendly lookup sync tests (#8592)

- Step 0 of the tree-sync roadmap https://github.com/sigp/lighthouse/issues/7678

Current lookup sync tests are written in an explicit way that assume how the internals of lookup sync work. For example the test would do:

- Emit unknown block parent message
- Expect block request for X
- Respond with successful block request
- Expect block processing request for X
- Response with successful processing request
- etc..

This is unnecessarily verbose. And it will requires a complete re-write when something changes in the internals of lookup sync (has happened a few times, mostly for deneb and fulu).

What we really want to assert is:

- WHEN: we receive an unknown block parent message
- THEN: Lookup sync can sync that block
- ASSERT: Without penalizing peers, without unnecessary retries


  Keep all existing tests and add new cases but written in the new style described above. The logic to serve and respond to request is in this function `fn simulate` 2288a3aeb1/beacon_node/network/src/sync/tests/lookups.rs (L301)
- It controls peer behavior based on a `CompleteStrategy` where you can set for example "respond to BlocksByRoot requests with empty"
- It actually runs beacon processor messages running their clousures. Now sync tests actually import blocks, increasing the test coverage to the interaction of sync and the da_checker.
- To achieve the above the tests create real blocks with the test harness. To make the tests as fast as before, I disabled crypto with `TestConfig`

Along the way I found a couple bugs, which I documented on the diff.


Co-Authored-By: dapplion <35266934+dapplion@users.noreply.github.com>
This commit is contained in:
Lion - dapplion
2026-02-12 21:24:51 -07:00
committed by GitHub
parent c59e4a0cee
commit f4a6b8d9b9
27 changed files with 2298 additions and 2381 deletions

View File

@@ -198,7 +198,14 @@ impl<T: BeaconChainTypes> ActiveCustodyRequest<T> {
cx: &mut SyncNetworkContext<T>,
) -> CustodyRequestResult<T::EthSpec> {
let _guard = self.span.clone().entered();
if self.column_requests.values().all(|r| r.is_downloaded()) {
let total_requests = self.column_requests.len();
let completed_requests = self
.column_requests
.values()
.filter(|r| r.is_downloaded())
.count();
if completed_requests >= total_requests {
// All requests have completed successfully.
let mut peers = HashMap::<PeerId, Vec<usize>>::new();
let mut seen_timestamps = vec![];
@@ -222,6 +229,7 @@ impl<T: BeaconChainTypes> ActiveCustodyRequest<T> {
let active_request_count_by_peer = cx.active_request_count_by_peer();
let mut columns_to_request_by_peer = HashMap::<PeerId, Vec<ColumnIndex>>::new();
let mut columns_without_peers = vec![];
let lookup_peers = self.lookup_peers.read();
// Create deterministic hasher per request to ensure consistent peer ordering within
// this request (avoiding fragmentation) while varying selection across different requests
@@ -256,6 +264,7 @@ impl<T: BeaconChainTypes> ActiveCustodyRequest<T> {
return Err(Error::NoPeer(*column_index));
} else {
// Do not issue requests if there is no custody peer on this column
columns_without_peers.push(*column_index);
}
}
}
@@ -270,10 +279,13 @@ impl<T: BeaconChainTypes> ActiveCustodyRequest<T> {
lookup_peers = lookup_peers.len(),
"Requesting {} columns from {} peers", columns_requested_count, peer_requests,
);
} else {
} else if !columns_without_peers.is_empty() {
debug!(
lookup_peers = lookup_peers.len(),
"No column peers found for look up",
total_requests,
completed_requests,
?columns_without_peers,
"No column peers found for lookup",
);
}
@@ -288,7 +300,7 @@ impl<T: BeaconChainTypes> ActiveCustodyRequest<T> {
},
// If peer is in the lookup peer set, it claims to have imported the block and
// must have its columns in custody. In that case, set `true = enforce max_requests`
// and downscore if data_columns_by_root does not returned the expected custody
// and downscore if data_columns_by_root does not return the expected custody
// columns. For the rest of peers, don't downscore if columns are missing.
lookup_peers.contains(&peer_id),
)