mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 00:31:02 +00:00
Fix Ethereum pallet benchmarks (#601)
This commit is contained in:
committed by
Bastian Köcher
parent
5ed92180bb
commit
481a3fff19
@@ -133,7 +133,7 @@ pub(crate) fn prepare_environment_for_claim<T: pallet_bridge_eth_poa::Config<I>,
|
||||
) -> bp_eth_poa::H256 {
|
||||
use bp_eth_poa::compute_merkle_root;
|
||||
use pallet_bridge_eth_poa::{
|
||||
test_utils::{insert_header, validator_utils::validator, HeaderBuilder},
|
||||
test_utils::{insert_dummy_header, validator_utils::validator, HeaderBuilder},
|
||||
BridgeStorage, Storage,
|
||||
};
|
||||
|
||||
@@ -143,7 +143,7 @@ pub(crate) fn prepare_environment_for_claim<T: pallet_bridge_eth_poa::Config<I>,
|
||||
.receipts_root(compute_merkle_root(transactions.iter().map(|(_, receipt)| receipt)))
|
||||
.sign_by(&validator(0));
|
||||
let header_id = header.compute_id();
|
||||
insert_header(&mut storage, header);
|
||||
insert_dummy_header(&mut storage, header);
|
||||
storage.finalize_and_prune_headers(Some(header_id), 0);
|
||||
|
||||
header_id.hash
|
||||
|
||||
@@ -140,7 +140,7 @@ fn is_finalized(
|
||||
}
|
||||
|
||||
/// Prepare 'votes' of header and its ancestors' signers.
|
||||
fn prepare_votes<Submitter>(
|
||||
pub(crate) fn prepare_votes<Submitter>(
|
||||
mut cached_votes: CachedFinalityVotes<Submitter>,
|
||||
best_finalized: HeaderId,
|
||||
validators: &BTreeSet<&Address>,
|
||||
|
||||
@@ -1049,6 +1049,7 @@ pub(crate) mod tests {
|
||||
genesis, insert_header, run_test, run_test_with_genesis, validators_addresses, HeaderBuilder, TestRuntime,
|
||||
GAS_LIMIT,
|
||||
};
|
||||
use crate::test_utils::validator_utils::*;
|
||||
use bp_eth_poa::compute_merkle_root;
|
||||
|
||||
const TOTAL_VALIDATORS: usize = 3;
|
||||
@@ -1069,33 +1070,24 @@ pub(crate) mod tests {
|
||||
}
|
||||
|
||||
fn example_header_with_failed_receipt() -> AuraHeader {
|
||||
AuraHeader {
|
||||
number: 3,
|
||||
transactions_root: compute_merkle_root(vec![example_tx()].into_iter()),
|
||||
receipts_root: compute_merkle_root(vec![example_tx_receipt(false)].into_iter()),
|
||||
parent_hash: example_header().compute_hash(),
|
||||
..Default::default()
|
||||
}
|
||||
HeaderBuilder::with_parent(&example_header())
|
||||
.transactions_root(compute_merkle_root(vec![example_tx()].into_iter()))
|
||||
.receipts_root(compute_merkle_root(vec![example_tx_receipt(false)].into_iter()))
|
||||
.sign_by(&validator(0))
|
||||
}
|
||||
|
||||
fn example_header() -> AuraHeader {
|
||||
AuraHeader {
|
||||
number: 2,
|
||||
transactions_root: compute_merkle_root(vec![example_tx()].into_iter()),
|
||||
receipts_root: compute_merkle_root(vec![example_tx_receipt(true)].into_iter()),
|
||||
parent_hash: example_header_parent().compute_hash(),
|
||||
..Default::default()
|
||||
}
|
||||
HeaderBuilder::with_parent(&example_header_parent())
|
||||
.transactions_root(compute_merkle_root(vec![example_tx()].into_iter()))
|
||||
.receipts_root(compute_merkle_root(vec![example_tx_receipt(true)].into_iter()))
|
||||
.sign_by(&validator(0))
|
||||
}
|
||||
|
||||
fn example_header_parent() -> AuraHeader {
|
||||
AuraHeader {
|
||||
number: 1,
|
||||
transactions_root: compute_merkle_root(vec![example_tx()].into_iter()),
|
||||
receipts_root: compute_merkle_root(vec![example_tx_receipt(true)].into_iter()),
|
||||
parent_hash: genesis().compute_hash(),
|
||||
..Default::default()
|
||||
}
|
||||
HeaderBuilder::with_parent(&genesis())
|
||||
.transactions_root(compute_merkle_root(vec![example_tx()].into_iter()))
|
||||
.receipts_root(compute_merkle_root(vec![example_tx_receipt(true)].into_iter()))
|
||||
.sign_by(&validator(0))
|
||||
}
|
||||
|
||||
fn with_headers_to_prune<T>(f: impl Fn(BridgeStorage<TestRuntime>) -> T) -> T {
|
||||
@@ -1277,10 +1269,7 @@ pub(crate) mod tests {
|
||||
let header_with_entry = HeaderBuilder::with_parent_number(interval - 1).sign_by_set(&ctx.validators);
|
||||
let header_with_entry_hash = header_with_entry.compute_hash();
|
||||
insert_header(&mut storage, header_with_entry);
|
||||
assert_eq!(
|
||||
FinalityCache::<TestRuntime>::get(&header_with_entry_hash),
|
||||
Some(Default::default()),
|
||||
);
|
||||
assert!(FinalityCache::<TestRuntime>::get(&header_with_entry_hash).is_some());
|
||||
|
||||
// when we later prune this header, cache entry is removed
|
||||
BlocksToPrune::<DefaultInstance>::put(PruningRange {
|
||||
|
||||
@@ -228,7 +228,41 @@ where
|
||||
}
|
||||
|
||||
/// Insert unverified header into storage.
|
||||
///
|
||||
/// This function assumes that the header is signed by validator from the current set.
|
||||
pub fn insert_header<S: Storage>(storage: &mut S, header: AuraHeader) {
|
||||
let id = header.compute_id();
|
||||
let best_finalized = storage.finalized_block();
|
||||
let import_context = storage.import_context(None, &header.parent_hash).unwrap();
|
||||
let parent_finality_votes = storage.cached_finality_votes(&header.parent_id().unwrap(), &best_finalized, |_| false);
|
||||
let finality_votes = crate::finality::prepare_votes(
|
||||
parent_finality_votes,
|
||||
best_finalized,
|
||||
&import_context.validators_set().validators.iter().collect(),
|
||||
id,
|
||||
&header,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
storage.insert_header(HeaderToImport {
|
||||
context: storage.import_context(None, &header.parent_hash).unwrap(),
|
||||
is_best: true,
|
||||
id,
|
||||
header,
|
||||
total_difficulty: 0.into(),
|
||||
enacted_change: None,
|
||||
scheduled_change: None,
|
||||
finality_votes,
|
||||
});
|
||||
}
|
||||
|
||||
/// Insert unverified header into storage.
|
||||
///
|
||||
/// No assumptions about header author are made. The cost is that finality votes cache
|
||||
/// is filled incorrectly, so this function shall not be used if you're going to insert
|
||||
/// (or import) header descendants.
|
||||
pub fn insert_dummy_header<S: Storage>(storage: &mut S, header: AuraHeader) {
|
||||
storage.insert_header(HeaderToImport {
|
||||
context: storage.import_context(None, &header.parent_hash).unwrap(),
|
||||
is_best: true,
|
||||
|
||||
Reference in New Issue
Block a user