Open shuijian-xu opened 4 years ago
import math
total = 16
max_depth = math.ceil(math.log(total, 2))
merkle_tree = []
for depth in range(max_depth + 1):
num_items = math.ceil(total / 2*(max_depth - depth))
level_hashes = [None] num_items
merkle_tree.append(level_hashes)
for level in merkle_tree: print(level)
Because Merkle trees are built from the leaves upward, the only thing a light client needs is the number of leaves that exist to know the structure.