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

Snappy frame encode big payloads as chunks as per the standard #3912

Merged
merged 11 commits into from
May 4, 2022

Conversation

g11tech
Copy link
Contributor

@g11tech g11tech commented Apr 12, 2022

Motivation
On a bellatrix block of goerli shadowfork2, lighthouse frame decoder failed to decode block it req/resp from a lodestar node. Turned out it was big block, but being streamed as a single chunk which didnot confirm to the snappy frame encoding/decoding specs.

This PR chunkifies a big payload in the compress stream as per the standards and add tests for the same block

Closes #3903

@codecov
Copy link

codecov bot commented Apr 12, 2022

Codecov Report

Merging #3912 (663deb2) into master (3a38e65) will increase coverage by 0.73%.
The diff coverage is n/a.

❗ Current head 663deb2 differs from pull request most recent head 23b0882. Consider uploading reports for the commit 23b0882 to get more accurate results

@@            Coverage Diff             @@
##           master    #3912      +/-   ##
==========================================
+ Coverage   36.26%   37.00%   +0.73%     
==========================================
  Files         324      325       +1     
  Lines        9099     9102       +3     
  Branches     1465     1465              
==========================================
+ Hits         3300     3368      +68     
+ Misses       5626     5543      -83     
- Partials      173      191      +18     

@github-actions
Copy link
Contributor

