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: trigger block search for unknown block attestations #5485

Merged
merged 8 commits into from
May 30, 2023

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented May 12, 2023

Motivation

  • At gossip time, we usually get unknown block attestations because gossip block comes after attestations, and we want to actively search for that block instead of waiting for gossip block passively

Description

  • New NetworkEvent.unknownBlock network event, emitted when unknown block attestations
  • Refactor unknownBlock sync to handle both unknownBlockParent and unknownBlock event
  • At each block there is usually a race between gossip block and rpc block. Most of the time gossip block wins.
  • Prevent unbundling attack

Closes #3613

@github-actions
Copy link
Contributor

github-actions bot commented May 12, 2023

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: f16fb27 Previous: 812ac92 Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 562.80 us/op 613.24 us/op 0.92
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 48.496 us/op 60.822 us/op 0.80
BLS verify - blst-native 1.2421 ms/op 1.2913 ms/op 0.96
BLS verifyMultipleSignatures 3 - blst-native 2.5281 ms/op 2.6469 ms/op 0.96
BLS verifyMultipleSignatures 8 - blst-native 5.4302 ms/op 5.5207 ms/op 0.98
BLS verifyMultipleSignatures 32 - blst-native 19.726 ms/op 19.605 ms/op 1.01
BLS aggregatePubkeys 32 - blst-native 26.268 us/op 26.560 us/op 0.99
BLS aggregatePubkeys 128 - blst-native 103.22 us/op 102.21 us/op 1.01
getAttestationsForBlock 59.006 ms/op 68.145 ms/op 0.87
isKnown best case - 1 super set check 272.00 ns/op 270.00 ns/op 1.01
isKnown normal case - 2 super set checks 270.00 ns/op 269.00 ns/op 1.00
isKnown worse case - 16 super set checks 266.00 ns/op 263.00 ns/op 1.01
CheckpointStateCache - add get delete 5.3540 us/op 6.2450 us/op 0.86
validate gossip signedAggregateAndProof - struct 2.8236 ms/op 3.0769 ms/op 0.92
validate gossip attestation - struct 1.3239 ms/op 1.3728 ms/op 0.96
pickEth1Vote - no votes 1.3287 ms/op 1.4218 ms/op 0.93
pickEth1Vote - max votes 9.6612 ms/op 11.940 ms/op 0.81
pickEth1Vote - Eth1Data hashTreeRoot value x2048 9.1108 ms/op 10.516 ms/op 0.87
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 14.493 ms/op 17.022 ms/op 0.85
pickEth1Vote - Eth1Data fastSerialize value x2048 669.64 us/op 765.51 us/op 0.87
pickEth1Vote - Eth1Data fastSerialize tree x2048 5.2290 ms/op 6.0191 ms/op 0.87
bytes32 toHexString 544.00 ns/op 726.00 ns/op 0.75
bytes32 Buffer.toString(hex) 406.00 ns/op 442.00 ns/op 0.92
bytes32 Buffer.toString(hex) from Uint8Array 609.00 ns/op 638.00 ns/op 0.95
bytes32 Buffer.toString(hex) + 0x 404.00 ns/op 441.00 ns/op 0.92
Object access 1 prop 0.18000 ns/op 0.20800 ns/op 0.87
Map access 1 prop 0.16500 ns/op 0.17100 ns/op 0.96
Object get x1000 6.8950 ns/op 7.3640 ns/op 0.94
Map get x1000 0.64500 ns/op 0.59600 ns/op 1.08
Object set x1000 55.882 ns/op 76.178 ns/op 0.73
Map set x1000 47.558 ns/op 57.682 ns/op 0.82
Return object 10000 times 0.24560 ns/op 0.26520 ns/op 0.93
Throw Error 10000 times 4.2908 us/op 4.4616 us/op 0.96
fastMsgIdFn sha256 / 200 bytes 3.4900 us/op 3.7270 us/op 0.94
fastMsgIdFn h32 xxhash / 200 bytes 293.00 ns/op 333.00 ns/op 0.88
fastMsgIdFn h64 xxhash / 200 bytes 420.00 ns/op 500.00 ns/op 0.84
fastMsgIdFn sha256 / 1000 bytes 11.799 us/op 12.254 us/op 0.96
fastMsgIdFn h32 xxhash / 1000 bytes 422.00 ns/op 460.00 ns/op 0.92
fastMsgIdFn h64 xxhash / 1000 bytes 506.00 ns/op 649.00 ns/op 0.78
fastMsgIdFn sha256 / 10000 bytes 105.18 us/op 146.17 us/op 0.72
fastMsgIdFn h32 xxhash / 10000 bytes 2.1140 us/op 2.9440 us/op 0.72
fastMsgIdFn h64 xxhash / 10000 bytes 1.5650 us/op 2.3130 us/op 0.68
enrSubnets - fastDeserialize 64 bits 1.3820 us/op 3.0960 us/op 0.45
enrSubnets - ssz BitVector 64 bits 548.00 ns/op 1.0860 us/op 0.50
enrSubnets - fastDeserialize 4 bits 196.00 ns/op 373.00 ns/op 0.53
enrSubnets - ssz BitVector 4 bits 551.00 ns/op 1.0450 us/op 0.53
prioritizePeers score -10:0 att 32-0.1 sync 2-0 110.21 us/op 216.08 us/op 0.51
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 154.85 us/op 279.04 us/op 0.55
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 169.85 us/op 329.94 us/op 0.51
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 334.92 us/op 563.44 us/op 0.59
prioritizePeers score 0:0 att 64-1 sync 4-1 377.91 us/op 790.24 us/op 0.48
array of 16000 items push then shift 1.6745 us/op 2.5764 us/op 0.65
LinkedList of 16000 items push then shift 9.2150 ns/op 15.683 ns/op 0.59
array of 16000 items push then pop 89.637 ns/op 173.89 ns/op 0.52
LinkedList of 16000 items push then pop 8.7910 ns/op 16.165 ns/op 0.54
array of 24000 items push then shift 2.3847 us/op 4.2206 us/op 0.57
LinkedList of 24000 items push then shift 8.9490 ns/op 15.082 ns/op 0.59
array of 24000 items push then pop 77.585 ns/op 156.36 ns/op 0.50
LinkedList of 24000 items push then pop 8.6920 ns/op 15.316 ns/op 0.57
intersect bitArray bitLen 8 13.318 ns/op 30.701 ns/op 0.43
intersect array and set length 8 81.094 ns/op 150.18 ns/op 0.54
intersect bitArray bitLen 128 44.406 ns/op 53.029 ns/op 0.84
intersect array and set length 128 1.1265 us/op 1.5224 us/op 0.74
Buffer.concat 32 items 2.8870 us/op 6.2040 us/op 0.47
Uint8Array.set 32 items 2.0950 us/op 5.0740 us/op 0.41
pass gossip attestations to forkchoice per slot 2.3095 ms/op 5.2660 ms/op 0.44
computeDeltas 3.0218 ms/op 4.8865 ms/op 0.62
computeProposerBoostScoreFromBalances 1.7889 ms/op 2.1414 ms/op 0.84
altair processAttestation - 250000 vs - 7PWei normalcase 2.6750 ms/op 3.7465 ms/op 0.71
altair processAttestation - 250000 vs - 7PWei worstcase 3.4218 ms/op 5.5744 ms/op 0.61
altair processAttestation - setStatus - 1/6 committees join 142.26 us/op 162.90 us/op 0.87
altair processAttestation - setStatus - 1/3 committees join 282.55 us/op 321.06 us/op 0.88
altair processAttestation - setStatus - 1/2 committees join 374.02 us/op 434.46 us/op 0.86
altair processAttestation - setStatus - 2/3 committees join 476.33 us/op 509.74 us/op 0.93
altair processAttestation - setStatus - 4/5 committees join 667.70 us/op 733.82 us/op 0.91
altair processAttestation - setStatus - 100% committees join 781.19 us/op 877.38 us/op 0.89
altair processBlock - 250000 vs - 7PWei normalcase 17.447 ms/op 22.297 ms/op 0.78
altair processBlock - 250000 vs - 7PWei normalcase hashState 29.132 ms/op 30.926 ms/op 0.94
altair processBlock - 250000 vs - 7PWei worstcase 46.943 ms/op 61.970 ms/op 0.76
altair processBlock - 250000 vs - 7PWei worstcase hashState 69.826 ms/op 77.260 ms/op 0.90
phase0 processBlock - 250000 vs - 7PWei normalcase 2.1159 ms/op 2.4902 ms/op 0.85
phase0 processBlock - 250000 vs - 7PWei worstcase 29.704 ms/op 31.892 ms/op 0.93
altair processEth1Data - 250000 vs - 7PWei normalcase 447.83 us/op 564.21 us/op 0.79
vc - 250000 eb 1 eth1 1 we 0 wn 0 - smpl 15 7.5500 us/op 8.3120 us/op 0.91
vc - 250000 eb 0.95 eth1 0.1 we 0.05 wn 0 - smpl 219 24.835 us/op 23.102 us/op 1.08
vc - 250000 eb 0.95 eth1 0.3 we 0.05 wn 0 - smpl 42 9.9940 us/op 10.145 us/op 0.99
vc - 250000 eb 0.95 eth1 0.7 we 0.05 wn 0 - smpl 18 7.5720 us/op 7.4000 us/op 1.02
vc - 250000 eb 0.1 eth1 0.1 we 0 wn 0 - smpl 1020 95.209 us/op 91.779 us/op 1.04
vc - 250000 eb 0.03 eth1 0.03 we 0 wn 0 - smpl 11777 659.83 us/op 769.34 us/op 0.86
vc - 250000 eb 0.01 eth1 0.01 we 0 wn 0 - smpl 16384 931.32 us/op 1.2757 ms/op 0.73
vc - 250000 eb 0 eth1 0 we 0 wn 0 - smpl 16384 884.38 us/op 1.6943 ms/op 0.52
vc - 250000 eb 0 eth1 0 we 0 wn 0 nocache - smpl 16384 2.3897 ms/op 2.6478 ms/op 0.90
vc - 250000 eb 0 eth1 1 we 0 wn 0 - smpl 16384 1.5431 ms/op 1.7497 ms/op 0.88
vc - 250000 eb 0 eth1 1 we 0 wn 0 nocache - smpl 16384 3.9250 ms/op 4.0459 ms/op 0.97
Tree 40 250000 create 285.65 ms/op 322.84 ms/op 0.88
Tree 40 250000 get(125000) 183.02 ns/op 187.56 ns/op 0.98
Tree 40 250000 set(125000) 887.08 ns/op 916.10 ns/op 0.97
Tree 40 250000 toArray() 17.994 ms/op 17.208 ms/op 1.05
Tree 40 250000 iterate all - toArray() + loop 18.180 ms/op 18.313 ms/op 0.99
Tree 40 250000 iterate all - get(i) 71.892 ms/op 69.910 ms/op 1.03
MutableVector 250000 create 10.379 ms/op 13.634 ms/op 0.76
MutableVector 250000 get(125000) 6.3730 ns/op 6.4700 ns/op 0.99
MutableVector 250000 set(125000) 263.75 ns/op 259.96 ns/op 1.01
MutableVector 250000 toArray() 2.8699 ms/op 2.6893 ms/op 1.07
MutableVector 250000 iterate all - toArray() + loop 3.0114 ms/op 2.7939 ms/op 1.08
MutableVector 250000 iterate all - get(i) 1.5254 ms/op 1.5276 ms/op 1.00
Array 250000 create 2.6518 ms/op 2.9231 ms/op 0.91
Array 250000 clone - spread 1.2518 ms/op 1.0637 ms/op 1.18
Array 250000 get(125000) 0.64000 ns/op 0.53600 ns/op 1.19
Array 250000 set(125000) 0.72400 ns/op 0.61100 ns/op 1.18
Array 250000 iterate all - loop 100.90 us/op 83.267 us/op 1.21
effectiveBalanceIncrements clone Uint8Array 300000 32.219 us/op 28.095 us/op 1.15
effectiveBalanceIncrements clone MutableVector 300000 402.00 ns/op 331.00 ns/op 1.21
effectiveBalanceIncrements rw all Uint8Array 300000 170.09 us/op 168.56 us/op 1.01
effectiveBalanceIncrements rw all MutableVector 300000 87.423 ms/op 79.092 ms/op 1.11
phase0 afterProcessEpoch - 250000 vs - 7PWei 116.26 ms/op 120.15 ms/op 0.97
phase0 beforeProcessEpoch - 250000 vs - 7PWei 33.715 ms/op 43.727 ms/op 0.77
altair processEpoch - mainnet_e81889 329.73 ms/op 349.26 ms/op 0.94
mainnet_e81889 - altair beforeProcessEpoch 68.783 ms/op 59.821 ms/op 1.15
mainnet_e81889 - altair processJustificationAndFinalization 17.111 us/op 35.592 us/op 0.48
mainnet_e81889 - altair processInactivityUpdates 5.5209 ms/op 5.8928 ms/op 0.94
mainnet_e81889 - altair processRewardsAndPenalties 53.207 ms/op 88.618 ms/op 0.60
mainnet_e81889 - altair processRegistryUpdates 2.4290 us/op 4.3640 us/op 0.56
mainnet_e81889 - altair processSlashings 480.00 ns/op 942.00 ns/op 0.51
mainnet_e81889 - altair processEth1DataReset 578.00 ns/op 874.00 ns/op 0.66
mainnet_e81889 - altair processEffectiveBalanceUpdates 1.2523 ms/op 2.2920 ms/op 0.55
mainnet_e81889 - altair processSlashingsReset 4.4590 us/op 6.3590 us/op 0.70
mainnet_e81889 - altair processRandaoMixesReset 4.4180 us/op 7.5010 us/op 0.59
mainnet_e81889 - altair processHistoricalRootsUpdate 627.00 ns/op 1.0720 us/op 0.58
mainnet_e81889 - altair processParticipationFlagUpdates 2.5690 us/op 3.7900 us/op 0.68
mainnet_e81889 - altair processSyncCommitteeUpdates 898.00 ns/op 916.00 ns/op 0.98
mainnet_e81889 - altair afterProcessEpoch 129.42 ms/op 129.21 ms/op 1.00
phase0 processEpoch - mainnet_e58758 344.43 ms/op 402.90 ms/op 0.85
mainnet_e58758 - phase0 beforeProcessEpoch 107.10 ms/op 154.44 ms/op 0.69
mainnet_e58758 - phase0 processJustificationAndFinalization 16.781 us/op 16.967 us/op 0.99
mainnet_e58758 - phase0 processRewardsAndPenalties 51.373 ms/op 74.299 ms/op 0.69
mainnet_e58758 - phase0 processRegistryUpdates 7.4610 us/op 13.746 us/op 0.54
mainnet_e58758 - phase0 processSlashings 575.00 ns/op 906.00 ns/op 0.63
mainnet_e58758 - phase0 processEth1DataReset 518.00 ns/op 654.00 ns/op 0.79
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 957.90 us/op 1.8864 ms/op 0.51
mainnet_e58758 - phase0 processSlashingsReset 3.3750 us/op 7.1670 us/op 0.47
mainnet_e58758 - phase0 processRandaoMixesReset 4.3780 us/op 5.4720 us/op 0.80
mainnet_e58758 - phase0 processHistoricalRootsUpdate 692.00 ns/op 988.00 ns/op 0.70
mainnet_e58758 - phase0 processParticipationRecordUpdates 3.6420 us/op 6.6770 us/op 0.55
mainnet_e58758 - phase0 afterProcessEpoch 96.728 ms/op 94.470 ms/op 1.02
phase0 processEffectiveBalanceUpdates - 250000 normalcase 1.2489 ms/op 1.1920 ms/op 1.05
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.4929 ms/op 1.4511 ms/op 1.03
altair processInactivityUpdates - 250000 normalcase 21.535 ms/op 31.460 ms/op 0.68
altair processInactivityUpdates - 250000 worstcase 20.568 ms/op 31.430 ms/op 0.65
phase0 processRegistryUpdates - 250000 normalcase 6.5410 us/op 10.931 us/op 0.60
phase0 processRegistryUpdates - 250000 badcase_full_deposits 250.17 us/op 466.01 us/op 0.54
phase0 processRegistryUpdates - 250000 worstcase 0.5 108.45 ms/op 156.19 ms/op 0.69
altair processRewardsAndPenalties - 250000 normalcase 53.563 ms/op 82.023 ms/op 0.65
altair processRewardsAndPenalties - 250000 worstcase 44.908 ms/op 83.210 ms/op 0.54
phase0 getAttestationDeltas - 250000 normalcase 7.0210 ms/op 6.5851 ms/op 1.07
phase0 getAttestationDeltas - 250000 worstcase 6.7379 ms/op 6.5383 ms/op 1.03
phase0 processSlashings - 250000 worstcase 3.4143 ms/op 3.5070 ms/op 0.97
altair processSyncCommitteeUpdates - 250000 169.63 ms/op 188.35 ms/op 0.90
BeaconState.hashTreeRoot - No change 265.00 ns/op 274.00 ns/op 0.97
BeaconState.hashTreeRoot - 1 full validator 50.532 us/op 57.164 us/op 0.88
BeaconState.hashTreeRoot - 32 full validator 476.63 us/op 637.91 us/op 0.75
BeaconState.hashTreeRoot - 512 full validator 4.9735 ms/op 5.9803 ms/op 0.83
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 63.278 us/op 66.564 us/op 0.95
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 889.87 us/op 1.0040 ms/op 0.89
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 10.833 ms/op 11.311 ms/op 0.96
BeaconState.hashTreeRoot - 1 balances 47.321 us/op 59.518 us/op 0.80
BeaconState.hashTreeRoot - 32 balances 429.90 us/op 443.78 us/op 0.97
BeaconState.hashTreeRoot - 512 balances 4.3257 ms/op 4.8830 ms/op 0.89
BeaconState.hashTreeRoot - 250000 balances 72.880 ms/op 86.887 ms/op 0.84
aggregationBits - 2048 els - zipIndexesInBitList 16.869 us/op 15.326 us/op 1.10
regular array get 100000 times 32.686 us/op 32.637 us/op 1.00
wrappedArray get 100000 times 32.686 us/op 32.947 us/op 0.99
arrayWithProxy get 100000 times 15.877 ms/op 15.322 ms/op 1.04
ssz.Root.equals 543.00 ns/op 535.00 ns/op 1.01
byteArrayEquals 535.00 ns/op 529.00 ns/op 1.01
shuffle list - 16384 els 6.9388 ms/op 6.7520 ms/op 1.03
shuffle list - 250000 els 101.26 ms/op 99.493 ms/op 1.02
processSlot - 1 slots 9.8270 us/op 9.0310 us/op 1.09
processSlot - 32 slots 1.4051 ms/op 1.3694 ms/op 1.03
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 32.274 ms/op 40.728 ms/op 0.79
getCommitteeAssignments - req 1 vs - 250000 vc 2.9077 ms/op 2.9989 ms/op 0.97
getCommitteeAssignments - req 100 vs - 250000 vc 4.1493 ms/op 4.1596 ms/op 1.00
getCommitteeAssignments - req 1000 vs - 250000 vc 4.5158 ms/op 4.4883 ms/op 1.01
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 4.8800 ns/op 4.6900 ns/op 1.04
state getBlockRootAtSlot - 250000 vs - 7PWei 910.96 ns/op 860.69 ns/op 1.06
computeProposers - vc 250000 11.068 ms/op 10.143 ms/op 1.09
computeEpochShuffling - vc 250000 105.28 ms/op 101.82 ms/op 1.03
getNextSyncCommittee - vc 250000 179.03 ms/op 167.58 ms/op 1.07
computeSigningRoot for AttestationData 14.952 us/op 12.592 us/op 1.19
hash AttestationData serialized data then Buffer.toString(base64) 2.5181 us/op 2.4470 us/op 1.03
toHexString serialized data 1.1503 us/op 1.0623 us/op 1.08
Buffer.toString(base64) 340.22 ns/op 324.43 ns/op 1.05

