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
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 @@ -106,7 +106,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
6 changes: 3 additions & 3 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1676,8 +1676,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 @@ -1701,7 +1701,7 @@ 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)
Expand Down
6 changes: 3 additions & 3 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1762,8 +1762,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 @@ -1787,7 +1787,7 @@ 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)
Expand Down
10 changes: 5 additions & 5 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1661,11 +1661,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 @@ -1696,10 +1696,10 @@ 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))
}

Expand Down
6 changes: 3 additions & 3 deletions runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,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 @@ -943,7 +943,7 @@ 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)
Expand Down
6 changes: 3 additions & 3 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1385,8 +1385,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 @@ -1414,7 +1414,7 @@ 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>
{

Expand Down