Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed May 9, 2024
1 parent 94be0c7 commit 58d273d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::common::ResponseType;
use super::{BlockComponent, PeerId, SINGLE_BLOCK_LOOKUP_MAX_ATTEMPTS};
use crate::sync::block_lookups::common::RequestState;
use crate::sync::block_lookups::Id;
Expand Down Expand Up @@ -150,6 +151,7 @@ impl<T: BeaconChainTypes> SingleBlockLookup<T> {
) -> Result<(), LookupRequestError> {
let id = self.id;
let awaiting_parent = self.awaiting_parent.is_some();
let block_is_processed = self.block_request_state.state.is_processed();
let request = R::request_state_mut(self);

// Attempt to progress awaiting downloads
Expand Down Expand Up @@ -181,7 +183,9 @@ impl<T: BeaconChainTypes> SingleBlockLookup<T> {
// Otherwise, attempt to progress awaiting processing
// If this request is awaiting a parent lookup to be processed, do not send for processing.
// The request will be rejected with unknown parent error.
} else if !awaiting_parent {
} else if !awaiting_parent
&& (block_is_processed || matches!(R::response_type(), ResponseType::Block))
{
// maybe_start_processing returns Some if state == AwaitingProcess. This pattern is
// useful to conditionally access the result data.
if let Some(result) = request.get_state_mut().maybe_start_processing() {
Expand Down
6 changes: 3 additions & 3 deletions beacon_node/network/src/sync/block_lookups/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ impl TestRig {
let peer_id = PeerId::random();
let slot = block.slot();
let block_root = block.canonical_root();
self.single_lookup_block_response(id, peer_id, Some(block.into()));
self.single_lookup_block_response(id, peer_id, Some(block));
self.single_lookup_block_response(id, peer_id, None);
// Expect processing and resolve with import
self.expect_block_process(ResponseType::Block);
Expand Down Expand Up @@ -1633,10 +1633,10 @@ fn custody_lookup_happy_path() {
r.trigger_unknown_block_from_attestation(block_root, peer_id);
// Should not request blobs
let id = r.expect_block_lookup_request(block.canonical_root());
r.complete_valid_block_request(id, block.into(), true);
// TODO(das): do not hardcode 4
let custody_ids = r.expect_only_data_columns_by_root_requests(block_root, 4);
r.complete_valid_custody_request(custody_ids, data_columns, true);
r.complete_valid_block_request(id, block.into(), false);
r.complete_valid_custody_request(custody_ids, data_columns, false);
r.expect_no_active_lookups();
}

Expand Down
6 changes: 4 additions & 2 deletions beacon_node/network/src/sync/network_context/custody.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ pub enum Error {
NoPeers(ColumnIndex),
}

type CustodyRequestResult<E> = Result<Option<(Vec<CustodyDataColumn<E>>, PeerGroup)>, Error>;

impl<T: BeaconChainTypes> ActiveCustodyRequest<T> {
pub(crate) fn new(
block_root: Hash256,
Expand Down Expand Up @@ -80,7 +82,7 @@ impl<T: BeaconChainTypes> ActiveCustodyRequest<T> {
column_index: ColumnIndex,
resp: RpcProcessingResult<DataColumnSidecarList<T::EthSpec>>,
cx: &mut SyncNetworkContext<T>,
) -> Result<Option<(Vec<CustodyDataColumn<T::EthSpec>>, PeerGroup)>, Error> {
) -> CustodyRequestResult<T::EthSpec> {
// TODO(das): Should downscore peers for verify errors here

let Some(request) = self.column_requests.get_mut(&column_index) else {
Expand Down Expand Up @@ -127,7 +129,7 @@ impl<T: BeaconChainTypes> ActiveCustodyRequest<T> {
pub(crate) fn continue_requests(
&mut self,
cx: &mut SyncNetworkContext<T>,
) -> Result<Option<(Vec<CustodyDataColumn<T::EthSpec>>, PeerGroup)>, Error> {
) -> CustodyRequestResult<T::EthSpec> {
// First check if sampling is completed, by computing `required_successes`
let mut successes = 0;

Expand Down

0 comments on commit 58d273d

Please sign in to comment.