sort corpus when hitting genesis (#4470)

This commit is contained in:
keorn 2017-02-08 02:55:56 -05:00 committed by Tomasz Drwięga
parent 5fe993f658
commit b0248cad0b
3 changed files with 9 additions and 0 deletions

View File

@ -220,6 +220,7 @@ pub trait BlockChainClient : Sync + Send {
let block = self.block(BlockId::Hash(h)).expect("h is either the best_block_hash or an ancestor; qed"); let block = self.block(BlockId::Hash(h)).expect("h is either the best_block_hash or an ancestor; qed");
let header = block.header_view(); let header = block.header_view();
if header.number() == 0 { if header.number() == 0 {
corpus.sort();
return corpus; return corpus;
} }
block.transaction_views().iter().foreach(|t| corpus.push(t.gas_price())); block.transaction_views().iter().foreach(|t| corpus.push(t.gas_price()));

View File

@ -233,6 +233,13 @@ fn empty_gas_price_histogram() {
assert!(client.gas_price_histogram(20, 5).is_none()); assert!(client.gas_price_histogram(20, 5).is_none());
} }
#[test]
fn corpus_is_sorted() {
let client_result = generate_dummy_client_with_data(2, 1, slice_into![U256::from_str("11426908979").unwrap(), U256::from_str("50426908979").unwrap()]);
let client = client_result.reference();
let corpus = client.gas_price_corpus(20);
assert!(corpus[0] < corpus[1]);
}
#[test] #[test]
fn can_handle_long_fork() { fn can_handle_long_fork() {

View File

@ -33,6 +33,7 @@ impl Histogram {
if corpus.len() < 1 { return None; } if corpus.len() < 1 { return None; }
let corpus_end = corpus.last().expect("there is at least 1 element; qed").clone(); let corpus_end = corpus.last().expect("there is at least 1 element; qed").clone();
let corpus_start = corpus.first().expect("there is at least 1 element; qed").clone(); let corpus_start = corpus.first().expect("there is at least 1 element; qed").clone();
trace!(target: "stats", "Computing histogram from {} to {} with {} buckets.", corpus_start, corpus_end, bucket_number);
// Bucket needs to be at least 1 wide. // Bucket needs to be at least 1 wide.
let bucket_size = { let bucket_size = {
// Round up to get the entire corpus included. // Round up to get the entire corpus included.