diff --git a/ethcore/light/src/client/mod.rs b/ethcore/light/src/client/mod.rs index bb43a9f5b..a113b4367 100644 --- a/ethcore/light/src/client/mod.rs +++ b/ethcore/light/src/client/mod.rs @@ -31,8 +31,7 @@ use ethcore::service::ClientIoMessage; use ethcore::encoded; use io::IoChannel; -use util::hash::H256; -use util::{Bytes, Mutex, RwLock}; +use util::{Bytes, H256, Mutex, RwLock}; use self::header_chain::HeaderChain; @@ -60,6 +59,9 @@ pub trait LightChainClient: Send + Sync { /// Attempt to get block header by block id. fn block_header(&self, id: BlockId) -> Option; + /// Get the best block header. + fn best_block_header(&self) -> encoded::Header; + /// Query whether a block is known. fn is_known(&self, hash: &H256) -> bool; @@ -157,6 +159,11 @@ impl Client { self.chain.block_header(id) } + /// Get the best block header. + pub fn best_block_header(&self) -> encoded::Header { + self.chain.best_header() + } + /// Flush the header queue. pub fn flush_queue(&self) { self.queue.flush() @@ -223,6 +230,10 @@ impl LightChainClient for Client { Client::block_header(self, id) } + fn best_block_header(&self) -> encoded::Header { + Client::best_block_header(self) + } + fn is_known(&self, hash: &H256) -> bool { self.status(hash) == BlockStatus::InChain } diff --git a/rpc/src/v1/helpers/dispatch.rs b/rpc/src/v1/helpers/dispatch.rs index 6174c060b..de0207d79 100644 --- a/rpc/src/v1/helpers/dispatch.rs +++ b/rpc/src/v1/helpers/dispatch.rs @@ -30,7 +30,6 @@ use util::sha3::Hashable; use ethkey::Signature; use ethsync::LightSync; -use ethcore::ids::BlockId; use ethcore::miner::MinerService; use ethcore::client::MiningBlockChainClient; use ethcore::transaction::{Action, SignedTransaction, PendingTransaction, Transaction}; @@ -190,8 +189,7 @@ impl Dispatcher for LightDispatcher { -> BoxFuture { let request = request; - let gas_limit = self.client.block_header(BlockId::Latest) - .expect("Best block header always kept; qed").gas_limit(); + let gas_limit = self.client.best_block_header().gas_limit(); future::ok(FilledTransactionRequest { from: request.from.unwrap_or(default_sender), @@ -211,8 +209,7 @@ impl Dispatcher for LightDispatcher { { let network_id = None; // TODO: fetch from client. let address = filled.from; - let best_header = self.client.block_header(BlockId::Latest) - .expect("Best block header always kept; qed"); + let best_header = self.client.best_block_header(); let with_nonce = move |filled: FilledTransactionRequest, nonce| { let t = Transaction { diff --git a/rpc/src/v1/impls/light/eth.rs b/rpc/src/v1/impls/light/eth.rs index f72a9bb69..18bd9682e 100644 --- a/rpc/src/v1/impls/light/eth.rs +++ b/rpc/src/v1/impls/light/eth.rs @@ -305,8 +305,7 @@ impl Eth for EthClient { } fn send_raw_transaction(&self, raw: Bytes) -> Result { - let best_header = self.client.block_header(BlockId::Latest) - .expect("best block header always stored; qed").decode(); + let best_header = self.client.best_block_header().decode(); UntrustedRlp::new(&raw.into_vec()).as_val() .map_err(errors::from_rlp_error)