mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 21:21:11 +00:00
Use number of downloaded blocks for test (#6234)
This commit is contained in:
@@ -533,9 +533,9 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> {
|
||||
self.sync.status().queued_blocks
|
||||
}
|
||||
|
||||
/// Number of processed blocks.
|
||||
pub fn num_processed_blocks(&self) -> usize {
|
||||
self.sync.num_processed_blocks()
|
||||
/// Number of downloaded blocks.
|
||||
pub fn num_downloaded_blocks(&self) -> usize {
|
||||
self.sync.num_downloaded_blocks()
|
||||
}
|
||||
|
||||
/// Number of active sync requests.
|
||||
|
||||
@@ -189,8 +189,8 @@ pub struct ChainSync<B: BlockT> {
|
||||
block_announce_validator: Box<dyn BlockAnnounceValidator<B> + Send>,
|
||||
/// Maximum number of peers to ask the same blocks in parallel.
|
||||
max_parallel_downloads: u32,
|
||||
/// Total number of processed blocks (imported or failed).
|
||||
processed_blocks: usize,
|
||||
/// Total number of downloaded blocks.
|
||||
downloaded_blocks: usize,
|
||||
}
|
||||
|
||||
/// All the data we have about a Peer that we are trying to sync with
|
||||
@@ -375,7 +375,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
pending_requests: Default::default(),
|
||||
block_announce_validator,
|
||||
max_parallel_downloads,
|
||||
processed_blocks: 0,
|
||||
downloaded_blocks: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,9 +415,9 @@ impl<B: BlockT> ChainSync<B> {
|
||||
self.fork_targets.len()
|
||||
}
|
||||
|
||||
/// Number of processed blocks.
|
||||
pub fn num_processed_blocks(&self) -> usize {
|
||||
self.processed_blocks
|
||||
/// Number of downloaded blocks.
|
||||
pub fn num_downloaded_blocks(&self) -> usize {
|
||||
self.downloaded_blocks
|
||||
}
|
||||
|
||||
/// Handle a new connected peer.
|
||||
@@ -719,6 +719,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
request: Option<BlockRequest<B>>,
|
||||
response: BlockResponse<B>
|
||||
) -> Result<OnBlockData<B>, BadPeer> {
|
||||
self.downloaded_blocks += response.blocks.len();
|
||||
let mut new_blocks: Vec<IncomingBlock<B>> =
|
||||
if let Some(peer) = self.peers.get_mut(who) {
|
||||
let mut blocks = response.blocks;
|
||||
@@ -1004,8 +1005,6 @@ impl<B: BlockT> ChainSync<B> {
|
||||
for (_, hash) in &results {
|
||||
self.queue_blocks.remove(&hash);
|
||||
}
|
||||
self.processed_blocks += results.len();
|
||||
|
||||
for (result, hash) in results {
|
||||
if has_error {
|
||||
continue;
|
||||
@@ -1274,7 +1273,6 @@ impl<B: BlockT> ChainSync<B> {
|
||||
|
||||
/// Restart the sync process.
|
||||
fn restart<'a>(&'a mut self) -> impl Iterator<Item = Result<(PeerId, BlockRequest<B>), BadPeer>> + 'a {
|
||||
self.processed_blocks = 0;
|
||||
self.blocks.clear();
|
||||
let info = self.client.info();
|
||||
self.best_queued_hash = info.best_hash;
|
||||
|
||||
@@ -390,9 +390,9 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
|
||||
self.network_service.user_protocol().num_queued_blocks()
|
||||
}
|
||||
|
||||
/// Returns the number of processed blocks.
|
||||
pub fn num_processed_blocks(&self) -> usize {
|
||||
self.network_service.user_protocol().num_processed_blocks()
|
||||
/// Returns the number of downloaded blocks.
|
||||
pub fn num_downloaded_blocks(&self) -> usize {
|
||||
self.network_service.user_protocol().num_downloaded_blocks()
|
||||
}
|
||||
|
||||
/// Number of active sync requests.
|
||||
|
||||
@@ -221,9 +221,9 @@ impl<D> Peer<D> {
|
||||
self.network.num_connected_peers()
|
||||
}
|
||||
|
||||
/// Returns the number of processed blocks.
|
||||
pub fn num_processed_blocks(&self) -> usize {
|
||||
self.network.num_processed_blocks()
|
||||
/// Returns the number of downloaded blocks.
|
||||
pub fn num_downloaded_blocks(&self) -> usize {
|
||||
self.network.num_downloaded_blocks()
|
||||
}
|
||||
|
||||
/// Returns true if we have no peer.
|
||||
|
||||
@@ -673,12 +673,12 @@ fn imports_stale_once() {
|
||||
// check that NEW block is imported from announce message
|
||||
let new_hash = net.peer(0).push_blocks(1, false);
|
||||
import_with_announce(&mut net, new_hash);
|
||||
assert_eq!(net.peer(1).num_processed_blocks(), 1);
|
||||
assert_eq!(net.peer(1).num_downloaded_blocks(), 1);
|
||||
|
||||
// check that KNOWN STALE block is imported from announce message
|
||||
let known_stale_hash = net.peer(0).push_blocks_at(BlockId::Number(0), 1, true);
|
||||
import_with_announce(&mut net, known_stale_hash);
|
||||
assert_eq!(net.peer(1).num_processed_blocks(), 2);
|
||||
assert_eq!(net.peer(1).num_downloaded_blocks(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user