refactor addHeadBlock() to research/ and tests/ helper (#5874)

* refactor addHeadBlock() to research/ and tests/ helper

* rm now-dead code
This commit is contained in:
tersec 2024-02-09 23:46:51 +00:00 committed by GitHub
parent 9593ef74b8
commit a4680cb7fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 40 additions and 23 deletions

View File

@ -314,25 +314,6 @@ proc addHeadBlockWithParent*(
sigVerifyDur = sigVerifyTick - stateDataTick,
stateVerifyDur = stateVerifyTick - sigVerifyTick)
proc addHeadBlock*(
dag: ChainDAGRef, verifier: var BatchVerifier,
signedBlock: ForkySignedBeaconBlock,
executionValid: bool,
onBlockAdded: OnForkyBlockAdded
): Result[BlockRef, VerifierError] =
addHeadBlockWithParent(
dag, verifier, signedBlock, ? dag.checkHeadBlock(signedBlock),
executionValid, onBlockAdded)
proc addHeadBlock*(
dag: ChainDAGRef, verifier: var BatchVerifier,
signedBlock: ForkySignedBeaconBlock,
onBlockAdded: OnForkyBlockAdded
): Result[BlockRef, VerifierError] =
addHeadBlockWithParent(
dag, verifier, signedBlock, ? dag.checkHeadBlock(signedBlock),
executionValid = true, onBlockAdded)
proc addBackfillBlock*(
dag: ChainDAGRef,
signedBlock: ForkySignedBeaconBlock | ForkySigVerifiedSignedBeaconBlock):

View File

@ -39,6 +39,7 @@ from ../beacon_chain/spec/beaconstate import
get_beacon_committee, get_beacon_proposer_index,
get_committee_count_per_slot, get_committee_indices
from ../beacon_chain/spec/state_transition_block import process_block
from ../tests/testbcutil import addHeadBlock
type Timers = enum
tBlock = "Process non-epoch slot with block"

View File

@ -27,6 +27,7 @@ from std/json import
JsonNode, getBool, getInt, getStr, hasKey, items, len, pairs, `$`, `[]`
from std/sequtils import mapIt, toSeq
from std/strutils import contains
from ../testbcutil import addHeadBlock
# Test format described at https://github.com/ethereum/consensus-specs/tree/v1.3.0/tests/formats/fork_choice
# Note that our implementation has been optimized with "ProtoArray"

View File

@ -8,7 +8,6 @@
{.used.}
import
std/sequtils,
# Status lib
unittest2,
chronicles, chronos,
@ -25,6 +24,9 @@ import
# Test utilities
./testutil, ./testdbutil, ./testblockutil
from std/sequtils import toSeq
from ./testbcutil import addHeadBlock
func combine(tgt: var Attestation, src: Attestation) =
## Combine the signature and participation bitfield, with the assumption that
## the same data is being signed - if the signatures overlap, they are not

View File

@ -8,7 +8,6 @@
{.used.}
import
std/[random, sequtils],
unittest2,
taskpools,
../beacon_chain/el/merkle_minimal,
@ -19,8 +18,11 @@ import
attestation_pool, blockchain_dag, block_quarantine, block_clearance],
./testutil, ./testdbutil, ./testblockutil
from std/random import rand, randomize, sample
from std/sequtils import toSeq
from ../beacon_chain/spec/datatypes/capella import
SignedBLSToExecutionChangeList
from ./testbcutil import addHeadBlock
func `$`(x: BlockRef): string = shortLog(x)

View File

@ -8,8 +8,6 @@
{.used.}
import
# Standard library
std/sequtils,
# Status lib
unittest2,
chronos,
@ -28,6 +26,9 @@ import
# Test utilities
./testutil, ./testdbutil, ./testblockutil
from std/sequtils import count, toSeq
from ./testbcutil import addHeadBlock
proc pruneAtFinalization(dag: ChainDAGRef, attPool: AttestationPool) =
if dag.needStateCachesAndForkChoicePruning():
dag.pruneStateCachesDAG()

View File

@ -17,6 +17,8 @@ import
# Test utilities
./testutil, ./testdbutil
from ./testbcutil import addHeadBlock
suite "Light client" & preset():
const # Test config, should be long enough to cover interesting transitions
headPeriod = 3.SyncCommitteePeriod

View File

@ -18,6 +18,8 @@ import
# Test utilities
./testutil, ./testdbutil
from ./testbcutil import addHeadBlock
suite "Light client processor" & preset():
const # Test config, should be long enough to cover interesting transitions
lowPeriod = 0.SyncCommitteePeriod

25
tests/testbcutil.nim Normal file
View File

@ -0,0 +1,25 @@
# beacon_chain
# Copyright (c) 2024 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.
import results
from ../beacon_chain/consensus_object_pools/block_clearance import
addHeadBlockWithParent
from ../beacon_chain/consensus_object_pools/block_dag import BlockRef
from ../beacon_chain/consensus_object_pools/block_pools_types import
ChainDAGRef, OnForkyBlockAdded, VerifierError
from ../beacon_chain/spec/forks import ForkySignedBeaconBlock
from ../beacon_chain/spec/signatures_batch import BatchVerifier
proc addHeadBlock*(
dag: ChainDAGRef, verifier: var BatchVerifier,
signedBlock: ForkySignedBeaconBlock,
onBlockAdded: OnForkyBlockAdded
): Result[BlockRef, VerifierError] =
addHeadBlockWithParent(
dag, verifier, signedBlock, ? dag.checkHeadBlock(signedBlock),
executionValid = true, onBlockAdded)