mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-16 16:41:10 +00:00
Removed pallet::getter usage from Beefy and MMR pallets (#3740)
Part of #3326 cc @kianenigma @ggwpez @liamaharon polkadot address: 12poSUQPtcF1HUPQGY3zZu2P8emuW9YnsPduA4XG3oCEfJVp --------- Signed-off-by: Matteo Muraca <mmuraca247@gmail.com>
This commit is contained in:
@@ -183,7 +183,6 @@ pub mod pallet {
|
||||
|
||||
/// Latest MMR Root hash.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn mmr_root_hash)]
|
||||
pub type RootHash<T: Config<I>, I: 'static = ()> = StorageValue<_, HashOf<T, I>, ValueQuery>;
|
||||
|
||||
/// Current size of the MMR (number of leaves).
|
||||
@@ -204,7 +203,7 @@ pub mod pallet {
|
||||
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
|
||||
fn on_initialize(_n: BlockNumberFor<T>) -> Weight {
|
||||
use primitives::LeafDataProvider;
|
||||
let leaves = Self::mmr_leaves();
|
||||
let leaves = NumberOfLeaves::<T, I>::get();
|
||||
let peaks_before = sp_mmr_primitives::utils::NodesUtils::new(leaves).number_of_peaks();
|
||||
let data = T::LeafData::leaf_data();
|
||||
|
||||
@@ -225,8 +224,8 @@ pub mod pallet {
|
||||
};
|
||||
<T::OnNewRoot as primitives::OnNewRoot<_>>::on_new_root(&root);
|
||||
|
||||
<NumberOfLeaves<T, I>>::put(leaves);
|
||||
<RootHash<T, I>>::put(root);
|
||||
NumberOfLeaves::<T, I>::put(leaves);
|
||||
RootHash::<T, I>::put(root);
|
||||
|
||||
let peaks_after = sp_mmr_primitives::utils::NodesUtils::new(leaves).number_of_peaks();
|
||||
|
||||
@@ -301,7 +300,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
{
|
||||
let first_mmr_block = utils::first_mmr_block_num::<HeaderFor<T>>(
|
||||
<frame_system::Pallet<T>>::block_number(),
|
||||
Self::mmr_leaves(),
|
||||
NumberOfLeaves::<T, I>::get(),
|
||||
)?;
|
||||
|
||||
utils::block_num_to_leaf_index::<HeaderFor<T>>(block_num, first_mmr_block)
|
||||
@@ -341,7 +340,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
|
||||
/// Return the on-chain MMR root hash.
|
||||
pub fn mmr_root() -> HashOf<T, I> {
|
||||
Self::mmr_root_hash()
|
||||
RootHash::<T, I>::get()
|
||||
}
|
||||
|
||||
/// Verify MMR proof for given `leaves`.
|
||||
@@ -354,7 +353,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
leaves: Vec<LeafOf<T, I>>,
|
||||
proof: primitives::Proof<HashOf<T, I>>,
|
||||
) -> Result<(), primitives::Error> {
|
||||
if proof.leaf_count > Self::mmr_leaves() ||
|
||||
if proof.leaf_count > NumberOfLeaves::<T, I>::get() ||
|
||||
proof.leaf_count == 0 ||
|
||||
(proof.items.len().saturating_add(leaves.len())) as u64 > proof.leaf_count
|
||||
{
|
||||
|
||||
@@ -111,7 +111,7 @@ where
|
||||
L: primitives::FullLeaf,
|
||||
{
|
||||
fn get_elem(&self, pos: NodeIndex) -> mmr_lib::Result<Option<NodeOf<T, I, L>>> {
|
||||
Ok(<Nodes<T, I>>::get(pos).map(Node::Hash))
|
||||
Ok(Nodes::<T, I>::get(pos).map(Node::Hash))
|
||||
}
|
||||
|
||||
fn append(&mut self, pos: NodeIndex, elems: Vec<NodeOf<T, I, L>>) -> mmr_lib::Result<()> {
|
||||
@@ -147,7 +147,7 @@ where
|
||||
for elem in elems {
|
||||
// On-chain we are going to only store new peaks.
|
||||
if peaks_to_store.next_if_eq(&node_index).is_some() {
|
||||
<Nodes<T, I>>::insert(node_index, elem.hash());
|
||||
Nodes::<T, I>::insert(node_index, elem.hash());
|
||||
}
|
||||
// We are storing full node off-chain (using indexing API).
|
||||
Self::store_to_offchain(node_index, parent_hash, &elem);
|
||||
@@ -164,7 +164,7 @@ where
|
||||
|
||||
// And remove all remaining items from `peaks_before` collection.
|
||||
for pos in peaks_to_prune {
|
||||
<Nodes<T, I>>::remove(pos);
|
||||
Nodes::<T, I>::remove(pos);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -608,9 +608,9 @@ fn verification_should_be_stateless() {
|
||||
let mut ext = new_test_ext();
|
||||
let (root_6, root_7) = ext.execute_with(|| {
|
||||
add_blocks(6);
|
||||
let root_6 = crate::Pallet::<Test>::mmr_root_hash();
|
||||
let root_6 = crate::Pallet::<Test>::mmr_root();
|
||||
add_blocks(1);
|
||||
let root_7 = crate::Pallet::<Test>::mmr_root_hash();
|
||||
let root_7 = crate::Pallet::<Test>::mmr_root();
|
||||
(root_6, root_7)
|
||||
});
|
||||
ext.persist_offchain_overlay();
|
||||
@@ -656,9 +656,9 @@ fn should_verify_batch_proof_statelessly() {
|
||||
let mut ext = new_test_ext();
|
||||
let (root_6, root_7) = ext.execute_with(|| {
|
||||
add_blocks(6);
|
||||
let root_6 = crate::Pallet::<Test>::mmr_root_hash();
|
||||
let root_6 = crate::Pallet::<Test>::mmr_root();
|
||||
add_blocks(1);
|
||||
let root_7 = crate::Pallet::<Test>::mmr_root_hash();
|
||||
let root_7 = crate::Pallet::<Test>::mmr_root();
|
||||
(root_6, root_7)
|
||||
});
|
||||
ext.persist_offchain_overlay();
|
||||
|
||||
Reference in New Issue
Block a user