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

feat: download blocks as ssz #5923

Merged
merged 7 commits into from
Sep 11, 2023
Merged

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented Aug 31, 2023

Motivation

This is the spec, we need to support "Accept" header for getBlock apis https://ethereum.github.io/beacon-APIs/#/

Description

  • Handle "Accept" header similar to what getState does

@twoeths twoeths force-pushed the tuyen/download_blocks_as_ssz branch 2 times, most recently from 381c6dc to fbeb88a Compare August 31, 2023 11:00
@github-actions
Copy link
Contributor

github-actions bot commented Aug 31, 2023

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: 595ceda Previous: d51ee94 Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 766.37 us/op 989.95 us/op 0.77
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 76.765 us/op 99.049 us/op 0.78
BLS verify - blst-native 1.2966 ms/op 1.3403 ms/op 0.97
BLS verifyMultipleSignatures 3 - blst-native 2.7171 ms/op 2.8101 ms/op 0.97
BLS verifyMultipleSignatures 8 - blst-native 5.9622 ms/op 6.3816 ms/op 0.93
BLS verifyMultipleSignatures 32 - blst-native 21.790 ms/op 22.790 ms/op 0.96
BLS verifyMultipleSignatures 64 - blst-native 42.978 ms/op 44.655 ms/op 0.96
BLS verifyMultipleSignatures 128 - blst-native 85.236 ms/op 90.877 ms/op 0.94
BLS deserializing 10000 signatures 888.69 ms/op 915.27 ms/op 0.97
BLS deserializing 100000 signatures 8.8128 s/op 9.0618 s/op 0.97
BLS verifyMultipleSignatures - same message - 3 - blst-native 1.2734 ms/op 1.3601 ms/op 0.94
BLS verifyMultipleSignatures - same message - 8 - blst-native 1.4252 ms/op 1.5152 ms/op 0.94
BLS verifyMultipleSignatures - same message - 32 - blst-native 2.1928 ms/op 2.3320 ms/op 0.94
BLS verifyMultipleSignatures - same message - 64 - blst-native 3.7488 ms/op 3.8011 ms/op 0.99
BLS verifyMultipleSignatures - same message - 128 - blst-native 5.4979 ms/op 6.4160 ms/op 0.86
BLS aggregatePubkeys 32 - blst-native 25.091 us/op 26.075 us/op 0.96
BLS aggregatePubkeys 128 - blst-native 98.311 us/op 99.855 us/op 0.98
getAttestationsForBlock 35.458 ms/op 34.173 ms/op 1.04
isKnown best case - 1 super set check 280.00 ns/op 267.00 ns/op 1.05
isKnown normal case - 2 super set checks 259.00 ns/op 267.00 ns/op 0.97
isKnown worse case - 16 super set checks 275.00 ns/op 268.00 ns/op 1.03
CheckpointStateCache - add get delete 4.8350 us/op 4.9110 us/op 0.98
validate api signedAggregateAndProof - struct 2.7495 ms/op 2.6347 ms/op 1.04
validate gossip signedAggregateAndProof - struct 2.7576 ms/op 2.6576 ms/op 1.04
validate gossip attestation - vc 640000 1.3244 ms/op 1.2981 ms/op 1.02
batch validate gossip attestation - vc 640000 - chunk 32 146.48 us/op 143.89 us/op 1.02
batch validate gossip attestation - vc 640000 - chunk 64 127.34 us/op 123.25 us/op 1.03
batch validate gossip attestation - vc 640000 - chunk 128 117.46 us/op 114.00 us/op 1.03
batch validate gossip attestation - vc 640000 - chunk 256 112.16 us/op 112.97 us/op 0.99
pickEth1Vote - no votes 1.1699 ms/op 1.1343 ms/op 1.03
pickEth1Vote - max votes 9.3904 ms/op 9.9728 ms/op 0.94
pickEth1Vote - Eth1Data hashTreeRoot value x2048 8.6050 ms/op 8.7616 ms/op 0.98
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 12.836 ms/op 15.427 ms/op 0.83
pickEth1Vote - Eth1Data fastSerialize value x2048 551.77 us/op 581.54 us/op 0.95
pickEth1Vote - Eth1Data fastSerialize tree x2048 6.2965 ms/op 4.1979 ms/op 1.50
bytes32 toHexString 448.00 ns/op 465.00 ns/op 0.96
bytes32 Buffer.toString(hex) 269.00 ns/op 283.00 ns/op 0.95
bytes32 Buffer.toString(hex) from Uint8Array 407.00 ns/op 437.00 ns/op 0.93
bytes32 Buffer.toString(hex) + 0x 273.00 ns/op 288.00 ns/op 0.95
Object access 1 prop 0.14800 ns/op 0.15900 ns/op 0.93
Map access 1 prop 0.14300 ns/op 0.14000 ns/op 1.02
Object get x1000 6.9470 ns/op 7.5740 ns/op 0.92
Map get x1000 0.58700 ns/op 0.59000 ns/op 0.99
Object set x1000 46.142 ns/op 48.165 ns/op 0.96
Map set x1000 37.178 ns/op 38.493 ns/op 0.97
Return object 10000 times 0.23540 ns/op 0.24170 ns/op 0.97
Throw Error 10000 times 3.6843 us/op 3.8557 us/op 0.96
fastMsgIdFn sha256 / 200 bytes 3.1710 us/op 3.3080 us/op 0.96
fastMsgIdFn h32 xxhash / 200 bytes 263.00 ns/op 304.00 ns/op 0.87
fastMsgIdFn h64 xxhash / 200 bytes 323.00 ns/op 348.00 ns/op 0.93
fastMsgIdFn sha256 / 1000 bytes 11.110 us/op 11.366 us/op 0.98
fastMsgIdFn h32 xxhash / 1000 bytes 392.00 ns/op 454.00 ns/op 0.86
fastMsgIdFn h64 xxhash / 1000 bytes 407.00 ns/op 426.00 ns/op 0.96
fastMsgIdFn sha256 / 10000 bytes 102.16 us/op 101.89 us/op 1.00
fastMsgIdFn h32 xxhash / 10000 bytes 1.8460 us/op 1.9550 us/op 0.94
fastMsgIdFn h64 xxhash / 10000 bytes 1.2660 us/op 1.3040 us/op 0.97
enrSubnets - fastDeserialize 64 bits 1.1610 us/op 1.1840 us/op 0.98
enrSubnets - ssz BitVector 64 bits 412.00 ns/op 412.00 ns/op 1.00
enrSubnets - fastDeserialize 4 bits 157.00 ns/op 157.00 ns/op 1.00
enrSubnets - ssz BitVector 4 bits 404.00 ns/op 410.00 ns/op 0.99
prioritizePeers score -10:0 att 32-0.1 sync 2-0 96.356 us/op 99.464 us/op 0.97
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 121.07 us/op 127.62 us/op 0.95
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 153.91 us/op 157.16 us/op 0.98
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 278.65 us/op 282.59 us/op 0.99
prioritizePeers score 0:0 att 64-1 sync 4-1 329.67 us/op 327.68 us/op 1.01
array of 16000 items push then shift 1.5783 us/op 1.6375 us/op 0.96
LinkedList of 16000 items push then shift 9.1570 ns/op 8.9530 ns/op 1.02
array of 16000 items push then pop 72.876 ns/op 89.209 ns/op 0.82
LinkedList of 16000 items push then pop 8.6560 ns/op 8.9150 ns/op 0.97
array of 24000 items push then shift 2.3486 us/op 2.4434 us/op 0.96
LinkedList of 24000 items push then shift 8.8790 ns/op 9.0880 ns/op 0.98
array of 24000 items push then pop 99.454 ns/op 108.72 ns/op 0.91
LinkedList of 24000 items push then pop 8.5790 ns/op 8.6450 ns/op 0.99
intersect bitArray bitLen 8 6.7140 ns/op 6.8270 ns/op 0.98
intersect array and set length 8 53.641 ns/op 55.384 ns/op 0.97
intersect bitArray bitLen 128 31.371 ns/op 31.934 ns/op 0.98
intersect array and set length 128 735.75 ns/op 760.04 ns/op 0.97
bitArray.getTrueBitIndexes() bitLen 128 1.4950 us/op 1.5290 us/op 0.98
bitArray.getTrueBitIndexes() bitLen 248 2.4090 us/op 2.4960 us/op 0.97
bitArray.getTrueBitIndexes() bitLen 512 4.6550 us/op 5.0720 us/op 0.92
Buffer.concat 32 items 973.00 ns/op 983.00 ns/op 0.99
Uint8Array.set 32 items 2.6500 us/op 1.8830 us/op 1.41
Set add up to 64 items then delete first 4.1675 us/op 4.6642 us/op 0.89
OrderedSet add up to 64 items then delete first 5.2462 us/op 5.5821 us/op 0.94
Set add up to 64 items then delete last 4.5125 us/op 5.0399 us/op 0.90
OrderedSet add up to 64 items then delete last 5.5567 us/op 5.9604 us/op 0.93
Set add up to 64 items then delete middle 4.4942 us/op 4.6665 us/op 0.96
OrderedSet add up to 64 items then delete middle 7.0050 us/op 7.3428 us/op 0.95
Set add up to 128 items then delete first 9.1524 us/op 9.8546 us/op 0.93
OrderedSet add up to 128 items then delete first 11.954 us/op 12.584 us/op 0.95
Set add up to 128 items then delete last 8.9759 us/op 9.5131 us/op 0.94
OrderedSet add up to 128 items then delete last 11.240 us/op 11.881 us/op 0.95
Set add up to 128 items then delete middle 8.7961 us/op 9.6559 us/op 0.91
OrderedSet add up to 128 items then delete middle 16.529 us/op 17.798 us/op 0.93
Set add up to 256 items then delete first 18.363 us/op 19.654 us/op 0.93
OrderedSet add up to 256 items then delete first 24.313 us/op 25.480 us/op 0.95
Set add up to 256 items then delete last 17.594 us/op 19.445 us/op 0.90
OrderedSet add up to 256 items then delete last 22.745 us/op 24.046 us/op 0.95
Set add up to 256 items then delete middle 17.592 us/op 19.186 us/op 0.92
OrderedSet add up to 256 items then delete middle 44.170 us/op 45.806 us/op 0.96
transfer serialized Status (84 B) 1.8620 us/op 1.9010 us/op 0.98
copy serialized Status (84 B) 1.5520 us/op 1.6600 us/op 0.93
transfer serialized SignedVoluntaryExit (112 B) 2.0980 us/op 2.1250 us/op 0.99
copy serialized SignedVoluntaryExit (112 B) 1.6950 us/op 1.7570 us/op 0.96
transfer serialized ProposerSlashing (416 B) 3.1480 us/op 3.0670 us/op 1.03
copy serialized ProposerSlashing (416 B) 2.9330 us/op 2.6860 us/op 1.09
transfer serialized Attestation (485 B) 3.0460 us/op 2.5640 us/op 1.19
copy serialized Attestation (485 B) 2.4550 us/op 2.1370 us/op 1.15
transfer serialized AttesterSlashing (33232 B) 2.8200 us/op 2.2940 us/op 1.23
copy serialized AttesterSlashing (33232 B) 5.3910 us/op 6.1610 us/op 0.88
transfer serialized Small SignedBeaconBlock (128000 B) 2.8750 us/op 2.8870 us/op 1.00
copy serialized Small SignedBeaconBlock (128000 B) 13.430 us/op 13.625 us/op 0.99
transfer serialized Avg SignedBeaconBlock (200000 B) 3.3140 us/op 3.1480 us/op 1.05
copy serialized Avg SignedBeaconBlock (200000 B) 18.319 us/op 20.419 us/op 0.90
transfer serialized BlobsSidecar (524380 B) 2.9020 us/op 3.1730 us/op 0.91
copy serialized BlobsSidecar (524380 B) 68.760 us/op 79.050 us/op 0.87
transfer serialized Big SignedBeaconBlock (1000000 B) 2.9430 us/op 3.0230 us/op 0.97
copy serialized Big SignedBeaconBlock (1000000 B) 160.76 us/op 161.25 us/op 1.00
pass gossip attestations to forkchoice per slot 3.6448 ms/op 3.6629 ms/op 1.00
forkChoice updateHead vc 100000 bc 64 eq 0 663.19 us/op 667.39 us/op 0.99
forkChoice updateHead vc 600000 bc 64 eq 0 4.7722 ms/op 4.2037 ms/op 1.14
forkChoice updateHead vc 1000000 bc 64 eq 0 7.1237 ms/op 7.2906 ms/op 0.98
forkChoice updateHead vc 600000 bc 320 eq 0 4.1285 ms/op 4.1531 ms/op 0.99
forkChoice updateHead vc 600000 bc 1200 eq 0 4.1384 ms/op 4.2444 ms/op 0.98
forkChoice updateHead vc 600000 bc 7200 eq 0 5.0038 ms/op 5.2219 ms/op 0.96
forkChoice updateHead vc 600000 bc 64 eq 1000 11.010 ms/op 11.416 ms/op 0.96
forkChoice updateHead vc 600000 bc 64 eq 10000 11.750 ms/op 12.104 ms/op 0.97
forkChoice updateHead vc 600000 bc 64 eq 300000 15.751 ms/op 16.095 ms/op 0.98
computeDeltas 500000 validators 300 proto nodes 6.2426 ms/op 6.2620 ms/op 1.00
computeDeltas 500000 validators 1200 proto nodes 6.1321 ms/op 6.1801 ms/op 0.99
computeDeltas 500000 validators 7200 proto nodes 6.1792 ms/op 6.1750 ms/op 1.00
computeDeltas 750000 validators 300 proto nodes 9.2209 ms/op 9.2956 ms/op 0.99
computeDeltas 750000 validators 1200 proto nodes 9.2686 ms/op 9.3243 ms/op 0.99
computeDeltas 750000 validators 7200 proto nodes 9.2641 ms/op 9.3666 ms/op 0.99
computeDeltas 1400000 validators 300 proto nodes 17.146 ms/op 17.714 ms/op 0.97
computeDeltas 1400000 validators 1200 proto nodes 17.334 ms/op 17.848 ms/op 0.97
computeDeltas 1400000 validators 7200 proto nodes 17.364 ms/op 18.440 ms/op 0.94
computeDeltas 2100000 validators 300 proto nodes 26.176 ms/op 26.702 ms/op 0.98
computeDeltas 2100000 validators 1200 proto nodes 26.192 ms/op 26.983 ms/op 0.97
computeDeltas 2100000 validators 7200 proto nodes 26.016 ms/op 27.433 ms/op 0.95
computeProposerBoostScoreFromBalances 500000 validators 3.1943 ms/op 3.4012 ms/op 0.94
computeProposerBoostScoreFromBalances 750000 validators 3.2005 ms/op 3.3007 ms/op 0.97
computeProposerBoostScoreFromBalances 1400000 validators 3.1912 ms/op 3.2428 ms/op 0.98
computeProposerBoostScoreFromBalances 2100000 validators 3.1878 ms/op 3.2122 ms/op 0.99
altair processAttestation - 250000 vs - 7PWei normalcase 2.2817 ms/op 2.3164 ms/op 0.99
altair processAttestation - 250000 vs - 7PWei worstcase 3.2108 ms/op 3.2420 ms/op 0.99
altair processAttestation - setStatus - 1/6 committees join 175.23 us/op 181.53 us/op 0.97
altair processAttestation - setStatus - 1/3 committees join 339.14 us/op 347.12 us/op 0.98
altair processAttestation - setStatus - 1/2 committees join 462.44 us/op 465.05 us/op 0.99
altair processAttestation - setStatus - 2/3 committees join 582.35 us/op 592.72 us/op 0.98
altair processAttestation - setStatus - 4/5 committees join 797.00 us/op 794.05 us/op 1.00
altair processAttestation - setStatus - 100% committees join 945.95 us/op 955.21 us/op 0.99
altair processBlock - 250000 vs - 7PWei normalcase 9.4434 ms/op 9.1252 ms/op 1.03
altair processBlock - 250000 vs - 7PWei normalcase hashState 17.406 ms/op 17.396 ms/op 1.00
altair processBlock - 250000 vs - 7PWei worstcase 37.479 ms/op 39.131 ms/op 0.96
altair processBlock - 250000 vs - 7PWei worstcase hashState 59.068 ms/op 59.609 ms/op 0.99
phase0 processBlock - 250000 vs - 7PWei normalcase 2.3638 ms/op 2.8829 ms/op 0.82
phase0 processBlock - 250000 vs - 7PWei worstcase 29.812 ms/op 29.315 ms/op 1.02
altair processEth1Data - 250000 vs - 7PWei normalcase 457.63 us/op 610.90 us/op 0.75
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 9.4430 us/op 10.173 us/op 0.93
getExpectedWithdrawals 250000 eb:0.95,eth1:0.1,we:0.05,wn:0,smpl:219 86.389 us/op 71.276 us/op 1.21
getExpectedWithdrawals 250000 eb:0.95,eth1:0.3,we:0.05,wn:0,smpl:42 15.794 us/op 19.316 us/op 0.82
getExpectedWithdrawals 250000 eb:0.95,eth1:0.7,we:0.05,wn:0,smpl:18 9.7530 us/op 14.557 us/op 0.67
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 156.15 us/op 154.14 us/op 1.01
getExpectedWithdrawals 250000 eb:0.03,eth1:0.03,we:0,wn:0,smpl:11777 1.3337 ms/op 1.3824 ms/op 0.96
getExpectedWithdrawals 250000 eb:0.01,eth1:0.01,we:0,wn:0,smpl:16384 1.5582 ms/op 1.6765 ms/op 0.93
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,smpl:16384 1.4865 ms/op 1.7787 ms/op 0.84
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,nocache,smpl:16384 3.2423 ms/op 3.3238 ms/op 0.98
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,smpl:16384 2.4226 ms/op 2.3987 ms/op 1.01
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,nocache,smpl:16384 5.1456 ms/op 4.4988 ms/op 1.14
Tree 40 250000 create 307.99 ms/op 316.14 ms/op 0.97
Tree 40 250000 get(125000) 193.84 ns/op 198.44 ns/op 0.98
Tree 40 250000 set(125000) 887.91 ns/op 922.57 ns/op 0.96
Tree 40 250000 toArray() 17.669 ms/op 18.733 ms/op 0.94
Tree 40 250000 iterate all - toArray() + loop 17.277 ms/op 18.764 ms/op 0.92
Tree 40 250000 iterate all - get(i) 63.706 ms/op 67.587 ms/op 0.94
MutableVector 250000 create 9.8825 ms/op 9.6366 ms/op 1.03
MutableVector 250000 get(125000) 6.5050 ns/op 6.4840 ns/op 1.00
MutableVector 250000 set(125000) 259.07 ns/op 260.76 ns/op 0.99
MutableVector 250000 toArray() 3.0031 ms/op 3.2982 ms/op 0.91
MutableVector 250000 iterate all - toArray() + loop 3.0988 ms/op 3.3726 ms/op 0.92
MutableVector 250000 iterate all - get(i) 1.5097 ms/op 1.5069 ms/op 1.00
Array 250000 create 2.9992 ms/op 3.0693 ms/op 0.98
Array 250000 clone - spread 992.54 us/op 1.3167 ms/op 0.75
Array 250000 get(125000) 0.48300 ns/op 0.61700 ns/op 0.78
Array 250000 set(125000) 0.55600 ns/op 0.70600 ns/op 0.79
Array 250000 iterate all - loop 81.823 us/op 83.088 us/op 0.98
effectiveBalanceIncrements clone Uint8Array 300000 23.036 us/op 31.857 us/op 0.72
effectiveBalanceIncrements clone MutableVector 300000 256.00 ns/op 393.00 ns/op 0.65
effectiveBalanceIncrements rw all Uint8Array 300000 167.11 us/op 182.41 us/op 0.92
effectiveBalanceIncrements rw all MutableVector 300000 73.900 ms/op 85.195 ms/op 0.87
phase0 afterProcessEpoch - 250000 vs - 7PWei 113.02 ms/op 119.98 ms/op 0.94
phase0 beforeProcessEpoch - 250000 vs - 7PWei 38.217 ms/op 33.629 ms/op 1.14
altair processEpoch - mainnet_e81889 316.33 ms/op 325.35 ms/op 0.97
mainnet_e81889 - altair beforeProcessEpoch 60.576 ms/op 63.630 ms/op 0.95
mainnet_e81889 - altair processJustificationAndFinalization 14.234 us/op 16.659 us/op 0.85
mainnet_e81889 - altair processInactivityUpdates 5.8460 ms/op 7.2124 ms/op 0.81
mainnet_e81889 - altair processRewardsAndPenalties 49.673 ms/op 63.494 ms/op 0.78
mainnet_e81889 - altair processRegistryUpdates 2.5760 us/op 2.5010 us/op 1.03
mainnet_e81889 - altair processSlashings 437.00 ns/op 407.00 ns/op 1.07
mainnet_e81889 - altair processEth1DataReset 516.00 ns/op 770.00 ns/op 0.67
mainnet_e81889 - altair processEffectiveBalanceUpdates 1.2370 ms/op 1.2815 ms/op 0.97
mainnet_e81889 - altair processSlashingsReset 3.1730 us/op 5.1190 us/op 0.62
mainnet_e81889 - altair processRandaoMixesReset 6.1010 us/op 6.2880 us/op 0.97
mainnet_e81889 - altair processHistoricalRootsUpdate 1.0930 us/op 782.00 ns/op 1.40
mainnet_e81889 - altair processParticipationFlagUpdates 1.5440 us/op 2.6680 us/op 0.58
mainnet_e81889 - altair processSyncCommitteeUpdates 687.00 ns/op 542.00 ns/op 1.27
mainnet_e81889 - altair afterProcessEpoch 124.11 ms/op 134.27 ms/op 0.92
capella processEpoch - mainnet_e217614 1.0061 s/op 1.0225 s/op 0.98
mainnet_e217614 - capella beforeProcessEpoch 236.12 ms/op 245.97 ms/op 0.96
mainnet_e217614 - capella processJustificationAndFinalization 12.600 us/op 16.338 us/op 0.77
mainnet_e217614 - capella processInactivityUpdates 17.406 ms/op 15.230 ms/op 1.14
mainnet_e217614 - capella processRewardsAndPenalties 282.54 ms/op 288.79 ms/op 0.98
mainnet_e217614 - capella processRegistryUpdates 17.820 us/op 19.449 us/op 0.92
mainnet_e217614 - capella processSlashings 540.00 ns/op 592.00 ns/op 0.91
mainnet_e217614 - capella processEth1DataReset 447.00 ns/op 1.0020 us/op 0.45
mainnet_e217614 - capella processEffectiveBalanceUpdates 4.1502 ms/op 4.1389 ms/op 1.00
mainnet_e217614 - capella processSlashingsReset 2.4220 us/op 3.0660 us/op 0.79
mainnet_e217614 - capella processRandaoMixesReset 3.8210 us/op 6.3260 us/op 0.60
mainnet_e217614 - capella processHistoricalRootsUpdate 593.00 ns/op 920.00 ns/op 0.64
mainnet_e217614 - capella processParticipationFlagUpdates 1.4880 us/op 3.9550 us/op 0.38
mainnet_e217614 - capella afterProcessEpoch 301.80 ms/op 333.58 ms/op 0.90
phase0 processEpoch - mainnet_e58758 333.14 ms/op 339.73 ms/op 0.98
mainnet_e58758 - phase0 beforeProcessEpoch 104.03 ms/op 129.73 ms/op 0.80
mainnet_e58758 - phase0 processJustificationAndFinalization 15.319 us/op 19.192 us/op 0.80
mainnet_e58758 - phase0 processRewardsAndPenalties 57.093 ms/op 62.250 ms/op 0.92
mainnet_e58758 - phase0 processRegistryUpdates 9.1940 us/op 14.775 us/op 0.62
mainnet_e58758 - phase0 processSlashings 528.00 ns/op 1.0360 us/op 0.51
mainnet_e58758 - phase0 processEth1DataReset 443.00 ns/op 913.00 ns/op 0.49
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 1.0417 ms/op 1.6961 ms/op 0.61
mainnet_e58758 - phase0 processSlashingsReset 2.2650 us/op 7.4710 us/op 0.30
mainnet_e58758 - phase0 processRandaoMixesReset 4.0160 us/op 8.1550 us/op 0.49
mainnet_e58758 - phase0 processHistoricalRootsUpdate 480.00 ns/op 1.0630 us/op 0.45
mainnet_e58758 - phase0 processParticipationRecordUpdates 3.6010 us/op 5.3010 us/op 0.68
mainnet_e58758 - phase0 afterProcessEpoch 101.06 ms/op 127.05 ms/op 0.80
phase0 processEffectiveBalanceUpdates - 250000 normalcase 1.9410 ms/op 1.2688 ms/op 1.53
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.4487 ms/op 2.2951 ms/op 0.63
altair processInactivityUpdates - 250000 normalcase 17.363 ms/op 33.402 ms/op 0.52
altair processInactivityUpdates - 250000 worstcase 20.500 ms/op 26.332 ms/op 0.78
phase0 processRegistryUpdates - 250000 normalcase 15.640 us/op 17.367 us/op 0.90
phase0 processRegistryUpdates - 250000 badcase_full_deposits 352.49 us/op 462.80 us/op 0.76
phase0 processRegistryUpdates - 250000 worstcase 0.5 128.49 ms/op 164.76 ms/op 0.78
altair processRewardsAndPenalties - 250000 normalcase 42.405 ms/op 72.083 ms/op 0.59
altair processRewardsAndPenalties - 250000 worstcase 64.440 ms/op 76.870 ms/op 0.84
phase0 getAttestationDeltas - 250000 normalcase 7.6673 ms/op 8.9741 ms/op 0.85
phase0 getAttestationDeltas - 250000 worstcase 7.7763 ms/op 10.109 ms/op 0.77
phase0 processSlashings - 250000 worstcase 2.3845 ms/op 2.4687 ms/op 0.97
altair processSyncCommitteeUpdates - 250000 148.99 ms/op 161.83 ms/op 0.92
BeaconState.hashTreeRoot - No change 271.00 ns/op 273.00 ns/op 0.99
BeaconState.hashTreeRoot - 1 full validator 52.143 us/op 52.283 us/op 1.00
BeaconState.hashTreeRoot - 32 full validator 517.53 us/op 562.47 us/op 0.92
BeaconState.hashTreeRoot - 512 full validator 5.0242 ms/op 5.9252 ms/op 0.85
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 64.172 us/op 66.196 us/op 0.97
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 877.86 us/op 908.85 us/op 0.97
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 11.734 ms/op 13.964 ms/op 0.84
BeaconState.hashTreeRoot - 1 balances 49.710 us/op 51.310 us/op 0.97
BeaconState.hashTreeRoot - 32 balances 440.11 us/op 489.88 us/op 0.90
BeaconState.hashTreeRoot - 512 balances 4.2350 ms/op 4.7255 ms/op 0.90
BeaconState.hashTreeRoot - 250000 balances 71.559 ms/op 77.497 ms/op 0.92
aggregationBits - 2048 els - zipIndexesInBitList 16.660 us/op 21.199 us/op 0.79
regular array get 100000 times 42.344 us/op 35.899 us/op 1.18
wrappedArray get 100000 times 32.793 us/op 35.828 us/op 0.92
arrayWithProxy get 100000 times 14.402 ms/op 16.892 ms/op 0.85
ssz.Root.equals 213.00 ns/op 250.00 ns/op 0.85
byteArrayEquals 208.00 ns/op 259.00 ns/op 0.80
shuffle list - 16384 els 6.8480 ms/op 7.6988 ms/op 0.89
shuffle list - 250000 els 102.28 ms/op 108.24 ms/op 0.94
processSlot - 1 slots 8.6290 us/op 9.0960 us/op 0.95
processSlot - 32 slots 1.3874 ms/op 1.3801 ms/op 1.01
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 49.491 ms/op 60.158 ms/op 0.82
getCommitteeAssignments - req 1 vs - 250000 vc 2.5326 ms/op 2.9014 ms/op 0.87
getCommitteeAssignments - req 100 vs - 250000 vc 3.7203 ms/op 4.0022 ms/op 0.93
getCommitteeAssignments - req 1000 vs - 250000 vc 4.0438 ms/op 4.4276 ms/op 0.91
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 4.6900 ns/op 5.6800 ns/op 0.83
state getBlockRootAtSlot - 250000 vs - 7PWei 542.83 ns/op 947.41 ns/op 0.57
computeProposers - vc 250000 8.7242 ms/op 11.598 ms/op 0.75
computeEpochShuffling - vc 250000 105.80 ms/op 121.04 ms/op 0.87
getNextSyncCommittee - vc 250000 148.10 ms/op 171.60 ms/op 0.86
computeSigningRoot for AttestationData 13.252 us/op 15.997 us/op 0.83
hash AttestationData serialized data then Buffer.toString(base64) 2.3477 us/op 2.5587 us/op 0.92
toHexString serialized data 1.1702 us/op 1.4579 us/op 0.80
Buffer.toString(base64) 230.45 ns/op 254.29 ns/op 0.91

