fix existing block lookup tests

This commit is contained in:
realbigsean
2023-04-26 14:44:32 -04:00
parent 46a9b3a7ed
commit 4390036887
3 changed files with 12 additions and 8 deletions

View File

@@ -803,7 +803,7 @@ impl<T: BeaconChainTypes> BlockLookups<T> {
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 {

View File

@@ -96,7 +96,7 @@ impl<T: BeaconChainTypes> ParentLookup<T> {
cx: &mut SyncNetworkContext<T>,
) -> 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<T: BeaconChainTypes> ParentLookup<T> {
cx: &mut SyncNetworkContext<T>,
) -> 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<T: BeaconChainTypes> ParentLookup<T> {
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<T: BeaconChainTypes> ParentLookup<T> {
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<T: BeaconChainTypes> ParentLookup<T> {
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;
}

View File

@@ -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);
}