Skip to content

Commit 6d00c6c

Browse files
remagpieforiequal0
authored andcommitted
Precompute is_empty for body downloader targets
1 parent ce85bf6 commit 6d00c6c

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

sync/src/block/downloader/body.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@ use std::collections::{HashMap, HashSet};
1818

1919
use ccore::UnverifiedTransaction;
2020
use ctypes::{BlockHash, Header};
21-
use primitives::H256;
2221

2322
use super::super::message::RequestMessage;
2423

2524
#[derive(Clone)]
2625
struct Target {
2726
hash: BlockHash,
28-
parent_hash: BlockHash,
29-
transactions_root: H256,
30-
transaction_root: H256,
27+
is_empty: bool,
3128
}
3229

3330
#[derive(Default)]
@@ -62,7 +59,7 @@ impl BodyDownloader {
6259
if self.downloading.remove(&hash) {
6360
if body.is_empty() {
6461
let target = self.targets.iter().find(|t| t.hash == hash).expect("Downloading target must exist");
65-
if target.transaction_root != target.transactions_root {
62+
if !target.is_empty {
6663
continue
6764
}
6865
}
@@ -72,13 +69,11 @@ impl BodyDownloader {
7269
self.downloading.shrink_to_fit();
7370
}
7471

75-
pub fn add_target(&mut self, header: &Header, parent: &Header) {
72+
pub fn add_target(&mut self, header: &Header, is_empty: bool) {
7673
cdebug!(SYNC, "Add download target: {}", header.hash());
7774
self.targets.push(Target {
7875
hash: header.hash(),
79-
parent_hash: parent.hash(),
80-
transactions_root: *header.transactions_root(),
81-
transaction_root: *parent.transactions_root(),
76+
is_empty,
8277
});
8378
}
8479

sync/src/block/extension.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ impl Extension {
8585
let child = &neighbors[0];
8686
let parent = &neighbors[1];
8787
cdebug!(SYNC, "Adding block #{} (hash: {}) for initial body download target", child.number(), child.hash());
88-
body_downloader.add_target(child, parent);
88+
let is_empty = child.transactions_root() == parent.transactions_root();
89+
body_downloader.add_target(child, is_empty);
8990
}
9091
cinfo!(SYNC, "Sync extension initialized");
9192
Extension {
@@ -410,7 +411,8 @@ impl Extension {
410411
.client
411412
.block_header(&BlockId::Hash(header.parent_hash()))
412413
.expect("Enacted header must have parent");
413-
self.body_downloader.add_target(&header.decode(), &parent.decode());
414+
let is_empty = header.transactions_root() == parent.transactions_root();
415+
self.body_downloader.add_target(&header.decode(), is_empty);
414416
}
415417
self.body_downloader.remove_target(&retracted);
416418
}

0 commit comments

Comments
 (0)