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

Bump SSZ to v0.9.0 #3760

Merged
merged 38 commits into from
Apr 4, 2022
Merged

Bump SSZ to v0.9.0 #3760

merged 38 commits into from
Apr 4, 2022

Conversation

dapplion
Copy link
Contributor

@dapplion dapplion commented Feb 15, 2022

Draft note

This PR installs a placeholder version of SSZ with this awesome tool https://gitpkg.vercel.app/. This PR is open now to proof that Lodestar can run with this new SSZ version before releasing it.

"@chainsafe/persistent-merkle-tree": "https://gitpkg.now.sh/dapplion/ssz/packages/persistent-merkle-tree?dapplion/v2",
"@chainsafe/ssz": "https://gitpkg.now.sh/dapplion/ssz/packages/ssz?dapplion/v2",

Motivation

Lodestar has implemented many optimizations around our data-structures. This PR together with ChainSafe/ssz#223 upstreams them to ssz.

See ChainSafe/ssz#223 for full rationale

Description

  • Bump SSZ to upcoming major version
  • Drop flat caches

TODO After merging

Closes #2859
Closes #2419
Closes #2408
Closes #3082
Closes #2966
Closes #3080

This is a combination of 50 commits.

Remove SSZ from params

Update types in lodestar-api

Replace .defaultValue() with .defaultValue

Fix more types

More type fixes

Fix upgradeState functions

Fix processDeposit pending logic

Update test types

f

Update fork-choice types

Update validator types

WIP Lodestar changes

WIP Lodestar

Fix spec tests

FIx more Lodestar types

Fix proofs types

Fix all type issues

Use Uint64NumInf only where applicable

Don't manipulate casing in loadYaml

WIP Fix spec tests

Fix build types

Fix test types

Update test types

Fix getRandaoMix tests

Review pickEth1Vote

syncPubkeys in createFromState

Fix unit tests

Safe clone for CachedBeaconState

Fix unit tests issues

Fix genesis logic with ViewDU

Fix all unit tests

Fix processRewardsAndPenaltiesAllForks

Commit state after processing

Fix statusProcessEpoch

Create valid pubkey cache in perf test

Fix getDeposits for perf test

Ensure CachedBeaconState clone is immutable

Fix genesis spec tests

Ensure stable commit in ViewDU

Add advice on running spec tests

Remove use of the type unsafe Number constructor

Fix casing in spec test definitions

Fix casing and bigint types in spec tests

Advance epochCtx cached time units

Add debug mode to fork-choice tests

Fix spec test bigint type

Fix typo in processAttestation flags

Fix altair transition spec tests

Fix altair transition tests

Commit ViewDU changes in upgradeState

Fix rebase issues
@codecov
Copy link

codecov bot commented Feb 15, 2022

Codecov Report

Merging #3760 (fc245ba) into master (3e1f9b2) will decrease coverage by 0.00%.
The diff coverage is n/a.

❗ Current head fc245ba differs from pull request most recent head cb36a54. Consider uploading reports for the commit cb36a54 to get more accurate results

@@            Coverage Diff             @@
##           master    #3760      +/-   ##
==========================================
- Coverage   36.25%   36.24%   -0.01%     
==========================================
  Files         328      327       -1     
  Lines        9142     9094      -48     
  Branches     1438     1429       -9     
==========================================
- Hits         3314     3296      -18     
+ Misses       5682     5655      -27     
+ Partials      146      143       -3     

@dapplion dapplion mentioned this pull request Feb 15, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Feb 20, 2022

Performance Report

✔️ no performance regression detected

🚀🚀 Significant benchmark improvement detected