github-actions bot commented Apr 12, 2022

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: 663deb2 Previous: 2b9fe2a Ratio
BeaconState.hashTreeRoot - No change 535.00 ns/op 654.00 ns/op 0.82
BeaconState.hashTreeRoot - 1 full validator 55.132 us/op 71.666 us/op 0.77
BeaconState.hashTreeRoot - 32 full validator 540.33 us/op 647.19 us/op 0.83
BeaconState.hashTreeRoot - 512 full validator 5.9712 ms/op 6.9920 ms/op 0.85
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 69.907 us/op 82.053 us/op 0.85
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 960.59 us/op 1.1269 ms/op 0.85
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 13.546 ms/op 15.066 ms/op 0.90
BeaconState.hashTreeRoot - 1 balances 52.608 us/op 62.614 us/op 0.84
BeaconState.hashTreeRoot - 32 balances 475.30 us/op 565.33 us/op 0.84
BeaconState.hashTreeRoot - 512 balances 4.6649 ms/op 5.4235 ms/op 0.86
BeaconState.hashTreeRoot - 250000 balances 104.44 ms/op 113.45 ms/op 0.92
processSlot - 1 slots 9.5840 us/op 11.269 us/op 0.85
processSlot - 32 slots 1.5823 ms/op 1.8476 ms/op 0.86
getCommitteeAssignments - req 1 vs - 250000 vc 5.2684 ms/op 6.3099 ms/op 0.83
getCommitteeAssignments - req 100 vs - 250000 vc 7.3623 ms/op 8.7769 ms/op 0.84
getCommitteeAssignments - req 1000 vs - 250000 vc 7.8036 ms/op 9.4504 ms/op 0.83
computeProposers - vc 250000 16.439 ms/op 19.223 ms/op 0.86
computeEpochShuffling - vc 250000 157.93 ms/op 190.35 ms/op 0.83
getNextSyncCommittee - vc 250000 270.75 ms/op 320.13 ms/op 0.85
altair processAttestation - 250000 vs - 7PWei normalcase 3.6817 ms/op 4.2059 ms/op 0.88
altair processAttestation - 250000 vs - 7PWei worstcase 5.7373 ms/op 6.1358 ms/op 0.94
altair processAttestation - setStatus - 1/6 committees join 196.52 us/op 242.16 us/op 0.81
altair processAttestation - setStatus - 1/3 committees join 377.18 us/op 464.57 us/op 0.81
altair processAttestation - setStatus - 1/2 committees join 525.90 us/op 655.65 us/op 0.80
altair processAttestation - setStatus - 2/3 committees join 680.77 us/op 847.17 us/op 0.80
altair processAttestation - setStatus - 4/5 committees join 938.68 us/op 1.1532 ms/op 0.81
altair processAttestation - setStatus - 100% committees join 1.0975 ms/op 1.3790 ms/op 0.80
altair processBlock - 250000 vs - 7PWei normalcase 24.169 ms/op 28.164 ms/op 0.86
altair processBlock - 250000 vs - 7PWei normalcase hashState 35.640 ms/op 38.852 ms/op 0.92
altair processBlock - 250000 vs - 7PWei worstcase 72.457 ms/op 83.241 ms/op 0.87
altair processBlock - 250000 vs - 7PWei worstcase hashState 109.05 ms/op 127.02 ms/op 0.86
altair processEth1Data - 250000 vs - 7PWei normalcase 792.74 us/op 853.84 us/op 0.93
altair processEpoch - mainnet_e81889 559.76 ms/op 640.95 ms/op 0.87
mainnet_e81889 - altair beforeProcessEpoch 147.57 ms/op 167.22 ms/op 0.88
mainnet_e81889 - altair processJustificationAndFinalization 22.815 us/op 32.850 us/op 0.69
mainnet_e81889 - altair processInactivityUpdates 11.395 ms/op 12.836 ms/op 0.89
mainnet_e81889 - altair processRewardsAndPenalties 137.03 ms/op 95.928 ms/op 1.43
mainnet_e81889 - altair processRegistryUpdates 3.4200 us/op 8.2590 us/op 0.41
mainnet_e81889 - altair processSlashings 1.0390 us/op 3.0590 us/op 0.34
mainnet_e81889 - altair processEth1DataReset 1.0330 us/op 3.3140 us/op 0.31
mainnet_e81889 - altair processEffectiveBalanceUpdates 7.8966 ms/op 7.8963 ms/op 1.00
mainnet_e81889 - altair processSlashingsReset 7.0460 us/op 14.184 us/op 0.50
mainnet_e81889 - altair processRandaoMixesReset 8.6010 us/op 12.383 us/op 0.69
mainnet_e81889 - altair processHistoricalRootsUpdate 1.5450 us/op 3.5200 us/op 0.44
mainnet_e81889 - altair processParticipationFlagUpdates 3.1900 us/op 9.4390 us/op 0.34
mainnet_e81889 - altair processSyncCommitteeUpdates 947.00 ns/op 2.5070 us/op 0.38
mainnet_e81889 - altair afterProcessEpoch 182.36 ms/op 219.62 ms/op 0.83
altair processInactivityUpdates - 250000 normalcase 32.128 ms/op 37.990 ms/op 0.85
altair processInactivityUpdates - 250000 worstcase 26.660 ms/op 32.423 ms/op 0.82
altair processRewardsAndPenalties - 250000 normalcase 125.75 ms/op 91.459 ms/op 1.37
altair processRewardsAndPenalties - 250000 worstcase 77.873 ms/op 93.808 ms/op 0.83
altair processSyncCommitteeUpdates - 250000 281.48 ms/op 336.03 ms/op 0.84
Tree 40 250000 create 703.62 ms/op 713.32 ms/op 0.99
Tree 40 250000 get(125000) 289.08 ns/op 336.20 ns/op 0.86
Tree 40 250000 set(125000) 2.3436 us/op 2.2400 us/op 1.05
Tree 40 250000 toArray() 32.668 ms/op 35.100 ms/op 0.93
Tree 40 250000 iterate all - toArray() + loop 32.692 ms/op 35.284 ms/op 0.93
Tree 40 250000 iterate all - get(i) 111.19 ms/op 127.54 ms/op 0.87
MutableVector 250000 create 14.698 ms/op 16.380 ms/op 0.90
MutableVector 250000 get(125000) 14.803 ns/op 17.780 ns/op 0.83
MutableVector 250000 set(125000) 592.03 ns/op 586.59 ns/op 1.01
MutableVector 250000 toArray() 6.3934 ms/op 7.2099 ms/op 0.89
MutableVector 250000 iterate all - toArray() + loop 6.5207 ms/op 7.1678 ms/op 0.91
MutableVector 250000 iterate all - get(i) 3.4398 ms/op 3.9363 ms/op 0.87
Array 250000 create 6.2468 ms/op 6.2857 ms/op 0.99
Array 250000 clone - spread 2.6240 ms/op 2.6289 ms/op 1.00
Array 250000 get(125000) 1.1880 ns/op 1.2740 ns/op 0.93
Array 250000 set(125000) 1.1600 ns/op 1.2830 ns/op 0.90
Array 250000 iterate all - loop 170.06 us/op 201.53 us/op 0.84
effectiveBalanceIncrements clone Uint8Array 300000 75.099 us/op 80.790 us/op 0.93
effectiveBalanceIncrements clone MutableVector 300000 523.00 ns/op 611.00 ns/op 0.86
effectiveBalanceIncrements rw all Uint8Array 300000 301.84 us/op 362.30 us/op 0.83
effectiveBalanceIncrements rw all MutableVector 300000 167.38 ms/op 169.56 ms/op 0.99
aggregationBits - 2048 els - zipIndexesInBitList 27.011 us/op 27.269 us/op 0.99
regular array get 100000 times 67.436 us/op 80.944 us/op 0.83
wrappedArray get 100000 times 67.463 us/op 80.967 us/op 0.83
arrayWithProxy get 100000 times 32.481 ms/op 39.870 ms/op 0.81
ssz.Root.equals 440.00 ns/op 510.00 ns/op 0.86
byteArrayEquals 457.00 ns/op 511.00 ns/op 0.89
phase0 processBlock - 250000 vs - 7PWei normalcase 3.5213 ms/op 3.8563 ms/op 0.91
phase0 processBlock - 250000 vs - 7PWei worstcase 46.584 ms/op 52.793 ms/op 0.88
phase0 afterProcessEpoch - 250000 vs - 7PWei 173.89 ms/op 207.84 ms/op 0.84
phase0 beforeProcessEpoch - 250000 vs - 7PWei 81.851 ms/op 80.548 ms/op 1.02
phase0 processEpoch - mainnet_e58758 515.90 ms/op 583.44 ms/op 0.88
mainnet_e58758 - phase0 beforeProcessEpoch 230.04 ms/op 238.95 ms/op 0.96
mainnet_e58758 - phase0 processJustificationAndFinalization 28.911 us/op 30.899 us/op 0.94
mainnet_e58758 - phase0 processRewardsAndPenalties 79.154 ms/op 81.640 ms/op 0.97
mainnet_e58758 - phase0 processRegistryUpdates 9.9160 us/op 16.878 us/op 0.59
mainnet_e58758 - phase0 processSlashings 1.5750 us/op 3.3660 us/op 0.47
mainnet_e58758 - phase0 processEth1DataReset 1.4320 us/op 3.1950 us/op 0.45
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 5.4884 ms/op 6.4117 ms/op 0.86
mainnet_e58758 - phase0 processSlashingsReset 6.7120 us/op 11.344 us/op 0.59
mainnet_e58758 - phase0 processRandaoMixesReset 7.4890 us/op 11.554 us/op 0.65
mainnet_e58758 - phase0 processHistoricalRootsUpdate 1.5560 us/op 4.0780 us/op 0.38
mainnet_e58758 - phase0 processParticipationRecordUpdates 7.1390 us/op 10.242 us/op 0.70
mainnet_e58758 - phase0 afterProcessEpoch 158.05 ms/op 183.09 ms/op 0.86
phase0 processEffectiveBalanceUpdates - 250000 normalcase 6.2664 ms/op 7.5612 ms/op 0.83
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 6.8377 ms/op 8.2232 ms/op 0.83
phase0 processRegistryUpdates - 250000 normalcase 12.199 us/op 13.977 us/op 0.87
phase0 processRegistryUpdates - 250000 badcase_full_deposits 506.39 us/op 549.87 us/op 0.92
phase0 processRegistryUpdates - 250000 worstcase 0.5 216.62 ms/op 282.87 ms/op 0.77
phase0 getAttestationDeltas - 250000 normalcase 14.909 ms/op 16.566 ms/op 0.90
phase0 getAttestationDeltas - 250000 worstcase 15.567 ms/op 16.788 ms/op 0.93
phase0 processSlashings - 250000 worstcase 5.7285 ms/op 6.5783 ms/op 0.87
shuffle list - 16384 els 11.162 ms/op 12.777 ms/op 0.87
shuffle list - 250000 els 152.98 ms/op 184.78 ms/op 0.83
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 334.53 us/op 458.91 us/op 0.73
pass gossip attestations to forkchoice per slot 3.3996 ms/op 3.9999 ms/op 0.85
computeDeltas 3.6703 ms/op 3.8112 ms/op 0.96
computeProposerBoostScoreFromBalances 503.13 us/op 603.73 us/op 0.83
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 2.4284 ms/op 2.2909 ms/op 1.06
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 76.083 us/op 84.129 us/op 0.90
BLS verify - blst-native 1.8509 ms/op 2.2302 ms/op 0.83
BLS verifyMultipleSignatures 3 - blst-native 3.7967 ms/op 4.5672 ms/op 0.83
BLS verifyMultipleSignatures 8 - blst-native 8.1688 ms/op 9.8387 ms/op 0.83
BLS verifyMultipleSignatures 32 - blst-native 29.603 ms/op 35.586 ms/op 0.83
BLS aggregatePubkeys 32 - blst-native 39.194 us/op 47.833 us/op 0.82
BLS aggregatePubkeys 128 - blst-native 153.06 us/op 187.99 us/op 0.81
getAttestationsForBlock 61.044 ms/op 67.017 ms/op 0.91
CheckpointStateCache - add get delete 10.804 us/op 12.518 us/op 0.86
validate gossip signedAggregateAndProof - struct 4.2626 ms/op 5.1118 ms/op 0.83
validate gossip attestation - struct 2.0241 ms/op 2.4410 ms/op 0.83
pickEth1Vote - no votes 2.1998 ms/op 2.5880 ms/op 0.85
pickEth1Vote - max votes 21.136 ms/op 21.173 ms/op 1.00
pickEth1Vote - Eth1Data hashTreeRoot value x2048 11.340 ms/op 12.534 ms/op 0.90
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 21.257 ms/op 22.849 ms/op 0.93
pickEth1Vote - Eth1Data fastSerialize value x2048 1.6743 ms/op 1.9782 ms/op 0.85
pickEth1Vote - Eth1Data fastSerialize tree x2048 14.716 ms/op 14.427 ms/op 1.02
bytes32 toHexString 1.0110 us/op 1.0870 us/op 0.93
bytes32 Buffer.toString(hex) 681.00 ns/op 798.00 ns/op 0.85
bytes32 Buffer.toString(hex) from Uint8Array 918.00 ns/op 1.0360 us/op 0.89
bytes32 Buffer.toString(hex) + 0x 686.00 ns/op 811.00 ns/op 0.85
Object access 1 prop 0.33600 ns/op 0.38900 ns/op 0.86
Map access 1 prop 0.29500 ns/op 0.34500 ns/op 0.86
Object get x1000 17.732 ns/op 20.722 ns/op 0.86
Map get x1000 0.96900 ns/op 1.2560 ns/op 0.77
Object set x1000 108.52 ns/op 122.37 ns/op 0.89
Map set x1000 65.796 ns/op 74.114 ns/op 0.89
Return object 10000 times 0.36700 ns/op 0.44920 ns/op 0.82
Throw Error 10000 times 6.0099 us/op 7.0308 us/op 0.85
enrSubnets - fastDeserialize 64 bits 2.8420 us/op 3.0080 us/op 0.94
enrSubnets - ssz BitVector 64 bits 778.00 ns/op 839.00 ns/op 0.93
enrSubnets - fastDeserialize 4 bits 394.00 ns/op 449.00 ns/op 0.88
enrSubnets - ssz BitVector 4 bits 815.00 ns/op 847.00 ns/op 0.96
RateTracker 1000000 limit, 1 obj count per request 183.20 ns/op 220.28 ns/op 0.83
RateTracker 1000000 limit, 2 obj count per request 139.16 ns/op 161.36 ns/op 0.86
RateTracker 1000000 limit, 4 obj count per request 116.92 ns/op 135.29 ns/op 0.86
RateTracker 1000000 limit, 8 obj count per request 111.88 ns/op 118.49 ns/op 0.94
RateTracker with prune 4.3820 us/op 4.5060 us/op 0.97
array of 16000 items push then shift 3.1475 us/op 3.7389 us/op 0.84
LinkedList of 16000 items push then shift 19.139 ns/op 18.819 ns/op 1.02
array of 16000 items push then pop 209.75 ns/op 235.90 ns/op 0.89
LinkedList of 16000 items push then pop 17.646 ns/op 19.150 ns/op 0.92
array of 24000 items push then shift 4.5618 us/op 5.4482 us/op 0.84
LinkedList of 24000 items push then shift 22.991 ns/op 21.377 ns/op 1.08
array of 24000 items push then pop 211.41 ns/op 231.58 ns/op 0.91
LinkedList of 24000 items push then pop 19.755 ns/op 20.484 ns/op 0.96

by benchmarkbot/action

@g11tech g11tech mentioned this pull request Apr 22, 2022
22 tasks
@g11tech g11tech requested a review from a team as a code owner April 27, 2022 12:25
*
* To use async version (for e.g. on big payloads) instantiate the stream with
* `createCompressStream({asyncCompress: true})`
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you so much for adding a nice reasoning comment! ❤️

@dapplion dapplion merged commit 029e7b7 into master May 4, 2022
@dapplion dapplion deleted the g11tech/snappyframechunks branch May 4, 2022 15:26
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.

investigate and fix snappy stream encoding of a big bellatrix block which was rejected by the lighthouse bn
3 participants