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

Fix peer score serialization #3520

Merged
merged 2 commits into from
Dec 15, 2021
Merged

Fix peer score serialization #3520

merged 2 commits into from
Dec 15, 2021

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented Dec 15, 2021

Motivation

  • When there are a lot of DIAL_ERROR, I don't see we say goodbye to peers with "Peer score too low" or "Peer banned"
  • We can't dial some peers with "protocol selection failed" and it's still in our connected peer without being banned

Description

  • Right now we use ssz.Number64 type to serialize/deserialize peer score which is float, a peer score of -20 is serialized and deserialized back as a very big uint64

  • Use a new floatSerdes which is similar to stringSerdes but we parse float as an extra step

  • If method is ping and we get "protocol selection failed", ban the peer immediately

Closes #3517

Tested in contabo-19
Screen Shot 2021-12-15 at 15 36 01

@codecov
Copy link

codecov bot commented Dec 15, 2021

Codecov Report

Merging #3520 (8036b8e) into master (78b23bc) will decrease coverage by 0.01%.
The diff coverage is n/a.

❗ Current head 8036b8e differs from pull request most recent head 161b732. Consider uploading reports for the commit 161b732 to get more accurate results

@@            Coverage Diff             @@
##           master    #3520      +/-   ##
==========================================
- Coverage   37.90%   37.89%   -0.02%     
==========================================
  Files         308      308              
  Lines        8129     8134       +5     
  Branches     1248     1250       +2     
==========================================
+ Hits         3081     3082       +1     
- Misses       4900     4904       +4     
  Partials      148      148              

@codeclimate
Copy link

codeclimate bot commented Dec 15, 2021

Code Climate has analyzed commit 161b732 and detected 0 issues on this pull request.

View more on Code Climate.

