新闻详情

新闻详情

首页 / 资讯中心 / 详情

DataHaven 的 Ethereum System Runtime API 深度指南:在 Substrate 运行时中查询 Ethereum 上的 Agent ID

发布时间:2026/11/17 7:26:10来源:尧图网络
DataHaven 的 Ethereum System Runtime API 深度指南:在 Substrate 运行时中查询 Ethereum 上的 Agent ID
区块链存储Web3【免费下载链接】datahavenAn EVM compatible Substrate chain, powered by StorageHub and secured by EigenLayer项目地址https://gitcode.com/gh_mirrors/da/datahaven点击查看免费下载本指南聚焦 DataHavenEVM 兼容的 Substrate 链由 StorageHub 驱动并由 EigenLayer 保障安全中 Snowbridge 系统运行时 API 的核心实现。我们将以 operator/pallets/system/runtime-api/README.md 为骨架深入解读ControlApi运行时 API 的声明、agent_id的底层计算逻辑、三条链mainnet/stagenet/testnet中的接入方式以及它在跨链桥体系中的实际用途。读完本文你将掌握如何查看、理解并复用以太坊侧 Agent 身份映射的完整调用链。一、这个 API 解决什么问题Agent ID 查询跨链桥场景中一条链如 Asset Hub、Bridge Hub需要在以太坊上拥有一个主权账户用于托管资产、接收消息。在 DataHaven 使用的 Snowbridge 体系中这个账户由部署在 Ethereum 上的Agent 合约承担。而ControlApi提供的agent_id函数就是完成给定一个 XCM Location → 得到唯一 Agent ID以太坊账户地址形式这一查询的运行时 API。原文档的表述非常精炼Provides an API for looking up an agent ID on Ethereum提供一个在以太坊上查找 agent ID 的 API本文将其展开为可实操、可追溯的完整技术脉络。二、API 的声明ControlApi 及其函数签名API 的声明位于 operator/pallets/system/runtime-api/src/lib.rs通过 Substrate 的sp_api::decl_runtime_apis!宏定义// SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2023 Snowfork hellosnowfork.com #![cfg_attr(not(feature std), no_std)] use snowbridge_core::AgentId; use xcm::VersionedLocation; sp_api::decl_runtime_apis! { pub trait ControlApi { fn agent_id(location: VersionedLocation) - OptionAgentId; } }关键点拆解trait ControlApi运行时 API 的 trait 名称编译期由decl_runtime_apis!宏展开为节点端可调用的 RPC 方法绑定入参VersionedLocationXCM 的版本化 Location 类型用于跨版本兼容地描述一条链上的位置如全局共识、平行链 ID、账户等返回值OptionAgentId查询可能失败Location 无法转换因此返回Option而非直接返回AgentIdAgentId的实际类型在 operator/primitives/snowbridge/core/src/location.rs 中定义为pub type AgentId H256;即一个 32 字节的哈希值作为以太坊上 Agent 合约的唯一标识契约型映射。该 crate 的元信息operator/pallets/system/runtime-api/Cargo.toml显示包名为snowbridge-system-runtime-api版本 0.13.0依赖codecSCALE 编解码、snowbridge-core、sp-api与xcm并默认开启stdfeature。三、agent_id 的底层实现从 Location 到哈希agent_id的实现分两层均可在仓库中找到对应源码。3.1 运行时 API 的辅助函数位于 operator/pallets/system/src/api.rsuse snowbridge_core::AgentId; use xcm::{prelude::*, VersionedLocation}; use crate::{agent_id_of, Config}; pub fn agent_idRuntime(location: VersionedLocation) - OptionAgentId where Runtime: Config, { let location: Location location.try_into().ok()?; agent_id_of::Runtime(location).ok() }这里先将版本化的VersionedLocation解包为Location失败则返回None随后调用 pallet 内部的agent_id_of。3.2 pallet 内部的转换函数位于 operator/pallets/system/src/lib.rspub fn agent_id_ofT: Config(location: Location) - ResultH256, DispatchError { T::AgentIdOf::convert_location(location).ok_or(Error::T::LocationConversionFailed.into()) }它委托给Config中声明的关联类型AgentIdOf见同文件第 121-122 行/// Converts Location to AgentId type AgentIdOf: ConvertLocationAgentId;3.3 AgentIdOf 的默认实现HashedDescription在 operator/primitives/snowbridge/core/src/location.rs 中AgentIdOf被实现为HashedDescription类型/// Creates an AgentId from a Location. An AgentId is a unique mapping to an Agent contract on /// Ethereum which acts as the sovereign account for the Location. /// Resolves Polkadot locations (as seen by Ethereum) to unique AgentId identifiers. pub type AgentIdOf HashedDescription AgentId, ( DescribeHere, DescribeFamilyDescribeAllTerminal, DescribeGlobalPrefix(DescribeTerminus, DescribeFamilyDescribeTokenTerminal), ), ;其原理是将 XCMLocation按一组描述器DescribeHere、DescribeFamilyDescribeAllTerminal、DescribeGlobalPrefix...序列化后做哈希运算得到唯一的H256标识。从源码注释可以看出这个 AgentId 是对以太坊上作为该 Location 主权账户的 Agent 合约的唯一映射且按以太坊视角解析 Polkadot 位置。这正是跨链消息路由、资产管理中链→以太坊账户映射的标准做法。四、运行时接入三套网络的 impl_runtime_apisControlApi只是 trait 声明真正可被节点调用需要在运行时实现。DataHaven 的三套运行时mainnet、stagenet、testnet均已接入operator/runtime/mainnet/src/lib.rsoperator/runtime/stagenet/src/lib.rsoperator/runtime/testnet/src/lib.rs三者实现方式完全一致例如 stagenetimpl snowbridge_system_v2_runtime_api::ControlV2ApiBlock for Runtime { fn agent_id(location: VersionedLocation) - OptionAgentId { snowbridge_pallet_system_v2::api::agent_id::Runtime(location) } }注意运行时实现中使用的是ControlV2ApiSnowbridge v2 命名空间下的封装内部直接转调snowbridge_pallet_system_v2::api::agent_id::Runtime(location)即上文第三节的辅助函数。这种API 声明 crate → pallet 辅助函数 → 运行时 impl的三层结构是 Substrate 运行时 API 的标准组织方式方便节点端通过 RPCstate_call/ 专门的 API 调用在链下查询状态。五、agent_id 的实际使用场景注册 Agent 与消息路由agent_id并非孤立存在它在 pallet 的初始化和消息处理流程中承担关键角色。从 operator/pallets/system/src/lib.rs 可以看到Agent 注册存储第 220 行定义了Agents存储映射StorageMap_, Twox64Concat, AgentId, (), OptionQuery以AgentId为键记录已注册的 Agent注册流程第 459-488 行附近初始化时调用agent_id_of::T(asset_hub_location)计算 Asset Hub 的asset_hub_agent_id并插入Agents随后计算 Bridge Hub 的bridge_hub_agent_id agent_id_of::T(Location::here())并插入相关事件agent_id: asset_hub_agent_id等随之发出单元测试佐证operator/pallets/system/src/tests.rs 中通过make_agent_id(origin_location)生成agent_id并断言其匹配operator/pallets/system/src/mock.rs 中的make_agent_id正是通过Test as snowbridge_system::Config::AgentIdOf::convert_location(location)复算验证了哈希映射的确定性。六、Agent ID 计算的确定性验证仓库中的运行时测试直接印证了 Agent ID 计算的确定性与可复现性。以 operator/runtime/testnet/src/configs/mod.rs 中的test_rewards_agent_id_computation为例stagenet 的 operator/runtime/stagenet/src/configs/mod.rs 亦同let computed_agent_id H256(blake2_256(encoded)); let expected_agent_id H256(hex_literal::hex!(...)); assert_eq!(computed_agent_id, expected_agent_id);测试先按给定编码规则计算blake2_256哈希得到computed_agent_id再与硬编码的expected_agent_id比对。这说明 Agent ID 的生成路径在 XCM Location 编码与哈希算法上均有明确的预期值约束是跨链合约侧Ethereum 上的 Agent 合约地址推导与链侧必须严格对齐的契约点。七、总结与延伸阅读ControlApi::agent_id是 DataHaven / Snowbridge 体系中Location ↔ 以太坊 Agent 账户映射的查询入口其完整链路为VersionedLocation → Locationapi.rs 解包 → agent_id_of::Tpallet 内转换 → T::AgentIdOf::convert_locationHashedDescription 哈希 → AgentId H256以太坊 Agent 合约的唯一标识API 声明查看 operator/pallets/system/runtime-api/src/lib.rs辅助实现查看 operator/pallets/system/src/api.rs 与 operator/pallets/system/src/lib.rs类型定义查看 operator/primitives/snowbridge/core/src/location.rs运行时接入查看 operator/runtime/stagenet/src/lib.rsmainnet、testnet 相同测试验证查看 operator/pallets/system/src/tests.rs、operator/runtime/testnet/src/configs/mod.rs如果你想在 DataHaven 节点上查询某个 Location 对应的 Agent ID可以基于上述ControlApi生成对应的运行时 API 调用例如通过 Substrate 的 state_call 机制或在本地测试网中参照test_rewards_agent_id_computation的方式复算验证。这为理解 DataHaven 的跨链 Agent 账户体系、以及在 Ethereum 侧定位 Agent 合约提供了坚实的技术起点。赞分享区块链存储Web3【免费下载链接】datahavenAn EVM compatible Substrate chain, powered by StorageHub and secured by EigenLayer项目地址https://gitcode.com/gh_mirrors/da/datahaven点击查看免费下载相关推荐Substrate 中的 FRAME NFTs Runtime API 详解NftsApi 的声明、实现与链上查询Substrate 中的 FRAME NFTs Runtime API 详解NftsApi 的声明、实现与链上查询 导读 本文以 Substrate 仓库中区块链开发框架后端ChatOllama Agent Runtime 深度指南基于 Vercel AI SDK 的可移植 Agent 会话运行时ChatOllama Agent Runtime 深度指南基于 Vercel AI SDK 的可移植 Agent 会话运行时 导读 packages/agenGraalVM Native Image 运行时模块系统支持Runtime Module System深度解析GraalVM Native Image 运行时模块系统支持Runtime Module System深度解析 Native Image 在构建可执行镜像时编译器JIT编译语言运行时高性能计算内存管理上一篇Qix技术学习资源宝库开发者必备的终极学习指南 下一篇LeRobot 机器人框架实操SO-100 从录数据到跑通 ACT 策略创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
网站建设高端定制企业官网
RELATED

