Use sensible gas price.
This commit is contained in:
parent
9592ccc0df
commit
5d626c7dd3
@ -64,7 +64,7 @@ mod transaction_queue;
|
|||||||
pub use transaction_queue::{TransactionQueue, AccountDetails};
|
pub use transaction_queue::{TransactionQueue, AccountDetails};
|
||||||
pub use miner::{Miner};
|
pub use miner::{Miner};
|
||||||
|
|
||||||
use util::{H256, Address, FixedHash, Bytes};
|
use util::{H256, U256, Address, FixedHash, Bytes};
|
||||||
use ethcore::client::{BlockChainClient};
|
use ethcore::client::{BlockChainClient};
|
||||||
use ethcore::block::{ClosedBlock};
|
use ethcore::block::{ClosedBlock};
|
||||||
use ethcore::error::{Error};
|
use ethcore::error::{Error};
|
||||||
@ -107,6 +107,9 @@ pub trait MinerService : Send + Sync {
|
|||||||
|
|
||||||
/// Query pending transactions for hash
|
/// Query pending transactions for hash
|
||||||
fn transaction(&self, hash: &H256) -> Option<SignedTransaction>;
|
fn transaction(&self, hash: &H256) -> Option<SignedTransaction>;
|
||||||
|
|
||||||
|
/// Suggested gas price
|
||||||
|
fn sensible_gas_price(&self) -> U256 { x!(20000000000u64) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mining status
|
/// Mining status
|
||||||
|
@ -198,6 +198,11 @@ impl MinerService for Miner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn sensible_gas_price(&self) -> U256 {
|
||||||
|
// 10% above our minimum.
|
||||||
|
self.transaction_queue.lock().unwrap().minimal_gas_price().clone() * x!(110) / x!(100)
|
||||||
|
}
|
||||||
|
|
||||||
fn author(&self) -> Address {
|
fn author(&self) -> Address {
|
||||||
*self.author.read().unwrap()
|
*self.author.read().unwrap()
|
||||||
}
|
}
|
||||||
|
@ -312,6 +312,11 @@ impl TransactionQueue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the minimal gas price.
|
||||||
|
pub fn minimal_gas_price(&self) -> &U256 {
|
||||||
|
&self.minimal_gas_price
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets new gas price threshold for incoming transactions.
|
/// Sets new gas price threshold for incoming transactions.
|
||||||
/// Any transaction already imported to the queue is not affected.
|
/// Any transaction already imported to the queue is not affected.
|
||||||
pub fn set_minimal_gas_price(&mut self, min_gas_price: U256) {
|
pub fn set_minimal_gas_price(&mut self, min_gas_price: U256) {
|
||||||
|
@ -31,7 +31,6 @@ use ethcore::client::*;
|
|||||||
use ethcore::block::IsBlock;
|
use ethcore::block::IsBlock;
|
||||||
use ethcore::views::*;
|
use ethcore::views::*;
|
||||||
use ethcore::ethereum::Ethash;
|
use ethcore::ethereum::Ethash;
|
||||||
use ethcore::ethereum::denominations::shannon;
|
|
||||||
use ethcore::transaction::{Transaction as EthTransaction, SignedTransaction, Action};
|
use ethcore::transaction::{Transaction as EthTransaction, SignedTransaction, Action};
|
||||||
use self::ethash::SeedHashCompute;
|
use self::ethash::SeedHashCompute;
|
||||||
use v1::traits::{Eth, EthFilter};
|
use v1::traits::{Eth, EthFilter};
|
||||||
@ -44,10 +43,6 @@ fn default_gas() -> U256 {
|
|||||||
U256::from(21_000)
|
U256::from(21_000)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_gas_price() -> U256 {
|
|
||||||
shannon() * U256::from(20)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Eth rpc implementation.
|
/// Eth rpc implementation.
|
||||||
pub struct EthClient<C, S, A, M, EM = ExternalMiner>
|
pub struct EthClient<C, S, A, M, EM = ExternalMiner>
|
||||||
where C: BlockChainClient,
|
where C: BlockChainClient,
|
||||||
@ -173,16 +168,18 @@ impl<C, S, A, M, EM> EthClient<C, S, A, M, EM>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sign_call(client: &Arc<C>, request: CallRequest) -> SignedTransaction {
|
fn sign_call(&self, request: CallRequest) -> Result<SignedTransaction, Error> {
|
||||||
|
let client = take_weak!(self.client);
|
||||||
|
let miner = take_weak!(self.miner);
|
||||||
let from = request.from.unwrap_or(Address::zero());
|
let from = request.from.unwrap_or(Address::zero());
|
||||||
EthTransaction {
|
Ok(EthTransaction {
|
||||||
nonce: request.nonce.unwrap_or_else(|| client.nonce(&from)),
|
nonce: request.nonce.unwrap_or_else(|| client.nonce(&from)),
|
||||||
action: request.to.map_or(Action::Create, Action::Call),
|
action: request.to.map_or(Action::Create, Action::Call),
|
||||||
gas: request.gas.unwrap_or_else(default_gas),
|
gas: request.gas.unwrap_or_else(default_gas),
|
||||||
gas_price: request.gas_price.unwrap_or_else(default_gas_price),
|
gas_price: request.gas_price.unwrap_or_else(|| miner.sensible_gas_price()),
|
||||||
value: request.value.unwrap_or_else(U256::zero),
|
value: request.value.unwrap_or_else(U256::zero),
|
||||||
data: request.data.map_or_else(Vec::new, |d| d.to_vec())
|
data: request.data.map_or_else(Vec::new, |d| d.to_vec())
|
||||||
}.fake_sign(from)
|
}.fake_sign(from))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_transaction(&self, signed_transaction: SignedTransaction, raw_transaction: Vec<u8>) -> Result<Value, Error> {
|
fn dispatch_transaction(&self, signed_transaction: SignedTransaction, raw_transaction: Vec<u8>) -> Result<Value, Error> {
|
||||||
@ -290,7 +287,7 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
|
|||||||
|
|
||||||
fn gas_price(&self, params: Params) -> Result<Value, Error> {
|
fn gas_price(&self, params: Params) -> Result<Value, Error> {
|
||||||
match params {
|
match params {
|
||||||
Params::None => to_value(&default_gas_price()),
|
Params::None => to_value(&take_weak!(self.miner).sensible_gas_price()),
|
||||||
_ => Err(Error::invalid_params())
|
_ => Err(Error::invalid_params())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -485,11 +482,12 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
|
|||||||
Ok(secret) => {
|
Ok(secret) => {
|
||||||
let signed_transaction = {
|
let signed_transaction = {
|
||||||
let client = take_weak!(self.client);
|
let client = take_weak!(self.client);
|
||||||
|
let miner = take_weak!(self.miner);
|
||||||
EthTransaction {
|
EthTransaction {
|
||||||
nonce: request.nonce.unwrap_or_else(|| client.nonce(&request.from)),
|
nonce: request.nonce.unwrap_or_else(|| client.nonce(&request.from)),
|
||||||
action: request.to.map_or(Action::Create, Action::Call),
|
action: request.to.map_or(Action::Create, Action::Call),
|
||||||
gas: request.gas.unwrap_or_else(default_gas),
|
gas: request.gas.unwrap_or_else(default_gas),
|
||||||
gas_price: request.gas_price.unwrap_or_else(default_gas_price),
|
gas_price: request.gas_price.unwrap_or_else(|| miner.sensible_gas_price()),
|
||||||
value: request.value.unwrap_or_else(U256::zero),
|
value: request.value.unwrap_or_else(U256::zero),
|
||||||
data: request.data.map_or_else(Vec::new, |d| d.to_vec()),
|
data: request.data.map_or_else(Vec::new, |d| d.to_vec()),
|
||||||
}.sign(&secret)
|
}.sign(&secret)
|
||||||
@ -515,8 +513,8 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
|
|||||||
|
|
||||||
fn call(&self, params: Params) -> Result<Value, Error> {
|
fn call(&self, params: Params) -> Result<Value, Error> {
|
||||||
from_params_discard_second(params).and_then(|(request, )| {
|
from_params_discard_second(params).and_then(|(request, )| {
|
||||||
|
let signed = try!(self.sign_call(request));
|
||||||
let client = take_weak!(self.client);
|
let client = take_weak!(self.client);
|
||||||
let signed = Self::sign_call(&client, request);
|
|
||||||
let output = client.call(&signed).map(|e| Bytes(e.output)).unwrap_or(Bytes::new(vec![]));
|
let output = client.call(&signed).map(|e| Bytes(e.output)).unwrap_or(Bytes::new(vec![]));
|
||||||
to_value(&output)
|
to_value(&output)
|
||||||
})
|
})
|
||||||
@ -524,8 +522,8 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
|
|||||||
|
|
||||||
fn estimate_gas(&self, params: Params) -> Result<Value, Error> {
|
fn estimate_gas(&self, params: Params) -> Result<Value, Error> {
|
||||||
from_params_discard_second(params).and_then(|(request, )| {
|
from_params_discard_second(params).and_then(|(request, )| {
|
||||||
|
let signed = try!(self.sign_call(request));
|
||||||
let client = take_weak!(self.client);
|
let client = take_weak!(self.client);
|
||||||
let signed = Self::sign_call(&client, request);
|
|
||||||
let used = client.call(&signed).map(|res| res.gas_used + res.refunded).unwrap_or(From::from(0));
|
let used = client.call(&signed).map(|res| res.gas_used + res.refunded).unwrap_or(From::from(0));
|
||||||
to_value(&used)
|
to_value(&used)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user