Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progressively compute target stake #4294

Merged
merged 5 commits into from Jul 14, 2022
Merged

Progressively compute target stake #4294

merged 5 commits into from Jul 14, 2022

Conversation

tuyennhv
Copy link
Contributor

Motivation

Research into computing target stake progressively to compute participation through an epoch instead of at the end of epoch.

Description

  • Add currentTargetUnslashedBalanceIncrements, previoustTargetUnslashedBalanceIncrements and compute it per block processing
  • Add assertion in beforeEpochProcess, by default do the assertion in spec tests
  • Also add cli flag to do the assertion, which allow us to sync from genesis and test

@tuyennhv tuyennhv mentioned this pull request Jul 14, 2022
4 tasks
@github-actions
Copy link
Contributor

github-actions bot commented Jul 14, 2022

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: f3df2a4 Previous: 7478093 Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 2.2781 ms/op 2.6862 ms/op 0.85
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 79.828 us/op 90.940 us/op 0.88
BLS verify - blst-native 2.6285 ms/op 2.1992 ms/op 1.20
BLS verifyMultipleSignatures 3 - blst-native 5.0633 ms/op 4.5196 ms/op 1.12
BLS verifyMultipleSignatures 8 - blst-native 11.329 ms/op 10.352 ms/op 1.09
BLS verifyMultipleSignatures 32 - blst-native 41.220 ms/op 35.863 ms/op 1.15
BLS aggregatePubkeys 32 - blst-native 56.478 us/op 45.232 us/op 1.25
BLS aggregatePubkeys 128 - blst-native 210.39 us/op 173.40 us/op 1.21
getAttestationsForBlock 53.356 ms/op 54.638 ms/op 0.98
isKnown best case - 1 super set check 481.00 ns/op 494.00 ns/op 0.97
isKnown normal case - 2 super set checks 485.00 ns/op 463.00 ns/op 1.05
isKnown worse case - 16 super set checks 483.00 ns/op 490.00 ns/op 0.99
CheckpointStateCache - add get delete 13.432 us/op 12.246 us/op 1.10
validate gossip signedAggregateAndProof - struct 6.2344 ms/op 4.6693 ms/op 1.34
validate gossip attestation - struct 2.9438 ms/op 2.2562 ms/op 1.30
altair verifyImport mainnet_s3766816:31 14.741 s/op 7.3320 s/op 2.01
pickEth1Vote - no votes 2.2619 ms/op 2.5005 ms/op 0.90
pickEth1Vote - max votes 25.866 ms/op 31.115 ms/op 0.83
pickEth1Vote - Eth1Data hashTreeRoot value x2048 13.710 ms/op 15.026 ms/op 0.91
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 23.812 ms/op 24.468 ms/op 0.97
pickEth1Vote - Eth1Data fastSerialize value x2048 1.7402 ms/op 1.6895 ms/op 1.03
pickEth1Vote - Eth1Data fastSerialize tree x2048 18.865 ms/op 20.194 ms/op 0.93
bytes32 toHexString 1.1790 us/op 1.3390 us/op 0.88
bytes32 Buffer.toString(hex) 724.00 ns/op 823.00 ns/op 0.88
bytes32 Buffer.toString(hex) from Uint8Array 984.00 ns/op 1.0360 us/op 0.95
bytes32 Buffer.toString(hex) + 0x 778.00 ns/op 715.00 ns/op 1.09
Object access 1 prop 0.40900 ns/op 0.36200 ns/op 1.13
Map access 1 prop 0.31600 ns/op 0.32000 ns/op 0.99
Object get x1000 14.834 ns/op 19.549 ns/op 0.76
Map get x1000 1.1420 ns/op 1.0110 ns/op 1.13
Object set x1000 109.03 ns/op 123.92 ns/op 0.88
Map set x1000 78.682 ns/op 68.263 ns/op 1.15
Return object 10000 times 0.39690 ns/op 0.39420 ns/op 1.01
Throw Error 10000 times 6.5715 us/op 6.3649 us/op 1.03
enrSubnets - fastDeserialize 64 bits 3.0990 us/op 2.7730 us/op 1.12
enrSubnets - ssz BitVector 64 bits 1.1380 us/op 737.00 ns/op 1.54
enrSubnets - fastDeserialize 4 bits 615.00 ns/op 428.00 ns/op 1.44
enrSubnets - ssz BitVector 4 bits 1.0690 us/op 740.00 ns/op 1.44
prioritizePeers score -10:0 att 32-0.1 sync 2-0 102.36 us/op 96.472 us/op 1.06
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 140.86 us/op 148.78 us/op 0.95
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 251.65 us/op 246.26 us/op 1.02
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 544.36 us/op 411.74 us/op 1.32
prioritizePeers score 0:0 att 64-1 sync 4-1 587.70 us/op 499.38 us/op 1.18
RateTracker 1000000 limit, 1 obj count per request 201.38 ns/op 217.25 ns/op 0.93
RateTracker 1000000 limit, 2 obj count per request 151.72 ns/op 172.79 ns/op 0.88
RateTracker 1000000 limit, 4 obj count per request 119.44 ns/op 151.05 ns/op 0.79
RateTracker 1000000 limit, 8 obj count per request 113.09 ns/op 137.09 ns/op 0.82
RateTracker with prune 4.9490 us/op 4.9390 us/op 1.00
array of 16000 items push then shift 4.6075 us/op 3.4446 us/op 1.34
LinkedList of 16000 items push then shift 24.844 ns/op 26.447 ns/op 0.94
array of 16000 items push then pop 233.72 ns/op 271.49 ns/op 0.86
LinkedList of 16000 items push then pop 21.551 ns/op 22.488 ns/op 0.96
array of 24000 items push then shift 7.3977 us/op 5.0316 us/op 1.47
LinkedList of 24000 items push then shift 25.364 ns/op 27.577 ns/op 0.92
array of 24000 items push then pop 186.51 ns/op 217.16 ns/op 0.86
LinkedList of 24000 items push then pop 21.259 ns/op 23.145 ns/op 0.92
intersect bitArray bitLen 8 11.477 ns/op 12.879 ns/op 0.89
intersect array and set length 8 178.91 ns/op 170.74 ns/op 1.05
intersect bitArray bitLen 128 66.101 ns/op 69.535 ns/op 0.95
intersect array and set length 128 2.3962 us/op 2.4601 us/op 0.97
pass gossip attestations to forkchoice per slot 3.1768 ms/op 7.0036 ms/op 0.45
computeDeltas 3.2375 ms/op 3.9859 ms/op 0.81
computeProposerBoostScoreFromBalances 822.80 us/op 1.0272 ms/op 0.80
altair processAttestation - 250000 vs - 7PWei normalcase 5.0529 ms/op 4.4347 ms/op 1.14
altair processAttestation - 250000 vs - 7PWei worstcase 7.2443 ms/op 6.3853 ms/op 1.13
altair processAttestation - setStatus - 1/6 committees join 245.09 us/op 220.93 us/op 1.11
altair processAttestation - setStatus - 1/3 committees join 421.13 us/op 441.75 us/op 0.95
altair processAttestation - setStatus - 1/2 committees join 635.43 us/op 647.11 us/op 0.98
altair processAttestation - setStatus - 2/3 committees join 817.34 us/op 804.94 us/op 1.02
altair processAttestation - setStatus - 4/5 committees join 1.1739 ms/op 1.0894 ms/op 1.08
altair processAttestation - setStatus - 100% committees join 1.4581 ms/op 1.3109 ms/op 1.11
altair processBlock - 250000 vs - 7PWei normalcase 27.721 ms/op 30.358 ms/op 0.91
altair processBlock - 250000 vs - 7PWei normalcase hashState 38.895 ms/op 40.843 ms/op 0.95
altair processBlock - 250000 vs - 7PWei worstcase 100.88 ms/op 92.763 ms/op 1.09
altair processBlock - 250000 vs - 7PWei worstcase hashState 109.79 ms/op 105.05 ms/op 1.05
phase0 processBlock - 250000 vs - 7PWei normalcase 4.6757 ms/op 3.8630 ms/op 1.21
phase0 processBlock - 250000 vs - 7PWei worstcase 60.186 ms/op 50.226 ms/op 1.20
altair processEth1Data - 250000 vs - 7PWei normalcase 999.33 us/op 1.0532 ms/op 0.95
Tree 40 250000 create 990.06 ms/op 882.23 ms/op 1.12
Tree 40 250000 get(125000) 309.21 ns/op 344.27 ns/op 0.90
Tree 40 250000 set(125000) 3.6894 us/op 3.0415 us/op 1.21
Tree 40 250000 toArray() 33.562 ms/op 37.520 ms/op 0.89
Tree 40 250000 iterate all - toArray() + loop 36.774 ms/op 37.732 ms/op 0.97
Tree 40 250000 iterate all - get(i) 123.10 ms/op 132.82 ms/op 0.93
MutableVector 250000 create 14.515 ms/op 18.869 ms/op 0.77
MutableVector 250000 get(125000) 13.148 ns/op 15.451 ns/op 0.85
MutableVector 250000 set(125000) 689.61 ns/op 663.20 ns/op 1.04
MutableVector 250000 toArray() 6.5358 ms/op 7.5228 ms/op 0.87
MutableVector 250000 iterate all - toArray() + loop 6.2910 ms/op 7.8403 ms/op 0.80
MutableVector 250000 iterate all - get(i) 3.4211 ms/op 3.7611 ms/op 0.91
Array 250000 create 5.7923 ms/op 7.0702 ms/op 0.82
Array 250000 clone - spread 3.0944 ms/op 4.5403 ms/op 0.68
Array 250000 get(125000) 1.3110 ns/op 1.9940 ns/op 0.66
Array 250000 set(125000) 1.4260 ns/op 1.9620 ns/op 0.73
Array 250000 iterate all - loop 144.86 us/op 198.30 us/op 0.73
effectiveBalanceIncrements clone Uint8Array 300000 275.27 us/op 89.045 us/op 3.09
effectiveBalanceIncrements clone MutableVector 300000 711.00 ns/op 756.00 ns/op 0.94
effectiveBalanceIncrements rw all Uint8Array 300000 298.11 us/op 277.49 us/op 1.07
effectiveBalanceIncrements rw all MutableVector 300000 204.13 ms/op 168.69 ms/op 1.21
phase0 afterProcessEpoch - 250000 vs - 7PWei 196.79 ms/op 190.15 ms/op 1.03
phase0 beforeProcessEpoch - 250000 vs - 7PWei 64.663 ms/op 73.638 ms/op 0.88
altair processEpoch - mainnet_e81889 632.92 ms/op 652.98 ms/op 0.97
mainnet_e81889 - altair beforeProcessEpoch 98.768 ms/op 184.87 ms/op 0.53
mainnet_e81889 - altair processJustificationAndFinalization 61.327 us/op 29.798 us/op 2.06
mainnet_e81889 - altair processInactivityUpdates 10.774 ms/op 12.425 ms/op 0.87
mainnet_e81889 - altair processRewardsAndPenalties 158.57 ms/op 108.21 ms/op 1.47
mainnet_e81889 - altair processRegistryUpdates 15.654 us/op 7.8650 us/op 1.99
mainnet_e81889 - altair processSlashings 3.7390 us/op 2.1020 us/op 1.78
mainnet_e81889 - altair processEth1DataReset 4.2210 us/op 2.3290 us/op 1.81
mainnet_e81889 - altair processEffectiveBalanceUpdates 2.9680 ms/op 2.7101 ms/op 1.10
mainnet_e81889 - altair processSlashingsReset 29.091 us/op 13.826 us/op 2.10
mainnet_e81889 - altair processRandaoMixesReset 28.646 us/op 11.463 us/op 2.50
mainnet_e81889 - altair processHistoricalRootsUpdate 3.8240 us/op 2.4290 us/op 1.57
mainnet_e81889 - altair processParticipationFlagUpdates 17.326 us/op 7.1450 us/op 2.42
mainnet_e81889 - altair processSyncCommitteeUpdates 3.8700 us/op 1.7250 us/op 2.24
mainnet_e81889 - altair afterProcessEpoch 201.14 ms/op 220.84 ms/op 0.91
phase0 processEpoch - mainnet_e58758 618.44 ms/op 598.58 ms/op 1.03
mainnet_e58758 - phase0 beforeProcessEpoch 279.82 ms/op 262.21 ms/op 1.07
mainnet_e58758 - phase0 processJustificationAndFinalization 59.750 us/op 32.127 us/op 1.86
mainnet_e58758 - phase0 processRewardsAndPenalties 78.891 ms/op 152.78 ms/op 0.52
mainnet_e58758 - phase0 processRegistryUpdates 39.753 us/op 23.801 us/op 1.67
mainnet_e58758 - phase0 processSlashings 3.9500 us/op 2.8430 us/op 1.39
mainnet_e58758 - phase0 processEth1DataReset 4.8690 us/op 2.4450 us/op 1.99
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 2.2840 ms/op 2.6006 ms/op 0.88
mainnet_e58758 - phase0 processSlashingsReset 20.271 us/op 12.009 us/op 1.69
mainnet_e58758 - phase0 processRandaoMixesReset 27.409 us/op 16.998 us/op 1.61
mainnet_e58758 - phase0 processHistoricalRootsUpdate 4.7810 us/op 2.9770 us/op 1.61
mainnet_e58758 - phase0 processParticipationRecordUpdates 23.816 us/op 10.288 us/op 2.31
mainnet_e58758 - phase0 afterProcessEpoch 172.26 ms/op 174.58 ms/op 0.99
phase0 processEffectiveBalanceUpdates - 250000 normalcase 2.4514 ms/op 3.2537 ms/op 0.75
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 2.5295 ms/op 2.5699 ms/op 0.98
altair processInactivityUpdates - 250000 normalcase 52.870 ms/op 41.727 ms/op 1.27
altair processInactivityUpdates - 250000 worstcase 43.715 ms/op 54.246 ms/op 0.81
phase0 processRegistryUpdates - 250000 normalcase 31.241 us/op 16.894 us/op 1.85
phase0 processRegistryUpdates - 250000 badcase_full_deposits 486.77 us/op 502.21 us/op 0.97
phase0 processRegistryUpdates - 250000 worstcase 0.5 241.02 ms/op 239.85 ms/op 1.00
altair processRewardsAndPenalties - 250000 normalcase 141.00 ms/op 154.72 ms/op 0.91
altair processRewardsAndPenalties - 250000 worstcase 101.13 ms/op 101.19 ms/op 1.00
phase0 getAttestationDeltas - 250000 normalcase 13.299 ms/op 14.529 ms/op 0.92
phase0 getAttestationDeltas - 250000 worstcase 14.349 ms/op 15.659 ms/op 0.92
phase0 processSlashings - 250000 worstcase 6.2555 ms/op 6.0293 ms/op 1.04
altair processSyncCommitteeUpdates - 250000 315.62 ms/op 310.30 ms/op 1.02
BeaconState.hashTreeRoot - No change 564.00 ns/op 534.00 ns/op 1.06
BeaconState.hashTreeRoot - 1 full validator 75.337 us/op 61.536 us/op 1.22
BeaconState.hashTreeRoot - 32 full validator 702.02 us/op 647.60 us/op 1.08
BeaconState.hashTreeRoot - 512 full validator 7.2041 ms/op 6.5905 ms/op 1.09
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 88.353 us/op 77.409 us/op 1.14
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 1.2164 ms/op 1.0830 ms/op 1.12
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 16.350 ms/op 14.285 ms/op 1.14
BeaconState.hashTreeRoot - 1 balances 71.784 us/op 60.958 us/op 1.18
BeaconState.hashTreeRoot - 32 balances 641.21 us/op 566.91 us/op 1.13
BeaconState.hashTreeRoot - 512 balances 5.9001 ms/op 5.1549 ms/op 1.14
BeaconState.hashTreeRoot - 250000 balances 105.56 ms/op 104.22 ms/op 1.01
aggregationBits - 2048 els - zipIndexesInBitList 31.818 us/op 28.894 us/op 1.10
regular array get 100000 times 55.328 us/op 74.653 us/op 0.74
wrappedArray get 100000 times 56.284 us/op 78.414 us/op 0.72
arrayWithProxy get 100000 times 35.359 ms/op 32.894 ms/op 1.07
ssz.Root.equals 594.00 ns/op 487.00 ns/op 1.22
byteArrayEquals 564.00 ns/op 493.00 ns/op 1.14
shuffle list - 16384 els 11.873 ms/op 12.700 ms/op 0.93
shuffle list - 250000 els 173.98 ms/op 184.69 ms/op 0.94
processSlot - 1 slots 16.530 us/op 11.663 us/op 1.42
processSlot - 32 slots 2.1382 ms/op 1.7728 ms/op 1.21
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 415.58 us/op 407.34 us/op 1.02
getCommitteeAssignments - req 1 vs - 250000 vc 5.3033 ms/op 5.4755 ms/op 0.97
getCommitteeAssignments - req 100 vs - 250000 vc 7.3257 ms/op 7.2944 ms/op 1.00
getCommitteeAssignments - req 1000 vs - 250000 vc 7.8133 ms/op 7.8240 ms/op 1.00
computeProposers - vc 250000 20.515 ms/op 20.457 ms/op 1.00
computeEpochShuffling - vc 250000 169.11 ms/op 182.19 ms/op 0.93
getNextSyncCommittee - vc 250000 298.05 ms/op 297.07 ms/op 1.00

