Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit ecd503d

Browse files
bkchrdavxy
andauthored
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>
1 parent ec6be6e commit ecd503d

File tree

67 files changed

+747
-1147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+747
-1147
lines changed

Cargo.lock

Lines changed: 7 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/node-template/node/src/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn new_partial(
4949
FullClient,
5050
FullBackend,
5151
FullSelectChain,
52-
sc_consensus::DefaultImportQueue<Block, FullClient>,
52+
sc_consensus::DefaultImportQueue<Block>,
5353
sc_transaction_pool::FullPool<Block, FullClient>,
5454
(
5555
sc_consensus_grandpa::GrandpaBlockImport<

bin/node/cli/benches/block_production.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,7 @@ fn extrinsic_set_time(now: u64) -> OpaqueExtrinsic {
112112
.into()
113113
}
114114

115-
fn import_block(
116-
mut client: &FullClient,
117-
built: BuiltBlock<
118-
node_primitives::Block,
119-
<FullClient as sp_api::CallApiAt<node_primitives::Block>>::StateBackend,
120-
>,
121-
) {
115+
fn import_block(mut client: &FullClient, built: BuiltBlock<node_primitives::Block>) {
122116
let mut params = BlockImportParams::new(BlockOrigin::File, built.block.header);
123117
params.state_action =
124118
StateAction::ApplyChanges(sc_consensus::StorageChanges::Changes(built.storage_changes));

bin/node/cli/src/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub fn new_partial(
140140
FullClient,
141141
FullBackend,
142142
FullSelectChain,
143-
sc_consensus::DefaultImportQueue<Block, FullClient>,
143+
sc_consensus::DefaultImportQueue<Block>,
144144
sc_transaction_pool::FullPool<Block, FullClient>,
145145
(
146146
impl Fn(

bin/node/testing/src/client.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ pub type Client = client::Client<
3636
kitchensink_runtime::RuntimeApi,
3737
>;
3838

39-
/// Transaction for kitchensink-runtime.
40-
pub type Transaction = sc_client_api::backend::TransactionFor<Backend, node_primitives::Block>;
41-
4239
/// Genesis configuration parameters for `TestClient`.
4340
#[derive(Default)]
4441
pub struct GenesisParameters;

client/api/src/backend.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,11 @@ use sp_storage::{ChildInfo, StorageData, StorageKey};
3636

3737
use crate::{blockchain::Backend as BlockchainBackend, UsageInfo};
3838

39-
pub use sp_state_machine::{Backend as StateBackend, KeyValueStates};
39+
pub use sp_state_machine::{Backend as StateBackend, BackendTransaction, KeyValueStates};
4040

4141
/// Extracts the state backend type for the given backend.
4242
pub type StateBackendFor<B, Block> = <B as Backend<Block>>::State;
4343

44-
/// Extracts the transaction for the given state backend.
45-
pub type TransactionForSB<B, Block> = <B as StateBackend<HashingFor<Block>>>::Transaction;
46-
47-
/// Extracts the transaction for the given backend.
48-
pub type TransactionFor<B, Block> = TransactionForSB<StateBackendFor<B, Block>, Block>;
49-
5044
/// Describes which block import notification stream should be notified.
5145
#[derive(Debug, Clone, Copy)]
5246
pub enum ImportNotificationAction {
@@ -181,7 +175,7 @@ pub trait BlockImportOperation<Block: BlockT> {
181175
/// Inject storage data into the database.
182176
fn update_db_storage(
183177
&mut self,
184-
update: TransactionForSB<Self::State, Block>,
178+
update: BackendTransaction<HashingFor<Block>>,
185179
) -> sp_blockchain::Result<()>;
186180

187181
/// Set genesis state. If `commit` is `false` the state is saved in memory, but is not written

client/api/src/call_executor.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use sp_state_machine::{OverlayedChanges, StorageProof};
2626
use std::cell::RefCell;
2727

2828
use crate::execution_extensions::ExecutionExtensions;
29-
use sp_api::{ProofRecorder, StorageTransactionCache};
29+
use sp_api::{HashingFor, ProofRecorder};
3030

3131
/// Executor Provider
3232
pub trait ExecutorProvider<Block: BlockT> {
@@ -72,12 +72,7 @@ pub trait CallExecutor<B: BlockT>: RuntimeVersionOf {
7272
at_hash: B::Hash,
7373
method: &str,
7474
call_data: &[u8],
75-
changes: &RefCell<OverlayedChanges>,
76-
storage_transaction_cache: Option<
77-
&RefCell<
78-
StorageTransactionCache<B, <Self::Backend as crate::backend::Backend<B>>::State>,
79-
>,
80-
>,
75+
changes: &RefCell<OverlayedChanges<HashingFor<B>>>,
8176
proof_recorder: &Option<ProofRecorder<B>>,
8277
call_context: CallContext,
8378
extensions: &RefCell<Extensions>,

client/api/src/in_mem.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use sp_runtime::{
2929
Justification, Justifications, StateVersion, Storage,
3030
};
3131
use sp_state_machine::{
32-
Backend as StateBackend, ChildStorageCollection, InMemoryBackend, IndexOperation,
33-
StorageCollection,
32+
Backend as StateBackend, BackendTransaction, ChildStorageCollection, InMemoryBackend,
33+
IndexOperation, StorageCollection,
3434
};
3535
use std::{
3636
collections::{HashMap, HashSet},
@@ -480,9 +480,7 @@ impl<Block: BlockT> backend::AuxStore for Blockchain<Block> {
480480
pub struct BlockImportOperation<Block: BlockT> {
481481
pending_block: Option<PendingBlock<Block>>,
482482
old_state: InMemoryBackend<HashingFor<Block>>,
483-
new_state: Option<
484-
<InMemoryBackend<HashingFor<Block>> as StateBackend<HashingFor<Block>>>::Transaction,
485-
>,
483+
new_state: Option<BackendTransaction<HashingFor<Block>>>,
486484
aux: Vec<(Vec<u8>, Option<Vec<u8>>)>,
487485
finalized_blocks: Vec<(Block::Hash, Option<Justification>)>,
488486
set_head: Option<Block::Hash>,
@@ -540,7 +538,7 @@ impl<Block: BlockT> backend::BlockImportOperation<Block> for BlockImportOperatio
540538

541539
fn update_db_storage(
542540
&mut self,
543-
update: <InMemoryBackend<HashingFor<Block>> as StateBackend<HashingFor<Block>>>::Transaction,
541+
update: BackendTransaction<HashingFor<Block>>,
544542
) -> sp_blockchain::Result<()> {
545543
self.new_state = Some(update);
546544
Ok(())

client/basic-authorship/src/basic_authorship.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ where
187187
+ Send
188188
+ Sync
189189
+ 'static,
190-
C::Api:
191-
ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>> + BlockBuilderApi<Block>,
190+
C::Api: ApiExt<Block> + BlockBuilderApi<Block>,
192191
{
193192
fn init_with_now(
194193
&mut self,
@@ -229,8 +228,7 @@ where
229228
+ Send
230229
+ Sync
231230
+ 'static,
232-
C::Api:
233-
ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>> + BlockBuilderApi<Block>,
231+
C::Api: ApiExt<Block> + BlockBuilderApi<Block>,
234232
PR: ProofRecording,
235233
{
236234
type CreateProposer = future::Ready<Result<Self::Proposer, Self::Error>>;
@@ -269,17 +267,11 @@ where
269267
+ Send
270268
+ Sync
271269
+ 'static,
272-
C::Api:
273-
ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>> + BlockBuilderApi<Block>,
270+
C::Api: ApiExt<Block> + BlockBuilderApi<Block>,
274271
PR: ProofRecording,
275272
{
276-
type Transaction = backend::TransactionFor<B, Block>;
277-
type Proposal = Pin<
278-
Box<
279-
dyn Future<Output = Result<Proposal<Block, Self::Transaction, PR::Proof>, Self::Error>>
280-
+ Send,
281-
>,
282-
>;
273+
type Proposal =
274+
Pin<Box<dyn Future<Output = Result<Proposal<Block, PR::Proof>, Self::Error>> + Send>>;
283275
type Error = sp_blockchain::Error;
284276
type ProofRecording = PR;
285277
type Proof = PR::Proof;
@@ -332,8 +324,7 @@ where
332324
+ Send
333325
+ Sync
334326
+ 'static,
335-
C::Api:
336-
ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>> + BlockBuilderApi<Block>,
327+
C::Api: ApiExt<Block> + BlockBuilderApi<Block>,
337328
PR: ProofRecording,
338329
{
339330
async fn propose_with(
@@ -342,8 +333,7 @@ where
342333
inherent_digests: Digest,
343334
deadline: time::Instant,
344335
block_size_limit: Option<usize>,
345-
) -> Result<Proposal<Block, backend::TransactionFor<B, Block>, PR::Proof>, sp_blockchain::Error>
346-
{
336+
) -> Result<Proposal<Block, PR::Proof>, sp_blockchain::Error> {
347337
let propose_with_timer = time::Instant::now();
348338
let mut block_builder =
349339
self.client.new_block_at(self.parent_hash, inherent_digests, PR::ENABLED)?;

client/block-builder/src/lib.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,18 @@ impl From<bool> for RecordProof {
8585
/// backend to get the state of the block. Furthermore an optional `proof` is included which
8686
/// can be used to proof that the build block contains the expected data. The `proof` will
8787
/// only be set when proof recording was activated.
88-
pub struct BuiltBlock<Block: BlockT, StateBackend: backend::StateBackend<HashingFor<Block>>> {
88+
pub struct BuiltBlock<Block: BlockT> {
8989
/// The actual block that was build.
9090
pub block: Block,
9191
/// The changes that need to be applied to the backend to get the state of the build block.
92-
pub storage_changes: StorageChanges<StateBackend, Block>,
92+
pub storage_changes: StorageChanges<Block>,
9393
/// An optional proof that was recorded while building the block.
9494
pub proof: Option<StorageProof>,
9595
}
9696

97-
impl<Block: BlockT, StateBackend: backend::StateBackend<HashingFor<Block>>>
98-
BuiltBlock<Block, StateBackend>
99-
{
97+
impl<Block: BlockT> BuiltBlock<Block> {
10098
/// Convert into the inner values.
101-
pub fn into_inner(self) -> (Block, StorageChanges<StateBackend, Block>, Option<StorageProof>) {
99+
pub fn into_inner(self) -> (Block, StorageChanges<Block>, Option<StorageProof>) {
102100
(self.block, self.storage_changes, self.proof)
103101
}
104102
}
@@ -145,8 +143,7 @@ impl<'a, Block, A, B> BlockBuilder<'a, Block, A, B>
145143
where
146144
Block: BlockT,
147145
A: ProvideRuntimeApi<Block> + 'a,
148-
A::Api:
149-
BlockBuilderApi<Block> + ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>>,
146+
A::Api: BlockBuilderApi<Block> + ApiExt<Block>,
150147
B: backend::Backend<Block>,
151148
{
152149
/// Create a new instance of builder based on the given `parent_hash` and `parent_number`.
@@ -231,7 +228,7 @@ where
231228
/// Returns the build `Block`, the changes to the storage and an optional `StorageProof`
232229
/// supplied by `self.api`, combined as [`BuiltBlock`].
233230
/// The storage proof will be `Some(_)` when proof recording was enabled.
234-
pub fn build(mut self) -> Result<BuiltBlock<Block, backend::StateBackendFor<B, Block>>, Error> {
231+
pub fn build(mut self) -> Result<BuiltBlock<Block>, Error> {
235232
let header = self.api.finalize_block(self.parent_hash)?;
236233

237234
debug_assert_eq!(

0 commit comments

Comments
 (0)