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: async shuffling refactor #6938

Merged
merged 81 commits into from
Sep 23, 2024
Merged

feat: async shuffling refactor #6938

merged 81 commits into from
Sep 23, 2024

Conversation

matthewkeil
Copy link
Member

@matthewkeil matthewkeil commented Jul 8, 2024

Motivation

Replaces #6521

Move calculation of next shuffling to async to get it off of critical path during epoch transition. There is a full second during epoch transition used to calculate the epochCtx.nextShuffling and that can be moved to an async process. Refactored a few pieces of the EpochCache to make this work and will continue under a separate PR for creating a worker that moves this calculation to a worker thread. Also will investigate using the rust shuffling implementation. Can maybe tune further using a worker thread that NICE to interleave the long calculation into thread idle time which could be ideal.

Description

  • Create IShufflingCache to pass shuffling cache to EpochCache so its available within CachedBeaconState
  • Keep ShufflingCache in beacon-node for further updates mentioned above
  • Remove calculation of nextShuffling from critical path during epoch transitions
  • Remove shufflingCache.processState from ShufflingCache and update process flow to no longer require it
  • Remove ShufflingGetter and use ShufflingCache directly

TODO's Before Review
[ ] - Investigate removal of MockShufflingCache fully (may require moving CachedBeaconState tests to beacon-node
[ ] - Verify all sim/e2e and other long running tests
[ ] - Confirm spec compliance

Copy link

codecov bot commented Jul 9, 2024

Codecov Report

Attention: Patch coverage is 35.88850% with 184 lines in your changes missing coverage. Please review.

Project coverage is 50.84%. Comparing base (19ac678) to head (af5c989).
Report is 26 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #6938      +/-   ##
============================================
+ Coverage     49.35%   50.84%   +1.49%     
============================================
  Files           592      597       +5     
  Lines         39293    39835     +542     
  Branches       2248     2058     -190     
============================================
+ Hits          19392    20254     +862     
+ Misses        19860    19581     -279     
+ Partials         41        0      -41     

Copy link
Contributor

github-actions bot commented Jul 11, 2024

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: 67ec051 Previous: bb40ef7 Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 1.9468 ms/op 1.9819 ms/op 0.98
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 40.326 us/op 48.475 us/op 0.83
BLS verify - blst 894.29 us/op 1.0266 ms/op 0.87
BLS verifyMultipleSignatures 3 - blst 1.3747 ms/op 1.3525 ms/op 1.02
BLS verifyMultipleSignatures 8 - blst 2.0907 ms/op 2.1102 ms/op 0.99
BLS verifyMultipleSignatures 32 - blst 4.6853 ms/op 6.6228 ms/op 0.71
BLS verifyMultipleSignatures 64 - blst 8.3381 ms/op 10.977 ms/op 0.76
BLS verifyMultipleSignatures 128 - blst 16.068 ms/op 17.663 ms/op 0.91
BLS deserializing 10000 signatures 635.05 ms/op 682.25 ms/op 0.93
BLS deserializing 100000 signatures 6.4209 s/op 6.9150 s/op 0.93
BLS verifyMultipleSignatures - same message - 3 - blst 990.35 us/op 1.0821 ms/op 0.92
BLS verifyMultipleSignatures - same message - 8 - blst 1.0668 ms/op 1.1089 ms/op 0.96
BLS verifyMultipleSignatures - same message - 32 - blst 1.7615 ms/op 1.8012 ms/op 0.98
BLS verifyMultipleSignatures - same message - 64 - blst 2.5473 ms/op 2.7281 ms/op 0.93
BLS verifyMultipleSignatures - same message - 128 - blst 4.1596 ms/op 4.3597 ms/op 0.95
BLS aggregatePubkeys 32 - blst 19.094 us/op 19.575 us/op 0.98
BLS aggregatePubkeys 128 - blst 63.453 us/op 70.147 us/op 0.90
notSeenSlots=1 numMissedVotes=1 numBadVotes=10 60.519 ms/op 70.245 ms/op 0.86
notSeenSlots=1 numMissedVotes=0 numBadVotes=4 42.152 ms/op 69.885 ms/op 0.60
notSeenSlots=2 numMissedVotes=1 numBadVotes=10 28.302 ms/op 39.012 ms/op 0.73
getSlashingsAndExits - default max 90.009 us/op 98.465 us/op 0.91
getSlashingsAndExits - 2k 299.00 us/op 304.24 us/op 0.98
proposeBlockBody type=full, size=empty 5.0798 ms/op 6.1662 ms/op 0.82
isKnown best case - 1 super set check 606.00 ns/op 331.00 ns/op 1.83
isKnown normal case - 2 super set checks 601.00 ns/op 304.00 ns/op 1.98
isKnown worse case - 16 super set checks 670.00 ns/op 312.00 ns/op 2.15
InMemoryCheckpointStateCache - add get delete 3.1530 us/op 2.9090 us/op 1.08
updateUnfinalizedPubkeys - updating 10 pubkeys 1.2960 ms/op 1.5418 ms/op 0.84
updateUnfinalizedPubkeys - updating 100 pubkeys 3.8649 ms/op 4.2937 ms/op 0.90
updateUnfinalizedPubkeys - updating 1000 pubkeys 44.959 ms/op 56.575 ms/op 0.79
validate api signedAggregateAndProof - struct 2.2628 ms/op 1.6026 ms/op 1.41
validate gossip signedAggregateAndProof - struct 2.0599 ms/op 1.6909 ms/op 1.22
validate gossip attestation - vc 640000 1.0027 ms/op 1.0663 ms/op 0.94
batch validate gossip attestation - vc 640000 - chunk 32 126.74 us/op 149.63 us/op 0.85
batch validate gossip attestation - vc 640000 - chunk 64 113.67 us/op 131.01 us/op 0.87
batch validate gossip attestation - vc 640000 - chunk 128 102.58 us/op 125.54 us/op 0.82
batch validate gossip attestation - vc 640000 - chunk 256 96.817 us/op 124.48 us/op 0.78
pickEth1Vote - no votes 871.03 us/op 1.2091 ms/op 0.72
pickEth1Vote - max votes 4.2797 ms/op 8.8825 ms/op 0.48
pickEth1Vote - Eth1Data hashTreeRoot value x2048 10.359 ms/op 14.882 ms/op 0.70
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 15.341 ms/op 21.231 ms/op 0.72
pickEth1Vote - Eth1Data fastSerialize value x2048 382.80 us/op 579.61 us/op 0.66
pickEth1Vote - Eth1Data fastSerialize tree x2048 3.2521 ms/op 4.5053 ms/op 0.72
bytes32 toHexString 733.00 ns/op 506.00 ns/op 1.45
bytes32 Buffer.toString(hex) 492.00 ns/op 272.00 ns/op 1.81
bytes32 Buffer.toString(hex) from Uint8Array 627.00 ns/op 465.00 ns/op 1.35
bytes32 Buffer.toString(hex) + 0x 454.00 ns/op 267.00 ns/op 1.70
Object access 1 prop 0.35700 ns/op 0.15600 ns/op 2.29
Map access 1 prop 0.33000 ns/op 0.13300 ns/op 2.48
Object get x1000 5.1610 ns/op 6.2810 ns/op 0.82
Map get x1000 5.9310 ns/op 6.9350 ns/op 0.86
Object set x1000 24.740 ns/op 39.276 ns/op 0.63
Map set x1000 19.701 ns/op 26.151 ns/op 0.75
Return object 10000 times 0.29730 ns/op 0.33060 ns/op 0.90
Throw Error 10000 times 2.6824 us/op 3.8156 us/op 0.70
toHex 105.20 ns/op 162.48 ns/op 0.65
Buffer.from 98.412 ns/op 148.25 ns/op 0.66
shared Buffer 74.040 ns/op 106.21 ns/op 0.70
fastMsgIdFn sha256 / 200 bytes 2.0970 us/op 2.4600 us/op 0.85
fastMsgIdFn h32 xxhash / 200 bytes 462.00 ns/op 288.00 ns/op 1.60
fastMsgIdFn h64 xxhash / 200 bytes 468.00 ns/op 295.00 ns/op 1.59
fastMsgIdFn sha256 / 1000 bytes 5.8430 us/op 7.5690 us/op 0.77
fastMsgIdFn h32 xxhash / 1000 bytes 579.00 ns/op 419.00 ns/op 1.38
fastMsgIdFn h64 xxhash / 1000 bytes 527.00 ns/op 377.00 ns/op 1.40
fastMsgIdFn sha256 / 10000 bytes 48.123 us/op 68.718 us/op 0.70
fastMsgIdFn h32 xxhash / 10000 bytes 1.9540 us/op 1.9820 us/op 0.99
fastMsgIdFn h64 xxhash / 10000 bytes 1.3410 us/op 1.3070 us/op 1.03
send data - 1000 256B messages 11.439 ms/op 14.693 ms/op 0.78
send data - 1000 512B messages 14.858 ms/op 20.004 ms/op 0.74
send data - 1000 1024B messages 24.442 ms/op 31.382 ms/op 0.78
send data - 1000 1200B messages 26.578 ms/op 33.126 ms/op 0.80
send data - 1000 2048B messages 32.926 ms/op 39.297 ms/op 0.84
send data - 1000 4096B messages 26.855 ms/op 37.175 ms/op 0.72
send data - 1000 16384B messages 74.383 ms/op 77.705 ms/op 0.96
send data - 1000 65536B messages 259.07 ms/op 245.52 ms/op 1.06
enrSubnets - fastDeserialize 64 bits 1.2280 us/op 1.2950 us/op 0.95
enrSubnets - ssz BitVector 64 bits 605.00 ns/op 468.00 ns/op 1.29
enrSubnets - fastDeserialize 4 bits 388.00 ns/op 211.00 ns/op 1.84
enrSubnets - ssz BitVector 4 bits 647.00 ns/op 473.00 ns/op 1.37
prioritizePeers score -10:0 att 32-0.1 sync 2-0 131.99 us/op 186.81 us/op 0.71
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 156.14 us/op 188.93 us/op 0.83
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 333.56 us/op 457.17 us/op 0.73
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 460.67 us/op 546.38 us/op 0.84
prioritizePeers score 0:0 att 64-1 sync 4-1 895.42 us/op 1.0111 ms/op 0.89
array of 16000 items push then shift 1.2678 us/op 1.9126 us/op 0.66
LinkedList of 16000 items push then shift 6.7110 ns/op 10.118 ns/op 0.66
array of 16000 items push then pop 96.551 ns/op 167.66 ns/op 0.58
LinkedList of 16000 items push then pop 6.2600 ns/op 9.7150 ns/op 0.64
array of 24000 items push then shift 1.9583 us/op 2.9853 us/op 0.66
LinkedList of 24000 items push then shift 7.2170 ns/op 9.5450 ns/op 0.76
array of 24000 items push then pop 151.29 ns/op 196.25 ns/op 0.77
LinkedList of 24000 items push then pop 6.3200 ns/op 8.7520 ns/op 0.72
intersect bitArray bitLen 8 5.6680 ns/op 7.7050 ns/op 0.74
intersect array and set length 8 39.696 ns/op 90.206 ns/op 0.44
intersect bitArray bitLen 128 26.684 ns/op 32.921 ns/op 0.81
intersect array and set length 128 596.91 ns/op 1.0748 us/op 0.56
bitArray.getTrueBitIndexes() bitLen 128 2.3870 us/op 3.0360 us/op 0.79
bitArray.getTrueBitIndexes() bitLen 248 3.6260 us/op 5.0690 us/op 0.72
bitArray.getTrueBitIndexes() bitLen 512 8.8630 us/op 13.678 us/op 0.65
Buffer.concat 32 items 1.1040 us/op 1.3060 us/op 0.85
Uint8Array.set 32 items 2.0320 us/op 2.5370 us/op 0.80
Buffer.copy 2.3810 us/op 3.1780 us/op 0.75
Uint8Array.set - with subarray 2.6620 us/op 3.9240 us/op 0.68
Uint8Array.set - without subarray 1.8640 us/op 1.9910 us/op 0.94
getUint32 - dataview 462.00 ns/op 343.00 ns/op 1.35
getUint32 - manual 401.00 ns/op 284.00 ns/op 1.41
Set add up to 64 items then delete first 1.8100 us/op 3.1384 us/op 0.58
OrderedSet add up to 64 items then delete first 2.8348 us/op 5.4223 us/op 0.52
Set add up to 64 items then delete last 2.0441 us/op 4.2805 us/op 0.48
OrderedSet add up to 64 items then delete last 3.1465 us/op 5.1915 us/op 0.61
Set add up to 64 items then delete middle 2.1097 us/op 3.6497 us/op 0.58
OrderedSet add up to 64 items then delete middle 4.4904 us/op 7.9798 us/op 0.56
Set add up to 128 items then delete first 4.0355 us/op 8.0303 us/op 0.50
OrderedSet add up to 128 items then delete first 6.3419 us/op 15.008 us/op 0.42
Set add up to 128 items then delete last 3.9012 us/op 7.7626 us/op 0.50
OrderedSet add up to 128 items then delete last 5.9289 us/op 11.758 us/op 0.50
Set add up to 128 items then delete middle 3.9305 us/op 7.4560 us/op 0.53
OrderedSet add up to 128 items then delete middle 11.909 us/op 19.736 us/op 0.60
Set add up to 256 items then delete first 7.9871 us/op 16.186 us/op 0.49
OrderedSet add up to 256 items then delete first 13.124 us/op 23.622 us/op 0.56
Set add up to 256 items then delete last 7.7898 us/op 14.717 us/op 0.53
OrderedSet add up to 256 items then delete last 11.848 us/op 25.876 us/op 0.46
Set add up to 256 items then delete middle 7.8836 us/op 15.320 us/op 0.51
OrderedSet add up to 256 items then delete middle 35.162 us/op 57.070 us/op 0.62
transfer serialized Status (84 B) 1.3460 us/op 1.7920 us/op 0.75
copy serialized Status (84 B) 1.1670 us/op 1.6600 us/op 0.70
transfer serialized SignedVoluntaryExit (112 B) 1.4340 us/op 1.8910 us/op 0.76
copy serialized SignedVoluntaryExit (112 B) 1.2250 us/op 1.6060 us/op 0.76
transfer serialized ProposerSlashing (416 B) 1.4700 us/op 2.9520 us/op 0.50
copy serialized ProposerSlashing (416 B) 1.9210 us/op 2.4450 us/op 0.79
transfer serialized Attestation (485 B) 2.3430 us/op 2.5250 us/op 0.93
copy serialized Attestation (485 B) 2.2350 us/op 2.3420 us/op 0.95
transfer serialized AttesterSlashing (33232 B) 1.7590 us/op 2.3800 us/op 0.74
copy serialized AttesterSlashing (33232 B) 4.9390 us/op 9.1950 us/op 0.54
transfer serialized Small SignedBeaconBlock (128000 B) 2.7620 us/op 3.5160 us/op 0.79
copy serialized Small SignedBeaconBlock (128000 B) 16.210 us/op 29.514 us/op 0.55
transfer serialized Avg SignedBeaconBlock (200000 B) 2.5690 us/op 4.1430 us/op 0.62
copy serialized Avg SignedBeaconBlock (200000 B) 12.166 us/op 42.536 us/op 0.29
transfer serialized BlobsSidecar (524380 B) 2.7350 us/op 4.6950 us/op 0.58
copy serialized BlobsSidecar (524380 B) 186.71 us/op 144.42 us/op 1.29
transfer serialized Big SignedBeaconBlock (1000000 B) 3.3310 us/op 5.6410 us/op 0.59
copy serialized Big SignedBeaconBlock (1000000 B) 379.52 us/op 267.15 us/op 1.42
pass gossip attestations to forkchoice per slot 2.5037 ms/op 3.3300 ms/op 0.75
forkChoice updateHead vc 100000 bc 64 eq 0 399.56 us/op 564.80 us/op 0.71
forkChoice updateHead vc 600000 bc 64 eq 0 2.5876 ms/op 4.2735 ms/op 0.61
forkChoice updateHead vc 1000000 bc 64 eq 0 4.4299 ms/op 6.7732 ms/op 0.65
forkChoice updateHead vc 600000 bc 320 eq 0 2.7251 ms/op 3.5246 ms/op 0.77
forkChoice updateHead vc 600000 bc 1200 eq 0 2.6796 ms/op 3.7537 ms/op 0.71
forkChoice updateHead vc 600000 bc 7200 eq 0 3.0915 ms/op 4.7980 ms/op 0.64
forkChoice updateHead vc 600000 bc 64 eq 1000 9.7528 ms/op 12.947 ms/op 0.75
forkChoice updateHead vc 600000 bc 64 eq 10000 9.6320 ms/op 12.071 ms/op 0.80
forkChoice updateHead vc 600000 bc 64 eq 300000 12.876 ms/op 17.849 ms/op 0.72
computeDeltas 500000 validators 300 proto nodes 2.9754 ms/op 5.1500 ms/op 0.58
computeDeltas 500000 validators 1200 proto nodes 3.0434 ms/op 4.7981 ms/op 0.63
computeDeltas 500000 validators 7200 proto nodes 3.1545 ms/op 4.9189 ms/op 0.64
computeDeltas 750000 validators 300 proto nodes 4.7495 ms/op 7.3694 ms/op 0.64
computeDeltas 750000 validators 1200 proto nodes 4.6355 ms/op 7.2950 ms/op 0.64
computeDeltas 750000 validators 7200 proto nodes 4.5017 ms/op 6.7431 ms/op 0.67
computeDeltas 1400000 validators 300 proto nodes 8.3176 ms/op 12.514 ms/op 0.66
computeDeltas 1400000 validators 1200 proto nodes 8.3850 ms/op 12.107 ms/op 0.69
computeDeltas 1400000 validators 7200 proto nodes 8.6957 ms/op 11.524 ms/op 0.75
computeDeltas 2100000 validators 300 proto nodes 12.670 ms/op 18.069 ms/op 0.70
computeDeltas 2100000 validators 1200 proto nodes 12.733 ms/op 17.369 ms/op 0.73
computeDeltas 2100000 validators 7200 proto nodes 12.601 ms/op 17.746 ms/op 0.71
altair processAttestation - 250000 vs - 7PWei normalcase 1.5033 ms/op 2.2313 ms/op 0.67
altair processAttestation - 250000 vs - 7PWei worstcase 2.1588 ms/op 3.0812 ms/op 0.70
altair processAttestation - setStatus - 1/6 committees join 73.181 us/op 104.67 us/op 0.70
altair processAttestation - setStatus - 1/3 committees join 144.48 us/op 209.31 us/op 0.69
altair processAttestation - setStatus - 1/2 committees join 195.75 us/op 293.02 us/op 0.67
altair processAttestation - setStatus - 2/3 committees join 252.73 us/op 368.48 us/op 0.69
altair processAttestation - setStatus - 4/5 committees join 380.58 us/op 530.27 us/op 0.72
altair processAttestation - setStatus - 100% committees join 468.28 us/op 704.55 us/op 0.66
altair processBlock - 250000 vs - 7PWei normalcase 3.5354 ms/op 5.1921 ms/op 0.68
altair processBlock - 250000 vs - 7PWei normalcase hashState 25.767 ms/op 30.098 ms/op 0.86
altair processBlock - 250000 vs - 7PWei worstcase 32.056 ms/op 42.046 ms/op 0.76
altair processBlock - 250000 vs - 7PWei worstcase hashState 76.093 ms/op 92.813 ms/op 0.82
phase0 processBlock - 250000 vs - 7PWei normalcase 2.3391 ms/op 2.6002 ms/op 0.90
phase0 processBlock - 250000 vs - 7PWei worstcase 22.673 ms/op 27.396 ms/op 0.83
altair processEth1Data - 250000 vs - 7PWei normalcase 243.86 us/op 380.53 us/op 0.64
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 5.0380 us/op 7.5610 us/op 0.67
getExpectedWithdrawals 250000 eb:0.95,eth1:0.1,we:0.05,wn:0,smpl:219 28.622 us/op 40.297 us/op 0.71
getExpectedWithdrawals 250000 eb:0.95,eth1:0.3,we:0.05,wn:0,smpl:42 8.6780 us/op 12.957 us/op 0.67
getExpectedWithdrawals 250000 eb:0.95,eth1:0.7,we:0.05,wn:0,smpl:18 5.1240 us/op 8.3260 us/op 0.62
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 129.08 us/op 139.59 us/op 0.92
getExpectedWithdrawals 250000 eb:0.03,eth1:0.03,we:0,wn:0,smpl:11777 1.4922 ms/op 1.6916 ms/op 0.88
getExpectedWithdrawals 250000 eb:0.01,eth1:0.01,we:0,wn:0,smpl:16384 1.2100 ms/op 2.8928 ms/op 0.42
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,smpl:16384 1.4486 ms/op 1.6729 ms/op 0.87
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,nocache,smpl:16384 2.8941 ms/op 3.6708 ms/op 0.79
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,smpl:16384 1.2547 ms/op 2.3037 ms/op 0.54
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,nocache,smpl:16384 2.9668 ms/op 3.8951 ms/op 0.76
Tree 40 250000 create 202.56 ms/op 234.63 ms/op 0.86
Tree 40 250000 get(125000) 120.73 ns/op 167.57 ns/op 0.72
Tree 40 250000 set(125000) 560.29 ns/op 799.54 ns/op 0.70
Tree 40 250000 toArray() 18.546 ms/op 20.598 ms/op 0.90
Tree 40 250000 iterate all - toArray() + loop 16.734 ms/op 22.045 ms/op 0.76
Tree 40 250000 iterate all - get(i) 45.175 ms/op 67.872 ms/op 0.67
Array 250000 create 2.9980 ms/op 3.9375 ms/op 0.76
Array 250000 clone - spread 1.2385 ms/op 1.6473 ms/op 0.75
Array 250000 get(125000) 0.59300 ns/op 0.44100 ns/op 1.34
Array 250000 set(125000) 0.59400 ns/op 0.46200 ns/op 1.29
Array 250000 iterate all - loop 76.161 us/op 104.11 us/op 0.73
phase0 afterProcessEpoch - 250000 vs - 7PWei 75.212 ms/op 99.668 ms/op 0.75
Array.fill - length 1000000 2.5092 ms/op 5.1340 ms/op 0.49
Array push - length 1000000 15.621 ms/op 19.208 ms/op 0.81
Array.get 0.25725 ns/op 0.32048 ns/op 0.80
Uint8Array.get 0.33489 ns/op 0.47165 ns/op 0.71
phase0 beforeProcessEpoch - 250000 vs - 7PWei 14.941 ms/op 19.317 ms/op 0.77
altair processEpoch - mainnet_e81889 264.86 ms/op 344.36 ms/op 0.77
mainnet_e81889 - altair beforeProcessEpoch 19.442 ms/op 20.025 ms/op 0.97
mainnet_e81889 - altair processJustificationAndFinalization 16.031 us/op 17.193 us/op 0.93
mainnet_e81889 - altair processInactivityUpdates 5.4580 ms/op 5.7576 ms/op 0.95
mainnet_e81889 - altair processRewardsAndPenalties 50.053 ms/op 55.128 ms/op 0.91
mainnet_e81889 - altair processRegistryUpdates 1.8420 us/op 3.7270 us/op 0.49
mainnet_e81889 - altair processSlashings 741.00 ns/op 591.00 ns/op 1.25
mainnet_e81889 - altair processEth1DataReset 701.00 ns/op 333.00 ns/op 2.11
mainnet_e81889 - altair processEffectiveBalanceUpdates 2.9765 ms/op 1.9343 ms/op 1.54
mainnet_e81889 - altair processSlashingsReset 2.1970 us/op 5.0700 us/op 0.43
mainnet_e81889 - altair processRandaoMixesReset 2.7390 us/op 7.3920 us/op 0.37
mainnet_e81889 - altair processHistoricalRootsUpdate 733.00 ns/op 793.00 ns/op 0.92
mainnet_e81889 - altair processParticipationFlagUpdates 2.0820 us/op 1.9700 us/op 1.06
mainnet_e81889 - altair processSyncCommitteeUpdates 920.00 ns/op 693.00 ns/op 1.33
mainnet_e81889 - altair afterProcessEpoch 77.692 ms/op 101.90 ms/op 0.76
capella processEpoch - mainnet_e217614 1.1939 s/op 1.2677 s/op 0.94
mainnet_e217614 - capella beforeProcessEpoch 72.457 ms/op 69.011 ms/op 1.05
mainnet_e217614 - capella processJustificationAndFinalization 16.550 us/op 22.114 us/op 0.75
mainnet_e217614 - capella processInactivityUpdates 16.448 ms/op 19.118 ms/op 0.86
mainnet_e217614 - capella processRewardsAndPenalties 257.66 ms/op 269.55 ms/op 0.96
mainnet_e217614 - capella processRegistryUpdates 12.766 us/op 16.006 us/op 0.80
mainnet_e217614 - capella processSlashings 783.00 ns/op 416.00 ns/op 1.88
mainnet_e217614 - capella processEth1DataReset 753.00 ns/op 318.00 ns/op 2.37
mainnet_e217614 - capella processEffectiveBalanceUpdates 16.510 ms/op 13.756 ms/op 1.20
mainnet_e217614 - capella processSlashingsReset 2.9550 us/op 3.1480 us/op 0.94
mainnet_e217614 - capella processRandaoMixesReset 3.9940 us/op 7.0780 us/op 0.56
mainnet_e217614 - capella processHistoricalRootsUpdate 2.4490 us/op 507.00 ns/op 4.83
mainnet_e217614 - capella processParticipationFlagUpdates 3.5210 us/op 1.8200 us/op 1.93
mainnet_e217614 - capella afterProcessEpoch 206.69 ms/op 247.11 ms/op 0.84
phase0 processEpoch - mainnet_e58758 442.80 ms/op 460.89 ms/op 0.96
mainnet_e58758 - phase0 beforeProcessEpoch 99.785 ms/op 98.938 ms/op 1.01
mainnet_e58758 - phase0 processJustificationAndFinalization 16.408 us/op 20.880 us/op 0.79
mainnet_e58758 - phase0 processRewardsAndPenalties 28.929 ms/op 33.745 ms/op 0.86
mainnet_e58758 - phase0 processRegistryUpdates 8.4840 us/op 7.8900 us/op 1.08
mainnet_e58758 - phase0 processSlashings 818.00 ns/op 425.00 ns/op 1.92
mainnet_e58758 - phase0 processEth1DataReset 739.00 ns/op 556.00 ns/op 1.33
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 905.70 us/op 1.5574 ms/op 0.58
mainnet_e58758 - phase0 processSlashingsReset 2.7930 us/op 3.0490 us/op 0.92
mainnet_e58758 - phase0 processRandaoMixesReset 3.9600 us/op 4.9660 us/op 0.80
mainnet_e58758 - phase0 processHistoricalRootsUpdate 1.0600 us/op 693.00 ns/op 1.53
mainnet_e58758 - phase0 processParticipationRecordUpdates 3.4000 us/op 6.1460 us/op 0.55
mainnet_e58758 - phase0 afterProcessEpoch 69.195 ms/op 93.483 ms/op 0.74
phase0 processEffectiveBalanceUpdates - 250000 normalcase 2.9644 ms/op 2.3220 ms/op 1.28
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.9905 ms/op 2.7812 ms/op 0.72
altair processInactivityUpdates - 250000 normalcase 18.060 ms/op 20.484 ms/op 0.88
altair processInactivityUpdates - 250000 worstcase 18.914 ms/op 19.346 ms/op 0.98
phase0 processRegistryUpdates - 250000 normalcase 7.0560 us/op 10.546 us/op 0.67
phase0 processRegistryUpdates - 250000 badcase_full_deposits 295.28 us/op 366.53 us/op 0.81
phase0 processRegistryUpdates - 250000 worstcase 0.5 121.28 ms/op 144.62 ms/op 0.84
altair processRewardsAndPenalties - 250000 normalcase 44.079 ms/op 44.294 ms/op 1.00
altair processRewardsAndPenalties - 250000 worstcase 42.509 ms/op 46.858 ms/op 0.91
phase0 getAttestationDeltas - 250000 normalcase 8.9518 ms/op 11.960 ms/op 0.75
phase0 getAttestationDeltas - 250000 worstcase 8.8210 ms/op 12.489 ms/op 0.71
phase0 processSlashings - 250000 worstcase 96.241 us/op 110.96 us/op 0.87
altair processSyncCommitteeUpdates - 250000 119.80 ms/op 154.29 ms/op 0.78
BeaconState.hashTreeRoot - No change 442.00 ns/op 448.00 ns/op 0.99
BeaconState.hashTreeRoot - 1 full validator 115.03 us/op 135.63 us/op 0.85
BeaconState.hashTreeRoot - 32 full validator 1.3815 ms/op 1.2190 ms/op 1.13
BeaconState.hashTreeRoot - 512 full validator 16.553 ms/op 16.398 ms/op 1.01
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 173.95 us/op 163.47 us/op 1.06
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 2.2967 ms/op 3.0442 ms/op 0.75
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 32.402 ms/op 46.331 ms/op 0.70
BeaconState.hashTreeRoot - 1 balances 126.75 us/op 187.56 us/op 0.68
BeaconState.hashTreeRoot - 32 balances 1.2044 ms/op 1.4102 ms/op 0.85
BeaconState.hashTreeRoot - 512 balances 11.851 ms/op 13.905 ms/op 0.85
BeaconState.hashTreeRoot - 250000 balances 167.59 ms/op 222.11 ms/op 0.75
aggregationBits - 2048 els - zipIndexesInBitList 22.224 us/op 36.180 us/op 0.61
byteArrayEquals 32 49.631 ns/op 62.570 ns/op 0.79
Buffer.compare 32 16.413 ns/op 19.089 ns/op 0.86
byteArrayEquals 1024 1.2833 us/op 1.7836 us/op 0.72
Buffer.compare 1024 23.618 ns/op 28.090 ns/op 0.84
byteArrayEquals 16384 20.384 us/op 27.260 us/op 0.75
Buffer.compare 16384 201.33 ns/op 220.47 ns/op 0.91
byteArrayEquals 123687377 154.03 ms/op 218.39 ms/op 0.71
Buffer.compare 123687377 6.2085 ms/op 10.260 ms/op 0.61
byteArrayEquals 32 - diff last byte 47.661 ns/op 58.625 ns/op 0.81
Buffer.compare 32 - diff last byte 16.006 ns/op 20.344 ns/op 0.79
byteArrayEquals 1024 - diff last byte 1.2661 us/op 1.7945 us/op 0.71
Buffer.compare 1024 - diff last byte 25.111 ns/op 30.815 ns/op 0.81
byteArrayEquals 16384 - diff last byte 20.189 us/op 28.208 us/op 0.72
Buffer.compare 16384 - diff last byte 175.08 ns/op 203.70 ns/op 0.86
byteArrayEquals 123687377 - diff last byte 154.85 ms/op 208.00 ms/op 0.74
Buffer.compare 123687377 - diff last byte 6.1236 ms/op 9.6462 ms/op 0.63
byteArrayEquals 32 - random bytes 5.0620 ns/op 6.3780 ns/op 0.79
Buffer.compare 32 - random bytes 16.060 ns/op 19.543 ns/op 0.82
byteArrayEquals 1024 - random bytes 4.9820 ns/op 5.5610 ns/op 0.90
Buffer.compare 1024 - random bytes 15.885 ns/op 18.745 ns/op 0.85
byteArrayEquals 16384 - random bytes 5.1210 ns/op 5.5350 ns/op 0.93
Buffer.compare 16384 - random bytes 15.917 ns/op 18.241 ns/op 0.87
byteArrayEquals 123687377 - random bytes 7.9600 ns/op 6.8700 ns/op 1.16
Buffer.compare 123687377 - random bytes 18.880 ns/op 20.230 ns/op 0.93
regular array get 100000 times 31.532 us/op 40.928 us/op 0.77
wrappedArray get 100000 times 31.374 us/op 37.994 us/op 0.83
arrayWithProxy get 100000 times 9.9621 ms/op 14.464 ms/op 0.69
ssz.Root.equals 44.580 ns/op 51.942 ns/op 0.86
byteArrayEquals 43.229 ns/op 49.604 ns/op 0.87
Buffer.compare 9.5000 ns/op 12.653 ns/op 0.75
shuffle list - 16384 els 5.5999 ms/op 8.2827 ms/op 0.68
shuffle list - 250000 els 83.835 ms/op 109.83 ms/op 0.76
processSlot - 1 slots 12.430 us/op 19.059 us/op 0.65
processSlot - 32 slots 3.6082 ms/op 3.5220 ms/op 1.02
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 39.312 ms/op 42.796 ms/op 0.92
getCommitteeAssignments - req 1 vs - 250000 vc 1.7931 ms/op 2.6644 ms/op 0.67
getCommitteeAssignments - req 100 vs - 250000 vc 3.5464 ms/op 5.0722 ms/op 0.70
getCommitteeAssignments - req 1000 vs - 250000 vc 3.8393 ms/op 5.3373 ms/op 0.72
findModifiedValidators - 10000 modified validators 246.37 ms/op 268.23 ms/op 0.92
findModifiedValidators - 1000 modified validators 177.81 ms/op 176.98 ms/op 1.00
findModifiedValidators - 100 modified validators 162.96 ms/op 190.44 ms/op 0.86
findModifiedValidators - 10 modified validators 159.35 ms/op 163.37 ms/op 0.98
findModifiedValidators - 1 modified validators 205.45 ms/op 177.11 ms/op 1.16
findModifiedValidators - no difference 202.22 ms/op 248.14 ms/op 0.81
compare ViewDUs 4.1624 s/op 3.4711 s/op 1.20
compare each validator Uint8Array 2.5387 s/op 1.3499 s/op 1.88
compare ViewDU to Uint8Array 1.1909 s/op 1.3222 s/op 0.90
migrate state 1000000 validators, 24 modified, 0 new 951.99 ms/op 670.74 ms/op 1.42
migrate state 1000000 validators, 1700 modified, 1000 new 1.1841 s/op 954.61 ms/op 1.24
migrate state 1000000 validators, 3400 modified, 2000 new 1.3409 s/op 1.1845 s/op 1.13
migrate state 1500000 validators, 24 modified, 0 new 877.49 ms/op 787.90 ms/op 1.11
migrate state 1500000 validators, 1700 modified, 1000 new 1.2022 s/op 1.0710 s/op 1.12
migrate state 1500000 validators, 3400 modified, 2000 new 1.1267 s/op 1.4247 s/op 0.79
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 5.9400 ns/op 6.2900 ns/op 0.94
state getBlockRootAtSlot - 250000 vs - 7PWei 566.91 ns/op 1.2018 us/op 0.47
computeProposers - vc 250000 5.2461 ms/op 11.480 ms/op 0.46
computeEpochShuffling - vc 250000 79.269 ms/op 113.61 ms/op 0.70
getNextSyncCommittee - vc 250000 104.26 ms/op 193.74 ms/op 0.54
computeSigningRoot for AttestationData 22.129 us/op 33.125 us/op 0.67
hash AttestationData serialized data then Buffer.toString(base64) 1.1854 us/op 2.3510 us/op 0.50
toHexString serialized data 789.36 ns/op 1.9590 us/op 0.40
Buffer.toString(base64) 144.97 ns/op 302.29 ns/op 0.48
nodejs block root to RootHex using toHex 116.35 ns/op 242.33 ns/op 0.48
nodejs block root to RootHex using toRootHex 77.262 ns/op 151.37 ns/op 0.51
browser block root to RootHex using the deprecated toHexString 209.38 ns/op 473.43 ns/op 0.44
browser block root to RootHex using toHex 178.83 ns/op 394.34 ns/op 0.45
browser block root to RootHex using toRootHex 154.38 ns/op 202.64 ns/op 0.76

by benchmarkbot/action

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.

This looks good

twoeths
twoeths previously approved these changes Sep 16, 2024
Copy link
Contributor

@twoeths twoeths left a comment

Choose a reason for hiding this comment

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

looks awesome, I think we should wait for v1.22 to be released first before merging this

@matthewkeil matthewkeil added the status-do-not-merge Merging this issue will break the build. Do not merge! label Sep 16, 2024
Copy link
Member

@nflaig nflaig left a comment

Choose a reason for hiding this comment

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

is there a reason why we use both upcoming and next epoch terminology?

@matthewkeil
Copy link
Member Author

is there a reason why we use both upcoming and next epoch terminology?

Yes. The slot gets incremented between processEpoch and afterProcessEpoch so technically the epoch has incremented there and its confusing in some contexts that the "next" epoch is actually the "current" epoch so to standardize terminology across the epoch transition phases I think using "upcoming" epoch for the one directly after the state transition is less confusing. The "next" fields like nextProposer during the transition are actually for epoch n+2 (epochAfterUpcoming) which is confusing because we update the "epochCtx.nextEpoch" right at the end of the epoch transition so "next" is referring to two different epochs.

@wemeetagain
Copy link
Member

Yes. ...

Can you commit this somewhere in the code as a jsdoc comment?

@matthewkeil matthewkeil requested review from wemeetagain and nflaig and removed request for wemeetagain September 20, 2024 07:21
Copy link
Member

@nflaig nflaig left a comment

Choose a reason for hiding this comment

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

LGTM - great work!

// in this context but that is not actually true because the state transition happens in the last 4 seconds of the
// epoch. For the context of this function "upcoming epoch" is used to denote the epoch that will begin after this
// function returns. The epoch that is "next" once the state transition is complete is referred to as the
// epochAfterUpcoming for the same reason to help minimize confusion.
const upcomingEpoch = this.nextEpoch;
Copy link
Contributor

Choose a reason for hiding this comment

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

yes I really like the name "upcomingEpoch" in this context 👍

@twoeths twoeths merged commit cd98c23 into unstable Sep 23, 2024
19 of 20 checks passed
@twoeths twoeths deleted the mkeil/shuffling-refactor branch September 23, 2024 01:41
ensi321 pushed a commit that referenced this pull request Sep 25, 2024
* feat: add ShufflingCache to EpochCache

* fix: implementation in state-transition for EpochCache with ShufflingCache

* feat: remove shufflingCache.processState

* feat: implement ShufflingCache changes in beacon-node

* feat: pass shufflingCache when loading cached state from db

* test: fix state-transition tests for EpochCache changes

* feat: Pass shufflingCache to EpochCache at startup

* test: fix slot off by one for decision root in perf test

* chore: use ?. syntax

* chore: refactoring

* feat: add comments and clean up afterProcessEpoch

* fix: perf test slot incrementing

* fix: remove MockShufflingCache

* Revert "chore: refactoring"

This reverts commit 104aa56.

* refactor: shufflingCache getters

* refactor: shufflingCache setters

* refactor: build and getOrBuild

* docs: add comments to ShufflingCache methods

* chore: lint issues

* test: update tests in beacon-node

* chore: lint

* feat: get shufflings from cache for API

* feat: minTimeDelayToBuildShuffling cli flag

* test: fix shufflingCache promise insertion test

* fix: rebase conflicts

* fix: changes from debugging sim tests

* refactor: minimize changes in afterProcessEpoch

* chore: fix lint

* chore: fix check-types

* chore: fix check-types

* feat: add diff utility

* fix: bug in spec tests from invalid nextActiveIndices

* refactor: add/remove comments

* refactor: remove this.activeIndicesLength from EpochCache

* refactor: simplify shufflingCache.getSync

* refactor: remove unnecessary undefined's

* refactor: clean up ShufflingCache unit test

* feat: add metrics for ShufflingCache

* feat: add shufflingCache metrics to state-transition

* chore: lint

* fix: metric name clash

* refactor: add comment about not having ShufflingCache in EpochCache

* refactor: rename shuffling decision root functions

* refactor: remove unused comment

* feat: async add nextShuffling to EpochCache after its built

* feat: make ShufflingCache.set private

* feat: chance metrics to nextShufflingNotOnEpochCache instead of positive case

* refactor: move diff to separate PR

* chore: fix tests using shufflingCache.set method

* feat: remove minTimeDelayToBuild

* feat: return promise from insertPromise and then through build

* fix: update metrics names and help field

* feat: move build of shuffling to beforeProcessEpoch

* feat: allow calc of pivot slot before slot increment

* fix: calc of pivot slot before slot increment

* Revert "fix: calc of pivot slot before slot increment"

This reverts commit 5e65f7e.

* Revert "feat: allow calc of pivot slot before slot increment"

This reverts commit ed850ee.

* feat: allow getting current block root for shuffling calculation

* fix: get nextShufflingDecisionRoot directly from state.blockRoots

* fix: convert toRootHex

* docs: add comment about pulling decisionRoot directly from state

* feat: add back metrics for regen attestation cache hit/miss

* docs: fix docstring on shufflingCache.build

* refactor: change validatorIndices to Uint32Array

* refactor: remove comment and change variable name

* fix: use toRootHex instead of toHexString

* refactor: deduplicate moved function computeAnchorCheckpoint

* fix: touch up metrics per PR comments

* fix: merge conflict

* chore: lint

* refactor: add scope around activeIndices to GC arrays

* feat: directly use Uint32Array instead of transcribing number array to Uint32Array

* refactor: activeIndices per tuyen comment

* refactor: rename to epochAfterNext

* chore: review PR

* feat: update no shuffling ApiError to 500 status

* fix: add back unnecessary eslint directive. to be remove under separate PR

* feat: update no shuffling ApiError to 500 status

* docs: add comment about upcomingEpoch

---------

Co-authored-by: Cayman <[email protected]>
Co-authored-by: Tuyen Nguyen <[email protected]>
philknows pushed a commit that referenced this pull request Sep 27, 2024
* feat: add ShufflingCache to EpochCache

* fix: implementation in state-transition for EpochCache with ShufflingCache

* feat: remove shufflingCache.processState

* feat: implement ShufflingCache changes in beacon-node

* feat: pass shufflingCache when loading cached state from db

* test: fix state-transition tests for EpochCache changes

* feat: Pass shufflingCache to EpochCache at startup

* test: fix slot off by one for decision root in perf test

* chore: use ?. syntax

* chore: refactoring

* feat: add comments and clean up afterProcessEpoch

* fix: perf test slot incrementing

* fix: remove MockShufflingCache

* Revert "chore: refactoring"

This reverts commit 104aa56.

* refactor: shufflingCache getters

* refactor: shufflingCache setters

* refactor: build and getOrBuild

* docs: add comments to ShufflingCache methods

* chore: lint issues

* test: update tests in beacon-node

* chore: lint

* feat: get shufflings from cache for API

* feat: minTimeDelayToBuildShuffling cli flag

* test: fix shufflingCache promise insertion test

* fix: rebase conflicts

* fix: changes from debugging sim tests

* refactor: minimize changes in afterProcessEpoch

* chore: fix lint

* chore: fix check-types

* chore: fix check-types

* feat: add diff utility

* fix: bug in spec tests from invalid nextActiveIndices

* refactor: add/remove comments

* refactor: remove this.activeIndicesLength from EpochCache

* refactor: simplify shufflingCache.getSync

* refactor: remove unnecessary undefined's

* refactor: clean up ShufflingCache unit test

* feat: add metrics for ShufflingCache

* feat: add shufflingCache metrics to state-transition

* chore: lint

* fix: metric name clash

* refactor: add comment about not having ShufflingCache in EpochCache

* refactor: rename shuffling decision root functions

* refactor: remove unused comment

* feat: async add nextShuffling to EpochCache after its built

* feat: make ShufflingCache.set private

* feat: chance metrics to nextShufflingNotOnEpochCache instead of positive case

* refactor: move diff to separate PR

* chore: fix tests using shufflingCache.set method

* feat: remove minTimeDelayToBuild

* feat: return promise from insertPromise and then through build

* fix: update metrics names and help field

* feat: move build of shuffling to beforeProcessEpoch

* feat: allow calc of pivot slot before slot increment

* fix: calc of pivot slot before slot increment

* Revert "fix: calc of pivot slot before slot increment"

This reverts commit 5e65f7e.

* Revert "feat: allow calc of pivot slot before slot increment"

This reverts commit ed850ee.

* feat: allow getting current block root for shuffling calculation

* fix: get nextShufflingDecisionRoot directly from state.blockRoots

* fix: convert toRootHex

* docs: add comment about pulling decisionRoot directly from state

* feat: add back metrics for regen attestation cache hit/miss

* docs: fix docstring on shufflingCache.build

* refactor: change validatorIndices to Uint32Array

* refactor: remove comment and change variable name

* fix: use toRootHex instead of toHexString

* refactor: deduplicate moved function computeAnchorCheckpoint

* fix: touch up metrics per PR comments

* fix: merge conflict

* chore: lint

* refactor: add scope around activeIndices to GC arrays

* feat: directly use Uint32Array instead of transcribing number array to Uint32Array

* refactor: activeIndices per tuyen comment

* refactor: rename to epochAfterNext

* chore: review PR

* feat: update no shuffling ApiError to 500 status

* fix: add back unnecessary eslint directive. to be remove under separate PR

* feat: update no shuffling ApiError to 500 status

* docs: add comment about upcomingEpoch

---------

Co-authored-by: Cayman <[email protected]>
Co-authored-by: Tuyen Nguyen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status-do-not-merge Merging this issue will break the build. Do not merge!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants