timestamp - 获取基板托盘范围内的系统时间
问题描述
我试图在基板托盘的外部调用执行范围内获取系统时间。它应该独立于目标架构(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
解决方案
有没有办法使用基板手段在托盘“功能”范围内获取系统/实际当前时间戳
除了使用托盘时间戳或实施类似托盘之外,我不知道任何其他方式。
当节点启动并在运行时递增时如何初始化托盘时间戳的时间戳/现在值(它的来源是什么)
它使用固有外部,块生产者的客户端生成一些包含当前时间的固有数据,并在运行时 api BlockBuilder::inherent_extrinsics的帮助下生成固有外部放入块中
其他验证器将通过生成一些内在数据并使用BlockBuilder::check_inherents检查内在外在来检查内在是否良好
在托盘时间戳的情况下,这将检查块中固有的外部设置时间戳是否设置了一个合理的时间。不久的将来,并且超过有效的最小值:https ://docs.rs/pallet-timestamp/3.0.0/src/pallet_timestamp/lib.rs.html#227-245
推荐阅读
- docker - Docker 推送到私有注册表错误 [拒绝:请求的资源访问被拒绝]
- python - 如何使用python在csv文件的开头插入一列
- centos - 在哪里可以找到 centos 的 scp 退出代码的完整列表
- node.js - 从 Node 获取包含二进制文件的对象数组
- azure-devops - Azure devops 管道格式不正确的 cron 语法
- c# - dotnet core IdentityModel 使用范围保护端点
- django - 无法看到 chart.js 中的线条
- python - 如何通过 Java 中的 GET 请求按日期过滤 JSON 输入
- amazon-web-services - 是否可以使用 AWS KMS 进行密钥管理,但将密钥保存在内存中以在本地加密/解密(无需进一步的 api 调用)?
- javascript - 为几个对象制作灵活的文本