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

Make BeaconChain dependencies readonly #4376

Merged
merged 2 commits into from Aug 7, 2022

Conversation

dapplion
Copy link
Contributor

@dapplion dapplion commented Aug 6, 2022

Motivation

Some properties on the class BeaconChain where not readonly, due to some stub tests that required mutation. Those dependencies are never updated in production code, so MUST be marked as readonly.

Description

This PR instead overwrites the type of BeaconChain to allow mutation only where necessary.

@dapplion dapplion requested a review from a team as a code owner August 6, 2022 10:23
@github-actions
Copy link
Contributor

github-actions bot commented Aug 6, 2022

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: 2488826 Previous: 1da9558 Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 1.9738 ms/op 2.2951 ms/op 0.86
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 74.221 us/op 80.114 us/op 0.93
BLS verify - blst-native 1.8500 ms/op 1.8636 ms/op 0.99
BLS verifyMultipleSignatures 3 - blst-native 3.7881 ms/op 3.8016 ms/op 1.00
BLS verifyMultipleSignatures 8 - blst-native 8.1669 ms/op 8.1873 ms/op 1.00
BLS verifyMultipleSignatures 32 - blst-native 29.630 ms/op 29.688 ms/op 1.00
BLS aggregatePubkeys 32 - blst-native 38.831 us/op 39.703 us/op 0.98
BLS aggregatePubkeys 128 - blst-native 152.38 us/op 152.82 us/op 1.00
getAttestationsForBlock 159.13 ms/op 170.15 ms/op 0.94
isKnown best case - 1 super set check 433.00 ns/op 446.00 ns/op 0.97
isKnown normal case - 2 super set checks 420.00 ns/op 426.00 ns/op 0.99
isKnown worse case - 16 super set checks 418.00 ns/op 424.00 ns/op 0.99
CheckpointStateCache - add get delete 8.3470 us/op 9.3240 us/op 0.90
validate gossip signedAggregateAndProof - struct 4.2579 ms/op 4.2895 ms/op 0.99
validate gossip attestation - struct 2.0365 ms/op 2.0394 ms/op 1.00
altair verifyImport mainnet_s3766816:31 8.5244 s/op 8.4311 s/op 1.01
pickEth1Vote - no votes 2.0269 ms/op 2.3136 ms/op 0.88
pickEth1Vote - max votes 22.152 ms/op 27.514 ms/op 0.81
pickEth1Vote - Eth1Data hashTreeRoot value x2048 11.126 ms/op 12.684 ms/op 0.88
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 20.529 ms/op 24.352 ms/op 0.84
pickEth1Vote - Eth1Data fastSerialize value x2048 1.5407 ms/op 1.5249 ms/op 1.01
pickEth1Vote - Eth1Data fastSerialize tree x2048 15.155 ms/op 13.500 ms/op 1.12
bytes32 toHexString 1.0430 us/op 1.0830 us/op 0.96
bytes32 Buffer.toString(hex) 693.00 ns/op 707.00 ns/op 0.98
bytes32 Buffer.toString(hex) from Uint8Array 921.00 ns/op 921.00 ns/op 1.00
bytes32 Buffer.toString(hex) + 0x 675.00 ns/op 684.00 ns/op 0.99
Object access 1 prop 0.35300 ns/op 0.34800 ns/op 1.01
Map access 1 prop 0.29400 ns/op 0.28500 ns/op 1.03
Object get x1000 18.308 ns/op 17.434 ns/op 1.05
Map get x1000 1.1060 ns/op 0.99600 ns/op 1.11
Object set x1000 113.82 ns/op 111.64 ns/op 1.02
Map set x1000 67.157 ns/op 69.399 ns/op 0.97
Return object 10000 times 0.37410 ns/op 0.36620 ns/op 1.02
Throw Error 10000 times 6.0500 us/op 5.8734 us/op 1.03
enrSubnets - fastDeserialize 64 bits 2.7000 us/op 2.6350 us/op 1.02
enrSubnets - ssz BitVector 64 bits 742.00 ns/op 817.00 ns/op 0.91
enrSubnets - fastDeserialize 4 bits 368.00 ns/op 365.00 ns/op 1.01
enrSubnets - ssz BitVector 4 bits 733.00 ns/op 761.00 ns/op 0.96
prioritizePeers score -10:0 att 32-0.1 sync 2-0 91.901 us/op 88.325 us/op 1.04
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 123.09 us/op 124.55 us/op 0.99
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 207.24 us/op 196.90 us/op 1.05
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 455.42 us/op 445.97 us/op 1.02
prioritizePeers score 0:0 att 64-1 sync 4-1 462.22 us/op 459.14 us/op 1.01
RateTracker 1000000 limit, 1 obj count per request 185.52 ns/op 183.27 ns/op 1.01
RateTracker 1000000 limit, 2 obj count per request 145.31 ns/op 137.28 ns/op 1.06
RateTracker 1000000 limit, 4 obj count per request 124.80 ns/op 121.38 ns/op 1.03
RateTracker 1000000 limit, 8 obj count per request 115.46 ns/op 110.36 ns/op 1.05
RateTracker with prune 4.4370 us/op 4.8720 us/op 0.91
array of 16000 items push then shift 3.0855 us/op 3.0885 us/op 1.00
LinkedList of 16000 items push then shift 26.059 ns/op 26.854 ns/op 0.97
array of 16000 items push then pop 243.99 ns/op 237.82 ns/op 1.03
LinkedList of 16000 items push then pop 22.262 ns/op 22.578 ns/op 0.99
array of 24000 items push then shift 4.5517 us/op 4.5870 us/op 0.99
LinkedList of 24000 items push then shift 28.749 ns/op 29.432 ns/op 0.98
array of 24000 items push then pop 204.71 ns/op 212.78 ns/op 0.96
LinkedList of 24000 items push then pop 23.708 ns/op 22.399 ns/op 1.06
intersect bitArray bitLen 8 11.721 ns/op 11.585 ns/op 1.01
intersect array and set length 8 165.70 ns/op 171.76 ns/op 0.96
intersect bitArray bitLen 128 72.182 ns/op 72.146 ns/op 1.00
intersect array and set length 128 2.1931 us/op 2.2754 us/op 0.96
Buffer.concat 32 items 1.8470 ns/op 1.9040 ns/op 0.97
pass gossip attestations to forkchoice per slot 3.5672 ms/op 5.0610 ms/op 0.70
computeDeltas 3.4517 ms/op 3.1833 ms/op 1.08
computeProposerBoostScoreFromBalances 921.14 us/op 908.21 us/op 1.01
altair processAttestation - 250000 vs - 7PWei normalcase 3.8387 ms/op 4.3258 ms/op 0.89
altair processAttestation - 250000 vs - 7PWei worstcase 5.7517 ms/op 5.8048 ms/op 0.99
altair processAttestation - setStatus - 1/6 committees join 208.73 us/op 211.21 us/op 0.99
altair processAttestation - setStatus - 1/3 committees join 393.60 us/op 398.12 us/op 0.99
altair processAttestation - setStatus - 1/2 committees join 551.88 us/op 563.49 us/op 0.98
altair processAttestation - setStatus - 2/3 committees join 706.69 us/op 717.32 us/op 0.99
altair processAttestation - setStatus - 4/5 committees join 984.94 us/op 1.0053 ms/op 0.98
altair processAttestation - setStatus - 100% committees join 1.1653 ms/op 1.2062 ms/op 0.97
altair processBlock - 250000 vs - 7PWei normalcase 27.755 ms/op 28.118 ms/op 0.99
altair processBlock - 250000 vs - 7PWei normalcase hashState 40.351 ms/op 39.995 ms/op 1.01
altair processBlock - 250000 vs - 7PWei worstcase 77.374 ms/op 89.033 ms/op 0.87
altair processBlock - 250000 vs - 7PWei worstcase hashState 97.091 ms/op 98.889 ms/op 0.98
phase0 processBlock - 250000 vs - 7PWei normalcase 4.1463 ms/op 4.8621 ms/op 0.85
phase0 processBlock - 250000 vs - 7PWei worstcase 46.781 ms/op 48.357 ms/op 0.97
altair processEth1Data - 250000 vs - 7PWei normalcase 822.41 us/op 919.12 us/op 0.89
Tree 40 250000 create 750.37 ms/op 845.11 ms/op 0.89
Tree 40 250000 get(125000) 282.34 ns/op 296.17 ns/op 0.95
Tree 40 250000 set(125000) 2.2572 us/op 2.8274 us/op 0.80
Tree 40 250000 toArray() 33.879 ms/op 33.305 ms/op 1.02
Tree 40 250000 iterate all - toArray() + loop 33.128 ms/op 33.561 ms/op 0.99
Tree 40 250000 iterate all - get(i) 110.30 ms/op 114.00 ms/op 0.97
MutableVector 250000 create 15.002 ms/op 14.100 ms/op 1.06
MutableVector 250000 get(125000) 14.950 ns/op 14.748 ns/op 1.01
MutableVector 250000 set(125000) 520.68 ns/op 707.41 ns/op 0.74
MutableVector 250000 toArray() 7.0072 ms/op 8.0500 ms/op 0.87
MutableVector 250000 iterate all - toArray() + loop 7.0569 ms/op 8.1962 ms/op 0.86
MutableVector 250000 iterate all - get(i) 3.2840 ms/op 3.5696 ms/op 0.92
Array 250000 create 6.0809 ms/op 7.4622 ms/op 0.81
Array 250000 clone - spread 2.6018 ms/op 3.9085 ms/op 0.67
Array 250000 get(125000) 1.1010 ns/op 1.5990 ns/op 0.69
Array 250000 set(125000) 1.1130 ns/op 1.6570 ns/op 0.67
Array 250000 iterate all - loop 167.88 us/op 167.91 us/op 1.00
effectiveBalanceIncrements clone Uint8Array 300000 61.605 us/op 100.77 us/op 0.61
effectiveBalanceIncrements clone MutableVector 300000 746.00 ns/op 1.1940 us/op 0.62
effectiveBalanceIncrements rw all Uint8Array 300000 252.43 us/op 252.60 us/op 1.00
effectiveBalanceIncrements rw all MutableVector 300000 169.35 ms/op 226.73 ms/op 0.75
phase0 afterProcessEpoch - 250000 vs - 7PWei 180.93 ms/op 202.40 ms/op 0.89
phase0 beforeProcessEpoch - 250000 vs - 7PWei 74.564 ms/op 70.840 ms/op 1.05
altair processEpoch - mainnet_e81889 508.08 ms/op 584.39 ms/op 0.87
mainnet_e81889 - altair beforeProcessEpoch 155.06 ms/op 149.58 ms/op 1.04
mainnet_e81889 - altair processJustificationAndFinalization 27.922 us/op 22.657 us/op 1.23
mainnet_e81889 - altair processInactivityUpdates 11.108 ms/op 11.106 ms/op 1.00
mainnet_e81889 - altair processRewardsAndPenalties 97.232 ms/op 93.442 ms/op 1.04
mainnet_e81889 - altair processRegistryUpdates 4.7660 us/op 5.4360 us/op 0.88
mainnet_e81889 - altair processSlashings 623.00 ns/op 1.3810 us/op 0.45
mainnet_e81889 - altair processEth1DataReset 1.1240 us/op 1.3070 us/op 0.86
mainnet_e81889 - altair processEffectiveBalanceUpdates 2.3530 ms/op 2.5663 ms/op 0.92
mainnet_e81889 - altair processSlashingsReset 7.7600 us/op 9.0140 us/op 0.86
mainnet_e81889 - altair processRandaoMixesReset 5.2260 us/op 6.6750 us/op 0.78
mainnet_e81889 - altair processHistoricalRootsUpdate 1.0590 us/op 953.00 ns/op 1.11
mainnet_e81889 - altair processParticipationFlagUpdates 4.0690 us/op 3.4230 us/op 1.19
mainnet_e81889 - altair processSyncCommitteeUpdates 751.00 ns/op 783.00 ns/op 0.96
mainnet_e81889 - altair afterProcessEpoch 193.25 ms/op 193.25 ms/op 1.00
phase0 processEpoch - mainnet_e58758 531.37 ms/op 512.42 ms/op 1.04
mainnet_e58758 - phase0 beforeProcessEpoch 232.96 ms/op 241.86 ms/op 0.96
mainnet_e58758 - phase0 processJustificationAndFinalization 27.027 us/op 28.706 us/op 0.94
mainnet_e58758 - phase0 processRewardsAndPenalties 119.38 ms/op 81.406 ms/op 1.47
mainnet_e58758 - phase0 processRegistryUpdates 13.275 us/op 10.180 us/op 1.30
mainnet_e58758 - phase0 processSlashings 1.1010 us/op 862.00 ns/op 1.28
mainnet_e58758 - phase0 processEth1DataReset 1.2060 us/op 857.00 ns/op 1.41
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 1.9780 ms/op 2.0069 ms/op 0.99
mainnet_e58758 - phase0 processSlashingsReset 7.2110 us/op 5.6360 us/op 1.28
mainnet_e58758 - phase0 processRandaoMixesReset 5.3540 us/op 6.1060 us/op 0.88
mainnet_e58758 - phase0 processHistoricalRootsUpdate 1.1010 us/op 987.00 ns/op 1.12
mainnet_e58758 - phase0 processParticipationRecordUpdates 4.9220 us/op 4.9700 us/op 0.99
mainnet_e58758 - phase0 afterProcessEpoch 157.36 ms/op 160.25 ms/op 0.98
phase0 processEffectiveBalanceUpdates - 250000 normalcase 2.5628 ms/op 2.6362 ms/op 0.97
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 3.2372 ms/op 3.5447 ms/op 0.91
altair processInactivityUpdates - 250000 normalcase 51.068 ms/op 41.163 ms/op 1.24
altair processInactivityUpdates - 250000 worstcase 42.169 ms/op 41.196 ms/op 1.02
phase0 processRegistryUpdates - 250000 normalcase 7.7890 us/op 9.2670 us/op 0.84
phase0 processRegistryUpdates - 250000 badcase_full_deposits 429.74 us/op 432.13 us/op 0.99
phase0 processRegistryUpdates - 250000 worstcase 0.5 240.33 ms/op 215.29 ms/op 1.12
altair processRewardsAndPenalties - 250000 normalcase 130.92 ms/op 130.96 ms/op 1.00
altair processRewardsAndPenalties - 250000 worstcase 130.53 ms/op 88.424 ms/op 1.48
phase0 getAttestationDeltas - 250000 normalcase 12.586 ms/op 15.113 ms/op 0.83
phase0 getAttestationDeltas - 250000 worstcase 12.873 ms/op 15.780 ms/op 0.82
phase0 processSlashings - 250000 worstcase 5.4434 ms/op 5.5991 ms/op 0.97
altair processSyncCommitteeUpdates - 250000 285.53 ms/op 293.34 ms/op 0.97
BeaconState.hashTreeRoot - No change 470.00 ns/op 481.00 ns/op 0.98
BeaconState.hashTreeRoot - 1 full validator 62.848 us/op 64.101 us/op 0.98
BeaconState.hashTreeRoot - 32 full validator 628.88 us/op 719.20 us/op 0.87
BeaconState.hashTreeRoot - 512 full validator 6.5327 ms/op 6.3749 ms/op 1.02
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 80.076 us/op 77.565 us/op 1.03
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 1.1346 ms/op 1.2026 ms/op 0.94
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 15.741 ms/op 15.984 ms/op 0.98
BeaconState.hashTreeRoot - 1 balances 83.214 us/op 60.557 us/op 1.37
BeaconState.hashTreeRoot - 32 balances 528.58 us/op 575.06 us/op 0.92
BeaconState.hashTreeRoot - 512 balances 5.3840 ms/op 5.6359 ms/op 0.96
BeaconState.hashTreeRoot - 250000 balances 88.549 ms/op 94.626 ms/op 0.94
aggregationBits - 2048 els - zipIndexesInBitList 31.816 us/op 29.156 us/op 1.09
regular array get 100000 times 67.382 us/op 67.391 us/op 1.00
wrappedArray get 100000 times 67.408 us/op 67.416 us/op 1.00
arrayWithProxy get 100000 times 34.022 ms/op 34.242 ms/op 0.99
ssz.Root.equals 460.00 ns/op 479.00 ns/op 0.96
byteArrayEquals 455.00 ns/op 458.00 ns/op 0.99
shuffle list - 16384 els 11.073 ms/op 11.001 ms/op 1.01
shuffle list - 250000 els 162.72 ms/op 163.07 ms/op 1.00
processSlot - 1 slots 12.321 us/op 11.761 us/op 1.05
processSlot - 32 slots 1.7456 ms/op 1.7814 ms/op 0.98
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 380.04 us/op 638.42 us/op 0.60
getCommitteeAssignments - req 1 vs - 250000 vc 5.2715 ms/op 5.2805 ms/op 1.00
getCommitteeAssignments - req 100 vs - 250000 vc 7.2635 ms/op 7.3645 ms/op 0.99
getCommitteeAssignments - req 1000 vs - 250000 vc 7.7604 ms/op 7.9839 ms/op 0.97
computeProposers - vc 250000 18.781 ms/op 19.378 ms/op 0.97
computeEpochShuffling - vc 250000 164.93 ms/op 164.83 ms/op 1.00
getNextSyncCommittee - vc 250000 269.78 ms/op 284.97 ms/op 0.95

by benchmarkbot/action

@wemeetagain wemeetagain merged commit ac5398e into unstable Aug 7, 2022
@wemeetagain wemeetagain deleted the dapplion/beaconchain-readonly branch August 7, 2022 14:24
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

2 participants