您当前的位置: 首页 >  ui

mutourend

暂无认证

  • 1浏览

    0关注

    661博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

IBC协议之 ics-024-host-requirements

mutourend 发布时间:2022-01-10 15:47:13 ,浏览量:1

1. 引言

ics-024-host-requirements 中,定义了实现IBC的host状态机所需实现的最小接口集合属性。

2. 动机

IBC设计为不同区块链和状态机之间的通用标准,因此必须明确定义host的要求。

IBC应设计为对底层状态机来说是尽可能简单的接口,以使正确实现最大化。

3. 技术说明 3.1 module system

host状态机必须支持module system,通过这种方式,自包含的、可能相互不信任的代码包可安全地运行在同一ledger上,控制它们如何以及何时允许其他模块与其通讯,并由a “master module” 或 execution environment来识别和操作。

IBC/TAO说明书中定义了2种module实现:

  • 核心的"IBC handler" module
  • “IBC relayer” module

IBC/APP说明书中进一步定义了处理应用逻辑的特定packet的module。

IBC要求“master module” 或 execution environment可用于 批准该host状态机上的其它module来访问 IBC handler module 和(或)IBC routing module,但除此之外,不会对可能位于状态机上的任何其他模块的功能或通信能力施加要求。

3.2 paths, identifiers, separators

“Indentifier”:为a bytestring,作为存储在state中object的key,如connection、channel 或 light client。 identifier必须为非空值(长度为正数)。 identifier必须包含以下字符类型中的一种:

  • 字母
  • ., _, +, -, #
  • [, ],

“path”:为a bytestring,作为存储在state中object的key。paths中仅包含identifiers,constant strings以及分隔符“/”。 identifier并不打算成为有价值的资源-为了防止名称占用,可以实现最小长度要求或伪随机生成,但本规范不施加特殊限制。

分隔符“/”用于分隔和连接2个identifiers,或一个identifier + 1个constant bytestring。identifiers中不能包含“/”字符,以避免混淆。

插入的变量以大括号包围,作为定义path格式的简写,如client/{clientIdentifier}/consensusState

本规范中的所有identifier以及所有string,都应以ASCII编码。

默认,identifier中的字符具有最小最大长度限制:

Port identifierClient identifierConnection identifierChannel identifier2 - 1289 - 6410 - 6410 - 64 3.3 key/value store

host 状态机必须提供key/value store接口,至少有以下三个函数:

  • get:
type get = (path: Path) => Value | void
  • set
type set = (path: Path, value: Value) => void
  • delete
type delete = (path: Path) => void

其中的Pathd定义见3.2节。Value为任意bytestring encoding of a particular data structure。

以上三个函数必须仅对IBC handler module许可授权,因此,仅IBC handler module可setdelete 其通过get读到的path。可实现为a sub-store (prefixed key-space) of a larger key/value store used by the entire state machine。

host状态机必须为该接口实现2个实例:

  • 1)provableStore:for storage read by (i.e. proven to) other chains。
    • MUST write to a key/value store whose data can be externally proved with a vector commitment as defined in ICS 23.
    • MUST use canonical data structure encodings provided in these specifications as proto3 files
  • 2)privateStore: for storage local to the host, upon which get, set, and delete can be called, e.g. provableStore.set('some/path', 'value')
    • MAY support external proofs, but is not required to - the IBC handler will never write data to it which needs to be proved.
    • MAY use canonical proto3 data structures, but is not required to - it can use whatever format is preferred by the application environment.

注意:任意实现了以上方法和属性的key/value store接口对于IBC就足够了。

3.4 path-space

当前,IBC/TAO中为provableStoreprivateStore推荐了如下path前缀:【注意下一client-related paths反应了ICS7中定义的Tendermint client,若为其它client,相关定义可能不同。】

StorePath formatValue typeDefined inprovableStore“clients/{identifier}/clientType”ClientTypeICS 2privateStore“clients/{identifier}/clientState”ClientStateICS 2provableStore“clients/{identifier}/consensusStates/{height}”ConsensusStateICS 7privateStore"clients/{identifier}/connections[]IdentifierICS 3provableStore“connections/{identifier}”ConnectionEndICS 3privateStore“ports/{identifier}”CapabilityKeyICS 5provableStore“channelEnds/ports/{identifier}/channels/{identifier}”ChannelEndICS 4provableStore“nextSequenceSend/ports/{identifier}/channels/{identifier}”uint64ICS 4provableStore“nextSequenceRecv/ports/{identifier}/channels/{identifier}”uint64ICS 4provableStore“nextSequenceAck/ports/{identifier}/channels/{identifier}”uint64ICS 4provableStore“commitments/ports/{identifier}/channels/{identifier}/sequences/{sequence}”bytesICS 4provableStore“receipts/ports/{identifier}/channels/{identifier}/sequences/{sequence}”bytesICS 4provableStore“acks/ports/{identifier}/channels/{identifier}/sequences/{sequence}”bytesICS 4 3.5 module布局

host状态机上modules布局为:(Aardvark、Betazoid 和 Cephalopod 为任意modules)

+----------------------------------------------------------------------------------+
|                                                                                  |
| Host State Machine                                                               |
|                                                                                  |
| +-------------------+       +--------------------+      +----------------------+ |
| | Module Aardvark   |   | IBC Routing Module |      | IBC Handler Module   | |
| +-------------------+       |                    |      |                      | |
|                             | Implements ICS 26. |      | Implements ICS 2, 3, | |
|                             |                    |      | 4, 5 internally.     | |
| +-------------------+       |                    |      |                      | |
| | Module Betazoid   |   |                    | -->  | Exposes interface    | |
| +-------------------+       |                    |      | defined in ICS 25.   | |
|                             |                    |      |                      | |
| +-------------------+       |                    |      |                      | |
| | Module Cephalopod |   |                    |      |                      | |
| +-------------------+       +--------------------+      +----------------------+ |
|                                                                                  |
+----------------------------------------------------------------------------------+
3.6 consensus state introspection

host 状态机:

  • 必须提供getCurrentHeight函数获取其当前height。
  • 必须定义唯一的ConsensusState类型,实现ICS2要求,并可进行binary序列化。
  • 必须提供getConsensusState函数获取其当前共识状态。getConsensusState MUST return the consensus state for at least some number n of contiguous recent heights, where n is constant for the host state machine. Heights older than n MAY be safely pruned (causing future calls to fail for those heights).
  • 必须提供getStoredRecentConsensusStateCount返回最近存储的n个共识状态。
3.7 commitment path introspection

host 链:

  • 必须提供getCommitmentPrefix函数返回commitment path。返回的CommitmentPrefix(必须为常量)会作为host状态机key-value store的前缀。
type getCommitmentPrefix = () => CommitmentPrefix

CommitmentRoot rootCommitmentState state一起,满足如下属性:

if provableStore.get(path) === value {
  prefixedPath = applyPrefix(getCommitmentPrefix(), path)
  if value !== nil {
    proof = createMembershipProof(state, prefixedPath, value)
    assert(verifyMembership(root, proof, prefixedPath, value))
  } else {
    proof = createNonMembershipProof(state, prefixedPath)
    assert(verifyNonMembership(root, proof, prefixedPath))
  }
}
3.8 timestamp access

host 链 :

  • 必须提供currentTimestamp()函数返回当前Unix timestamp。

为了在timeout中安全使用timestamp,后续headers的timestamp必须为非递减的。

参考资料

[1] ics-024-host-requirements

关注
打赏
1664532908
查看更多评论
立即登录/注册

微信扫码登录

0.1200s