叶节点定义为元组编码路径,值,encodedPath使用十六进制前缀编码.是否有可能我们有一个叶节点的encodedPath只有前缀和不包括部分路径?
利用以下数据..。
<5e 52> : 'val1'
<ac 40> : 'val2'
<ac 4f> : 'val3'...would,特里埃看起来像这样,还是我错了?
rootHash: [ <>, <>, <>, <>, <>, hashA, <>, <>, <>, <>, hashB, <>, <>, <>, <>, <>, <> ]
hashA: [ <3e 52>, 'val1' ]
hashB: [ <00 c4>, hashC ]
hashC: [ hashD, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, <>, hashE, <> ]
hashD: [ <20>, 'val2' ]
hashE: [ <20>, 'val3' ]请注意,rootHash和hashC是分支节点;hashB是扩展节点;hashA、hashD和hashE是叶节点。我的怀疑与hashD和hashE encodedPaths有关。如果我理解的话,将20放在HP中是正确的,编码路径长度为偶数的叶节点(在这种情况下为0)应该得到前缀2和一个额外的0填充小块。
发布于 2018-09-03 14:29:40
我以与您相同的格式构造了trie (给出了https://github.com/ethereum/wiki/wiki/Patricia-Tree中的信息),这使我得到了相同的结果。要回答您的问题:是的,如果叶节点在部分路径中不包含任何进一步的啃食,则以前缀20结束(如您所写的,前缀为20( path nibbles计数为2,path =0)。
编码的路径将作为字节数组存储。该算法的工作方式如下:给定编码路径b为字节数组:
# 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 onhttps://ethereum.stackexchange.com/questions/57983
复制相似问题