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: improve processSlashings #6121

Merged
merged 7 commits into from
Dec 1, 2023
Merged

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented Nov 23, 2023

Motivation

  • Improve processSlashings() which only run when there are validators getting slashed

Description

  • Resolves all TODOs for state.slashings:
    • Cache total slashings in EpochCache so that we don't need to compute in processSlashings
    • With that we can store state.slashings as number[] instead of BigInt[]
  • Update slashing penalties once in processRewardsAndPenalties
  • Also no need to recompute slashing penalties for validators with the same effective balance

part of #6112

part of #5892

Testing

  • This reduces the processSlashing() to almost zero cost.
  • Before
phase0 processSlashings
✔ phase0 processSlashings - 250000 worstcase                          377.9087 ops/s    2.646142 ms/op        -        858 runs   14.7 s
  • After
phase0 processSlashings
✔ phase0 processSlashings - 250000 worstcase                          10352.72 ops/s    96.59300 us/op        -       1647 runs   14.0 s

Copy link
Contributor

github-actions bot commented Nov 23, 2023

Performance Report

✔️ no performance regression detected

🚀🚀 Significant benchmark improvement detected

Benchmark suite Current: 67f801c Previous: 248b64c Ratio
phase0 processSlashings - 250000 worstcase 81.754 us/op 1.5516 ms/op 0.05
Full benchmark results
Benchmark suite Current: 67f801c Previous: 248b64c Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 738.36 us/op 721.34 us/op 1.02
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 158.63 us/op 58.808 us/op 2.70
BLS verify - blst-native 1.3803 ms/op 1.0515 ms/op 1.31
BLS verifyMultipleSignatures 3 - blst-native 2.8990 ms/op 2.2681 ms/op 1.28
BLS verifyMultipleSignatures 8 - blst-native 6.3556 ms/op 4.9597 ms/op 1.28
BLS verifyMultipleSignatures 32 - blst-native 23.325 ms/op 18.263 ms/op 1.28
BLS verifyMultipleSignatures 64 - blst-native 46.077 ms/op 36.052 ms/op 1.28
BLS verifyMultipleSignatures 128 - blst-native 95.731 ms/op 72.656 ms/op 1.32
BLS deserializing 10000 signatures 969.36 ms/op 782.41 ms/op 1.24
BLS deserializing 100000 signatures 9.5830 s/op 7.8599 s/op 1.22
BLS verifyMultipleSignatures - same message - 3 - blst-native 1.3819 ms/op 1.0825 ms/op 1.28
BLS verifyMultipleSignatures - same message - 8 - blst-native 1.5601 ms/op 1.2389 ms/op 1.26
BLS verifyMultipleSignatures - same message - 32 - blst-native 2.4077 ms/op 1.9340 ms/op 1.24
BLS verifyMultipleSignatures - same message - 64 - blst-native 4.2276 ms/op 3.5968 ms/op 1.18
BLS verifyMultipleSignatures - same message - 128 - blst-native 5.7888 ms/op 4.7065 ms/op 1.23
BLS aggregatePubkeys 32 - blst-native 26.255 us/op 21.629 us/op 1.21
BLS aggregatePubkeys 128 - blst-native 103.27 us/op 84.790 us/op 1.22
getAttestationsForBlock 46.679 ms/op 38.722 ms/op 1.21
isKnown best case - 1 super set check 425.00 ns/op 402.00 ns/op 1.06
isKnown normal case - 2 super set checks 440.00 ns/op 372.00 ns/op 1.18
isKnown worse case - 16 super set checks 407.00 ns/op 346.00 ns/op 1.18
CheckpointStateCache - add get delete 6.6150 us/op 4.1430 us/op 1.60
validate api signedAggregateAndProof - struct 2.8090 ms/op 2.3151 ms/op 1.21
validate gossip signedAggregateAndProof - struct 2.8086 ms/op 2.3302 ms/op 1.21
validate gossip attestation - vc 640000 1.3703 ms/op 1.1339 ms/op 1.21
batch validate gossip attestation - vc 640000 - chunk 32 163.82 us/op 139.84 us/op 1.17
batch validate gossip attestation - vc 640000 - chunk 64 146.17 us/op 127.15 us/op 1.15
batch validate gossip attestation - vc 640000 - chunk 128 133.01 us/op 119.58 us/op 1.11
batch validate gossip attestation - vc 640000 - chunk 256 130.68 us/op 112.93 us/op 1.16
pickEth1Vote - no votes 1.2133 ms/op 883.95 us/op 1.37
pickEth1Vote - max votes 10.642 ms/op 5.8068 ms/op 1.83
pickEth1Vote - Eth1Data hashTreeRoot value x2048 17.657 ms/op 11.492 ms/op 1.54
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 27.602 ms/op 18.392 ms/op 1.50
pickEth1Vote - Eth1Data fastSerialize value x2048 719.14 us/op 418.07 us/op 1.72
pickEth1Vote - Eth1Data fastSerialize tree x2048 5.0353 ms/op 4.5388 ms/op 1.11
bytes32 toHexString 490.00 ns/op 453.00 ns/op 1.08
bytes32 Buffer.toString(hex) 273.00 ns/op 343.00 ns/op 0.80
bytes32 Buffer.toString(hex) from Uint8Array 437.00 ns/op 429.00 ns/op 1.02
bytes32 Buffer.toString(hex) + 0x 283.00 ns/op 315.00 ns/op 0.90
Object access 1 prop 0.15300 ns/op 0.19900 ns/op 0.77
Map access 1 prop 0.13500 ns/op 0.18400 ns/op 0.73
Object get x1000 6.8870 ns/op 5.6730 ns/op 1.21
Map get x1000 0.73600 ns/op 0.75100 ns/op 0.98
Object set x1000 49.160 ns/op 25.555 ns/op 1.92
Map set x1000 38.496 ns/op 17.117 ns/op 2.25
Return object 10000 times 0.23820 ns/op 0.22740 ns/op 1.05
Throw Error 10000 times 3.8265 us/op 2.8388 us/op 1.35
fastMsgIdFn sha256 / 200 bytes 3.2330 us/op 1.9610 us/op 1.65
fastMsgIdFn h32 xxhash / 200 bytes 264.00 ns/op 301.00 ns/op 0.88
fastMsgIdFn h64 xxhash / 200 bytes 331.00 ns/op 346.00 ns/op 0.96
fastMsgIdFn sha256 / 1000 bytes 11.304 us/op 6.1810 us/op 1.83
fastMsgIdFn h32 xxhash / 1000 bytes 399.00 ns/op 426.00 ns/op 0.94
fastMsgIdFn h64 xxhash / 1000 bytes 400.00 ns/op 414.00 ns/op 0.97
fastMsgIdFn sha256 / 10000 bytes 102.64 us/op 53.542 us/op 1.92
fastMsgIdFn h32 xxhash / 10000 bytes 1.8840 us/op 1.8330 us/op 1.03
fastMsgIdFn h64 xxhash / 10000 bytes 1.2700 us/op 1.2470 us/op 1.02
send data - 1000 256B messages 19.740 ms/op 11.414 ms/op 1.73
send data - 1000 512B messages 27.415 ms/op 15.324 ms/op 1.79
send data - 1000 1024B messages 40.599 ms/op 22.410 ms/op 1.81
send data - 1000 1200B messages 31.989 ms/op 26.448 ms/op 1.21
send data - 1000 2048B messages 39.959 ms/op 33.577 ms/op 1.19
send data - 1000 4096B messages 39.859 ms/op 30.003 ms/op 1.33
send data - 1000 16384B messages 101.86 ms/op 82.027 ms/op 1.24
send data - 1000 65536B messages 395.77 ms/op 445.16 ms/op 0.89
enrSubnets - fastDeserialize 64 bits 1.2380 us/op 1.0110 us/op 1.22
enrSubnets - ssz BitVector 64 bits 413.00 ns/op 410.00 ns/op 1.01
enrSubnets - fastDeserialize 4 bits 160.00 ns/op 203.00 ns/op 0.79
enrSubnets - ssz BitVector 4 bits 405.00 ns/op 410.00 ns/op 0.99
prioritizePeers score -10:0 att 32-0.1 sync 2-0 98.629 us/op 65.784 us/op 1.50
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 125.52 us/op 77.930 us/op 1.61
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 176.66 us/op 110.21 us/op 1.60
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 309.53 us/op 191.78 us/op 1.61
prioritizePeers score 0:0 att 64-1 sync 4-1 349.33 us/op 206.89 us/op 1.69
array of 16000 items push then shift 1.6458 us/op 1.3376 us/op 1.23
LinkedList of 16000 items push then shift 9.0400 ns/op 6.1020 ns/op 1.48
array of 16000 items push then pop 91.435 ns/op 70.466 ns/op 1.30
LinkedList of 16000 items push then pop 8.7680 ns/op 5.7750 ns/op 1.52
array of 24000 items push then shift 2.4740 us/op 1.9458 us/op 1.27
LinkedList of 24000 items push then shift 9.0480 ns/op 6.5830 ns/op 1.37
array of 24000 items push then pop 115.22 ns/op 86.333 ns/op 1.33
LinkedList of 24000 items push then pop 8.6740 ns/op 6.0010 ns/op 1.45
intersect bitArray bitLen 8 6.4650 ns/op 5.3650 ns/op 1.21
intersect array and set length 8 62.787 ns/op 49.134 ns/op 1.28
intersect bitArray bitLen 128 34.181 ns/op 28.040 ns/op 1.22
intersect array and set length 128 864.62 ns/op 690.90 ns/op 1.25
bitArray.getTrueBitIndexes() bitLen 128 1.5100 us/op 1.2030 us/op 1.26
bitArray.getTrueBitIndexes() bitLen 248 2.4630 us/op 1.9010 us/op 1.30
bitArray.getTrueBitIndexes() bitLen 512 4.8590 us/op 3.7810 us/op 1.29
Buffer.concat 32 items 971.00 ns/op 943.00 ns/op 1.03
Uint8Array.set 32 items 2.3020 us/op 1.8880 us/op 1.22
Set add up to 64 items then delete first 4.3607 us/op 1.7847 us/op 2.44
OrderedSet add up to 64 items then delete first 5.4620 us/op 2.6867 us/op 2.03
Set add up to 64 items then delete last 4.7104 us/op 1.9878 us/op 2.37
OrderedSet add up to 64 items then delete last 6.1457 us/op 2.9900 us/op 2.06
Set add up to 64 items then delete middle 4.7397 us/op 2.0418 us/op 2.32
OrderedSet add up to 64 items then delete middle 7.3215 us/op 4.1934 us/op 1.75
Set add up to 128 items then delete first 9.3527 us/op 3.9054 us/op 2.39
OrderedSet add up to 128 items then delete first 12.146 us/op 6.1387 us/op 1.98
Set add up to 128 items then delete last 9.5717 us/op 4.1001 us/op 2.33
OrderedSet add up to 128 items then delete last 12.584 us/op 5.7025 us/op 2.21
Set add up to 128 items then delete middle 9.4431 us/op 3.8006 us/op 2.48
OrderedSet add up to 128 items then delete middle 18.847 us/op 10.663 us/op 1.77
Set add up to 256 items then delete first 20.390 us/op 7.6962 us/op 2.65
OrderedSet add up to 256 items then delete first 26.735 us/op 12.213 us/op 2.19
Set add up to 256 items then delete last 20.308 us/op 7.5426 us/op 2.69
OrderedSet add up to 256 items then delete last 29.158 us/op 11.402 us/op 2.56
Set add up to 256 items then delete middle 19.639 us/op 7.4030 us/op 2.65
OrderedSet add up to 256 items then delete middle 49.967 us/op 31.129 us/op 1.61
transfer serialized Status (84 B) 1.9500 us/op 1.4330 us/op 1.36
copy serialized Status (84 B) 1.7320 us/op 1.2470 us/op 1.39
transfer serialized SignedVoluntaryExit (112 B) 1.9230 us/op 1.4550 us/op 1.32
copy serialized SignedVoluntaryExit (112 B) 1.7650 us/op 1.3060 us/op 1.35
transfer serialized ProposerSlashing (416 B) 2.5070 us/op 2.6570 us/op 0.94
copy serialized ProposerSlashing (416 B) 2.7830 us/op 2.1320 us/op 1.31
transfer serialized Attestation (485 B) 2.7680 us/op 2.0110 us/op 1.38
copy serialized Attestation (485 B) 2.6980 us/op 2.1710 us/op 1.24
transfer serialized AttesterSlashing (33232 B) 2.8490 us/op 2.3660 us/op 1.20
copy serialized AttesterSlashing (33232 B) 6.9170 us/op 5.6280 us/op 1.23
transfer serialized Small SignedBeaconBlock (128000 B) 3.4330 us/op 2.9380 us/op 1.17
copy serialized Small SignedBeaconBlock (128000 B) 16.205 us/op 10.130 us/op 1.60
transfer serialized Avg SignedBeaconBlock (200000 B) 3.5060 us/op 2.9440 us/op 1.19
copy serialized Avg SignedBeaconBlock (200000 B) 24.279 us/op 13.529 us/op 1.79
transfer serialized BlobsSidecar (524380 B) 3.7780 us/op 2.6140 us/op 1.45
copy serialized BlobsSidecar (524380 B) 104.68 us/op 83.466 us/op 1.25
transfer serialized Big SignedBeaconBlock (1000000 B) 4.0920 us/op 2.8590 us/op 1.43
copy serialized Big SignedBeaconBlock (1000000 B) 186.07 us/op 230.34 us/op 0.81
pass gossip attestations to forkchoice per slot 4.2100 ms/op 2.7913 ms/op 1.51
forkChoice updateHead vc 100000 bc 64 eq 0 697.61 us/op 464.07 us/op 1.50
forkChoice updateHead vc 600000 bc 64 eq 0 5.1499 ms/op 2.9140 ms/op 1.77
forkChoice updateHead vc 1000000 bc 64 eq 0 7.3553 ms/op 4.3870 ms/op 1.68
forkChoice updateHead vc 600000 bc 320 eq 0 4.2503 ms/op 2.5996 ms/op 1.63
forkChoice updateHead vc 600000 bc 1200 eq 0 4.3117 ms/op 2.7985 ms/op 1.54
forkChoice updateHead vc 600000 bc 7200 eq 0 5.3776 ms/op 3.4079 ms/op 1.58
forkChoice updateHead vc 600000 bc 64 eq 1000 11.275 ms/op 9.9445 ms/op 1.13
forkChoice updateHead vc 600000 bc 64 eq 10000 12.081 ms/op 9.6908 ms/op 1.25
forkChoice updateHead vc 600000 bc 64 eq 300000 16.652 ms/op 12.088 ms/op 1.38
computeDeltas 500000 validators 300 proto nodes 6.6927 ms/op 3.2696 ms/op 2.05
computeDeltas 500000 validators 1200 proto nodes 6.5523 ms/op 3.1771 ms/op 2.06
computeDeltas 500000 validators 7200 proto nodes 6.4581 ms/op 3.0388 ms/op 2.13
computeDeltas 750000 validators 300 proto nodes 10.074 ms/op 4.6756 ms/op 2.15
computeDeltas 750000 validators 1200 proto nodes 9.8938 ms/op 4.7163 ms/op 2.10
computeDeltas 750000 validators 7200 proto nodes 9.9718 ms/op 4.5701 ms/op 2.18
computeDeltas 1400000 validators 300 proto nodes 18.421 ms/op 8.8973 ms/op 2.07
computeDeltas 1400000 validators 1200 proto nodes 18.829 ms/op 9.6214 ms/op 1.96
computeDeltas 1400000 validators 7200 proto nodes 18.856 ms/op 9.7586 ms/op 1.93
computeDeltas 2100000 validators 300 proto nodes 27.676 ms/op 14.877 ms/op 1.86
computeDeltas 2100000 validators 1200 proto nodes 27.386 ms/op 14.355 ms/op 1.91
computeDeltas 2100000 validators 7200 proto nodes 27.602 ms/op 15.613 ms/op 1.77
computeProposerBoostScoreFromBalances 500000 validators 3.7734 ms/op 3.5260 ms/op 1.07
computeProposerBoostScoreFromBalances 750000 validators 3.7956 ms/op 3.5423 ms/op 1.07
computeProposerBoostScoreFromBalances 1400000 validators 3.8254 ms/op 3.6051 ms/op 1.06
computeProposerBoostScoreFromBalances 2100000 validators 3.8179 ms/op 3.4655 ms/op 1.10
altair processAttestation - 250000 vs - 7PWei normalcase 2.3028 ms/op 1.9945 ms/op 1.15
altair processAttestation - 250000 vs - 7PWei worstcase 3.2004 ms/op 2.5389 ms/op 1.26
altair processAttestation - setStatus - 1/6 committees join 152.24 us/op 112.30 us/op 1.36
altair processAttestation - setStatus - 1/3 committees join 287.01 us/op 200.05 us/op 1.43
altair processAttestation - setStatus - 1/2 committees join 384.51 us/op 292.82 us/op 1.31
altair processAttestation - setStatus - 2/3 committees join 493.12 us/op 385.31 us/op 1.28
altair processAttestation - setStatus - 4/5 committees join 695.81 us/op 520.95 us/op 1.34
altair processAttestation - setStatus - 100% committees join 834.83 us/op 602.82 us/op 1.38
altair processBlock - 250000 vs - 7PWei normalcase 9.9465 ms/op 8.4755 ms/op 1.17
altair processBlock - 250000 vs - 7PWei normalcase hashState 37.179 ms/op 33.145 ms/op 1.12
altair processBlock - 250000 vs - 7PWei worstcase 37.993 ms/op 36.089 ms/op 1.05
altair processBlock - 250000 vs - 7PWei worstcase hashState 101.40 ms/op 79.849 ms/op 1.27
phase0 processBlock - 250000 vs - 7PWei normalcase 2.8901 ms/op 2.5830 ms/op 1.12
phase0 processBlock - 250000 vs - 7PWei worstcase 32.297 ms/op 27.429 ms/op 1.18
altair processEth1Data - 250000 vs - 7PWei normalcase 607.84 us/op 380.20 us/op 1.60
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 10.251 us/op 10.784 us/op 0.95
getExpectedWithdrawals 250000 eb:0.95,eth1:0.1,we:0.05,wn:0,smpl:219 79.606 us/op 46.181 us/op 1.72
getExpectedWithdrawals 250000 eb:0.95,eth1:0.3,we:0.05,wn:0,smpl:42 19.420 us/op 17.702 us/op 1.10
getExpectedWithdrawals 250000 eb:0.95,eth1:0.7,we:0.05,wn:0,smpl:18 12.588 us/op 13.092 us/op 0.96
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 207.28 us/op 173.32 us/op 1.20
getExpectedWithdrawals 250000 eb:0.03,eth1:0.03,we:0,wn:0,smpl:11777 1.3485 ms/op 939.51 us/op 1.44
getExpectedWithdrawals 250000 eb:0.01,eth1:0.01,we:0,wn:0,smpl:16384 1.6061 ms/op 1.5439 ms/op 1.04
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,smpl:16384 1.6116 ms/op 1.4320 ms/op 1.13
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,nocache,smpl:16384 3.6803 ms/op 2.5264 ms/op 1.46
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,smpl:16384 3.4828 ms/op 2.1984 ms/op 1.58
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,nocache,smpl:16384 5.8735 ms/op 3.5885 ms/op 1.64
Tree 40 250000 create 378.71 ms/op 293.89 ms/op 1.29
Tree 40 250000 get(125000) 209.78 ns/op 112.83 ns/op 1.86
Tree 40 250000 set(125000) 1.0249 us/op 777.66 ns/op 1.32
Tree 40 250000 toArray() 21.257 ms/op 20.763 ms/op 1.02
Tree 40 250000 iterate all - toArray() + loop 22.241 ms/op 11.185 ms/op 1.99
Tree 40 250000 iterate all - get(i) 74.008 ms/op 48.869 ms/op 1.51
MutableVector 250000 create 12.602 ms/op 8.4395 ms/op 1.49
MutableVector 250000 get(125000) 6.7100 ns/op 6.0770 ns/op 1.10
MutableVector 250000 set(125000) 297.71 ns/op 272.31 ns/op 1.09
MutableVector 250000 toArray() 5.4973 ms/op 3.1450 ms/op 1.75
MutableVector 250000 iterate all - toArray() + loop 4.1570 ms/op 2.3390 ms/op 1.78
MutableVector 250000 iterate all - get(i) 1.5778 ms/op 1.3331 ms/op 1.18
Array 250000 create 4.0962 ms/op 2.5315 ms/op 1.62
Array 250000 clone - spread 1.2585 ms/op 1.1630 ms/op 1.08
Array 250000 get(125000) 1.0370 ns/op 1.0360 ns/op 1.00
Array 250000 set(125000) 4.2440 ns/op 1.2550 ns/op 3.38
Array 250000 iterate all - loop 170.51 us/op 158.29 us/op 1.08
effectiveBalanceIncrements clone Uint8Array 300000 46.511 us/op 14.548 us/op 3.20
effectiveBalanceIncrements clone MutableVector 300000 366.00 ns/op 403.00 ns/op 0.91
effectiveBalanceIncrements rw all Uint8Array 300000 210.38 us/op 187.15 us/op 1.12
effectiveBalanceIncrements rw all MutableVector 300000 91.536 ms/op 62.846 ms/op 1.46
phase0 afterProcessEpoch - 250000 vs - 7PWei 116.96 ms/op 77.246 ms/op 1.51
phase0 beforeProcessEpoch - 250000 vs - 7PWei 51.291 ms/op 33.808 ms/op 1.52
altair processEpoch - mainnet_e81889 490.68 ms/op 434.93 ms/op 1.13
mainnet_e81889 - altair beforeProcessEpoch 78.330 ms/op 73.883 ms/op 1.06
mainnet_e81889 - altair processJustificationAndFinalization 14.017 us/op 19.055 us/op 0.74
mainnet_e81889 - altair processInactivityUpdates 5.6905 ms/op 4.2335 ms/op 1.34
mainnet_e81889 - altair processRewardsAndPenalties 60.393 ms/op 57.498 ms/op 1.05
mainnet_e81889 - altair processRegistryUpdates 2.7370 us/op 3.2570 us/op 0.84
mainnet_e81889 - altair processSlashings 457.00 ns/op 1.0360 us/op 0.44
mainnet_e81889 - altair processEth1DataReset 488.00 ns/op 985.00 ns/op 0.50
mainnet_e81889 - altair processEffectiveBalanceUpdates 1.9337 ms/op 1.0035 ms/op 1.93
mainnet_e81889 - altair processSlashingsReset 4.6730 us/op 4.4710 us/op 1.05
mainnet_e81889 - altair processRandaoMixesReset 4.8790 us/op 5.8480 us/op 0.83
mainnet_e81889 - altair processHistoricalRootsUpdate 637.00 ns/op 1.0290 us/op 0.62
mainnet_e81889 - altair processParticipationFlagUpdates 1.6920 us/op 2.8930 us/op 0.58
mainnet_e81889 - altair processSyncCommitteeUpdates 755.00 ns/op 1.0170 us/op 0.74
mainnet_e81889 - altair afterProcessEpoch 121.88 ms/op 84.825 ms/op 1.44
capella processEpoch - mainnet_e217614 2.2486 s/op 1.7560 s/op 1.28
mainnet_e217614 - capella beforeProcessEpoch 468.41 ms/op 387.88 ms/op 1.21
mainnet_e217614 - capella processJustificationAndFinalization 17.899 us/op 7.0120 us/op 2.55
mainnet_e217614 - capella processInactivityUpdates 21.708 ms/op 16.742 ms/op 1.30
mainnet_e217614 - capella processRewardsAndPenalties 460.57 ms/op 461.03 ms/op 1.00
mainnet_e217614 - capella processRegistryUpdates 32.493 us/op 20.778 us/op 1.56
mainnet_e217614 - capella processSlashings 610.00 ns/op 679.00 ns/op 0.90
mainnet_e217614 - capella processEth1DataReset 760.00 ns/op 611.00 ns/op 1.24
mainnet_e217614 - capella processEffectiveBalanceUpdates 6.8739 ms/op 3.4500 ms/op 1.99
mainnet_e217614 - capella processSlashingsReset 6.6290 us/op 1.9930 us/op 3.33
mainnet_e217614 - capella processRandaoMixesReset 6.8880 us/op 3.5150 us/op 1.96
mainnet_e217614 - capella processHistoricalRootsUpdate 805.00 ns/op 572.00 ns/op 1.41
mainnet_e217614 - capella processParticipationFlagUpdates 4.2930 us/op 1.6460 us/op 2.61
mainnet_e217614 - capella afterProcessEpoch 344.11 ms/op 213.00 ms/op 1.62
phase0 processEpoch - mainnet_e58758 527.76 ms/op 361.74 ms/op 1.46
mainnet_e58758 - phase0 beforeProcessEpoch 155.71 ms/op 124.49 ms/op 1.25
mainnet_e58758 - phase0 processJustificationAndFinalization 16.406 us/op 11.938 us/op 1.37
mainnet_e58758 - phase0 processRewardsAndPenalties 50.324 ms/op 51.115 ms/op 0.98
mainnet_e58758 - phase0 processRegistryUpdates 11.455 us/op 6.4010 us/op 1.79
mainnet_e58758 - phase0 processSlashings 552.00 ns/op 617.00 ns/op 0.89
mainnet_e58758 - phase0 processEth1DataReset 426.00 ns/op 547.00 ns/op 0.78
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 1.1797 ms/op 880.36 us/op 1.34
mainnet_e58758 - phase0 processSlashingsReset 2.8950 us/op 2.4690 us/op 1.17
mainnet_e58758 - phase0 processRandaoMixesReset 3.7690 us/op 2.9070 us/op 1.30
mainnet_e58758 - phase0 processHistoricalRootsUpdate 407.00 ns/op 519.00 ns/op 0.78
mainnet_e58758 - phase0 processParticipationRecordUpdates 3.3870 us/op 3.3650 us/op 1.01
mainnet_e58758 - phase0 afterProcessEpoch 103.14 ms/op 65.205 ms/op 1.58
phase0 processEffectiveBalanceUpdates - 250000 normalcase 1.4027 ms/op 991.60 us/op 1.41
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.5450 ms/op 1.1226 ms/op 1.38
altair processInactivityUpdates - 250000 normalcase 22.867 ms/op 16.574 ms/op 1.38
altair processInactivityUpdates - 250000 worstcase 25.999 ms/op 18.375 ms/op 1.41
phase0 processRegistryUpdates - 250000 normalcase 10.000 us/op 5.4020 us/op 1.85
phase0 processRegistryUpdates - 250000 badcase_full_deposits 356.24 us/op 348.06 us/op 1.02
phase0 processRegistryUpdates - 250000 worstcase 0.5 125.95 ms/op 105.99 ms/op 1.19
altair processRewardsAndPenalties - 250000 normalcase 54.785 ms/op 67.200 ms/op 0.82
altair processRewardsAndPenalties - 250000 worstcase 54.202 ms/op 64.456 ms/op 0.84
phase0 getAttestationDeltas - 250000 normalcase 8.8025 ms/op 5.5742 ms/op 1.58
phase0 getAttestationDeltas - 250000 worstcase 8.8138 ms/op 5.1119 ms/op 1.72
phase0 processSlashings - 250000 worstcase 81.754 us/op 1.5516 ms/op 0.05
altair processSyncCommitteeUpdates - 250000 153.73 ms/op 112.51 ms/op 1.37
BeaconState.hashTreeRoot - No change 247.00 ns/op 313.00 ns/op 0.79
BeaconState.hashTreeRoot - 1 full validator 120.07 us/op 138.40 us/op 0.87
BeaconState.hashTreeRoot - 32 full validator 1.2690 ms/op 1.1668 ms/op 1.09
BeaconState.hashTreeRoot - 512 full validator 12.763 ms/op 16.894 ms/op 0.76
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 144.56 us/op 106.30 us/op 1.36
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 1.9480 ms/op 1.4698 ms/op 1.33
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 24.316 ms/op 19.708 ms/op 1.23
BeaconState.hashTreeRoot - 1 balances 118.59 us/op 91.520 us/op 1.30
BeaconState.hashTreeRoot - 32 balances 1.0967 ms/op 859.43 us/op 1.28
BeaconState.hashTreeRoot - 512 balances 10.129 ms/op 9.9996 ms/op 1.01
BeaconState.hashTreeRoot - 250000 balances 186.84 ms/op 193.97 ms/op 0.96
aggregationBits - 2048 els - zipIndexesInBitList 17.070 us/op 16.946 us/op 1.01
byteArrayEquals 32 75.742 ns/op 62.998 ns/op 1.20
Buffer.compare 32 56.237 ns/op 38.567 ns/op 1.46
byteArrayEquals 1024 2.0487 us/op 1.6782 us/op 1.22
Buffer.compare 1024 71.325 ns/op 45.343 ns/op 1.57
byteArrayEquals 16384 32.645 us/op 26.329 us/op 1.24
Buffer.compare 16384 269.95 ns/op 216.89 ns/op 1.24
byteArrayEquals 123687377 245.04 ms/op 214.82 ms/op 1.14
Buffer.compare 123687377 6.9595 ms/op 7.5090 ms/op 0.93
byteArrayEquals 32 - diff last byte 73.277 ns/op 68.630 ns/op 1.07
Buffer.compare 32 - diff last byte 57.296 ns/op 45.048 ns/op 1.27
byteArrayEquals 1024 - diff last byte 2.0786 us/op 1.7132 us/op 1.21
Buffer.compare 1024 - diff last byte 71.800 ns/op 45.591 ns/op 1.57
byteArrayEquals 16384 - diff last byte 33.046 us/op 27.095 us/op 1.22
Buffer.compare 16384 - diff last byte 285.98 ns/op 225.05 ns/op 1.27
byteArrayEquals 123687377 - diff last byte 247.96 ms/op 219.52 ms/op 1.13
Buffer.compare 123687377 - diff last byte 6.7163 ms/op 7.3654 ms/op 0.91
byteArrayEquals 32 - random bytes 5.4740 ns/op 5.5610 ns/op 0.98
Buffer.compare 32 - random bytes 61.589 ns/op 39.037 ns/op 1.58
byteArrayEquals 1024 - random bytes 5.2290 ns/op 5.8130 ns/op 0.90
Buffer.compare 1024 - random bytes 61.318 ns/op 38.284 ns/op 1.60
byteArrayEquals 16384 - random bytes 5.2700 ns/op 5.8640 ns/op 0.90
Buffer.compare 16384 - random bytes 61.774 ns/op 37.548 ns/op 1.65
byteArrayEquals 123687377 - random bytes 8.3500 ns/op 19.090 ns/op 0.44
Buffer.compare 123687377 - random bytes 64.170 ns/op 49.110 ns/op 1.31
regular array get 100000 times 44.456 us/op 43.738 us/op 1.02
wrappedArray get 100000 times 45.119 us/op 41.745 us/op 1.08
arrayWithProxy get 100000 times 15.136 ms/op 10.900 ms/op 1.39
ssz.Root.equals 54.161 ns/op 55.577 ns/op 0.97
byteArrayEquals 53.294 ns/op 54.777 ns/op 0.97
Buffer.compare 17.135 ns/op 10.403 ns/op 1.65
shuffle list - 16384 els 7.0035 ms/op 4.8334 ms/op 1.45
shuffle list - 250000 els 103.12 ms/op 71.351 ms/op 1.45
processSlot - 1 slots 15.832 us/op 15.697 us/op 1.01
processSlot - 32 slots 2.9972 ms/op 2.8431 ms/op 1.05
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 54.090 ms/op 49.134 ms/op 1.10
getCommitteeAssignments - req 1 vs - 250000 vc 2.5255 ms/op 2.1878 ms/op 1.15
getCommitteeAssignments - req 100 vs - 250000 vc 3.7544 ms/op 3.6931 ms/op 1.02
getCommitteeAssignments - req 1000 vs - 250000 vc 4.1114 ms/op 3.7812 ms/op 1.09
findModifiedValidators - 10000 modified validators 527.55 ms/op 492.69 ms/op 1.07
findModifiedValidators - 1000 modified validators 416.07 ms/op 350.93 ms/op 1.19
findModifiedValidators - 100 modified validators 430.22 ms/op 351.96 ms/op 1.22
findModifiedValidators - 10 modified validators 398.13 ms/op 320.67 ms/op 1.24
findModifiedValidators - 1 modified validators 409.26 ms/op 321.48 ms/op 1.27
findModifiedValidators - no difference 418.41 ms/op 308.34 ms/op 1.36
compare ViewDUs 4.3410 s/op 4.1643 s/op 1.04
compare each validator Uint8Array 1.2380 s/op 1.4691 s/op 0.84
compare ViewDU to Uint8Array 1.1218 s/op 1.0421 s/op 1.08
migrate state 1000000 validators, 24 modified, 0 new 781.13 ms/op 754.71 ms/op 1.04
migrate state 1000000 validators, 1700 modified, 1000 new 1.0251 s/op 994.20 ms/op 1.03
migrate state 1000000 validators, 3400 modified, 2000 new 1.2937 s/op 1.2467 s/op 1.04
migrate state 1500000 validators, 24 modified, 0 new 727.76 ms/op 663.06 ms/op 1.10
migrate state 1500000 validators, 1700 modified, 1000 new 1.0675 s/op 949.23 ms/op 1.12
migrate state 1500000 validators, 3400 modified, 2000 new 1.2235 s/op 1.0932 s/op 1.12
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 4.2700 ns/op 4.0100 ns/op 1.06
state getBlockRootAtSlot - 250000 vs - 7PWei 820.70 ns/op 935.17 ns/op 0.88
computeProposers - vc 250000 9.2139 ms/op 6.8803 ms/op 1.34
computeEpochShuffling - vc 250000 104.28 ms/op 69.861 ms/op 1.49
getNextSyncCommittee - vc 250000 146.96 ms/op 114.48 ms/op 1.28
computeSigningRoot for AttestationData 26.282 us/op 30.474 us/op 0.86
hash AttestationData serialized data then Buffer.toString(base64) 2.2734 us/op 1.2555 us/op 1.81
toHexString serialized data 1.0699 us/op 867.84 ns/op 1.23
Buffer.toString(base64) 216.11 ns/op 157.25 ns/op 1.37