by benchmarkbot/action

@tuyennhv tuyennhv marked this pull request as ready for review July 14, 2022 09:55
@tuyennhv tuyennhv requested a review from a team as a code owner July 14, 2022 09:55
@dapplion dapplion enabled auto-merge (squash) July 14, 2022 11:44
@dapplion
Copy link
Contributor

dapplion commented Jul 14, 2022

For some reason build:docs script breaks in this PR https://github.com/ChainSafe/lodestar/runs/7339174005?check_suite_focus=true

@chainsafe/lodestar: Error [ERR_LOADER_CHAIN_INCOMPLETE]: "file:///home/runner/work/lodestar/lodestar/node_modules/ts-node/child-loader.mjs 'resolve'" did not call the next hook in its chain and did not explicitly signal a short circuit. If this is intentional, include `shortCircuit: true` in the hook's return.
@chainsafe/lodestar:     at new NodeError (node:internal/errors:387:5)
@chainsafe/lodestar:     at ESMLoader.resolve (node:internal/modules/esm/loader:860:13)
@chainsafe/lodestar:     at async ESMLoader.getModuleJob (node:internal/modules/esm/loader:439:7)
@chainsafe/lodestar:     at async Promise.all (index 0)
@chainsafe/lodestar:     at async ESMLoader.import (node:internal/modules/esm/loader:541:24)
@chainsafe/lodestar:     at async loadESM (node:internal/process/esm_loader:83:5)
@chainsafe/lodestar:     at async handleMainPromise (node:internal/modules/run_main:65:12) {
@chainsafe/lodestar:   code: 'ERR_LOADER_CHAIN_INCOMPLETE'
@chainsafe/lodestar: }

Running locally:

  • Node 16: it works
  • Node 18: TBD

Fix:

@@ -369,6 +376,23 @@ export function beforeProcessEpoch(state: CachedBeaconStateAllForks): EpochProce
currTargetUnslStake += effectiveBalanceByIncrement;
}
}

if (opts?.assertCorrectProgressiveBalances) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this configurable? because it was only used during debugging? and in normal practice it just adds overhead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it could/should just be 'always on'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wemeetagain yeah I think we can turn it on when:

  • code is unchanged for a while
  • sync through prater
  • sync through mainnet
  • other testnets?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants