Skip to content
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

[FRAME] Add paged NMap #4604

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
17 changes: 14 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ members = [
"substrate/frame/statement",
"substrate/frame/sudo",
"substrate/frame/support",
"substrate/frame/support/fuzzer",
"substrate/frame/support/procedural",
"substrate/frame/support/procedural/tools",
"substrate/frame/support/procedural/tools/derive",
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/paged-list/fuzzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ path = "src/paged_list.rs"

[dependencies]
arbitrary = "1.3.2"
honggfuzz = "0.5.49"
honggfuzz = "0.5.56"

frame-support = { path = "../../support", default-features = false, features = ["std"] }
sp-io = { path = "../../../primitives/io", default-features = false, features = ["std"] }
Expand Down
8 changes: 5 additions & 3 deletions substrate/frame/paged-list/fuzzer/src/paged_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
//!
//! # Debugging a panic
//! Once a panic is found, it can be debugged with
//! `cargo hfuzz run-debug pallet-paged-list hfuzz_workspace/pallet-paged-list/*.fuzz`.
//! `cargo hfuzz run-debug pallet-paged-list-fuzzer
//! hfuzz_workspace/pallet-paged-list-fuzzer/*.fuzz`.
//!
//! # More information
//! More information about `honggfuzz` can be found
Expand All @@ -47,7 +48,7 @@ fn main() {
///
/// It also changes the maximal number of elements per page dynamically, hence the `page_size`.
fn drain_append_work(ops: Vec<Op>, page_size: u8) {
if page_size == 0 {
if page_size < 4 {
return
}

Expand All @@ -61,11 +62,12 @@ fn drain_append_work(ops: Vec<Op>, page_size: u8) {

assert!(total >= 0);
assert_eq!(List::iter().count(), total as usize);
assert_eq!(total as u64, List::len());

// We have the assumption that the queue removes the metadata when empty.
if total == 0 {
assert_eq!(List::drain().count(), 0);
assert_eq!(Meta::from_storage().unwrap_or_default(), Default::default());
assert_eq!(Meta::from_storage(((),)).unwrap_or_default(), Default::default());
}
}

Expand Down
7 changes: 5 additions & 2 deletions substrate/frame/paged-list/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,14 @@
pub use pallet::*;

pub mod mock;
mod paged_list;
mod tests;

use codec::FullCodec;
use frame_support::{
pallet_prelude::StorageList,
storage::types::StoragePagedList,
traits::{PalletInfoAccess, StorageInstance},
};
pub use paged_list::StoragePagedList;

#[frame_support::pallet]
pub mod pallet {
Expand Down Expand Up @@ -111,6 +110,10 @@ impl<T: Config<I>, I: 'static> StorageList<T::Value> for Pallet<T, I> {
type Iterator = <List<T, I> as StorageList<T::Value>>::Iterator;
type Appender = <List<T, I> as StorageList<T::Value>>::Appender;

fn len() -> u64 {
List::<T, I>::len()
}

fn iter() -> Self::Iterator {
List::<T, I>::iter()
}
Expand Down
13 changes: 4 additions & 9 deletions substrate/frame/paged-list/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

#![cfg(feature = "std")]

use crate::{paged_list::StoragePagedListMeta, Config, ListPrefix};
use frame_support::{derive_impl, traits::ConstU16};
use crate::{Config, ListPrefix};
use frame_support::{derive_impl, storage::types::StoragePagedListMeta, traits::ConstU64};
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
Expand Down Expand Up @@ -53,14 +53,9 @@ impl frame_system::Config for Test {
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ConstU16<42>;
type OnSetCode = ();
type PalletInfo = PalletInfo; // FAIL-CI remove more
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

Expand Down
Loading
Loading