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

Implement standard keymanager API - review #3880

Merged
merged 10 commits into from
Apr 12, 2022
Merged

Conversation

dapplion
Copy link
Contributor

@dapplion dapplion commented Apr 3, 2022

Motivation

Post-merge review of #3522

Description

Fixes some potential issues:

@dapplion dapplion changed the title Dapplion/keymanager review Implement standard keymanager API - review Apr 3, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Apr 3, 2022

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: 4de0f07 Previous: 60fc678 Ratio
BeaconState.hashTreeRoot - No change 526.00 ns/op 509.00 ns/op 1.03
BeaconState.hashTreeRoot - 1 full validator 56.391 us/op 67.360 us/op 0.84
BeaconState.hashTreeRoot - 32 full validator 543.63 us/op 658.30 us/op 0.83
BeaconState.hashTreeRoot - 512 full validator 6.0301 ms/op 7.2378 ms/op 0.83
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 69.431 us/op 81.784 us/op 0.85
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 947.49 us/op 1.1394 ms/op 0.83
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 12.760 ms/op 15.740 ms/op 0.81
BeaconState.hashTreeRoot - 1 balances 52.980 us/op 64.099 us/op 0.83
BeaconState.hashTreeRoot - 32 balances 475.30 us/op 557.80 us/op 0.85
BeaconState.hashTreeRoot - 512 balances 4.5727 ms/op 5.4068 ms/op 0.85
BeaconState.hashTreeRoot - 250000 balances 96.325 ms/op 117.57 ms/op 0.82
processSlot - 1 slots 9.3740 us/op 11.859 us/op 0.79
processSlot - 32 slots 1.5587 ms/op 1.8648 ms/op 0.84
getCommitteeAssignments - req 1 vs - 250000 vc 5.2265 ms/op 6.2461 ms/op 0.84
getCommitteeAssignments - req 100 vs - 250000 vc 7.2494 ms/op 8.6855 ms/op 0.83
getCommitteeAssignments - req 1000 vs - 250000 vc 7.7086 ms/op 9.2608 ms/op 0.83
computeProposers - vc 250000 16.223 ms/op 19.442 ms/op 0.83
computeEpochShuffling - vc 250000 158.82 ms/op 188.24 ms/op 0.84
getNextSyncCommittee - vc 250000 267.19 ms/op 321.14 ms/op 0.83
altair processAttestation - 250000 vs - 7PWei normalcase 3.4789 ms/op 4.6725 ms/op 0.74
altair processAttestation - 250000 vs - 7PWei worstcase 5.1652 ms/op 6.7660 ms/op 0.76
altair processAttestation - setStatus - 1/6 committees join 184.42 us/op 225.84 us/op 0.82
altair processAttestation - setStatus - 1/3 committees join 360.38 us/op 430.19 us/op 0.84
altair processAttestation - setStatus - 1/2 committees join 506.01 us/op 607.75 us/op 0.83
altair processAttestation - setStatus - 2/3 committees join 653.85 us/op 795.83 us/op 0.82
altair processAttestation - setStatus - 4/5 committees join 886.35 us/op 1.0818 ms/op 0.82
altair processAttestation - setStatus - 100% committees join 1.0610 ms/op 1.2911 ms/op 0.82
altair processBlock - 250000 vs - 7PWei normalcase 22.415 ms/op 30.127 ms/op 0.74
altair processBlock - 250000 vs - 7PWei normalcase hashState 33.734 ms/op 37.814 ms/op 0.89
altair processBlock - 250000 vs - 7PWei worstcase 73.608 ms/op 83.674 ms/op 0.88
altair processBlock - 250000 vs - 7PWei worstcase hashState 92.125 ms/op 123.98 ms/op 0.74
altair processEth1Data - 250000 vs - 7PWei normalcase 757.25 us/op 893.11 us/op 0.85
altair processEpoch - mainnet_e81889 466.91 ms/op 563.98 ms/op 0.83
mainnet_e81889 - altair beforeProcessEpoch 136.16 ms/op 170.47 ms/op 0.80
mainnet_e81889 - altair processJustificationAndFinalization 30.570 us/op 44.103 us/op 0.69
mainnet_e81889 - altair processInactivityUpdates 10.017 ms/op 11.461 ms/op 0.87
mainnet_e81889 - altair processRewardsAndPenalties 126.18 ms/op 142.29 ms/op 0.89
mainnet_e81889 - altair processRegistryUpdates 3.7320 us/op 8.8040 us/op 0.42
mainnet_e81889 - altair processSlashings 1.2850 us/op 3.6160 us/op 0.36
mainnet_e81889 - altair processEth1DataReset 1.0310 us/op 3.5520 us/op 0.29
mainnet_e81889 - altair processEffectiveBalanceUpdates 6.7037 ms/op 7.9810 ms/op 0.84
mainnet_e81889 - altair processSlashingsReset 7.7700 us/op 13.347 us/op 0.58
mainnet_e81889 - altair processRandaoMixesReset 8.3670 us/op 16.001 us/op 0.52
mainnet_e81889 - altair processHistoricalRootsUpdate 2.1500 us/op 5.8140 us/op 0.37
mainnet_e81889 - altair processParticipationFlagUpdates 6.3190 us/op 9.5540 us/op 0.66
mainnet_e81889 - altair processSyncCommitteeUpdates 2.8880 us/op 3.6410 us/op 0.79
mainnet_e81889 - altair afterProcessEpoch 205.69 ms/op 214.66 ms/op 0.96
altair processInactivityUpdates - 250000 normalcase 32.952 ms/op 36.016 ms/op 0.91
altair processInactivityUpdates - 250000 worstcase 28.302 ms/op 30.971 ms/op 0.91
altair processParticipationFlagUpdates - 250000 anycase 5.1920 us/op 6.0390 us/op 0.86
altair processRewardsAndPenalties - 250000 normalcase 109.06 ms/op 134.38 ms/op 0.81
altair processRewardsAndPenalties - 250000 worstcase 74.521 ms/op 109.84 ms/op 0.68
altair processSyncCommitteeUpdates - 250000 277.40 ms/op 326.50 ms/op 0.85
Tree 40 250000 create 580.25 ms/op 701.84 ms/op 0.83
Tree 40 250000 get(125000) 275.44 ns/op 326.76 ns/op 0.84
Tree 40 250000 set(125000) 1.8654 us/op 2.2246 us/op 0.84
Tree 40 250000 toArray() 30.350 ms/op 34.185 ms/op 0.89
Tree 40 250000 iterate all - toArray() + loop 30.395 ms/op 36.044 ms/op 0.84
Tree 40 250000 iterate all - get(i) 107.78 ms/op 123.94 ms/op 0.87
MutableVector 250000 create 13.527 ms/op 16.399 ms/op 0.82
MutableVector 250000 get(125000) 13.103 ns/op 17.351 ns/op 0.76
MutableVector 250000 set(125000) 504.98 ns/op 592.66 ns/op 0.85
MutableVector 250000 toArray() 5.4644 ms/op 7.1506 ms/op 0.76
MutableVector 250000 iterate all - toArray() + loop 5.7323 ms/op 7.3403 ms/op 0.78
MutableVector 250000 iterate all - get(i) 3.2785 ms/op 3.7544 ms/op 0.87
Array 250000 create 4.7738 ms/op 6.2991 ms/op 0.76
Array 250000 clone - spread 2.1877 ms/op 2.7144 ms/op 0.81
Array 250000 get(125000) 1.0490 ns/op 1.3190 ns/op 0.80
Array 250000 set(125000) 1.0520 ns/op 1.2990 ns/op 0.81
Array 250000 iterate all - loop 139.72 us/op 197.33 us/op 0.71
effectiveBalanceIncrements clone Uint8Array 300000 59.603 us/op 84.765 us/op 0.70
effectiveBalanceIncrements clone MutableVector 300000 682.00 ns/op 608.00 ns/op 1.12
effectiveBalanceIncrements rw all Uint8Array 300000 301.75 us/op 339.87 us/op 0.89
effectiveBalanceIncrements rw all MutableVector 300000 163.68 ms/op 168.96 ms/op 0.97
aggregationBits - 2048 els - zipIndexesInBitList 24.921 us/op 26.625 us/op 0.94
regular array get 100000 times 56.058 us/op 76.627 us/op 0.73
wrappedArray get 100000 times 56.086 us/op 76.934 us/op 0.73
arrayWithProxy get 100000 times 28.761 ms/op 38.475 ms/op 0.75
ssz.Root.equals 445.00 ns/op 509.00 ns/op 0.87
byteArrayEquals 418.00 ns/op 499.00 ns/op 0.84
phase0 processBlock - 250000 vs - 7PWei normalcase 3.2267 ms/op 3.9811 ms/op 0.81
phase0 processBlock - 250000 vs - 7PWei worstcase 44.415 ms/op 53.116 ms/op 0.84
phase0 afterProcessEpoch - 250000 vs - 7PWei 174.20 ms/op 200.22 ms/op 0.87
phase0 beforeProcessEpoch - 250000 vs - 7PWei 67.816 ms/op 84.018 ms/op 0.81
phase0 processEpoch - mainnet_e58758 593.51 ms/op 602.80 ms/op 0.98
mainnet_e58758 - phase0 beforeProcessEpoch 188.90 ms/op 229.00 ms/op 0.82
mainnet_e58758 - phase0 processJustificationAndFinalization 43.336 us/op 38.926 us/op 1.11
mainnet_e58758 - phase0 processRewardsAndPenalties 125.26 ms/op 81.223 ms/op 1.54
mainnet_e58758 - phase0 processRegistryUpdates 21.055 us/op 18.445 us/op 1.14
mainnet_e58758 - phase0 processSlashings 2.4140 us/op 3.5160 us/op 0.69
mainnet_e58758 - phase0 processEth1DataReset 2.1460 us/op 3.0200 us/op 0.71
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 6.0193 ms/op 6.4672 ms/op 0.93
mainnet_e58758 - phase0 processSlashingsReset 8.0010 us/op 10.245 us/op 0.78
mainnet_e58758 - phase0 processRandaoMixesReset 12.977 us/op 13.600 us/op 0.95
mainnet_e58758 - phase0 processHistoricalRootsUpdate 2.0580 us/op 3.9890 us/op 0.52
mainnet_e58758 - phase0 processParticipationRecordUpdates 12.028 us/op 11.190 us/op 1.07
mainnet_e58758 - phase0 afterProcessEpoch 152.44 ms/op 179.17 ms/op 0.85
phase0 processEffectiveBalanceUpdates - 250000 normalcase 6.7793 ms/op 7.6619 ms/op 0.88
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 7.2256 ms/op 7.9935 ms/op 0.90
phase0 processRegistryUpdates - 250000 normalcase 18.301 us/op 15.825 us/op 1.16
phase0 processRegistryUpdates - 250000 badcase_full_deposits 519.56 us/op 607.28 us/op 0.86
phase0 processRegistryUpdates - 250000 worstcase 0.5 201.59 ms/op 241.47 ms/op 0.83
phase0 getAttestationDeltas - 250000 normalcase 14.083 ms/op 15.593 ms/op 0.90
phase0 getAttestationDeltas - 250000 worstcase 14.139 ms/op 16.047 ms/op 0.88
phase0 processSlashings - 250000 worstcase 6.5094 ms/op 6.5625 ms/op 0.99
shuffle list - 16384 els 10.657 ms/op 12.342 ms/op 0.86
shuffle list - 250000 els 153.24 ms/op 179.91 ms/op 0.85
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 383.44 us/op 422.82 us/op 0.91
pass gossip attestations to forkchoice per slot 3.8131 ms/op 4.0761 ms/op 0.94
computeDeltas 3.6391 ms/op 3.9865 ms/op 0.91
computeProposerBoostScoreFromBalances 502.62 us/op 585.99 us/op 0.86
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 1.8854 ms/op 1.9921 ms/op 0.95
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 71.822 us/op 89.673 us/op 0.80
BLS verify - blst-native 1.8553 ms/op 2.1312 ms/op 0.87
BLS verifyMultipleSignatures 3 - blst-native 3.7986 ms/op 4.5129 ms/op 0.84
BLS verifyMultipleSignatures 8 - blst-native 8.1790 ms/op 9.8259 ms/op 0.83
BLS verifyMultipleSignatures 32 - blst-native 29.658 ms/op 33.916 ms/op 0.87
BLS aggregatePubkeys 32 - blst-native 39.207 us/op 45.330 us/op 0.86
BLS aggregatePubkeys 128 - blst-native 153.91 us/op 175.13 us/op 0.88
getAttestationsForBlock 53.060 ms/op 65.293 ms/op 0.81
CheckpointStateCache - add get delete 10.002 us/op 12.139 us/op 0.82
validate gossip signedAggregateAndProof - struct 4.2575 ms/op 4.9216 ms/op 0.87
validate gossip attestation - struct 2.0260 ms/op 2.3334 ms/op 0.87
pickEth1Vote - no votes 2.2132 ms/op 2.5627 ms/op 0.86
pickEth1Vote - max votes 16.643 ms/op 20.773 ms/op 0.80
pickEth1Vote - Eth1Data hashTreeRoot value x2048 11.282 ms/op 13.443 ms/op 0.84
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 19.990 ms/op 23.036 ms/op 0.87
pickEth1Vote - Eth1Data fastSerialize value x2048 1.6525 ms/op 1.9750 ms/op 0.84
pickEth1Vote - Eth1Data fastSerialize tree x2048 11.492 ms/op 13.945 ms/op 0.82
bytes32 toHexString 896.00 ns/op 1.0680 us/op 0.84
bytes32 Buffer.toString(hex) 707.00 ns/op 780.00 ns/op 0.91
bytes32 Buffer.toString(hex) from Uint8Array 897.00 ns/op 1.0010 us/op 0.90
bytes32 Buffer.toString(hex) + 0x 712.00 ns/op 775.00 ns/op 0.92
Object access 1 prop 0.33700 ns/op 0.39400 ns/op 0.86
Map access 1 prop 0.30000 ns/op 0.35300 ns/op 0.85
Object get x1000 17.485 ns/op 20.206 ns/op 0.87
Map get x1000 0.94500 ns/op 1.1410 ns/op 0.83
Object set x1000 98.947 ns/op 120.56 ns/op 0.82
Map set x1000 59.098 ns/op 74.555 ns/op 0.79
Return object 10000 times 0.36780 ns/op 0.41800 ns/op 0.88
Throw Error 10000 times 5.9414 us/op 6.7602 us/op 0.88
enrSubnets - fastDeserialize 64 bits 903.00 ns/op 1.0500 us/op 0.86
enrSubnets - ssz BitVector 64 bits 586.00 ns/op 676.00 ns/op 0.87
enrSubnets - fastDeserialize 4 bits 380.00 ns/op 453.00 ns/op 0.84
enrSubnets - ssz BitVector 4 bits 573.00 ns/op 659.00 ns/op 0.87
RateTracker 1000000 limit, 1 obj count per request 175.22 ns/op 206.79 ns/op 0.85
RateTracker 1000000 limit, 2 obj count per request 128.05 ns/op 154.54 ns/op 0.83
RateTracker 1000000 limit, 4 obj count per request 106.80 ns/op 125.76 ns/op 0.85
RateTracker 1000000 limit, 8 obj count per request 94.881 ns/op 111.30 ns/op 0.85
RateTracker with prune 3.5600 us/op 4.2700 us/op 0.83
array of 16000 items push then shift 3.1356 us/op 3.5714 us/op 0.88
LinkedList of 16000 items push then shift 16.611 ns/op 18.431 ns/op 0.90
array of 16000 items push then pop 202.01 ns/op 226.87 ns/op 0.89
LinkedList of 16000 items push then pop 15.000 ns/op 18.684 ns/op 0.80
array of 24000 items push then shift 4.5481 us/op 5.2989 us/op 0.86
LinkedList of 24000 items push then shift 18.574 ns/op 21.114 ns/op 0.88
array of 24000 items push then pop 187.88 ns/op 217.62 ns/op 0.86
LinkedList of 24000 items push then pop 16.620 ns/op 19.924 ns/op 0.83

