-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Remove RefCell from Header #8227
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely a step in the right direction, but eventually I'd love to see a full separation of Header with and without hash :) #1267
@@ -269,7 +269,6 @@ impl<'x> OpenBlock<'x> { | |||
r.block.header.set_author(author); | |||
r.block.header.set_timestamp_now(parent.timestamp()); | |||
r.block.header.set_extra_data(extra_data); | |||
r.block.header.note_dirty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
ethcore/src/block.rs
Outdated
@@ -374,7 +375,7 @@ impl<'x> OpenBlock<'x> { | |||
s.block.header.set_uncles_hash(keccak(&uncle_bytes)); | |||
s.block.header.set_state_root(s.block.state.root().clone()); | |||
s.block.header.set_receipts_root(ordered_trie_root(s.block.receipts.iter().map(|r| r.rlp_bytes()))); | |||
s.block.header.set_log_bloom(s.block.receipts.iter().fold(Bloom::zero(), |mut b, r| {b = &b | &r.log_bloom; b})); //TODO: use |= operator | |||
s.block.header.set_log_bloom(s.block.receipts.iter().fold(Bloom::zero(), |b, r| &b | &r.log_bloom )); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will be even more efficient if you use accrue_bloom method as it modifying bloom inplace without allocating 256 bytes for every loop iteration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logged an issue for that :)
ethcore/src/block.rs
Outdated
@@ -407,7 +409,7 @@ impl<'x> OpenBlock<'x> { | |||
} | |||
|
|||
s.block.header.set_state_root(s.block.state.root().clone()); | |||
s.block.header.set_log_bloom(s.block.receipts.iter().fold(Bloom::zero(), |mut b, r| {b = &b | &r.log_bloom; b})); //TODO: use |= operator | |||
s.block.header.set_log_bloom(s.block.receipts.iter().fold(Bloom::zero(), |b, r| &b | &r.log_bloom)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, please look into accrue_bloom
@@ -53,19 +53,19 @@ lazy_static! { | |||
// only "first" proofs are such. | |||
struct StateProof { | |||
contract_address: Address, | |||
header: Mutex<Header>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lgtm, but I'm not changing the label as it is currently marked 'inprogress' |
@debris Marked as in progress cause I wanted to benchmark blockchain import speed (that it's not worse). |
Did some performance tests (importing first 2M blocks of eth mainnet):
So the difference is insignificant (note I was using my computer during this time, so it's not comparative benchmark) and new code doesn't cause any major performance regression during sync (which I believe is not a good benchmark for that code either, but at least we know that normal mode operation is not affected). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
} | ||
|
||
impl PartialEq for Header { | ||
fn eq(&self, c: &Header) -> bool { | ||
if let (&Some(ref h1), &Some(ref h2)) = (&self.hash, &c.hash) { | ||
if h1 == h2 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be return h1 == h2
instead? I.e. if the hash is defined for both we do the comparison strictly on the hash.
There's a conflict that needs fixing. |
This makes
Header
Sync
.I've analyzed the actual usage of
Header
hash cache andencoded::Header
hashing and:Decoded
headers and we fetchhash()
multiple times (andbare_hash()
at most once)best_block_header
and it's hash, previously we were usually decodingencoded::Header
to do that.This PR removes
Blockchain::block_header
since it was always causing decoding, and was mostly used to get best block header. Instead it introducesBlockchain::best_block_header
which returns a cached and decoded header and a helper method inClient
doing the same.As a result even though we are dropping
bare_hash
cache we should not see any performance drawback. Actually we might see a small improvement due to less decoding and hashing. This is still being benchmarked.It will also help with #8074 and the
unsafe Sync
discussion there.