Fix for sync.

This commit is contained in:
Gav Wood 2016-01-15 23:32:17 +01:00
parent e876a04afb
commit 4fde74c5e8
4 changed files with 23 additions and 3 deletions

View File

@ -126,6 +126,15 @@ impl<'x, 'y> OpenBlock<'x, 'y> {
/// Alter the timestamp of the block.
pub fn set_timestamp(&mut self, timestamp: u64) { self.block.header.set_timestamp(timestamp); }
/// Alter the difficulty for the block.
pub fn set_difficulty(&mut self, a: U256) { self.block.header.set_difficulty(a); }
/// Alter the gas limit for the block.
pub fn set_gas_limit(&mut self, a: U256) { self.block.header.set_gas_limit(a); }
/// Alter the gas limit for the block.
pub fn set_gas_used(&mut self, a: U256) { self.block.header.set_gas_used(a); }
/// Alter the extra_data for the block.
pub fn set_extra_data(&mut self, extra_data: Bytes) -> Result<(), BlockError> {
if extra_data.len() > self.engine.maximum_extra_data_size() {
@ -158,7 +167,7 @@ impl<'x, 'y> OpenBlock<'x, 'y> {
author: self.block.header.author.clone(),
timestamp: self.block.header.timestamp,
difficulty: self.block.header.difficulty.clone(),
last_hashes: self.last_hashes.clone(),
last_hashes: self.last_hashes.clone(), // TODO: should be a reference.
gas_used: self.block.archive.last().map(|t| t.receipt.gas_used).unwrap_or(U256::from(0)),
gas_limit: self.block.header.gas_limit.clone(),
}
@ -169,6 +178,7 @@ impl<'x, 'y> OpenBlock<'x, 'y> {
/// If valid, it will be executed, and archived together with the receipt.
pub fn push_transaction(&mut self, t: Transaction, h: Option<H256>) -> Result<&Receipt, Error> {
let env_info = self.env_info();
// info!("env_info says gas_used={}", env_info.gas_used);
match self.block.state.apply(&env_info, self.engine, &t) {
Ok(receipt) => {
self.block.archive_set.insert(h.unwrap_or_else(||t.hash()));
@ -260,10 +270,14 @@ pub fn enact<'x, 'y>(block_bytes: &[u8], engine: &'x Engine, db: OverlayDB, pare
let s = State::from_existing(db.clone(), parent.state_root().clone(), engine.account_start_nonce());
// flush(format!("enact(): root={}, author={}, author_balance={}\n", s.root(), header.author(), s.balance(&header.author())));
}
let block = BlockView::new(block_bytes);
let header = block.header_view();
let mut b = OpenBlock::new(engine, db, parent, last_hashes, header.author(), header.extra_data());
b.set_difficulty(header.difficulty());
b.set_gas_limit(header.gas_limit());
b.set_timestamp(header.timestamp());
// info!("enact: Enacting #{}. env_info={:?}", header.number(), b.env_info());
for t in block.transactions().into_iter() { try!(b.push_transaction(t, None)); }
for u in block.uncles().into_iter() { try!(b.push_uncle(u)); }
Ok(b.close())

View File

@ -43,6 +43,8 @@ impl Engine for Ethash {
max(gas_floor_target, gas_limit - gas_limit / bound_divisor + x!(1) + (header.gas_used * x!(6) / x!(5)) / bound_divisor)
}
};
// info!("ethash: populate_from_parent #{}: difficulty={} and gas_limit={}", header.number, header.difficulty, header.gas_limit);
}
/// Apply the block reward on finalisation of the block.

View File

@ -196,8 +196,6 @@ impl<'a> Executive<'a> {
// part of substate that may be reverted
let mut unconfirmed_substate = Substate::new();
info!("exec: call; env_info={:?}", self.info);
let res = {
let mut ext = self.to_externalities(params, &mut unconfirmed_substate, OutputPolicy::Return(output));
let evm = Factory::create();

View File

@ -67,7 +67,9 @@ impl Header {
pub fn state_root(&self) -> &H256 { &self.state_root }
pub fn receipts_root(&self) -> &H256 { &self.receipts_root }
pub fn gas_limit(&self) -> &U256 { &self.gas_limit }
pub fn difficulty(&self) -> &U256 { &self.difficulty }
pub fn seal(&self) -> &Vec<Bytes> { &self.seal }
// TODO: seal_at, set_seal_at &c.
@ -79,6 +81,10 @@ impl Header {
pub fn set_extra_data(&mut self, a: Bytes) { if a != self.extra_data { self.extra_data = a; self.note_dirty(); } }
pub fn set_gas_used(&mut self, a: U256) { self.gas_used = a; self.note_dirty(); }
pub fn set_gas_limit(&mut self, a: U256) { self.gas_limit = a; self.note_dirty(); }
pub fn set_difficulty(&mut self, a: U256) { self.difficulty = a; self.note_dirty(); }
pub fn set_seal(&mut self, a: Vec<Bytes>) { self.seal = a; self.note_dirty(); }
/// Get the hash of this header (sha3 of the RLP).