* https://github.com/multiformats/js-multistream-select/blame/cf4e297b362a43bde2ea117085ceba78cbce1c12/src/select.js#L50
*/
const multiStreamSelectErrorCodes = {
protocolSelectionFailed: "protocol selection failed",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

once this error happens, it'll happen all the time and the peer is useless to us. It's similar to the ERR_UNSUPPORTED_PROTOCOL error below

@github-actions
Copy link
Contributor

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: 8036b8e Previous: 78b23bc Ratio
BeaconState.hashTreeRoot - No change 659.00 ns/op 772.00 ns/op 0.85
BeaconState.hashTreeRoot - 1 full validator 82.067 us/op 100.05 us/op 0.82
BeaconState.hashTreeRoot - 32 full validator 1.2127 ms/op 1.3217 ms/op 0.92
BeaconState.hashTreeRoot - 512 full validator 15.133 ms/op 15.814 ms/op 0.96
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 84.623 us/op 90.577 us/op 0.93
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 1.3985 ms/op 1.5115 ms/op 0.93
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 19.300 ms/op 19.229 ms/op 1.00
BeaconState.hashTreeRoot - 1 balances 62.906 us/op 66.031 us/op 0.95
BeaconState.hashTreeRoot - 32 balances 533.96 us/op 556.66 us/op 0.96
BeaconState.hashTreeRoot - 512 balances 4.9775 ms/op 5.3087 ms/op 0.94
BeaconState.hashTreeRoot - 250000 balances 99.416 ms/op 102.04 ms/op 0.97
processSlot - 1 slots 37.773 us/op 41.149 us/op 0.92
processSlot - 32 slots 2.1546 ms/op 2.3730 ms/op 0.91
getCommitteeAssignments - req 1 vs - 250000 vc 5.9357 ms/op 6.3270 ms/op 0.94
getCommitteeAssignments - req 100 vs - 250000 vc 8.6150 ms/op 8.9598 ms/op 0.96
getCommitteeAssignments - req 1000 vs - 250000 vc 9.2861 ms/op 9.4782 ms/op 0.98
computeProposers - vc 250000 22.809 ms/op 23.801 ms/op 0.96
computeEpochShuffling - vc 250000 207.42 ms/op 219.80 ms/op 0.94
getNextSyncCommittee - vc 250000 365.84 ms/op 390.62 ms/op 0.94
altair processAttestation - 250000 vs - 7PWei normalcase 39.376 ms/op 41.010 ms/op 0.96
altair processAttestation - 250000 vs - 7PWei worstcase 46.502 ms/op 49.836 ms/op 0.93
altair processAttestation - setStatus - 1/6 committees join 9.0988 ms/op 9.2231 ms/op 0.99
altair processAttestation - setStatus - 1/3 committees join 18.846 ms/op 19.229 ms/op 0.98
altair processAttestation - setStatus - 1/2 committees join 30.441 ms/op 30.076 ms/op 1.01
altair processAttestation - setStatus - 2/3 committees join 40.585 ms/op 38.832 ms/op 1.05
altair processAttestation - setStatus - 4/5 committees join 51.375 ms/op 46.583 ms/op 1.10
altair processAttestation - setStatus - 100% committees join 67.055 ms/op 60.434 ms/op 1.11
altair processAttestation - updateEpochParticipants - 1/6 committees join 10.737 ms/op 11.057 ms/op 0.97
altair processAttestation - updateEpochParticipants - 1/3 committees join 20.770 ms/op 20.515 ms/op 1.01
altair processAttestation - updateEpochParticipants - 1/2 committees join 26.873 ms/op 26.833 ms/op 1.00
altair processAttestation - updateEpochParticipants - 2/3 committees join 29.194 ms/op 30.417 ms/op 0.96
altair processAttestation - updateEpochParticipants - 4/5 committees join 35.430 ms/op 36.208 ms/op 0.98
altair processAttestation - updateEpochParticipants - 100% committees join 32.374 ms/op 33.007 ms/op 0.98
altair processAttestation - updateAllStatus 22.499 ms/op 23.259 ms/op 0.97
altair processBlock - 250000 vs - 7PWei normalcase 48.899 ms/op 50.736 ms/op 0.96
altair processBlock - 250000 vs - 7PWei worstcase 127.29 ms/op 129.45 ms/op 0.98
altair processEpoch - mainnet_e81889 1.0258 s/op 1.0621 s/op 0.97
mainnet_e81889 - altair beforeProcessEpoch 288.86 ms/op 300.45 ms/op 0.96
mainnet_e81889 - altair processJustificationAndFinalization 70.638 us/op 98.067 us/op 0.72
mainnet_e81889 - altair processInactivityUpdates 20.711 ms/op 20.676 ms/op 1.00
mainnet_e81889 - altair processRewardsAndPenalties 131.44 ms/op 137.34 ms/op 0.96
mainnet_e81889 - altair processRegistryUpdates 12.959 us/op 14.329 us/op 0.90
mainnet_e81889 - altair processSlashings 3.8060 us/op 4.0250 us/op 0.95
mainnet_e81889 - altair processEth1DataReset 3.8420 us/op 4.3060 us/op 0.89
mainnet_e81889 - altair processEffectiveBalanceUpdates 12.522 ms/op 14.084 ms/op 0.89
mainnet_e81889 - altair processSlashingsReset 14.570 us/op 20.921 us/op 0.70
mainnet_e81889 - altair processRandaoMixesReset 26.362 us/op 28.819 us/op 0.91
mainnet_e81889 - altair processHistoricalRootsUpdate 4.8460 us/op 6.0430 us/op 0.80
mainnet_e81889 - altair processParticipationFlagUpdates 162.35 ms/op 173.29 ms/op 0.94
mainnet_e81889 - altair processSyncCommitteeUpdates 3.2070 us/op 3.3870 us/op 0.95
mainnet_e81889 - altair afterProcessEpoch 243.19 ms/op 256.51 ms/op 0.95
altair processInactivityUpdates - 250000 normalcase 65.579 ms/op 68.733 ms/op 0.95
altair processInactivityUpdates - 250000 worstcase 66.992 ms/op 67.792 ms/op 0.99
altair processParticipationFlagUpdates - 250000 anycase 94.266 ms/op 100.04 ms/op 0.94
altair processRewardsAndPenalties - 250000 normalcase 129.24 ms/op 133.35 ms/op 0.97
altair processRewardsAndPenalties - 250000 worstcase 147.32 ms/op 158.70 ms/op 0.93
altair processSyncCommitteeUpdates - 250000 394.13 ms/op 407.85 ms/op 0.97
Tree 40 250000 create 494.29 ms/op 495.65 ms/op 1.00
Tree 40 250000 get(125000) 370.72 ns/op 359.68 ns/op 1.03
Tree 40 250000 set(125000) 1.5323 us/op 1.5241 us/op 1.01
Tree 40 250000 toArray() 40.604 ms/op 40.594 ms/op 1.00
Tree 40 250000 iterate all - toArray() + loop 45.016 ms/op 41.094 ms/op 1.10
Tree 40 250000 iterate all - get(i) 129.42 ms/op 141.35 ms/op 0.92
MutableVector 250000 create 19.598 ms/op 23.963 ms/op 0.82
MutableVector 250000 get(125000) 15.084 ns/op 16.137 ns/op 0.93
MutableVector 250000 set(125000) 495.29 ns/op 534.45 ns/op 0.93
MutableVector 250000 toArray() 8.8726 ms/op 9.4279 ms/op 0.94
MutableVector 250000 iterate all - toArray() + loop 9.3840 ms/op 9.6559 ms/op 0.97
MutableVector 250000 iterate all - get(i) 3.4432 ms/op 4.1775 ms/op 0.82
Array 250000 create 5.7635 ms/op 6.7107 ms/op 0.86
Array 250000 clone - spread 2.0822 ms/op 2.0804 ms/op 1.00
Array 250000 get(125000) 1.0290 ns/op 1.0760 ns/op 0.96
Array 250000 set(125000) 1.0610 ns/op 1.0960 ns/op 0.97
Array 250000 iterate all - loop 195.44 us/op 196.63 us/op 0.99
aggregationBits - 2048 els - readonlyValues 243.14 us/op 244.15 us/op 1.00
aggregationBits - 2048 els - zipIndexesInBitList 41.286 us/op 47.607 us/op 0.87
regular array get 100000 times 79.666 us/op 77.979 us/op 1.02
wrappedArray get 100000 times 77.346 us/op 77.977 us/op 0.99
arrayWithProxy get 100000 times 32.461 ms/op 39.127 ms/op 0.83
ssz.Root.equals 1.2320 us/op 1.3300 us/op 0.93
ssz.Root.equals with valueOf() 1.4160 us/op 1.4600 us/op 0.97
byteArrayEquals with valueOf() 1.3900 us/op 1.4310 us/op 0.97
phase0 processBlock - 250000 vs - 7PWei normalcase 11.435 ms/op 11.294 ms/op 1.01
phase0 processBlock - 250000 vs - 7PWei worstcase 79.135 ms/op 77.743 ms/op 1.02
phase0 afterProcessEpoch - 250000 vs - 7PWei 228.55 ms/op 228.72 ms/op 1.00
phase0 beforeProcessEpoch - 250000 vs - 7PWei 620.07 ms/op 578.84 ms/op 1.07
phase0 processEpoch - mainnet_e58758 811.72 ms/op 857.33 ms/op 0.95
mainnet_e58758 - phase0 beforeProcessEpoch 477.21 ms/op 492.23 ms/op 0.97
mainnet_e58758 - phase0 processJustificationAndFinalization 79.926 us/op 95.980 us/op 0.83
mainnet_e58758 - phase0 processRewardsAndPenalties 107.41 ms/op 118.56 ms/op 0.91
mainnet_e58758 - phase0 processRegistryUpdates 64.936 us/op 60.104 us/op 1.08
mainnet_e58758 - phase0 processSlashings 3.5250 us/op 4.2750 us/op 0.82
mainnet_e58758 - phase0 processEth1DataReset 3.7630 us/op 2.9580 us/op 1.27
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 10.437 ms/op 10.839 ms/op 0.96
mainnet_e58758 - phase0 processSlashingsReset 14.880 us/op 20.649 us/op 0.72
mainnet_e58758 - phase0 processRandaoMixesReset 19.998 us/op 24.249 us/op 0.82
mainnet_e58758 - phase0 processHistoricalRootsUpdate 5.3480 us/op 4.8520 us/op 1.10
mainnet_e58758 - phase0 processParticipationRecordUpdates 15.094 us/op 14.376 us/op 1.05
mainnet_e58758 - phase0 afterProcessEpoch 199.96 ms/op 206.14 ms/op 0.97
phase0 processEffectiveBalanceUpdates - 250000 normalcase 12.171 ms/op 13.050 ms/op 0.93
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.1199 s/op 1.1730 s/op 0.95
phase0 processRegistryUpdates - 250000 normalcase 58.093 us/op 68.448 us/op 0.85
phase0 processRegistryUpdates - 250000 badcase_full_deposits 2.7992 ms/op 2.8266 ms/op 0.99
phase0 processRegistryUpdates - 250000 worstcase 0.5 1.4801 s/op 1.4963 s/op 0.99
phase0 getAttestationDeltas - 250000 normalcase 48.210 ms/op 44.373 ms/op 1.09
phase0 getAttestationDeltas - 250000 worstcase 47.601 ms/op 44.435 ms/op 1.07
phase0 processSlashings - 250000 worstcase 31.578 ms/op 33.289 ms/op 0.95
shuffle list - 16384 els 14.607 ms/op 14.968 ms/op 0.98
shuffle list - 250000 els 201.73 ms/op 208.02 ms/op 0.97
getEffectiveBalances - 250000 vs - 7PWei 14.779 ms/op 14.019 ms/op 1.05
computeDeltas 3.8968 ms/op 4.1180 ms/op 0.95
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 2.3444 ms/op 2.2514 ms/op 1.04
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 773.63 us/op 748.01 us/op 1.03
BLS verify - blst-native 2.1347 ms/op 2.1416 ms/op 1.00
BLS verifyMultipleSignatures 3 - blst-native 4.3467 ms/op 4.4207 ms/op 0.98
BLS verifyMultipleSignatures 8 - blst-native 9.1175 ms/op 9.5266 ms/op 0.96
BLS verifyMultipleSignatures 32 - blst-native 32.877 ms/op 34.725 ms/op 0.95
BLS aggregatePubkeys 32 - blst-native 44.060 us/op 46.169 us/op 0.95
BLS aggregatePubkeys 128 - blst-native 173.97 us/op 177.48 us/op 0.98
getAttestationsForBlock 86.294 ms/op 89.389 ms/op 0.97
CheckpointStateCache - add get delete 16.834 us/op 16.627 us/op 1.01
validate gossip signedAggregateAndProof - struct 4.9742 ms/op 5.0903 ms/op 0.98
validate gossip signedAggregateAndProof - treeBacked 4.8727 ms/op 4.9887 ms/op 0.98
validate gossip attestation - struct 2.3248 ms/op 2.3748 ms/op 0.98
validate gossip attestation - treeBacked 2.3237 ms/op 2.4131 ms/op 0.96
Object access 1 prop 0.33900 ns/op 0.37600 ns/op 0.90
Map access 1 prop 0.31300 ns/op 0.32500 ns/op 0.96
Object get x1000 19.235 ns/op 21.330 ns/op 0.90
Map get x1000 1.1780 ns/op 1.1270 ns/op 1.05
Object set x1000 114.98 ns/op 123.22 ns/op 0.93
Map set x1000 71.441 ns/op 74.572 ns/op 0.96
Return object 10000 times 0.41340 ns/op 0.42690 ns/op 0.97
Throw Error 10000 times 6.5439 us/op 6.7281 us/op 0.97

by benchmarkbot/action

Copy link
Contributor

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

Nice find! 🙏

@wemeetagain wemeetagain merged commit 0150e17 into master Dec 15, 2021
@wemeetagain wemeetagain deleted the tuyen/fix-peer-score branch December 15, 2021 16:35
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.

Ban peers with bad scores
3 participants