diff --git a/beacon_node/network/src/sync/block_lookups/mod.rs b/beacon_node/network/src/sync/block_lookups/mod.rs index b8ee17c652..a63dc228f1 100644 --- a/beacon_node/network/src/sync/block_lookups/mod.rs +++ b/beacon_node/network/src/sync/block_lookups/mod.rs @@ -803,7 +803,7 @@ impl BlockLookups { block_id_opt .as_mut() .or(blob_id_opt.as_mut()) - .and_then(|id_ref| (*id_ref != id).then_some((index, id_ref, req))) + .and_then(|id_ref| (*id_ref == id).then_some((index, id_ref, req))) }, ); let (index, request_id_ref, request_ref) = match lookup_components_opt { diff --git a/beacon_node/network/src/sync/block_lookups/parent_lookup.rs b/beacon_node/network/src/sync/block_lookups/parent_lookup.rs index 66b97ac8c7..7424fb8349 100644 --- a/beacon_node/network/src/sync/block_lookups/parent_lookup.rs +++ b/beacon_node/network/src/sync/block_lookups/parent_lookup.rs @@ -96,7 +96,7 @@ impl ParentLookup { cx: &mut SyncNetworkContext, ) -> Result<(), RequestError> { // check to make sure this request hasn't failed - if self.downloaded_blocks.len() >= PARENT_DEPTH_TOLERANCE { + if self.downloaded_blocks.len() + 1 >= PARENT_DEPTH_TOLERANCE { return Err(RequestError::ChainTooLong); } @@ -120,7 +120,7 @@ impl ParentLookup { cx: &mut SyncNetworkContext, ) -> Result<(), RequestError> { // check to make sure this request hasn't failed - if self.downloaded_blocks.len() >= PARENT_DEPTH_TOLERANCE { + if self.downloaded_blocks.len() + 1 >= PARENT_DEPTH_TOLERANCE { return Err(RequestError::ChainTooLong); } @@ -164,6 +164,8 @@ impl ParentLookup { single_block_lookup::State::AwaitingDownload; self.current_parent_request_id = None; self.current_parent_blob_request_id = None; + self.current_parent_request.downloaded_block = None; + self.current_parent_request.downloaded_blobs = <_>::default(); } pub fn add_block( @@ -246,6 +248,7 @@ impl ParentLookup { self.current_parent_request .block_request_state .register_failure_processing(); + self.current_parent_request.downloaded_block = None; self.current_parent_request_id = None; } @@ -253,6 +256,8 @@ impl ParentLookup { self.current_parent_request .blob_request_state .register_failure_processing(); + //TODO(sean) can make this only clear the blobs that failed to process + self.current_parent_request.downloaded_blobs = <_>::default(); self.current_parent_blob_request_id = None; } diff --git a/beacon_node/network/src/sync/block_lookups/tests.rs b/beacon_node/network/src/sync/block_lookups/tests.rs index 2a77c0f147..256ed80042 100644 --- a/beacon_node/network/src/sync/block_lookups/tests.rs +++ b/beacon_node/network/src/sync/block_lookups/tests.rs @@ -286,7 +286,7 @@ fn test_single_block_lookup_becomes_parent_request() { ResponseType::Block, &mut cx, ); - assert_eq!(bl.single_block_lookups.len(), 0); + assert_eq!(bl.single_block_lookups.len(), 1); rig.expect_parent_request(); rig.expect_empty_network(); assert_eq!(bl.parent_lookups.len(), 1); @@ -557,7 +557,6 @@ fn test_parent_lookup_too_many_processing_attempts_must_blacklist() { let parent = Arc::new(rig.rand_block()); let block = rig.block_with_parent(parent.canonical_root()); - let block_hash = block.canonical_root(); let peer_id = PeerId::random(); let block_root = block.canonical_root(); let parent_root = block.parent_root(); @@ -584,11 +583,11 @@ fn test_parent_lookup_too_many_processing_attempts_must_blacklist() { // Now fail processing a block in the parent request for _ in 0..PROCESSING_FAILURES { let id = dbg!(rig.expect_parent_request()); - assert!(!bl.failed_chains.contains(&block_hash)); + assert!(!bl.failed_chains.contains(&block_root)); // send the right parent but fail processing bl.parent_lookup_response(id, peer_id, Some(parent.clone()), D, &mut cx); bl.parent_block_processed( - block_hash, + block_root, BlockError::InvalidSignature.into(), ResponseType::Block, &mut cx, @@ -597,7 +596,7 @@ fn test_parent_lookup_too_many_processing_attempts_must_blacklist() { rig.expect_penalty(); } - assert!(bl.failed_chains.contains(&block_hash)); + assert!(bl.failed_chains.contains(&block_root)); assert_eq!(bl.parent_lookups.len(), 0); }