Substrateでのtimestampモジュール解析

1396 ワード

Substrateでのtimestampモジュール解析
Timestampモジュールでは、ブロック認証者が各blockでタイムスタンプを設定および検証することができます.
Inherents(内部固有)を使用してtimestampデータを設定し、ブロックアウト者設定、他のノードで検証します.ブロックごとに1回しか設定できませんが、ブロック高さは時間測定によって問題が発生します.蓄積された計算ミスのため、ブロック高さとして使用時間測定を避ける必要があります.
Trait
///        
type Moment: Parameter + Default + SimpleArithmetic
    + Scale<:blocknumber output="Self::Moment"> + Copy;

///            ,         
type OnTimestampSet: OnTimestampSet<:moment>;

///        
type MinimumPeriod: Get<:moment>;

Module
fn set(origin, #[compact] now: T::Moment)

現在の時間を設定するには、各ブロックに1回しか設定できません.ブロックを出た人は設定し、設定した時間が1つのブロックに設定されたタイムスタンプに続く時間差はMinimumPeriodより大きくなければなりません.
Store
/// Current time for the current block.
pub Now get(fn now) build(|_| 0.into()): T::Moment;

/// Did the timestamp get updated in this block?
DidUpdate: bool;

Module
  • pub fn get() -> T::Moment
  • 現在のブロックのタイムスタンプ
  • を取得する.
  • pub fn set_timestamp(now: T::Moment)
  • 試験網による設定

  • ProvideInherent
    ProvideInherentはノードが署名する必要がなく、内部固有で、主にタイムスタンプです.
  • fn create_inherent(data: &InherentData) -> Option<:call/>
  • fn check_inherent(call: &Self::Call, data: &InherentData) -> result::Result