Don't fail badly when no transactions in last 100 blocks. (#2856)
This commit is contained in:
parent
5ae87a64b1
commit
a6fd922ffb
@ -194,15 +194,20 @@ pub trait BlockChainClient : Sync + Send {
|
|||||||
fn gas_price_statistics(&self, sample_size: usize, distribution_size: usize) -> Result<Vec<U256>, ()> {
|
fn gas_price_statistics(&self, sample_size: usize, distribution_size: usize) -> Result<Vec<U256>, ()> {
|
||||||
let mut h = self.chain_info().best_block_hash;
|
let mut h = self.chain_info().best_block_hash;
|
||||||
let mut corpus = Vec::new();
|
let mut corpus = Vec::new();
|
||||||
for _ in 0..sample_size {
|
while corpus.is_empty() {
|
||||||
let block_bytes = self.block(BlockID::Hash(h)).expect("h is either the best_block_hash or an ancestor; qed");
|
for _ in 0..sample_size {
|
||||||
let block = BlockView::new(&block_bytes);
|
let block_bytes = self.block(BlockID::Hash(h)).expect("h is either the best_block_hash or an ancestor; qed");
|
||||||
let header = block.header_view();
|
let block = BlockView::new(&block_bytes);
|
||||||
if header.number() == 0 {
|
let header = block.header_view();
|
||||||
break;
|
if header.number() == 0 {
|
||||||
|
if corpus.is_empty() {
|
||||||
|
corpus.push(20_000_000_000u64.into()); // we have literally no information - it' as good a number as any.
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
block.transaction_views().iter().foreach(|t| corpus.push(t.gas_price()));
|
||||||
|
h = header.parent_hash().clone();
|
||||||
}
|
}
|
||||||
block.transaction_views().iter().foreach(|t| corpus.push(t.gas_price()));
|
|
||||||
h = header.parent_hash().clone();
|
|
||||||
}
|
}
|
||||||
corpus.sort();
|
corpus.sort();
|
||||||
let n = corpus.len();
|
let n = corpus.len();
|
||||||
|
Loading…
Reference in New Issue
Block a user