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
@@ -40,38 +40,37 @@
//!
//! ## What for?
//!
//! Primary use case for this pallet is to generate MMR root hashes, that can latter on be used by
//! BEEFY protocol (see <https://github.com/paritytech/grandpa-bridge-gadget>).
//! MMR root hashes along with BEEFY will make it possible to build Super Light Clients (SLC) of
//! Substrate-based chains. The SLC will be able to follow finality and can be shown proofs of more
//! details that happened on the source chain.
//! In that case the chain which contains the pallet generates the Root Hashes and Proofs, which
//! are then presented to another chain acting as a light client which can verify them.
//! Primary use case for this pallet is to generate MMR root hashes, that can latter on be used by
//! BEEFY protocol (see <https://github.com/paritytech/grandpa-bridge-gadget>).
//! MMR root hashes along with BEEFY will make it possible to build Super Light Clients (SLC) of
//! Substrate-based chains. The SLC will be able to follow finality and can be shown proofs of more
//! details that happened on the source chain.
//! In that case the chain which contains the pallet generates the Root Hashes and Proofs, which
//! are then presented to another chain acting as a light client which can verify them.
//!
//! Secondary use case is to archive historical data, but still be able to retrieve them on-demand
//! if needed. For instance if parent block hashes are stored in the MMR it's possible at any point
//! in time to provide a MMR proof about some past block hash, while this data can be safely pruned
//! from on-chain storage.
//! Secondary use case is to archive historical data, but still be able to retrieve them on-demand
//! if needed. For instance if parent block hashes are stored in the MMR it's possible at any point
//! in time to provide a MMR proof about some past block hash, while this data can be safely pruned
//! from on-chain storage.
//!
//! NOTE This pallet is experimental and not proven to work in production.
//!
#![cfg_attr(not(feature = "std"), no_std)]
use codec::Encode;
use frame_support::weights::Weight;
use sp_runtime::traits;
mod default_weights;
mod mmr;
#[cfg(any(feature = "runtime-benchmarks", test))]
mod benchmarking;
mod default_weights;
mod mmr;
#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;
pub use pallet_mmr_primitives as primitives;
pub use pallet::*;
pub use pallet_mmr_primitives as primitives;
pub trait WeightInfo {
fn on_initialize(peaks: u64) -> Weight;
@@ -79,9 +78,9 @@ pub trait WeightInfo {
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use super::*;
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
@@ -116,8 +115,15 @@ pub mod pallet {
///
/// This type is actually going to be stored in the MMR.
/// Required to be provided again, to satisfy trait bounds for storage items.
type Hash: traits::Member + traits::MaybeSerializeDeserialize + sp_std::fmt::Debug
+ sp_std::hash::Hash + AsRef<[u8]> + AsMut<[u8]> + Copy + Default + codec::Codec
type Hash: traits::Member
+ traits::MaybeSerializeDeserialize
+ sp_std::fmt::Debug
+ sp_std::hash::Hash
+ AsRef<[u8]>
+ AsMut<[u8]>
+ Copy
+ Default
+ codec::Codec
+ codec::EncodeLike;
/// Data stored in the leaf nodes.
@@ -147,7 +153,8 @@ pub mod pallet {
/// Latest MMR Root hash.
#[pallet::storage]
#[pallet::getter(fn mmr_root_hash)]
pub type RootHash<T: Config<I>, I: 'static = ()> = StorageValue<_, <T as Config<I>>::Hash, ValueQuery>;
pub type RootHash<T: Config<I>, I: 'static = ()> =
StorageValue<_, <T as Config<I>>::Hash, ValueQuery>;
/// Current size of the MMR (number of leaves).
#[pallet::storage]
@@ -160,13 +167,8 @@ pub mod pallet {
/// are pruned and only stored in the Offchain DB.
#[pallet::storage]
#[pallet::getter(fn mmr_peak)]
pub type Nodes<T: Config<I>, I: 'static = ()> = StorageMap<
_,
Identity,
u64,
<T as Config<I>>::Hash,
OptionQuery
>;
pub type Nodes<T: Config<I>, I: 'static = ()> =
StorageMap<_, Identity, u64, <T as Config<I>>::Hash, OptionQuery>;
#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
@@ -211,7 +213,8 @@ pub fn verify_leaf_proof<H, L>(
root: H::Output,
leaf: mmr::Node<H, L>,
proof: primitives::Proof<H::Output>,
) -> Result<(), primitives::Error> where
) -> Result<(), primitives::Error>
where
H: traits::Hash,
L: primitives::FullLeaf,
{
@@ -234,10 +237,9 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// (Offchain Worker or Runtime API call), since it requires
/// all the leaves to be present.
/// It may return an error or panic if used incorrectly.
pub fn generate_proof(leaf_index: u64) -> Result<
(LeafOf<T, I>, primitives::Proof<<T as Config<I>>::Hash>),
primitives::Error,
> {
pub fn generate_proof(
leaf_index: u64,
) -> Result<(LeafOf<T, I>, primitives::Proof<<T as Config<I>>::Hash>), primitives::Error> {
let mmr: ModuleMmr<mmr::storage::OffchainStorage, T, I> = mmr::Mmr::new(Self::mmr_leaves());
mmr.generate_proof(leaf_index)
}
@@ -252,13 +254,12 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
leaf: LeafOf<T, I>,
proof: primitives::Proof<<T as Config<I>>::Hash>,
) -> Result<(), primitives::Error> {
if proof.leaf_count > Self::mmr_leaves()
|| proof.leaf_count == 0
|| proof.items.len() as u32 > mmr::utils::NodesUtils::new(proof.leaf_count).depth()
if proof.leaf_count > Self::mmr_leaves() ||
proof.leaf_count == 0 ||
proof.items.len() as u32 > mmr::utils::NodesUtils::new(proof.leaf_count).depth()
{
return Err(primitives::Error::Verify.log_debug(
"The proof has incorrect number of leaves or proof items."
));
return Err(primitives::Error::Verify
.log_debug("The proof has incorrect number of leaves or proof items."))
}
let mmr: ModuleMmr<mmr::storage::RuntimeStorage, T, I> = mmr::Mmr::new(proof.leaf_count);