rm more state_sim remnants (#5334)

This commit is contained in:
tersec 2023-08-23 16:40:48 +00:00 committed by GitHub
parent a5151bc546
commit 93d82e2892
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 28 deletions

View File

@ -280,7 +280,7 @@ func makeAttestationData*(
) )
) )
func makeAttestationSig*( func makeAttestationSig(
fork: Fork, genesis_validators_root: Eth2Digest, data: AttestationData, fork: Fork, genesis_validators_root: Eth2Digest, data: AttestationData,
committee: openArray[ValidatorIndex], committee: openArray[ValidatorIndex],
bits: CommitteeValidatorsBits): ValidatorSig = bits: CommitteeValidatorsBits): ValidatorSig =
@ -317,15 +317,11 @@ func makeAttestationData*(
makeAttestationData( makeAttestationData(
forkyState.data, slot, committee_index, beacon_block_root) forkyState.data, slot, committee_index, beacon_block_root)
func makeAttestation*( func makeAttestation(
state: ForkedHashedBeaconState, beacon_block_root: Eth2Digest, state: ForkedHashedBeaconState, beacon_block_root: Eth2Digest,
committee: seq[ValidatorIndex], slot: Slot, committee_index: CommitteeIndex, committee: seq[ValidatorIndex], slot: Slot, committee_index: CommitteeIndex,
validator_index: ValidatorIndex, cache: var StateCache, validator_index: ValidatorIndex, cache: var StateCache,
flags: UpdateFlags = {}): Attestation = flags: UpdateFlags = {}): Attestation =
# Avoids state_sim silliness; as it's responsible for all validators,
# transforming, from monotonic enumerable index -> committee index ->
# monotonic enumerable index, is wasteful and slow. Most test callers
# want ValidatorIndex, so that's supported too.
let let
index_in_committee = committee.find(validator_index) index_in_committee = committee.find(validator_index)
data = makeAttestationData(state, slot, committee_index, beacon_block_root) data = makeAttestationData(state, slot, committee_index, beacon_block_root)

View File

@ -6,41 +6,25 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms. # at your option. This file may not be copied, modified, or distributed except according to those terms.
{.push raises: [].} {.push raises: [].}
{.used.}
import import
std/[algorithm, strformat, stats, tables, times],
testutils/markdown_reports, testutils/markdown_reports,
unittest2, unittest2,
../beacon_chain/spec/presets ../beacon_chain/spec/presets
from std/algorithm import SortOrder, sort
from std/strformat import `&`
from std/tables import OrderedTable, `[]=`, initOrderedTable, mgetOrPut, sort
from std/times import Duration, inNanoseconds
export unittest2 export unittest2
type type
TestDuration = tuple[duration: float, label: string] TestDuration = tuple[duration: float, label: string]
func preset*(): string = func preset*(): string {.compileTime.} =
" [Preset: " & const_preset & ']' " [Preset: " & const_preset & ']'
# For state_sim
template withTimer*(duration: var float, body: untyped) =
let start = getMonoTime()
block:
body
duration = (getMonoTime() - start).inMicroseconds.float / 1000000.0
# For state_sim
template withTimerRet*(stats: var RunningStat, body: untyped): untyped =
let start = getMonoTime()
let tmp = block:
body
let stop = getMonoTime()
stats.push (stop - start).inMicroseconds.float / 1000000.0
tmp
var testTimes: seq[TestDuration] var testTimes: seq[TestDuration]
var status = initOrderedTable[string, OrderedTable[string, Status]]() var status = initOrderedTable[string, OrderedTable[string, Status]]()