Crates.io | pallet-im-online |
lib.rs | pallet-im-online |
version | 37.0.0 |
source | src |
created_at | 2020-02-27 23:21:36.957682 |
updated_at | 2024-09-26 06:38:12.081986 |
description | FRAME's I'm online pallet |
homepage | https://paritytech.github.io/polkadot-sdk/ |
repository | https://github.com/paritytech/polkadot-sdk.git |
max_upload_size | |
id | 213381 |
size | 72,182 |
If the local node is a validator (i.e. contains an authority key), this module gossips a heartbeat transaction with each new session. The heartbeat functions as a simple mechanism to signal that the node is online in the current era.
Received heartbeats are tracked for one era and reset with each new era. The module exposes two public functions to query if a heartbeat has been received in the current era or session.
The heartbeat is a signed transaction, which was signed using the session key
and includes the recent best block number of the local validators chain as well
as the NetworkState
.
It is submitted as an Unsigned Transaction via off-chain workers.
is_online
- True if the validator sent a heartbeat in the current session.use pallet_im_online::{self as im_online};
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::config]
pub trait Config: frame_system::Config + im_online::Config {}
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(0)]
pub fn is_online(origin: OriginFor<T>, authority_index: u32) -> DispatchResult {
let _sender = ensure_signed(origin)?;
let _is_online = <im_online::Pallet<T>>::is_online(authority_index);
Ok(())
}
}
}
This module depends on the Session module.
License: Apache-2.0
Polkadot SDK stable2409