mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-10 14:26:26 +00:00
~50% speedup by fast-pathing Eth2Digest merkle hashing
This commit is contained in:
parent
843c461af6
commit
bde20436e8
@ -258,8 +258,8 @@ func is_valid_genesis_state*(state: BeaconState): bool =
|
||||
return false
|
||||
return true
|
||||
|
||||
# TODO candidate for spec?
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/0.5.1/specs/core/0_beacon-chain.md#on-genesis
|
||||
# TODO this is now a non-spec helper function, and it's not really accurate
|
||||
# so only usable/used in research/ and tests/
|
||||
func get_initial_beacon_block*(state: BeaconState): BeaconBlock =
|
||||
BeaconBlock(
|
||||
slot: GENESIS_SLOT,
|
||||
|
@ -139,7 +139,7 @@ func writeFixedSized(c: var WriteCursor, x: auto) =
|
||||
c.append x
|
||||
else:
|
||||
for elem in x:
|
||||
trs "WRITING FIXED SIZE ARRAY ELEMENENT"
|
||||
trs "WRITING FIXED SIZE ARRAY ELEMENT"
|
||||
c.writeFixedSized toSszType(elem)
|
||||
elif x is tuple|object:
|
||||
enumInstanceSerializedFields(x, fieldName, field):
|
||||
@ -508,7 +508,12 @@ func bitlistHashTreeRoot(merkelizer: SszChunksMerkelizer, x: BitSeq): Eth2Digest
|
||||
mixInLength contentsHash, x.len
|
||||
|
||||
func hashTreeRootImpl[T](x: T): Eth2Digest =
|
||||
when (T is BasicType) or (when T is array: ElemType(T) is BasicType else: false):
|
||||
when (when T is array: ElemType(T) is byte and
|
||||
sizeof(T) == sizeof(Eth2Digest) else: false):
|
||||
# TODO is this sizeof comparison guranteed? it's whole structure vs field
|
||||
trs "ETH2DIGEST; IDENTITY MAPPING"
|
||||
Eth2Digest(data: x)
|
||||
elif (T is BasicType) or (when T is array: ElemType(T) is BasicType else: false):
|
||||
trs "FIXED TYPE; USE CHUNK STREAM"
|
||||
merkelizeSerializedChunks x
|
||||
elif T is string or (when T is (seq|openarray): ElemType(T) is BasicType else: false):
|
||||
|
Loading…
x
Reference in New Issue
Block a user