`Hash` is no longer part of `pallet_mmr::Config`, but this code
would still build because it assumes we're referring to underlying
`<pallet_mmr::Config as frame_system::Config>::Hash` which is not
what we want when using different hashing between `frame_system`
and `pallet_mmr`.
Disambiguate by using correct `pallet_mmr::Config::Hashing` type.
Signed-off-by: acatangiu <adrian@parity.io>
* Revert "Optimize merkle proofs for efficient verification in Solidity (#12857)"
This reverts commit c077597afb since we
still require commitment to the leaves - see #12820.
* remove PartialOrd trait from mmr hash type
* Remove use of trait Store from staking pallet
* Remove use of trait Store from bounties pallet
* Remove use of trait Store from collective pallet
* Remove use of trait Store from babe pallet
* Remove use of trait Store from assets pallet
* Remove use of trait Store from grandpa pallet
* Remove use of trait Store from balances pallet
* Remove use of trait Store from authorship pallet
* Remove use of trait Store from authority-discovery pallet
* Remove use of trait Store from atomic-swap pallet
* Remove use of trait Store from sudo pallet
* Remove use of trait Store from scheduler pallet
* Remove use of trait Store from scored-pool pallet
* Remove use of trait Store from society pallet
* Remove use of trait Store from lottery pallet
* Remove use of trait Store from executive pallet
* Remove use of trait Store from democracy pallet
* Remove use of trait Store from elections-phragmen pallet
* Remove use of trait Store from indices pallet
* Remove use of trait Store from identity pallet
* Remove use of trait Store from multisig pallet
* Remove use of trait Store from merkle-mountain-range pallet
* Remove use of trait Store from im-online pallet
* Remove use of trait Store from membership pallet
* Remove use of trait Store from nicks pallet
* Remove use of trait Store from session pallet
* Remove use of trait Store from transaction-payment pallet
* Remove use of trait Store from utility pallet
* Remove use of trait Store from child-bounties pallet
* Remove use of trait Store from nis pallet
* Remove use of trait Store from nfts pallet
* Remove use of trait Store from conviction-voting pallet
* Remove use of trait Store from treasury pallet
* Remove use of trait Store from vesting pallet
* Remove use of trait Store from preimage pallet
* Remove use of trait Store from uniques pallet
* Remove use of trait Store from ranked-collective pallet
* Remove use of trait Store from beefy-mmr pallet
* Remove use of trait Store from referenda pallet
* Remove use of trait Store from whitelist pallet
* Remove use of trait Store from alliance pallet
* Remove use of trait Store from nomination-pools pallet
* Remove use of trait Store from state-trie-migration pallet
* Remove use of trait Store from message-queue pallet
* Remove use of trait Store from root-offences pallet
* Remove use of trait Store from root-testing pallet
* Remove use of trait Store from timestamps pallet
* Remove use of trait Store from system pallet
* Remove use of trait Store from offences pallet
* Remove use of trait Store from recovery pallet
* Remove use of trait Store from node-authorization pallet
* Remove use of trait Store from proxy pallet
* Remove use of trait Store from benchmarking pallet
* Remove use of trait Store from bags-list pallet
* Add deprecated warning in store_trait
* Change warning message
* Run cargo fmt
* Fix warning and update tests
* Remove unnecessary allow deprecated
* Remove use of trait Store
* Fix mismatch in expected output
* Minor update to warning message for deprecation of generate_store with Store trait attribute
* Fixes as per review comments
* Fixes as per review suggestions
* Remove use of Store trait from core-fellowship pallet
* Fix type in store_trait.rs
* Fixes as pre review comment
* Trivial adjustments to beefy and grandpa pallets
* Introduce offence report system to beefy pallet
* Minor adjustments
* Fix beefy-mmr mock
* Apply suggestions from code review
Co-authored-by: Anton <anton.kalyaev@gmail.com>
---------
Co-authored-by: Anton <anton.kalyaev@gmail.com>
* Change copyright year to 2023 from 2022
* Fix incorrect update of copyright year
* Remove years from copy right header
* Fix remaining files
* Fix typo in a header and remove update-copyright.sh
Add limit for the number of entries in the `SetIdSession` mapping.
For example, it can be set to the bonding duration (in sessions).
Signed-off-by: acatangiu <adrian@parity.io>
* move BeefyMmrApi to pallet-beefy-mmr
* fix test_utils use pallet-beefy-mmr BeefyMmrApi
* Move beefy-merkle-tree to utils and Rename to Merkle-tree
* fix fmt and test
* Update merkle-tree to binary-merkle-tree and Remove Keccak256 mod from merkle-tree
* change merkle-tree name to binary-merkle-tree
* mirr fix
* pallet-mmr: cosmetic improvements
* pallet-mmr: fix offchain storage for initial sync
* address review comments
* pallet-mmr: change offchain fork-resistant key to `(prefix, pos, parent_hash)`
Do this so that both canon and fork-resitant keys have the same
`(prefix, pos).encode()` prefix. Might be useful in the future if we'd
be able to to "get" offchain db entries using key prefixes as well.
Signed-off-by: acatangiu <adrian@parity.io>
Signed-off-by: acatangiu <adrian@parity.io>
* beefy-mmr: reuse sp_runtime::traits::Keccak256
* beefy-mmr: use sp_runtime::traits:Hash for generating merkle proofs
* beefy-mmr: use sp_runtime::traits:Hash for validating merkle proofs
* beefy-mmr: remove primitives::Hasher and primitives::Hash
* fixes
* beefy-mmr: reduce the number of generic parameters for merkle_root()
* fix
* compute upper Vec capacity more accurately
* 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 <>
* BREAKING: Rename Origin
* more renaming
* a bit more renaming
* fix
* more fixing
* fix in frame_support
* even more fixes
* fix
* small fix
* ...
* update .stderr
* docs
* update docs
* update docs
* docs
* 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>
* pallet-beefy: add Config::OnNewValidatorSet type
Add a hook to pallet-beefy for doing specific work when
BEEFY validator set changes.
For example, this can be used by pallet-beefy-mmr to cache
a lightweight MMR root over validators and make it available
to light clients.
* pallet-beefy-mmr: implement OnNewValidatorSet
Implement pallet-beefy::OnNewValidatorSet to be notified of BEEFY
validator set changes. Use the notifications to compute and cache
a light weight 'BEEFY authority set' which is an MMR root over
BEEFY validator set plus some extra info.
Previously, pallet-beefy-mmr was interogating pallet-beefy about
validator set id on every block to find out when it needs to recompute
the authority set.
By using the event-driven approach in this commit, we also save one
extra state interogation per block.
* pallet-beefy-mmr: add new authority_set() API
Expose current and next BEEFY authority sets through runtime API.
These can be directly used by light clients to avoid having them
compute them themselves based on BEEFY validator sets.
Signed-off-by: acatangiu <adrian@parity.io>
* rename BeefyMmr exposed runtime api
* Implement MaxEncodedLen on pallet-beefy
* Return Result in intialize_authorities
* Update docs
* Log error when authorities list gets truncated
* Update frame/beefy/src/lib.rs
Co-authored-by: Adrian Catangiu <adrian@parity.io>
* cargo fmt
Co-authored-by: Adrian Catangiu <adrian@parity.io>
* `ecdsa::Public::to_eth_address` + test, beefy-mmr `convert()` to use it, contracts Ext interface
* `seal_ecdsa_to_eth_address` all but benchmark done
* `seal_ecdsa_to_eth_address` + wasm test
* `seal_ecdsa_to_eth_address` + benchmark
* fixed dependencies
* Apply suggestions from code review
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* fixes from review #1
* ecdsa::Public(*pk).to_eth_address() moved to frame_support and contracts to use it
* beefy-mmr to use newly added frame_support function for convertion
* a doc fix
* import fix
* benchmark fix-1 (still fails)
* benchmark fixed
* Apply suggestions from code review
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* fixes on Alex T feedback
* to_eth_address() put into extension trait for sp-core::ecdsa::Public
* Update frame/support/src/crypto/ecdsa.rs
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* Update frame/contracts/src/wasm/mod.rs
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* fixes on issues pointed out in review
* benchmark errors fixed
* fmt fix
* EcdsaRecoverFailed err docs updated
* Apply suggestions from code review
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* make applied suggestions compile
* get rid of unwrap() in runtime
* Remove expect
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Bastian Köcher <info@kchr.de>
* 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
* refactor beefy mmr
* use plain vector of bytes for leaf extra
* update comment
* update comments
* remove unused vars
* Use sp_std::vec::Vec
Co-authored-by: Adrian Catangiu <adrian@parity.io>
* make extra data generic
* fix tests
* refactor beefy-mmr
* Update frame/beefy-mmr/src/lib.rs
* minor fix
* fmt
* Update frame/beefy-mmr/src/lib.rs
Co-authored-by: Adrian Catangiu <adrian@parity.io>
* Replace libsecp256k1 with k256 in beefy-mmr
* Port of FRAME `contracts` benchmarking from `libsecp256k1` to `k256`
* Newtype to allow `Pcg32` rng usage with `k256` in contracts benchmarks
* Use `sp-io::crypto` to generate dummy keys in `contracts` bechmarks
* More compact code
* Cargo fmt
* Build `sp-keystore` only for dev profile
* Move public key generation back to the `map`
Compressed ECDSA keys requires to have 0x02 or 0x03 as their first byte
in order to allow public key recovery.
Nevertheless the test was working because of the `unwrap_or_default()`
at the end of the conversion routine (i.e. the invalid keys were
converted to an empty vector).