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: use proper state to verify attestations #5500

Merged
merged 4 commits into from May 24, 2023

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented May 17, 2023

Motivation

Right now we always use head state to verify attestations

Description

We should only use head block state if:

  • head block slot and attestation slot are in the same fork
  • and head block state includes committees of target epoch

otherwise we should use head state dialed to target epoch. Notice that with maxSkippedSlot=32 we'll always use head state unless it's at epoch boundary

Also add some metrics to monitor slot distances in attestation

Closes #5498 Closes #4831

TODOs

  • Unit test
  • Deploy and monitor on a test mainnet node

@github-actions
Copy link
Contributor

github-actions bot commented May 17, 2023

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: e25657a Previous: 1a8476b Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 788.04 us/op 594.09 us/op 1.33
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 68.648 us/op 50.378 us/op 1.36
BLS verify - blst-native 1.3101 ms/op 1.2699 ms/op 1.03
BLS verifyMultipleSignatures 3 - blst-native 2.6549 ms/op 2.5834 ms/op 1.03
BLS verifyMultipleSignatures 8 - blst-native 5.6657 ms/op 5.7131 ms/op 0.99
BLS verifyMultipleSignatures 32 - blst-native 20.443 ms/op 20.199 ms/op 1.01
BLS aggregatePubkeys 32 - blst-native 29.454 us/op 27.969 us/op 1.05
BLS aggregatePubkeys 128 - blst-native 110.24 us/op 105.25 us/op 1.05
getAttestationsForBlock 68.057 ms/op 57.916 ms/op 1.18
isKnown best case - 1 super set check 309.00 ns/op 281.00 ns/op 1.10
isKnown normal case - 2 super set checks 292.00 ns/op 275.00 ns/op 1.06
isKnown worse case - 16 super set checks 292.00 ns/op 269.00 ns/op 1.09
CheckpointStateCache - add get delete 6.0490 us/op 6.3280 us/op 0.96
validate gossip signedAggregateAndProof - struct 3.2070 ms/op 2.9373 ms/op 1.09
validate gossip attestation - struct 1.4619 ms/op 1.3926 ms/op 1.05
pickEth1Vote - no votes 1.6665 ms/op 1.4406 ms/op 1.16
pickEth1Vote - max votes 12.223 ms/op 10.459 ms/op 1.17
pickEth1Vote - Eth1Data hashTreeRoot value x2048 10.328 ms/op 9.4720 ms/op 1.09
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 18.036 ms/op 14.729 ms/op 1.22
pickEth1Vote - Eth1Data fastSerialize value x2048 916.83 us/op 681.24 us/op 1.35
pickEth1Vote - Eth1Data fastSerialize tree x2048 6.3974 ms/op 4.9961 ms/op 1.28
bytes32 toHexString 806.00 ns/op 561.00 ns/op 1.44
bytes32 Buffer.toString(hex) 474.00 ns/op 400.00 ns/op 1.19
bytes32 Buffer.toString(hex) from Uint8Array 723.00 ns/op 614.00 ns/op 1.18
bytes32 Buffer.toString(hex) + 0x 486.00 ns/op 392.00 ns/op 1.24
Object access 1 prop 0.22400 ns/op 0.17800 ns/op 1.26
Map access 1 prop 0.21200 ns/op 0.17100 ns/op 1.24
Object get x1000 11.037 ns/op 7.0780 ns/op 1.56
Map get x1000 0.83900 ns/op 0.70100 ns/op 1.20
Object set x1000 92.467 ns/op 78.640 ns/op 1.18
Map set x1000 66.507 ns/op 54.849 ns/op 1.21
Return object 10000 times 0.36490 ns/op 0.26350 ns/op 1.38
Throw Error 10000 times 5.6425 us/op 4.6812 us/op 1.21
fastMsgIdFn sha256 / 200 bytes 4.2790 us/op 3.8300 us/op 1.12
fastMsgIdFn h32 xxhash / 200 bytes 397.00 ns/op 322.00 ns/op 1.23
fastMsgIdFn h64 xxhash / 200 bytes 570.00 ns/op 460.00 ns/op 1.24
fastMsgIdFn sha256 / 1000 bytes 14.449 us/op 12.791 us/op 1.13
fastMsgIdFn h32 xxhash / 1000 bytes 542.00 ns/op 466.00 ns/op 1.16
fastMsgIdFn h64 xxhash / 1000 bytes 759.00 ns/op 544.00 ns/op 1.40
fastMsgIdFn sha256 / 10000 bytes 128.21 us/op 118.49 us/op 1.08
fastMsgIdFn h32 xxhash / 10000 bytes 2.3600 us/op 2.0470 us/op 1.15
fastMsgIdFn h64 xxhash / 10000 bytes 1.6870 us/op 1.4590 us/op 1.16
enrSubnets - fastDeserialize 64 bits 2.0190 us/op 1.4370 us/op 1.41
enrSubnets - ssz BitVector 64 bits 672.00 ns/op 623.00 ns/op 1.08
enrSubnets - fastDeserialize 4 bits 243.00 ns/op 196.00 ns/op 1.24
enrSubnets - ssz BitVector 4 bits 692.00 ns/op 603.00 ns/op 1.15
prioritizePeers score -10:0 att 32-0.1 sync 2-0 133.30 us/op 127.86 us/op 1.04
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 178.27 us/op 163.43 us/op 1.09
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 216.14 us/op 208.20 us/op 1.04
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 395.59 us/op 420.85 us/op 0.94
prioritizePeers score 0:0 att 64-1 sync 4-1 491.58 us/op 472.93 us/op 1.04
array of 16000 items push then shift 1.9772 us/op 1.8498 us/op 1.07
LinkedList of 16000 items push then shift 11.271 ns/op 10.357 ns/op 1.09
array of 16000 items push then pop 131.68 ns/op 117.38 ns/op 1.12
LinkedList of 16000 items push then pop 11.678 ns/op 9.6750 ns/op 1.21
array of 24000 items push then shift 2.8171 us/op 2.6436 us/op 1.07
LinkedList of 24000 items push then shift 11.369 ns/op 9.5990 ns/op 1.18
array of 24000 items push then pop 123.17 ns/op 99.149 ns/op 1.24
LinkedList of 24000 items push then pop 12.358 ns/op 9.6940 ns/op 1.27
intersect bitArray bitLen 8 21.433 ns/op 14.976 ns/op 1.43
intersect array and set length 8 155.53 ns/op 92.651 ns/op 1.68
intersect bitArray bitLen 128 70.221 ns/op 47.938 ns/op 1.46
intersect array and set length 128 1.8602 us/op 1.3018 us/op 1.43
Buffer.concat 32 items 4.2100 us/op 2.9060 us/op 1.45
Uint8Array.set 32 items 2.9770 us/op 2.5460 us/op 1.17
pass gossip attestations to forkchoice per slot 2.8345 ms/op 2.6454 ms/op 1.07
computeDeltas 4.3810 ms/op 3.1504 ms/op 1.39
computeProposerBoostScoreFromBalances 2.4541 ms/op 1.9008 ms/op 1.29
altair processAttestation - 250000 vs - 7PWei normalcase 5.8173 ms/op 3.0267 ms/op 1.92
altair processAttestation - 250000 vs - 7PWei worstcase 9.7386 ms/op 4.2039 ms/op 2.32
altair processAttestation - setStatus - 1/6 committees join 229.03 us/op 158.36 us/op 1.45
altair processAttestation - setStatus - 1/3 committees join 409.33 us/op 295.65 us/op 1.38
altair processAttestation - setStatus - 1/2 committees join 472.53 us/op 420.16 us/op 1.12
altair processAttestation - setStatus - 2/3 committees join 694.12 us/op 531.05 us/op 1.31
altair processAttestation - setStatus - 4/5 committees join 1.0384 ms/op 701.10 us/op 1.48
altair processAttestation - setStatus - 100% committees join 1.2308 ms/op 828.62 us/op 1.49
altair processBlock - 250000 vs - 7PWei normalcase 29.430 ms/op 19.320 ms/op 1.52
altair processBlock - 250000 vs - 7PWei normalcase hashState 38.828 ms/op 31.244 ms/op 1.24
altair processBlock - 250000 vs - 7PWei worstcase 73.499 ms/op 57.177 ms/op 1.29
altair processBlock - 250000 vs - 7PWei worstcase hashState 101.73 ms/op 77.984 ms/op 1.30
phase0 processBlock - 250000 vs - 7PWei normalcase 3.9386 ms/op 2.6750 ms/op 1.47
phase0 processBlock - 250000 vs - 7PWei worstcase 41.910 ms/op 36.246 ms/op 1.16
altair processEth1Data - 250000 vs - 7PWei normalcase 862.54 us/op 673.43 us/op 1.28
vc - 250000 eb 1 eth1 1 we 0 wn 0 - smpl 15 15.552 us/op 10.173 us/op 1.53
vc - 250000 eb 0.95 eth1 0.1 we 0.05 wn 0 - smpl 219 45.281 us/op 28.844 us/op 1.57
vc - 250000 eb 0.95 eth1 0.3 we 0.05 wn 0 - smpl 42 19.700 us/op 11.395 us/op 1.73
vc - 250000 eb 0.95 eth1 0.7 we 0.05 wn 0 - smpl 18 17.520 us/op 11.986 us/op 1.46
vc - 250000 eb 0.1 eth1 0.1 we 0 wn 0 - smpl 1020 129.24 us/op 115.72 us/op 1.12
vc - 250000 eb 0.03 eth1 0.03 we 0 wn 0 - smpl 11777 1.1123 ms/op 795.62 us/op 1.40
vc - 250000 eb 0.01 eth1 0.01 we 0 wn 0 - smpl 16384 1.2482 ms/op 972.92 us/op 1.28
vc - 250000 eb 0 eth1 0 we 0 wn 0 - smpl 16384 1.7326 ms/op 949.41 us/op 1.82
vc - 250000 eb 0 eth1 0 we 0 wn 0 nocache - smpl 16384 4.8916 ms/op 3.0225 ms/op 1.62
vc - 250000 eb 0 eth1 1 we 0 wn 0 - smpl 16384 3.1228 ms/op 1.8979 ms/op 1.65
vc - 250000 eb 0 eth1 1 we 0 wn 0 nocache - smpl 16384 8.6871 ms/op 4.9730 ms/op 1.75
Tree 40 250000 create 1.0340 s/op 444.41 ms/op 2.33
Tree 40 250000 get(125000) 242.60 ns/op 222.09 ns/op 1.09
Tree 40 250000 set(125000) 3.0652 us/op 1.1471 us/op 2.67
Tree 40 250000 toArray() 40.857 ms/op 23.776 ms/op 1.72
Tree 40 250000 iterate all - toArray() + loop 34.223 ms/op 23.512 ms/op 1.46
Tree 40 250000 iterate all - get(i) 96.679 ms/op 83.376 ms/op 1.16
MutableVector 250000 create 16.445 ms/op 12.597 ms/op 1.31
MutableVector 250000 get(125000) 9.0320 ns/op 7.3890 ns/op 1.22
MutableVector 250000 set(125000) 709.74 ns/op 374.13 ns/op 1.90
MutableVector 250000 toArray() 5.6873 ms/op 4.4458 ms/op 1.28
MutableVector 250000 iterate all - toArray() + loop 6.8854 ms/op 5.1903 ms/op 1.33
MutableVector 250000 iterate all - get(i) 2.1456 ms/op 1.7564 ms/op 1.22
Array 250000 create 5.3825 ms/op 4.1640 ms/op 1.29
Array 250000 clone - spread 3.4745 ms/op 1.3973 ms/op 2.49
Array 250000 get(125000) 2.3310 ns/op 0.92000 ns/op 2.53
Array 250000 set(125000) 2.6320 ns/op 1.1320 ns/op 2.33
Array 250000 iterate all - loop 141.29 us/op 136.13 us/op 1.04
effectiveBalanceIncrements clone Uint8Array 300000 90.834 us/op 52.897 us/op 1.72
effectiveBalanceIncrements clone MutableVector 300000 2.1720 us/op 395.00 ns/op 5.50
effectiveBalanceIncrements rw all Uint8Array 300000 244.87 us/op 199.64 us/op 1.23
effectiveBalanceIncrements rw all MutableVector 300000 265.16 ms/op 140.89 ms/op 1.88
phase0 afterProcessEpoch - 250000 vs - 7PWei 154.40 ms/op 135.56 ms/op 1.14
phase0 beforeProcessEpoch - 250000 vs - 7PWei 67.956 ms/op 56.645 ms/op 1.20
altair processEpoch - mainnet_e81889 423.86 ms/op 383.49 ms/op 1.11
mainnet_e81889 - altair beforeProcessEpoch 91.513 ms/op 57.612 ms/op 1.59
mainnet_e81889 - altair processJustificationAndFinalization 40.521 us/op 23.089 us/op 1.75
mainnet_e81889 - altair processInactivityUpdates 6.8863 ms/op 6.5976 ms/op 1.04
mainnet_e81889 - altair processRewardsAndPenalties 68.473 ms/op 76.264 ms/op 0.90
mainnet_e81889 - altair processRegistryUpdates 2.9480 us/op 3.6270 us/op 0.81
mainnet_e81889 - altair processSlashings 543.00 ns/op 717.00 ns/op 0.76
mainnet_e81889 - altair processEth1DataReset 614.00 ns/op 1.5390 us/op 0.40
mainnet_e81889 - altair processEffectiveBalanceUpdates 1.3025 ms/op 1.4057 ms/op 0.93
mainnet_e81889 - altair processSlashingsReset 4.5080 us/op 5.8360 us/op 0.77
mainnet_e81889 - altair processRandaoMixesReset 5.0010 us/op 7.8870 us/op 0.63
mainnet_e81889 - altair processHistoricalRootsUpdate 806.00 ns/op 1.9990 us/op 0.40
mainnet_e81889 - altair processParticipationFlagUpdates 3.7730 us/op 4.9850 us/op 0.76
mainnet_e81889 - altair processSyncCommitteeUpdates 722.00 ns/op 1.4870 us/op 0.49
mainnet_e81889 - altair afterProcessEpoch 136.37 ms/op 156.47 ms/op 0.87
phase0 processEpoch - mainnet_e58758 406.72 ms/op 478.85 ms/op 0.85
mainnet_e58758 - phase0 beforeProcessEpoch 163.50 ms/op 203.08 ms/op 0.81
mainnet_e58758 - phase0 processJustificationAndFinalization 19.476 us/op 38.588 us/op 0.50
mainnet_e58758 - phase0 processRewardsAndPenalties 67.668 ms/op 74.597 ms/op 0.91
mainnet_e58758 - phase0 processRegistryUpdates 9.2010 us/op 18.995 us/op 0.48
mainnet_e58758 - phase0 processSlashings 577.00 ns/op 1.1190 us/op 0.52
mainnet_e58758 - phase0 processEth1DataReset 644.00 ns/op 1.1240 us/op 0.57
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 1.0627 ms/op 1.2444 ms/op 0.85
mainnet_e58758 - phase0 processSlashingsReset 4.1910 us/op 8.3580 us/op 0.50
mainnet_e58758 - phase0 processRandaoMixesReset 4.6760 us/op 9.2440 us/op 0.51
mainnet_e58758 - phase0 processHistoricalRootsUpdate 667.00 ns/op 1.8370 us/op 0.36
mainnet_e58758 - phase0 processParticipationRecordUpdates 4.4770 us/op 8.8200 us/op 0.51
mainnet_e58758 - phase0 afterProcessEpoch 103.84 ms/op 122.93 ms/op 0.84
phase0 processEffectiveBalanceUpdates - 250000 normalcase 1.2989 ms/op 1.7036 ms/op 0.76
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.6133 ms/op 2.7409 ms/op 0.59
altair processInactivityUpdates - 250000 normalcase 32.870 ms/op 28.574 ms/op 1.15
altair processInactivityUpdates - 250000 worstcase 31.023 ms/op 38.834 ms/op 0.80
phase0 processRegistryUpdates - 250000 normalcase 8.8440 us/op 16.973 us/op 0.52
phase0 processRegistryUpdates - 250000 badcase_full_deposits 274.45 us/op 420.28 us/op 0.65
phase0 processRegistryUpdates - 250000 worstcase 0.5 132.13 ms/op 166.67 ms/op 0.79
altair processRewardsAndPenalties - 250000 normalcase 68.532 ms/op 89.942 ms/op 0.76
altair processRewardsAndPenalties - 250000 worstcase 72.209 ms/op 85.800 ms/op 0.84
phase0 getAttestationDeltas - 250000 normalcase 6.6578 ms/op 10.541 ms/op 0.63
phase0 getAttestationDeltas - 250000 worstcase 6.5630 ms/op 10.054 ms/op 0.65
phase0 processSlashings - 250000 worstcase 4.3701 ms/op 4.6830 ms/op 0.93
altair processSyncCommitteeUpdates - 250000 178.38 ms/op 216.74 ms/op 0.82
BeaconState.hashTreeRoot - No change 262.00 ns/op 423.00 ns/op 0.62
BeaconState.hashTreeRoot - 1 full validator 53.135 us/op 65.632 us/op 0.81
BeaconState.hashTreeRoot - 32 full validator 567.49 us/op 602.36 us/op 0.94
BeaconState.hashTreeRoot - 512 full validator 5.0448 ms/op 7.3435 ms/op 0.69
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 66.988 us/op 76.593 us/op 0.87
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 896.58 us/op 1.1034 ms/op 0.81
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 11.929 ms/op 13.084 ms/op 0.91
BeaconState.hashTreeRoot - 1 balances 50.291 us/op 60.685 us/op 0.83
BeaconState.hashTreeRoot - 32 balances 466.23 us/op 522.99 us/op 0.89
BeaconState.hashTreeRoot - 512 balances 4.4822 ms/op 5.5006 ms/op 0.81
BeaconState.hashTreeRoot - 250000 balances 76.927 ms/op 88.312 ms/op 0.87
aggregationBits - 2048 els - zipIndexesInBitList 16.609 us/op 23.051 us/op 0.72
regular array get 100000 times 33.795 us/op 45.866 us/op 0.74
wrappedArray get 100000 times 33.772 us/op 48.544 us/op 0.70
arrayWithProxy get 100000 times 17.000 ms/op 19.957 ms/op 0.85
ssz.Root.equals 562.00 ns/op 634.00 ns/op 0.89
byteArrayEquals 563.00 ns/op 647.00 ns/op 0.87
shuffle list - 16384 els 7.1789 ms/op 8.0841 ms/op 0.89
shuffle list - 250000 els 104.30 ms/op 120.16 ms/op 0.87
processSlot - 1 slots 8.7530 us/op 10.892 us/op 0.80
processSlot - 32 slots 1.3761 ms/op 1.5695 ms/op 0.88
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 36.884 ms/op 39.212 ms/op 0.94
getCommitteeAssignments - req 1 vs - 250000 vc 2.9690 ms/op 3.4146 ms/op 0.87
getCommitteeAssignments - req 100 vs - 250000 vc 4.2372 ms/op 4.8364 ms/op 0.88
getCommitteeAssignments - req 1000 vs - 250000 vc 4.5855 ms/op 5.2854 ms/op 0.87
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 4.8400 ns/op 5.6200 ns/op 0.86
state getBlockRootAtSlot - 250000 vs - 7PWei 641.64 ns/op 967.06 ns/op 0.66
computeProposers - vc 250000 10.556 ms/op 12.844 ms/op 0.82
computeEpochShuffling - vc 250000 102.92 ms/op 120.11 ms/op 0.86
getNextSyncCommittee - vc 250000 170.84 ms/op 202.63 ms/op 0.84
computeSigningRoot for AttestationData 12.789 us/op 15.432 us/op 0.83
hash AttestationData serialized data then Buffer.toString(base64) 2.4477 us/op 2.8782 us/op 0.85
toHexString serialized data 1.0726 us/op 1.2306 us/op 0.87
Buffer.toString(base64) 333.86 ns/op 357.50 ns/op 0.93

by benchmarkbot/action

@twoeths twoeths force-pushed the tuyen/state_verify_attestations branch from bf74eae to 508274f Compare May 23, 2023 03:14
@twoeths
Copy link
Contributor Author

twoeths commented May 23, 2023

Tested for some days on a mainnet node lodestar_gossip_attestation_use_head_block_state_dialed_to_target_epoch_count shows no value. Ready for review.

@twoeths twoeths marked this pull request as ready for review May 23, 2023 03:42
@twoeths twoeths requested a review from a team as a code owner May 23, 2023 03:42
Copy link
Member

@wemeetagain wemeetagain left a comment

Choose a reason for hiding this comment

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

remove stale comments

Copy link
Member

@wemeetagain wemeetagain left a comment

Choose a reason for hiding this comment

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

lgtm

@wemeetagain wemeetagain merged commit 172d181 into unstable May 24, 2023
11 checks passed
@wemeetagain wemeetagain deleted the tuyen/state_verify_attestations branch May 24, 2023 16:38
@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.

Use proper state to verify attestations Wrong state in attestation validation
2 participants