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

pallet-mmr: RPC and Runtime APIs work with block numbers #6072

Merged
merged 11 commits into from
Oct 13, 2022
418 changes: 239 additions & 179 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions node/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub trait RuntimeApiCollection:
+ ParachainHost<Block>
+ sp_block_builder::BlockBuilder<Block>
+ frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce>
+ sp_mmr_primitives::MmrApi<Block, <Block as BlockT>::Hash>
+ sp_mmr_primitives::MmrApi<Block, <Block as BlockT>::Hash, BlockNumber>
+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>
+ sp_api::Metadata<Block>
+ sp_offchain::OffchainWorkerApi<Block>
Expand All @@ -149,7 +149,7 @@ where
+ ParachainHost<Block>
+ sp_block_builder::BlockBuilder<Block>
+ frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce>
+ sp_mmr_primitives::MmrApi<Block, <Block as BlockT>::Hash>
+ sp_mmr_primitives::MmrApi<Block, <Block as BlockT>::Hash, BlockNumber>
+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>
+ sp_api::Metadata<Block>
+ sp_offchain::OffchainWorkerApi<Block>
Expand Down
6 changes: 5 additions & 1 deletion rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ where
+ Sync
+ 'static,
C::Api: frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: pallet_mmr_rpc::MmrRuntimeApi<Block, <Block as sp_runtime::traits::Block>::Hash>,
C::Api: pallet_mmr_rpc::MmrRuntimeApi<
Block,
<Block as sp_runtime::traits::Block>::Hash,
BlockNumber,
>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BabeApi<Block>,
C::Api: BlockBuilder<Block>,
Expand Down
10 changes: 5 additions & 5 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1714,8 +1714,8 @@ sp_api::impl_runtime_apis! {
}
}

