From 5302a7dd58265728f230d14bb1358a90ec1d2497 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 22 Jun 2016 19:49:07 +0200 Subject: [PATCH 1/3] Ensure judging the SF trigger by relative branch 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 fa063cd6132..69329646944 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 c1bc3203c4b..589b65e16c9 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 41e4b48100c..290e94059eb 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(); From 1602906b565aecbebbb3b221255663ad68ffb7d9 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 22 Jun 2016 21:37:29 +0200 Subject: [PATCH 2/3] Shortcut SF condition when canon known --- ethcore/src/client/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ethcore/src/client/mod.rs b/ethcore/src/client/mod.rs index 589b65e16c9..3ed56573ac6 100644 --- a/ethcore/src/client/mod.rs +++ b/ethcore/src/client/mod.rs @@ -228,6 +228,11 @@ 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, chain_hash: H256) -> Option { + // shortcut if the canon chain is already known. + if self.chain_info().best_block_number > 1_761_000 { + return self.block_header(BlockID::Number(1_760_000)).map(|header| HeaderView::new(&header).gas_limit()); + } + // otherwise check according to `chain_hash`. if let Some(mut header) = self.block_header(BlockID::Hash(chain_hash)) { if HeaderView::new(&header).number() < 1_760_000 { None From 129ce97ad57f21021873ea2e8651724d997cba1f Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 23 Jun 2016 11:30:48 +0200 Subject: [PATCH 3/3] Constants for SF# and update. --- ethcore/src/block.rs | 3 ++- ethcore/src/client/mod.rs | 12 ++++++------ ethcore/src/env_info.rs | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ethcore/src/block.rs b/ethcore/src/block.rs index ff05b5af17a..f7288c85b4d 100644 --- a/ethcore/src/block.rs +++ b/ethcore/src/block.rs @@ -288,6 +288,7 @@ impl<'x> OpenBlock<'x> { /// Get the environment info concerning this block. pub fn env_info(&self) -> EnvInfo { // TODO: memoise. + const SOFT_FORK_BLOCK: u64 = 1775000; EnvInfo { number: self.block.base.header.number, author: self.block.base.header.author.clone(), @@ -296,7 +297,7 @@ impl<'x> OpenBlock<'x> { last_hashes: self.last_hashes.clone(), // TODO: should be a reference. gas_used: self.block.receipts.last().map_or(U256::zero(), |r| r.gas_used), gas_limit: self.block.base.header.gas_limit.clone(), - dao_rescue_block_gas_limit: if self.block.base.header.number == 1760000 { Some(self.block.base.header.gas_limit) } else { self.dao_rescue_block_gas_limit }, + dao_rescue_block_gas_limit: if self.block.base.header.number == SOFT_FORK_BLOCK { Some(self.block.base.header.gas_limit) } else { self.dao_rescue_block_gas_limit }, } } diff --git a/ethcore/src/client/mod.rs b/ethcore/src/client/mod.rs index 3ed56573ac6..86686cb4c8d 100644 --- a/ethcore/src/client/mod.rs +++ b/ethcore/src/client/mod.rs @@ -225,19 +225,19 @@ pub trait BlockChainClient : Sync + Send { } } - - /// Get `Some` gas limit of block 1_760_000, or `None` if chain is not yet that long. + /// Get `Some` gas limit of SOFT_FORK_BLOCK, or `None` if chain is not yet that long. fn dao_rescue_block_gas_limit(&self, chain_hash: H256) -> Option { + const SOFT_FORK_BLOCK: u64 = 1775000; // shortcut if the canon chain is already known. - if self.chain_info().best_block_number > 1_761_000 { - return self.block_header(BlockID::Number(1_760_000)).map(|header| HeaderView::new(&header).gas_limit()); + if self.chain_info().best_block_number > SOFT_FORK_BLOCK + 1000 { + return self.block_header(BlockID::Number(SOFT_FORK_BLOCK)).map(|header| HeaderView::new(&header).gas_limit()); } // otherwise check according to `chain_hash`. if let Some(mut header) = self.block_header(BlockID::Hash(chain_hash)) { - if HeaderView::new(&header).number() < 1_760_000 { + if HeaderView::new(&header).number() < SOFT_FORK_BLOCK { None } else { - while HeaderView::new(&header).number() != 1_760_000 { + while HeaderView::new(&header).number() != SOFT_FORK_BLOCK { 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()) diff --git a/ethcore/src/env_info.rs b/ethcore/src/env_info.rs index a38a31ff716..8304fcc0351 100644 --- a/ethcore/src/env_info.rs +++ b/ethcore/src/env_info.rs @@ -40,7 +40,7 @@ pub struct EnvInfo { /// The gas used. pub gas_used: U256, - /// Block gas limit at DAO rescue block #1760000 or None if not yet there. + /// Block gas limit at DAO rescue block SOFT_FORK_BLOCK or None if not yet there. pub dao_rescue_block_gas_limit: Option, }