Refactored in-mem backed to use the actual trie (#5730)

This commit is contained in:
Arkadiy Paronyan
2020-04-23 19:00:36 +02:00
committed by GitHub
parent ca3f54b4af
commit 59f13e6e0d
10 changed files with 180 additions and 305 deletions
+9 -4
View File
@@ -464,7 +464,7 @@ pub struct BlockImportOperation<Block: BlockT> {
pending_block: Option<PendingBlock<Block>>,
pending_cache: HashMap<CacheKeyId, Vec<u8>>,
old_state: InMemoryBackend<HashFor<Block>>,
new_state: Option<InMemoryBackend<HashFor<Block>>>,
new_state: Option<<InMemoryBackend<HashFor<Block>> as StateBackend<HashFor<Block>>>::Transaction>,
aux: Vec<(Vec<u8>, Option<Vec<u8>>)>,
finalized_blocks: Vec<(BlockId<Block>, Option<Justification>)>,
set_head: Option<BlockId<Block>>,
@@ -502,7 +502,7 @@ impl<Block: BlockT> backend::BlockImportOperation<Block> for BlockImportOperatio
&mut self,
update: <InMemoryBackend<HashFor<Block>> as StateBackend<HashFor<Block>>>::Transaction,
) -> sp_blockchain::Result<()> {
self.new_state = Some(self.old_state.update(update));
self.new_state = Some(update);
Ok(())
}
@@ -525,7 +525,7 @@ impl<Block: BlockT> backend::BlockImportOperation<Block> for BlockImportOperatio
child_delta
);
self.new_state = Some(InMemoryBackend::from(transaction));
self.new_state = Some(transaction);
Ok(root)
}
@@ -638,7 +638,12 @@ impl<Block: BlockT> backend::Backend<Block> for Backend<Block> where Block::Hash
let hash = header.hash();
self.states.write().insert(hash, operation.new_state.unwrap_or_else(|| old_state.clone()));
let new_state = match operation.new_state {
Some(state) => old_state.update_backend(*header.state_root(), state),
None => old_state.clone(),
};
self.states.write().insert(hash, new_state);
self.blockchain.insert(hash, header, justification, body, pending_block.state)?;
}