Skip to content

Commit b2c00ce

Browse files
authored
Merge of #6473
2 parents ee7fca3 + dd6370b commit b2c00ce

File tree

3 files changed

+60
-38
lines changed

3 files changed

+60
-38
lines changed

beacon_node/network/src/sync/block_lookups/tests.rs

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,14 +1319,44 @@ impl TestRig {
13191319
});
13201320
}
13211321

1322-
fn assert_sampling_request_status(
1323-
&self,
1324-
block_root: Hash256,
1325-
ongoing: &Vec<ColumnIndex>,
1326-
no_peers: &Vec<ColumnIndex>,
1327-
) {
1328-
self.sync_manager
1329-
.assert_sampling_request_status(block_root, ongoing, no_peers)
1322+
fn assert_sampling_request_ongoing(&self, block_root: Hash256, indices: &[ColumnIndex]) {
1323+
for index in indices {
1324+
let status = self
1325+
.sync_manager
1326+
.get_sampling_request_status(block_root, index)
1327+
.unwrap_or_else(|| panic!("No request state for {index}"));
1328+
if !matches!(status, crate::sync::peer_sampling::Status::Sampling { .. }) {
1329+
panic!("expected {block_root} {index} request to be on going: {status:?}");
1330+
}
1331+
}
1332+
}
1333+
1334+
fn assert_sampling_request_nopeers(&self, block_root: Hash256, indices: &[ColumnIndex]) {
1335+
for index in indices {
1336+
let status = self
1337+
.sync_manager
1338+
.get_sampling_request_status(block_root, index)
1339+
.unwrap_or_else(|| panic!("No request state for {index}"));
1340+
if !matches!(status, crate::sync::peer_sampling::Status::NoPeers { .. }) {
1341+
panic!("expected {block_root} {index} request to be no peers: {status:?}");
1342+
}
1343+
}
1344+
}
1345+
1346+
fn log_sampling_requests(&self, block_root: Hash256, indices: &[ColumnIndex]) {
1347+
let statuses = indices
1348+
.iter()
1349+
.map(|index| {
1350+
let status = self
1351+
.sync_manager
1352+
.get_sampling_request_status(block_root, index)
1353+
.unwrap_or_else(|| panic!("No request state for {index}"));
1354+
(index, status)
1355+
})
1356+
.collect::<Vec<_>>();
1357+
self.log(&format!(
1358+
"Sampling request status for {block_root}: {statuses:?}"
1359+
));
13301360
}
13311361
}
13321362

