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

Overhaul blinded types into multi-fork #4565

Merged
merged 4 commits into from Sep 20, 2022
Merged

Conversation

g11tech
Copy link
Contributor

@g11tech g11tech commented Sep 19, 2022

The blinded types currently used (for dev simplicity) are only of bellatrix

This PR overhauls blinded types into multi-fork in preparation for the capella hardfork

@g11tech g11tech requested a review from a team as a code owner September 19, 2022 10:33
@github-actions
Copy link
Contributor

github-actions bot commented Sep 19, 2022

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: c02ce15 Previous: 31f220e Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 2.3048 ms/op 3.0094 ms/op 0.77
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 86.625 us/op 100.58 us/op 0.86
BLS verify - blst-native 2.6702 ms/op 2.3937 ms/op 1.12
BLS verifyMultipleSignatures 3 - blst-native 5.7886 ms/op 4.9040 ms/op 1.18
BLS verifyMultipleSignatures 8 - blst-native 12.047 ms/op 10.293 ms/op 1.17
BLS verifyMultipleSignatures 32 - blst-native 46.623 ms/op 38.472 ms/op 1.21
BLS aggregatePubkeys 32 - blst-native 61.931 us/op 52.179 us/op 1.19
BLS aggregatePubkeys 128 - blst-native 237.01 us/op 194.04 us/op 1.22
getAttestationsForBlock 120.28 ms/op 120.20 ms/op 1.00
isKnown best case - 1 super set check 540.00 ns/op 547.00 ns/op 0.99
isKnown normal case - 2 super set checks 528.00 ns/op 517.00 ns/op 1.02
isKnown worse case - 16 super set checks 530.00 ns/op 532.00 ns/op 1.00
CheckpointStateCache - add get delete 11.517 us/op 11.572 us/op 1.00
validate gossip signedAggregateAndProof - struct 6.3394 ms/op 5.3912 ms/op 1.18
validate gossip attestation - struct 3.0898 ms/op 2.5870 ms/op 1.19
pickEth1Vote - no votes 2.6341 ms/op 2.7711 ms/op 0.95
pickEth1Vote - max votes 23.979 ms/op 27.804 ms/op 0.86
pickEth1Vote - Eth1Data hashTreeRoot value x2048 14.939 ms/op 14.974 ms/op 1.00
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 25.041 ms/op 26.870 ms/op 0.93
pickEth1Vote - Eth1Data fastSerialize value x2048 1.8021 ms/op 2.0045 ms/op 0.90
pickEth1Vote - Eth1Data fastSerialize tree x2048 17.062 ms/op 18.619 ms/op 0.92
bytes32 toHexString 1.3020 us/op 1.4500 us/op 0.90
bytes32 Buffer.toString(hex) 1.0090 us/op 910.00 ns/op 1.11
bytes32 Buffer.toString(hex) from Uint8Array 1.1900 us/op 1.2130 us/op 0.98
bytes32 Buffer.toString(hex) + 0x 902.00 ns/op 929.00 ns/op 0.97
Object access 1 prop 0.47200 ns/op 0.51100 ns/op 0.92
Map access 1 prop 0.38200 ns/op 0.38500 ns/op 0.99
Object get x1000 18.133 ns/op 17.729 ns/op 1.02
Map get x1000 1.0430 ns/op 1.2420 ns/op 0.84
Object set x1000 128.40 ns/op 139.20 ns/op 0.92
Map set x1000 88.594 ns/op 89.640 ns/op 0.99
Return object 10000 times 0.42930 ns/op 0.44600 ns/op 0.96
Throw Error 10000 times 8.4717 us/op 8.7314 us/op 0.97
enrSubnets - fastDeserialize 64 bits 3.4490 us/op 3.5390 us/op 0.97
enrSubnets - ssz BitVector 64 bits 932.00 ns/op 1.0110 us/op 0.92
enrSubnets - fastDeserialize 4 bits 468.00 ns/op 469.00 ns/op 1.00
enrSubnets - ssz BitVector 4 bits 942.00 ns/op 937.00 ns/op 1.01
prioritizePeers score -10:0 att 32-0.1 sync 2-0 142.82 us/op 145.05 us/op 0.98
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 156.86 us/op 169.52 us/op 0.93
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 287.48 us/op 305.64 us/op 0.94
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 601.35 us/op 670.57 us/op 0.90
prioritizePeers score 0:0 att 64-1 sync 4-1 653.04 us/op 595.34 us/op 1.10
RateTracker 1000000 limit, 1 obj count per request 218.89 ns/op 222.88 ns/op 0.98
RateTracker 1000000 limit, 2 obj count per request 165.95 ns/op 165.33 ns/op 1.00
RateTracker 1000000 limit, 4 obj count per request 135.15 ns/op 140.93 ns/op 0.96
RateTracker 1000000 limit, 8 obj count per request 123.01 ns/op 125.08 ns/op 0.98
RateTracker with prune 5.9040 us/op 6.1940 us/op 0.95
array of 16000 items push then shift 5.6480 us/op 5.6634 us/op 1.00
LinkedList of 16000 items push then shift 21.720 ns/op 22.238 ns/op 0.98
array of 16000 items push then pop 260.76 ns/op 287.13 ns/op 0.91
LinkedList of 16000 items push then pop 18.988 ns/op 20.972 ns/op 0.91
array of 24000 items push then shift 7.8676 us/op 8.3103 us/op 0.95
LinkedList of 24000 items push then shift 20.971 ns/op 22.487 ns/op 0.93
array of 24000 items push then pop 254.93 ns/op 266.04 ns/op 0.96
LinkedList of 24000 items push then pop 19.497 ns/op 20.384 ns/op 0.96
intersect bitArray bitLen 8 12.514 ns/op 12.943 ns/op 0.97
intersect array and set length 8 218.43 ns/op 219.86 ns/op 0.99
intersect bitArray bitLen 128 72.635 ns/op 75.958 ns/op 0.96
intersect array and set length 128 2.5624 us/op 2.6060 us/op 0.98
Buffer.concat 32 items 3.0260 ns/op 2.8670 ns/op 1.06
pass gossip attestations to forkchoice per slot 8.1441 ms/op 6.2911 ms/op 1.29
computeDeltas 3.9402 ms/op 4.5224 ms/op 0.87
computeProposerBoostScoreFromBalances 914.38 us/op 933.08 us/op 0.98
altair processAttestation - 250000 vs - 7PWei normalcase 5.4307 ms/op 6.0966 ms/op 0.89
altair processAttestation - 250000 vs - 7PWei worstcase 8.8519 ms/op 8.5674 ms/op 1.03
altair processAttestation - setStatus - 1/6 committees join 253.67 us/op 265.23 us/op 0.96
altair processAttestation - setStatus - 1/3 committees join 509.28 us/op 506.02 us/op 1.01
altair processAttestation - setStatus - 1/2 committees join 697.94 us/op 765.45 us/op 0.91
altair processAttestation - setStatus - 2/3 committees join 887.44 us/op 1.0078 ms/op 0.88
altair processAttestation - setStatus - 4/5 committees join 1.2783 ms/op 1.4331 ms/op 0.89
altair processAttestation - setStatus - 100% committees join 1.4307 ms/op 1.7136 ms/op 0.83
altair processBlock - 250000 vs - 7PWei normalcase 31.637 ms/op 36.186 ms/op 0.87
altair processBlock - 250000 vs - 7PWei normalcase hashState 45.212 ms/op 50.440 ms/op 0.90
altair processBlock - 250000 vs - 7PWei worstcase 104.27 ms/op 104.48 ms/op 1.00
altair processBlock - 250000 vs - 7PWei worstcase hashState 126.79 ms/op 130.89 ms/op 0.97
phase0 processBlock - 250000 vs - 7PWei normalcase 5.1319 ms/op 4.8605 ms/op 1.06
phase0 processBlock - 250000 vs - 7PWei worstcase 69.909 ms/op 61.382 ms/op 1.14
altair processEth1Data - 250000 vs - 7PWei normalcase 1.4417 ms/op 1.3191 ms/op 1.09
Tree 40 250000 create 1.1745 s/op 1.1379 s/op 1.03
Tree 40 250000 get(125000) 347.87 ns/op 349.77 ns/op 0.99
Tree 40 250000 set(125000) 4.3141 us/op 4.0754 us/op 1.06
Tree 40 250000 toArray() 37.275 ms/op 40.629 ms/op 0.92
Tree 40 250000 iterate all - toArray() + loop 35.855 ms/op 40.365 ms/op 0.89
Tree 40 250000 iterate all - get(i) 142.82 ms/op 143.98 ms/op 0.99
MutableVector 250000 create 19.694 ms/op 19.326 ms/op 1.02
MutableVector 250000 get(125000) 15.238 ns/op 15.354 ns/op 0.99
MutableVector 250000 set(125000) 971.73 ns/op 1.1746 us/op 0.83
MutableVector 250000 toArray() 8.2667 ms/op 9.2474 ms/op 0.89
MutableVector 250000 iterate all - toArray() + loop 8.3525 ms/op 9.3399 ms/op 0.89
MutableVector 250000 iterate all - get(i) 3.6180 ms/op 3.6005 ms/op 1.00
Array 250000 create 8.5939 ms/op 8.5621 ms/op 1.00
Array 250000 clone - spread 3.2555 ms/op 4.9507 ms/op 0.66
Array 250000 get(125000) 1.3270 ns/op 2.1840 ns/op 0.61
Array 250000 set(125000) 1.4700 ns/op 2.2370 ns/op 0.66
Array 250000 iterate all - loop 145.85 us/op 150.92 us/op 0.97
effectiveBalanceIncrements clone Uint8Array 300000 276.29 us/op 425.29 us/op 0.65
effectiveBalanceIncrements clone MutableVector 300000 2.5280 us/op 1.2030 us/op 2.10
effectiveBalanceIncrements rw all Uint8Array 300000 304.04 us/op 300.70 us/op 1.01
effectiveBalanceIncrements rw all MutableVector 300000 224.01 ms/op 247.96 ms/op 0.90
phase0 afterProcessEpoch - 250000 vs - 7PWei 219.21 ms/op 222.24 ms/op 0.99
phase0 beforeProcessEpoch - 250000 vs - 7PWei 73.321 ms/op 84.335 ms/op 0.87
altair processEpoch - mainnet_e81889 685.77 ms/op 697.72 ms/op 0.98
mainnet_e81889 - altair beforeProcessEpoch 106.97 ms/op 192.41 ms/op 0.56
mainnet_e81889 - altair processJustificationAndFinalization 68.230 us/op 64.296 us/op 1.06
mainnet_e81889 - altair processInactivityUpdates 11.691 ms/op 12.972 ms/op 0.90
mainnet_e81889 - altair processRewardsAndPenalties 170.18 ms/op 112.72 ms/op 1.51
mainnet_e81889 - altair processRegistryUpdates 12.748 us/op 15.663 us/op 0.81
mainnet_e81889 - altair processSlashings 4.0400 us/op 4.2670 us/op 0.95
mainnet_e81889 - altair processEth1DataReset 3.8600 us/op 4.1180 us/op 0.94
mainnet_e81889 - altair processEffectiveBalanceUpdates 3.6155 ms/op 2.7223 ms/op 1.33
mainnet_e81889 - altair processSlashingsReset 23.979 us/op 24.922 us/op 0.96
mainnet_e81889 - altair processRandaoMixesReset 23.636 us/op 24.526 us/op 0.96
mainnet_e81889 - altair processHistoricalRootsUpdate 3.8770 us/op 4.1000 us/op 0.95
mainnet_e81889 - altair processParticipationFlagUpdates 14.378 us/op 15.950 us/op 0.90
mainnet_e81889 - altair processSyncCommitteeUpdates 3.1740 us/op 3.5880 us/op 0.88
mainnet_e81889 - altair afterProcessEpoch 227.33 ms/op 228.08 ms/op 1.00
phase0 processEpoch - mainnet_e58758 624.69 ms/op 646.75 ms/op 0.97
mainnet_e58758 - phase0 beforeProcessEpoch 253.24 ms/op 306.41 ms/op 0.83
mainnet_e58758 - phase0 processJustificationAndFinalization 56.540 us/op 64.189 us/op 0.88
mainnet_e58758 - phase0 processRewardsAndPenalties 85.798 ms/op 170.96 ms/op 0.50
mainnet_e58758 - phase0 processRegistryUpdates 34.624 us/op 38.143 us/op 0.91
mainnet_e58758 - phase0 processSlashings 2.9990 us/op 3.7800 us/op 0.79
mainnet_e58758 - phase0 processEth1DataReset 3.0330 us/op 3.7430 us/op 0.81
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 1.9883 ms/op 2.4432 ms/op 0.81
mainnet_e58758 - phase0 processSlashingsReset 15.577 us/op 16.562 us/op 0.94
mainnet_e58758 - phase0 processRandaoMixesReset 24.969 us/op 24.796 us/op 1.01
mainnet_e58758 - phase0 processHistoricalRootsUpdate 4.4790 us/op 4.0450 us/op 1.11
mainnet_e58758 - phase0 processParticipationRecordUpdates 23.750 us/op 22.356 us/op 1.06
mainnet_e58758 - phase0 afterProcessEpoch 190.40 ms/op 179.41 ms/op 1.06
phase0 processEffectiveBalanceUpdates - 250000 normalcase 2.5439 ms/op 2.5140 ms/op 1.01
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 2.9778 ms/op 3.1279 ms/op 0.95
altair processInactivityUpdates - 250000 normalcase 55.887 ms/op 55.293 ms/op 1.01
altair processInactivityUpdates - 250000 worstcase 58.178 ms/op 68.901 ms/op 0.84
phase0 processRegistryUpdates - 250000 normalcase 27.221 us/op 27.188 us/op 1.00
phase0 processRegistryUpdates - 250000 badcase_full_deposits 534.33 us/op 536.46 us/op 1.00
phase0 processRegistryUpdates - 250000 worstcase 0.5 276.25 ms/op 276.41 ms/op 1.00
altair processRewardsAndPenalties - 250000 normalcase 97.018 ms/op 166.01 ms/op 0.58
altair processRewardsAndPenalties - 250000 worstcase 141.04 ms/op 108.09 ms/op 1.30
phase0 getAttestationDeltas - 250000 normalcase 14.919 ms/op 16.868 ms/op 0.88
phase0 getAttestationDeltas - 250000 worstcase 13.361 ms/op 15.048 ms/op 0.89
phase0 processSlashings - 250000 worstcase 6.7685 ms/op 6.8064 ms/op 0.99
altair processSyncCommitteeUpdates - 250000 343.49 ms/op 362.97 ms/op 0.95
BeaconState.hashTreeRoot - No change 621.00 ns/op 637.00 ns/op 0.97
BeaconState.hashTreeRoot - 1 full validator 82.280 us/op 80.291 us/op 1.02
BeaconState.hashTreeRoot - 32 full validator 797.67 us/op 795.66 us/op 1.00
BeaconState.hashTreeRoot - 512 full validator 8.5861 ms/op 8.0108 ms/op 1.07
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 108.57 us/op 110.62 us/op 0.98
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 1.5611 ms/op 1.6490 ms/op 0.95
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 20.647 ms/op 21.402 ms/op 0.96
BeaconState.hashTreeRoot - 1 balances 85.015 us/op 78.411 us/op 1.08
BeaconState.hashTreeRoot - 32 balances 787.27 us/op 741.90 us/op 1.06
BeaconState.hashTreeRoot - 512 balances 7.3976 ms/op 8.3720 ms/op 0.88
BeaconState.hashTreeRoot - 250000 balances 127.19 ms/op 115.29 ms/op 1.10
aggregationBits - 2048 els - zipIndexesInBitList 31.828 us/op 32.777 us/op 0.97
regular array get 100000 times 56.669 us/op 56.781 us/op 1.00
wrappedArray get 100000 times 61.789 us/op 59.612 us/op 1.04
arrayWithProxy get 100000 times 41.187 ms/op 37.272 ms/op 1.11
ssz.Root.equals 573.00 ns/op 611.00 ns/op 0.94
byteArrayEquals 574.00 ns/op 602.00 ns/op 0.95
shuffle list - 16384 els 13.231 ms/op 12.564 ms/op 1.05
shuffle list - 250000 els 179.34 ms/op 181.00 ms/op 0.99
processSlot - 1 slots 17.810 us/op 18.299 us/op 0.97
processSlot - 32 slots 2.3951 ms/op 2.4606 ms/op 0.97
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 522.37 us/op 574.02 us/op 0.91
getCommitteeAssignments - req 1 vs - 250000 vc 5.4625 ms/op 6.1799 ms/op 0.88
getCommitteeAssignments - req 100 vs - 250000 vc 8.0777 ms/op 8.2521 ms/op 0.98
getCommitteeAssignments - req 1000 vs - 250000 vc 8.1361 ms/op 9.0278 ms/op 0.90
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 11.010 ns/op 9.6100 ns/op 1.15
state getBlockRootAtSlot - 250000 vs - 7PWei 1.3655 us/op 1.4590 us/op 0.94
computeProposers - vc 250000 22.817 ms/op 22.678 ms/op 1.01
computeEpochShuffling - vc 250000 188.47 ms/op 187.44 ms/op 1.01
getNextSyncCommittee - vc 250000 374.53 ms/op 345.98 ms/op 1.08

