From 230c6c889ab34b7f874be852eb64e5055d65bda7 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 22 Jun 2016 21:33:10 +0200 Subject: [PATCH] Ensure judging the SF trigger by relative branch (#1399) Rather than just the canon chain. --- ethcore/src/client/client.rs | 6 +++--- ethcore/src/client/mod.rs | 16 +++++++++++++--- ethcore/src/miner/miner.rs | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index fa063cd61..693296469 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -230,7 +230,7 @@ impl Client where V: Verifier { let last_hashes = self.build_last_hashes(header.parent_hash.clone()); let db = self.state_db.lock().unwrap().boxed_clone(); - let enact_result = enact_verified(&block, engine, self.tracedb.tracing_enabled(), db, &parent, last_hashes, self.dao_rescue_block_gas_limit(), &self.vm_factory); + let enact_result = enact_verified(&block, engine, self.tracedb.tracing_enabled(), db, &parent, last_hashes, self.dao_rescue_block_gas_limit(header.parent_hash.clone()), &self.vm_factory); if let Err(e) = enact_result { warn!(target: "client", "Block import failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e); return Err(()); @@ -486,7 +486,7 @@ impl BlockChainClient for Client where V: Verifier { last_hashes: last_hashes, gas_used: U256::zero(), gas_limit: U256::max_value(), - dao_rescue_block_gas_limit: self.dao_rescue_block_gas_limit(), + dao_rescue_block_gas_limit: self.dao_rescue_block_gas_limit(view.parent_hash()), }; // that's just a copy of the state. let mut state = self.state(); @@ -808,7 +808,7 @@ impl MiningBlockChainClient for Client where V: Verifier { self.state_db.lock().unwrap().boxed_clone(), &self.chain.block_header(&h).expect("h is best block hash: so it's header must exist: qed"), self.build_last_hashes(h.clone()), - self.dao_rescue_block_gas_limit(), + self.dao_rescue_block_gas_limit(h.clone()), author, gas_floor_target, extra_data, diff --git a/ethcore/src/client/mod.rs b/ethcore/src/client/mod.rs index c1bc3203c..589b65e16 100644 --- a/ethcore/src/client/mod.rs +++ b/ethcore/src/client/mod.rs @@ -227,9 +227,19 @@ pub trait BlockChainClient : Sync + Send { /// Get `Some` gas limit of block 1_760_000, or `None` if chain is not yet that long. - fn dao_rescue_block_gas_limit(&self) -> Option { - self.block_header(BlockID::Number(1_760_000)) - .map(|header| HeaderView::new(&header).gas_limit()) + fn dao_rescue_block_gas_limit(&self, chain_hash: H256) -> Option { + if let Some(mut header) = self.block_header(BlockID::Hash(chain_hash)) { + if HeaderView::new(&header).number() < 1_760_000 { + None + } else { + while HeaderView::new(&header).number() != 1_760_000 { + header = self.block_header(BlockID::Hash(HeaderView::new(&header).parent_hash())).expect("chain is complete; parent of chain entry must be in chain; qed"); + } + Some(HeaderView::new(&header).gas_limit()) + } + } else { + None + } } } diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 41e4b4810..290e94059 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -274,7 +274,7 @@ impl MinerService for Miner { last_hashes: last_hashes, gas_used: U256::zero(), gas_limit: U256::max_value(), - dao_rescue_block_gas_limit: chain.dao_rescue_block_gas_limit(), + dao_rescue_block_gas_limit: chain.dao_rescue_block_gas_limit(header.parent_hash().clone()), }; // that's just a copy of the state. let mut state = block.state().clone();