Skip to content

Commit

Permalink
fix: correct createFromState() with cached current shuffling (#6240)
Browse files Browse the repository at this point in the history
* fix: correct createFromState() with cached current shuffling

* chore: fix lint
  • Loading branch information
twoeths authored Dec 29, 2023
1 parent 4c6c33e commit 5408bab
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
6 changes: 4 additions & 2 deletions packages/state-transition/src/cache/epochCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,10 @@ export class EpochCache {
if (cachedPreviousShuffling == null && isActiveValidator(validator, previousEpoch)) {
previousActiveIndices.push(i);
}
if (cachedCurrentShuffling == null && isActiveValidator(validator, currentEpoch)) {
currentActiveIndices.push(i);
if (isActiveValidator(validator, currentEpoch)) {
if (cachedCurrentShuffling == null) {
currentActiveIndices.push(i);
}
// We track totalActiveBalanceIncrements as ETH to fit total network balance in a JS number (53 bits)
totalActiveBalanceIncrements += effectiveBalanceIncrements[i];
}
Expand Down
45 changes: 42 additions & 3 deletions packages/state-transition/test/unit/cachedBeaconState.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {describe, it, expect} from "vitest";
import {ssz} from "@lodestar/types";
import {Epoch, ssz, RootHex} from "@lodestar/types";
import {toHexString} from "@lodestar/utils";
import {config} from "@lodestar/config/default";
import {config as defaultConfig} from "@lodestar/config/default";
import {createBeaconConfig} from "@lodestar/config";
import {createCachedBeaconStateTest} from "../utils/state.js";
import {PubkeyIndexMap} from "../../src/cache/pubkeyCache.js";
import {createCachedBeaconState, loadUnfinalizedCachedBeaconState} from "../../src/cache/stateCache.js";
import {interopPubkeysCached} from "../utils/interop.js";
import {modifyStateSameValidator, newStateWithValidators} from "../utils/capella.js";
import {EpochShuffling, getShufflingDecisionBlock} from "../../src/util/epochShuffling.js";

describe("CachedBeaconState", () => {
it("Clone and mutate", () => {
Expand Down Expand Up @@ -57,10 +58,11 @@ describe("CachedBeaconState", () => {
const pubkeys = interopPubkeysCached(2 * numValidator);

const stateView = newStateWithValidators(numValidator);
const config = createBeaconConfig(defaultConfig, stateView.genesisValidatorsRoot);
const seedState = createCachedBeaconState(
stateView,
{
config: createBeaconConfig(config, stateView.genesisValidatorsRoot),
config,
pubkey2index: new PubkeyIndexMap(),
index2pubkey: [],
},
Expand Down Expand Up @@ -131,6 +133,43 @@ describe("CachedBeaconState", () => {
const newStateBytes = newCachedState.serialize();
expect(newStateBytes).toEqual(stateBytes);
expect(newCachedState.hashTreeRoot()).toEqual(state.hashTreeRoot());
const shufflingGetter = (shufflingEpoch: Epoch, dependentRoot: RootHex): EpochShuffling | null => {
if (
shufflingEpoch === seedState.epochCtx.epoch - 1 &&
dependentRoot === getShufflingDecisionBlock(seedState, shufflingEpoch)
) {
return seedState.epochCtx.previousShuffling;
}

if (
shufflingEpoch === seedState.epochCtx.epoch &&
dependentRoot === getShufflingDecisionBlock(seedState, shufflingEpoch)
) {
return seedState.epochCtx.currentShuffling;
}

if (
shufflingEpoch === seedState.epochCtx.epoch + 1 &&
dependentRoot === getShufflingDecisionBlock(seedState, shufflingEpoch)
) {
return seedState.epochCtx.nextShuffling;
}

return null;
};
const cachedState = createCachedBeaconState(
state,
{
config,
pubkey2index: new PubkeyIndexMap(),
index2pubkey: [],
},
{skipSyncCommitteeCache: true, shufflingGetter}
);
// validatorCountDelta < 0 is unrealistic and shuffling computation results in a different result
if (validatorCountDelta >= 0) {
expect(newCachedState.epochCtx).toEqual(cachedState.epochCtx);
}

// confirm loadUnfinalizedCachedBeaconState() result
for (let i = 0; i < newCachedState.validators.length; i++) {
Expand Down
20 changes: 18 additions & 2 deletions packages/state-transition/test/utils/capella.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import crypto from "node:crypto";
import {ssz} from "@lodestar/types";
import {config} from "@lodestar/config/default";
import {BLS_WITHDRAWAL_PREFIX, ETH1_ADDRESS_WITHDRAWAL_PREFIX, SLOTS_PER_EPOCH} from "@lodestar/params";
import {
BLS_WITHDRAWAL_PREFIX,
ETH1_ADDRESS_WITHDRAWAL_PREFIX,
SLOTS_PER_EPOCH,
SLOTS_PER_HISTORICAL_ROOT,
} from "@lodestar/params";
import {BeaconStateCapella, CachedBeaconStateCapella} from "../../src/index.js";
import {createCachedBeaconStateTest} from "./state.js";
import {mulberry32} from "./rand.js";
Expand Down Expand Up @@ -67,10 +72,17 @@ export function newStateWithValidators(numValidator: number): BeaconStateCapella
const capellaStateType = ssz.capella.BeaconState;
const stateView = capellaStateType.defaultViewDU();
stateView.slot = config.CAPELLA_FORK_EPOCH * SLOTS_PER_EPOCH + 100;
for (let i = 0; i < SLOTS_PER_HISTORICAL_ROOT; i++) {
stateView.blockRoots.set(i, crypto.randomBytes(32));
}

for (let i = 0; i < numValidator; i++) {
const validator = ssz.phase0.Validator.defaultViewDU();
validator.pubkey = pubkeys[i];
// make all validators active
validator.activationEpoch = 0;
validator.exitEpoch = Infinity;
validator.effectiveBalance = 32e9;
stateView.validators.push(validator);
stateView.balances.push(32);
stateView.inactivityScores.push(0);
Expand All @@ -85,15 +97,19 @@ export function newStateWithValidators(numValidator: number): BeaconStateCapella
* Modify a state without changing number of validators
*/
export function modifyStateSameValidator(seedState: BeaconStateCapella): BeaconStateCapella {
const slotDiff = 10;
const state = seedState.clone();
state.slot = seedState.slot + 10;
state.slot = seedState.slot + slotDiff;
state.latestBlockHeader = ssz.phase0.BeaconBlockHeader.toViewDU({
slot: state.slot,
proposerIndex: 0,
parentRoot: state.hashTreeRoot(),
stateRoot: state.hashTreeRoot(),
bodyRoot: ssz.phase0.BeaconBlockBody.hashTreeRoot(ssz.phase0.BeaconBlockBody.defaultValue()),
});
for (let i = 1; i <= slotDiff; i++) {
state.blockRoots.set((seedState.slot + i) % SLOTS_PER_HISTORICAL_ROOT, crypto.randomBytes(32));
}
state.blockRoots.set(0, crypto.randomBytes(32));
state.stateRoots.set(0, crypto.randomBytes(32));
state.historicalRoots.push(crypto.randomBytes(32));
Expand Down

1 comment on commit 5408bab

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for some benchmarks.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold.

Benchmark suite Current: 5408bab Previous: 4c6c33e Ratio
Object set x1000 80.805 ns/op 25.295 ns/op 3.19
Map set x1000 57.927 ns/op 17.412 ns/op 3.33
Full benchmark results
Benchmark suite Current: 5408bab Previous: 4c6c33e Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 967.74 us/op 939.69 us/op 1.03
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 117.06 us/op 56.590 us/op 2.07
BLS verify - blst-native 1.3108 ms/op 1.0893 ms/op 1.20
BLS verifyMultipleSignatures 3 - blst-native 2.7468 ms/op 2.3185 ms/op 1.18
BLS verifyMultipleSignatures 8 - blst-native 6.0526 ms/op 5.1586 ms/op 1.17
BLS verifyMultipleSignatures 32 - blst-native 22.040 ms/op 18.724 ms/op 1.18
BLS verifyMultipleSignatures 64 - blst-native 43.490 ms/op 37.167 ms/op 1.17
BLS verifyMultipleSignatures 128 - blst-native 86.651 ms/op 73.646 ms/op 1.18
BLS deserializing 10000 signatures 953.77 ms/op 807.43 ms/op 1.18
BLS deserializing 100000 signatures 9.5645 s/op 8.2790 s/op 1.16
BLS verifyMultipleSignatures - same message - 3 - blst-native 1.3397 ms/op 1.1326 ms/op 1.18
BLS verifyMultipleSignatures - same message - 8 - blst-native 1.5073 ms/op 1.2828 ms/op 1.17
BLS verifyMultipleSignatures - same message - 32 - blst-native 2.3301 ms/op 2.0177 ms/op 1.15
BLS verifyMultipleSignatures - same message - 64 - blst-native 4.6731 ms/op 3.9466 ms/op 1.18
BLS verifyMultipleSignatures - same message - 128 - blst-native 5.9966 ms/op 6.5415 ms/op 0.92
BLS aggregatePubkeys 32 - blst-native 26.167 us/op 24.424 us/op 1.07
BLS aggregatePubkeys 128 - blst-native 101.84 us/op 88.923 us/op 1.15
getAttestationsForBlock 60.353 ms/op 31.243 ms/op 1.93
getSlashingsAndExits - default max 169.31 us/op 132.72 us/op 1.28
getSlashingsAndExits - 2k 481.19 us/op 349.62 us/op 1.38
proposeBlockBody type=full, size=empty 5.4236 ms/op 3.7586 ms/op 1.44
isKnown best case - 1 super set check 519.00 ns/op 424.00 ns/op 1.22
isKnown normal case - 2 super set checks 502.00 ns/op 475.00 ns/op 1.06
isKnown worse case - 16 super set checks 573.00 ns/op 508.00 ns/op 1.13
CheckpointStateCache - add get delete 5.7910 us/op 4.8210 us/op 1.20
validate api signedAggregateAndProof - struct 2.8138 ms/op 2.3880 ms/op 1.18
validate gossip signedAggregateAndProof - struct 2.8030 ms/op 2.4031 ms/op 1.17
validate gossip attestation - vc 640000 1.3649 ms/op 1.1413 ms/op 1.20
batch validate gossip attestation - vc 640000 - chunk 32 163.25 us/op 140.92 us/op 1.16
batch validate gossip attestation - vc 640000 - chunk 64 144.47 us/op 126.50 us/op 1.14
batch validate gossip attestation - vc 640000 - chunk 128 143.53 us/op 116.80 us/op 1.23
batch validate gossip attestation - vc 640000 - chunk 256 147.68 us/op 110.46 us/op 1.34
pickEth1Vote - no votes 1.4450 ms/op 950.10 us/op 1.52
pickEth1Vote - max votes 13.722 ms/op 11.132 ms/op 1.23
pickEth1Vote - Eth1Data hashTreeRoot value x2048 25.105 ms/op 20.993 ms/op 1.20
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 34.577 ms/op 26.329 ms/op 1.31
pickEth1Vote - Eth1Data fastSerialize value x2048 810.48 us/op 430.52 us/op 1.88
pickEth1Vote - Eth1Data fastSerialize tree x2048 7.5699 ms/op 6.6194 ms/op 1.14
bytes32 toHexString 802.00 ns/op 437.00 ns/op 1.84
bytes32 Buffer.toString(hex) 364.00 ns/op 321.00 ns/op 1.13
bytes32 Buffer.toString(hex) from Uint8Array 620.00 ns/op 477.00 ns/op 1.30
bytes32 Buffer.toString(hex) + 0x 359.00 ns/op 322.00 ns/op 1.11
Object access 1 prop 0.24700 ns/op 0.20000 ns/op 1.23
Map access 1 prop 0.18100 ns/op 0.18600 ns/op 0.97
Object get x1000 7.8980 ns/op 4.9040 ns/op 1.61
Map get x1000 0.92900 ns/op 0.75600 ns/op 1.23
Object set x1000 80.805 ns/op 25.295 ns/op 3.19
Map set x1000 57.927 ns/op 17.412 ns/op 3.33
Return object 10000 times 0.27220 ns/op 0.22200 ns/op 1.23
Throw Error 10000 times 4.0919 us/op 2.7659 us/op 1.48
fastMsgIdFn sha256 / 200 bytes 3.5790 us/op 2.0000 us/op 1.79
fastMsgIdFn h32 xxhash / 200 bytes 382.00 ns/op 301.00 ns/op 1.27
fastMsgIdFn h64 xxhash / 200 bytes 437.00 ns/op 359.00 ns/op 1.22
fastMsgIdFn sha256 / 1000 bytes 11.923 us/op 6.2830 us/op 1.90
fastMsgIdFn h32 xxhash / 1000 bytes 515.00 ns/op 437.00 ns/op 1.18
fastMsgIdFn h64 xxhash / 1000 bytes 517.00 ns/op 411.00 ns/op 1.26
fastMsgIdFn sha256 / 10000 bytes 106.02 us/op 50.885 us/op 2.08
fastMsgIdFn h32 xxhash / 10000 bytes 2.0850 us/op 1.7700 us/op 1.18
fastMsgIdFn h64 xxhash / 10000 bytes 1.4570 us/op 1.2170 us/op 1.20
send data - 1000 256B messages 22.278 ms/op 12.377 ms/op 1.80
send data - 1000 512B messages 29.794 ms/op 15.696 ms/op 1.90
send data - 1000 1024B messages 45.357 ms/op 22.754 ms/op 1.99
send data - 1000 1200B messages 42.551 ms/op 30.524 ms/op 1.39
send data - 1000 2048B messages 45.384 ms/op 33.282 ms/op 1.36
send data - 1000 4096B messages 31.980 ms/op 33.069 ms/op 0.97
send data - 1000 16384B messages 127.26 ms/op 82.067 ms/op 1.55
send data - 1000 65536B messages 471.71 ms/op 401.69 ms/op 1.17
enrSubnets - fastDeserialize 64 bits 1.3050 us/op 1.0010 us/op 1.30
enrSubnets - ssz BitVector 64 bits 448.00 ns/op 502.00 ns/op 0.89
enrSubnets - fastDeserialize 4 bits 188.00 ns/op 218.00 ns/op 0.86
enrSubnets - ssz BitVector 4 bits 454.00 ns/op 474.00 ns/op 0.96
prioritizePeers score -10:0 att 32-0.1 sync 2-0 101.48 us/op 66.169 us/op 1.53
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 131.16 us/op 79.009 us/op 1.66
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 161.01 us/op 120.72 us/op 1.33
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 291.06 us/op 237.05 us/op 1.23
prioritizePeers score 0:0 att 64-1 sync 4-1 355.97 us/op 231.44 us/op 1.54
array of 16000 items push then shift 1.6909 us/op 1.2543 us/op 1.35
LinkedList of 16000 items push then shift 9.2590 ns/op 7.3890 ns/op 1.25
array of 16000 items push then pop 101.21 ns/op 92.394 ns/op 1.10
LinkedList of 16000 items push then pop 9.2130 ns/op 5.7310 ns/op 1.61
array of 24000 items push then shift 2.4363 us/op 1.8290 us/op 1.33
LinkedList of 24000 items push then shift 8.9610 ns/op 6.8110 ns/op 1.32
array of 24000 items push then pop 125.04 ns/op 128.11 ns/op 0.98
LinkedList of 24000 items push then pop 8.4300 ns/op 5.8490 ns/op 1.44
intersect bitArray bitLen 8 6.2560 ns/op 4.8830 ns/op 1.28
intersect array and set length 8 62.571 ns/op 49.880 ns/op 1.25
intersect bitArray bitLen 128 33.487 ns/op 26.959 ns/op 1.24
intersect array and set length 128 884.95 ns/op 688.82 ns/op 1.28
bitArray.getTrueBitIndexes() bitLen 128 1.4770 us/op 1.3480 us/op 1.10
bitArray.getTrueBitIndexes() bitLen 248 2.5250 us/op 2.1230 us/op 1.19
bitArray.getTrueBitIndexes() bitLen 512 4.7890 us/op 4.4260 us/op 1.08
Buffer.concat 32 items 939.00 ns/op 869.00 ns/op 1.08
Uint8Array.set 32 items 1.9060 us/op 1.8570 us/op 1.03
Set add up to 64 items then delete first 4.2974 us/op 1.7100 us/op 2.51
OrderedSet add up to 64 items then delete first 5.4849 us/op 2.6100 us/op 2.10
Set add up to 64 items then delete last 4.5266 us/op 1.9992 us/op 2.26
OrderedSet add up to 64 items then delete last 5.6602 us/op 2.9810 us/op 1.90
Set add up to 64 items then delete middle 4.6500 us/op 1.9423 us/op 2.39
OrderedSet add up to 64 items then delete middle 7.0957 us/op 4.0843 us/op 1.74
Set add up to 128 items then delete first 9.4312 us/op 3.7511 us/op 2.51
OrderedSet add up to 128 items then delete first 12.576 us/op 6.0267 us/op 2.09
Set add up to 128 items then delete last 9.1584 us/op 3.7205 us/op 2.46
OrderedSet add up to 128 items then delete last 11.688 us/op 5.7321 us/op 2.04
Set add up to 128 items then delete middle 9.1396 us/op 3.7733 us/op 2.42
OrderedSet add up to 128 items then delete middle 17.039 us/op 11.322 us/op 1.50
Set add up to 256 items then delete first 18.838 us/op 7.6746 us/op 2.45
OrderedSet add up to 256 items then delete first 25.489 us/op 12.786 us/op 1.99
Set add up to 256 items then delete last 18.279 us/op 7.5113 us/op 2.43
OrderedSet add up to 256 items then delete last 23.560 us/op 11.548 us/op 2.04
Set add up to 256 items then delete middle 18.195 us/op 7.2771 us/op 2.50
OrderedSet add up to 256 items then delete middle 45.481 us/op 32.161 us/op 1.41
transfer serialized Status (84 B) 1.8940 us/op 1.4500 us/op 1.31
copy serialized Status (84 B) 1.5050 us/op 1.3450 us/op 1.12
transfer serialized SignedVoluntaryExit (112 B) 1.9670 us/op 1.5280 us/op 1.29
copy serialized SignedVoluntaryExit (112 B) 1.5920 us/op 1.3800 us/op 1.15
transfer serialized ProposerSlashing (416 B) 2.1330 us/op 1.9890 us/op 1.07
copy serialized ProposerSlashing (416 B) 1.9030 us/op 2.0620 us/op 0.92
transfer serialized Attestation (485 B) 2.1730 us/op 2.1790 us/op 1.00
copy serialized Attestation (485 B) 2.2770 us/op 1.8700 us/op 1.22
transfer serialized AttesterSlashing (33232 B) 2.4600 us/op 2.0230 us/op 1.22
copy serialized AttesterSlashing (33232 B) 5.9210 us/op 6.0460 us/op 0.98
transfer serialized Small SignedBeaconBlock (128000 B) 2.6860 us/op 2.0960 us/op 1.28
copy serialized Small SignedBeaconBlock (128000 B) 14.843 us/op 16.630 us/op 0.89
transfer serialized Avg SignedBeaconBlock (200000 B) 3.0580 us/op 2.9850 us/op 1.02
copy serialized Avg SignedBeaconBlock (200000 B) 21.185 us/op 21.460 us/op 0.99
transfer serialized BlobsSidecar (524380 B) 3.2900 us/op 2.9420 us/op 1.12
copy serialized BlobsSidecar (524380 B) 110.72 us/op 119.00 us/op 0.93
transfer serialized Big SignedBeaconBlock (1000000 B) 3.2500 us/op 3.2640 us/op 1.00
copy serialized Big SignedBeaconBlock (1000000 B) 158.44 us/op 129.42 us/op 1.22
pass gossip attestations to forkchoice per slot 4.4035 ms/op 2.6918 ms/op 1.64
forkChoice updateHead vc 100000 bc 64 eq 0 701.68 us/op 450.82 us/op 1.56
forkChoice updateHead vc 600000 bc 64 eq 0 4.4929 ms/op 2.7949 ms/op 1.61
forkChoice updateHead vc 1000000 bc 64 eq 0 7.4205 ms/op 4.3289 ms/op 1.71
forkChoice updateHead vc 600000 bc 320 eq 0 4.2795 ms/op 2.6196 ms/op 1.63
forkChoice updateHead vc 600000 bc 1200 eq 0 4.3677 ms/op 2.7588 ms/op 1.58
forkChoice updateHead vc 600000 bc 7200 eq 0 5.2919 ms/op 3.4437 ms/op 1.54
forkChoice updateHead vc 600000 bc 64 eq 1000 11.416 ms/op 9.8943 ms/op 1.15
forkChoice updateHead vc 600000 bc 64 eq 10000 12.009 ms/op 9.8351 ms/op 1.22
forkChoice updateHead vc 600000 bc 64 eq 300000 15.787 ms/op 12.385 ms/op 1.27
computeDeltas 500000 validators 300 proto nodes 6.4833 ms/op 3.1556 ms/op 2.05
computeDeltas 500000 validators 1200 proto nodes 6.4104 ms/op 2.9939 ms/op 2.14
computeDeltas 500000 validators 7200 proto nodes 6.3163 ms/op 2.9462 ms/op 2.14
computeDeltas 750000 validators 300 proto nodes 9.5625 ms/op 4.7585 ms/op 2.01
computeDeltas 750000 validators 1200 proto nodes 9.5719 ms/op 5.1949 ms/op 1.84
computeDeltas 750000 validators 7200 proto nodes 9.8052 ms/op 4.8414 ms/op 2.03
computeDeltas 1400000 validators 300 proto nodes 18.649 ms/op 8.9693 ms/op 2.08
computeDeltas 1400000 validators 1200 proto nodes 18.528 ms/op 8.8744 ms/op 2.09
computeDeltas 1400000 validators 7200 proto nodes 18.954 ms/op 9.1561 ms/op 2.07
computeDeltas 2100000 validators 300 proto nodes 28.272 ms/op 13.883 ms/op 2.04
computeDeltas 2100000 validators 1200 proto nodes 28.091 ms/op 14.171 ms/op 1.98
computeDeltas 2100000 validators 7200 proto nodes 28.027 ms/op 13.819 ms/op 2.03
computeProposerBoostScoreFromBalances 500000 validators 3.6984 ms/op 3.2183 ms/op 1.15
computeProposerBoostScoreFromBalances 750000 validators 3.7079 ms/op 3.2188 ms/op 1.15
computeProposerBoostScoreFromBalances 1400000 validators 3.6854 ms/op 3.2697 ms/op 1.13
computeProposerBoostScoreFromBalances 2100000 validators 3.7152 ms/op 3.2960 ms/op 1.13
altair processAttestation - 250000 vs - 7PWei normalcase 2.1668 ms/op 1.6606 ms/op 1.30
altair processAttestation - 250000 vs - 7PWei worstcase 3.4561 ms/op 2.4232 ms/op 1.43
altair processAttestation - setStatus - 1/6 committees join 148.21 us/op 104.38 us/op 1.42
altair processAttestation - setStatus - 1/3 committees join 280.36 us/op 197.31 us/op 1.42
altair processAttestation - setStatus - 1/2 committees join 379.00 us/op 303.69 us/op 1.25
altair processAttestation - setStatus - 2/3 committees join 464.60 us/op 378.50 us/op 1.23
altair processAttestation - setStatus - 4/5 committees join 663.42 us/op 522.44 us/op 1.27
altair processAttestation - setStatus - 100% committees join 769.82 us/op 599.82 us/op 1.28
altair processBlock - 250000 vs - 7PWei normalcase 9.6865 ms/op 10.484 ms/op 0.92
altair processBlock - 250000 vs - 7PWei normalcase hashState 41.473 ms/op 32.336 ms/op 1.28
altair processBlock - 250000 vs - 7PWei worstcase 39.272 ms/op 32.647 ms/op 1.20
altair processBlock - 250000 vs - 7PWei worstcase hashState 100.00 ms/op 80.434 ms/op 1.24
phase0 processBlock - 250000 vs - 7PWei normalcase 2.9903 ms/op 2.3068 ms/op 1.30
phase0 processBlock - 250000 vs - 7PWei worstcase 29.894 ms/op 27.699 ms/op 1.08
altair processEth1Data - 250000 vs - 7PWei normalcase 506.81 us/op 294.92 us/op 1.72
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 9.3650 us/op 14.334 us/op 0.65
getExpectedWithdrawals 250000 eb:0.95,eth1:0.1,we:0.05,wn:0,smpl:219 36.705 us/op 35.655 us/op 1.03
getExpectedWithdrawals 250000 eb:0.95,eth1:0.3,we:0.05,wn:0,smpl:42 13.150 us/op 21.326 us/op 0.62
getExpectedWithdrawals 250000 eb:0.95,eth1:0.7,we:0.05,wn:0,smpl:18 11.521 us/op 8.9110 us/op 1.29
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 135.38 us/op 147.45 us/op 0.92
getExpectedWithdrawals 250000 eb:0.03,eth1:0.03,we:0,wn:0,smpl:11777 1.3788 ms/op 1.4366 ms/op 0.96
getExpectedWithdrawals 250000 eb:0.01,eth1:0.01,we:0,wn:0,smpl:16384 1.5212 ms/op 1.1997 ms/op 1.27
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,smpl:16384 1.4266 ms/op 1.0051 ms/op 1.42
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,nocache,smpl:16384 3.6269 ms/op 2.0999 ms/op 1.73
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,smpl:16384 2.2911 ms/op 1.9279 ms/op 1.19
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,nocache,smpl:16384 5.2602 ms/op 4.1169 ms/op 1.28
Tree 40 250000 create 365.60 ms/op 273.19 ms/op 1.34
Tree 40 250000 get(125000) 196.42 ns/op 113.76 ns/op 1.73
Tree 40 250000 set(125000) 994.33 ns/op 764.40 ns/op 1.30
Tree 40 250000 toArray() 18.007 ms/op 12.188 ms/op 1.48
Tree 40 250000 iterate all - toArray() + loop 18.077 ms/op 13.401 ms/op 1.35
Tree 40 250000 iterate all - get(i) 62.599 ms/op 49.077 ms/op 1.28
MutableVector 250000 create 15.414 ms/op 10.522 ms/op 1.46
MutableVector 250000 get(125000) 6.3880 ns/op 5.6720 ns/op 1.13
MutableVector 250000 set(125000) 248.37 ns/op 223.02 ns/op 1.11
MutableVector 250000 toArray() 3.2168 ms/op 3.5143 ms/op 0.92
MutableVector 250000 iterate all - toArray() + loop 3.2932 ms/op 3.9135 ms/op 0.84
MutableVector 250000 iterate all - get(i) 1.4998 ms/op 1.3444 ms/op 1.12
Array 250000 create 2.8415 ms/op 3.7502 ms/op 0.76
Array 250000 clone - spread 1.2239 ms/op 1.0707 ms/op 1.14
Array 250000 get(125000) 1.0170 ns/op 1.0450 ns/op 0.97
Array 250000 set(125000) 4.1130 ns/op 1.1850 ns/op 3.47
Array 250000 iterate all - loop 161.90 us/op 154.18 us/op 1.05
effectiveBalanceIncrements clone Uint8Array 300000 26.261 us/op 20.756 us/op 1.27
effectiveBalanceIncrements clone MutableVector 300000 363.00 ns/op 363.00 ns/op 1.00
effectiveBalanceIncrements rw all Uint8Array 300000 195.56 us/op 184.56 us/op 1.06
effectiveBalanceIncrements rw all MutableVector 300000 79.333 ms/op 64.711 ms/op 1.23
phase0 afterProcessEpoch - 250000 vs - 7PWei 112.30 ms/op 77.370 ms/op 1.45
phase0 beforeProcessEpoch - 250000 vs - 7PWei 52.676 ms/op 45.930 ms/op 1.15
altair processEpoch - mainnet_e81889 517.65 ms/op 412.11 ms/op 1.26
mainnet_e81889 - altair beforeProcessEpoch 82.101 ms/op 67.273 ms/op 1.22
mainnet_e81889 - altair processJustificationAndFinalization 14.652 us/op 11.519 us/op 1.27
mainnet_e81889 - altair processInactivityUpdates 6.0079 ms/op 5.3892 ms/op 1.11
mainnet_e81889 - altair processRewardsAndPenalties 61.756 ms/op 60.894 ms/op 1.01
mainnet_e81889 - altair processRegistryUpdates 2.6840 us/op 1.7660 us/op 1.52
mainnet_e81889 - altair processSlashings 577.00 ns/op 516.00 ns/op 1.12
mainnet_e81889 - altair processEth1DataReset 431.00 ns/op 531.00 ns/op 0.81
mainnet_e81889 - altair processEffectiveBalanceUpdates 1.4343 ms/op 1.0721 ms/op 1.34
mainnet_e81889 - altair processSlashingsReset 3.5310 us/op 3.0770 us/op 1.15
mainnet_e81889 - altair processRandaoMixesReset 5.8660 us/op 4.2940 us/op 1.37
mainnet_e81889 - altair processHistoricalRootsUpdate 891.00 ns/op 1.1050 us/op 0.81
mainnet_e81889 - altair processParticipationFlagUpdates 1.9390 us/op 1.3430 us/op 1.44
mainnet_e81889 - altair processSyncCommitteeUpdates 597.00 ns/op 636.00 ns/op 0.94
mainnet_e81889 - altair afterProcessEpoch 113.88 ms/op 78.315 ms/op 1.45
capella processEpoch - mainnet_e217614 2.0468 s/op 1.7133 s/op 1.19
mainnet_e217614 - capella beforeProcessEpoch 478.66 ms/op 420.43 ms/op 1.14
mainnet_e217614 - capella processJustificationAndFinalization 14.092 us/op 11.424 us/op 1.23
mainnet_e217614 - capella processInactivityUpdates 21.472 ms/op 16.274 ms/op 1.32
mainnet_e217614 - capella processRewardsAndPenalties 438.83 ms/op 373.55 ms/op 1.17
mainnet_e217614 - capella processRegistryUpdates 16.960 us/op 12.473 us/op 1.36
mainnet_e217614 - capella processSlashings 509.00 ns/op 648.00 ns/op 0.79
mainnet_e217614 - capella processEth1DataReset 436.00 ns/op 584.00 ns/op 0.75
mainnet_e217614 - capella processEffectiveBalanceUpdates 4.9376 ms/op 3.2799 ms/op 1.51
mainnet_e217614 - capella processSlashingsReset 3.2510 us/op 1.5840 us/op 2.05
mainnet_e217614 - capella processRandaoMixesReset 4.7270 us/op 2.9640 us/op 1.59
mainnet_e217614 - capella processHistoricalRootsUpdate 586.00 ns/op 653.00 ns/op 0.90
mainnet_e217614 - capella processParticipationFlagUpdates 1.4610 us/op 1.9640 us/op 0.74
mainnet_e217614 - capella afterProcessEpoch 305.99 ms/op 213.51 ms/op 1.43
phase0 processEpoch - mainnet_e58758 428.72 ms/op 381.67 ms/op 1.12
mainnet_e58758 - phase0 beforeProcessEpoch 132.91 ms/op 114.02 ms/op 1.17
mainnet_e58758 - phase0 processJustificationAndFinalization 15.026 us/op 11.365 us/op 1.32
mainnet_e58758 - phase0 processRewardsAndPenalties 57.818 ms/op 54.167 ms/op 1.07
mainnet_e58758 - phase0 processRegistryUpdates 12.391 us/op 3.7890 us/op 3.27
mainnet_e58758 - phase0 processSlashings 549.00 ns/op 324.00 ns/op 1.69
mainnet_e58758 - phase0 processEth1DataReset 406.00 ns/op 291.00 ns/op 1.40
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 1.1561 ms/op 848.25 us/op 1.36
mainnet_e58758 - phase0 processSlashingsReset 3.3550 us/op 3.1980 us/op 1.05
mainnet_e58758 - phase0 processRandaoMixesReset 4.1710 us/op 2.4480 us/op 1.70
mainnet_e58758 - phase0 processHistoricalRootsUpdate 446.00 ns/op 472.00 ns/op 0.94
mainnet_e58758 - phase0 processParticipationRecordUpdates 3.8740 us/op 2.7690 us/op 1.40
mainnet_e58758 - phase0 afterProcessEpoch 95.980 ms/op 60.033 ms/op 1.60
phase0 processEffectiveBalanceUpdates - 250000 normalcase 1.3886 ms/op 969.06 us/op 1.43
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.4526 ms/op 1.0827 ms/op 1.34
altair processInactivityUpdates - 250000 normalcase 24.292 ms/op 24.763 ms/op 0.98
altair processInactivityUpdates - 250000 worstcase 26.907 ms/op 25.741 ms/op 1.05
phase0 processRegistryUpdates - 250000 normalcase 8.7360 us/op 7.1690 us/op 1.22
phase0 processRegistryUpdates - 250000 badcase_full_deposits 329.43 us/op 360.36 us/op 0.91
phase0 processRegistryUpdates - 250000 worstcase 0.5 124.87 ms/op 121.14 ms/op 1.03
altair processRewardsAndPenalties - 250000 normalcase 45.590 ms/op 60.786 ms/op 0.75
altair processRewardsAndPenalties - 250000 worstcase 57.169 ms/op 55.136 ms/op 1.04
phase0 getAttestationDeltas - 250000 normalcase 9.4645 ms/op 5.1942 ms/op 1.82
phase0 getAttestationDeltas - 250000 worstcase 8.9948 ms/op 5.8199 ms/op 1.55
phase0 processSlashings - 250000 worstcase 98.911 us/op 80.745 us/op 1.22
altair processSyncCommitteeUpdates - 250000 156.58 ms/op 103.56 ms/op 1.51
BeaconState.hashTreeRoot - No change 277.00 ns/op 392.00 ns/op 0.71
BeaconState.hashTreeRoot - 1 full validator 128.06 us/op 116.35 us/op 1.10
BeaconState.hashTreeRoot - 32 full validator 1.4120 ms/op 1.0935 ms/op 1.29
BeaconState.hashTreeRoot - 512 full validator 17.620 ms/op 10.216 ms/op 1.72
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 189.37 us/op 122.11 us/op 1.55
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 2.6727 ms/op 2.1777 ms/op 1.23
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 30.019 ms/op 25.757 ms/op 1.17
BeaconState.hashTreeRoot - 1 balances 148.12 us/op 109.59 us/op 1.35
BeaconState.hashTreeRoot - 32 balances 1.3400 ms/op 1.3402 ms/op 1.00
BeaconState.hashTreeRoot - 512 balances 14.364 ms/op 8.4192 ms/op 1.71
BeaconState.hashTreeRoot - 250000 balances 222.95 ms/op 157.86 ms/op 1.41
aggregationBits - 2048 els - zipIndexesInBitList 17.980 us/op 14.100 us/op 1.28
byteArrayEquals 32 77.712 ns/op 62.793 ns/op 1.24
Buffer.compare 32 57.770 ns/op 36.924 ns/op 1.56
byteArrayEquals 1024 2.0884 us/op 1.6545 us/op 1.26
Buffer.compare 1024 72.807 ns/op 41.783 ns/op 1.74
byteArrayEquals 16384 33.248 us/op 26.410 us/op 1.26
Buffer.compare 16384 258.61 ns/op 197.56 ns/op 1.31
byteArrayEquals 123687377 246.87 ms/op 205.51 ms/op 1.20
Buffer.compare 123687377 7.0999 ms/op 5.7402 ms/op 1.24
byteArrayEquals 32 - diff last byte 73.048 ns/op 58.944 ns/op 1.24
Buffer.compare 32 - diff last byte 57.274 ns/op 38.252 ns/op 1.50
byteArrayEquals 1024 - diff last byte 2.0646 us/op 1.6410 us/op 1.26
Buffer.compare 1024 - diff last byte 71.690 ns/op 43.679 ns/op 1.64
byteArrayEquals 16384 - diff last byte 32.827 us/op 26.588 us/op 1.23
Buffer.compare 16384 - diff last byte 255.78 ns/op 196.61 ns/op 1.30
byteArrayEquals 123687377 - diff last byte 242.60 ms/op 201.71 ms/op 1.20
Buffer.compare 123687377 - diff last byte 6.0794 ms/op 5.8466 ms/op 1.04
byteArrayEquals 32 - random bytes 5.1910 ns/op 5.1880 ns/op 1.00
Buffer.compare 32 - random bytes 58.456 ns/op 38.437 ns/op 1.52
byteArrayEquals 1024 - random bytes 5.0320 ns/op 4.7210 ns/op 1.07
Buffer.compare 1024 - random bytes 58.098 ns/op 36.937 ns/op 1.57
byteArrayEquals 16384 - random bytes 5.0260 ns/op 4.9040 ns/op 1.02
Buffer.compare 16384 - random bytes 58.133 ns/op 36.716 ns/op 1.58
byteArrayEquals 123687377 - random bytes 8.1600 ns/op 7.9000 ns/op 1.03
Buffer.compare 123687377 - random bytes 65.350 ns/op 43.830 ns/op 1.49
regular array get 100000 times 42.881 us/op 41.950 us/op 1.02
wrappedArray get 100000 times 42.818 us/op 41.708 us/op 1.03
arrayWithProxy get 100000 times 13.815 ms/op 10.500 ms/op 1.32
ssz.Root.equals 52.017 ns/op 55.874 ns/op 0.93
byteArrayEquals 51.157 ns/op 55.552 ns/op 0.92
Buffer.compare 10.524 ns/op 9.5450 ns/op 1.10
shuffle list - 16384 els 6.7390 ms/op 4.7625 ms/op 1.42
shuffle list - 250000 els 98.831 ms/op 69.493 ms/op 1.42
processSlot - 1 slots 16.580 us/op 21.456 us/op 0.77
processSlot - 32 slots 3.7364 ms/op 3.5612 ms/op 1.05
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 60.730 ms/op 47.189 ms/op 1.29
getCommitteeAssignments - req 1 vs - 250000 vc 2.4643 ms/op 2.2408 ms/op 1.10
getCommitteeAssignments - req 100 vs - 250000 vc 3.7070 ms/op 3.4954 ms/op 1.06
getCommitteeAssignments - req 1000 vs - 250000 vc 4.0670 ms/op 3.7829 ms/op 1.08
findModifiedValidators - 10000 modified validators 514.90 ms/op 454.49 ms/op 1.13
findModifiedValidators - 1000 modified validators 414.29 ms/op 340.11 ms/op 1.22
findModifiedValidators - 100 modified validators 412.53 ms/op 330.53 ms/op 1.25
findModifiedValidators - 10 modified validators 401.85 ms/op 348.49 ms/op 1.15
findModifiedValidators - 1 modified validators 391.86 ms/op 323.11 ms/op 1.21
findModifiedValidators - no difference 420.02 ms/op 330.75 ms/op 1.27
compare ViewDUs 4.4603 s/op 3.8412 s/op 1.16
compare each validator Uint8Array 1.3397 s/op 1.7436 s/op 0.77
compare ViewDU to Uint8Array 1.1781 s/op 1.1163 s/op 1.06
migrate state 1000000 validators, 24 modified, 0 new 726.30 ms/op 725.64 ms/op 1.00
migrate state 1000000 validators, 1700 modified, 1000 new 980.32 ms/op 958.26 ms/op 1.02
migrate state 1000000 validators, 3400 modified, 2000 new 1.2179 s/op 1.2223 s/op 1.00
migrate state 1500000 validators, 24 modified, 0 new 774.28 ms/op 762.32 ms/op 1.02
migrate state 1500000 validators, 1700 modified, 1000 new 1.0877 s/op 993.34 ms/op 1.10
migrate state 1500000 validators, 3400 modified, 2000 new 1.3187 s/op 963.77 ms/op 1.37
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 4.4200 ns/op 4.8800 ns/op 0.91
state getBlockRootAtSlot - 250000 vs - 7PWei 725.93 ns/op 624.62 ns/op 1.16
computeProposers - vc 250000 9.2452 ms/op 6.8699 ms/op 1.35
computeEpochShuffling - vc 250000 101.87 ms/op 68.984 ms/op 1.48
getNextSyncCommittee - vc 250000 155.34 ms/op 116.01 ms/op 1.34
computeSigningRoot for AttestationData 29.655 us/op 16.771 us/op 1.77
hash AttestationData serialized data then Buffer.toString(base64) 2.2913 us/op 1.2666 us/op 1.81
toHexString serialized data 1.0464 us/op 777.81 ns/op 1.35
Buffer.toString(base64) 214.16 ns/op 137.24 ns/op 1.56

Please sign in to comment.