相关资讯

更多精彩内容,欢迎继续阅读

较早相关资讯

最新相关资讯

【外设】之大彩串口显示屏 2026/11/17 7:04:08

【外设】之大彩串口显示屏

大彩串口屏初步使用 1 .官网下载 STM32 屏幕 GUI 设计资料 http://www.gz-dc.com/category/typeid/4112 找到 STM32 Keil 工程,移植相关代码因项目而异进行移植,由于项目简单,本人只对用到的指令接口进行修改。 比如:注意事项&…

阅读更多 →
无法下载Windows系统iso文件 2026/11/17 5:42:44

无法下载Windows系统iso文件

当我遇到这个问题的时候,我打开了一个网站: 登录 然后我打算下载的时候: 突然那个官方的连接就可以下载了:

阅读更多 →
【清华代码熊】DeepSeek V4.1 Flash 后训练详解 2026/11/17 19:43:34

【清华代码熊】DeepSeek V4.1 Flash 后训练详解

📌 上期解析了 DeepSeek V4.1 Flash 模型架构改进,本期解析 DeepSeek V4.1 Flash 预训练/后训练技术: 🌟 预训练:45T 文本 多模态混合语料、直接训练 sparse attention(取消 DeepSeek V4 的 dense 冷启动&…

阅读更多 →
Shuffle-R1: Efficient RL framework for Multimodal Large Language Models via Data-centric Dynamic ... 2026/11/17 6:55:04

Shuffle-R1: Efficient RL framework for Multimodal Large Language Models via Data-centric Dynamic ...

文章主要内容和创新点 主要内容 本文聚焦于多模态大语言模型(MLLM)强化学习(RL)训练中的效率问题,提出了一个名为Shuffle-R1的框架。研究发现,当前RL训练存在两个关键缺陷: 优势值坍缩(Advantage Collapsing):批次中大多数优势值集中在零附近,导致有效梯度信号被淹…

阅读更多 →
PRvL: Quantifying the Capabilities and Risks of Large Language Models for PII Redaction 2026/11/17 5:57:47

PRvL: Quantifying the Capabilities and Risks of Large Language Models for PII Redaction

一、文章主要内容总结 本文聚焦于利用大型语言模型(LLMs)实现个人身份信息(PII)脱敏的研究,旨在解决传统脱敏方法(如基于规则的系统、领域特定命名实体识别(NER)模型)泛化能力差、跨格式/跨语境适应性弱的问题。 研究通过全面评估多种LLM架构(包括密集型LLM(D-LLM…

阅读更多 →
LLaVA-RE: Binary Image-Text Relevancy Evaluation with Multimodal Large Language Model 2026/11/17 19:43:32

LLaVA-RE: Binary Image-Text Relevancy Evaluation with Multimodal Large Language Model

文章主要内容和创新点 主要内容 本文聚焦于二进制图像-文本相关性评估任务(判断图像与文本“相关”或“不相关”),针对该任务中文本格式多样、相关性定义随场景变化等挑战,提出了基于多模态大语言模型(MLLM)的解决方案LLaVA-RE。 模型设计:LLaVA-RE基于LLaVA 1.5架构,…

阅读更多 →

今日资讯

本周资讯

本月资讯

看完文章仍有疑问?

联系尧图顾问,获取一对一建站咨询

立即免费咨询 📞 400-888-8888
📞 ✉