Crate pallet_block_producer_metadata

Source
Expand description

Pallet storing metadata for Partner Chain block producers.

§Purpose of this pallet

This pallet enables Partner Chain block producers to provide information about themselves that can then be displayed by chain explorers and other tools to potential delegators looking for pools to delegate to.

§Usage - PC Builders

PC Builders wishing to include this pallet in their runtime should first define a BlockProducerMetadata type for their runtime to use, eg.

use sidechain_domain::byte_string::BoundedString;
use sp_core::{Encode, ConstU32, Decode, MaxEncodedLen};

type MaxNameLength = ConstU32<64>;
type MaxDescriptionLength = ConstU32<512>;
type MaxUrlLength = ConstU32<256>;

#[derive(Encode, Decode, MaxEncodedLen)]
pub struct BlockProducerMetadata {
    pub name: BoundedString<MaxNameLength>,
    pub description: BoundedString<MaxDescriptionLength>,
    pub logo_url: BoundedString<MaxUrlLength>
}

This type can be arbitrary to allow PC Builders to include any data that would be relevant to their chain. However, care should be taken to keep its size to minimum to avoid inflating on-chain storage size by eg. linking to off-chain storage for bulkier data:

pub struct BlockProducerMetadataType {
    pub url: BoundedString<MaxUrlLength>,
    pub hash: SizedByteString<32>,
}

Once the metadata type is defined, the pallet can be added to the runtime and should be configured:

impl pallet_block_producer_metadata::Config for Runtime {
    type WeightInfo = pallet_block_producer_metadata::weights::SubstrateWeight<Runtime>;

    type BlockProducerMetadata = BlockProducerMetadata;

    fn genesis_utxo() -> sidechain_domain::UtxoId {
        Sidechain::genesis_utxo()
    }
}

Here, besides providing the metadata type and using weights already provided with the pallet, we are also wiring the genesis_utxo function to fetch the chain’s genesis UTXO from the pallet_sidechain pallet.

At this point, the pallet is ready to be used.

§Signing command

To ensure that only the block producer is able to update their own metadata, a signature is required by the pallet’s extrinsic. To make it easy for PC Builders to provide their users with a signing utility, the cli_commands crate includes a command for signing the appropriate message. Consult the crate’s own documentation for more details.

§Benchmarking

See documentation of [benchmarking] module.

§RPC

See documentation of pallet_block_producer_metadata_rpc crate.

§Usage - PC Users

This pallet exposes a single extrinsic upsert_metadata for current or prospective block producers to add or update their metadata. The extrinsic requires a valid signature, which the user should prepare using the sign-block-producer-metadata command provided by the chain’s node. This command returns the signature and the metadata encoded as hex bytes.

After the signature has been obtained, the user should submit the upsert_metadata extrinsic (eg. using PolkadotJS) providing:

  • metadata value: when using PolkadotJS UI, care must be taken to submit the same values that were passed to the CLI
  • signature returned by the CLI
  • cross-chain public key corresponding to the private key used for signing with the CLI

Re-exports§

pub use pallet::*;

Modules§

pallet
The pallet module in each FRAME pallet hosts the most important items needed to construct this pallet.
weights
Autogenerated weights for pallet_block_producer_metadata