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
@@ -30,9 +30,6 @@ pub mod timestamp;
/// Consensus data provider, manual seal uses this trait object for authoring blocks valid
/// for any runtime.
pub trait ConsensusDataProvider<B: BlockT>: Send + Sync {
/// Block import transaction type
type Transaction;
/// The proof type.
type Proof;
@@ -43,7 +40,7 @@ pub trait ConsensusDataProvider<B: BlockT>: Send + Sync {
fn append_block_import(
&self,
parent: &B::Header,
params: &mut BlockImportParams<B, Self::Transaction>,
params: &mut BlockImportParams<B>,
inherents: &InherentData,
proof: Self::Proof,
) -> Result<(), Error>;
@@ -22,7 +22,7 @@
use crate::{ConsensusDataProvider, Error};
use sc_client_api::{AuxStore, UsageProvider};
use sc_consensus::BlockImportParams;
use sp_api::{ProvideRuntimeApi, TransactionFor};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::{HeaderBackend, HeaderMetadata};
use sp_consensus_aura::{
digests::CompatibleDigestItem,
@@ -69,7 +69,6 @@ where
C::Api: AuraApi<B, AuthorityId>,
P: Send + Sync,
{
type Transaction = TransactionFor<C, B>;
type Proof = P;
fn create_digest(
@@ -92,7 +91,7 @@ where
fn append_block_import(
&self,
_parent: &B::Header,
_params: &mut BlockImportParams<B, Self::Transaction>,
_params: &mut BlockImportParams<B>,
_inherents: &InherentData,
_proof: Self::Proof,
) -> Result<(), Error> {
@@ -33,7 +33,7 @@ use sp_keystore::KeystorePtr;
use std::{marker::PhantomData, sync::Arc};
use sc_consensus::{BlockImportParams, ForkChoiceStrategy, Verifier};
use sp_api::{ProvideRuntimeApi, TransactionFor};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::{HeaderBackend, HeaderMetadata};
use sp_consensus_babe::{
digests::{NextEpochDescriptor, PreDigest, SecondaryPlainPreDigest},
@@ -97,8 +97,8 @@ where
{
async fn verify(
&mut self,
mut import_params: BlockImportParams<B, ()>,
) -> Result<BlockImportParams<B, ()>, String> {
mut import_params: BlockImportParams<B>,
) -> Result<BlockImportParams<B>, String> {
import_params.finalized = false;
import_params.fork_choice = Some(ForkChoiceStrategy::LongestChain);
@@ -197,7 +197,6 @@ where
C::Api: BabeApi<B>,
P: Send + Sync,
{
type Transaction = TransactionFor<C, B>;
type Proof = P;
fn create_digest(&self, parent: &B::Header, inherents: &InherentData) -> Result<Digest, Error> {
@@ -264,7 +263,7 @@ where
fn append_block_import(
&self,
parent: &B::Header,
params: &mut BlockImportParams<B, Self::Transaction>,
params: &mut BlockImportParams<B>,
inherents: &InherentData,
_proof: Self::Proof,
) -> Result<(), Error> {
@@ -52,7 +52,7 @@ pub use self::{
seal_block::{seal_block, SealBlockParams, MAX_PROPOSAL_DURATION},
};
use sc_transaction_pool_api::TransactionPool;
use sp_api::{ProvideRuntimeApi, TransactionFor};
use sp_api::ProvideRuntimeApi;
const LOG_TARGET: &str = "manual-seal";
@@ -66,8 +66,8 @@ struct ManualSealVerifier;
impl<B: BlockT> Verifier<B> for ManualSealVerifier {
async fn verify(
&mut self,
mut block: BlockImportParams<B, ()>,
) -> Result<BlockImportParams<B, ()>, String> {
mut block: BlockImportParams<B>,
) -> Result<BlockImportParams<B>, String> {
block.finalized = false;
block.fork_choice = Some(ForkChoiceStrategy::LongestChain);
Ok(block)
@@ -75,14 +75,13 @@ impl<B: BlockT> Verifier<B> for ManualSealVerifier {
}
/// Instantiate the import queue for the manual seal consensus engine.
pub fn import_queue<Block, Transaction>(
block_import: BoxBlockImport<Block, Transaction>,
pub fn import_queue<Block>(
block_import: BoxBlockImport<Block>,
spawner: &impl sp_core::traits::SpawnEssentialNamed,
registry: Option<&Registry>,
) -> BasicQueue<Block, Transaction>
) -> BasicQueue<Block>
where
Block: BlockT,
Transaction: Send + Sync + 'static,
{
BasicQueue::new(ManualSealVerifier, block_import, None, spawner, registry)
}
@@ -109,8 +108,7 @@ pub struct ManualSealParams<B: BlockT, BI, E, C: ProvideRuntimeApi<B>, TP, SC, C
pub select_chain: SC,
/// Digest provider for inclusion in blocks.
pub consensus_data_provider:
Option<Box<dyn ConsensusDataProvider<B, Proof = P, Transaction = TransactionFor<C, B>>>>,
pub consensus_data_provider: Option<Box<dyn ConsensusDataProvider<B, Proof = P>>>,
/// Something that can create the inherent data providers.
pub create_inherent_data_providers: CIDP,
@@ -134,8 +132,7 @@ pub struct InstantSealParams<B: BlockT, BI, E, C: ProvideRuntimeApi<B>, TP, SC,
pub select_chain: SC,
/// Digest provider for inclusion in blocks.
pub consensus_data_provider:
Option<Box<dyn ConsensusDataProvider<B, Proof = P, Transaction = TransactionFor<C, B>>>>,
pub consensus_data_provider: Option<Box<dyn ConsensusDataProvider<B, Proof = P>>>,
/// Something that can create the inherent data providers.
pub create_inherent_data_providers: CIDP,
@@ -167,17 +164,13 @@ pub async fn run_manual_seal<B, BI, CB, E, C, TP, SC, CS, CIDP, P>(
}: ManualSealParams<B, BI, E, C, TP, SC, CS, CIDP, P>,
) where
B: BlockT + 'static,
BI: BlockImport<B, Error = sp_consensus::Error, Transaction = sp_api::TransactionFor<C, B>>
+ Send
+ Sync
+ 'static,
BI: BlockImport<B, Error = sp_consensus::Error> + Send + Sync + 'static,
C: HeaderBackend<B> + Finalizer<B, CB> + ProvideRuntimeApi<B> + 'static,
CB: ClientBackend<B> + 'static,
E: Environment<B> + 'static,
E::Proposer: Proposer<B, Proof = P, Transaction = TransactionFor<C, B>>,
E::Proposer: Proposer<B, Proof = P>,
CS: Stream<Item = EngineCommand<<B as BlockT>::Hash>> + Unpin + 'static,
SC: SelectChain<B> + 'static,
TransactionFor<C, B>: 'static,
TP: TransactionPool<Block = B>,
CIDP: CreateInherentDataProviders<B, ()>,
P: Send + Sync + 'static,
@@ -230,16 +223,12 @@ pub async fn run_instant_seal<B, BI, CB, E, C, TP, SC, CIDP, P>(
}: InstantSealParams<B, BI, E, C, TP, SC, CIDP, P>,
) where
B: BlockT + 'static,
BI: BlockImport<B, Error = sp_consensus::Error, Transaction = sp_api::TransactionFor<C, B>>
+ Send
+ Sync
+ 'static,
BI: BlockImport<B, Error = sp_consensus::Error> + Send + Sync + 'static,
C: HeaderBackend<B> + Finalizer<B, CB> + ProvideRuntimeApi<B> + 'static,
CB: ClientBackend<B> + 'static,
E: Environment<B> + 'static,
E::Proposer: Proposer<B, Proof = P, Transaction = TransactionFor<C, B>>,
E::Proposer: Proposer<B, Proof = P>,
SC: SelectChain<B> + 'static,
TransactionFor<C, B>: 'static,
TP: TransactionPool<Block = B>,
CIDP: CreateInherentDataProviders<B, ()>,
P: Send + Sync + 'static,
@@ -284,16 +273,12 @@ pub async fn run_instant_seal_and_finalize<B, BI, CB, E, C, TP, SC, CIDP, P>(
}: InstantSealParams<B, BI, E, C, TP, SC, CIDP, P>,
) where
B: BlockT + 'static,
BI: BlockImport<B, Error = sp_consensus::Error, Transaction = sp_api::TransactionFor<C, B>>
+ Send
+ Sync
+ 'static,
BI: BlockImport<B, Error = sp_consensus::Error> + Send + Sync + 'static,
C: HeaderBackend<B> + Finalizer<B, CB> + ProvideRuntimeApi<B> + 'static,
CB: ClientBackend<B> + 'static,
E: Environment<B> + 'static,
E::Proposer: Proposer<B, Proof = P, Transaction = TransactionFor<C, B>>,
E::Proposer: Proposer<B, Proof = P>,
SC: SelectChain<B> + 'static,
TransactionFor<C, B>: 'static,
TP: TransactionPool<Block = B>,
CIDP: CreateInherentDataProviders<B, ()>,
P: Send + Sync + 'static,
@@ -386,7 +371,6 @@ mod tests {
B: BlockT,
C: ProvideRuntimeApi<B> + Send + Sync,
{
type Transaction = TransactionFor<C, B>;
type Proof = ();
fn create_digest(
@@ -400,7 +384,7 @@ mod tests {
fn append_block_import(
&self,
_parent: &B::Header,
params: &mut BlockImportParams<B, Self::Transaction>,
params: &mut BlockImportParams<B>,
_inherents: &InherentData,
_proof: Self::Proof,
) -> Result<(), Error> {
@@ -22,7 +22,7 @@ use crate::{rpc, ConsensusDataProvider, CreatedBlock, Error};
use futures::prelude::*;
use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy, ImportResult, StateAction};
use sc_transaction_pool_api::TransactionPool;
use sp_api::{ProvideRuntimeApi, TransactionFor};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_consensus::{self, BlockOrigin, Environment, Proposer, SelectChain};
use sp_inherents::{CreateInherentDataProviders, InherentDataProvider};
@@ -52,8 +52,7 @@ pub struct SealBlockParams<'a, B: BlockT, BI, SC, C: ProvideRuntimeApi<B>, E, TP
/// SelectChain object
pub select_chain: &'a SC,
/// Digest provider for inclusion in blocks.
pub consensus_data_provider:
Option<&'a dyn ConsensusDataProvider<B, Proof = P, Transaction = TransactionFor<C, B>>>,
pub consensus_data_provider: Option<&'a dyn ConsensusDataProvider<B, Proof = P>>,
/// block import object
pub block_import: &'a mut BI,
/// Something that can create the inherent data providers.
@@ -77,16 +76,12 @@ pub async fn seal_block<B, BI, SC, C, E, TP, CIDP, P>(
}: SealBlockParams<'_, B, BI, SC, C, E, TP, CIDP, P>,
) where
B: BlockT,
BI: BlockImport<B, Error = sp_consensus::Error, Transaction = sp_api::TransactionFor<C, B>>
+ Send
+ Sync
+ 'static,
BI: BlockImport<B, Error = sp_consensus::Error> + Send + Sync + 'static,
C: HeaderBackend<B> + ProvideRuntimeApi<B>,
E: Environment<B>,
E::Proposer: Proposer<B, Proof = P, Transaction = TransactionFor<C, B>>,
E::Proposer: Proposer<B, Proof = P>,
TP: TransactionPool<Block = B>,
SC: SelectChain<B>,
TransactionFor<C, B>: 'static,
CIDP: CreateInherentDataProviders<B, ()>,
P: Send + Sync + 'static,
{