Set StateBackend::Transaction to PrefixedMemoryDB (#14612)

* Yep

* Try to get it working everywhere

* Make `from_raw_storage` start with an empty db

* More fixes!

* Make everything compile

* Fix `child_storage_root`

* Fix after merge

* Cleanups

* Update primitives/state-machine/src/overlayed_changes/mod.rs

Co-authored-by: Davide Galassi <davxy@datawok.net>

* Review comments

* Fix issues

* Silence warning

* FMT

* Clippy

---------

Co-authored-by: Davide Galassi <davxy@datawok.net>
This commit is contained in:
Bastian Köcher
2023-08-17 12:49:38 +02:00
committed by GitHub
parent a892fa7f92
commit ecf8035da6
67 changed files with 750 additions and 1150 deletions
+12 -32
View File
@@ -21,7 +21,7 @@
use super::*;
use authorship::claim_slot;
use sc_block_builder::{BlockBuilder, BlockBuilderProvider};
use sc_client_api::{backend::TransactionFor, BlockchainEvents, Finalizer};
use sc_client_api::{BlockchainEvents, Finalizer};
use sc_consensus::{BoxBlockImport, BoxJustificationImport};
use sc_consensus_epochs::{EpochIdentifier, EpochIdentifierPosition};
use sc_consensus_slots::BackoffAuthoringOnFinalizedHeadLagging;
@@ -97,16 +97,7 @@ impl DummyProposer {
fn propose_with(
&mut self,
pre_digests: Digest,
) -> future::Ready<
Result<
Proposal<
TestBlock,
sc_client_api::TransactionFor<substrate_test_runtime_client::Backend, TestBlock>,
(),
>,
Error,
>,
> {
) -> future::Ready<Result<Proposal<TestBlock, ()>, Error>> {
let block_builder =
self.factory.client.new_block_at(self.parent_hash, pre_digests, false).unwrap();
@@ -124,9 +115,7 @@ impl DummyProposer {
impl Proposer<TestBlock> for DummyProposer {
type Error = Error;
type Transaction =
sc_client_api::TransactionFor<substrate_test_runtime_client::Backend, TestBlock>;
type Proposal = future::Ready<Result<Proposal<TestBlock, Self::Transaction, ()>, Error>>;
type Proposal = future::Ready<Result<Proposal<TestBlock, ()>, Error>>;
type ProofRecording = DisableProofRecording;
type Proof = ();
@@ -151,15 +140,13 @@ pub struct PanickingBlockImport<B>(B);
#[async_trait::async_trait]
impl<B: BlockImport<TestBlock>> BlockImport<TestBlock> for PanickingBlockImport<B>
where
B::Transaction: Send,
B: Send,
{
type Error = B::Error;
type Transaction = B::Transaction;
async fn import_block(
&mut self,
block: BlockImportParams<TestBlock, Self::Transaction>,
block: BlockImportParams<TestBlock>,
) -> Result<ImportResult, Self::Error> {
Ok(self.0.import_block(block).await.expect("importing block failed"))
}
@@ -207,8 +194,8 @@ impl Verifier<TestBlock> for TestVerifier {
/// presented to the User in the logs.
async fn verify(
&mut self,
mut block: BlockImportParams<TestBlock, ()>,
) -> Result<BlockImportParams<TestBlock, ()>, String> {
mut block: BlockImportParams<TestBlock>,
) -> Result<BlockImportParams<TestBlock>, String> {
// apply post-sealing mutations (i.e. stripping seal, if desired).
(self.mutator)(&mut block.header, Stage::PostSeal);
self.inner.verify(block).await
@@ -217,14 +204,7 @@ impl Verifier<TestBlock> for TestVerifier {
pub struct PeerData {
link: BabeLink<TestBlock>,
block_import: Mutex<
Option<
BoxBlockImport<
TestBlock,
TransactionFor<substrate_test_runtime_client::Backend, TestBlock>,
>,
>,
>,
block_import: Mutex<Option<BoxBlockImport<TestBlock>>>,
}
impl TestNetFactory for BabeTestNet {
@@ -249,7 +229,7 @@ impl TestNetFactory for BabeTestNet {
let block_import = PanickingBlockImport(block_import);
let data_block_import =
Mutex::new(Some(Box::new(block_import.clone()) as BoxBlockImport<_, _>));
Mutex::new(Some(Box::new(block_import.clone()) as BoxBlockImport<_>));
(
BlockImportAdapter::new(block_import),
None,
@@ -630,11 +610,11 @@ fn claim_vrf_check() {
}
// Propose and import a new BABE block on top of the given parent.
async fn propose_and_import_block<Transaction: Send + 'static>(
async fn propose_and_import_block(
parent: &TestHeader,
slot: Option<Slot>,
proposer_factory: &mut DummyFactory,
block_import: &mut BoxBlockImport<TestBlock, Transaction>,
block_import: &mut BoxBlockImport<TestBlock>,
) -> Hash {
let mut proposer = proposer_factory.init(parent).await.unwrap();
@@ -701,10 +681,10 @@ async fn propose_and_import_block<Transaction: Send + 'static>(
// Propose and import n valid BABE blocks that are built on top of the given parent.
// The proposer takes care of producing epoch change digests according to the epoch
// duration (which is set to 6 slots in the test runtime).
async fn propose_and_import_blocks<Transaction: Send + 'static>(
async fn propose_and_import_blocks(
client: &PeersFullClient,
proposer_factory: &mut DummyFactory,
block_import: &mut BoxBlockImport<TestBlock, Transaction>,
block_import: &mut BoxBlockImport<TestBlock>,
parent_hash: Hash,
n: usize,
) -> Vec<Hash> {