From 8fcec203982b7c60fc30187a19f1ac6dd14c9bf0 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 23 Jun 2016 14:29:16 +0200 Subject: [PATCH 01/12] Gas limit ceiling option. --- ethcore/src/basic_authority.rs | 2 +- ethcore/src/block.rs | 6 +++--- ethcore/src/client/client.rs | 4 ++-- ethcore/src/client/mod.rs | 2 +- ethcore/src/client/test_client.rs | 2 +- ethcore/src/engine.rs | 2 +- ethcore/src/ethereum/ethash.rs | 12 +++++++---- ethcore/src/miner/miner.rs | 25 +++++++++++++++-------- ethcore/src/miner/mod.rs | 11 ++++++++-- parity/cli.rs | 3 +++ parity/configuration.rs | 11 +++++++++- parity/main.rs | 1 + rpc/src/v1/impls/ethcore.rs | 4 ++++ rpc/src/v1/impls/ethcore_set.rs | 11 ++++++++-- rpc/src/v1/tests/helpers/miner_service.rs | 19 ++++++++++++----- rpc/src/v1/traits/ethcore.rs | 4 ++++ rpc/src/v1/traits/ethcore_set.rs | 4 ++++ 17 files changed, 92 insertions(+), 31 deletions(-) diff --git a/ethcore/src/basic_authority.rs b/ethcore/src/basic_authority.rs index bac3ea5ac..40898e509 100644 --- a/ethcore/src/basic_authority.rs +++ b/ethcore/src/basic_authority.rs @@ -80,7 +80,7 @@ impl Engine for BasicAuthority { Schedule::new_homestead() } - fn populate_from_parent(&self, header: &mut Header, parent: &Header, gas_floor_target: U256) { + fn populate_from_parent(&self, header: &mut Header, parent: &Header, gas_floor_target: U256, _gas_ceil_target: U256) { header.difficulty = parent.difficulty; header.gas_limit = { let gas_limit = parent.gas_limit; diff --git a/ethcore/src/block.rs b/ethcore/src/block.rs index f7288c85b..989a3075b 100644 --- a/ethcore/src/block.rs +++ b/ethcore/src/block.rs @@ -222,7 +222,7 @@ impl<'x> OpenBlock<'x> { last_hashes: LastHashes, dao_rescue_block_gas_limit: Option, author: Address, - gas_floor_target: U256, + gas_range_target: (U256, U256), extra_data: Bytes, ) -> Result { let state = try!(State::from_existing(db, parent.state_root().clone(), engine.account_start_nonce())); @@ -241,7 +241,7 @@ impl<'x> OpenBlock<'x> { r.block.base.header.extra_data = extra_data; r.block.base.header.note_dirty(); - engine.populate_from_parent(&mut r.block.base.header, parent, gas_floor_target); + engine.populate_from_parent(&mut r.block.base.header, parent, gas_range_target.0, gas_range_target.1); engine.on_new_block(&mut r.block); Ok(r) } @@ -480,7 +480,7 @@ pub fn enact( } } - let mut b = try!(OpenBlock::new(engine, vm_factory, tracing, db, parent, last_hashes, dao_rescue_block_gas_limit, header.author().clone(), 3141562.into(), header.extra_data().clone())); + let mut b = try!(OpenBlock::new(engine, vm_factory, tracing, db, parent, last_hashes, dao_rescue_block_gas_limit, header.author().clone(), (3141562.into(), 31415620.into()), header.extra_data().clone())); b.set_difficulty(*header.difficulty()); b.set_gas_limit(*header.gas_limit()); b.set_timestamp(header.timestamp()); diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 693296469..4ccfb7360 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -797,7 +797,7 @@ impl BlockChainClient for Client where V: Verifier { } impl MiningBlockChainClient for Client where V: Verifier { - fn prepare_open_block(&self, author: Address, gas_floor_target: U256, extra_data: Bytes) -> OpenBlock { + fn prepare_open_block(&self, author: Address, gas_range_target: (U256, U256), extra_data: Bytes) -> OpenBlock { let engine = self.engine.deref().deref(); let h = self.chain.best_block_hash(); @@ -810,7 +810,7 @@ impl MiningBlockChainClient for Client where V: Verifier { self.build_last_hashes(h.clone()), self.dao_rescue_block_gas_limit(h.clone()), author, - gas_floor_target, + gas_range_target, extra_data, ).expect("OpenBlock::new only fails if parent state root invalid; state root of best block's header is never invalid; qed"); diff --git a/ethcore/src/client/mod.rs b/ethcore/src/client/mod.rs index 86686cb4c..433881e9a 100644 --- a/ethcore/src/client/mod.rs +++ b/ethcore/src/client/mod.rs @@ -251,6 +251,6 @@ pub trait BlockChainClient : Sync + Send { /// Extended client interface used for mining pub trait MiningBlockChainClient : BlockChainClient { /// Returns OpenBlock prepared for closing. - fn prepare_open_block(&self, author: Address, gas_floor_target: U256, extra_data: Bytes) + fn prepare_open_block(&self, author: Address, gas_range_target: (U256, U256), extra_data: Bytes) -> OpenBlock; } diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 29f91a1d6..621f880c5 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -240,7 +240,7 @@ impl TestBlockChainClient { } impl MiningBlockChainClient for TestBlockChainClient { - fn prepare_open_block(&self, _author: Address, _gas_floor_target: U256, _extra_data: Bytes) -> OpenBlock { + fn prepare_open_block(&self, _author: Address, _gas_range_target: (U256, U256), _extra_data: Bytes) -> OpenBlock { unimplemented!(); } } diff --git a/ethcore/src/engine.rs b/ethcore/src/engine.rs index 98ebac40e..e78f84c13 100644 --- a/ethcore/src/engine.rs +++ b/ethcore/src/engine.rs @@ -96,7 +96,7 @@ pub trait Engine : Sync + Send { /// Don't forget to call Super::populate_from_parent when subclassing & overriding. // TODO: consider including State in the params. - fn populate_from_parent(&self, header: &mut Header, parent: &Header, _gas_floor_target: U256) { + fn populate_from_parent(&self, header: &mut Header, parent: &Header, _gas_floor_target: U256, _gas_ceil_target: U256) { header.difficulty = parent.difficulty; header.gas_limit = parent.gas_limit; header.note_dirty(); diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 0e90e3867..34918993a 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -112,15 +112,20 @@ impl Engine for Ethash { } } - fn populate_from_parent(&self, header: &mut Header, parent: &Header, gas_floor_target: U256) { + fn populate_from_parent(&self, header: &mut Header, parent: &Header, gas_floor_target: U256, gas_ceil_target: U256) { header.difficulty = self.calculate_difficuty(header, parent); header.gas_limit = { let gas_limit = parent.gas_limit; let bound_divisor = self.ethash_params.gas_limit_bound_divisor; if gas_limit < gas_floor_target { min(gas_floor_target, gas_limit + gas_limit / bound_divisor - 1.into()) + } else if gas_limit > gas_ceil_target { + max(gas_ceil_target, gas_limit - gas_limit / bound_divisor + 1.into()) } else { - max(gas_floor_target, gas_limit - gas_limit / bound_divisor + 1.into() + (header.gas_used * 6.into() / 5.into()) / bound_divisor) + max(gas_ceil_target, + max(gas_floor_target, + gas_limit - gas_limit / bound_divisor + 1.into() + + (header.gas_used * 6.into() / 5.into()) / bound_divisor)) } }; header.note_dirty(); @@ -237,8 +242,7 @@ impl Ethash { let mut target = if header.number < frontier_limit { if header.timestamp >= parent.timestamp + duration_limit { parent.difficulty - (parent.difficulty / difficulty_bound_divisor) - } - else { + } else { parent.difficulty + (parent.difficulty / difficulty_bound_divisor) } } diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 290e94059..709a32482 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -39,7 +39,7 @@ pub struct Miner { force_sealing: bool, sealing_enabled: AtomicBool, sealing_block_last_request: Mutex, - gas_floor_target: RwLock, + gas_range_target: RwLock<(U256, U256)>, author: RwLock
, extra_data: RwLock, spec: Spec, @@ -55,7 +55,7 @@ impl Default for Miner { sealing_enabled: AtomicBool::new(false), sealing_block_last_request: Mutex::new(0), sealing_work: Mutex::new(UsingQueue::new(5)), - gas_floor_target: RwLock::new(U256::zero()), + gas_range_target: RwLock::new((U256::zero(), U256::zero())), author: RwLock::new(Address::default()), extra_data: RwLock::new(Vec::new()), accounts: None, @@ -73,7 +73,7 @@ impl Miner { sealing_enabled: AtomicBool::new(force_sealing), sealing_block_last_request: Mutex::new(0), sealing_work: Mutex::new(UsingQueue::new(5)), - gas_floor_target: RwLock::new(U256::zero()), + gas_range_target: RwLock::new((U256::zero(), U256::zero())), author: RwLock::new(Address::default()), extra_data: RwLock::new(Vec::new()), accounts: None, @@ -89,7 +89,7 @@ impl Miner { sealing_enabled: AtomicBool::new(force_sealing), sealing_block_last_request: Mutex::new(0), sealing_work: Mutex::new(UsingQueue::new(5)), - gas_floor_target: RwLock::new(U256::zero()), + gas_range_target: RwLock::new((U256::zero(), U256::zero())), author: RwLock::new(Address::default()), extra_data: RwLock::new(Vec::new()), accounts: Some(accounts), @@ -131,7 +131,7 @@ impl Miner { trace!(target: "miner", "No existing work - making new block"); chain.prepare_open_block( self.author(), - self.gas_floor_target(), + (self.gas_floor_target(), self.gas_ceil_target()), self.extra_data() ) } @@ -341,7 +341,11 @@ impl MinerService for Miner { /// Set the gas limit we wish to target when sealing a new block. fn set_gas_floor_target(&self, target: U256) { - *self.gas_floor_target.write().unwrap() = target; + self.gas_range_target.write().unwrap().0 = target; + } + + fn set_gas_ceil_target(&self, target: U256) { + self.gas_range_target.write().unwrap().1 = target; } fn set_minimal_gas_price(&self, min_gas_price: U256) { @@ -358,7 +362,7 @@ impl MinerService for Miner { } fn sensible_gas_limit(&self) -> U256 { - *self.gas_floor_target.read().unwrap() / 5.into() + self.gas_range_target.read().unwrap().0 / 5.into() } fn transactions_limit(&self) -> usize { @@ -381,7 +385,12 @@ impl MinerService for Miner { /// Get the gas limit we wish to target when sealing a new block. fn gas_floor_target(&self) -> U256 { - *self.gas_floor_target.read().unwrap() + self.gas_range_target.read().unwrap().0 + } + + /// Get the gas limit we wish to target when sealing a new block. + fn gas_ceil_target(&self) -> U256 { + self.gas_range_target.read().unwrap().1 } fn import_transactions(&self, chain: &MiningBlockChainClient, transactions: Vec, fetch_account: T) -> diff --git a/ethcore/src/miner/mod.rs b/ethcore/src/miner/mod.rs index 697f7513f..b28dcbe8d 100644 --- a/ethcore/src/miner/mod.rs +++ b/ethcore/src/miner/mod.rs @@ -81,12 +81,19 @@ pub trait MinerService : Send + Sync { /// Set minimal gas price of transaction to be accepted for mining. fn set_minimal_gas_price(&self, min_gas_price: U256); - /// Get the gas limit we wish to target when sealing a new block. + /// Get the lower bound of the gas limit we wish to target when sealing a new block. fn gas_floor_target(&self) -> U256; - /// Set the gas limit we wish to target when sealing a new block. + /// Get the upper bound of the gas limit we wish to target when sealing a new block. + fn gas_ceil_target(&self) -> U256; + + // TODO: coalesce into single set_range function. + /// Set the lower bound of gas limit we wish to target when sealing a new block. fn set_gas_floor_target(&self, target: U256); + /// Set the upper bound of gas limit we wish to target when sealing a new block. + fn set_gas_ceil_target(&self, target: U256); + /// Get current transactions limit in queue. fn transactions_limit(&self) -> usize; diff --git a/parity/cli.rs b/parity/cli.rs index 7fd8d6482..9e9671c69 100644 --- a/parity/cli.rs +++ b/parity/cli.rs @@ -137,6 +137,8 @@ Sealing/Mining Options: good value [default: auto]. --gas-floor-target GAS Amount of gas per block to target when sealing a new block [default: 3141592]. + --gas-cap GAS A cap on how large we will raise the gas limit per + block due to transaction volume [default: 3141592]. --author ADDRESS Specify the block author (aka "coinbase") address for sending block rewards from sealed blocks [default: 0037a6b811ffeb6e072da21179d11b1406371c63]. @@ -283,6 +285,7 @@ pub struct Args { pub flag_usd_per_tx: String, pub flag_usd_per_eth: String, pub flag_gas_floor_target: String, + pub flag_gas_cap: String, pub flag_extra_data: Option, pub flag_tx_limit: usize, pub flag_logging: Option, diff --git a/parity/configuration.rs b/parity/configuration.rs index 4196564b5..3800e3dc8 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -85,7 +85,16 @@ impl Configuration { } } - + pub fn gas_ceil_target(&self) -> U256 { + if self.args.flag_dont_help_rescue_dao || self.args.flag_dogmatic { + 10_000_000.into() + } else { + let d = &self.args.flag_gas_cap; + U256::from_dec_str(d).unwrap_or_else(|_| { + die!("{}: Invalid target gas ceiling given. Must be a decimal unsigned 256-bit number.", d) + }) + } + } pub fn gas_price(&self) -> U256 { match self.args.flag_gasprice.as_ref() { diff --git a/parity/main.rs b/parity/main.rs index 0b64d0644..1fd77caa7 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -211,6 +211,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig) let miner = Miner::with_accounts(conf.args.flag_force_sealing, conf.spec(), account_service.clone()); miner.set_author(conf.author()); miner.set_gas_floor_target(conf.gas_floor_target()); + miner.set_gas_ceil_target(conf.gas_ceil_target()); miner.set_extra_data(conf.extra_data()); miner.set_minimal_gas_price(conf.gas_price()); miner.set_transactions_limit(conf.args.flag_tx_limit); diff --git a/rpc/src/v1/impls/ethcore.rs b/rpc/src/v1/impls/ethcore.rs index 3a8b8a4a0..3a58d8672 100644 --- a/rpc/src/v1/impls/ethcore.rs +++ b/rpc/src/v1/impls/ethcore.rs @@ -72,6 +72,10 @@ impl Ethcore for EthcoreClient where M: MinerService + 'static, C: M to_value(&take_weak!(self.miner).gas_floor_target()) } + fn gas_ceil_target(&self, _: Params) -> Result { + to_value(&take_weak!(self.miner).gas_ceil_target()) + } + fn dev_logs(&self, _params: Params) -> Result { let logs = self.logger.logs(); to_value(&logs.deref().as_slice()) diff --git a/rpc/src/v1/impls/ethcore_set.rs b/rpc/src/v1/impls/ethcore_set.rs index 66f1a34aa..55164217c 100644 --- a/rpc/src/v1/impls/ethcore_set.rs +++ b/rpc/src/v1/impls/ethcore_set.rs @@ -52,8 +52,15 @@ impl EthcoreSet for EthcoreSetClient where M: MinerService + 'static { } fn set_gas_floor_target(&self, params: Params) -> Result { - from_params::<(U256,)>(params).and_then(|(gas_floor_target,)| { - take_weak!(self.miner).set_gas_floor_target(gas_floor_target); + from_params::<(U256,)>(params).and_then(|(target,)| { + take_weak!(self.miner).set_gas_floor_target(target); + to_value(&true) + }) + } + + fn set_gas_ceil_target(&self, params: Params) -> Result { + from_params::<(U256,)>(params).and_then(|(target,)| { + take_weak!(self.miner).set_gas_ceil_target(target); to_value(&true) }) } diff --git a/rpc/src/v1/tests/helpers/miner_service.rs b/rpc/src/v1/tests/helpers/miner_service.rs index 7ec7fc1cc..b87b650e1 100644 --- a/rpc/src/v1/tests/helpers/miner_service.rs +++ b/rpc/src/v1/tests/helpers/miner_service.rs @@ -39,7 +39,7 @@ pub struct TestMinerService { pub last_nonces: RwLock>, min_gas_price: RwLock, - gas_floor_target: RwLock, + gas_range_target: RwLock<(U256, U256)>, author: RwLock
, extra_data: RwLock, limit: RwLock, @@ -54,7 +54,7 @@ impl Default for TestMinerService { pending_receipts: Mutex::new(BTreeMap::new()), last_nonces: RwLock::new(HashMap::new()), min_gas_price: RwLock::new(U256::from(20_000_000)), - gas_floor_target: RwLock::new(U256::from(12345)), + gas_range_target: RwLock::new((U256::from(12345), U256::from(54321))), author: RwLock::new(Address::zero()), extra_data: RwLock::new(vec![1, 2, 3, 4]), limit: RwLock::new(1024), @@ -81,9 +81,14 @@ impl MinerService for TestMinerService { *self.extra_data.write().unwrap() = extra_data; } - /// Set the gas limit we wish to target when sealing a new block. + /// Set the lower gas limit we wish to target when sealing a new block. fn set_gas_floor_target(&self, target: U256) { - *self.gas_floor_target.write().unwrap() = target; + self.gas_range_target.write().unwrap().0 = target; + } + + /// Set the upper gas limit we wish to target when sealing a new block. + fn set_gas_ceil_target(&self, target: U256) { + self.gas_range_target.write().unwrap().1 = target; } fn set_minimal_gas_price(&self, min_gas_price: U256) { @@ -111,7 +116,11 @@ impl MinerService for TestMinerService { } fn gas_floor_target(&self) -> U256 { - *self.gas_floor_target.read().unwrap() + self.gas_range_target.read().unwrap().0 + } + + fn gas_ceil_target(&self) -> U256 { + self.gas_range_target.read().unwrap().1 } /// Imports transactions to transaction queue. diff --git a/rpc/src/v1/traits/ethcore.rs b/rpc/src/v1/traits/ethcore.rs index 32855727f..a5032d3e2 100644 --- a/rpc/src/v1/traits/ethcore.rs +++ b/rpc/src/v1/traits/ethcore.rs @@ -30,6 +30,9 @@ pub trait Ethcore: Sized + Send + Sync + 'static { /// Returns mining gas floor target. fn gas_floor_target(&self, _: Params) -> Result; + /// Returns mining gas floor cap. + fn gas_ceil_target(&self, _: Params) -> Result; + /// Returns minimal gas price for transaction to be included in queue. fn min_gas_price(&self, _: Params) -> Result; @@ -70,6 +73,7 @@ pub trait Ethcore: Sized + Send + Sync + 'static { delegate.add_method("ethcore_extraData", Ethcore::extra_data); delegate.add_method("ethcore_gasFloorTarget", Ethcore::gas_floor_target); + delegate.add_method("ethcore_gasCeilTarget", Ethcore::gas_ceil_target); delegate.add_method("ethcore_minGasPrice", Ethcore::min_gas_price); delegate.add_method("ethcore_transactionsLimit", Ethcore::transactions_limit); delegate.add_method("ethcore_devLogs", Ethcore::dev_logs); diff --git a/rpc/src/v1/traits/ethcore_set.rs b/rpc/src/v1/traits/ethcore_set.rs index ed4303be1..d00295036 100644 --- a/rpc/src/v1/traits/ethcore_set.rs +++ b/rpc/src/v1/traits/ethcore_set.rs @@ -28,6 +28,9 @@ pub trait EthcoreSet: Sized + Send + Sync + 'static { /// Sets new gas floor target for mined blocks. fn set_gas_floor_target(&self, _: Params) -> Result; + /// Sets new gas ceiling target for mined blocks. + fn set_gas_ceil_target(&self, _: Params) -> Result; + /// Sets new extra data for mined blocks. fn set_extra_data(&self, _: Params) -> Result; @@ -54,6 +57,7 @@ pub trait EthcoreSet: Sized + Send + Sync + 'static { let mut delegate = IoDelegate::new(Arc::new(self)); delegate.add_method("ethcore_setMinGasPrice", EthcoreSet::set_min_gas_price); delegate.add_method("ethcore_setGasFloorTarget", EthcoreSet::set_gas_floor_target); + delegate.add_method("ethcore_setGasCeilTarget", EthcoreSet::set_gas_ceil_target); delegate.add_method("ethcore_setExtraData", EthcoreSet::set_extra_data); delegate.add_method("ethcore_setAuthor", EthcoreSet::set_author); delegate.add_method("ethcore_setTransactionsLimit", EthcoreSet::set_transactions_limit); From 41e0769e63348e2c0acf385481974878803bae54 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 23 Jun 2016 14:43:20 +0200 Subject: [PATCH 02/12] Fix tests, --- ethcore/src/basic_authority.rs | 2 +- ethcore/src/block.rs | 6 +++--- ethcore/src/ethereum/ethash.rs | 4 ++-- ethcore/src/tests/client.rs | 2 +- ethcore/src/tests/helpers.rs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ethcore/src/basic_authority.rs b/ethcore/src/basic_authority.rs index 40898e509..4426d3059 100644 --- a/ethcore/src/basic_authority.rs +++ b/ethcore/src/basic_authority.rs @@ -254,7 +254,7 @@ mod tests { spec.ensure_db_good(db.as_hashdb_mut()); let last_hashes = vec![genesis_header.hash()]; let vm_factory = Default::default(); - let b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, last_hashes, None, addr, 3141562.into(), vec![]).unwrap(); + let b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, last_hashes, None, addr, (3141562.into(), 31415620.into()), vec![]).unwrap(); let b = b.close_and_lock(); let seal = engine.generate_seal(b.block(), Some(&tap)).unwrap(); assert!(b.try_seal(engine.deref(), seal).is_ok()); diff --git a/ethcore/src/block.rs b/ethcore/src/block.rs index 989a3075b..9c522baed 100644 --- a/ethcore/src/block.rs +++ b/ethcore/src/block.rs @@ -552,7 +552,7 @@ mod tests { spec.ensure_db_good(db.as_hashdb_mut()); let last_hashes = vec![genesis_header.hash()]; let vm_factory = Default::default(); - let b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, last_hashes, None, Address::zero(), 3141562.into(), vec![]).unwrap(); + let b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, last_hashes, None, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); let b = b.close_and_lock(); let _ = b.seal(engine.deref(), vec![]); } @@ -568,7 +568,7 @@ mod tests { let mut db = db_result.take(); spec.ensure_db_good(db.as_hashdb_mut()); let vm_factory = Default::default(); - let b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, vec![genesis_header.hash()], None, Address::zero(), 3141562.into(), vec![]).unwrap() + let b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, vec![genesis_header.hash()], None, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap() .close_and_lock().seal(engine.deref(), vec![]).unwrap(); let orig_bytes = b.rlp_bytes(); let orig_db = b.drain(); @@ -596,7 +596,7 @@ mod tests { let mut db = db_result.take(); spec.ensure_db_good(db.as_hashdb_mut()); let vm_factory = Default::default(); - let mut open_block = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, vec![genesis_header.hash()], None, Address::zero(), 3141562.into(), vec![]).unwrap(); + let mut open_block = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, vec![genesis_header.hash()], None, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); let mut uncle1_header = Header::new(); uncle1_header.extra_data = b"uncle1".to_vec(); let mut uncle2_header = Header::new(); diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 34918993a..83a2fc9bc 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -327,7 +327,7 @@ mod tests { spec.ensure_db_good(db.as_hashdb_mut()); let last_hashes = vec![genesis_header.hash()]; let vm_factory = Default::default(); - let b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, last_hashes, None, Address::zero(), 3141562.into(), vec![]).unwrap(); + let b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, last_hashes, None, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); let b = b.close(); assert_eq!(b.state().balance(&Address::zero()), U256::from_str("4563918244f40000").unwrap()); } @@ -342,7 +342,7 @@ mod tests { spec.ensure_db_good(db.as_hashdb_mut()); let last_hashes = vec![genesis_header.hash()]; let vm_factory = Default::default(); - let mut b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, last_hashes, None, Address::zero(), 3141562.into(), vec![]).unwrap(); + let mut b = OpenBlock::new(engine.deref(), &vm_factory, false, db, &genesis_header, last_hashes, None, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); let mut uncle = Header::new(); let uncle_author = address_from_hex("ef2d6d194084c2de36e0dabfce45d046b37d1106"); uncle.author = uncle_author.clone(); diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index f2ab62840..79ffa7147 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -150,7 +150,7 @@ fn can_mine() { let client_result = get_test_client_with_blocks(vec![dummy_blocks[0].clone()]); let client = client_result.reference(); - let b = client.prepare_open_block(Address::default(), 31415926.into(), vec![]).close(); + let b = client.prepare_open_block(Address::default(), (3141562.into(), 31415620.into()), vec![]).close(); assert_eq!(*b.block().header().parent_hash(), BlockView::new(&dummy_blocks[0]).header_view().sha3()); } diff --git a/ethcore/src/tests/helpers.rs b/ethcore/src/tests/helpers.rs index ce204f647..ab538922c 100644 --- a/ethcore/src/tests/helpers.rs +++ b/ethcore/src/tests/helpers.rs @@ -181,7 +181,7 @@ pub fn generate_dummy_client_with_spec_and_data(get_test_spec: F, block_numbe last_hashes.clone(), None, author.clone(), - 3141562.into(), + (3141562.into(), 31415620.into()), vec![] ).unwrap(); b.set_difficulty(U256::from(0x20000)); From e77cce66a1f49851eff42f8b1299667c8ffb4ffc Mon Sep 17 00:00:00 2001 From: arkpar Date: Thu, 23 Jun 2016 22:40:44 +0200 Subject: [PATCH 03/12] Update highest block progress --- sync/src/chain.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 33b04eca0..5d0976aac 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -534,6 +534,9 @@ impl ChainSync { let h = header_rlp.as_raw().sha3(); trace!(target: "sync", "{} -> NewBlock ({})", peer_id, h); let header: BlockHeader = try!(header_rlp.as_val()); + if header.number() > self.highest_block.unwrap_or(0) { + self.highest_block = Some(header.number()); + } let mut unknown = false; { let peer = self.peers.get_mut(&peer_id).unwrap(); @@ -587,6 +590,10 @@ impl ChainSync { fn on_peer_new_hashes(&mut self, io: &mut SyncIo, peer_id: PeerId, r: &UntrustedRlp) -> Result<(), PacketDecodeError> { if self.state != SyncState::Idle { trace!(target: "sync", "Ignoring new hashes since we're already downloading."); + let max = r.iter().take(MAX_NEW_HASHES).map(|item| item.val_at::(1).unwrap_or(0)).fold(0u64, max); + if max > self.highest_block.unwrap_or(0) { + self.highest_block = Some(max); + } return Ok(()); } trace!(target: "sync", "{} -> NewHashes ({} entries)", peer_id, r.item_count()); @@ -596,6 +603,9 @@ impl ChainSync { for (rh, rd) in hashes { let h = try!(rh); let d = try!(rd); + if d > self.highest_block.unwrap_or(0) { + self.highest_block = Some(d); + } if self.blocks.is_downloading(&h) { continue; } From e3e10335f92aec9043a9ebe422de2bb75f815eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 24 Jun 2016 11:26:04 +0200 Subject: [PATCH 04/12] Bumping TopBar, Minimal SignerUI and wallet --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f735f0e54..a4c9c4171 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -936,7 +936,7 @@ dependencies = [ [[package]] name = "parity-dapps-builtins" version = "0.5.1" -source = "git+https://github.com/ethcore/parity-dapps-builtins-rs.git#650b0d94d076635904b86c1fd45c5f4a2061463f" +source = "git+https://github.com/ethcore/parity-dapps-builtins-rs.git#7408838e8ca3b57c6b0cf5da2e31e0e275959955" dependencies = [ "parity-dapps 0.3.0 (git+https://github.com/ethcore/parity-dapps-rs.git)", ] @@ -952,7 +952,7 @@ dependencies = [ [[package]] name = "parity-dapps-wallet" version = "0.6.1" -source = "git+https://github.com/ethcore/parity-dapps-wallet-rs.git#8923d4c73359c75ce04f0639bbcde46adb846b81" +source = "git+https://github.com/ethcore/parity-dapps-wallet-rs.git#867994fe25038f000f1cc09cd024a83700a03930" dependencies = [ "parity-dapps 0.3.0 (git+https://github.com/ethcore/parity-dapps-rs.git)", ] @@ -960,7 +960,7 @@ dependencies = [ [[package]] name = "parity-minimal-sysui" version = "0.1.0" -source = "git+https://github.com/ethcore/parity-dapps-minimal-sysui-rs.git#3c6ad40680126a760eb867b07b506ea996819ce3" +source = "git+https://github.com/ethcore/parity-dapps-minimal-sysui-rs.git#cc5ea4bd786982f0509a8d3d5deb4217c659af85" [[package]] name = "phf" From 84ce5af2b0bc4d1247c947690ef6bd4fbbeafd6a Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 24 Jun 2016 11:40:25 +0200 Subject: [PATCH 05/12] max/min incorrect --- ethcore/src/ethereum/ethash.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index dc8dd5482..3400220db 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -122,7 +122,7 @@ impl Engine for Ethash { } else if gas_limit > gas_ceil_target { max(gas_ceil_target, gas_limit - gas_limit / bound_divisor + 1.into()) } else { - max(gas_ceil_target, + min(gas_ceil_target, max(gas_floor_target, gas_limit - gas_limit / bound_divisor + 1.into() + (header.gas_used * 6.into() / 5.into()) / bound_divisor)) From 23732fa5167f82d82d001671e271cf206ed68a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 24 Jun 2016 12:10:36 +0200 Subject: [PATCH 06/12] Fixing interface and port for parity ui --- parity/configuration.rs | 16 ++++++++++++++++ parity/dapps.rs | 7 +------ parity/main.rs | 9 ++++++--- parity/rpc.rs | 7 +------ 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/parity/configuration.rs b/parity/configuration.rs index 4560324d3..4d201ffa8 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -438,6 +438,22 @@ impl Configuration { Some(self.args.flag_signer_port) } } + + pub fn rpc_interface(&self) -> String { + match self.network_settings().rpc_interface.as_str() { + "all" => "0.0.0.0", + "local" => "127.0.0.1", + x => x, + }.into() + } + + pub fn dapps_interface(&self) -> String { + match self.args.flag_dapps_interface.as_str() { + "all" => "0.0.0.0", + "local" => "127.0.0.1", + x => x, + }.into() + } } #[cfg(test)] diff --git a/parity/dapps.rs b/parity/dapps.rs index 59a9ee552..917c59fc6 100644 --- a/parity/dapps.rs +++ b/parity/dapps.rs @@ -45,12 +45,7 @@ pub fn new(configuration: Configuration, deps: Dependencies) -> Option "0.0.0.0", - "local" => "127.0.0.1", - x => x, - }; - let url = format!("{}:{}", interface, configuration.port); + let url = format!("{}:{}", configuration.interface, configuration.port); let addr = SocketAddr::from_str(&url).unwrap_or_else(|_| die!("{}: Invalid Webapps listen host/port given.", url)); let auth = configuration.user.as_ref().map(|username| { diff --git a/parity/main.rs b/parity/main.rs index 8beba61b5..de1d81b0b 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -252,7 +252,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig) // Setup http rpc let rpc_server = rpc::new_http(rpc::HttpConfiguration { enabled: network_settings.rpc_enabled, - interface: network_settings.rpc_interface.clone(), + interface: conf.rpc_interface(), port: network_settings.rpc_port, apis: conf.rpc_apis(), cors: conf.rpc_cors(), @@ -265,7 +265,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig) if conf.args.flag_webapp { println!("WARNING: Flag -w/--webapp is deprecated. Dapps server is now on by default. Ignoring."); } let dapps_server = dapps::new(dapps::Configuration { enabled: !conf.args.flag_dapps_off && !conf.args.flag_no_dapps, - interface: conf.args.flag_dapps_interface.clone(), + interface: conf.dapps_interface(), port: conf.args.flag_dapps_port, user: conf.args.flag_dapps_user.clone(), pass: conf.args.flag_dapps_pass.clone(), @@ -296,7 +296,10 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig) service.register_io_handler(io_handler).expect("Error registering IO handler"); if conf.args.cmd_ui { - url::open("http://localhost:8080/") + if conf.args.flag_dapps_off { + die_with_message("Cannot use UI command with Dapps turned off."); + } + url::open(&format!("http://{}:{}/", conf.dapps_interface(), conf.args.flag_dapps_port)); } // Handle exit diff --git a/parity/rpc.rs b/parity/rpc.rs index c10635889..df1e14524 100644 --- a/parity/rpc.rs +++ b/parity/rpc.rs @@ -66,13 +66,8 @@ pub fn new_http(conf: HttpConfiguration, deps: &Dependencies) -> Option "0.0.0.0", - "local" => "127.0.0.1", - x => x, - }; let apis = conf.apis.split(',').collect(); - let url = format!("{}:{}", interface, conf.port); + let url = format!("{}:{}", conf.interface, conf.port); let addr = SocketAddr::from_str(&url).unwrap_or_else(|_| die!("{}: Invalid JSONRPC listen host/port given.", url)); Some(setup_http_rpc_server(deps, &addr, conf.cors, apis)) From 566bb030ec48ef2ee7f1e3281fd3340df81b41b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 24 Jun 2016 12:14:46 +0200 Subject: [PATCH 07/12] Fixing detecting if dapps are off --- parity/configuration.rs | 4 ++++ parity/main.rs | 4 ++-- parity/url.rs | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/parity/configuration.rs b/parity/configuration.rs index 4d201ffa8..e27ad3f2a 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -454,6 +454,10 @@ impl Configuration { x => x, }.into() } + + pub fn dapps_enabled(&self) -> bool { + !self.args.flag_dapps_off && !self.args.flag_no_dapps + } } #[cfg(test)] diff --git a/parity/main.rs b/parity/main.rs index de1d81b0b..26f7b45ac 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -264,7 +264,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig) if conf.args.flag_webapp { println!("WARNING: Flag -w/--webapp is deprecated. Dapps server is now on by default. Ignoring."); } let dapps_server = dapps::new(dapps::Configuration { - enabled: !conf.args.flag_dapps_off && !conf.args.flag_no_dapps, + enabled: conf.dapps_enabled(), interface: conf.dapps_interface(), port: conf.args.flag_dapps_port, user: conf.args.flag_dapps_user.clone(), @@ -296,7 +296,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig) service.register_io_handler(io_handler).expect("Error registering IO handler"); if conf.args.cmd_ui { - if conf.args.flag_dapps_off { + if !conf.dapps_enabled() { die_with_message("Cannot use UI command with Dapps turned off."); } url::open(&format!("http://{}:{}/", conf.dapps_interface(), conf.args.flag_dapps_port)); diff --git a/parity/url.rs b/parity/url.rs index 8ab6a2eda..4ba866241 100644 --- a/parity/url.rs +++ b/parity/url.rs @@ -55,5 +55,5 @@ pub fn open(url: &str) { #[cfg(target_os="linux")] pub fn open(url: &str) { use std; - let _ = std::process::Command::new("xdg-open").arg(url).output(); + let _ = std::process::Command::new("xdg-open").arg(url).spawn(); } From 653a36878392399c84017a003b95ce278d833a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 24 Jun 2016 12:30:54 +0200 Subject: [PATCH 08/12] Changing macos impl --- parity/url.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parity/url.rs b/parity/url.rs index 4ba866241..129812387 100644 --- a/parity/url.rs +++ b/parity/url.rs @@ -49,7 +49,7 @@ pub fn open(url: &str) { #[cfg(target_os="macos")] pub fn open(url: &str) { use std; - let _ = std::process::Command::new("open").arg(url).output(); + let _ = std::process::Command::new("open").arg(url).spawn(); } #[cfg(target_os="linux")] From 44d6e1f443e0d55c181d66f18dbaa58298c14919 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 24 Jun 2016 13:32:43 +0200 Subject: [PATCH 09/12] Remove experimental pruning options. --- parity/cli.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/parity/cli.rs b/parity/cli.rs index cc68a8d4d..a612d0877 100644 --- a/parity/cli.rs +++ b/parity/cli.rs @@ -155,10 +155,6 @@ Footprint Options: may be one of auto, archive, fast, basic, light: archive - keep all state trie data. No pruning. fast - maintain journal overlay. Fast but 50MB used. - basic - reference count in disk DB. Slow, light, and - experimental! - light - early merges with partial tracking. Fast, - light, and experimental! auto - use the method most recently synced or default to fast if none synced [default: auto]. --cache-pref-size BYTES Specify the prefered size of the blockchain cache in From 568dc907693f92c14df4f10db41d30edb338d96a Mon Sep 17 00:00:00 2001 From: arkpar Date: Fri, 24 Jun 2016 14:20:39 +0200 Subject: [PATCH 10/12] Signer enabled by default for UI --- parity/cli.rs | 5 ++++- parity/configuration.rs | 5 +++++ parity/main.rs | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/parity/cli.rs b/parity/cli.rs index 8a4e050af..0133ca0fb 100644 --- a/parity/cli.rs +++ b/parity/cli.rs @@ -117,7 +117,9 @@ API and Console Options: [default: $HOME/.parity/dapps] --signer Enable Trusted Signer WebSocket endpoint used by - Signer UIs. + Signer UIs. Default if no command is specified. + --no-signer Disable Trusted Signer WebSocket endpoint used by + Signer UIs. Default if run with ui command. --signer-port PORT Specify the port of Trusted Signer server [default: 8180]. --signer-path PATH Specify directory where Signer UIs tokens should @@ -280,6 +282,7 @@ pub struct Args { pub flag_dapps_pass: Option, pub flag_dapps_path: String, pub flag_signer: bool, + pub flag_no_signer: bool, pub flag_signer_port: u16, pub flag_signer_path: String, pub flag_no_token: bool, diff --git a/parity/configuration.rs b/parity/configuration.rs index f0cbebdb4..925d2041c 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -467,6 +467,11 @@ impl Configuration { pub fn dapps_enabled(&self) -> bool { !self.args.flag_dapps_off && !self.args.flag_no_dapps } + + pub fn signer_enabled(&self) -> bool { + (self.args.cmd_ui && !self.args.flag_no_signer) || + (!self.args.cmd_ui && self.args.flag_signer) + } } #[cfg(test)] diff --git a/parity/main.rs b/parity/main.rs index fd7e8a437..84f144396 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -192,14 +192,14 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig) let sync_config = conf.sync_config(&spec); // Create and display a new token for UIs. - if conf.args.flag_signer && !conf.args.flag_no_token { + if conf.signer_enabled() && !conf.args.flag_no_token { new_token(conf.directories().signer).unwrap_or_else(|e| { die!("Error generating token: {:?}", e) }); } // Display warning about using unlock with signer - if conf.args.flag_signer && conf.args.flag_unlock.is_some() { + if conf.signer_enabled() && conf.args.flag_unlock.is_some() { warn!("Using Trusted Signer and --unlock is not recommended!"); warn!("NOTE that Signer will not ask you to confirm transactions from unlocked account."); } From 3e7edb2665363f482ab909b54c49219d5104a897 Mon Sep 17 00:00:00 2001 From: arkpar Date: Fri, 24 Jun 2016 14:29:15 +0200 Subject: [PATCH 11/12] More cases --- parity/cli.rs | 4 ++-- parity/configuration.rs | 2 +- parity/main.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/parity/cli.rs b/parity/cli.rs index 0133ca0fb..12ec8344f 100644 --- a/parity/cli.rs +++ b/parity/cli.rs @@ -117,9 +117,9 @@ API and Console Options: [default: $HOME/.parity/dapps] --signer Enable Trusted Signer WebSocket endpoint used by - Signer UIs. Default if no command is specified. - --no-signer Disable Trusted Signer WebSocket endpoint used by Signer UIs. Default if run with ui command. + --no-signer Disable Trusted Signer WebSocket endpoint used by + Signer UIs. Default if no command is specified. --signer-port PORT Specify the port of Trusted Signer server [default: 8180]. --signer-path PATH Specify directory where Signer UIs tokens should diff --git a/parity/configuration.rs b/parity/configuration.rs index 925d2041c..d92e50a41 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -441,7 +441,7 @@ impl Configuration { } pub fn signer_port(&self) -> Option { - if !self.args.flag_signer { + if !self.signer_enabled() { None } else { Some(self.args.flag_signer_port) diff --git a/parity/main.rs b/parity/main.rs index 84f144396..7d39143cb 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -278,7 +278,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig) // Set up a signer let signer_server = signer::start(signer::Configuration { - enabled: deps_for_rpc_apis.signer_port.is_some(), + enabled: conf.signer_enabled(), port: conf.args.flag_signer_port, signer_path: conf.directories().signer, }, signer::Dependencies { From bf11fb66334a07082e01a5bebe142416f0d29a21 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 24 Jun 2016 16:12:15 +0200 Subject: [PATCH 12/12] Fix up selection. --- parity/cli.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parity/cli.rs b/parity/cli.rs index a612d0877..98fb6eac0 100644 --- a/parity/cli.rs +++ b/parity/cli.rs @@ -152,7 +152,7 @@ Footprint Options: off. auto uses last used value of this option (off if it does not exist) [default: auto]. --pruning METHOD Configure pruning of the state/storage trie. METHOD - may be one of auto, archive, fast, basic, light: + may be one of auto, archive, fast: archive - keep all state trie data. No pruning. fast - maintain journal overlay. Fast but 50MB used. auto - use the method most recently synced or