@@ -2099,7 +2129,7 @@ fn sampling_batch_requests() {
20992129
.pop()
21002130
.unwrap();
21012131
assert_eq!(column_indexes.len(), SAMPLING_REQUIRED_SUCCESSES);
2102-
r.assert_sampling_request_status(block_root, &column_indexes, &vec![]);
2132+
r.assert_sampling_request_ongoing(block_root, &column_indexes);
21032133

21042134
// Resolve the request.
21052135
r.complete_valid_sampling_column_requests(
@@ -2127,7 +2157,7 @@ fn sampling_batch_requests_not_enough_responses_returned() {
21272157
assert_eq!(column_indexes.len(), SAMPLING_REQUIRED_SUCCESSES);
21282158

21292159
// The request status should be set to Sampling.
2130-
r.assert_sampling_request_status(block_root, &column_indexes, &vec![]);
2160+
r.assert_sampling_request_ongoing(block_root, &column_indexes);
21312161

21322162
// Split the indexes to simulate the case where the supernode doesn't have the requested column.
21332163
let (_column_indexes_supernode_does_not_have, column_indexes_to_complete) =
@@ -2145,7 +2175,8 @@ fn sampling_batch_requests_not_enough_responses_returned() {
21452175
);
21462176

21472177
// The request status should be set to NoPeers since the supernode, the only peer, returned not enough responses.
2148-
r.assert_sampling_request_status(block_root, &vec![], &column_indexes);
2178+
r.log_sampling_requests(block_root, &column_indexes);
2179+
r.assert_sampling_request_nopeers(block_root, &column_indexes);
21492180

21502181
// The sampling request stalls.
21512182
r.expect_empty_network();

beacon_node/network/src/sync/manager.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,12 @@ impl<T: BeaconChainTypes> SyncManager<T> {
354354
}
355355

356356
#[cfg(test)]
357-
pub(crate) fn assert_sampling_request_status(
357+
pub(crate) fn get_sampling_request_status(
358358
&self,
359359
block_root: Hash256,
360-
ongoing: &Vec<ColumnIndex>,
361-
no_peers: &Vec<ColumnIndex>,
362-
) {
363-
self.sampling
364-
.assert_sampling_request_status(block_root, ongoing, no_peers);
360+
index: &ColumnIndex,
361+
) -> Option<super::peer_sampling::Status> {
362+
self.sampling.get_request_status(block_root, index)
365363
}
366364

367365
fn network_globals(&self) -> &NetworkGlobals<T::EthSpec> {

beacon_node/network/src/sync/peer_sampling.rs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use self::request::ActiveColumnSampleRequest;
2+
#[cfg(test)]
3+
pub(crate) use self::request::Status;
24
use super::network_context::{
35
DataColumnsByRootSingleBlockRequest, RpcResponseError, SyncNetworkContext,
46
};
@@ -43,15 +45,15 @@ impl<T: BeaconChainTypes> Sampling<T> {
4345
}
4446

4547
#[cfg(test)]
46-
pub fn assert_sampling_request_status(
48+
pub fn get_request_status(
4749
&self,
4850
block_root: Hash256,
49-
ongoing: &Vec<ColumnIndex>,
50-
no_peers: &Vec<ColumnIndex>,
51-
) {
51+
index: &ColumnIndex,
52+
) -> Option<self::request::Status> {
5253
let requester = SamplingRequester::ImportedBlock(block_root);
53-
let active_sampling_request = self.requests.get(&requester).unwrap();
54-
active_sampling_request.assert_sampling_request_status(ongoing, no_peers);
54+
self.requests
55+
.get(&requester)
56+
.and_then(|req| req.get_request_status(index))
5557
}
5658

5759
/// Create a new sampling request for a known block
@@ -233,18 +235,8 @@ impl<T: BeaconChainTypes> ActiveSamplingRequest<T> {
233235
}
234236

235237
#[cfg(test)]
236-
pub fn assert_sampling_request_status(
237-
&self,
238-
ongoing: &Vec<ColumnIndex>,
239-
no_peers: &Vec<ColumnIndex>,
240-
) {
241-
for idx in ongoing {
242-
assert!(self.column_requests.get(idx).unwrap().is_ongoing());
243-
}
244-
245-
for idx in no_peers {
246-
assert!(self.column_requests.get(idx).unwrap().is_no_peers());
247-
}
238+
pub fn get_request_status(&self, index: &ColumnIndex) -> Option<self::request::Status> {
239+
self.column_requests.get(index).map(|req| req.status())
248240
}
249241

250242
/// Insert a downloaded column into an active sampling request. Then make progress on the
@@ -584,8 +576,9 @@ mod request {
584576
peers_dont_have: HashSet<PeerId>,
585577
}
586578

579+
// Exposed only for testing assertions in lookup tests
587580
#[derive(Debug, Clone)]
588-
enum Status {
581+
pub(crate) enum Status {
589582
NoPeers,
590583
NotStarted,
591584
Sampling(PeerId),
@@ -630,8 +623,8 @@ mod request {
630623
}
631624

632625
#[cfg(test)]
633-
pub(crate) fn is_no_peers(&self) -> bool {
634-
matches!(self.status, Status::NoPeers)
626+
pub(crate) fn status(&self) -> Status {
627+
self.status.clone()
635628
}
636629

637630
pub(crate) fn choose_peer<T: BeaconChainTypes>(

0 commit comments

Comments
 (0)