Include RPC configurability for max tx gas limit.

Also Move the gas limit into the transaction queue from the miner.
This commit is contained in:
Gav Wood
2016-06-27 20:19:01 +02:00
parent a102015ecf
commit 10aa32b0f5
8 changed files with 82 additions and 16 deletions

View File

@@ -22,7 +22,7 @@ use jsonrpc_core::*;
use ethcore::miner::MinerService;
use ethcore::service::SyncMessage;
use v1::traits::EthcoreSet;
use v1::types::{Bytes};
use v1::types::{OptionalValue, Bytes};
/// Ethcore-specific rpc interface for operations altering the settings.
pub struct EthcoreSetClient<M> where
@@ -86,6 +86,13 @@ impl<M> EthcoreSet for EthcoreSetClient<M> where M: MinerService + 'static {
})
}
fn set_tx_gas_limit(&self, params: Params) -> Result<Value, Error> {
from_params::<(OptionalValue<U256>,)>(params).and_then(|(limit,)| {
take_weak!(self.miner).set_tx_gas_limit(limit.into());
to_value(&true)
})
}
fn add_reserved_peer(&self, params: Params) -> Result<Value, Error> {
from_params::<(String,)>(params).and_then(|(peer,)| {
match take_weak!(self.net).add_reserved_peer(&peer) {

View File

@@ -43,6 +43,7 @@ pub struct TestMinerService {
author: RwLock<Address>,
extra_data: RwLock<Bytes>,
limit: RwLock<usize>,
tx_gas_limit: RwLock<Option<U256>>,
}
impl Default for TestMinerService {
@@ -58,6 +59,7 @@ impl Default for TestMinerService {
author: RwLock::new(Address::zero()),
extra_data: RwLock::new(vec![1, 2, 3, 4]),
limit: RwLock::new(1024),
tx_gas_limit: RwLock::new(None),
}
}
}
@@ -99,6 +101,10 @@ impl MinerService for TestMinerService {
*self.limit.write().unwrap() = limit;
}
fn set_tx_gas_limit(&self, limit: Option<U256>) {
*self.tx_gas_limit.write().unwrap() = limit;
}
fn transactions_limit(&self) -> usize {
*self.limit.read().unwrap()
}

View File

@@ -40,6 +40,9 @@ pub trait EthcoreSet: Sized + Send + Sync + 'static {
/// Sets the limits for transaction queue.
fn set_transactions_limit(&self, _: Params) -> Result<Value, Error>;
/// Sets the maximum amount of gas a single transaction may consume.
fn set_tx_gas_limit(&self, _: Params) -> Result<Value, Error>;
/// Add a reserved peer.
fn add_reserved_peer(&self, _: Params) -> Result<Value, Error>;
@@ -60,6 +63,7 @@ pub trait EthcoreSet: Sized + Send + Sync + 'static {
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_setMaxTransactionGas", EthcoreSet::set_tx_gas_limit);
delegate.add_method("ethcore_setTransactionsLimit", EthcoreSet::set_transactions_limit);
delegate.add_method("ethcore_addReservedPeer", EthcoreSet::add_reserved_peer);
delegate.add_method("ethcore_removeReservedPeer", EthcoreSet::remove_reserved_peer);

View File

@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use serde::{Serialize, Serializer};
use serde::{Serialize, Serializer, Deserialize, Deserializer};
use serde_json::Value;
/// Optional value
@@ -26,13 +26,22 @@ pub enum OptionalValue<T> where T: Serialize {
Null
}
impl<T> Default for OptionalValue<T> where T: Serialize {
impl<T> Default for OptionalValue<T> where T: Serialize + Deserialize {
fn default() -> Self {
OptionalValue::Null
}
}
impl<T> Serialize for OptionalValue<T> where T: Serialize {
impl<T> Into<Option<T>> for OptionalValue<T> where T: Serialize + Deserialize {
fn into(self) -> Option<T> {
match self {
OptionalValue::Null => None,
OptionalValue::Value(t) => Some(t),
}
}
}
impl<T> Serialize for OptionalValue<T> where T: Serialize + Deserialize {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: Serializer {
match *self {
@@ -42,6 +51,17 @@ impl<T> Serialize for OptionalValue<T> where T: Serialize {
}
}
impl<T> Deserialize for OptionalValue<T> where T: Serialize + Deserialize {
fn deserialize<D>(deserializer: &mut D) -> Result<OptionalValue<T>, D::Error>
where D: Deserializer {
let deser_result: Result<T, D::Error> = Deserialize::deserialize(deserializer);
match deser_result {
Ok(t) => Ok(OptionalValue::Value(t)),
Err(_) => Ok(OptionalValue::Null),
}
}
}
#[cfg(test)]
mod tests {
use serde_json;