Sensible gas limits for eth_sendTransaction (#953)

* Sensible gas limits for eth_sendTransaction

Fixes #859

* Compile fix.

* Remove !.
This commit is contained in:
Gav Wood 2016-04-14 12:01:12 -07:00
parent 01e7d2d872
commit d909bc05c4
4 changed files with 13 additions and 13 deletions

View File

@ -132,8 +132,11 @@ pub trait MinerService : Send + Sync {
/// Returns highest transaction nonce for given address.
fn last_nonce(&self, address: &Address) -> Option<U256>;
/// Suggested gas price
/// Suggested gas price.
fn sensible_gas_price(&self) -> U256 { x!(20000000000u64) }
/// Suggested gas limit.
fn sensible_gas_limit(&self) -> U256 { x!(21000) }
}
/// Mining status

View File

@ -201,6 +201,10 @@ impl MinerService for Miner {
*self.transaction_queue.lock().unwrap().minimal_gas_price() * x!(110) / x!(100)
}
fn sensible_gas_limit(&self) -> U256 {
*self.gas_floor_target.read().unwrap() / x!(5)
}
/// Get the author that we will seal blocks as.
fn author(&self) -> Address {
*self.author.read().unwrap()

View File

@ -622,9 +622,9 @@ impl Configuration {
let mut secret_store = SecretStore::new_in(Path::new(&self.keys_path()));
if self.args.cmd_new {
println!("Please note that password is NOT RECOVERABLE.");
println!("Type password: ");
print!("Type password: ");
let password = read_password().unwrap();
println!("Repeat password: ");
print!("Repeat password: ");
let password_repeat = read_password().unwrap();
if password != password_repeat {
println!("Passwords do not match!");

View File

@ -40,14 +40,6 @@ use v1::helpers::{PollFilter, PollManager, ExternalMinerService, ExternalMiner};
use util::keys::store::AccountProvider;
use serde;
fn default_gas() -> U256 {
U256::from(21_000)
}
fn default_call_gas() -> U256 {
U256::from(50_000_000)
}
/// Eth rpc implementation.
pub struct EthClient<C, S, A, M, EM = ExternalMiner>
where C: BlockChainClient,
@ -180,7 +172,7 @@ impl<C, S, A, M, EM> EthClient<C, S, A, M, EM>
Ok(EthTransaction {
nonce: request.nonce.unwrap_or_else(|| client.nonce(&from)),
action: request.to.map_or(Action::Create, Action::Call),
gas: request.gas.unwrap_or_else(default_call_gas),
gas: request.gas.unwrap_or(U256::from(50_000_000)),
gas_price: request.gas_price.unwrap_or_else(|| miner.sensible_gas_price()),
value: request.value.unwrap_or_else(U256::zero),
data: request.data.map_or_else(Vec::new, |d| d.to_vec())
@ -498,7 +490,7 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
.map(|nonce| nonce + U256::one()))
.unwrap_or_else(|| client.nonce(&request.from)),
action: request.to.map_or(Action::Create, Action::Call),
gas: request.gas.unwrap_or_else(default_gas),
gas: request.gas.unwrap_or_else(|| miner.sensible_gas_limit()),
gas_price: request.gas_price.unwrap_or_else(|| miner.sensible_gas_price()),
value: request.value.unwrap_or_else(U256::zero),
data: request.data.map_or_else(Vec::new, |d| d.to_vec()),
@ -524,6 +516,7 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
}
fn call(&self, params: Params) -> Result<Value, Error> {
trace!(target: "jsonrpc", "call: {:?}", params);
from_params_discard_second(params).and_then(|(request, )| {
let signed = try!(self.sign_call(request));
let client = take_weak!(self.client);