by benchmarkbot/action

@twoeths twoeths marked this pull request as ready for review November 23, 2023 07:25
@twoeths twoeths requested a review from a team as a code owner November 23, 2023 07:25
@twoeths twoeths mentioned this pull request Nov 23, 2023
const slashingIndex = epoch % EPOCHS_PER_SLASHINGS_VECTOR;
state.slashings.set(slashingIndex, state.slashings.get(slashingIndex) + BigInt(effectiveBalance));
state.slashings.set(slashingIndex, state.slashings.get(slashingIndex) + effectiveBalance);
epochCtx.totalSlashingsByIncrement += effectiveBalanceIncrements[slashedIndex];
Copy link
Member

Choose a reason for hiding this comment

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

can effectiveBalanceIncrements[slashedIndex] be undefined? may be worth adding ?? 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

effectiveBalanceIncrements is populated with validator count and increased its length per processDeposit so the default value for any validator index is always 0

I also doubled check all use of effectiveBalanceIncrements, we don't need to handle undefined there so I think we don't need to do it here too. For example

epochCtx.currentTargetUnslashedBalanceIncrements += effectiveBalanceIncrements[index];

const slashingIndex = epoch % EPOCHS_PER_SLASHINGS_VECTOR;
state.slashings.set(slashingIndex, state.slashings.get(slashingIndex) + BigInt(effectiveBalance));
state.slashings.set(slashingIndex, state.slashings.get(slashingIndex) + effectiveBalance);
Copy link
Member

Choose a reason for hiding this comment

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

can state.slashings.get(slashingIndex) be undefined? may be worth adding ?? 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added it 👍

@twoeths
Copy link
Contributor Author

twoeths commented Nov 24, 2023

@wemeetagain @dapplion in the last commit I added reasoning on how UintNum64 is good enough for state.slashings please have a look ac08e7d

@twoeths
Copy link
Contributor Author

twoeths commented Nov 29, 2023

@dapplion I addressed the comment in ac08e7d#r133684342

@twoeths twoeths merged commit c0c8d95 into unstable Dec 1, 2023
15 checks passed
@twoeths twoeths deleted the tuyen/improve_process_slashings branch December 1, 2023 10:49
@wemeetagain
Copy link
Member

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

None yet

3 participants