impl mmr::MmrApi<Block, Hash> for Runtime {
fn generate_proof(_leaf_index: u64)
impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
fn generate_proof(_block_number: BlockNumber)
-> Result<(mmr::EncodableOpaqueLeaf, mmr::Proof<Hash>), mmr::Error>
{
Err(mmr::Error::PalletNotIncluded)
Expand All @@ -1739,15 +1739,15 @@ sp_api::impl_runtime_apis! {
Err(mmr::Error::PalletNotIncluded)
}

fn generate_batch_proof(_leaf_indices: Vec<u64>)
fn generate_batch_proof(_block_numbers: Vec<BlockNumber>)
Szegoo marked this conversation as resolved.
Show resolved Hide resolved
-> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error>
{
Err(mmr::Error::PalletNotIncluded)
}

fn generate_historical_batch_proof(
_leaf_indices: Vec<u64>,
_leaves_count: u64,
_block_numbers: Vec<BlockNumber>,
_best_known_block_number: BlockNumber,
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error> {
Err(mmr::Error::PalletNotIncluded)
}
Expand Down
10 changes: 5 additions & 5 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1807,8 +1807,8 @@ sp_api::impl_runtime_apis! {
}
}

impl mmr::MmrApi<Block, Hash> for Runtime {
fn generate_proof(_leaf_index: u64)
impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
fn generate_proof(_block_number: BlockNumber)
-> Result<(mmr::EncodableOpaqueLeaf, mmr::Proof<Hash>), mmr::Error>
{
Err(mmr::Error::PalletNotIncluded)
Expand All @@ -1832,15 +1832,15 @@ sp_api::impl_runtime_apis! {
Err(mmr::Error::PalletNotIncluded)
}

fn generate_batch_proof(_leaf_indices: Vec<u64>)
fn generate_batch_proof(_block_numbers: Vec<BlockNumber>)
-> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error>
{
Err(mmr::Error::PalletNotIncluded)
}

fn generate_historical_batch_proof(
_leaf_indices: Vec<u64>,
_leaves_count: u64,
_block_numbers: Vec<BlockNumber>,
_best_known_block_number: BlockNumber,
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error> {
Err(mmr::Error::PalletNotIncluded)
}
Expand Down
16 changes: 8 additions & 8 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,11 +1690,11 @@ sp_api::impl_runtime_apis! {
}
}

impl mmr::MmrApi<Block, Hash> for Runtime {
fn generate_proof(leaf_index: u64)
impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
fn generate_proof(block_number: BlockNumber)
-> Result<(mmr::EncodableOpaqueLeaf, mmr::Proof<Hash>), mmr::Error>
{
Mmr::generate_batch_proof(vec![leaf_index])
Mmr::generate_batch_proof(vec![block_number])
.and_then(|(leaves, proof)| Ok((
mmr::EncodableOpaqueLeaf::from_leaf(&leaves[0]),
mmr::BatchProof::into_single_leaf_proof(proof)?
Expand Down Expand Up @@ -1725,18 +1725,18 @@ sp_api::impl_runtime_apis! {
Ok(Mmr::mmr_root())
}

fn generate_batch_proof(leaf_indices: Vec<mmr::LeafIndex>)
fn generate_batch_proof(block_numbers: Vec<BlockNumber>)
-> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error>
{
Mmr::generate_batch_proof(leaf_indices)
Mmr::generate_batch_proof(block_numbers)
.map(|(leaves, proof)| (leaves.into_iter().map(|leaf| mmr::EncodableOpaqueLeaf::from_leaf(&leaf)).collect(), proof))
}

fn generate_historical_batch_proof(
leaf_indices: Vec<mmr::LeafIndex>,
leaves_count: mmr::LeafIndex,
block_numbers: Vec<BlockNumber>,
best_known_block_number: BlockNumber,
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error> {
Mmr::generate_historical_batch_proof(leaf_indices, leaves_count).map(
Mmr::generate_historical_batch_proof(block_numbers, best_known_block_number).map(
|(leaves, proof)| {
(
leaves
Expand Down
10 changes: 5 additions & 5 deletions runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,8 +919,8 @@ sp_api::impl_runtime_apis! {
}
}

impl mmr::MmrApi<Block, Hash> for Runtime {
fn generate_proof(_leaf_index: u64)
impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
fn generate_proof(_block_number: BlockNumber)
-> Result<(mmr::EncodableOpaqueLeaf, mmr::Proof<Hash>), mmr::Error>
{
Err(mmr::Error::PalletNotIncluded)
Expand All @@ -944,15 +944,15 @@ sp_api::impl_runtime_apis! {
Err(mmr::Error::PalletNotIncluded)
}

fn generate_batch_proof(_leaf_indices: Vec<u64>)
fn generate_batch_proof(_block_numbers: Vec<BlockNumber>)
-> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error>
{
Err(mmr::Error::PalletNotIncluded)
}

fn generate_historical_batch_proof(
_leaf_indices: Vec<u64>,
_leaves_count: u64,
_block_numbers: Vec<BlockNumber>,
_best_known_block_number: BlockNumber,
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error> {
Err(mmr::Error::PalletNotIncluded)
}
Expand Down
10 changes: 5 additions & 5 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1448,8 +1448,8 @@ sp_api::impl_runtime_apis! {
}
}

impl mmr::MmrApi<Block, Hash> for Runtime {
fn generate_proof(_leaf_index: u64)
impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
fn generate_proof(_block_number: BlockNumber)
-> Result<(mmr::EncodableOpaqueLeaf, mmr::Proof<Hash>), mmr::Error>
{

Expand Down Expand Up @@ -1477,15 +1477,15 @@ sp_api::impl_runtime_apis! {
Err(mmr::Error::PalletNotIncluded)
}

fn generate_batch_proof(_leaf_indices: Vec<u64>)
fn generate_batch_proof(_block_numbers: Vec<BlockNumber>)
-> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error>
{
Err(mmr::Error::PalletNotIncluded)
}

fn generate_historical_batch_proof(
_leaf_indices: Vec<u64>,
_leaves_count: u64,
_block_numbers: Vec<BlockNumber>,
_best_known_block_number: BlockNumber,
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error> {
Err(mmr::Error::PalletNotIncluded)
}
Expand Down