* Use `array-bytes` for All Array/Bytes/Hex Operations
Signed-off-by: Xavier Lau <xavier@inv.cafe>
* Reorder
* Self Review
* Format
* Fix Tests
* Bump `array-bytes`
* Optimize large test res
Signed-off-by: Xavier Lau <xavier@inv.cafe>
Co-authored-by: parity-processbot <>
* pallet-mmr: fix some typos
* pallet-mmr: make the MMR resilient to chain forks
* pallet-mmr: get hash for block that added node
* beefy-mmr: add debug logging
* add explanatory comment
* account for block offset of pallet activation
* add support for finding all nodes added by leaf
* minor improvements
* add helper to return all nodes added to mmr with a leaf append
* simplify leaf_node_index_to_leaf_index
summing the (shifted) differences in peak positions adds up to the (shifted) final position, so
don't need to fold over positions.
* dead fish: this also doesn't work
The idea was to keep a rolling window of `(parent_hash, pos)` leaf
entries in the offchain db, with the window matching the one
that provides `block_num -> block_hash` mappings in `frame_system`.
Once a leaf exits the window it would be "canonicalized" by switching
its offchain db key from `(parent_hash, pos)` to simple `pos`.
This doesn't work however because there's no way to get leaf contents
from offchain db while in runtime context.. so no way to get+clear+set
leaf to change its key in offchain db.
Ideas:
1. move the "canonicalization" logic to offchain worker
2. enhance IndexingApi with "offchain::move(old_key, new_key)"
This is weird, but correct, deterministic and safe AFAICT, so
it could be exposed to runtime.
* simplify rightmost_leaf_node_index_from_pos
* minor fix
* move leaf canonicalization to offchain worker
* move storage related code to storage.rs
* on offchain reads use canonic key for old leaves
* fix offchain worker write using canon key
* fix pallet-mmr tests
* add documentation and fix logging
* add offchain mmr canonicalization test
* test canon + generate + verify
* fix pallet-beefy-mmr tests
* implement review suggestions
* improve test
* pallet-mmr: add offchain pruning of forks
* pallet-mmr: improve offchain pruning
Instead of keeping pruning map as single blob in offchain db,
keep individual parent-hash lists with block-num identifier as part
of the offchain key.
Signed-off-by: acatangiu <adrian@parity.io>
* pallet-mmr: improve MMRStore<OffchainStorage>::get()
Do the math and retrieve node using correct (canon or non-canon)
offchain db key, instead of blindly looking in both canon and non-canon
offchain db locations for each node.
Still fallback on looking at both if for any reason it's not where
expected.
Signed-off-by: acatangiu <adrian@parity.io>
* pallet-mmr: storage: improve logs
* fix tests: correctly persist overlay
runtime indexing API works on overlay, whereas offchain context
bypasses overlay, so for loops > canon-window, canon would fail.
* pallet-mmr: fix numeric typo in test
* add comment around LeafData requirements
Signed-off-by: acatangiu <adrian@parity.io>
Co-authored-by: Robert Hambrock <roberthambrock@gmail.com>
* updated mmr rpc api with functions for batch generation of proof
* update code comments
* fix build errors
* added tests to mmr-rpc
* add tests to pallet-mmr
* update comments
* minor comment fix
* remove unused variables
* fix rust doc errors
* refactor mmr runtime api
* fix tests
* minor fix
* minor fix
* fix node-runtime
* revert to initial api
* impl from proof fot batchproof
* minor fix
* minor fix
* use explicit functions to convert btw batch proof and single proof
* minor fix
* add new variant to mmr error
* fmt
* update conversion to single leaf proof
* fix style nit
Co-authored-by: Adrian Catangiu <adrian@parity.io>
* beefy-gadget: allow custom runtime api provider
* beefy-gadget: use mock runtime api in tests
* pallet-mmr: expose mmr root from state through runtime API
* beefy-gadget: get mmr root from runtime state
* pallet-beefy-mmr: remove MmrRoot from header digests
* frame/mmr: move mmr primitives out of frame
* frame/mmr: completely move primitives out of frame
* address review comments
* beefy-mmr: bring back mmr root from header digest
* clippy fixes for rustc 1.60
* address review comments