Gas limit ceiling option.

This commit is contained in:
Gav Wood
2016-06-23 14:29:16 +02:00
parent 129ce97ad5
commit 8fcec20398
17 changed files with 92 additions and 31 deletions

View File

@@ -72,6 +72,10 @@ impl<C, M> Ethcore for EthcoreClient<C, M> where M: MinerService + 'static, C: M
to_value(&take_weak!(self.miner).gas_floor_target())
}
fn gas_ceil_target(&self, _: Params) -> Result<Value, Error> {
to_value(&take_weak!(self.miner).gas_ceil_target())
}
fn dev_logs(&self, _params: Params) -> Result<Value, Error> {
let logs = self.logger.logs();
to_value(&logs.deref().as_slice())

View File

@@ -52,8 +52,15 @@ impl<M> EthcoreSet for EthcoreSetClient<M> where M: MinerService + 'static {
}
fn set_gas_floor_target(&self, params: Params) -> Result<Value, Error> {
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<Value, Error> {
from_params::<(U256,)>(params).and_then(|(target,)| {
take_weak!(self.miner).set_gas_ceil_target(target);
to_value(&true)
})
}

View File

@@ -39,7 +39,7 @@ pub struct TestMinerService {
pub last_nonces: RwLock<HashMap<Address, U256>>,
min_gas_price: RwLock<U256>,
gas_floor_target: RwLock<U256>,
gas_range_target: RwLock<(U256, U256)>,
author: RwLock<Address>,
extra_data: RwLock<Bytes>,
limit: RwLock<usize>,
@@ -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.

View File

@@ -30,6 +30,9 @@ pub trait Ethcore: Sized + Send + Sync + 'static {
/// Returns mining gas floor target.
fn gas_floor_target(&self, _: Params) -> Result<Value, Error>;
/// Returns mining gas floor cap.
fn gas_ceil_target(&self, _: Params) -> Result<Value, Error>;
/// Returns minimal gas price for transaction to be included in queue.
fn min_gas_price(&self, _: Params) -> Result<Value, Error>;
@@ -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);

View File

@@ -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<Value, Error>;
/// Sets new gas ceiling target for mined blocks.
fn set_gas_ceil_target(&self, _: Params) -> Result<Value, Error>;
/// Sets new extra data for mined blocks.
fn set_extra_data(&self, _: Params) -> Result<Value, Error>;
@@ -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);