Run cargo fmt on the whole code base (#9394)

* Run cargo fmt on the whole code base

* Second run

* Add CI check

* Fix compilation

* More unnecessary braces

* Handle weights

* Use --all

* Use correct attributes...

* Fix UI tests

* AHHHHHHHHH

* 🤦

* Docs

* Fix compilation

* 🤷

* Please stop

* 🤦 x 2

* More

* make rustfmt.toml consistent with polkadot

Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
@@ -17,17 +17,19 @@
//! Houses the code that implements the transactional overlay storage.
use super::{StorageKey, StorageValue, Extrinsics};
use super::{Extrinsics, StorageKey, StorageValue};
#[cfg(feature = "std")]
use std::collections::HashSet as Set;
#[cfg(not(feature = "std"))]
use sp_std::collections::btree_set::BTreeSet as Set;
#[cfg(feature = "std")]
use std::collections::HashSet as Set;
use sp_std::collections::{btree_map::BTreeMap, btree_set::BTreeSet};
use sp_std::hash::Hash;
use smallvec::SmallVec;
use crate::warn;
use smallvec::SmallVec;
use sp_std::{
collections::{btree_map::BTreeMap, btree_set::BTreeSet},
hash::Hash,
};
const PROOF_OVERLAY_NON_EMPTY: &str = "\
An OverlayValue is always created with at least one transaction and dropped as soon
@@ -82,9 +84,7 @@ pub struct OverlayedEntry<V> {
impl<V> Default for OverlayedEntry<V> {
fn default() -> Self {
Self {
transactions: SmallVec::new(),
}
Self { transactions: SmallVec::new() }
}
}
@@ -142,7 +142,9 @@ impl<V> OverlayedEntry<V> {
/// Unique list of extrinsic indices which modified the value.
pub fn extrinsics(&self) -> BTreeSet<u32> {
let mut set = BTreeSet::new();
self.transactions.iter().for_each(|t| t.extrinsics.copy_extrinsics_into(&mut set));
self.transactions
.iter()
.for_each(|t| t.extrinsics.copy_extrinsics_into(&mut set));
set
}
@@ -165,17 +167,9 @@ impl<V> OverlayedEntry<V> {
///
/// This makes sure that the old version is not overwritten and can be properly
/// rolled back when required.
fn set(
&mut self,
value: V,
first_write_in_tx: bool,
at_extrinsic: Option<u32>,
) {
fn set(&mut self, value: V, first_write_in_tx: bool, at_extrinsic: Option<u32>) {
if first_write_in_tx || self.transactions.is_empty() {
self.transactions.push(InnerValue {
value,
extrinsics: Default::default(),
});
self.transactions.push(InnerValue { value, extrinsics: Default::default() });
} else {
*self.value_mut() = value;
}
@@ -223,9 +217,9 @@ impl<K: Ord + Hash + Clone, V> OverlayedMap<K, V> {
/// Get an optional reference to the value stored for the specified key.
pub fn get<Q>(&self, key: &Q) -> Option<&OverlayedEntry<V>>
where
K: sp_std::borrow::Borrow<Q>,
Q: Ord + ?Sized,
where
K: sp_std::borrow::Borrow<Q>,
Q: Ord + ?Sized,
{
self.changes.get(key)
}
@@ -233,24 +227,19 @@ impl<K: Ord + Hash + Clone, V> OverlayedMap<K, V> {
/// Set a new value for the specified key.
///
/// Can be rolled back or committed when called inside a transaction.
pub fn set(
&mut self,
key: K,
value: V,
at_extrinsic: Option<u32>,
) {
pub fn set(&mut self, key: K, value: V, at_extrinsic: Option<u32>) {
let overlayed = self.changes.entry(key.clone()).or_default();
overlayed.set(value, insert_dirty(&mut self.dirty_keys, key), at_extrinsic);
}
/// Get a list of all changes as seen by current transaction.
pub fn changes(&self) -> impl Iterator<Item=(&K, &OverlayedEntry<V>)> {
pub fn changes(&self) -> impl Iterator<Item = (&K, &OverlayedEntry<V>)> {
self.changes.iter()
}
/// Get a list of all changes as seen by current transaction, consumes
/// the overlay.
pub fn into_changes(self) -> impl Iterator<Item=(K, OverlayedEntry<V>)> {
pub fn into_changes(self) -> impl Iterator<Item = (K, OverlayedEntry<V>)> {
self.changes.into_iter()
}
@@ -258,7 +247,7 @@ impl<K: Ord + Hash + Clone, V> OverlayedMap<K, V> {
///
/// Panics:
/// Panics if there are open transactions: `transaction_depth() > 0`
pub fn drain_commited(self) -> impl Iterator<Item=(K, V)> {
pub fn drain_commited(self) -> impl Iterator<Item = (K, V)> {
assert!(self.transaction_depth() == 0, "Drain is not allowed with open transactions.");
self.changes.into_iter().map(|(k, mut v)| (k, v.pop_transaction().value))
}
@@ -276,7 +265,7 @@ impl<K: Ord + Hash + Clone, V> OverlayedMap<K, V> {
/// Calling this while already inside the runtime will return an error.
pub fn enter_runtime(&mut self) -> Result<(), AlreadyInRuntime> {
if let ExecutionMode::Runtime = self.execution_mode {
return Err(AlreadyInRuntime);
return Err(AlreadyInRuntime)
}
self.execution_mode = ExecutionMode::Runtime;
self.num_client_transactions = self.transaction_depth();
@@ -289,7 +278,7 @@ impl<K: Ord + Hash + Clone, V> OverlayedMap<K, V> {
/// Calling this while already outside the runtime will return an error.
pub fn exit_runtime(&mut self) -> Result<(), NotInRuntime> {
if let ExecutionMode::Client = self.execution_mode {
return Err(NotInRuntime);
return Err(NotInRuntime)
}
self.execution_mode = ExecutionMode::Client;
if self.has_open_runtime_transactions() {
@@ -341,11 +330,13 @@ impl<K: Ord + Hash + Clone, V> OverlayedMap<K, V> {
}
for key in self.dirty_keys.pop().ok_or(NoOpenTransaction)? {
let overlayed = self.changes.get_mut(&key).expect("\
let overlayed = self.changes.get_mut(&key).expect(
"\
A write to an OverlayedValue is recorded in the dirty key set. Before an
OverlayedValue is removed, its containing dirty set is removed. This
function is only called for keys that are in the dirty set. qed\
");
",
);
if rollback {
overlayed.pop_transaction();
@@ -443,9 +434,12 @@ mod test {
type Drained<'a> = Vec<(&'a [u8], Option<&'a [u8]>)>;
fn assert_changes(is: &OverlayedChangeSet, expected: &Changes) {
let is: Changes = is.changes().map(|(k, v)| {
(k.as_ref(), (v.value().map(AsRef::as_ref), v.extrinsics().into_iter().collect()))
}).collect();
let is: Changes = is
.changes()
.map(|(k, v)| {
(k.as_ref(), (v.value().map(AsRef::as_ref), v.extrinsics().into_iter().collect()))
})
.collect();
assert_eq!(&is, expected);
}
@@ -453,7 +447,8 @@ mod test {
let is = is.drain_commited().collect::<Vec<_>>();
let expected = expected
.iter()
.map(|(k, v)| (k.to_vec(), v.0.map(From::from))).collect::<Vec<_>>();
.map(|(k, v)| (k.to_vec(), v.0.map(From::from)))
.collect::<Vec<_>>();
assert_eq!(is, expected);
}
@@ -461,7 +456,8 @@ mod test {
let is = is.drain_commited().collect::<Vec<_>>();
let expected = expected
.iter()
.map(|(k, v)| (k.to_vec(), v.map(From::from))).collect::<Vec<_>>();
.map(|(k, v)| (k.to_vec(), v.map(From::from)))
.collect::<Vec<_>>();
assert_eq!(is, expected);
}
@@ -474,10 +470,7 @@ mod test {
changeset.set(b"key1".to_vec(), Some(b"val1".to_vec()), Some(2));
changeset.set(b"key0".to_vec(), Some(b"val0-1".to_vec()), Some(9));
assert_drained(changeset, vec![
(b"key0", Some(b"val0-1")),
(b"key1", Some(b"val1")),
]);
assert_drained(changeset, vec![(b"key0", Some(b"val0-1")), (b"key1", Some(b"val1"))]);
}
#[test]
@@ -599,10 +592,8 @@ mod test {
changeset.rollback_transaction().unwrap();
assert_eq!(changeset.transaction_depth(), 0);
let rolled_back: Changes = vec![
(b"key0", (Some(b"val0-1"), vec![1, 10])),
(b"key1", (Some(b"val1"), vec![1])),
];
let rolled_back: Changes =
vec![(b"key0", (Some(b"val0-1"), vec![1, 10])), (b"key1", (Some(b"val1"), vec![1]))];
assert_changes(&changeset, &rolled_back);
assert_drained_changes(changeset, rolled_back);
@@ -676,21 +667,27 @@ mod test {
changeset.clear_where(|k, _| k.starts_with(b"del"), Some(5));
assert_changes(&changeset, &vec![
(b"del1", (None, vec![3, 5])),
(b"del2", (None, vec![4, 5])),
(b"key0", (Some(b"val0"), vec![1])),
(b"key1", (Some(b"val1"), vec![2])),
]);
assert_changes(
&changeset,
&vec![
(b"del1", (None, vec![3, 5])),
(b"del2", (None, vec![4, 5])),
(b"key0", (Some(b"val0"), vec![1])),
(b"key1", (Some(b"val1"), vec![2])),
],
);
changeset.rollback_transaction().unwrap();
assert_changes(&changeset, &vec![
(b"del1", (Some(b"delval1"), vec![3])),
(b"del2", (Some(b"delval2"), vec![4])),
(b"key0", (Some(b"val0"), vec![1])),
(b"key1", (Some(b"val1"), vec![2])),
]);
assert_changes(
&changeset,
&vec![
(b"del1", (Some(b"delval1"), vec![3])),
(b"del2", (Some(b"delval2"), vec![4])),
(b"key0", (Some(b"val0"), vec![1])),
(b"key1", (Some(b"val1"), vec![2])),
],
);
}
#[test]
@@ -708,29 +705,52 @@ mod test {
changeset.set(b"key11".to_vec(), Some(b"val11".to_vec()), Some(11));
assert_eq!(changeset.changes_after(b"key0").next().unwrap().0, b"key1");
assert_eq!(changeset.changes_after(b"key0").next().unwrap().1.value(), Some(&b"val1".to_vec()));
assert_eq!(
changeset.changes_after(b"key0").next().unwrap().1.value(),
Some(&b"val1".to_vec())
);
assert_eq!(changeset.changes_after(b"key1").next().unwrap().0, b"key11");
assert_eq!(changeset.changes_after(b"key1").next().unwrap().1.value(), Some(&b"val11".to_vec()));
assert_eq!(
changeset.changes_after(b"key1").next().unwrap().1.value(),
Some(&b"val11".to_vec())
);
assert_eq!(changeset.changes_after(b"key11").next().unwrap().0, b"key2");
assert_eq!(changeset.changes_after(b"key11").next().unwrap().1.value(), Some(&b"val2".to_vec()));
assert_eq!(
changeset.changes_after(b"key11").next().unwrap().1.value(),
Some(&b"val2".to_vec())
);
assert_eq!(changeset.changes_after(b"key2").next().unwrap().0, b"key3");
assert_eq!(changeset.changes_after(b"key2").next().unwrap().1.value(), Some(&b"val3".to_vec()));
assert_eq!(
changeset.changes_after(b"key2").next().unwrap().1.value(),
Some(&b"val3".to_vec())
);
assert_eq!(changeset.changes_after(b"key3").next().unwrap().0, b"key4");
assert_eq!(changeset.changes_after(b"key3").next().unwrap().1.value(), Some(&b"val4".to_vec()));
assert_eq!(
changeset.changes_after(b"key3").next().unwrap().1.value(),
Some(&b"val4".to_vec())
);
assert_eq!(changeset.changes_after(b"key4").next(), None);
changeset.rollback_transaction().unwrap();
assert_eq!(changeset.changes_after(b"key0").next().unwrap().0, b"key1");
assert_eq!(changeset.changes_after(b"key0").next().unwrap().1.value(), Some(&b"val1".to_vec()));
assert_eq!(
changeset.changes_after(b"key0").next().unwrap().1.value(),
Some(&b"val1".to_vec())
);
assert_eq!(changeset.changes_after(b"key1").next().unwrap().0, b"key2");
assert_eq!(changeset.changes_after(b"key1").next().unwrap().1.value(), Some(&b"val2".to_vec()));
assert_eq!(
changeset.changes_after(b"key1").next().unwrap().1.value(),
Some(&b"val2".to_vec())
);
assert_eq!(changeset.changes_after(b"key11").next().unwrap().0, b"key2");
assert_eq!(changeset.changes_after(b"key11").next().unwrap().1.value(), Some(&b"val2".to_vec()));
assert_eq!(
changeset.changes_after(b"key11").next().unwrap().1.value(),
Some(&b"val2".to_vec())
);
assert_eq!(changeset.changes_after(b"key2").next(), None);
assert_eq!(changeset.changes_after(b"key3").next(), None);
assert_eq!(changeset.changes_after(b"key4").next(), None);
}
#[test]
@@ -790,9 +810,7 @@ mod test {
changeset.commit_transaction().unwrap();
assert_eq!(changeset.transaction_depth(), 0);
assert_drained(changeset, vec![
(b"key0", Some(b"val0")),
]);
assert_drained(changeset, vec![(b"key0", Some(b"val0"))]);
}
#[test]