by benchmarkbot/action

@twoeths
Copy link
Contributor Author

twoeths commented May 12, 2023

blocked by #5486

@twoeths
Copy link
Contributor Author

twoeths commented May 15, 2023

at each slot, there's likely 1 unknown block root sync due to unknown block attestation

Screenshot 2023-05-15 at 13 52 18

however, most of the time gossip blocks are processed before rpc (unknown root) block

Screenshot 2023-05-15 at 13 53 11

@twoeths twoeths marked this pull request as ready for review May 15, 2023 06:56
@twoeths twoeths requested a review from a team as a code owner May 15, 2023 06:56
// Trigger unknown block root search here
const rootHex = toHexString(blockRoot);
events.emit(NetworkEvent.unknownBlock, {rootHex});
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this safeguard against spamming unknownBlock events if multiple attestations reference to the same unknown block root

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dapplion I addressed this in the latest commit, there is a cache inside NetworkProcessor to only search for 1 root per slot, and NetworkEvent.unknownBlock is triggered in a single place

@twoeths
Copy link
Contributor Author

twoeths commented May 25, 2023

we need to also cover triggering block search for unknown root sync committee and blobsidecar, will do it in another PR

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.

Looks great! Thank you

@wemeetagain
Copy link
Member

🎉 This PR is included in v1.9.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.

Trigger block search when receiving unknown block root gossip attestations
3 participants