update MMR API (#5479)

* update MMR RPC API

use latest MMR RPC API

* update MMR API

* correct mmr_root interface

* add back v1 of MmrApi

* decouple mmr api v1 & v2

the signature's changed in v2 for all runtime calls that they share.

* Apply suggestions (all dangling ,'s as reported)

* Apply lint fixes (asc. order of keys & missing ;)

---------

Co-authored-by: Jaco <jacogr@gmail.com>
This commit is contained in:
Robert Hambrock
2023-03-23 12:11:33 +02:00
committed by GitHub
co-authored by Jaco
parent 17a7427e04
commit a79dcca89f
9 changed files with 138 additions and 79 deletions
@@ -22,6 +22,7 @@ export default {
MmrError: {
_enum: ['Push', 'GetRoot', 'Commit', 'GenerateProof', 'Verify', 'LeafNotFound', ' PalletNotIncluded', 'InvalidLeafIndex']
},
MmrHash: 'Hash',
MmrLeafBatchProof: {
blockHash: 'BlockHash',
leaves: 'Bytes',
+43 -15
View File
@@ -4,27 +4,16 @@
import type { DefinitionsRpc } from '../../types/index.js';
export const rpc: DefinitionsRpc = {
generateBatchProof: {
description: 'Generate MMR proof for the given leaf indices.',
generateProof: {
description: 'Generate MMR proof for the given block numbers.',
params: [
{
name: 'leafIndices',
name: 'blockNumbers',
type: 'Vec<u64>'
},
{
isHistoric: true,
isOptional: true,
name: 'at',
type: 'BlockHash'
}
],
type: 'MmrLeafProof'
},
generateProof: {
description: 'Generate MMR proof for given leaf index.',
params: [
{
name: 'leafIndex',
name: 'bestKnownBlockNumber',
type: 'u64'
},
{
@@ -35,5 +24,44 @@ export const rpc: DefinitionsRpc = {
}
],
type: 'MmrLeafBatchProof'
},
root: {
description: 'Get the MMR root hash for the current best block.',
params: [
{
isHistoric: true,
isOptional: true,
name: 'at',
type: 'BlockHash'
}
],
type: 'MmrHash'
},
verifyProof: {
description: 'Verify an MMR proof',
params: [
{
name: 'proof',
type: 'MmrLeafBatchProof'
}
],
type: 'bool'
},
verifyProofStateless: {
description: 'Verify an MMR proof statelessly given an mmr_root',
params: [
{
name: 'root',
type: 'MmrHash'
},
{
name: 'proof',
type: 'MmrLeafBatchProof'
}
],
type: 'bool'
}
};
+57 -3
View File
@@ -3,7 +3,61 @@
import type { DefinitionCall, DefinitionsCall } from '../../types/index.js';
const MMR_V1_V2: Record<string, DefinitionCall> = {
const MMR_V2: Record<string, DefinitionCall> = {
generate_proof: {
description: 'Generate MMR proof for the given block numbers.',
params: [
{
name: 'blockNumbers',
type: 'Vec<BlockNumber>'
},
{
name: 'bestKnownBlockNumber',
type: 'Option<BlockNumber>'
}
],
type: 'Result<(Vec<MmrEncodableOpaqueLeaf>, MmrBatchProof), MmrError>'
},
root: {
description: 'Return the on-chain MMR root hash.',
params: [],
type: 'Result<Hash, MmrError>'
},
verify_proof: {
description: 'Verify MMR proof against on-chain MMR.',
params: [
{
name: 'leaves',
type: 'Vec<MmrEncodableOpaqueLeaf>'
},
{
name: 'proof',
type: 'MmrBatchProof'
}
],
type: 'Result<(), MmrError>'
},
verify_proof_stateless: {
description: 'Verify MMR proof against given root hash.',
params: [
{
name: 'root',
type: 'Hash'
},
{
name: 'leaves',
type: 'Vec<MmrEncodableOpaqueLeaf>'
},
{
name: 'proof',
type: 'MmrBatchProof'
}
],
type: 'Result<(), MmrError>'
}
};
const MMR_V1: Record<string, DefinitionCall> = {
generate_batch_proof: {
description: 'Generate MMR proof for a series of leaves under given indices.',
params: [
@@ -98,11 +152,11 @@ const MMR_V1_V2: Record<string, DefinitionCall> = {
export const runtime: DefinitionsCall = {
MmrApi: [
{
methods: MMR_V1_V2,
methods: MMR_V2,
version: 2
},
{
methods: MMR_V1_V2,
methods: MMR_V1,
version: 1
}
]
@@ -28,6 +28,9 @@ export interface MmrError extends Enum {
readonly type: 'Push' | 'GetRoot' | 'Commit' | 'GenerateProof' | 'Verify' | 'LeafNotFound' | 'PalletNotIncluded' | 'InvalidLeafIndex';
}
/** @name MmrHash */
export interface MmrHash extends Hash {}
/** @name MmrLeafBatchProof */
export interface MmrLeafBatchProof extends Struct {
readonly blockHash: BlockHash;