Fixing minimal transaction queue price (#4204)

* Fixing minimal transaction queue price

* Fixing tests
This commit is contained in:
Tomasz Drwięga
2017-01-18 19:44:24 +01:00
committed by Arkadiy Paronyan
parent 73b80869f5
commit 24aec5191a
6 changed files with 46 additions and 19 deletions

View File

@@ -250,7 +250,7 @@ impl TestBlockChainClient {
value: U256::from(100),
data: "3331600055".from_hex().unwrap(),
gas: U256::from(100_000),
gas_price: U256::one(),
gas_price: U256::from(200_000_000_000u64),
nonce: U256::zero()
};
let signed_tx = tx.sign(keypair.secret(), None);
@@ -316,11 +316,11 @@ impl TestBlockChainClient {
value: U256::from(100),
data: "3331600055".from_hex().unwrap(),
gas: U256::from(100_000),
gas_price: U256::one(),
gas_price: U256::from(20_000_000_000u64),
nonce: U256::zero()
};
let signed_tx = tx.sign(keypair.secret(), None);
self.set_balance(signed_tx.sender(), 10_000_000.into());
self.set_balance(signed_tx.sender(), U256::from(10_000_000_000_000_000_000u64));
let res = self.miner.import_external_transactions(self, vec![signed_tx.into()]);
let res = res.into_iter().next().unwrap().expect("Successful import");
assert_eq!(res, TransactionImportResult::Current);

View File

@@ -303,16 +303,6 @@ impl Miner {
#[cfg_attr(feature="dev", allow(match_same_arms))]
/// Prepares new block for sealing including top transactions from queue.
fn prepare_block(&self, chain: &MiningBlockChainClient) -> (ClosedBlock, Option<H256>) {
{
trace!(target: "miner", "prepare_block: recalibrating...");
let txq = self.transaction_queue.clone();
self.gas_pricer.lock().recalibrate(move |price| {
trace!(target: "miner", "prepare_block: Got gas price! {}", price);
txq.lock().set_minimal_gas_price(price);
});
trace!(target: "miner", "prepare_block: done recalibration.");
}
let _timer = PerfTimer::new("prepare_block");
let chain_info = chain.chain_info();
let (transactions, mut open_block, original_work_hash) = {
@@ -427,6 +417,16 @@ impl Miner {
(block, original_work_hash)
}
/// Asynchronously updates minimal gas price for transaction queue
pub fn recalibrate_minimal_gas_price(&self) {
debug!(target: "miner", "minimal_gas_price: recalibrating...");
let txq = self.transaction_queue.clone();
self.gas_pricer.lock().recalibrate(move |price| {
debug!(target: "miner", "minimal_gas_price: Got gas price! {}", price);
txq.lock().set_minimal_gas_price(price);
});
}
/// Check is reseal is allowed and necessary.
fn requires_reseal(&self, best_block: BlockNumber) -> bool {
let has_local_transactions = self.transaction_queue.lock().has_local_pending_transactions();
@@ -1120,6 +1120,9 @@ impl MinerService for Miner {
// First update gas limit in transaction queue
self.update_gas_limit(chain);
// Update minimal gas price
self.recalibrate_minimal_gas_price();
// Then import all transactions...
{