convert hash_tree_roots_prefix(...) to an iterator
This commit is contained in:
parent
c3d2634b97
commit
b82328b148
|
@ -229,11 +229,12 @@ func initialize_beacon_state_from_eth1*(
|
|||
# Process deposits
|
||||
let
|
||||
leaves = deposits.mapIt(it.data)
|
||||
prefix_roots =
|
||||
hash_tree_roots_prefix(leaves, 2'i64^DEPOSIT_CONTRACT_TREE_DEPTH)
|
||||
for i, deposit in deposits:
|
||||
state.eth1_data.deposit_root = prefix_roots[i]
|
||||
discard process_deposit(state, deposit, flags)
|
||||
var i = 0
|
||||
for prefix_root in hash_tree_roots_prefix(
|
||||
leaves, 2'i64^DEPOSIT_CONTRACT_TREE_DEPTH):
|
||||
state.eth1_data.deposit_root = prefix_root
|
||||
discard process_deposit(state, deposits[i], flags)
|
||||
i += 1
|
||||
|
||||
# Process activations
|
||||
for validator_index in 0 ..< state.validators.len:
|
||||
|
|
|
@ -573,8 +573,8 @@ func hash_tree_root*(x: auto): Eth2Digest =
|
|||
|
||||
trs "HASH TREE ROOT FOR ", name(type x), " = ", "0x", $result
|
||||
|
||||
func hash_tree_roots_prefix*[T](lst: openarray[T], limit: auto):
|
||||
seq[Eth2Digest] =
|
||||
iterator hash_tree_roots_prefix*[T](lst: openarray[T], limit: auto):
|
||||
Eth2Digest =
|
||||
# This is a particular type's instantiation of a general fold, reduce,
|
||||
# accumulation, prefix sums, etc family of operations. As long as that
|
||||
# Eth1 deposit case is the only notable example -- the usual uses of a
|
||||
|
@ -583,7 +583,7 @@ func hash_tree_roots_prefix*[T](lst: openarray[T], limit: auto):
|
|||
var merkelizer = SszChunksMerkelizer(limit: uint64(limit))
|
||||
for i, elem in lst:
|
||||
merkelizer.addChunk(hash_tree_root(elem).data)
|
||||
result.add mixInLength(merkelizer.getFinalHash(), i + 1)
|
||||
yield mixInLength(merkelizer.getFinalHash(), i + 1)
|
||||
|
||||
func lastFieldName(RecordType: type): string {.compileTime.} =
|
||||
enumAllSerializedFields(RecordType):
|
||||
|
|
Loading…
Reference in New Issue