transactional: Wrap pallet::calls directly in storage layers (#11927)

* transactional: Wrap `pallet::calls` directly in storage layers

Before this pr we only wrapped `pallet::calls` into storage layers when executing the calls with
`dispatch`. This pr is solving that by wrapping each call function inside a storage layer.

* Teach `BasicExternalities` transactions support

* Fix crates

* FMT

* Fix benchmarking tests

* Use correct span

* Support old decl macros

* Fix test

* Apply suggestions from code review

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/state-trie-migration/src/lib.rs

* Update frame/state-trie-migration/src/lib.rs

* Update frame/state-trie-migration/src/lib.rs

* Feedback

* Apply suggestions from code review

Co-authored-by: cheme <emericchevalier.pro@gmail.com>

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: cheme <emericchevalier.pro@gmail.com>
This commit is contained in:
Bastian Köcher
2022-08-10 22:27:01 +02:00
committed by GitHub
parent 043b1697c7
commit aa5f68a827
10 changed files with 316 additions and 294 deletions
@@ -57,7 +57,7 @@ pub struct NotInRuntime;
/// Describes in which mode the node is currently executing.
#[derive(Debug, Clone, Copy)]
pub enum ExecutionMode {
/// Exeuting in client mode: Removal of all transactions possible.
/// Executing in client mode: Removal of all transactions possible.
Client,
/// Executing in runtime mode: Transactions started by the client are protected.
Runtime,
@@ -95,7 +95,7 @@ pub type OverlayedChangeSet = OverlayedMap<StorageKey, Option<StorageValue>>;
/// Holds a set of changes with the ability modify them using nested transactions.
#[derive(Debug, Clone)]
pub struct OverlayedMap<K: Ord + Hash, V> {
pub struct OverlayedMap<K, V> {
/// Stores the changes that this overlay constitutes.
changes: BTreeMap<K, OverlayedEntry<V>>,
/// Stores which keys are dirty per transaction. Needed in order to determine which
@@ -110,7 +110,7 @@ pub struct OverlayedMap<K: Ord + Hash, V> {
execution_mode: ExecutionMode,
}
impl<K: Ord + Hash, V> Default for OverlayedMap<K, V> {
impl<K, V> Default for OverlayedMap<K, V> {
fn default() -> Self {
Self {
changes: BTreeMap::new(),
@@ -121,6 +121,31 @@ impl<K: Ord + Hash, V> Default for OverlayedMap<K, V> {
}
}
#[cfg(feature = "std")]
impl From<sp_core::storage::StorageMap> for OverlayedMap<StorageKey, Option<StorageValue>> {
fn from(storage: sp_core::storage::StorageMap) -> Self {
Self {
changes: storage
.into_iter()
.map(|(k, v)| {
(
k,
OverlayedEntry {
transactions: SmallVec::from_iter([InnerValue {
value: Some(v),
extrinsics: Default::default(),
}]),
},
)
})
.collect(),
dirty_keys: Default::default(),
num_client_transactions: 0,
execution_mode: ExecutionMode::Client,
}
}
}
impl Default for ExecutionMode {
fn default() -> Self {
Self::Client
@@ -638,6 +638,21 @@ impl OverlayedChanges {
}
}
#[cfg(feature = "std")]
impl From<sp_core::storage::Storage> for OverlayedChanges {
fn from(storage: sp_core::storage::Storage) -> Self {
Self {
top: storage.top.into(),
children: storage
.children_default
.into_iter()
.map(|(k, v)| (k, (v.data.into(), v.child_info)))
.collect(),
..Default::default()
}
}
}
#[cfg(feature = "std")]
fn retain_map<K, V, F>(map: &mut Map<K, V>, f: F)
where