【问题标题】:Get system time in scope of substrate pallet获取基板托盘范围内的系统时间
【发布时间】:2021-09-10 07:54:15
【问题描述】:

我正在尝试在基材托盘的外部调用执行范围内获取系统时间。 它应该独立于目标架构(wasm、unix 等)和构建模式(std、no_std)

使用 std::time::SystemTime、chrono 或 wasm-timer 库不是一个选项,因为它们严重依赖于 std。

在自定义托盘范围内引用时间戳托盘也不是一种选择,因为它随时提供链上时间戳,即当前或下一个区块时间戳。

问题:

  • 有没有办法使用基板手段在托盘“功能”范围内获取系统/实际当前时间戳

  • 当节点启动时如何初始化托盘时间戳的时间戳/现在值并在运行时递增(它的来源是什么)

  • 您能否建议任何提供此类方法的库,这些方法可以与托盘链接而不会遇到以下类似错误

    Compiling pallet-template v3.0.0-monthly-2021-08 (/workspace/supra/examples/concurrency_poc/node/pallets/template)
 error: duplicate lang item in crate `std` (which `wasm_timer` depends on): `panic_impl`.
   |
   = note: the lang item is first defined in crate `sp_io` (which `frame_support` depends on)
   = note: first definition in `sp_io` loaded from /workspace/supra/examples/concurrency_poc/node/target/debug/wbuild/node-template-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-e941cef754f8762e.rmeta
   = note: second definition in `std` loaded from /home/areg/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-0c448d560077210c.rlib

 error: duplicate lang item in crate `std` (which `wasm_timer` depends on): `oom`.
   |
   = note: the lang item is first defined in crate `sp_io` (which `frame_support` depends on)
   = note: first definition in `sp_io` loaded from /workspace/supra/examples/concurrency_poc/node/target/debug/wbuild/node-template-runtime/target/wasm32-unknown-unknown/release/deps/libsp_io-e941cef754f8762e.rmeta
   = note: second definition in `std` loaded from /home/areg/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-0c448d560077210c.rlib

【问题讨论】:

    标签: timestamp substrate pallet


    【解决方案1】:

    有没有办法使用基板手段在托盘“功能”范围内获取系统/实际当前时间戳

    除了使用pallet-timestamp 或实现类似的pallet,我不知道任何其他方法。

    当节点启动时如何初始化托盘时间戳的时间戳/现在值并在运行时递增(它的来源是什么)

    它使用固有外在,块生产者的客户端生成一些包含当前时间的固有数据,并在运行时apiBlockBuilder::inherent_extrinsics的帮助下生成固有外在放入块中

    其他验证器将通过生成一些内在数据并使用BlockBuilder::check_inherents检查内在外在来检查内在是否良好

    在pallet-timestamp 的情况下,这将检查在块中设置时间戳的内在外部设置是否设置了合理的时间。不久的将来,并且超过有效的最小值:https://docs.rs/pallet-timestamp/3.0.0/src/pallet_timestamp/lib.rs.html#227-245

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-12
    • 2010-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-04
    相关资源
    最近更新 更多