by benchmarkbot/action

Copy link
Contributor

@dapplion dapplion left a comment

Choose a reason for hiding this comment

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

Overall looks good! Some minor comments

@@ -443,7 +443,12 @@ export function getReturnTypes(): ReturnTypes<Api> {
getSyncCommitteeDuties: ContainerDataExecutionOptimistic(ArrayOf(SyncDuty)),
produceBlock: ContainerData(ssz.phase0.BeaconBlock),
produceBlockV2: WithVersion((fork: ForkName) => ssz[fork].BeaconBlock),
produceBlindedBlock: WithVersion((_fork: ForkName) => ssz.bellatrix.BlindedBeaconBlock),
produceBlindedBlock: WithVersion((fork: ForkName) => {
if (fork === ForkName.phase0 || fork === ForkName.altair) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use ForkSeq and < ForkSeq.bellatrix comparator

Copy link
Contributor

Choose a reason for hiding this comment

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

Same for packages/config/src/forkConfig/index.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in packages/config/src/forkConfig/index.ts typescript can't infer with seq comparision that fork is not pre bellatrix causing type issues for accessing ssz.allForksBlinded[forkName]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also same here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

duplicated the bellatrix blinded types for phase0 and altair for type consistency, the check here is no more required, while the check in packages/config/src/forkConfig/index.ts is now using seq comparision. let me know if this approach is good

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right, yeah then it's okay typesafety always wins

packages/api/src/beacon/routes/validator.ts Outdated Show resolved Hide resolved
packages/state-transition/src/block/processBlockHeader.ts Outdated Show resolved Hide resolved
@g11tech g11tech enabled auto-merge (squash) September 20, 2022 08:07
altair: {
BeaconBlockBody: bellatrix.BlindedBeaconBlockBody,
BeaconBlock: bellatrix.BlindedBeaconBlock,
SignedBeaconBlock: bellatrix.SignedBlindedBeaconBlock,
Copy link
Contributor

Choose a reason for hiding this comment

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

I actually prefer your original approach of using multiple ForkName comparisions and only defining the types for forks with blinded blocks. Sorry for the back and forth!

@g11tech g11tech merged commit ef48293 into unstable Sep 20, 2022
@g11tech g11tech deleted the g11tech/blinded-forks branch September 20, 2022 10:02
@dapplion dapplion added the spec-capella 🦉 Issues targeting the Capella spec version label Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spec-capella 🦉 Issues targeting the Capella spec version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants