首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >中只含十六进制前缀的encodedPath叶节点

中只含十六进制前缀的encodedPath叶节点
EN

Ethereum用户
提问于 2018-09-03 11:43:58
回答 1查看 205关注 0票数 2

叶节点定义为元组编码路径,值,encodedPath使用十六进制前缀编码.是否有可能我们有一个叶节点的encodedPath只有前缀和不包括部分路径?

利用以下数据..。

代码语言:javascript
复制
<5e 52> : 'val1'
<ac 40> : 'val2'
<ac 4f> : 'val3'

...would,特里埃看起来像这样,还是我错了?

代码语言:javascript
复制
rootHash: [ <>, <>, <>, <>, <>, hashA, <>, <>, <>, <>, hashB, <>, <>, <>, <>, <>, <> ]
hashA:    [ <3e 52>, 'val1' ]
hashB:    [ <00 c4>, hashC ]
hashC:    [ hashD, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, hashE, <> ]
hashD:    [ <20>, 'val2' ]
hashE:    [ <20>, 'val3' ]

请注意,rootHashhashC是分支节点;hashB是扩展节点;hashAhashDhashE是叶节点。我的怀疑与hashDhashE encodedPaths有关。如果我理解的话,将20放在HP中是正确的,编码路径长度为偶数的叶节点(在这种情况下为0)应该得到前缀2和一个额外的0填充小块。

EN

回答 1

Ethereum用户

回答已采纳

发布于 2018-09-03 14:29:40

我以与您相同的格式构造了trie (给出了https://github.com/ethereum/wiki/wiki/Patricia-Tree中的信息),这使我得到了相同的结果。要回答您的问题:是的,如果叶节点在部分路径中不包含任何进一步的啃食,则以前缀20结束(如您所写的,前缀为20( path nibbles计数为2,path =0)。

编码的路径将作为字节数组存储。该算法的工作方式如下:给定编码路径b为字节数组:

代码语言:javascript
复制
# Python style code
flag = b[0] & 0xF0
nodetype = flag & 0x2
parity = flag & 0x1
partial_path = []

# parity odd?
if parity:
    partial_path.append(b[0] & 0x0F)

# append all other bytes from the encoded path (or do nothing if there is no encoded path)
for item in b[1:]:
    partial_path.append(item)

# extension node
if not nodetype:
    # do stuff ...

# and so on
票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/57983

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档