1+ import { beforeAll , bench , describe } from "@chainsafe/benchmark" ;
12import { BitArray , toHexString } from "@chainsafe/ssz" ;
2- import { itBench } from "@dapplion/benchmark" ;
33import { DataAvailabilityStatus , ExecutionStatus , ForkChoice , IForkChoiceStore , ProtoArray } from "@lodestar/fork-choice" ;
44import { HISTORICAL_ROOTS_LIMIT , SLOTS_PER_EPOCH } from "@lodestar/params" ;
55import {
@@ -30,57 +30,30 @@ describe(`getAttestationsForBlock vc=${vc}`, () => {
3030 let protoArray : ProtoArray ;
3131 let forkchoice : ForkChoice ;
3232
33- before ( function ( ) {
34- this . timeout ( 5 * 60 * 1000 ) ; // Generating the states for the first time is very slow
33+ beforeAll (
34+ ( ) => {
35+ originalState = generatePerfTestCachedStateAltair ( { goBackOneSlot : true , vc} ) ;
3536
36- originalState = generatePerfTestCachedStateAltair ( { goBackOneSlot : true , vc} ) ;
37-
38- const { blockHeader, checkpoint} = computeAnchorCheckpoint ( originalState . config , originalState ) ;
39- // TODO figure out why getBlockRootAtSlot(originalState, justifiedSlot) is not the same to justifiedCheckpoint.root
40- const finalizedEpoch = originalState . finalizedCheckpoint . epoch ;
41- const finalizedCheckpoint = {
42- epoch : finalizedEpoch ,
43- root : getBlockRootAtSlot ( originalState , computeStartSlotAtEpoch ( finalizedEpoch ) ) ,
44- } ;
45- const justifiedEpoch = originalState . currentJustifiedCheckpoint . epoch ;
46- const justifiedCheckpoint = {
47- epoch : justifiedEpoch ,
48- root : getBlockRootAtSlot ( originalState , computeStartSlotAtEpoch ( justifiedEpoch ) ) ,
49- } ;
50-
51- protoArray = ProtoArray . initialize (
52- {
53- slot : blockHeader . slot ,
54- parentRoot : toHexString ( blockHeader . parentRoot ) ,
55- stateRoot : toHexString ( blockHeader . stateRoot ) ,
56- blockRoot : toHexString ( checkpoint . root ) ,
57-
58- justifiedEpoch : justifiedCheckpoint . epoch ,
59- justifiedRoot : toHexString ( justifiedCheckpoint . root ) ,
60- finalizedEpoch : finalizedCheckpoint . epoch ,
61- finalizedRoot : toHexString ( finalizedCheckpoint . root ) ,
62- unrealizedJustifiedEpoch : justifiedCheckpoint . epoch ,
63- unrealizedJustifiedRoot : toHexString ( justifiedCheckpoint . root ) ,
64- unrealizedFinalizedEpoch : finalizedCheckpoint . epoch ,
65- unrealizedFinalizedRoot : toHexString ( finalizedCheckpoint . root ) ,
66- executionPayloadBlockHash : null ,
67- executionStatus : ExecutionStatus . PreMerge ,
68-
69- timeliness : false ,
70- dataAvailabilityStatus : DataAvailabilityStatus . PreData ,
71- } ,
72- originalState . slot
73- ) ;
37+ const { blockHeader, checkpoint} = computeAnchorCheckpoint ( originalState . config , originalState ) ;
38+ // TODO figure out why getBlockRootAtSlot(originalState, justifiedSlot) is not the same to justifiedCheckpoint.root
39+ const finalizedEpoch = originalState . finalizedCheckpoint . epoch ;
40+ const finalizedCheckpoint = {
41+ epoch : finalizedEpoch ,
42+ root : getBlockRootAtSlot ( originalState , computeStartSlotAtEpoch ( finalizedEpoch ) ) ,
43+ } ;
44+ const justifiedEpoch = originalState . currentJustifiedCheckpoint . epoch ;
45+ const justifiedCheckpoint = {
46+ epoch : justifiedEpoch ,
47+ root : getBlockRootAtSlot ( originalState , computeStartSlotAtEpoch ( justifiedEpoch ) ) ,
48+ } ;
7449
75- for ( let slot = computeStartSlotAtEpoch ( finalizedCheckpoint . epoch ) ; slot < originalState . slot ; slot ++ ) {
76- const epoch = computeEpochAtSlot ( slot ) ;
77- protoArray . onBlock (
50+ protoArray = ProtoArray . initialize (
7851 {
79- slot,
80- blockRoot : toHexString ( getBlockRootAtSlot ( originalState , slot ) ) ,
81- parentRoot : toHexString ( getBlockRootAtSlot ( originalState , slot - 1 ) ) ,
82- stateRoot : toHexString ( originalState . stateRoots . get ( slot % HISTORICAL_ROOTS_LIMIT ) ) ,
83- targetRoot : toHexString ( getBlockRootAtSlot ( originalState , computeStartSlotAtEpoch ( epoch ) ) ) ,
52+ slot : blockHeader . slot ,
53+ parentRoot : toHexString ( blockHeader . parentRoot ) ,
54+ stateRoot : toHexString ( blockHeader . stateRoot ) ,
55+ blockRoot : toHexString ( checkpoint . root ) ,
56+
8457 justifiedEpoch : justifiedCheckpoint . epoch ,
8558 justifiedRoot : toHexString ( justifiedCheckpoint . root ) ,
8659 finalizedEpoch : finalizedCheckpoint . epoch ,
@@ -91,36 +64,64 @@ describe(`getAttestationsForBlock vc=${vc}`, () => {
9164 unrealizedFinalizedRoot : toHexString ( finalizedCheckpoint . root ) ,
9265 executionPayloadBlockHash : null ,
9366 executionStatus : ExecutionStatus . PreMerge ,
67+
9468 timeliness : false ,
9569 dataAvailabilityStatus : DataAvailabilityStatus . PreData ,
9670 } ,
97- slot
71+ originalState . slot
9872 ) ;
99- }
10073
101- let totalBalance = 0 ;
102- for ( let i = 0 ; i < originalState . epochCtx . effectiveBalanceIncrements . length ; i ++ ) {
103- totalBalance += originalState . epochCtx . effectiveBalanceIncrements [ i ] ;
104- }
74+ for ( let slot = computeStartSlotAtEpoch ( finalizedCheckpoint . epoch ) ; slot < originalState . slot ; slot ++ ) {
75+ const epoch = computeEpochAtSlot ( slot ) ;
76+ protoArray . onBlock (
77+ {
78+ slot,
79+ blockRoot : toHexString ( getBlockRootAtSlot ( originalState , slot ) ) ,
80+ parentRoot : toHexString ( getBlockRootAtSlot ( originalState , slot - 1 ) ) ,
81+ stateRoot : toHexString ( originalState . stateRoots . get ( slot % HISTORICAL_ROOTS_LIMIT ) ) ,
82+ targetRoot : toHexString ( getBlockRootAtSlot ( originalState , computeStartSlotAtEpoch ( epoch ) ) ) ,
83+ justifiedEpoch : justifiedCheckpoint . epoch ,
84+ justifiedRoot : toHexString ( justifiedCheckpoint . root ) ,
85+ finalizedEpoch : finalizedCheckpoint . epoch ,
86+ finalizedRoot : toHexString ( finalizedCheckpoint . root ) ,
87+ unrealizedJustifiedEpoch : justifiedCheckpoint . epoch ,
88+ unrealizedJustifiedRoot : toHexString ( justifiedCheckpoint . root ) ,
89+ unrealizedFinalizedEpoch : finalizedCheckpoint . epoch ,
90+ unrealizedFinalizedRoot : toHexString ( finalizedCheckpoint . root ) ,
91+ executionPayloadBlockHash : null ,
92+ executionStatus : ExecutionStatus . PreMerge ,
93+ timeliness : false ,
94+ dataAvailabilityStatus : DataAvailabilityStatus . PreData ,
95+ } ,
96+ slot
97+ ) ;
98+ }
10599
106- const fcStore : IForkChoiceStore = {
107- currentSlot : originalState . slot ,
108- justified : {
109- checkpoint : { ...justifiedCheckpoint , rootHex : toHexString ( justifiedCheckpoint . root ) } ,
110- balances : originalState . epochCtx . effectiveBalanceIncrements ,
111- totalBalance,
112- } ,
113- unrealizedJustified : {
114- checkpoint : { ...justifiedCheckpoint , rootHex : toHexString ( justifiedCheckpoint . root ) } ,
115- balances : originalState . epochCtx . effectiveBalanceIncrements ,
116- } ,
117- finalizedCheckpoint : { ...finalizedCheckpoint , rootHex : toHexString ( finalizedCheckpoint . root ) } ,
118- unrealizedFinalizedCheckpoint : { ...finalizedCheckpoint , rootHex : toHexString ( finalizedCheckpoint . root ) } ,
119- justifiedBalancesGetter : ( ) => originalState . epochCtx . effectiveBalanceIncrements ,
120- equivocatingIndices : new Set ( ) ,
121- } ;
122- forkchoice = new ForkChoice ( originalState . config , fcStore , protoArray ) ;
123- } ) ;
100+ let totalBalance = 0 ;
101+ for ( let i = 0 ; i < originalState . epochCtx . effectiveBalanceIncrements . length ; i ++ ) {
102+ totalBalance += originalState . epochCtx . effectiveBalanceIncrements [ i ] ;
103+ }
104+
105+ const fcStore : IForkChoiceStore = {
106+ currentSlot : originalState . slot ,
107+ justified : {
108+ checkpoint : { ...justifiedCheckpoint , rootHex : toHexString ( justifiedCheckpoint . root ) } ,
109+ balances : originalState . epochCtx . effectiveBalanceIncrements ,
110+ totalBalance,
111+ } ,
112+ unrealizedJustified : {
113+ checkpoint : { ...justifiedCheckpoint , rootHex : toHexString ( justifiedCheckpoint . root ) } ,
114+ balances : originalState . epochCtx . effectiveBalanceIncrements ,
115+ } ,
116+ finalizedCheckpoint : { ...finalizedCheckpoint , rootHex : toHexString ( finalizedCheckpoint . root ) } ,
117+ unrealizedFinalizedCheckpoint : { ...finalizedCheckpoint , rootHex : toHexString ( finalizedCheckpoint . root ) } ,
118+ justifiedBalancesGetter : ( ) => originalState . epochCtx . effectiveBalanceIncrements ,
119+ equivocatingIndices : new Set ( ) ,
120+ } ;
121+ forkchoice = new ForkChoice ( originalState . config , fcStore , protoArray ) ;
122+ } ,
123+ 5 * 60 * 1000
124+ ) ;
124125
125126 // notSeenSlots should be >=1
126127 for ( const [ notSeenSlots , numMissedVotes , numBadVotes ] of [
@@ -129,7 +130,7 @@ describe(`getAttestationsForBlock vc=${vc}`, () => {
129130 // notSeenSlots=2 means the previous block slot is missed
130131 [ 2 , 1 , 10 ] ,
131132 ] ) {
132- itBench ( {
133+ bench ( {
133134 id : `notSeenSlots=${ notSeenSlots } numMissedVotes=${ numMissedVotes } numBadVotes=${ numBadVotes } ` ,
134135 before : ( ) => {
135136 const state = originalState . clone ( ) ;
@@ -181,7 +182,7 @@ describe.skip("getAttestationsForBlock aggregationBits intersectValues vs get",
181182 const aggregationBits = BitArray . fromBoolArray ( Array . from ( { length : committeeLen } , ( ) => true ) ) ;
182183 const notSeenValidatorIndices = Array . from ( { length : committeeLen } , ( _ , i ) => i ) ;
183184
184- itBench ( {
185+ bench ( {
185186 id : "aggregationBits.intersectValues()" ,
186187 fn : ( ) => {
187188 for ( let i = 0 ; i < runsFactor ; i ++ ) {
@@ -191,7 +192,7 @@ describe.skip("getAttestationsForBlock aggregationBits intersectValues vs get",
191192 runsFactor,
192193 } ) ;
193194
194- itBench ( {
195+ bench ( {
195196 id : "aggregationBits.get()" ,
196197 fn : ( ) => {
197198 for ( let i = 0 ; i < runsFactor ; i ++ ) {
@@ -203,7 +204,7 @@ describe.skip("getAttestationsForBlock aggregationBits intersectValues vs get",
203204 runsFactor,
204205 } ) ;
205206
206- itBench ( {
207+ bench ( {
207208 id : "aggregationBits.get() with push()" ,
208209 fn : ( ) => {
209210 for ( let i = 0 ; i < runsFactor ; i ++ ) {
0 commit comments