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 {
|
) -> bp_eth_poa::H256 {
|
||||||
use bp_eth_poa::compute_merkle_root;
|
use bp_eth_poa::compute_merkle_root;
|
||||||
use pallet_bridge_eth_poa::{
|
use pallet_bridge_eth_poa::{
|
||||||
test_utils::{insert_header, validator_utils::validator, HeaderBuilder},
|
test_utils::{insert_dummy_header, validator_utils::validator, HeaderBuilder},
|
||||||
BridgeStorage, Storage,
|
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)))
|
.receipts_root(compute_merkle_root(transactions.iter().map(|(_, receipt)| receipt)))
|
||||||
.sign_by(&validator(0));
|
.sign_by(&validator(0));
|
||||||
let header_id = header.compute_id();
|
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);
|
storage.finalize_and_prune_headers(Some(header_id), 0);
|
||||||
|
|
||||||
header_id.hash
|
header_id.hash
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ fn is_finalized(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Prepare 'votes' of header and its ancestors' signers.
|
/// Prepare 'votes' of header and its ancestors' signers.
|
||||||
fn prepare_votes<Submitter>(
|
pub(crate) fn prepare_votes<Submitter>(
|
||||||
mut cached_votes: CachedFinalityVotes<Submitter>,
|
mut cached_votes: CachedFinalityVotes<Submitter>,
|
||||||
best_finalized: HeaderId,
|
best_finalized: HeaderId,
|
||||||
validators: &BTreeSet<&Address>,
|
validators: &BTreeSet<&Address>,
|
||||||
|
|||||||
@@ -1049,6 +1049,7 @@ pub(crate) mod tests {
|
|||||||
genesis, insert_header, run_test, run_test_with_genesis, validators_addresses, HeaderBuilder, TestRuntime,
|
genesis, insert_header, run_test, run_test_with_genesis, validators_addresses, HeaderBuilder, TestRuntime,
|
||||||
GAS_LIMIT,
|
GAS_LIMIT,
|
||||||
};
|
};
|
||||||
|
use crate::test_utils::validator_utils::*;
|
||||||
use bp_eth_poa::compute_merkle_root;
|
use bp_eth_poa::compute_merkle_root;
|
||||||
|
|
||||||
const TOTAL_VALIDATORS: usize = 3;
|
const TOTAL_VALIDATORS: usize = 3;
|
||||||
@@ -1069,33 +1070,24 @@ pub(crate) mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn example_header_with_failed_receipt() -> AuraHeader {
|
fn example_header_with_failed_receipt() -> AuraHeader {
|
||||||
AuraHeader {
|
HeaderBuilder::with_parent(&example_header())
|
||||||
number: 3,
|
.transactions_root(compute_merkle_root(vec![example_tx()].into_iter()))
|
||||||
transactions_root: compute_merkle_root(vec![example_tx()].into_iter()),
|
.receipts_root(compute_merkle_root(vec![example_tx_receipt(false)].into_iter()))
|
||||||
receipts_root: compute_merkle_root(vec![example_tx_receipt(false)].into_iter()),
|
.sign_by(&validator(0))
|
||||||
parent_hash: example_header().compute_hash(),
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn example_header() -> AuraHeader {
|
fn example_header() -> AuraHeader {
|
||||||
AuraHeader {
|
HeaderBuilder::with_parent(&example_header_parent())
|
||||||
number: 2,
|
.transactions_root(compute_merkle_root(vec![example_tx()].into_iter()))
|
||||||
transactions_root: compute_merkle_root(vec![example_tx()].into_iter()),
|
.receipts_root(compute_merkle_root(vec![example_tx_receipt(true)].into_iter()))
|
||||||
receipts_root: compute_merkle_root(vec![example_tx_receipt(true)].into_iter()),
|
.sign_by(&validator(0))
|
||||||
parent_hash: example_header_parent().compute_hash(),
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn example_header_parent() -> AuraHeader {
|
fn example_header_parent() -> AuraHeader {
|
||||||
AuraHeader {
|
HeaderBuilder::with_parent(&genesis())
|
||||||
number: 1,
|
.transactions_root(compute_merkle_root(vec![example_tx()].into_iter()))
|
||||||
transactions_root: compute_merkle_root(vec![example_tx()].into_iter()),
|
.receipts_root(compute_merkle_root(vec![example_tx_receipt(true)].into_iter()))
|
||||||
receipts_root: compute_merkle_root(vec![example_tx_receipt(true)].into_iter()),
|
.sign_by(&validator(0))
|
||||||
parent_hash: genesis().compute_hash(),
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_headers_to_prune<T>(f: impl Fn(BridgeStorage<TestRuntime>) -> T) -> T {
|
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 = HeaderBuilder::with_parent_number(interval - 1).sign_by_set(&ctx.validators);
|
||||||
let header_with_entry_hash = header_with_entry.compute_hash();
|
let header_with_entry_hash = header_with_entry.compute_hash();
|
||||||
insert_header(&mut storage, header_with_entry);
|
insert_header(&mut storage, header_with_entry);
|
||||||
assert_eq!(
|
assert!(FinalityCache::<TestRuntime>::get(&header_with_entry_hash).is_some());
|
||||||
FinalityCache::<TestRuntime>::get(&header_with_entry_hash),
|
|
||||||
Some(Default::default()),
|
|
||||||
);
|
|
||||||
|
|
||||||
// when we later prune this header, cache entry is removed
|
// when we later prune this header, cache entry is removed
|
||||||
BlocksToPrune::<DefaultInstance>::put(PruningRange {
|
BlocksToPrune::<DefaultInstance>::put(PruningRange {
|
||||||
|
|||||||
@@ -228,7 +228,41 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Insert unverified header into storage.
|
/// 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) {
|
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 {
|
storage.insert_header(HeaderToImport {
|
||||||
context: storage.import_context(None, &header.parent_hash).unwrap(),
|
context: storage.import_context(None, &header.parent_hash).unwrap(),
|
||||||
is_best: true,
|
is_best: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user