correct ready transaction condition

This commit is contained in:
Robert Habermeier 2017-02-04 17:19:39 +01:00
parent 484b93abdc
commit 197695414e
2 changed files with 16 additions and 11 deletions

View File

@ -236,6 +236,11 @@ impl HeaderChain {
} }
} }
/// Get the best block's header.
pub fn best_header(&self) -> encoded::Header {
self.get_header(BlockId::Latest).expect("Header for best block always stored; qed")
}
/// Get the nth CHT root, if it's been computed. /// Get the nth CHT root, if it's been computed.
/// ///
/// CHT root 0 is from block `1..2048`. /// CHT root 0 is from block `1..2048`.

View File

@ -21,7 +21,6 @@ use ethcore::block_status::BlockStatus;
use ethcore::client::ClientReport; use ethcore::client::ClientReport;
use ethcore::ids::BlockId; use ethcore::ids::BlockId;
use ethcore::header::Header; use ethcore::header::Header;
use ethcore::views::HeaderView;
use ethcore::verification::queue::{self, HeaderQueue}; use ethcore::verification::queue::{self, HeaderQueue};
use ethcore::transaction::{PendingTransaction, Condition as TransactionCondition}; use ethcore::transaction::{PendingTransaction, Condition as TransactionCondition};
use ethcore::blockchain_info::BlockChainInfo; use ethcore::blockchain_info::BlockChainInfo;
@ -35,7 +34,6 @@ use util::{Bytes, Mutex, RwLock};
use provider::Provider; use provider::Provider;
use request; use request;
use time;
use self::header_chain::HeaderChain; use self::header_chain::HeaderChain;
@ -109,12 +107,12 @@ impl Client {
/// Fetch a vector of all pending transactions. /// Fetch a vector of all pending transactions.
pub fn ready_transactions(&self) -> Vec<PendingTransaction> { pub fn ready_transactions(&self) -> Vec<PendingTransaction> {
let best_num = self.chain.best_block().number; let best = self.chain.best_header();
self.tx_pool.lock() self.tx_pool.lock()
.values() .values()
.filter(|t| match t.condition { .filter(|t| match t.condition {
Some(TransactionCondition::Number(ref x)) => x <= &best_num, Some(TransactionCondition::Number(x)) => x <= best.number(),
Some(TransactionCondition::Timestamp(ref x)) => *x <= time::get_time().sec as u64, Some(TransactionCondition::Timestamp(x)) => x <= best.timestamp(),
None => true, None => true,
}) })
.cloned() .cloned()
@ -131,17 +129,19 @@ impl Client {
/// Get the chain info. /// Get the chain info.
pub fn chain_info(&self) -> BlockChainInfo { pub fn chain_info(&self) -> BlockChainInfo {
let best_block = self.chain.best_block(); let best_hdr = self.chain.best_header();
let best_td = self.chain.best_block().total_difficulty;
let first_block = self.chain.first_block(); let first_block = self.chain.first_block();
let genesis_hash = self.chain.genesis_hash(); let genesis_hash = self.chain.genesis_hash();
BlockChainInfo { BlockChainInfo {
total_difficulty: best_block.total_difficulty, total_difficulty: best_td,
pending_total_difficulty: best_block.total_difficulty + self.queue.total_difficulty(), pending_total_difficulty: best_td + self.queue.total_difficulty(),
genesis_hash: genesis_hash, genesis_hash: genesis_hash,
best_block_hash: best_block.hash, best_block_hash: best_hdr.hash(),
best_block_number: best_block.number, best_block_number: best_hdr.number(),
best_block_timestamp: HeaderView::new(&self.chain.get_header(BlockId::Latest).expect("Latest hash is always in the chain")).timestamp(), best_block_timestamp: best_hdr.timestamp(),
ancient_block_hash: if first_block.is_some() { Some(genesis_hash) } else { None }, ancient_block_hash: if first_block.is_some() { Some(genesis_hash) } else { None },
ancient_block_number: if first_block.is_some() { Some(0) } else { None }, ancient_block_number: if first_block.is_some() { Some(0) } else { None },
first_block_hash: first_block.as_ref().map(|first| first.hash), first_block_hash: first_block.as_ref().map(|first| first.hash),