diff --git a/prdoc/pr_10437.prdoc b/prdoc/pr_10437.prdoc new file mode 100644 index 0000000000000..f4dc157b4cdee --- /dev/null +++ b/prdoc/pr_10437.prdoc @@ -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 diff --git a/substrate/frame/merkle-mountain-range/src/lib.rs b/substrate/frame/merkle-mountain-range/src/lib.rs index cc64dfcb7de88..745ab04b98160 100644 --- a/substrate/frame/merkle-mountain-range/src/lib.rs +++ b/substrate/frame/merkle-mountain-range/src/lib.rs @@ -222,7 +222,6 @@ pub mod pallet { /// Current size of the MMR (number of leaves). #[pallet::storage] - #[pallet::getter(fn mmr_leaves)] pub type NumberOfLeaves = StorageValue<_, LeafIndex, ValueQuery>; /// Hashes of the nodes in the MMR. @@ -230,7 +229,6 @@ pub mod pallet { /// 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, I: 'static = ()> = StorageMap<_, Identity, NodeIndex, HashOf, OptionQuery>; @@ -338,7 +336,7 @@ impl, I: 'static> Pallet { // `block_num = (current_block_num - leaves_count) + leaf_idx + 1` // `parent_block_num = current_block_num - leaves_count + leaf_idx`. >::block_number() - .saturating_sub(Self::mmr_leaves().saturated_into()) + .saturating_sub(NumberOfLeaves::::get().saturated_into()) .saturating_add(leaf_index.saturated_into()) } @@ -462,4 +460,14 @@ impl, I: 'static> Pallet { pub fn mmr_root() -> HashOf { RootHash::::get() } + + /// Returns the current size of the MMR (number of leaves). + pub fn mmr_leaves() -> LeafIndex { + NumberOfLeaves::::get() + } + + /// Returns the hash of a node in the MMR, if one exists. + pub fn mmr_peak(node_index: NodeIndex) -> Option> { + Nodes::::get(node_index) + } }