by benchmarkbot/action

matthewkeil
matthewkeil previously approved these changes Aug 31, 2023
Copy link
Member

@matthewkeil matthewkeil left a comment

Choose a reason for hiding this comment

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

Very nice!!! You rock. Noticed ssz wasnt available when I was pulling the some test blocks. You did a great job and made this look easy!! 🎉 🚀

@@ -30,11 +30,11 @@ export const testData: GenericServerTestCases<Api> = {
// block

getBlock: {
args: ["head"],
args: ["head", "json"],
Copy link
Member

Choose a reason for hiding this comment

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

Should we also check for ssz? Not sure if its needed. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these test data are keyed by api name so we can only test with either "json" or "ssz". This is "json" because by default we use it, and majority of consumers use "json" so I'd go with it to maintain the test case going forward

Copy link
Member

Choose a reason for hiding this comment

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

It doesn't look like we unit test the ssz format for state either. I will be happy to add a unit test case after this gets merged. Will be good practice for me. I haven't worked with the API code much

getState: {
args: ["head", "json"],
res: {executionOptimistic: true, data: ssz.phase0.BeaconState.defaultValue()},
},
getStateV2: {
args: ["head", "json"],
res: {executionOptimistic: true, data: ssz.altair.BeaconState.defaultValue(), version: ForkName.altair},
},

Copy link
Member

Choose a reason for hiding this comment

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

This test is just testing the shape/types of the input and output data, not any behavior. Since we added a param to the getBlock functions, we need to add a param here.

@twoeths twoeths marked this pull request as ready for review September 1, 2023 07:15
@twoeths twoeths requested a review from a team as a code owner September 1, 2023 07:15
Copy link
Member

@matthewkeil matthewkeil left a comment

Choose a reason for hiding this comment

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

Mostly just the question about sharing the types with the debug/state routes. Am approving because those are pretty small. Depending on how you feel you can update and Ill reapprove if you push code. Overall great work and a great example to follow in the future!!! 🚀 You are a 🥷

...client,
async getBlock<T extends ResponseFormat = "json">(blockId: BlockId, format?: T) {
if (format === "ssz") {
const res = await httpClient.arrayBuffer({
Copy link
Member

Choose a reason for hiding this comment

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

This is sweet. I didnt know our httpClient did so much under the hood. was looking at how its implemented.

@@ -31,6 +31,7 @@ import {
// See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes

export type BlockId = RootHex | Slot | "head" | "genesis" | "finalized";
export const mimeTypeSSZ = "application/octet-stream";
Copy link
Member

Choose a reason for hiding this comment

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

This already exists for state downloads. Do you think we should move this to a CONST and pull both from the same place?

export const mimeTypeSSZ = "application/octet-stream";

Comment on lines +55 to +74
export type BlockResponse<T extends ResponseFormat = "json"> = T extends "ssz"
? ApiClientResponse<{[HttpStatusCode.OK]: Uint8Array}, HttpStatusCode.BAD_REQUEST | HttpStatusCode.NOT_FOUND>
: ApiClientResponse<
{[HttpStatusCode.OK]: {data: allForks.SignedBeaconBlock}},
HttpStatusCode.BAD_REQUEST | HttpStatusCode.NOT_FOUND
>;

export type BlockV2Response<T extends ResponseFormat = "json"> = T extends "ssz"
? ApiClientResponse<{[HttpStatusCode.OK]: Uint8Array}, HttpStatusCode.BAD_REQUEST | HttpStatusCode.NOT_FOUND>
: ApiClientResponse<
{
[HttpStatusCode.OK]: {
data: allForks.SignedBeaconBlock;
executionOptimistic: ExecutionOptimistic;
version: ForkName;
};
},
HttpStatusCode.BAD_REQUEST | HttpStatusCode.NOT_FOUND
>;

Copy link
Member

Choose a reason for hiding this comment

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

Very nice TS work!!! 🚀 Is very helpful to see how you created these response types

@@ -246,11 +256,12 @@ export const routesData: RoutesData<Api> = {

/* eslint-disable @typescript-eslint/naming-convention */

type GetBlockReq = {params: {block_id: string}; headers: {accept?: string}};
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity why do we use the snake case for url params. Seems like a good pattern and I see that its the norm throughout the codebase. Just want to expand my understanding.

Copy link
Member

Choose a reason for hiding this comment

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

its part of the beacon api spec
https://github.com/ethereum/beacon-apis

They say: use this specific url path with these specific url query params, should return a response with these codes and these payloads

@@ -3,6 +3,7 @@ import {Resolves} from "./utils/types.js";

/* eslint-disable @typescript-eslint/no-explicit-any */

export type ResponseFormat = "json" | "ssz";
Copy link
Member

Choose a reason for hiding this comment

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

This type is also used by the debug state routes. Should we put this somewhere that both can pull from the same type?

export type StateFormat = "json" | "ssz";

@@ -30,11 +30,11 @@ export const testData: GenericServerTestCases<Api> = {
// block

getBlock: {
args: ["head"],
args: ["head", "json"],
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't look like we unit test the ssz format for state either. I will be happy to add a unit test case after this gets merged. Will be good practice for me. I haven't worked with the API code much

getState: {
args: ["head", "json"],
res: {executionOptimistic: true, data: ssz.phase0.BeaconState.defaultValue()},
},
getStateV2: {
args: ["head", "json"],
res: {executionOptimistic: true, data: ssz.altair.BeaconState.defaultValue(), version: ForkName.altair},
},

@wemeetagain wemeetagain merged commit 8f308c0 into unstable Sep 11, 2023
12 checks passed
@wemeetagain wemeetagain deleted the tuyen/download_blocks_as_ssz branch September 11, 2023 15:14
@wemeetagain
Copy link
Member

🎉 This PR is included in v1.12.0 🎉

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.

3 participants