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

Replace findAttesterDependentRoot with getDependantRoot #4555

Merged
merged 5 commits into from Sep 16, 2022

Conversation

dapplion
Copy link
Contributor

Motivation

Generalize logic from findAttesterDependentRoot to work for both proposer and attester dependant root computation. To be used latter in API impl

Description

  • Replace findAttesterDependentRoot with getDependantRoot

@dapplion dapplion requested a review from a team as a code owner September 16, 2022 10:21
@github-actions
Copy link
Contributor

github-actions bot commented Sep 16, 2022

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: 40e1280 Previous: 146f826 Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 2.0455 ms/op 2.3167 ms/op 0.88
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 81.536 us/op 79.913 us/op 1.02
BLS verify - blst-native 2.5945 ms/op 1.8552 ms/op 1.40
BLS verifyMultipleSignatures 3 - blst-native 5.2264 ms/op 3.8073 ms/op 1.37
BLS verifyMultipleSignatures 8 - blst-native 11.597 ms/op 8.1900 ms/op 1.42
BLS verifyMultipleSignatures 32 - blst-native 41.212 ms/op 29.682 ms/op 1.39
BLS aggregatePubkeys 32 - blst-native 56.349 us/op 39.194 us/op 1.44
BLS aggregatePubkeys 128 - blst-native 223.10 us/op 152.94 us/op 1.46
getAttestationsForBlock 100.87 ms/op 169.08 ms/op 0.60
isKnown best case - 1 super set check 471.00 ns/op 437.00 ns/op 1.08
isKnown normal case - 2 super set checks 456.00 ns/op 422.00 ns/op 1.08
isKnown worse case - 16 super set checks 469.00 ns/op 424.00 ns/op 1.11
CheckpointStateCache - add get delete 10.138 us/op 9.1400 us/op 1.11
validate gossip signedAggregateAndProof - struct 5.7590 ms/op 4.2948 ms/op 1.34
validate gossip attestation - struct 2.7231 ms/op 2.0279 ms/op 1.34
pickEth1Vote - no votes 2.3939 ms/op 2.1853 ms/op 1.10
pickEth1Vote - max votes 20.109 ms/op 19.827 ms/op 1.01
pickEth1Vote - Eth1Data hashTreeRoot value x2048 13.669 ms/op 11.588 ms/op 1.18
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 22.199 ms/op 21.195 ms/op 1.05
pickEth1Vote - Eth1Data fastSerialize value x2048 1.6286 ms/op 1.6710 ms/op 0.97
pickEth1Vote - Eth1Data fastSerialize tree x2048 13.742 ms/op 13.884 ms/op 0.99
bytes32 toHexString 1.1550 us/op 1.1590 us/op 1.00
bytes32 Buffer.toString(hex) 779.00 ns/op 781.00 ns/op 1.00
bytes32 Buffer.toString(hex) from Uint8Array 1.1340 us/op 1.0180 us/op 1.11
bytes32 Buffer.toString(hex) + 0x 771.00 ns/op 751.00 ns/op 1.03
Object access 1 prop 0.38000 ns/op 0.40400 ns/op 0.94
Map access 1 prop 0.31900 ns/op 0.29300 ns/op 1.09
Object get x1000 15.883 ns/op 17.498 ns/op 0.91
Map get x1000 1.0530 ns/op 0.97600 ns/op 1.08
Object set x1000 107.91 ns/op 129.37 ns/op 0.83
Map set x1000 75.464 ns/op 77.093 ns/op 0.98
Return object 10000 times 0.39970 ns/op 0.38020 ns/op 1.05
Throw Error 10000 times 7.5995 us/op 5.9289 us/op 1.28
enrSubnets - fastDeserialize 64 bits 2.9880 us/op 2.8620 us/op 1.04
enrSubnets - ssz BitVector 64 bits 811.00 ns/op 767.00 ns/op 1.06
enrSubnets - fastDeserialize 4 bits 412.00 ns/op 436.00 ns/op 0.94
enrSubnets - ssz BitVector 4 bits 784.00 ns/op 816.00 ns/op 0.96
prioritizePeers score -10:0 att 32-0.1 sync 2-0 102.82 us/op 100.61 us/op 1.02
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 153.07 us/op 135.02 us/op 1.13
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 267.62 us/op 254.79 us/op 1.05
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 561.82 us/op 496.68 us/op 1.13
prioritizePeers score 0:0 att 64-1 sync 4-1 609.97 us/op 462.99 us/op 1.32
RateTracker 1000000 limit, 1 obj count per request 192.36 ns/op 223.36 ns/op 0.86
RateTracker 1000000 limit, 2 obj count per request 146.31 ns/op 172.18 ns/op 0.85
RateTracker 1000000 limit, 4 obj count per request 125.06 ns/op 146.29 ns/op 0.85
RateTracker 1000000 limit, 8 obj count per request 109.66 ns/op 131.95 ns/op 0.83
RateTracker with prune 5.1280 us/op 5.4420 us/op 0.94
array of 16000 items push then shift 5.0150 us/op 3.2009 us/op 1.57
LinkedList of 16000 items push then shift 19.512 ns/op 17.553 ns/op 1.11
array of 16000 items push then pop 250.02 ns/op 249.58 ns/op 1.00
LinkedList of 16000 items push then pop 17.237 ns/op 16.756 ns/op 1.03
array of 24000 items push then shift 7.9215 us/op 4.5653 us/op 1.74
LinkedList of 24000 items push then shift 19.411 ns/op 21.298 ns/op 0.91
array of 24000 items push then pop 236.69 ns/op 224.49 ns/op 1.05
LinkedList of 24000 items push then pop 18.056 ns/op 18.363 ns/op 0.98
intersect bitArray bitLen 8 12.116 ns/op 11.780 ns/op 1.03
intersect array and set length 8 189.11 ns/op 188.70 ns/op 1.00
intersect bitArray bitLen 128 65.895 ns/op 62.109 ns/op 1.06
intersect array and set length 128 2.2360 us/op 2.4114 us/op 0.93
Buffer.concat 32 items 2.1340 ns/op 1.9390 ns/op 1.10
pass gossip attestations to forkchoice per slot 3.4418 ms/op 6.6230 ms/op 0.52
computeDeltas 4.0082 ms/op 3.3529 ms/op 1.20
computeProposerBoostScoreFromBalances 847.04 us/op 907.87 us/op 0.93
altair processAttestation - 250000 vs - 7PWei normalcase 4.6966 ms/op 3.8480 ms/op 1.22
altair processAttestation - 250000 vs - 7PWei worstcase 6.6568 ms/op 5.8259 ms/op 1.14
altair processAttestation - setStatus - 1/6 committees join 245.77 us/op 221.78 us/op 1.11
altair processAttestation - setStatus - 1/3 committees join 487.55 us/op 420.90 us/op 1.16
altair processAttestation - setStatus - 1/2 committees join 659.54 us/op 583.56 us/op 1.13
altair processAttestation - setStatus - 2/3 committees join 883.44 us/op 754.79 us/op 1.17
altair processAttestation - setStatus - 4/5 committees join 1.1786 ms/op 1.0419 ms/op 1.13
altair processAttestation - setStatus - 100% committees join 1.3979 ms/op 1.2297 ms/op 1.14
altair processBlock - 250000 vs - 7PWei normalcase 30.723 ms/op 27.972 ms/op 1.10
altair processBlock - 250000 vs - 7PWei normalcase hashState 45.620 ms/op 42.813 ms/op 1.07
altair processBlock - 250000 vs - 7PWei worstcase 108.21 ms/op 75.519 ms/op 1.43
altair processBlock - 250000 vs - 7PWei worstcase hashState 118.48 ms/op 98.179 ms/op 1.21
phase0 processBlock - 250000 vs - 7PWei normalcase 3.9905 ms/op 3.8845 ms/op 1.03
phase0 processBlock - 250000 vs - 7PWei worstcase 60.870 ms/op 47.700 ms/op 1.28
altair processEth1Data - 250000 vs - 7PWei normalcase 931.12 us/op 842.94 us/op 1.10
Tree 40 250000 create 943.45 ms/op 833.95 ms/op 1.13
Tree 40 250000 get(125000) 318.01 ns/op 300.91 ns/op 1.06
Tree 40 250000 set(125000) 3.0459 us/op 2.9512 us/op 1.03
Tree 40 250000 toArray() 32.732 ms/op 33.430 ms/op 0.98
Tree 40 250000 iterate all - toArray() + loop 33.854 ms/op 33.202 ms/op 1.02
Tree 40 250000 iterate all - get(i) 122.70 ms/op 113.86 ms/op 1.08
MutableVector 250000 create 16.680 ms/op 38.798 ms/op 0.43
MutableVector 250000 get(125000) 12.822 ns/op 13.614 ns/op 0.94
MutableVector 250000 set(125000) 844.92 ns/op 538.94 ns/op 1.57
MutableVector 250000 toArray() 7.3374 ms/op 7.0607 ms/op 1.04
MutableVector 250000 iterate all - toArray() + loop 6.9722 ms/op 7.1528 ms/op 0.97
MutableVector 250000 iterate all - get(i) 3.3260 ms/op 3.2791 ms/op 1.01
Array 250000 create 6.5559 ms/op 6.5894 ms/op 0.99
Array 250000 clone - spread 4.1426 ms/op 2.8370 ms/op 1.46
Array 250000 get(125000) 1.7220 ns/op 1.2350 ns/op 1.39
Array 250000 set(125000) 1.7160 ns/op 1.2300 ns/op 1.40
Array 250000 iterate all - loop 137.96 us/op 167.91 us/op 0.82
effectiveBalanceIncrements clone Uint8Array 300000 348.33 us/op 82.053 us/op 4.25
effectiveBalanceIncrements clone MutableVector 300000 799.00 ns/op 827.00 ns/op 0.97
effectiveBalanceIncrements rw all Uint8Array 300000 273.88 us/op 252.48 us/op 1.08
effectiveBalanceIncrements rw all MutableVector 300000 202.00 ms/op 174.34 ms/op 1.16
phase0 afterProcessEpoch - 250000 vs - 7PWei 206.48 ms/op 181.96 ms/op 1.13
phase0 beforeProcessEpoch - 250000 vs - 7PWei 70.914 ms/op 73.918 ms/op 0.96
altair processEpoch - mainnet_e81889 641.91 ms/op 501.22 ms/op 1.28
mainnet_e81889 - altair beforeProcessEpoch 142.69 ms/op 132.81 ms/op 1.07
mainnet_e81889 - altair processJustificationAndFinalization 76.404 us/op 22.908 us/op 3.34
mainnet_e81889 - altair processInactivityUpdates 10.800 ms/op 10.891 ms/op 0.99
mainnet_e81889 - altair processRewardsAndPenalties 96.601 ms/op 92.570 ms/op 1.04
mainnet_e81889 - altair processRegistryUpdates 19.949 us/op 3.3600 us/op 5.94
mainnet_e81889 - altair processSlashings 4.8660 us/op 694.00 ns/op 7.01
mainnet_e81889 - altair processEth1DataReset 5.2880 us/op 825.00 ns/op 6.41
mainnet_e81889 - altair processEffectiveBalanceUpdates 2.3467 ms/op 2.4244 ms/op 0.97
mainnet_e81889 - altair processSlashingsReset 23.032 us/op 5.7910 us/op 3.98
mainnet_e81889 - altair processRandaoMixesReset 30.243 us/op 5.8050 us/op 5.21
mainnet_e81889 - altair processHistoricalRootsUpdate 4.7220 us/op 944.00 ns/op 5.00
mainnet_e81889 - altair processParticipationFlagUpdates 20.785 us/op 2.6270 us/op 7.91
mainnet_e81889 - altair processSyncCommitteeUpdates 4.1660 us/op 808.00 ns/op 5.16
mainnet_e81889 - altair afterProcessEpoch 202.62 ms/op 193.81 ms/op 1.05
phase0 processEpoch - mainnet_e58758 711.35 ms/op 529.78 ms/op 1.34
mainnet_e58758 - phase0 beforeProcessEpoch 229.47 ms/op 232.64 ms/op 0.99
mainnet_e58758 - phase0 processJustificationAndFinalization 69.941 us/op 21.990 us/op 3.18
mainnet_e58758 - phase0 processRewardsAndPenalties 143.55 ms/op 124.62 ms/op 1.15
mainnet_e58758 - phase0 processRegistryUpdates 36.354 us/op 9.8150 us/op 3.70
mainnet_e58758 - phase0 processSlashings 3.5440 us/op 834.00 ns/op 4.25
mainnet_e58758 - phase0 processEth1DataReset 3.8640 us/op 861.00 ns/op 4.49
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 2.1298 ms/op 1.9066 ms/op 1.12
mainnet_e58758 - phase0 processSlashingsReset 19.480 us/op 4.8740 us/op 4.00
mainnet_e58758 - phase0 processRandaoMixesReset 28.395 us/op 5.7080 us/op 4.97
mainnet_e58758 - phase0 processHistoricalRootsUpdate 4.8750 us/op 874.00 ns/op 5.58
mainnet_e58758 - phase0 processParticipationRecordUpdates 25.531 us/op 4.6480 us/op 5.49
mainnet_e58758 - phase0 afterProcessEpoch 158.64 ms/op 158.29 ms/op 1.00
phase0 processEffectiveBalanceUpdates - 250000 normalcase 2.4058 ms/op 2.5450 ms/op 0.95
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 2.6731 ms/op 3.4307 ms/op 0.78
altair processInactivityUpdates - 250000 normalcase 48.418 ms/op 41.702 ms/op 1.16
altair processInactivityUpdates - 250000 worstcase 59.210 ms/op 42.083 ms/op 1.41
phase0 processRegistryUpdates - 250000 normalcase 33.911 us/op 7.9930 us/op 4.24
phase0 processRegistryUpdates - 250000 badcase_full_deposits 522.41 us/op 430.96 us/op 1.21
phase0 processRegistryUpdates - 250000 worstcase 0.5 229.19 ms/op 210.38 ms/op 1.09
altair processRewardsAndPenalties - 250000 normalcase 149.33 ms/op 89.406 ms/op 1.67
altair processRewardsAndPenalties - 250000 worstcase 91.695 ms/op 137.33 ms/op 0.67
phase0 getAttestationDeltas - 250000 normalcase 13.865 ms/op 13.312 ms/op 1.04
phase0 getAttestationDeltas - 250000 worstcase 14.540 ms/op 13.391 ms/op 1.09
phase0 processSlashings - 250000 worstcase 6.1259 ms/op 5.4168 ms/op 1.13
altair processSyncCommitteeUpdates - 250000 315.41 ms/op 284.61 ms/op 1.11
BeaconState.hashTreeRoot - No change 631.00 ns/op 479.00 ns/op 1.32
BeaconState.hashTreeRoot - 1 full validator 84.133 us/op 62.647 us/op 1.34
BeaconState.hashTreeRoot - 32 full validator 844.67 us/op 638.43 us/op 1.32
BeaconState.hashTreeRoot - 512 full validator 8.3713 ms/op 6.1450 ms/op 1.36
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 121.39 us/op 80.676 us/op 1.50
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 1.4915 ms/op 1.2221 ms/op 1.22
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 19.121 ms/op 16.151 ms/op 1.18
BeaconState.hashTreeRoot - 1 balances 75.476 us/op 61.997 us/op 1.22
BeaconState.hashTreeRoot - 32 balances 723.43 us/op 639.00 us/op 1.13
BeaconState.hashTreeRoot - 512 balances 6.9538 ms/op 5.8874 ms/op 1.18
BeaconState.hashTreeRoot - 250000 balances 110.66 ms/op 86.385 ms/op 1.28
aggregationBits - 2048 els - zipIndexesInBitList 35.677 us/op 35.545 us/op 1.00
regular array get 100000 times 58.188 us/op 67.416 us/op 0.86
wrappedArray get 100000 times 56.625 us/op 67.394 us/op 0.84
arrayWithProxy get 100000 times 33.344 ms/op 28.949 ms/op 1.15
ssz.Root.equals 605.00 ns/op 547.00 ns/op 1.11
byteArrayEquals 575.00 ns/op 521.00 ns/op 1.10
shuffle list - 16384 els 11.555 ms/op 12.309 ms/op 0.94
shuffle list - 250000 els 170.69 ms/op 162.39 ms/op 1.05
processSlot - 1 slots 16.991 us/op 11.714 us/op 1.45
processSlot - 32 slots 2.3809 ms/op 1.6978 ms/op 1.40
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 565.07 us/op 397.99 us/op 1.42
getCommitteeAssignments - req 1 vs - 250000 vc 5.4424 ms/op 5.2708 ms/op 1.03
getCommitteeAssignments - req 100 vs - 250000 vc 7.6091 ms/op 7.3272 ms/op 1.04
getCommitteeAssignments - req 1000 vs - 250000 vc 8.3609 ms/op 7.7663 ms/op 1.08
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 10.010 ns/op 9.7000 ns/op 1.03
state getBlockRootAtSlot - 250000 vs - 7PWei 1.2510 us/op 1.1563 us/op 1.08
computeProposers - vc 250000 20.436 ms/op 16.550 ms/op 1.23
computeEpochShuffling - vc 250000 173.65 ms/op 166.23 ms/op 1.04
getNextSyncCommittee - vc 250000 322.19 ms/op 275.45 ms/op 1.17

by benchmarkbot/action


// Special case close to genesis block, return the genesis block root
if (beforeSlot <= 0) {
const genesisBlock = this.protoArray.nodes[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

If that's the usage may be we make the getNodeFromIndex function public and then use it here.

Copy link
Contributor Author

@dapplion dapplion Sep 16, 2022

Choose a reason for hiding this comment

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

Yes, but getNodeFromIndex would throw PROTO_ARRAY_ERROR_INVALID_NODE_INDEX, while this implementation would throw Genesis block not available, which would be much easier to debug if a user reports. Would prefer to stick to this one-line re-implementation, as it's quite peculiar use of the nodes array

@wemeetagain
Copy link
Member

dependant -> dependent

nazarhussain
nazarhussain previously approved these changes Sep 16, 2022
@nazarhussain
Copy link
Contributor

@wemeetagain @dapplion Interesting information. Seems both are valid spellings.

image

@dapplion dapplion merged commit 342e231 into unstable Sep 16, 2022
@dapplion dapplion deleted the dapplion/getDependantRoot-2 branch September 16, 2022 14:23
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