Benchmark suite Current: fc245ba Previous: 3e1f9b2 Ratio
BeaconState.hashTreeRoot - 512 full validator 5.4035 ms/op 22.649 ms/op 0.24
processSlot - 1 slots 8.7250 us/op 47.628 us/op 0.18
altair processAttestation - 250000 vs - 7PWei normalcase 3.9257 ms/op 36.488 ms/op 0.11
altair processAttestation - 250000 vs - 7PWei worstcase 5.5376 ms/op 35.355 ms/op 0.16
altair processAttestation - setStatus - 1/6 committees join 175.08 us/op 12.342 ms/op 0.01
altair processAttestation - setStatus - 1/3 committees join 375.08 us/op 21.113 ms/op 0.02
altair processAttestation - setStatus - 1/2 committees join 471.59 us/op 31.401 ms/op 0.02
altair processAttestation - setStatus - 2/3 committees join 600.19 us/op 42.620 ms/op 0.01
altair processAttestation - setStatus - 4/5 committees join 837.16 us/op 51.800 ms/op 0.02
altair processAttestation - setStatus - 100% committees join 992.68 us/op 66.916 ms/op 0.01
altair processParticipationFlagUpdates - 250000 anycase 3.2130 us/op 65.442 ms/op 0.00
phase0 beforeProcessEpoch - 250000 vs - 7PWei 77.751 ms/op 519.71 ms/op 0.15
phase0 processRegistryUpdates - 250000 badcase_full_deposits 370.33 us/op 2.8896 ms/op 0.13
phase0 processRegistryUpdates - 250000 worstcase 0.5 207.27 ms/op 1.5390 s/op 0.13
phase0 processSlashings - 250000 worstcase 5.7197 ms/op 37.313 ms/op 0.15
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 68.373 us/op 630.59 us/op 0.11
pickEth1Vote - no votes 1.9747 ms/op 8.3613 ms/op 0.24
enrSubnets - ssz BitVector 64 bits 556.00 ns/op 14.408 us/op 0.04
enrSubnets - ssz BitVector 4 bits 551.00 ns/op 2.5810 us/op 0.21
Full benchmark results
Benchmark suite Current: fc245ba Previous: 3e1f9b2 Ratio
BeaconState.hashTreeRoot - No change 536.00 ns/op 557.00 ns/op 0.96
BeaconState.hashTreeRoot - 1 full validator 51.272 us/op 128.92 us/op 0.40
BeaconState.hashTreeRoot - 32 full validator 477.00 us/op 1.7686 ms/op 0.27
BeaconState.hashTreeRoot - 512 full validator 5.4035 ms/op 22.649 ms/op 0.24
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 60.637 us/op 117.89 us/op 0.51
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 849.03 us/op 2.3084 ms/op 0.37
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 12.428 ms/op 25.560 ms/op 0.49
BeaconState.hashTreeRoot - 1 balances 46.529 us/op 84.752 us/op 0.55
BeaconState.hashTreeRoot - 32 balances 418.62 us/op 742.71 us/op 0.56
BeaconState.hashTreeRoot - 512 balances 4.1753 ms/op 6.8637 ms/op 0.61
BeaconState.hashTreeRoot - 250000 balances 86.989 ms/op 136.89 ms/op 0.64
processSlot - 1 slots 8.7250 us/op 47.628 us/op 0.18
processSlot - 32 slots 1.4297 ms/op 2.6216 ms/op 0.55
getCommitteeAssignments - req 1 vs - 250000 vc 4.6655 ms/op 5.3019 ms/op 0.88
getCommitteeAssignments - req 100 vs - 250000 vc 6.4662 ms/op 7.4343 ms/op 0.87
getCommitteeAssignments - req 1000 vs - 250000 vc 6.9173 ms/op 7.9531 ms/op 0.87
computeProposers - vc 250000 15.281 ms/op 21.923 ms/op 0.70
computeEpochShuffling - vc 250000 146.03 ms/op 189.10 ms/op 0.77
getNextSyncCommittee - vc 250000 256.03 ms/op 358.22 ms/op 0.71
altair processAttestation - 250000 vs - 7PWei normalcase 3.9257 ms/op 36.488 ms/op 0.11
altair processAttestation - 250000 vs - 7PWei worstcase 5.5376 ms/op 35.355 ms/op 0.16
altair processAttestation - setStatus - 1/6 committees join 175.08 us/op 12.342 ms/op 0.01
altair processAttestation - setStatus - 1/3 committees join 375.08 us/op 21.113 ms/op 0.02
altair processAttestation - setStatus - 1/2 committees join 471.59 us/op 31.401 ms/op 0.02
altair processAttestation - setStatus - 2/3 committees join 600.19 us/op 42.620 ms/op 0.01
altair processAttestation - setStatus - 4/5 committees join 837.16 us/op 51.800 ms/op 0.02
altair processAttestation - setStatus - 100% committees join 992.68 us/op 66.916 ms/op 0.01
altair processBlock - 250000 vs - 7PWei normalcase 25.046 ms/op 30.770 ms/op 0.81
altair processBlock - 250000 vs - 7PWei normalcase hashState 34.154 ms/op
altair processBlock - 250000 vs - 7PWei worstcase 69.094 ms/op 97.096 ms/op 0.71
altair processBlock - 250000 vs - 7PWei worstcase hashState 90.021 ms/op
altair processEth1Data - 250000 vs - 7PWei normalcase 772.60 us/op
altair processEpoch - mainnet_e81889 442.70 ms/op 850.89 ms/op 0.52
mainnet_e81889 - altair beforeProcessEpoch 142.51 ms/op 277.64 ms/op 0.51
mainnet_e81889 - altair processJustificationAndFinalization 26.580 us/op 82.085 us/op 0.32
mainnet_e81889 - altair processInactivityUpdates 11.461 ms/op 21.506 ms/op 0.53
mainnet_e81889 - altair processRewardsAndPenalties 120.87 ms/op 127.31 ms/op 0.95
mainnet_e81889 - altair processRegistryUpdates 3.9920 us/op 9.1930 us/op 0.43
mainnet_e81889 - altair processSlashings 1.2050 us/op 1.9220 us/op 0.63
mainnet_e81889 - altair processEth1DataReset 1.2540 us/op 1.0560 us/op 1.19
mainnet_e81889 - altair processEffectiveBalanceUpdates 5.9200 ms/op 5.7471 ms/op 1.03
mainnet_e81889 - altair processSlashingsReset 5.7070 us/op 14.495 us/op 0.39
mainnet_e81889 - altair processRandaoMixesReset 6.4440 us/op 20.873 us/op 0.31
mainnet_e81889 - altair processHistoricalRootsUpdate 1.7070 us/op 2.3810 us/op 0.72
mainnet_e81889 - altair processParticipationFlagUpdates 4.4480 us/op 79.526 ms/op 0.00
mainnet_e81889 - altair processSyncCommitteeUpdates 2.6100 us/op 1.6070 us/op 1.62
mainnet_e81889 - altair afterProcessEpoch 166.54 ms/op 206.17 ms/op 0.81
altair processInactivityUpdates - 250000 normalcase 28.503 ms/op 61.331 ms/op 0.46
altair processInactivityUpdates - 250000 worstcase 27.402 ms/op 64.027 ms/op 0.43
altair processParticipationFlagUpdates - 250000 anycase 3.2130 us/op 65.442 ms/op 0.00
altair processRewardsAndPenalties - 250000 normalcase 106.64 ms/op 84.109 ms/op 1.27
altair processRewardsAndPenalties - 250000 worstcase 75.312 ms/op 95.394 ms/op 0.79
altair processSyncCommitteeUpdates - 250000 265.68 ms/op 356.98 ms/op 0.74
Tree 40 250000 create 650.23 ms/op 602.82 ms/op 1.08
Tree 40 250000 get(125000) 253.93 ns/op 331.13 ns/op 0.77
Tree 40 250000 set(125000) 2.0883 us/op 2.0850 us/op 1.00
Tree 40 250000 toArray() 30.636 ms/op 42.547 ms/op 0.72
Tree 40 250000 iterate all - toArray() + loop 31.000 ms/op 41.621 ms/op 0.74
Tree 40 250000 iterate all - get(i) 99.475 ms/op 123.02 ms/op 0.81
MutableVector 250000 create 14.485 ms/op 19.196 ms/op 0.75
MutableVector 250000 get(125000) 13.077 ns/op 11.032 ns/op 1.19
MutableVector 250000 set(125000) 584.30 ns/op 501.69 ns/op 1.16
MutableVector 250000 toArray() 6.5240 ms/op 7.8262 ms/op 0.83
MutableVector 250000 iterate all - toArray() + loop 6.3120 ms/op 9.1859 ms/op 0.69
MutableVector 250000 iterate all - get(i) 3.0499 ms/op 3.5506 ms/op 0.86
Array 250000 create 5.3458 ms/op 4.9195 ms/op 1.09
Array 250000 clone - spread 2.2373 ms/op 1.9844 ms/op 1.13
Array 250000 get(125000) 0.99600 ns/op 0.93100 ns/op 1.07
Array 250000 set(125000) 0.99000 ns/op 0.92300 ns/op 1.07
Array 250000 iterate all - loop 149.99 us/op 149.66 us/op 1.00
effectiveBalanceIncrements clone Uint8Array 300000 75.978 us/op 63.291 us/op 1.20
effectiveBalanceIncrements clone MutableVector 300000 667.00 ns/op 606.00 ns/op 1.10
effectiveBalanceIncrements rw all Uint8Array 300000 266.42 us/op 266.36 us/op 1.00
effectiveBalanceIncrements rw all MutableVector 300000 171.96 ms/op 173.26 ms/op 0.99
aggregationBits - 2048 els - zipIndexesInBitList 29.390 us/op 32.787 us/op 0.90
regular array get 100000 times 59.541 us/op 59.350 us/op 1.00
wrappedArray get 100000 times 59.477 us/op 59.349 us/op 1.00
arrayWithProxy get 100000 times 25.801 ms/op 28.168 ms/op 0.92
ssz.Root.equals 431.00 ns/op 1.0190 us/op 0.42
byteArrayEquals 422.00 ns/op
phase0 processBlock - 250000 vs - 7PWei normalcase 3.3056 ms/op 7.9363 ms/op 0.42
phase0 processBlock - 250000 vs - 7PWei worstcase 41.689 ms/op 72.769 ms/op 0.57
phase0 afterProcessEpoch - 250000 vs - 7PWei 158.24 ms/op 223.48 ms/op 0.71
phase0 beforeProcessEpoch - 250000 vs - 7PWei 77.751 ms/op 519.71 ms/op 0.15
phase0 processEpoch - mainnet_e58758 519.94 ms/op 753.04 ms/op 0.69
mainnet_e58758 - phase0 beforeProcessEpoch 241.49 ms/op 422.60 ms/op 0.57
mainnet_e58758 - phase0 processJustificationAndFinalization 27.937 us/op 55.394 us/op 0.50
mainnet_e58758 - phase0 processRewardsAndPenalties 125.52 ms/op 111.29 ms/op 1.13
mainnet_e58758 - phase0 processRegistryUpdates 9.7060 us/op 37.813 us/op 0.26
mainnet_e58758 - phase0 processSlashings 1.3110 us/op 1.8130 us/op 0.72
mainnet_e58758 - phase0 processEth1DataReset 1.2240 us/op 1.8880 us/op 0.65
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 4.7710 ms/op 4.7368 ms/op 1.01
mainnet_e58758 - phase0 processSlashingsReset 4.8120 us/op 9.2050 us/op 0.52
mainnet_e58758 - phase0 processRandaoMixesReset 8.0630 us/op 14.594 us/op 0.55
mainnet_e58758 - phase0 processHistoricalRootsUpdate 1.2340 us/op 1.9400 us/op 0.64
mainnet_e58758 - phase0 processParticipationRecordUpdates 5.9970 us/op 11.747 us/op 0.51
mainnet_e58758 - phase0 afterProcessEpoch 137.94 ms/op 172.03 ms/op 0.80
phase0 processEffectiveBalanceUpdates - 250000 normalcase 5.5297 ms/op 5.3088 ms/op 1.04
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 6.0134 ms/op 5.6608 ms/op 1.06
phase0 processRegistryUpdates - 250000 normalcase 9.3370 us/op 36.085 us/op 0.26
phase0 processRegistryUpdates - 250000 badcase_full_deposits 370.33 us/op 2.8896 ms/op 0.13
phase0 processRegistryUpdates - 250000 worstcase 0.5 207.27 ms/op 1.5390 s/op 0.13
phase0 getAttestationDeltas - 250000 normalcase 14.014 ms/op 13.243 ms/op 1.06
phase0 getAttestationDeltas - 250000 worstcase 14.543 ms/op 13.223 ms/op 1.10
phase0 processSlashings - 250000 worstcase 5.7197 ms/op 37.313 ms/op 0.15
shuffle list - 16384 els 9.4457 ms/op 12.919 ms/op 0.73
shuffle list - 250000 els 136.24 ms/op 185.52 ms/op 0.73
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 325.55 us/op 431.67 us/op 0.75
pass gossip attestations to forkchoice per slot 5.4618 ms/op 14.677 ms/op 0.37
computeDeltas 3.3954 ms/op 3.3587 ms/op 1.01
computeProposerBoostScoreFromBalances 444.46 us/op 503.19 us/op 0.88
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 2.3999 ms/op 1.8189 ms/op 1.32
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 68.373 us/op 630.59 us/op 0.11
BLS verify - blst-native 1.6327 ms/op 1.6366 ms/op 1.00
BLS verifyMultipleSignatures 3 - blst-native 3.3475 ms/op 3.3603 ms/op 1.00
BLS verifyMultipleSignatures 8 - blst-native 7.2286 ms/op 7.2144 ms/op 1.00
BLS verifyMultipleSignatures 32 - blst-native 26.190 ms/op 26.131 ms/op 1.00
BLS aggregatePubkeys 32 - blst-native 35.097 us/op 34.659 us/op 1.01
BLS aggregatePubkeys 128 - blst-native 138.02 us/op 135.51 us/op 1.02
getAttestationsForBlock 54.660 ms/op 57.981 ms/op 0.94
CheckpointStateCache - add get delete 9.6200 us/op 16.586 us/op 0.58
validate gossip signedAggregateAndProof - struct 3.7964 ms/op 3.9204 ms/op 0.97
validate gossip attestation - struct 1.7768 ms/op 1.8486 ms/op 0.96
pickEth1Vote - no votes 1.9747 ms/op 8.3613 ms/op 0.24
pickEth1Vote - max votes 19.077 ms/op 50.908 ms/op 0.37
pickEth1Vote - Eth1Data hashTreeRoot value x2048 10.777 ms/op 22.401 ms/op 0.48
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 20.634 ms/op 8.5674 ms/op 2.41
pickEth1Vote - Eth1Data fastSerialize value x2048 1.5264 ms/op 4.5781 ms/op 0.33
pickEth1Vote - Eth1Data fastSerialize tree x2048 13.106 ms/op 20.983 ms/op 0.62
bytes32 toHexString 896.00 ns/op 1.4620 us/op 0.61
bytes32 Buffer.toString(hex) 625.00 ns/op 596.00 ns/op 1.05
bytes32 Buffer.toString(hex) from Uint8Array 796.00 ns/op 808.00 ns/op 0.99
bytes32 Buffer.toString(hex) + 0x 628.00 ns/op 599.00 ns/op 1.05
Object access 1 prop 0.31800 ns/op 0.29600 ns/op 1.07
Map access 1 prop 0.26700 ns/op 0.26500 ns/op 1.01
Object get x1000 15.576 ns/op 15.461 ns/op 1.01
Map get x1000 0.87400 ns/op 0.87600 ns/op 1.00
Object set x1000 100.34 ns/op 93.527 ns/op 1.07
Map set x1000 61.872 ns/op 56.381 ns/op 1.10
Return object 10000 times 0.33050 ns/op 0.33020 ns/op 1.00
Throw Error 10000 times 5.2404 us/op 5.1259 us/op 1.02
enrSubnets - fastDeserialize 64 bits 878.00 ns/op 1.0810 us/op 0.81
enrSubnets - ssz BitVector 64 bits 556.00 ns/op 14.408 us/op 0.04
enrSubnets - fastDeserialize 4 bits 391.00 ns/op 407.00 ns/op 0.96
enrSubnets - ssz BitVector 4 bits 551.00 ns/op 2.5810 us/op 0.21
RateTracker 1000000 limit, 1 obj count per request 176.83 ns/op 155.70 ns/op 1.14
RateTracker 1000000 limit, 2 obj count per request 130.52 ns/op 117.23 ns/op 1.11
RateTracker 1000000 limit, 4 obj count per request 106.83 ns/op 95.008 ns/op 1.12
RateTracker 1000000 limit, 8 obj count per request 93.770 ns/op 86.171 ns/op 1.09
RateTracker with prune 3.8450 us/op 3.5580 us/op 1.08
array of 16000 items push then shift 2.7380 us/op 3.0104 us/op 0.91
LinkedList of 16000 items push then shift 16.706 ns/op 18.247 ns/op 0.92
array of 16000 items push then pop 199.73 ns/op 201.97 ns/op 0.99
LinkedList of 16000 items push then pop 15.332 ns/op 15.980 ns/op 0.96
array of 24000 items push then shift 4.0351 us/op 4.5596 us/op 0.88
LinkedList of 24000 items push then shift 21.124 ns/op 20.819 ns/op 1.01
array of 24000 items push then pop 180.51 ns/op 173.12 ns/op 1.04
LinkedList of 24000 items push then pop 17.791 ns/op 16.855 ns/op 1.06

by benchmarkbot/action

yarn.lock Outdated
@@ -505,6 +525,15 @@
buffer-from "^1.1.1"
snappy "^6.3.5"

"@chainsafe/ssz@^0.8.20":
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Warning, this should not be in the yarn.lock. Who is depending in the old versions?

@wemeetagain wemeetagain dismissed a stale review via c83991f April 4, 2022 16:16
@wemeetagain wemeetagain merged commit 3d1fd18 into master Apr 4, 2022
@wemeetagain wemeetagain deleted the dapplion/ssz-v2 branch April 4, 2022 16:51
@philknows philknows modified the milestones: v0.36.0-old, v0.35.0 Apr 5, 2022
@philknows philknows mentioned this pull request Apr 5, 2022
@philknows philknows modified the milestones: v0.35.0, v1.0.0 May 10, 2022
@dapplion dapplion removed this from the Audit 2022Q2-batch1 milestone Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants