Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions prdoc/pr_10437.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: Remove pallet::getter usage from merkel mountain range pallet
doc:
- audience: Runtime Dev
description: 'Advances #3326'
crates:
- name: pallet-mmr
bump: minor
14 changes: 11 additions & 3 deletions substrate/frame/merkle-mountain-range/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,13 @@ pub mod pallet {

/// Current size of the MMR (number of leaves).
#[pallet::storage]
#[pallet::getter(fn mmr_leaves)]
pub type NumberOfLeaves<T, I = ()> = StorageValue<_, LeafIndex, ValueQuery>;

/// Hashes of the nodes in the MMR.
///
/// Note this collection only contains MMR peaks, the inner nodes (and leaves)
/// 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, NodeIndex, HashOf<T, I>, OptionQuery>;

Expand Down Expand Up @@ -338,7 +336,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
// `block_num = (current_block_num - leaves_count) + leaf_idx + 1`
// `parent_block_num = current_block_num - leaves_count + leaf_idx`.
<frame_system::Pallet<T>>::block_number()
.saturating_sub(Self::mmr_leaves().saturated_into())
.saturating_sub(NumberOfLeaves::<T, I>::get().saturated_into())
.saturating_add(leaf_index.saturated_into())
}

Expand Down Expand Up @@ -462,4 +460,14 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
pub fn mmr_root() -> HashOf<T, I> {
RootHash::<T, I>::get()
}

/// Returns the current size of the MMR (number of leaves).
pub fn mmr_leaves() -> LeafIndex {
NumberOfLeaves::<T, I>::get()
}

/// Returns the hash of a node in the MMR, if one exists.
pub fn mmr_peak(node_index: NodeIndex) -> Option<HashOf<T, I>> {
Nodes::<T, I>::get(node_index)
}
}
Loading