Support MMR Pruning (#9700)

* Use `0.3.2`

* Replace `u64` with `NodeIndex`

* Fix Typo

* Add Pruning Logic

* Fix Some Tests

* Remove Comment

* Log Only Under STD

* Return while No Element to Append

* Optimize Pruning Algorithm

* Update Doc

* Update Doc

* Zero Copy Algorithm

* Import Missing Type

* Fix Merge Mistake

* Import Missing Item

* Make `verify` Off-Chain

* `cargo fmt`

* Avoid using NodeIndex in incorrect places.

* Simplify pruning.

* Format

Co-authored-by: Tomasz Drwięga <tomasz@parity.io>
This commit is contained in:
Xavier Lau
2021-11-23 21:04:05 +08:00
committed by GitHub
parent 76737891bb
commit f9122a870e
11 changed files with 165 additions and 61 deletions
@@ -32,7 +32,7 @@ use sp_blockchain::HeaderBackend;
use sp_core::Bytes;
use sp_runtime::{generic::BlockId, traits::Block as BlockT};
pub use pallet_mmr_primitives::MmrApi as MmrRuntimeApi;
pub use pallet_mmr_primitives::{LeafIndex, MmrApi as MmrRuntimeApi};
/// Retrieved MMR leaf and its proof.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
@@ -71,7 +71,7 @@ pub trait MmrApi<BlockHash> {
#[rpc(name = "mmr_generateProof")]
fn generate_proof(
&self,
leaf_index: u64,
leaf_index: LeafIndex,
at: Option<BlockHash>,
) -> Result<LeafProof<BlockHash>>;
}
@@ -98,7 +98,7 @@ where
{
fn generate_proof(
&self,
leaf_index: u64,
leaf_index: LeafIndex,
at: Option<<Block as BlockT>::Hash>,
) -> Result<LeafProof<<Block as BlockT>::Hash>> {
let api = self.client.runtime_api();