1
+ import { beforeAll , bench , describe } from "@chainsafe/benchmark" ;
1
2
import { BitArray , toHexString } from "@chainsafe/ssz" ;
2
- import { itBench } from "@dapplion/benchmark" ;
3
3
import { DataAvailabilityStatus , ExecutionStatus , ForkChoice , IForkChoiceStore , ProtoArray } from "@lodestar/fork-choice" ;
4
4
import { HISTORICAL_ROOTS_LIMIT , SLOTS_PER_EPOCH } from "@lodestar/params" ;
5
5
import {
@@ -30,57 +30,30 @@ describe(`getAttestationsForBlock vc=${vc}`, () => {
30
30
let protoArray : ProtoArray ;
31
31
let forkchoice : ForkChoice ;
32
32
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} ) ;
35
36
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
+ } ;
74
49
75
- for ( let slot = computeStartSlotAtEpoch ( finalizedCheckpoint . epoch ) ; slot < originalState . slot ; slot ++ ) {
76
- const epoch = computeEpochAtSlot ( slot ) ;
77
- protoArray . onBlock (
50
+ protoArray = ProtoArray . initialize (
78
51
{
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
+
84
57
justifiedEpoch : justifiedCheckpoint . epoch ,
85
58
justifiedRoot : toHexString ( justifiedCheckpoint . root ) ,
86
59
finalizedEpoch : finalizedCheckpoint . epoch ,
@@ -91,36 +64,64 @@ describe(`getAttestationsForBlock vc=${vc}`, () => {
91
64
unrealizedFinalizedRoot : toHexString ( finalizedCheckpoint . root ) ,
92
65
executionPayloadBlockHash : null ,
93
66
executionStatus : ExecutionStatus . PreMerge ,
67
+
94
68
timeliness : false ,
95
69
dataAvailabilityStatus : DataAvailabilityStatus . PreData ,
96
70
} ,
97
- slot
71
+ originalState . slot
98
72
) ;
99
- }
100
73
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
+ }
105
99
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
+ ) ;
124
125
125
126
// notSeenSlots should be >=1
126
127
for ( const [ notSeenSlots , numMissedVotes , numBadVotes ] of [
@@ -129,7 +130,7 @@ describe(`getAttestationsForBlock vc=${vc}`, () => {
129
130
// notSeenSlots=2 means the previous block slot is missed
130
131
[ 2 , 1 , 10 ] ,
131
132
] ) {
132
- itBench ( {
133
+ bench ( {
133
134
id : `notSeenSlots=${ notSeenSlots } numMissedVotes=${ numMissedVotes } numBadVotes=${ numBadVotes } ` ,
134
135
before : ( ) => {
135
136
const state = originalState . clone ( ) ;
@@ -181,7 +182,7 @@ describe.skip("getAttestationsForBlock aggregationBits intersectValues vs get",
181
182
const aggregationBits = BitArray . fromBoolArray ( Array . from ( { length : committeeLen } , ( ) => true ) ) ;
182
183
const notSeenValidatorIndices = Array . from ( { length : committeeLen } , ( _ , i ) => i ) ;
183
184
184
- itBench ( {
185
+ bench ( {
185
186
id : "aggregationBits.intersectValues()" ,
186
187
fn : ( ) => {
187
188
for ( let i = 0 ; i < runsFactor ; i ++ ) {
@@ -191,7 +192,7 @@ describe.skip("getAttestationsForBlock aggregationBits intersectValues vs get",
191
192
runsFactor,
192
193
} ) ;
193
194
194
- itBench ( {
195
+ bench ( {
195
196
id : "aggregationBits.get()" ,
196
197
fn : ( ) => {
197
198
for ( let i = 0 ; i < runsFactor ; i ++ ) {
@@ -203,7 +204,7 @@ describe.skip("getAttestationsForBlock aggregationBits intersectValues vs get",
203
204
runsFactor,
204
205
} ) ;
205
206
206
- itBench ( {
207
+ bench ( {
207
208
id : "aggregationBits.get() with push()" ,
208
209
fn : ( ) => {
209
210
for ( let i = 0 ; i < runsFactor ; i ++ ) {
0 commit comments