Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Merkle Mountain Range pallet (#7312)
Browse files Browse the repository at this point in the history
* Add MMR pallet.

* WiP

* Working on testing.

* WiP - test

* Tests passing.

* Add proof generation.

* Generate and verify proofs.

* Allow verification of older proofs.

* Move stuff to a module.

* Split MMR stuff to it's own module.

* Add docs.

* Make parent hash optional.

* LeafData failed approach.

* Finally implement Compact stuff.

* Compact encoding WiP

* Implement remaining pieces.

* Fix tests

* Add docs to compact.

* Implement for tuples.

* Fix documentation.

* Fix warnings and address review suggestion.

* Update frame/merkle-mountain-range/src/primitives.rs

Co-authored-by: cheme <[email protected]>

* Address review grumbles.

* Removing missing crate.

* Fix test.

* Add some docs and test.

* Add multiple instances.

* Cargo.toml sync.

* Fix no_std compilation.

* More no_std stuff.

* Rename MMR struct.

* Addressing other grumbles.

* Fix test.

* Remove format for no_std compat.

* Add test for MMR pallet.

* Fix std feature.

* Update versions.

* Add to node/runtime.

* Add hook to insert digest.

* Make primitives public.

* Update lib.rs

tech spec/typos etc

* Use WeightInfo and benchmarks.

* Fix test.

* Fix benchmarks.

* Trait -> Config.

* Fix typo.

* Fix tests.

Co-authored-by: cheme <[email protected]>
Co-authored-by: Addie Wagenknecht <[email protected]>
  • Loading branch information
3 people authored Dec 9, 2020
1 parent be8fd05 commit 661bbc9
Show file tree
Hide file tree
Showing 19 changed files with 1,751 additions and 50 deletions.
47 changes: 44 additions & 3 deletions Cargo.lock

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

64 changes: 32 additions & 32 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[workspace]
members = [
"bin/node-template/node",
"bin/node-template/runtime",
"bin/node-template/pallets/template",
"bin/node-template/runtime",
"bin/node/bench",
"bin/node/browser-testing",
"bin/node/cli",
"bin/node/executor",
"bin/node/primitives",
"bin/node/rpc-client",
"bin/node/rpc",
"bin/node/rpc-client",
"bin/node/runtime",
"bin/node/testing",
"bin/utils/subkey",
"bin/utils/chain-spec-builder",
"bin/utils/subkey",
"client/api",
"client/authority-discovery",
"client/basic-authorship",
Expand All @@ -26,42 +26,41 @@ members = [
"client/consensus/babe",
"client/consensus/babe/rpc",
"client/consensus/common",
"client/consensus/epochs",
"client/consensus/manual-seal",
"client/consensus/pow",
"client/consensus/uncles",
"client/consensus/slots",
"client/consensus/epochs",
"client/consensus/uncles",
"client/db",
"client/executor",
"client/executor/common",
"client/executor/runtime-test",
"client/executor/wasmi",
"client/executor/wasmtime",
"client/executor/runtime-test",
"client/finality-grandpa",
"client/informant",
"client/light",
"client/tracing",
"client/keystore",
"client/light",
"client/network",
"client/network/test",
"client/network-gossip",
"client/network/test",
"client/offchain",
"client/peerset",
"client/proposer-metrics",
"client/rpc-servers",
"client/rpc",
"client/rpc-api",
"client/rpc-servers",
"client/service",
"client/service/test",
"client/state-db",
"client/sync-state-rpc",
"client/telemetry",
"client/tracing",
"client/transaction-pool",
"client/transaction-pool/graph",
"utils/prometheus",
"frame/assets",
"frame/aura",
"frame/atomic-swap",
"frame/aura",
"frame/authority-discovery",
"frame/authorship",
"frame/babe",
Expand All @@ -72,7 +71,6 @@ members = [
"frame/contracts/rpc",
"frame/contracts/rpc/runtime-api",
"frame/democracy",
"frame/elections-phragmen",
"frame/elections",
"frame/example",
"frame/example-offchain-worker",
Expand All @@ -83,6 +81,7 @@ members = [
"frame/im-online",
"frame/indices",
"frame/membership",
"frame/merkle-mountain-range",
"frame/metadata",
"frame/multisig",
"frame/nicks",
Expand All @@ -97,8 +96,8 @@ members = [
"frame/session/benchmarking",
"frame/society",
"frame/staking",
"frame/staking/reward-curve",
"frame/staking/fuzzer",
"frame/staking/reward-curve",
"frame/sudo",
"frame/support",
"frame/support/procedural",
Expand All @@ -116,59 +115,59 @@ members = [
"frame/utility",
"frame/vesting",
"primitives/allocator",
"primitives/api",
"primitives/api/proc-macro",
"primitives/api/test",
"primitives/application-crypto",
"primitives/application-crypto/test",
"primitives/arithmetic",
"primitives/arithmetic/fuzzer",
"primitives/authority-discovery",
"primitives/authorship",
"primitives/block-builder",
"primitives/blockchain",
"primitives/chain-spec",
"primitives/consensus/aura",
"primitives/consensus/babe",
"primitives/consensus/common",
"primitives/consensus/pow",
"primitives/consensus/vrf",
"primitives/core",
"primitives/chain-spec",
"primitives/database",
"primitives/debug-derive",
"primitives/storage",
"primitives/externalities",
"primitives/finality-grandpa",
"primitives/inherents",
"primitives/io",
"primitives/keyring",
"primitives/keystore",
"primitives/offchain",
"primitives/panic-handler",
"primitives/npos-elections",
"primitives/npos-elections/fuzzer",
"primitives/npos-elections/compact",
"primitives/npos-elections/fuzzer",
"primitives/offchain",
"primitives/panic-handler",
"primitives/rpc",
"primitives/runtime",
"primitives/runtime-interface",
"primitives/runtime-interface/proc-macro",
"primitives/runtime-interface/test",
"primitives/runtime-interface/test-wasm",
"primitives/runtime-interface/test-wasm-deprecated",
"primitives/runtime-interface/test",
"primitives/sandbox",
"primitives/serializer",
"primitives/session",
"primitives/api",
"primitives/api/proc-macro",
"primitives/api/test",
"primitives/arithmetic",
"primitives/arithmetic/fuzzer",
"primitives/io",
"primitives/runtime",
"primitives/sandbox",
"primitives/staking",
"primitives/std",
"primitives/version",
"primitives/state-machine",
"primitives/std",
"primitives/storage",
"primitives/tasks",
"primitives/timestamp",
"primitives/test-primitives",
"primitives/transaction-pool",
"primitives/timestamp",
"primitives/tracing",
"primitives/transaction-pool",
"primitives/trie",
"primitives/utils",
"primitives/version",
"primitives/wasm-interface",
"test-utils/client",
"test-utils/derive",
Expand All @@ -183,6 +182,7 @@ members = [
"utils/frame/frame-utilities-cli",
"utils/frame/rpc/support",
"utils/frame/rpc/system",
"utils/prometheus",
"utils/wasm-builder",
]

Expand Down
3 changes: 3 additions & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pallet-im-online = { version = "2.0.0", default-features = false, path = "../../
pallet-indices = { version = "2.0.0", default-features = false, path = "../../../frame/indices" }
pallet-identity = { version = "2.0.0", default-features = false, path = "../../../frame/identity" }
pallet-membership = { version = "2.0.0", default-features = false, path = "../../../frame/membership" }
pallet-mmr = { version = "2.0.0", default-features = false, path = "../../../frame/merkle-mountain-range" }
pallet-multisig = { version = "2.0.0", default-features = false, path = "../../../frame/multisig" }
pallet-offences = { version = "2.0.0", default-features = false, path = "../../../frame/offences" }
pallet-offences-benchmarking = { version = "2.0.0", path = "../../../frame/offences/benchmarking", default-features = false, optional = true }
Expand Down Expand Up @@ -110,6 +111,7 @@ std = [
"pallet-indices/std",
"sp-inherents/std",
"pallet-membership/std",
"pallet-mmr/std",
"pallet-multisig/std",
"pallet-identity/std",
"pallet-scheduler/std",
Expand Down Expand Up @@ -160,6 +162,7 @@ runtime-benchmarks = [
"pallet-identity/runtime-benchmarks",
"pallet-im-online/runtime-benchmarks",
"pallet-indices/runtime-benchmarks",
"pallet-mmr/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
Expand Down
11 changes: 11 additions & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,15 @@ impl pallet_vesting::Config for Runtime {
type WeightInfo = pallet_vesting::weights::SubstrateWeight<Runtime>;
}

impl pallet_mmr::Config for Runtime {
const INDEXING_PREFIX: &'static [u8] = b"mmr";
type Hashing = <Runtime as frame_system::Config>::Hashing;
type Hash = <Runtime as frame_system::Config>::Hash;
type LeafData = frame_system::Module<Self>;
type OnNewRoot = ();
type WeightInfo = ();
}

parameter_types! {
pub const AssetDepositBase: Balance = 100 * DOLLARS;
pub const AssetDepositPerZombie: Balance = 1 * DOLLARS;
Expand Down Expand Up @@ -969,6 +978,7 @@ construct_runtime!(
Proxy: pallet_proxy::{Module, Call, Storage, Event<T>},
Multisig: pallet_multisig::{Module, Call, Storage, Event<T>},
Assets: pallet_assets::{Module, Call, Storage, Event<T>},
Mmr: pallet_mmr::{Module, Storage},
}
);

Expand Down Expand Up @@ -1246,6 +1256,7 @@ impl_runtime_apis! {
add_benchmark!(params, batches, pallet_identity, Identity);
add_benchmark!(params, batches, pallet_im_online, ImOnline);
add_benchmark!(params, batches, pallet_indices, Indices);
add_benchmark!(params, batches, pallet_mmr, Mmr);
add_benchmark!(params, batches, pallet_multisig, Multisig);
add_benchmark!(params, batches, pallet_offences, OffencesBench::<Runtime>);
add_benchmark!(params, batches, pallet_proxy, Proxy);
Expand Down
4 changes: 1 addition & 3 deletions client/executor/src/integration_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,6 @@ fn offchain_index(wasm_method: WasmExecutionMethod) {
#[test_case(WasmExecutionMethod::Interpreted)]
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
fn offchain_local_storage_should_work(wasm_method: WasmExecutionMethod) {
use sp_core::offchain::OffchainStorage;

let mut ext = TestExternalities::default();
let (offchain, state) = testing::TestOffchainExt::new();
ext.register_extension(OffchainExt::new(offchain));
Expand All @@ -489,7 +487,7 @@ fn offchain_local_storage_should_work(wasm_method: WasmExecutionMethod) {
).unwrap(),
true.encode(),
);
assert_eq!(state.read().persistent_storage.get(b"", b"test"), Some(vec![]));
assert_eq!(state.read().persistent_storage.get(b"test"), Some(vec![]));
}

#[test_case(WasmExecutionMethod::Interpreted)]
Expand Down
Loading

0 comments on commit 661bbc9

Please sign in to comment.