more `zeroMem` avoidance, value semantics for merkleizer
This commit is contained in:
Jacek Sieka 2023-09-28 13:59:33 +02:00 committed by GitHub
parent e9c8f82282
commit 252473d2d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 7 deletions

View File

@ -670,7 +670,7 @@ proc popFirst(chain: var Eth1Chain) =
chain.blocksByHash.del removed.hash.asBlockHash
eth1_chain_len.set chain.blocks.len.int64
func getDepositsRoot*(m: DepositsMerkleizer): Eth2Digest =
func getDepositsRoot*(m: var DepositsMerkleizer): Eth2Digest =
mixInLength(m.getFinalHash, int m.totalChunks)
proc addBlock*(chain: var Eth1Chain, newBlock: Eth1Block) =
@ -1783,7 +1783,7 @@ proc getBlockProposalData*(chain: var Eth1Chain,
deposits.add data
depositRoots.add hash_tree_root(data)
var scratchMerkleizer = copy chain.finalizedDepositsMerkleizer
var scratchMerkleizer = chain.finalizedDepositsMerkleizer
if chain.advanceMerkleizer(scratchMerkleizer, stateDepositIdx):
let proofs = scratchMerkleizer.addChunksAndGenMerkleProofs(depositRoots)
for i in 0 ..< totalDepositsInNewBlock:
@ -1844,7 +1844,7 @@ proc init*(T: type Eth1Chain,
cfg: cfg,
finalizedBlockHash: finalizedBlockHash,
finalizedDepositsMerkleizer: m,
headMerkleizer: copy m)
headMerkleizer: m)
proc new*(T: type ELManager,
cfg: RuntimeConfig,
@ -1877,7 +1877,7 @@ proc safeCancel(fut: var Future[void]) =
func clear(chain: var Eth1Chain) =
chain.blocks.clear()
chain.blocksByHash.clear()
chain.headMerkleizer = copy chain.finalizedDepositsMerkleizer
chain.headMerkleizer = chain.finalizedDepositsMerkleizer
chain.hasConsensusViolation = false
proc doStop(m: ELManager) {.async.} =

View File

@ -1,3 +1,12 @@
# beacon_chain
# Copyright (c) 2018-2023 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
{.push raises: [].}
from stew/objects import isZeroMemory
import ./eth2_merkleization
@ -35,11 +44,11 @@ template getDepositCountU64*(d: OldDepositContractSnapshot |
func getDepositRoot*(d: OldDepositContractSnapshot |
DepositTreeSnapshot): Eth2Digest =
let merk = DepositsMerkleizer.init(d.depositContractState)
var merk = DepositsMerkleizer.init(d.depositContractState)
let hash = merk.getFinalHash()
# TODO: mixInLength should accept unsigned int instead of int as
# this right now cuts in half the theoretical number of deposits.
return mixInLength(hash, int(merk.totalChunks))
return mixInLength(hash, int(merk.getChunkCount()))
func isValid*(d: DepositTreeSnapshot, wantedDepositRoot: Eth2Digest): bool =
## `isValid` requires the snapshot to be self-consistent and

@ -1 +1 @@
Subproject commit a5767c1b4992dca3e5bd72557aadd4df0f183bf8
Subproject commit edf07d4f7e0cb27afd207aa183c23cf448082d1b