-
Notifications
You must be signed in to change notification settings - Fork 766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate pallet-mmr to umbrella crate #7081
base: master
Are you sure you want to change the base?
Changes from 4 commits
917b413
ee1d06d
b61709d
0aaa37d
124f5bb
a7962ec
565985b
16761dc
8941248
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,5 @@ substrate.code-workspace | |
target/ | ||
*.scale | ||
justfile | ||
python-venv | ||
.zed | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 | ||
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json | ||
|
||
title: '[pallet-mmr] Migrate to using frame umbrella crate' | ||
|
||
doc: | ||
- audience: Runtime Dev | ||
description: This PR migrates the pallet-mmr to use the frame umbrella crate. This | ||
is part of the ongoing effort to migrate all pallets to use the frame umbrella crate. | ||
The effort is tracked [here](https://github.com/paritytech/polkadot-sdk/issues/6504). | ||
|
||
crates: | ||
- name: pallet-mmr | ||
bump: minor | ||
- name: polkadot-sdk-frame | ||
bump: minor |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,15 +16,9 @@ targets = ["x86_64-unknown-linux-gnu"] | |
|
||
[dependencies] | ||
codec = { workspace = true } | ||
frame-benchmarking = { optional = true, workspace = true } | ||
frame-support = { workspace = true } | ||
frame-system = { workspace = true } | ||
frame = { workspace = true, features = ["experimental", "runtime"] } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just follow other PRs. Yeah, it's a bit confusing, it won't compile after removing the feature.
Same concern in #6504 (comment) |
||
log = { workspace = true } | ||
scale-info = { features = ["derive"], workspace = true } | ||
sp-core = { workspace = true } | ||
sp-io = { workspace = true } | ||
sp-mmr-primitives = { workspace = true } | ||
sp-runtime = { workspace = true } | ||
|
||
[dev-dependencies] | ||
array-bytes = { workspace = true, default-features = true } | ||
|
@@ -35,24 +29,13 @@ sp-tracing = { workspace = true, default-features = true } | |
default = ["std"] | ||
std = [ | ||
"codec/std", | ||
"frame-benchmarking?/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"frame/std", | ||
"log/std", | ||
"scale-info/std", | ||
"sp-core/std", | ||
"sp-io/std", | ||
"sp-mmr-primitives/std", | ||
"sp-runtime/std", | ||
] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
"sp-runtime/runtime-benchmarks", | ||
"frame/runtime-benchmarks", | ||
] | ||
try-runtime = [ | ||
"frame-support/try-runtime", | ||
"frame-system/try-runtime", | ||
"sp-runtime/try-runtime", | ||
"frame/try-runtime", | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,19 +59,16 @@ | |
extern crate alloc; | ||
|
||
use alloc::vec::Vec; | ||
use frame_support::weights::Weight; | ||
use frame_system::pallet_prelude::{BlockNumberFor, HeaderFor}; | ||
use log; | ||
use sp_mmr_primitives::utils; | ||
use sp_runtime::{ | ||
traits::{self, One, Saturating}, | ||
SaturatedConversion, | ||
|
||
pub use frame::{ | ||
deps::sp_mmr_primitives::{ | ||
self as primitives, utils, utils::NodesUtils, Error, LeafDataProvider, LeafIndex, NodeIndex, | ||
}, | ||
prelude::*, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be exported publicly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}; | ||
|
||
pub use pallet::*; | ||
pub use sp_mmr_primitives::{ | ||
self as primitives, utils::NodesUtils, Error, LeafDataProvider, LeafIndex, NodeIndex, | ||
}; | ||
|
||
#[cfg(feature = "runtime-benchmarks")] | ||
mod benchmarking; | ||
|
@@ -90,11 +87,11 @@ mod tests; | |
/// crate-local wrapper over [frame_system::Pallet]. Since the current block hash | ||
/// is not available (since the block is not finished yet), | ||
/// we use the `parent_hash` here along with parent block number. | ||
pub struct ParentNumberAndHash<T: frame_system::Config> { | ||
_phantom: core::marker::PhantomData<T>, | ||
pub struct ParentNumberAndHash<T: Config> { | ||
_phantom: PhantomData<T>, | ||
} | ||
|
||
impl<T: frame_system::Config> LeafDataProvider for ParentNumberAndHash<T> { | ||
impl<T: Config> LeafDataProvider for ParentNumberAndHash<T> { | ||
type LeafData = (BlockNumberFor<T>, <T as frame_system::Config>::Hash); | ||
|
||
fn leaf_data() -> Self::LeafData { | ||
|
@@ -111,13 +108,11 @@ pub trait BlockHashProvider<BlockNumber, BlockHash> { | |
} | ||
|
||
/// Default implementation of BlockHashProvider using frame_system. | ||
pub struct DefaultBlockHashProvider<T: frame_system::Config> { | ||
pub struct DefaultBlockHashProvider<T: Config> { | ||
_phantom: core::marker::PhantomData<T>, | ||
} | ||
|
||
impl<T: frame_system::Config> BlockHashProvider<BlockNumberFor<T>, T::Hash> | ||
for DefaultBlockHashProvider<T> | ||
{ | ||
impl<T: Config> BlockHashProvider<BlockNumberFor<T>, T::Hash> for DefaultBlockHashProvider<T> { | ||
fn block_hash(block_number: BlockNumberFor<T>) -> T::Hash { | ||
frame_system::Pallet::<T>::block_hash(block_number) | ||
} | ||
|
@@ -147,12 +142,11 @@ type LeafOf<T, I> = <<T as Config<I>>::LeafData as primitives::LeafDataProvider> | |
/// Hashing used for the pallet. | ||
pub(crate) type HashingOf<T, I> = <T as Config<I>>::Hashing; | ||
/// Hash type used for the pallet. | ||
pub(crate) type HashOf<T, I> = <<T as Config<I>>::Hashing as traits::Hash>::Output; | ||
pub(crate) type HashOf<T, I> = <<T as Config<I>>::Hashing as Hash>::Output; | ||
|
||
#[frame_support::pallet] | ||
#[frame::pallet] | ||
pub mod pallet { | ||
use super::*; | ||
use frame_support::pallet_prelude::*; | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>); | ||
|
@@ -180,7 +174,7 @@ pub mod pallet { | |
/// | ||
/// 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. | ||
type Hashing: traits::Hash; | ||
type Hashing: Hash; | ||
|
||
/// Data stored in the leaf nodes. | ||
/// | ||
|
@@ -250,7 +244,7 @@ pub mod pallet { | |
fn on_initialize(_n: BlockNumberFor<T>) -> Weight { | ||
use primitives::LeafDataProvider; | ||
let leaves = NumberOfLeaves::<T, I>::get(); | ||
let peaks_before = sp_mmr_primitives::utils::NodesUtils::new(leaves).number_of_peaks(); | ||
let peaks_before = primitives::utils::NodesUtils::new(leaves).number_of_peaks(); | ||
let data = T::LeafData::leaf_data(); | ||
|
||
// append new leaf to MMR | ||
|
@@ -273,7 +267,7 @@ pub mod pallet { | |
NumberOfLeaves::<T, I>::put(leaves); | ||
RootHash::<T, I>::put(root); | ||
|
||
let peaks_after = sp_mmr_primitives::utils::NodesUtils::new(leaves).number_of_peaks(); | ||
let peaks_after = primitives::utils::NodesUtils::new(leaves).number_of_peaks(); | ||
|
||
T::WeightInfo::on_initialize(peaks_before.max(peaks_after) as u32) | ||
} | ||
|
@@ -293,7 +287,7 @@ pub fn verify_leaves_proof<H, L>( | |
proof: primitives::LeafProof<H::Output>, | ||
) -> Result<(), primitives::Error> | ||
where | ||
H: traits::Hash, | ||
H: Hash, | ||
L: primitives::FullLeaf, | ||
{ | ||
let is_valid = mmr::verify_leaves_proof::<H, L>(root, leaves, proof)?; | ||
|
@@ -310,7 +304,7 @@ pub fn verify_ancestry_proof<H, L>( | |
ancestry_proof: primitives::AncestryProof<H::Output>, | ||
) -> Result<H::Output, Error> | ||
where | ||
H: traits::Hash, | ||
H: Hash, | ||
L: primitives::FullLeaf, | ||
{ | ||
mmr::verify_ancestry_proof::<H, L>(root, ancestry_proof) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit obscure, maybe add
.zed
file to your global gitignore configuration?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
124f5bb