1717import
1818 confutils, chronicles, eth/ db/ kvstore_sqlite3,
1919 chronos, chronos/ timer, taskpools,
20- ../ tests/ testblockutil,
2120 ../ beacon_chain/ spec/ [forks, state_transition],
2221 ../ beacon_chain/ beacon_chain_db,
2322 ../ beacon_chain/ gossip_processing/ [batch_validation, gossip_validation],
2423 ../ beacon_chain/ consensus_object_pools/ [blockchain_dag, block_clearance],
2524 ./ simutils
2625
27- from std/ random import Rand , gauss, initRand, rand
26+ from std/ random import initRand, rand
2827from std/ stats import RunningStat
2928from ../ beacon_chain/ consensus_object_pools/ attestation_pool import
3029 AttestationPool , addAttestation, addForkChoice,
@@ -34,14 +33,12 @@ from ../beacon_chain/consensus_object_pools/block_quarantine import
3433from ../ beacon_chain/ consensus_object_pools/ sync_committee_msg_pool import
3534 SyncCommitteeMsgPool , addContribution, addSyncCommitteeMessage, init,
3635 produceContribution, produceSyncAggregate, pruneData
37- from ../ beacon_chain/ el/ eth1_chain import
38- Eth1Block , Eth1BlockNumber , Eth1BlockTimestamp , Eth1Chain , addBlock,
39- getBlockProposalData, init
4036from ../ beacon_chain/ spec/ beaconstate import
4137 get_beacon_committee, get_beacon_proposer_index,
4238 get_committee_count_per_slot, get_committee_indices
4339from ../ beacon_chain/ spec/ state_transition_block import process_block
4440from ../ tests/ testbcutil import addHeadBlock
41+ from ../ tests/ testblockutil import makeAttestationData, MockPrivKeys , `[]`
4542
4643type Timers = enum
4744 tBlock = " Process non-epoch slot with block"
@@ -57,10 +54,7 @@ proc makeSimulationBlock(
5754 state: var electra.HashedBeaconState ,
5855 proposer_index: ValidatorIndex ,
5956 randao_reveal: ValidatorSig ,
60- eth1_data: Eth1Data ,
61- graffiti: GraffitiBytes ,
6257 attestations: seq [electra.Attestation ],
63- deposits: seq [Deposit ],
6458 exits: BeaconBlockValidatorChanges ,
6559 sync_aggregate: SyncAggregate ,
6660 execution_payload: electra.ExecutionPayloadForSigning ,
@@ -80,9 +74,9 @@ proc makeSimulationBlock(
8074 # some validations.
8175
8276 var blck = partialBeaconBlock (
83- cfg, state, proposer_index, randao_reveal, eth1_data, graffiti ,
84- attestations, deposits , exits, sync_aggregate, execution_payload ,
85- default ( ExecutionRequests ))
77+ cfg, state, proposer_index, randao_reveal, Eth1Data () ,
78+ default ( GraffitiBytes ), attestations, @ [] , exits, sync_aggregate,
79+ execution_payload, ExecutionRequests ( ))
8680
8781 let res = process_block (
8882 cfg, state.data, blck.asSigVerified (), verificationFlags, cache)
@@ -101,10 +95,7 @@ proc makeSimulationBlock(
10195 state: var fulu.HashedBeaconState ,
10296 proposer_index: ValidatorIndex ,
10397 randao_reveal: ValidatorSig ,
104- eth1_data: Eth1Data ,
105- graffiti: GraffitiBytes ,
10698 attestations: seq [electra.Attestation ],
107- deposits: seq [Deposit ],
10899 exits: BeaconBlockValidatorChanges ,
109100 sync_aggregate: SyncAggregate ,
110101 execution_payload: fulu.ExecutionPayloadForSigning ,
@@ -124,9 +115,9 @@ proc makeSimulationBlock(
124115 # some validations.
125116
126117 var blck = partialBeaconBlock (
127- cfg, state, proposer_index, randao_reveal, eth1_data, graffiti ,
128- attestations, deposits , exits, sync_aggregate, execution_payload ,
129- default ( ExecutionRequests ))
118+ cfg, state, proposer_index, randao_reveal, Eth1Data () ,
119+ default ( GraffitiBytes ), attestations, @ [] , exits, sync_aggregate,
120+ execution_payload, ExecutionRequests ( ))
130121
131122 let res = process_block (
132123 cfg, state.data, blck.asSigVerified (), verificationFlags, cache)
@@ -147,9 +138,7 @@ cli do(slots = SLOTS_PER_EPOCH * 7,
147138 syncCommitteeRatio {.desc: " ratio of validators that perform sync committee actions in each round" } = 0.82 ,
148139 blockRatio {.desc: " ratio of slots with blocks" } = 1.0 ,
149140 replay = true ):
150- let
151- (genesisState, depositTreeSnapshot) = loadGenesis (validators, false )
152- genesisTime = float getStateField (genesisState[], genesis_time)
141+ let (genesisState, depositTreeSnapshot) = loadGenesis (validators, false )
153142 const cfg = getSimulationConfig ()
154143
155144 echo " Starting simulation..."
@@ -164,8 +153,6 @@ cli do(slots = SLOTS_PER_EPOCH * 7,
164153 var
165154 validatorMonitor = newClone (ValidatorMonitor .init ())
166155 dag = ChainDAGRef .init (cfg, db, validatorMonitor, {})
167- eth1Chain = Eth1Chain .init (cfg, db, 0 , default Eth2Digest )
168- merkleizer = DepositsMerkleizer .init (depositTreeSnapshot.depositContractState)
169156 taskpool =
170157 try :
171158 Taskpool .new ()
@@ -184,10 +171,6 @@ cli do(slots = SLOTS_PER_EPOCH * 7,
184171 r = initRand (1 )
185172 tmpState = assignClone (dag.headState)
186173
187- eth1Chain.addBlock Eth1Block (
188- number: Eth1BlockNumber 1 ,
189- timestamp: Eth1BlockTimestamp genesisTime)
190-
191174 let replayState = assignClone (dag.headState)
192175
193176 proc handleAttestations (slot: Slot ) =
@@ -343,14 +326,9 @@ cli do(slots = SLOTS_PER_EPOCH * 7,
343326 proc getNewBlock [T](
344327 state: var ForkedHashedBeaconState , slot: Slot , cache: var StateCache ): T =
345328 let
346- finalizedEpochRef = dag.getFinalizedEpochRef ()
347329 proposerIdx = get_beacon_proposer_index (
348330 state, cache, getStateField (state, slot)).get ()
349331 privKey = MockPrivKeys [proposerIdx]
350- eth1ProposalData = eth1Chain.getBlockProposalData (
351- state,
352- finalizedEpochRef.eth1_data,
353- finalizedEpochRef.eth1_deposit_index)
354332 sync_aggregate =
355333 syncCommitteePool[].produceSyncAggregate (dag.head.bid, slot)
356334 hashedState =
@@ -368,10 +346,7 @@ cli do(slots = SLOTS_PER_EPOCH * 7,
368346 getStateField (state, fork),
369347 getStateField (state, genesis_validators_root),
370348 slot.epoch, privKey).toValidatorSig (),
371- eth1ProposalData.vote,
372- default (GraffitiBytes ),
373349 attPool.getElectraAttestationsForBlock (state, cache),
374- eth1ProposalData.deposits,
375350 BeaconBlockValidatorChanges (),
376351 sync_aggregate,
377352 (when T is electra.SignedBeaconBlock :
@@ -447,42 +422,12 @@ cli do(slots = SLOTS_PER_EPOCH * 7,
447422 do :
448423 raiseAssert " withUpdatedState failed"
449424
450- var
451- lastEth1BlockAt = genesisTime
452- eth1BlockNum = 1000
453-
454425 for i in 0 ..< slots:
455426 let
456427 slot = Slot (i + 1 )
457428 t =
458429 if slot.is_epoch: tEpoch
459430 else : tBlock
460- now = genesisTime + float (slot * SECONDS_PER_SLOT )
461-
462- while true :
463- let nextBlockTime = lastEth1BlockAt +
464- max (1.0 , gauss (r, float cfg.SECONDS_PER_ETH1_BLOCK , 3.0 ))
465- if nextBlockTime > now:
466- break
467-
468- inc eth1BlockNum
469- var eth1Block = Eth1Block (
470- hash: makeFakeHash (eth1BlockNum),
471- number: Eth1BlockNumber eth1BlockNum,
472- timestamp: Eth1BlockTimestamp nextBlockTime)
473-
474- let newDeposits = int clamp (gauss (r, 5.0 , 8.0 ), 0.0 , 1000.0 )
475- for i in 0 ..< newDeposits:
476- let validatorIdx = merkleizer.getChunkCount.int
477- let d = makeDeposit (validatorIdx, {skipBlsValidation})
478- eth1Block.deposits.add d
479- merkleizer.addChunk hash_tree_root (d).data
480-
481- eth1Block.depositRoot = merkleizer.getDepositsRoot
482- eth1Block.depositCount = merkleizer.getChunkCount
483-
484- eth1Chain.addBlock eth1Block
485- lastEth1BlockAt = nextBlockTime
486431
487432 if blockRatio > 0.0 :
488433 withTimer (timers[t]):
0 commit comments