mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 15:47:58 +00:00
Don't return the same block twice in ancestor binary search (#11067)
* Don't return the same block in ancestor search * Add regression test for ancestor search repeat
This commit is contained in:
@@ -2320,7 +2320,11 @@ fn handle_ancestor_search_state<B: BlockT>(
|
||||
}
|
||||
assert!(right >= left);
|
||||
let middle = left + (right - left) / two;
|
||||
Some((AncestorSearchState::BinarySearch(left, right), middle))
|
||||
if middle == curr_block_num {
|
||||
None
|
||||
} else {
|
||||
Some((AncestorSearchState::BinarySearch(left, right), middle))
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -3238,4 +3242,9 @@ mod test {
|
||||
sync.on_block_data(&peer_id1, Some(request), response).unwrap();
|
||||
assert_eq!(sync.best_queued_number, 4);
|
||||
}
|
||||
#[test]
|
||||
fn ancestor_search_repeat() {
|
||||
let state = AncestorSearchState::<Block>::BinarySearch(1, 3);
|
||||
assert!(handle_ancestor_search_state(&state, 2, true).is_none());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user