Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PeerDAS stuck range sync when multiple columns are batched in a single request #6276

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
71 changes: 67 additions & 4 deletions beacon_node/network/src/sync/block_sidecar_coupling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ pub struct RangeBlockComponentsRequest<E: EthSpec> {
/// Used to determine if this accumulator should wait for a sidecars stream termination
expects_blobs: bool,
expects_custody_columns: Option<Vec<ColumnIndex>>,
/// Used to determine if the number of data columns stream termination this accumulator should
/// wait for. This may be less than the number of `expects_custody_columns` due to request batching.
num_custody_column_requests: Option<usize>,
/// The peers the request was made to.
pub(crate) peer_ids: Vec<PeerId>,
}
Expand All @@ -34,6 +37,7 @@ impl<E: EthSpec> RangeBlockComponentsRequest<E> {
pub fn new(
expects_blobs: bool,
expects_custody_columns: Option<Vec<ColumnIndex>>,
num_custody_column_requests: Option<usize>,
peer_ids: Vec<PeerId>,
) -> Self {
Self {
Expand All @@ -45,6 +49,7 @@ impl<E: EthSpec> RangeBlockComponentsRequest<E> {
custody_columns_streams_terminated: 0,
expects_blobs,
expects_custody_columns,
num_custody_column_requests,
peer_ids,
}
}
Expand Down Expand Up @@ -219,8 +224,8 @@ impl<E: EthSpec> RangeBlockComponentsRequest<E> {
if self.expects_blobs && !self.is_sidecars_stream_terminated {
return false;
}
if let Some(expects_custody_columns) = &self.expects_custody_columns {
if self.custody_columns_streams_terminated < expects_custody_columns.len() {
if let Some(expects_custody_column_responses) = self.num_custody_column_requests {
if self.custody_columns_streams_terminated < expects_custody_column_responses {
return false;
}
}
Expand All @@ -241,7 +246,7 @@ mod tests {
#[test]
fn no_blobs_into_responses() {
let peer_id = PeerId::random();
let mut info = RangeBlockComponentsRequest::<E>::new(false, None, vec![peer_id]);
let mut info = RangeBlockComponentsRequest::<E>::new(false, None, None, vec![peer_id]);
let mut rng = XorShiftRng::from_seed([42; 16]);
let blocks = (0..4)
.map(|_| generate_rand_block_and_blobs::<E>(ForkName::Base, NumBlobs::None, &mut rng).0)
Expand All @@ -261,7 +266,7 @@ mod tests {
#[test]
fn empty_blobs_into_responses() {
let peer_id = PeerId::random();
let mut info = RangeBlockComponentsRequest::<E>::new(true, None, vec![peer_id]);
let mut info = RangeBlockComponentsRequest::<E>::new(true, None, None, vec![peer_id]);
let mut rng = XorShiftRng::from_seed([42; 16]);
let blocks = (0..4)
.map(|_| {
Expand Down Expand Up @@ -292,6 +297,7 @@ mod tests {
let mut info = RangeBlockComponentsRequest::<E>::new(
false,
Some(expects_custody_columns.clone()),
Some(expects_custody_columns.len()),
vec![PeerId::random()],
);
let mut rng = XorShiftRng::from_seed([42; 16]);
Expand Down Expand Up @@ -343,4 +349,61 @@ mod tests {
// All completed construct response
info.into_responses(&spec).unwrap();
}

#[test]
fn rpc_block_with_custody_columns_batched() {
let spec = test_spec::<E>();
let expects_custody_columns = vec![1, 2, 3, 4];
let num_of_data_column_requests = 2;
let mut info = RangeBlockComponentsRequest::<E>::new(
false,
Some(expects_custody_columns.clone()),
Some(num_of_data_column_requests),
vec![PeerId::random()],
);
let mut rng = XorShiftRng::from_seed([42; 16]);
let blocks = (0..4)
.map(|_| {
generate_rand_block_and_data_columns::<E>(
ForkName::Deneb,
NumBlobs::Number(1),
&mut rng,
&spec,
)
})
.collect::<Vec<_>>();

// Send blocks and complete terminate response
for block in &blocks {
info.add_block_response(Some(block.0.clone().into()));
}
info.add_block_response(None);
// Assert response is not finished
assert!(!info.is_finished());

// Send data columns interleaved
for block in &blocks {
for column in &block.1 {
if expects_custody_columns.contains(&column.index) {
info.add_data_column(Some(column.clone()));
}
}
}

// Terminate the requests
for i in 0..num_of_data_column_requests {
info.add_data_column(None);
if i < num_of_data_column_requests - 1 {
assert!(
!info.is_finished(),
"requested should not be finished at loop {i}"
);
} else {
assert!(info.is_finished(), "request should be finished at loop {i}");
}
}

// All completed construct response
info.into_responses(&spec).unwrap();
}
}
1 change: 1 addition & 0 deletions beacon_node/network/src/sync/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,7 @@ impl<T: BeaconChainTypes> SyncManager<T> {
RangeBlockComponentsRequest::new(
resp.expects_blobs,
resp.expects_custody_columns,
None,
vec![],
),
);
Expand Down
64 changes: 34 additions & 30 deletions beacon_node/network/src/sync/network_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,41 +380,45 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
false
};

let expects_custody_columns = if matches!(batch_type, ByRangeRequestType::BlocksAndColumns)
{
let custody_indexes = self.network_globals().custody_columns(epoch);

for (peer_id, columns_by_range_request) in
self.make_columns_by_range_requests(epoch, request, &custody_indexes)?
{
requested_peers.push(peer_id);

debug!(
self.log,
"Sending DataColumnsByRange requests";
"method" => "DataColumnsByRange",
"count" => columns_by_range_request.count,
"epoch" => epoch,
"columns" => ?columns_by_range_request.columns,
"peer" => %peer_id,
);

self.send_network_msg(NetworkMessage::SendRequest {
peer_id,
request: Request::DataColumnsByRange(columns_by_range_request),
request_id: AppRequestId::Sync(SyncRequestId::RangeBlockAndBlobs { id }),
})
.map_err(|_| RpcRequestSendError::NetworkSendError)?;
}
let (expects_custody_columns, num_of_custody_column_req) =
if matches!(batch_type, ByRangeRequestType::BlocksAndColumns) {
let custody_indexes = self.network_globals().custody_columns(epoch);
let mut num_of_custody_column_req = 0;

for (peer_id, columns_by_range_request) in
self.make_columns_by_range_requests(epoch, request, &custody_indexes)?
{
requested_peers.push(peer_id);

debug!(
self.log,
"Sending DataColumnsByRange requests";
"method" => "DataColumnsByRange",
"count" => columns_by_range_request.count,
"epoch" => epoch,
"columns" => ?columns_by_range_request.columns,
"peer" => %peer_id,
);

self.send_network_msg(NetworkMessage::SendRequest {
peer_id,
request: Request::DataColumnsByRange(columns_by_range_request),
request_id: AppRequestId::Sync(SyncRequestId::RangeBlockAndBlobs { id }),
})
.map_err(|_| RpcRequestSendError::NetworkSendError)?;

num_of_custody_column_req += 1;
}

Some(custody_indexes)
} else {
None
};
(Some(custody_indexes), Some(num_of_custody_column_req))
} else {
(None, None)
};

let info = RangeBlockComponentsRequest::new(
expected_blobs,
expects_custody_columns,
num_of_custody_column_req,
requested_peers,
);
self.range_block_components_requests
Expand Down
Loading