by benchmarkbot/action

@@ -80,7 +76,7 @@ export class KeymanagerApi implements Api {
message?: string;
}[];
}> {
const interchange = (slashingProtectionStr as unknown) as Interchange;
const interchange = JSON.parse(slashingProtectionStr) as Interchange;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dadepo do you know why JSON.parse() was not necessary if slashingProtectionStr is supposed to be a string?

Copy link
Contributor

@dadepo dadepo Apr 5, 2022

Choose a reason for hiding this comment

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

That's because the arguments to the function is passed in as an http body and fastify parses it already, so by the time our code calls finds the relevant handler here it is already an object hence no need to use JSON.parse within the function.

I also think the types safety of the function is weaker as it is decoupled from the calling logic in here so at runtime, it is an object that is passed in, which is then attempted to be parsed into JSON

My guess is that If it were a query path or params, then the parsing will be needed.

Copy link
Contributor Author

@dapplion dapplion Apr 5, 2022

Choose a reason for hiding this comment

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

So can you add a nice long comment explaining this above my change and do conditional parsing?

const interchange: Interchange = typeof slashingProtectionStr === "string" ? JSON.parse(slashingProtectionStr) : slashingProtectionStr;

Copy link
Contributor

Choose a reason for hiding this comment

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

I added a comment but I feel that the conditional parsing is not necessary since the endpoint is going to be called with the payload within the body of the request.

Also the snippet you shared won't work. What will work will require changing the type for slashingProtectionStr: SlashingProtectionData | Record<string, unknown> and then have the conditional parsing as follows:

    const interchange = typeof slashingProtectionStr === "string"
        ? (JSON.parse(slashingProtectionStr) as Interchange)
        : ((slashingProtectionStr as unknown) as Interchange);

Which I think is a bit too much since payload will always come within the body

@codecov
Copy link

codecov bot commented Apr 3, 2022

Codecov Report

Merging #3880 (2b65387) into master (43b4c17) will decrease coverage by 1.28%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #3880      +/-   ##
==========================================
- Coverage   36.25%   34.96%   -1.29%     
==========================================
  Files         328      328              
  Lines        9142    10683    +1541     
  Branches     1438     1790     +352     
==========================================
+ Hits         3314     3735     +421     
- Misses       5682     6795    +1113     
- Partials      146      153       +7     

@philknows philknows mentioned this pull request Apr 5, 2022
@dadepo dadepo self-assigned this Apr 5, 2022
@dapplion
Copy link
Contributor Author

dapplion commented Apr 5, 2022

@dadepo Please if you can fix the test I broken and approve if it looks good then 🙏

@dadepo dadepo dismissed a stale review via 2b65387 April 5, 2022 22:22
@dadepo
Copy link
Contributor

dadepo commented Apr 5, 2022

@dadepo Please if you can fix the test I broken and approve if it looks good then 🙏

Tests are now passing!

@dadepo dadepo marked this pull request as ready for review April 5, 2022 22:43
Copy link
Contributor Author

@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.

Meta-Approve ✔️ @dadepo it's my PR so you or someone else has to approve

@dapplion dapplion merged commit e74af11 into master Apr 12, 2022
@dapplion dapplion deleted the dapplion/keymanager-review branch April 12, 2022 10:34
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

5 participants