referrerpolicy=no-referrer-when-downgrade

Trait pallet_mmr::pallet::Config

source ·
pub trait Config<I: 'static = ()>: Config {
    type Hashing: Hash;
    type LeafData: LeafDataProvider;
    type OnNewRoot: OnNewRoot<<<Self as Config<I>>::Hashing as Hash>::Output>;
    type BlockHashProvider: BlockHashProvider<BlockNumberFor<Self>, <Self as Config>::Hash>;
    type WeightInfo: WeightInfo;
    type BenchmarkHelper: BenchmarkHelper;

    const INDEXING_PREFIX: &'static [u8];
}
Expand description

Configuration trait of this pallet.

The main purpose of this trait is to act as an interface between this pallet and the runtime in which it is embedded in. A type, function, or constant in this trait is essentially left to be configured by the runtime that includes this pallet.

Consequently, a runtime that wants to include this pallet must implement this trait. This pallet’s configuration trait

Required Associated Types§

source

type Hashing: Hash

A hasher type for MMR.

To construct trie nodes that result in merging (bagging) two peaks, depending on the node kind we take either:

  • The node (hash) itself if it’s an inner node.
  • The hash of SCALE-encoding of the leaf data if it’s a leaf node.

Then we create a tuple of these two hashes, SCALE-encode it (concatenate) and hash, to obtain a new MMR inner node - the new peak.

source

type LeafData: LeafDataProvider

Data stored in the leaf nodes.

The LeafData is responsible for returning the entire leaf data that will be inserted to the MMR. LeafDataProviders can be composed into tuples to put multiple elements into the tree. In such a case it might be worth using [primitives::Compact] to make MMR proof for one element of the tuple leaner.

Note that the leaf at each block MUST be unique. You may want to include a block hash or block number as an easiest way to ensure that. Also note that the leaf added by each block is expected to only reference data coming from ancestor blocks (leaves are saved offchain using (pos, parent_hash) key to be fork-resistant, as such conflicts could only happen on 1-block deep forks, which means two forks with identical line of ancestors compete to write the same offchain key, but that’s fine as long as leaves only contain data coming from ancestors - conflicting writes are identical).

source

type OnNewRoot: OnNewRoot<<<Self as Config<I>>::Hashing as Hash>::Output>

A hook to act on the new MMR root.

For some applications it might be beneficial to make the MMR root available externally apart from having it in the storage. For instance you might output it in the header digest (see [frame_system::Pallet::deposit_log]) to make it available for Light Clients. Hook complexity should be O(1).

source

type BlockHashProvider: BlockHashProvider<BlockNumberFor<Self>, <Self as Config>::Hash>

Block hash provider for a given block number.

source

type WeightInfo: WeightInfo

Weights for this pallet.

source

type BenchmarkHelper: BenchmarkHelper

Benchmarking setup helper trait.

Required Associated Constants§

source

const INDEXING_PREFIX: &'static [u8]

Prefix for elements stored in the Off-chain DB via Indexing API.

Each node of the MMR is inserted both on-chain and off-chain via Indexing API. The former does not store full leaf content, just its compact version (hash), and some of the inner mmr nodes might be pruned from on-chain storage. The latter will contain all the entries in their full form.

Each node is stored in the Off-chain DB under key derived from the Self::INDEXING_PREFIX and its in-tree index (MMR position).

Object Safety§

This trait is not object safe.

Implementors§