mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 00:28:01 +00:00
Companion for substrate#12530: Consolidate and deduplicate MMR API methods (#6167)
* histor. batch proof: make best block arg optional
* make generate_batch_proof stub for historical
* merge generate_{historical_}batch_proof functions
* merge generate_{batch_}proof functions
* merge verify_{batch_}proof functions
* merge verify_{batch_}proof_stateless functions
* rename BatchProof->Proof
* update lockfile for {"substrate"}
Co-authored-by: parity-processbot <>
This commit is contained in:
Generated
+182
-180
File diff suppressed because it is too large
Load Diff
@@ -1691,53 +1691,27 @@ sp_api::impl_runtime_apis! {
|
||||
}
|
||||
|
||||
impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
|
||||
fn generate_proof(_block_number: BlockNumber)
|
||||
-> Result<(mmr::EncodableOpaqueLeaf, mmr::Proof<Hash>), mmr::Error>
|
||||
{
|
||||
fn mmr_root() -> Result<Hash, mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_proof(_leaf: mmr::EncodableOpaqueLeaf, _proof: mmr::Proof<Hash>)
|
||||
fn generate_proof(
|
||||
_block_numbers: Vec<BlockNumber>,
|
||||
_best_known_block_number: Option<BlockNumber>,
|
||||
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::Proof<Hash>), mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::Proof<Hash>)
|
||||
-> Result<(), mmr::Error>
|
||||
{
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_proof_stateless(
|
||||
_root: Hash,
|
||||
_leaf: mmr::EncodableOpaqueLeaf,
|
||||
_proof: mmr::Proof<Hash>
|
||||
) -> Result<(), mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn mmr_root() -> Result<Hash, mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
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(
|
||||
_block_numbers: Vec<BlockNumber>,
|
||||
_best_known_block_number: BlockNumber,
|
||||
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_batch_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::BatchProof<Hash>)
|
||||
-> Result<(), mmr::Error>
|
||||
{
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_batch_proof_stateless(
|
||||
_root: Hash,
|
||||
_leaves: Vec<mmr::EncodableOpaqueLeaf>,
|
||||
_proof: mmr::BatchProof<Hash>
|
||||
_proof: mmr::Proof<Hash>
|
||||
) -> Result<(), mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
@@ -1848,53 +1848,27 @@ sp_api::impl_runtime_apis! {
|
||||
}
|
||||
|
||||
impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
|
||||
fn generate_proof(_block_number: BlockNumber)
|
||||
-> Result<(mmr::EncodableOpaqueLeaf, mmr::Proof<Hash>), mmr::Error>
|
||||
{
|
||||
fn mmr_root() -> Result<Hash, mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_proof(_leaf: mmr::EncodableOpaqueLeaf, _proof: mmr::Proof<Hash>)
|
||||
fn generate_proof(
|
||||
_block_numbers: Vec<BlockNumber>,
|
||||
_best_known_block_number: Option<BlockNumber>,
|
||||
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::Proof<Hash>), mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::Proof<Hash>)
|
||||
-> Result<(), mmr::Error>
|
||||
{
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_proof_stateless(
|
||||
_root: Hash,
|
||||
_leaf: mmr::EncodableOpaqueLeaf,
|
||||
_proof: mmr::Proof<Hash>
|
||||
) -> Result<(), mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn mmr_root() -> Result<Hash, mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
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(
|
||||
_block_numbers: Vec<BlockNumber>,
|
||||
_best_known_block_number: BlockNumber,
|
||||
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_batch_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::BatchProof<Hash>)
|
||||
-> Result<(), mmr::Error>
|
||||
{
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_batch_proof_stateless(
|
||||
_root: Hash,
|
||||
_leaves: Vec<mmr::EncodableOpaqueLeaf>,
|
||||
_proof: mmr::BatchProof<Hash>
|
||||
_proof: mmr::Proof<Hash>
|
||||
) -> Result<(), mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
@@ -1691,52 +1691,15 @@ sp_api::impl_runtime_apis! {
|
||||
}
|
||||
|
||||
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![block_number])
|
||||
.and_then(|(leaves, proof)| Ok((
|
||||
mmr::EncodableOpaqueLeaf::from_leaf(&leaves[0]),
|
||||
mmr::BatchProof::into_single_leaf_proof(proof)?
|
||||
)))
|
||||
}
|
||||
|
||||
fn verify_proof(leaf: mmr::EncodableOpaqueLeaf, proof: mmr::Proof<Hash>)
|
||||
-> Result<(), mmr::Error>
|
||||
{
|
||||
pub type MmrLeaf = <<Runtime as pallet_mmr::Config>::LeafData as mmr::LeafDataProvider>::LeafData;
|
||||
let leaf: MmrLeaf = leaf
|
||||
.into_opaque_leaf()
|
||||
.try_decode()
|
||||
.ok_or(mmr::Error::Verify)?;
|
||||
Mmr::verify_leaves(vec![leaf], mmr::Proof::into_batch_proof(proof))
|
||||
}
|
||||
|
||||
fn verify_proof_stateless(
|
||||
root: Hash,
|
||||
leaf: mmr::EncodableOpaqueLeaf,
|
||||
proof: mmr::Proof<Hash>
|
||||
) -> Result<(), mmr::Error> {
|
||||
let node = mmr::DataOrHash::Data(leaf.into_opaque_leaf());
|
||||
pallet_mmr::verify_leaves_proof::<MmrHashing, _>(root, vec![node], mmr::Proof::into_batch_proof(proof))
|
||||
}
|
||||
|
||||
fn mmr_root() -> Result<Hash, mmr::Error> {
|
||||
Ok(Mmr::mmr_root())
|
||||
}
|
||||
|
||||
fn generate_batch_proof(block_numbers: Vec<BlockNumber>)
|
||||
-> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error>
|
||||
{
|
||||
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(
|
||||
fn generate_proof(
|
||||
block_numbers: Vec<BlockNumber>,
|
||||
best_known_block_number: BlockNumber,
|
||||
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error> {
|
||||
Mmr::generate_historical_batch_proof(block_numbers, best_known_block_number).map(
|
||||
best_known_block_number: Option<BlockNumber>,
|
||||
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::Proof<Hash>), mmr::Error> {
|
||||
Mmr::generate_proof(block_numbers, best_known_block_number).map(
|
||||
|(leaves, proof)| {
|
||||
(
|
||||
leaves
|
||||
@@ -1749,7 +1712,7 @@ sp_api::impl_runtime_apis! {
|
||||
)
|
||||
}
|
||||
|
||||
fn verify_batch_proof(leaves: Vec<mmr::EncodableOpaqueLeaf>, proof: mmr::BatchProof<Hash>)
|
||||
fn verify_proof(leaves: Vec<mmr::EncodableOpaqueLeaf>, proof: mmr::Proof<Hash>)
|
||||
-> Result<(), mmr::Error>
|
||||
{
|
||||
pub type MmrLeaf = <<Runtime as pallet_mmr::Config>::LeafData as mmr::LeafDataProvider>::LeafData;
|
||||
@@ -1760,10 +1723,10 @@ sp_api::impl_runtime_apis! {
|
||||
Mmr::verify_leaves(leaves, proof)
|
||||
}
|
||||
|
||||
fn verify_batch_proof_stateless(
|
||||
fn verify_proof_stateless(
|
||||
root: Hash,
|
||||
leaves: Vec<mmr::EncodableOpaqueLeaf>,
|
||||
proof: mmr::BatchProof<Hash>
|
||||
proof: mmr::Proof<Hash>
|
||||
) -> Result<(), mmr::Error> {
|
||||
let nodes = leaves.into_iter().map(|leaf|mmr::DataOrHash::Data(leaf.into_opaque_leaf())).collect();
|
||||
pallet_mmr::verify_leaves_proof::<MmrHashing, _>(root, nodes, proof)
|
||||
|
||||
@@ -926,53 +926,27 @@ sp_api::impl_runtime_apis! {
|
||||
}
|
||||
|
||||
impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
|
||||
fn generate_proof(_block_number: BlockNumber)
|
||||
-> Result<(mmr::EncodableOpaqueLeaf, mmr::Proof<Hash>), mmr::Error>
|
||||
{
|
||||
fn mmr_root() -> Result<Hash, mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_proof(_leaf: mmr::EncodableOpaqueLeaf, _proof: mmr::Proof<Hash>)
|
||||
fn generate_proof(
|
||||
_block_numbers: Vec<BlockNumber>,
|
||||
_best_known_block_number: Option<BlockNumber>,
|
||||
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::Proof<Hash>), mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::Proof<Hash>)
|
||||
-> Result<(), mmr::Error>
|
||||
{
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_proof_stateless(
|
||||
_root: Hash,
|
||||
_leaf: mmr::EncodableOpaqueLeaf,
|
||||
_proof: mmr::Proof<Hash>
|
||||
) -> Result<(), mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn mmr_root() -> Result<Hash, mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
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(
|
||||
_block_numbers: Vec<BlockNumber>,
|
||||
_best_known_block_number: BlockNumber,
|
||||
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_batch_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::BatchProof<Hash>)
|
||||
-> Result<(), mmr::Error>
|
||||
{
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_batch_proof_stateless(
|
||||
_root: Hash,
|
||||
_leaves: Vec<mmr::EncodableOpaqueLeaf>,
|
||||
_proof: mmr::BatchProof<Hash>
|
||||
_proof: mmr::Proof<Hash>
|
||||
) -> Result<(), mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
@@ -1458,14 +1458,19 @@ sp_api::impl_runtime_apis! {
|
||||
}
|
||||
|
||||
impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
|
||||
fn generate_proof(_block_number: BlockNumber)
|
||||
-> Result<(mmr::EncodableOpaqueLeaf, mmr::Proof<Hash>), mmr::Error>
|
||||
{
|
||||
fn mmr_root() -> Result<Hash, mmr::Error> {
|
||||
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_proof(_leaf: mmr::EncodableOpaqueLeaf, _proof: mmr::Proof<Hash>)
|
||||
fn generate_proof(
|
||||
_block_numbers: Vec<BlockNumber>,
|
||||
_best_known_block_number: Option<BlockNumber>,
|
||||
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::Proof<Hash>), mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::Proof<Hash>)
|
||||
-> Result<(), mmr::Error>
|
||||
{
|
||||
|
||||
@@ -1473,43 +1478,9 @@ sp_api::impl_runtime_apis! {
|
||||
}
|
||||
|
||||
fn verify_proof_stateless(
|
||||
_root: Hash,
|
||||
_leaf: mmr::EncodableOpaqueLeaf,
|
||||
_proof: mmr::Proof<Hash>
|
||||
) -> Result<(), mmr::Error> {
|
||||
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn mmr_root() -> Result<Hash, mmr::Error> {
|
||||
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
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(
|
||||
_block_numbers: Vec<BlockNumber>,
|
||||
_best_known_block_number: BlockNumber,
|
||||
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error> {
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_batch_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::BatchProof<Hash>)
|
||||
-> Result<(), mmr::Error>
|
||||
{
|
||||
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
}
|
||||
|
||||
fn verify_batch_proof_stateless(
|
||||
_root: Hash,
|
||||
_leaves: Vec<mmr::EncodableOpaqueLeaf>,
|
||||
_proof: mmr::BatchProof<Hash>
|
||||
_proof: mmr::Proof<Hash>
|
||||
) -> Result<(), mmr::Error> {
|
||||
|
||||
Err(mmr::Error::PalletNotIncluded)
|
||||
|
||||
Reference in New Issue
Block a user