Expand description

Gear Messenger Pallet

The Gear Messenger Pallet provides functionality for handling messages.

Overview

The Gear Messenger Pallet’s main aim is to separate message storages out of Gear’s execution logic and provide soft functionality to manage them.

The Gear Messenger Pallet provides functions for:

  • Counting amount of messages sent from outside (from extrinsics) within the current block.
  • Counting amount of messages removed from queue to be processed or skipped withing the current block.
  • Managing continuation of queue processing withing the current block.
  • Storing and managing message queue, it’s pushing and popping algorithms.
  • Storing and managing mailbox, it’s insertion and removal algorithms, including the value claiming with Balances Pallet as Currency Config’s associated type.

Interface

The Gear Messenger Pallet implements gear_common::storage::Messenger trait and shouldn’t contain any other functionality, except this trait declares.

Usage

How to use the messaging functionality from the Gear Messenger Pallet:

  1. Implement it’s Config for your runtime with specified Currency type.
// `runtime/src/lib.rs`
// ... //

impl pallet_gear_messenger::Config for Runtime {
    type Currency = .. ;
}

// ... //
  1. Provide associated type for your pallet’s Config, which implements gear_common::storage::Messenger trait, specifying associated types if needed.
// `some_pallet/src/lib.rs`
// ... //

use gear_common::storage::Messenger;

#[pallet::config]
pub trait Config: frame_system::Config {
    // .. //

    type Messenger: Messenger<Capacity = u32>;

    // .. //
}
  1. Declare Gear Messenger Pallet in your construct_runtime! macro.
// `runtime/src/lib.rs`
// ... //

construct_runtime!(
    pub enum Runtime
        where // ... //
    {
        // ... //

        GearMessenger: pallet_gear_messenger,

        // ... //
    }
);

// ... //

GearMessenger: pallet_gear_messenger

  1. Set GearMessenger as your pallet Config’s `Messenger type.
// `runtime/src/lib.rs`
// ... //

impl some_pallet::Config for Runtime {
    // ... //

    type Messenger = GearMessenger;

    // ... //
}

// ... //
  1. Work with Gear Messenger Pallet in your pallet with provided associated type interface.

Genesis config

The Gear Messenger Pallet doesn’t depend on the GenesisConfig.

Assumptions

  • You should manually control storage load from queue and mailbox length overflow (see Gear Payment Pallet).

Re-exports

Modules

  • Database migration module.
  • The module that hosts all the FRAME types needed to add this pallet to a runtime.