Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Print warnings when fetching pending blocks #8711

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions ethcore/src/miner/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,12 @@ impl Miner {
{
self.sealing.lock().queue
.peek_last_ref()
.and_then(|b| if b.block().header().number() > latest_block_number {
Some(f(b))
} else {
None
.and_then(|b| {
if b.block().header().number() > latest_block_number {
Some(f(b))
} else {
None
}
})
}

Expand Down
36 changes: 23 additions & 13 deletions rpc/src/v1/impls/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub struct EthClient<C, SN: ?Sized, S: ?Sized, M, EM> where
eip86_transition: u64,
}

#[derive(Debug)]
enum BlockNumberOrId {
Number(BlockNumber),
Id(BlockId),
Expand Down Expand Up @@ -184,29 +185,38 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM, T: StateInfo + 'static> EthClient<C, SN, S
let (block, difficulty, extra, is_pending) = match id {
BlockNumberOrId::Number(BlockNumber::Pending) => {
let info = self.client.chain_info();
let pending_block = self.miner.pending_block(info.best_block_number);
let difficulty = {
let latest_difficulty = self.client.block_total_difficulty(BlockId::Latest).expect("blocks in chain have details; qed");
let pending_difficulty = self.miner.pending_block_header(info.best_block_number).map(|header| *header.difficulty());
match self.miner.pending_block(info.best_block_number) {
Some(pending_block) => {
warn!("`Pending` is deprecated and may be removed in future versions.");

if let Some(difficulty) = pending_difficulty {
difficulty + latest_difficulty
} else {
latest_difficulty
}
};
let difficulty = {
let latest_difficulty = self.client.block_total_difficulty(BlockId::Latest).expect("blocks in chain have details; qed");
let pending_difficulty = self.miner.pending_block_header(info.best_block_number).map(|header| *header.difficulty());

if let Some(difficulty) = pending_difficulty {
difficulty + latest_difficulty
} else {
latest_difficulty
}
};

let extra = pending_block.as_ref().map(|b| self.client.engine().extra_info(&b.header));
let extra = self.client.engine().extra_info(&pending_block.header);

(pending_block.map(|b| encoded::Block::new(b.rlp_bytes())), Some(difficulty), extra, true)
(Some(encoded::Block::new(pending_block.rlp_bytes())), Some(difficulty), Some(extra), true)
},
None => {
warn!("`Pending` is deprecated and may be removed in future versions. Falling back to `Latest`");
client_query(BlockId::Latest)
}
}
},

BlockNumberOrId::Number(num) => {
let id = match num {
BlockNumber::Latest => BlockId::Latest,
BlockNumber::Earliest => BlockId::Earliest,
BlockNumber::Num(n) => BlockId::Number(n),
BlockNumber::Pending => unreachable!(), // Already covered
BlockNumber::Pending => unreachable!() // Already covered
};

client_query(id)
Expand Down