diff --git a/rpc/src/v1/helpers/errors.rs b/rpc/src/v1/helpers/errors.rs index f177e251568..197d8ec3aca 100644 --- a/rpc/src/v1/helpers/errors.rs +++ b/rpc/src/v1/helpers/errors.rs @@ -206,6 +206,14 @@ pub fn cannot_submit_work(err: EthcoreError) -> Error { } } +pub fn ancient_block_missing() -> Error { + Error { + code: ErrorCode::ServerError(codes::UNSUPPORTED_REQUEST), + message: "Ancient block missing".into(), + data: None, + } +} + pub fn not_enough_data() -> Error { Error { code: ErrorCode::ServerError(codes::UNSUPPORTED_REQUEST), diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 548271f8929..2148dd966ee 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -650,6 +650,12 @@ impl Eth for EthClient< } fn transaction_by_hash(&self, hash: RpcH256) -> BoxFuture> { + if let Ok(SyncStatus::Info(_)) = self.syncing() { + // alas, we're still syncing! + warn!("Attempted to fetch transaction via hash while sync is in progress"); + return Box::new(future::err(errors::ancient_block_missing())) + } + let hash: H256 = hash.into(); let tx = try_bf!(self.transaction(PendingTransactionId::Hash(hash))).or_else(|| { self.miner.transaction(&hash) @@ -661,7 +667,16 @@ impl Eth for EthClient< fn transaction_by_block_hash_and_index(&self, hash: RpcH256, index: Index) -> BoxFuture> { let id = PendingTransactionId::Location(PendingOrBlock::Block(BlockId::Hash(hash.into())), index.value()); - Box::new(future::done(self.transaction(id))) + Box::new(future::done(self.transaction(id).and_then(|res| { + if res.is_none() { + if let Ok(SyncStatus::Info(_)) = self.syncing() { + // alas, we're still syncing! + warn!("Call made to transaction_by_block_hash_and_index while sync is in progress"); + return Err(errors::ancient_block_missing()) + } + } + Ok(res) + }))) } fn transaction_by_block_number_and_index(&self, num: BlockNumber, index: Index) -> BoxFuture> { @@ -677,6 +692,12 @@ impl Eth for EthClient< } fn transaction_receipt(&self, hash: RpcH256) -> BoxFuture> { + if let Ok(SyncStatus::Info(_)) = self.syncing() { + // alas, we're still syncing! + warn!("Attempted to fetch transaction via hash while sync is in progress"); + return Box::new(future::err(errors::ancient_block_missing())) + } + let hash: H256 = hash.into(); if self.options.allow_pending_receipt_query {