Merkle Mountain Range pallet (#7312)

* 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 <emericchevalier.pro@gmail.com>

* 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 <emericchevalier.pro@gmail.com>
Co-authored-by: Addie Wagenknecht <addie@nortd.com>
This commit is contained in:
Tomasz Drwięga
2020-12-09 16:35:13 +01:00
committed by GitHub
parent 2ed2832046
commit 02f66e8823
19 changed files with 1751 additions and 50 deletions
@@ -70,6 +70,8 @@ pub struct TestPersistentOffchainDB {
}
impl TestPersistentOffchainDB {
const PREFIX: &'static [u8] = b"";
/// Create a new and empty offchain storage db for persistent items
pub fn new() -> Self {
Self {
@@ -82,11 +84,16 @@ impl TestPersistentOffchainDB {
let mut me = self.persistent.write();
for ((_prefix, key), value_operation) in changes.drain() {
match value_operation {
OffchainOverlayedChange::SetValue(val) => me.set(b"", key.as_slice(), val.as_slice()),
OffchainOverlayedChange::Remove => me.remove(b"", key.as_slice()),
OffchainOverlayedChange::SetValue(val) => me.set(Self::PREFIX, key.as_slice(), val.as_slice()),
OffchainOverlayedChange::Remove => me.remove(Self::PREFIX, key.as_slice()),
}
}
}
/// Retrieve a key from the test backend.
pub fn get(&self, key: &[u8]) -> Option<Vec<u8>> {
OffchainStorage::get(self, Self::PREFIX, key)
}
}
impl OffchainStorage for TestPersistentOffchainDB {
@@ -266,8 +273,8 @@ impl offchain::Externalities for TestOffchainExt {
fn local_storage_get(&mut self, kind: StorageKind, key: &[u8]) -> Option<Vec<u8>> {
let state = self.0.read();
match kind {
StorageKind::LOCAL => state.local_storage.get(b"", key),
StorageKind::PERSISTENT => state.persistent_storage.get(b"", key),
StorageKind::LOCAL => state.local_storage.get(TestPersistentOffchainDB::PREFIX, key),
StorageKind::PERSISTENT => state.persistent_storage.get(key),
}
}