Benchmark Ethereum Pallet (#149)

* Add skeleton for worst case import_unsigned_header

* Fix a typo

* Add benchmark test for best case unsigned header import

* Add finality verification to worst case bench

* Move `insert_header()` from mock to test_utils

Allows the benchmarking code to use this without having to pull it in from the mock.

* Add a rough bench to test a finalizing a "long" chain

* Try to use complexity parameter for finality bench

* Improve long finality bench

* Remove stray dot file

* Remove old "worst" case bench

* Scribble some ideas down for pruning bench

* Prune headers during benchmarking

* Clean up some comments

* Make finality bench work for entire range of complexity parameter

* Place initialization code into a function

* Add bench for block finalization with caching

* First attempt at bench with receipts

* Try and trigger validator set change

* Perform a validator set change during benchmarking

* Move `validators_change_receipt()` to shared location

Allows unit tests and benchmarks to access the same helper function
and const

* Extract a test receipt root into a constant

* Clean up description of pruning bench

* Fix cache and pruning tests

* Remove unecessary `build_custom_header` usage

* Get rid of warnings

* Remove code duplication comment

I don't think its entirely worth it to split out so few lines of code.
The benches aren't particularly hard to read anyways.

* Increase the range of the complexity parameter

* Use dynamic number of receipts while benchmarking

As part of this change we have removed the hardcoded TEST_RECEIPT_ROOT
and instead chose to calculate the receipt root on the fly. This will
make tests and benches less fragile.

* Prune a dynamic number of headers
This commit is contained in:
Hernando Castano
2020-07-10 05:10:53 -04:00
committed by Bastian Köcher
parent 1cd7be9214
commit 002e18a47c
9 changed files with 315 additions and 71 deletions
+40 -1
View File
@@ -21,12 +21,18 @@
//!
//! On the other hand, they may be used directly by the bechmarking module.
// Since this is test code it's fine that not everything is used
#![allow(dead_code)]
use crate::finality::FinalityVotes;
use crate::validators::CHANGE_EVENT_HASH;
use crate::verification::calculate_score;
use crate::{HeaderToImport, Storage};
use primitives::{
rlp_encode,
signatures::{secret_to_address, sign, SignHeader},
Address, Bloom, Header, SealedEmptyStep, H256, U256,
Address, Bloom, Header, Receipt, SealedEmptyStep, H256, U256,
};
use secp256k1::SecretKey;
use sp_std::prelude::*;
@@ -206,6 +212,39 @@ where
custom_header.sign_by(author)
}
/// Insert unverified header into storage.
pub fn insert_header<S: Storage>(storage: &mut S, header: Header) {
storage.insert_header(HeaderToImport {
context: storage.import_context(None, &header.parent_hash).unwrap(),
is_best: true,
id: header.compute_id(),
header,
total_difficulty: 0.into(),
enacted_change: None,
scheduled_change: None,
finality_votes: FinalityVotes::default(),
});
}
pub fn validators_change_receipt(parent_hash: H256) -> Receipt {
use primitives::{LogEntry, TransactionOutcome};
Receipt {
gas_used: 0.into(),
log_bloom: (&[0xff; 256]).into(),
outcome: TransactionOutcome::Unknown,
logs: vec![LogEntry {
address: [3; 20].into(),
topics: vec![CHANGE_EVENT_HASH.into(), parent_hash],
data: vec![
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
],
}],
}
}
pub mod validator_utils {
use super::*;