rebuild uncles hash from uncle headers
This commit is contained in:
parent
da9e9692dc
commit
24ec696062
@ -24,9 +24,9 @@ use header::Header;
|
|||||||
|
|
||||||
use views::BlockView;
|
use views::BlockView;
|
||||||
use util::rlp::{DecoderError, RlpStream, Stream, UntrustedRlp, View};
|
use util::rlp::{DecoderError, RlpStream, Stream, UntrustedRlp, View};
|
||||||
use util::{Bytes, H256};
|
use util::{Bytes, Hashable, H256};
|
||||||
|
|
||||||
const HEADER_FIELDS: usize = 11;
|
const HEADER_FIELDS: usize = 10;
|
||||||
const BLOCK_FIELDS: usize = 2;
|
const BLOCK_FIELDS: usize = 2;
|
||||||
|
|
||||||
pub struct AbridgedBlock {
|
pub struct AbridgedBlock {
|
||||||
@ -53,7 +53,7 @@ impl AbridgedBlock {
|
|||||||
|
|
||||||
let seal_fields = header.seal();
|
let seal_fields = header.seal();
|
||||||
|
|
||||||
// 11 header fields, unknown amount of seal fields, and 2 block fields.
|
// 10 header fields, unknown amount of seal fields, and 2 block fields.
|
||||||
let mut stream = RlpStream::new_list(
|
let mut stream = RlpStream::new_list(
|
||||||
HEADER_FIELDS +
|
HEADER_FIELDS +
|
||||||
seal_fields.len() +
|
seal_fields.len() +
|
||||||
@ -62,7 +62,6 @@ impl AbridgedBlock {
|
|||||||
|
|
||||||
// write header values.
|
// write header values.
|
||||||
stream
|
stream
|
||||||
.append(&header.uncles_hash())
|
|
||||||
.append(&header.author())
|
.append(&header.author())
|
||||||
.append(&header.state_root())
|
.append(&header.state_root())
|
||||||
.append(&header.transactions_root())
|
.append(&header.transactions_root())
|
||||||
@ -74,14 +73,14 @@ impl AbridgedBlock {
|
|||||||
.append(&header.timestamp())
|
.append(&header.timestamp())
|
||||||
.append(&header.extra_data());
|
.append(&header.extra_data());
|
||||||
|
|
||||||
|
// write block values.
|
||||||
|
stream.append(&block_view.transactions()).append(&block_view.uncles());
|
||||||
|
|
||||||
// write seal fields.
|
// write seal fields.
|
||||||
for field in seal_fields {
|
for field in seal_fields {
|
||||||
stream.append_raw(&field, 1);
|
stream.append_raw(&field, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// write block values.
|
|
||||||
stream.append(&block_view.transactions()).append(&block_view.uncles());
|
|
||||||
|
|
||||||
AbridgedBlock {
|
AbridgedBlock {
|
||||||
rlp: stream.out(),
|
rlp: stream.out(),
|
||||||
}
|
}
|
||||||
@ -95,29 +94,46 @@ impl AbridgedBlock {
|
|||||||
|
|
||||||
let mut header = Header {
|
let mut header = Header {
|
||||||
parent_hash: parent_hash,
|
parent_hash: parent_hash,
|
||||||
uncles_hash: try!(rlp.val_at(0)),
|
author: try!(rlp.val_at(0)),
|
||||||
author: try!(rlp.val_at(1)),
|
state_root: try!(rlp.val_at(1)),
|
||||||
state_root: try!(rlp.val_at(2)),
|
transactions_root: try!(rlp.val_at(2)),
|
||||||
transactions_root: try!(rlp.val_at(3)),
|
receipts_root: try!(rlp.val_at(3)),
|
||||||
receipts_root: try!(rlp.val_at(4)),
|
log_bloom: try!(rlp.val_at(4)),
|
||||||
log_bloom: try!(rlp.val_at(5)),
|
difficulty: try!(rlp.val_at(5)),
|
||||||
difficulty: try!(rlp.val_at(6)),
|
|
||||||
number: number,
|
number: number,
|
||||||
gas_limit: try!(rlp.val_at(7)),
|
gas_limit: try!(rlp.val_at(6)),
|
||||||
gas_used: try!(rlp.val_at(8)),
|
gas_used: try!(rlp.val_at(7)),
|
||||||
timestamp: try!(rlp.val_at(9)),
|
timestamp: try!(rlp.val_at(8)),
|
||||||
extra_data: try!(rlp.val_at(10)),
|
extra_data: try!(rlp.val_at(9)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
let transactions = try!(rlp.val_at(10));
|
||||||
|
let uncles: Vec<Header> = try!(rlp.val_at(11));
|
||||||
|
|
||||||
let seal: Vec<Bytes> = try!(rlp.val_at(11));
|
// iterator-based approach is cleaner but doesn't work w/ try.
|
||||||
|
let seal = {
|
||||||
|
let mut seal = Vec::new();
|
||||||
|
|
||||||
|
for i in 12..rlp.item_count() {
|
||||||
|
seal.push(try!(rlp.val_at(i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
seal
|
||||||
|
};
|
||||||
|
|
||||||
header.set_seal(seal);
|
header.set_seal(seal);
|
||||||
|
|
||||||
|
let uncle_bytes = uncles.iter()
|
||||||
|
.fold(RlpStream::new_list(uncles.len()), |mut s, u| {
|
||||||
|
s.append_raw(&u.rlp(::basic_types::Seal::With), 1);
|
||||||
|
s
|
||||||
|
}).out();
|
||||||
|
header.uncles_hash = uncle_bytes.sha3();
|
||||||
|
|
||||||
Ok(Block {
|
Ok(Block {
|
||||||
header: header,
|
header: header,
|
||||||
transactions: try!(rlp.val_at(12)),
|
transactions: transactions,
|
||||||
uncles: try!(rlp.val_at(13)),
|
uncles: uncles,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user