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 @@ -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 @@ -1708,8 +1708,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 @@ -1733,15 +1733,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<u64>,
_best_known_block_number: u64,
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
10 changes: 5 additions & 5 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1797,8 +1797,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 @@ -1822,15 +1822,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<u64>,
_best_known_block_number: u64,
) -> 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 @@ -1682,11 +1682,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 @@ -1717,18 +1717,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<mmr::LeafIndex>,
best_known_block_number: mmr::LeafIndex,
) -> 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 @@ -916,8 +916,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 @@ -941,15 +941,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<u64>,
_best_known_block_number: u64,
) -> 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 @@ -1442,8 +1442,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 @@ -1471,15 +1471,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<u64>,
_best_known_block_number: u64,
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error> {
Err(mmr::Error::PalletNotIncluded)
}
Expand Down