@lodestar/state-transition 1.41.0-dev.aeb5a213ee → 1.41.0-dev.b847afb846
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/block/externalData.d.ts +2 -1
- package/lib/block/externalData.d.ts.map +1 -1
- package/lib/block/externalData.js +2 -0
- package/lib/block/externalData.js.map +1 -1
- package/lib/block/isValidIndexedAttestation.d.ts +3 -3
- package/lib/block/isValidIndexedAttestation.d.ts.map +1 -1
- package/lib/block/isValidIndexedAttestation.js +4 -4
- package/lib/block/isValidIndexedAttestation.js.map +1 -1
- package/lib/block/isValidIndexedPayloadAttestation.js +1 -1
- package/lib/block/isValidIndexedPayloadAttestation.js.map +1 -1
- package/lib/block/processAttestationPhase0.js +1 -1
- package/lib/block/processAttestationPhase0.js.map +1 -1
- package/lib/block/processAttestationsAltair.js +1 -1
- package/lib/block/processAttestationsAltair.js.map +1 -1
- package/lib/block/processAttesterSlashing.d.ts +2 -2
- package/lib/block/processAttesterSlashing.d.ts.map +1 -1
- package/lib/block/processAttesterSlashing.js +3 -3
- package/lib/block/processAttesterSlashing.js.map +1 -1
- package/lib/block/processExecutionPayloadEnvelope.js +5 -1
- package/lib/block/processExecutionPayloadEnvelope.js.map +1 -1
- package/lib/block/processProposerSlashing.d.ts +2 -2
- package/lib/block/processProposerSlashing.d.ts.map +1 -1
- package/lib/block/processProposerSlashing.js +3 -3
- package/lib/block/processProposerSlashing.js.map +1 -1
- package/lib/block/processRandao.js +1 -1
- package/lib/block/processRandao.js.map +1 -1
- package/lib/block/processSyncCommittee.js +1 -1
- package/lib/block/processSyncCommittee.js.map +1 -1
- package/lib/block/processVoluntaryExit.js +1 -1
- package/lib/block/processVoluntaryExit.js.map +1 -1
- package/lib/block/processWithdrawalRequest.js +2 -2
- package/lib/block/processWithdrawalRequest.js.map +1 -1
- package/lib/cache/epochCache.d.ts +8 -15
- package/lib/cache/epochCache.d.ts.map +1 -1
- package/lib/cache/epochCache.js +34 -33
- package/lib/cache/epochCache.js.map +1 -1
- package/lib/cache/pubkeyCache.d.ts +21 -6
- package/lib/cache/pubkeyCache.d.ts.map +1 -1
- package/lib/cache/pubkeyCache.js +39 -14
- package/lib/cache/pubkeyCache.js.map +1 -1
- package/lib/cache/stateCache.d.ts.map +1 -1
- package/lib/cache/stateCache.js +3 -7
- package/lib/cache/stateCache.js.map +1 -1
- package/lib/cache/syncCommitteeCache.d.ts +3 -2
- package/lib/cache/syncCommitteeCache.d.ts.map +1 -1
- package/lib/cache/syncCommitteeCache.js +4 -4
- package/lib/cache/syncCommitteeCache.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/rewards/attestationsRewards.d.ts +2 -2
- package/lib/rewards/attestationsRewards.d.ts.map +1 -1
- package/lib/rewards/attestationsRewards.js +4 -4
- package/lib/rewards/attestationsRewards.js.map +1 -1
- package/lib/rewards/syncCommitteeRewards.d.ts +2 -2
- package/lib/rewards/syncCommitteeRewards.d.ts.map +1 -1
- package/lib/rewards/syncCommitteeRewards.js +5 -2
- package/lib/rewards/syncCommitteeRewards.js.map +1 -1
- package/lib/signatureSets/proposer.d.ts +2 -2
- package/lib/signatureSets/proposer.d.ts.map +1 -1
- package/lib/signatureSets/proposer.js +2 -2
- package/lib/signatureSets/proposer.js.map +1 -1
- package/lib/signatureSets/randao.d.ts +2 -2
- package/lib/signatureSets/randao.d.ts.map +1 -1
- package/lib/signatureSets/randao.js +2 -2
- package/lib/signatureSets/randao.js.map +1 -1
- package/lib/signatureSets/voluntaryExits.d.ts +2 -2
- package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
- package/lib/signatureSets/voluntaryExits.js +2 -2
- package/lib/signatureSets/voluntaryExits.js.map +1 -1
- package/lib/stateTransition.js +1 -1
- package/lib/stateTransition.js.map +1 -1
- package/lib/stateView/beaconStateView.d.ts.map +1 -1
- package/lib/stateView/beaconStateView.js +10 -12
- package/lib/stateView/beaconStateView.js.map +1 -1
- package/lib/util/signatureSets.d.ts +7 -7
- package/lib/util/signatureSets.d.ts.map +1 -1
- package/lib/util/signatureSets.js +18 -12
- package/lib/util/signatureSets.js.map +1 -1
- package/package.json +7 -7
- package/src/block/externalData.ts +2 -0
- package/src/block/isValidIndexedAttestation.ts +5 -5
- package/src/block/isValidIndexedPayloadAttestation.ts +1 -1
- package/src/block/processAttestationPhase0.ts +1 -1
- package/src/block/processAttestationsAltair.ts +1 -1
- package/src/block/processAttesterSlashing.ts +4 -4
- package/src/block/processExecutionPayloadEnvelope.ts +5 -1
- package/src/block/processProposerSlashing.ts +4 -4
- package/src/block/processRandao.ts +1 -1
- package/src/block/processSyncCommittee.ts +1 -1
- package/src/block/processVoluntaryExit.ts +1 -1
- package/src/block/processWithdrawalRequest.ts +2 -2
- package/src/cache/epochCache.ts +44 -36
- package/src/cache/pubkeyCache.ts +62 -21
- package/src/cache/stateCache.ts +3 -7
- package/src/cache/syncCommitteeCache.ts +4 -5
- package/src/index.ts +1 -1
- package/src/rewards/attestationsRewards.ts +5 -5
- package/src/rewards/syncCommitteeRewards.ts +6 -5
- package/src/signatureSets/proposer.ts +3 -3
- package/src/signatureSets/randao.ts +3 -7
- package/src/signatureSets/voluntaryExits.ts +3 -3
- package/src/stateTransition.ts +1 -1
- package/src/stateView/beaconStateView.ts +10 -12
- package/src/util/signatureSets.ts +23 -17
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/ChainSafe/lodestar/issues"
|
|
13
13
|
},
|
|
14
|
-
"version": "1.41.0-dev.
|
|
14
|
+
"version": "1.41.0-dev.b847afb846",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
@@ -62,14 +62,14 @@
|
|
|
62
62
|
"@chainsafe/pubkey-index-map": "^3.0.0",
|
|
63
63
|
"@chainsafe/ssz": "^1.2.2",
|
|
64
64
|
"@chainsafe/swap-or-not-shuffle": "^1.2.1",
|
|
65
|
-
"@lodestar/config": "^1.41.0-dev.
|
|
66
|
-
"@lodestar/params": "^1.41.0-dev.
|
|
67
|
-
"@lodestar/types": "^1.41.0-dev.
|
|
68
|
-
"@lodestar/utils": "^1.41.0-dev.
|
|
65
|
+
"@lodestar/config": "^1.41.0-dev.b847afb846",
|
|
66
|
+
"@lodestar/params": "^1.41.0-dev.b847afb846",
|
|
67
|
+
"@lodestar/types": "^1.41.0-dev.b847afb846",
|
|
68
|
+
"@lodestar/utils": "^1.41.0-dev.b847afb846",
|
|
69
69
|
"@vekexasia/bigint-buffer2": "^1.1.0"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@lodestar/api": "^1.41.0-dev.
|
|
72
|
+
"@lodestar/api": "^1.41.0-dev.b847afb846"
|
|
73
73
|
},
|
|
74
74
|
"keywords": [
|
|
75
75
|
"ethereum",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"beacon",
|
|
78
78
|
"blockchain"
|
|
79
79
|
],
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "545a634cab90a74fd09d90001aedd9ed757b7019"
|
|
81
81
|
}
|
|
@@ -18,6 +18,8 @@ export enum DataAvailabilityStatus {
|
|
|
18
18
|
/* validator activities can't be performed on out of range data */
|
|
19
19
|
OutOfRange = "OutOfRange",
|
|
20
20
|
Available = "Available",
|
|
21
|
+
/* Gloas: beacon blocks have no DA requirement, execution payload is separate */
|
|
22
|
+
NotRequired = "NotRequired",
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export interface BlockExternalData {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
2
|
import {ForkSeq, MAX_COMMITTEES_PER_SLOT, MAX_VALIDATORS_PER_COMMITTEE} from "@lodestar/params";
|
|
3
3
|
import {IndexedAttestation, IndexedAttestationBigint, Slot} from "@lodestar/types";
|
|
4
|
-
import {
|
|
4
|
+
import {PubkeyCache} from "../cache/pubkeyCache.js";
|
|
5
5
|
import {getIndexedAttestationBigintSignatureSet, getIndexedAttestationSignatureSet} from "../signatureSets/index.js";
|
|
6
6
|
import {verifySignatureSet} from "../util/index.js";
|
|
7
7
|
|
|
@@ -10,7 +10,7 @@ import {verifySignatureSet} from "../util/index.js";
|
|
|
10
10
|
*/
|
|
11
11
|
export function isValidIndexedAttestation(
|
|
12
12
|
config: BeaconConfig,
|
|
13
|
-
|
|
13
|
+
pubkeyCache: PubkeyCache,
|
|
14
14
|
stateSlot: Slot,
|
|
15
15
|
validatorsLen: number,
|
|
16
16
|
indexedAttestation: IndexedAttestation,
|
|
@@ -21,14 +21,14 @@ export function isValidIndexedAttestation(
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
if (verifySignature) {
|
|
24
|
-
return verifySignatureSet(getIndexedAttestationSignatureSet(config, stateSlot, indexedAttestation),
|
|
24
|
+
return verifySignatureSet(getIndexedAttestationSignatureSet(config, stateSlot, indexedAttestation), pubkeyCache);
|
|
25
25
|
}
|
|
26
26
|
return true;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export function isValidIndexedAttestationBigint(
|
|
30
30
|
config: BeaconConfig,
|
|
31
|
-
|
|
31
|
+
pubkeyCache: PubkeyCache,
|
|
32
32
|
stateSlot: Slot,
|
|
33
33
|
validatorsLen: number,
|
|
34
34
|
indexedAttestation: IndexedAttestationBigint,
|
|
@@ -41,7 +41,7 @@ export function isValidIndexedAttestationBigint(
|
|
|
41
41
|
if (verifySignature) {
|
|
42
42
|
return verifySignatureSet(
|
|
43
43
|
getIndexedAttestationBigintSignatureSet(config, stateSlot, indexedAttestation),
|
|
44
|
-
|
|
44
|
+
pubkeyCache
|
|
45
45
|
);
|
|
46
46
|
}
|
|
47
47
|
return true;
|
|
@@ -18,7 +18,7 @@ export function isValidIndexedPayloadAttestation(
|
|
|
18
18
|
if (verifySignature) {
|
|
19
19
|
return verifySignatureSet(
|
|
20
20
|
getIndexedPayloadAttestationSignatureSet(state.config, indexedPayloadAttestation),
|
|
21
|
-
state.epochCtx.
|
|
21
|
+
state.epochCtx.pubkeyCache
|
|
22
22
|
);
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -64,7 +64,7 @@ export function processAttestationsAltair(
|
|
|
64
64
|
// we can verify only that and nothing else.
|
|
65
65
|
if (verifySignature) {
|
|
66
66
|
const sigSet = getAttestationWithIndicesSignatureSet(state.config, state.slot, attestation, attestingIndices);
|
|
67
|
-
if (!verifySignatureSet(sigSet, state.epochCtx.
|
|
67
|
+
if (!verifySignatureSet(sigSet, state.epochCtx.pubkeyCache)) {
|
|
68
68
|
throw new Error("Attestation signature is not valid");
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
2
2
|
import {ForkSeq} from "@lodestar/params";
|
|
3
3
|
import {AttesterSlashing, Slot} from "@lodestar/types";
|
|
4
|
-
import {
|
|
4
|
+
import {PubkeyCache} from "../cache/pubkeyCache.js";
|
|
5
5
|
import {CachedBeaconStateAllForks} from "../types.js";
|
|
6
6
|
import {getAttesterSlashableIndices, isSlashableAttestationData, isSlashableValidator} from "../util/index.js";
|
|
7
7
|
import {isValidIndexedAttestationBigint} from "./isValidIndexedAttestation.js";
|
|
@@ -22,7 +22,7 @@ export function processAttesterSlashing(
|
|
|
22
22
|
const {epochCtx} = state;
|
|
23
23
|
assertValidAttesterSlashing(
|
|
24
24
|
state.config,
|
|
25
|
-
epochCtx.
|
|
25
|
+
epochCtx.pubkeyCache,
|
|
26
26
|
state.slot,
|
|
27
27
|
state.validators.length,
|
|
28
28
|
attesterSlashing,
|
|
@@ -48,7 +48,7 @@ export function processAttesterSlashing(
|
|
|
48
48
|
|
|
49
49
|
export function assertValidAttesterSlashing(
|
|
50
50
|
config: BeaconConfig,
|
|
51
|
-
|
|
51
|
+
pubkeyCache: PubkeyCache,
|
|
52
52
|
stateSlot: Slot,
|
|
53
53
|
validatorsLen: number,
|
|
54
54
|
attesterSlashing: AttesterSlashing,
|
|
@@ -66,7 +66,7 @@ export function assertValidAttesterSlashing(
|
|
|
66
66
|
// can be any arbitrary value. Must use bigint variants to hash correctly to all possible values
|
|
67
67
|
for (const [i, attestation] of [attestation1, attestation2].entries()) {
|
|
68
68
|
if (
|
|
69
|
-
!isValidIndexedAttestationBigint(config,
|
|
69
|
+
!isValidIndexedAttestationBigint(config, pubkeyCache, stateSlot, validatorsLen, attestation, verifySignatures)
|
|
70
70
|
) {
|
|
71
71
|
throw new Error(`AttesterSlashing attestation${i} is invalid`);
|
|
72
72
|
}
|
|
@@ -156,7 +156,11 @@ function verifyExecutionPayloadEnvelopeSignature(
|
|
|
156
156
|
|
|
157
157
|
if (builderIndex === BUILDER_INDEX_SELF_BUILD) {
|
|
158
158
|
const validatorIndex = state.latestBlockHeader.proposerIndex;
|
|
159
|
-
|
|
159
|
+
const proposerPubkey = state.epochCtx.pubkeyCache.get(validatorIndex);
|
|
160
|
+
if (!proposerPubkey) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
publicKey = proposerPubkey;
|
|
160
164
|
} else {
|
|
161
165
|
publicKey = PublicKey.fromBytes(state.builders.getReadonly(builderIndex).pubkey);
|
|
162
166
|
}
|
|
@@ -2,7 +2,7 @@ import {BeaconConfig} from "@lodestar/config";
|
|
|
2
2
|
import {ForkSeq, SLOTS_PER_EPOCH} from "@lodestar/params";
|
|
3
3
|
import {Slot, phase0, ssz} from "@lodestar/types";
|
|
4
4
|
import {Validator} from "@lodestar/types/phase0";
|
|
5
|
-
import {
|
|
5
|
+
import {PubkeyCache} from "../cache/pubkeyCache.js";
|
|
6
6
|
import {getProposerSlashingSignatureSets} from "../signatureSets/index.js";
|
|
7
7
|
import {CachedBeaconStateAllForks, CachedBeaconStateGloas} from "../types.js";
|
|
8
8
|
import {computeEpochAtSlot, isSlashableValidator} from "../util/index.js";
|
|
@@ -24,7 +24,7 @@ export function processProposerSlashing(
|
|
|
24
24
|
const proposer = state.validators.getReadonly(proposerSlashing.signedHeader1.message.proposerIndex);
|
|
25
25
|
assertValidProposerSlashing(
|
|
26
26
|
state.config,
|
|
27
|
-
state.epochCtx.
|
|
27
|
+
state.epochCtx.pubkeyCache,
|
|
28
28
|
state.slot,
|
|
29
29
|
proposerSlashing,
|
|
30
30
|
proposer,
|
|
@@ -57,7 +57,7 @@ export function processProposerSlashing(
|
|
|
57
57
|
|
|
58
58
|
export function assertValidProposerSlashing(
|
|
59
59
|
config: BeaconConfig,
|
|
60
|
-
|
|
60
|
+
pubkeyCache: PubkeyCache,
|
|
61
61
|
stateSlot: Slot,
|
|
62
62
|
proposerSlashing: phase0.ProposerSlashing,
|
|
63
63
|
proposer: Validator,
|
|
@@ -94,7 +94,7 @@ export function assertValidProposerSlashing(
|
|
|
94
94
|
if (verifySignatures) {
|
|
95
95
|
const signatureSets = getProposerSlashingSignatureSets(config, stateSlot, proposerSlashing);
|
|
96
96
|
for (let i = 0; i < signatureSets.length; i++) {
|
|
97
|
-
if (!verifySignatureSet(signatureSets[i],
|
|
97
|
+
if (!verifySignatureSet(signatureSets[i], pubkeyCache)) {
|
|
98
98
|
throw new Error(`ProposerSlashing header${i + 1} signature invalid`);
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -17,7 +17,7 @@ export function processRandao(state: CachedBeaconStateAllForks, block: BeaconBlo
|
|
|
17
17
|
const randaoReveal = block.body.randaoReveal;
|
|
18
18
|
|
|
19
19
|
// verify RANDAO reveal
|
|
20
|
-
if (verifySignature && !verifyRandaoSignature(config, epochCtx.
|
|
20
|
+
if (verifySignature && !verifyRandaoSignature(config, epochCtx.pubkeyCache, block)) {
|
|
21
21
|
throw new Error("RANDAO reveal is an invalid signature");
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -32,7 +32,7 @@ export function processSyncAggregate(
|
|
|
32
32
|
participantIndices
|
|
33
33
|
);
|
|
34
34
|
// When there's no participation we consider the signature valid and just ignore it
|
|
35
|
-
if (signatureSet !== null && !verifySignatureSet(signatureSet, state.epochCtx.
|
|
35
|
+
if (signatureSet !== null && !verifySignatureSet(signatureSet, state.epochCtx.pubkeyCache)) {
|
|
36
36
|
throw Error("Sync committee signature invalid");
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -131,7 +131,7 @@ export function getVoluntaryExitValidity(
|
|
|
131
131
|
|
|
132
132
|
if (
|
|
133
133
|
verifySignature &&
|
|
134
|
-
!verifyVoluntaryExitSignature(state.config, epochCtx.
|
|
134
|
+
!verifyVoluntaryExitSignature(state.config, epochCtx.pubkeyCache, state.slot, signedVoluntaryExit)
|
|
135
135
|
) {
|
|
136
136
|
return VoluntaryExitValidity.invalidSignature;
|
|
137
137
|
}
|
|
@@ -21,7 +21,7 @@ export function processWithdrawalRequest(
|
|
|
21
21
|
const amount = Number(withdrawalRequest.amount);
|
|
22
22
|
const {pendingPartialWithdrawals, validators, epochCtx} = state;
|
|
23
23
|
// no need to use unfinalized pubkey cache from 6110 as validator won't be active anyway
|
|
24
|
-
const {
|
|
24
|
+
const {pubkeyCache, config} = epochCtx;
|
|
25
25
|
const isFullExitRequest = amount === FULL_EXIT_REQUEST_AMOUNT;
|
|
26
26
|
|
|
27
27
|
// If partial withdrawal queue is full, only full exits are processed
|
|
@@ -31,7 +31,7 @@ export function processWithdrawalRequest(
|
|
|
31
31
|
|
|
32
32
|
// bail out if validator is not in beacon state
|
|
33
33
|
// note that we don't need to check for 6110 unfinalized vals as they won't be eligible for withdraw/exit anyway
|
|
34
|
-
const validatorIndex =
|
|
34
|
+
const validatorIndex = pubkeyCache.getIndex(withdrawalRequest.validatorPubkey);
|
|
35
35
|
if (validatorIndex === null) {
|
|
36
36
|
return;
|
|
37
37
|
}
|
package/src/cache/epochCache.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {PublicKey} from "@chainsafe/blst";
|
|
2
|
-
import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
|
|
3
2
|
import {BeaconConfig, ChainConfig, createBeaconConfig} from "@lodestar/config";
|
|
4
3
|
import {
|
|
5
4
|
ATTESTATION_SUBNET_COUNT,
|
|
@@ -56,7 +55,7 @@ import {computeBaseRewardPerIncrement, computeSyncParticipantReward} from "../ut
|
|
|
56
55
|
import {sumTargetUnslashedBalanceIncrements} from "../util/targetUnslashedBalance.js";
|
|
57
56
|
import {EffectiveBalanceIncrements, getEffectiveBalanceIncrementsWithLen} from "./effectiveBalanceIncrements.js";
|
|
58
57
|
import {EpochTransitionCache} from "./epochTransitionCache.js";
|
|
59
|
-
import {
|
|
58
|
+
import {PubkeyCache, createPubkeyCache, syncPubkeys} from "./pubkeyCache.js";
|
|
60
59
|
import {CachedBeaconStateAllForks, CachedBeaconStateFulu} from "./stateCache.js";
|
|
61
60
|
import {
|
|
62
61
|
SyncCommitteeCache,
|
|
@@ -71,8 +70,7 @@ export const PROPOSER_WEIGHT_FACTOR = PROPOSER_WEIGHT / (WEIGHT_DENOMINATOR - PR
|
|
|
71
70
|
|
|
72
71
|
export type EpochCacheImmutableData = {
|
|
73
72
|
config: BeaconConfig;
|
|
74
|
-
|
|
75
|
-
index2pubkey: Index2PubkeyCache;
|
|
73
|
+
pubkeyCache: PubkeyCache;
|
|
76
74
|
};
|
|
77
75
|
|
|
78
76
|
export type EpochCacheOpts = {
|
|
@@ -111,15 +109,9 @@ export class EpochCache {
|
|
|
111
109
|
/**
|
|
112
110
|
* Unique globally shared pubkey registry. There should only exist one for the entire application.
|
|
113
111
|
*
|
|
114
|
-
*
|
|
112
|
+
* Couples both index→pubkey and pubkey→index lookups, keeping them in sync atomically.
|
|
115
113
|
*/
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Unique globally shared pubkey registry. There should only exist one for the entire application.
|
|
119
|
-
*
|
|
120
|
-
* $VALIDATOR_COUNT x BLST deserialized pubkey (Jacobian coordinates)
|
|
121
|
-
*/
|
|
122
|
-
index2pubkey: Index2PubkeyCache;
|
|
114
|
+
pubkeyCache: PubkeyCache;
|
|
123
115
|
/**
|
|
124
116
|
* Indexes of the block proposers for the current epoch.
|
|
125
117
|
* For pre-fulu, this is computed and cached from the current shuffling.
|
|
@@ -234,7 +226,9 @@ export class EpochCache {
|
|
|
234
226
|
/** TODO: Indexed SyncCommitteeCache */
|
|
235
227
|
nextSyncCommitteeIndexed: SyncCommitteeCache;
|
|
236
228
|
|
|
237
|
-
// TODO GLOAS: See if we need to
|
|
229
|
+
// TODO GLOAS: See if we need to cache PTC for next epoch
|
|
230
|
+
// PTC for previous epoch, required for slot N block validating slot N-1 attestations
|
|
231
|
+
previousPayloadTimelinessCommittees: Uint32Array[];
|
|
238
232
|
// PTC for current epoch, computed eagerly at epoch transition
|
|
239
233
|
payloadTimelinessCommittees: Uint32Array[];
|
|
240
234
|
|
|
@@ -249,8 +243,7 @@ export class EpochCache {
|
|
|
249
243
|
|
|
250
244
|
constructor(data: {
|
|
251
245
|
config: BeaconConfig;
|
|
252
|
-
|
|
253
|
-
index2pubkey: Index2PubkeyCache;
|
|
246
|
+
pubkeyCache: PubkeyCache;
|
|
254
247
|
proposers: number[];
|
|
255
248
|
proposersPrevEpoch: number[] | null;
|
|
256
249
|
proposersNextEpoch: ProposersDeferred;
|
|
@@ -275,13 +268,13 @@ export class EpochCache {
|
|
|
275
268
|
previousTargetUnslashedBalanceIncrements: number;
|
|
276
269
|
currentSyncCommitteeIndexed: SyncCommitteeCache;
|
|
277
270
|
nextSyncCommitteeIndexed: SyncCommitteeCache;
|
|
271
|
+
previousPayloadTimelinessCommittees: Uint32Array[];
|
|
278
272
|
payloadTimelinessCommittees: Uint32Array[];
|
|
279
273
|
epoch: Epoch;
|
|
280
274
|
syncPeriod: SyncPeriod;
|
|
281
275
|
}) {
|
|
282
276
|
this.config = data.config;
|
|
283
|
-
this.
|
|
284
|
-
this.index2pubkey = data.index2pubkey;
|
|
277
|
+
this.pubkeyCache = data.pubkeyCache;
|
|
285
278
|
this.proposers = data.proposers;
|
|
286
279
|
this.proposersPrevEpoch = data.proposersPrevEpoch;
|
|
287
280
|
this.proposersNextEpoch = data.proposersNextEpoch;
|
|
@@ -306,6 +299,7 @@ export class EpochCache {
|
|
|
306
299
|
this.previousTargetUnslashedBalanceIncrements = data.previousTargetUnslashedBalanceIncrements;
|
|
307
300
|
this.currentSyncCommitteeIndexed = data.currentSyncCommitteeIndexed;
|
|
308
301
|
this.nextSyncCommitteeIndexed = data.nextSyncCommitteeIndexed;
|
|
302
|
+
this.previousPayloadTimelinessCommittees = data.previousPayloadTimelinessCommittees;
|
|
309
303
|
this.payloadTimelinessCommittees = data.payloadTimelinessCommittees;
|
|
310
304
|
this.epoch = data.epoch;
|
|
311
305
|
this.syncPeriod = data.syncPeriod;
|
|
@@ -319,7 +313,7 @@ export class EpochCache {
|
|
|
319
313
|
*/
|
|
320
314
|
static createFromState(
|
|
321
315
|
state: BeaconStateAllForks,
|
|
322
|
-
{config,
|
|
316
|
+
{config, pubkeyCache}: EpochCacheImmutableData,
|
|
323
317
|
opts?: EpochCacheOpts
|
|
324
318
|
): EpochCache {
|
|
325
319
|
const currentEpoch = computeEpochAtSlot(state.slot);
|
|
@@ -335,9 +329,9 @@ export class EpochCache {
|
|
|
335
329
|
const validatorCount = validators.length;
|
|
336
330
|
|
|
337
331
|
// syncPubkeys here to ensure EpochCacheImmutableData is popualted before computing the rest of caches
|
|
338
|
-
// - computeSyncCommitteeCache() needs a fully populated
|
|
332
|
+
// - computeSyncCommitteeCache() needs a fully populated pubkeyCache
|
|
339
333
|
if (!opts?.skipSyncPubkeys) {
|
|
340
|
-
syncPubkeys(
|
|
334
|
+
syncPubkeys(pubkeyCache, validators);
|
|
341
335
|
}
|
|
342
336
|
|
|
343
337
|
const effectiveBalanceIncrements = getEffectiveBalanceIncrementsWithLen(validatorCount);
|
|
@@ -450,14 +444,15 @@ export class EpochCache {
|
|
|
450
444
|
// Allow to skip populating sync committee for initializeBeaconStateFromEth1()
|
|
451
445
|
if (afterAltairFork && !opts?.skipSyncCommitteeCache) {
|
|
452
446
|
const altairState = state as BeaconStateAltair;
|
|
453
|
-
currentSyncCommitteeIndexed = computeSyncCommitteeCache(altairState.currentSyncCommittee,
|
|
454
|
-
nextSyncCommitteeIndexed = computeSyncCommitteeCache(altairState.nextSyncCommittee,
|
|
447
|
+
currentSyncCommitteeIndexed = computeSyncCommitteeCache(altairState.currentSyncCommittee, pubkeyCache);
|
|
448
|
+
nextSyncCommitteeIndexed = computeSyncCommitteeCache(altairState.nextSyncCommittee, pubkeyCache);
|
|
455
449
|
} else {
|
|
456
450
|
currentSyncCommitteeIndexed = new SyncCommitteeCacheEmpty();
|
|
457
451
|
nextSyncCommitteeIndexed = new SyncCommitteeCacheEmpty();
|
|
458
452
|
}
|
|
459
453
|
|
|
460
|
-
// Compute PTC
|
|
454
|
+
// Compute PTC for all slots in the prev/current epoch
|
|
455
|
+
let previousPayloadTimelinessCommittees: Uint32Array[] = [];
|
|
461
456
|
let payloadTimelinessCommittees: Uint32Array[] = [];
|
|
462
457
|
if (currentEpoch >= config.GLOAS_FORK_EPOCH) {
|
|
463
458
|
payloadTimelinessCommittees = computePayloadTimelinessCommitteesForEpoch(
|
|
@@ -466,6 +461,15 @@ export class EpochCache {
|
|
|
466
461
|
currentShuffling.committees,
|
|
467
462
|
effectiveBalanceIncrements
|
|
468
463
|
);
|
|
464
|
+
|
|
465
|
+
if (!isGenesis && previousEpoch >= config.GLOAS_FORK_EPOCH) {
|
|
466
|
+
previousPayloadTimelinessCommittees = computePayloadTimelinessCommitteesForEpoch(
|
|
467
|
+
state,
|
|
468
|
+
previousEpoch,
|
|
469
|
+
previousShuffling.committees,
|
|
470
|
+
effectiveBalanceIncrements
|
|
471
|
+
);
|
|
472
|
+
}
|
|
469
473
|
}
|
|
470
474
|
|
|
471
475
|
// Precompute churnLimit for efficient initiateValidatorExit() during block proposing MUST be recompute everytime the
|
|
@@ -514,8 +518,7 @@ export class EpochCache {
|
|
|
514
518
|
|
|
515
519
|
return new EpochCache({
|
|
516
520
|
config,
|
|
517
|
-
|
|
518
|
-
index2pubkey,
|
|
521
|
+
pubkeyCache,
|
|
519
522
|
proposers,
|
|
520
523
|
// On first epoch, set to null to prevent unnecessary work since this is only used for metrics
|
|
521
524
|
proposersPrevEpoch: null,
|
|
@@ -541,6 +544,7 @@ export class EpochCache {
|
|
|
541
544
|
currentTargetUnslashedBalanceIncrements,
|
|
542
545
|
currentSyncCommitteeIndexed,
|
|
543
546
|
nextSyncCommitteeIndexed,
|
|
547
|
+
previousPayloadTimelinessCommittees,
|
|
544
548
|
payloadTimelinessCommittees,
|
|
545
549
|
epoch: currentEpoch,
|
|
546
550
|
syncPeriod: computeSyncPeriodAtEpoch(currentEpoch),
|
|
@@ -557,8 +561,7 @@ export class EpochCache {
|
|
|
557
561
|
return new EpochCache({
|
|
558
562
|
config: this.config,
|
|
559
563
|
// Common append-only structures shared with all states, no need to clone
|
|
560
|
-
|
|
561
|
-
index2pubkey: this.index2pubkey,
|
|
564
|
+
pubkeyCache: this.pubkeyCache,
|
|
562
565
|
// Immutable data
|
|
563
566
|
proposers: this.proposers,
|
|
564
567
|
proposersPrevEpoch: this.proposersPrevEpoch,
|
|
@@ -587,6 +590,7 @@ export class EpochCache {
|
|
|
587
590
|
currentTargetUnslashedBalanceIncrements: this.currentTargetUnslashedBalanceIncrements,
|
|
588
591
|
currentSyncCommitteeIndexed: this.currentSyncCommitteeIndexed,
|
|
589
592
|
nextSyncCommitteeIndexed: this.nextSyncCommitteeIndexed,
|
|
593
|
+
previousPayloadTimelinessCommittees: this.previousPayloadTimelinessCommittees,
|
|
590
594
|
payloadTimelinessCommittees: this.payloadTimelinessCommittees,
|
|
591
595
|
epoch: this.epoch,
|
|
592
596
|
syncPeriod: this.syncPeriod,
|
|
@@ -698,6 +702,8 @@ export class EpochCache {
|
|
|
698
702
|
|
|
699
703
|
this.proposersPrevEpoch = this.proposers;
|
|
700
704
|
if (upcomingEpoch >= this.config.GLOAS_FORK_EPOCH) {
|
|
705
|
+
// Shift and compute current epoch PTC eagerly for all slots
|
|
706
|
+
this.previousPayloadTimelinessCommittees = this.payloadTimelinessCommittees;
|
|
701
707
|
this.payloadTimelinessCommittees = computePayloadTimelinessCommitteesForEpoch(
|
|
702
708
|
state,
|
|
703
709
|
upcomingEpoch,
|
|
@@ -882,16 +888,15 @@ export class EpochCache {
|
|
|
882
888
|
* Return pubkey given the validator index.
|
|
883
889
|
*/
|
|
884
890
|
getPubkey(index: ValidatorIndex): PublicKey | undefined {
|
|
885
|
-
return this.
|
|
891
|
+
return this.pubkeyCache.get(index);
|
|
886
892
|
}
|
|
887
893
|
|
|
888
894
|
getValidatorIndex(pubkey: Uint8Array): ValidatorIndex | null {
|
|
889
|
-
return this.
|
|
895
|
+
return this.pubkeyCache.getIndex(pubkey);
|
|
890
896
|
}
|
|
891
897
|
|
|
892
898
|
addPubkey(index: ValidatorIndex, pubkey: Uint8Array): void {
|
|
893
|
-
this.
|
|
894
|
-
this.index2pubkey[index] = PublicKey.fromBytes(pubkey); // Optimize for aggregation
|
|
899
|
+
this.pubkeyCache.set(index, pubkey);
|
|
895
900
|
}
|
|
896
901
|
|
|
897
902
|
getShufflingAtSlot(slot: Slot): EpochShuffling {
|
|
@@ -1029,11 +1034,15 @@ export class EpochCache {
|
|
|
1029
1034
|
throw new Error("Payload Timeliness Committee is not available before gloas fork");
|
|
1030
1035
|
}
|
|
1031
1036
|
|
|
1032
|
-
if (epoch
|
|
1033
|
-
|
|
1037
|
+
if (epoch === this.epoch) {
|
|
1038
|
+
return this.payloadTimelinessCommittees[slot % SLOTS_PER_EPOCH];
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
if (epoch === this.epoch - 1 && this.previousPayloadTimelinessCommittees.length > 0) {
|
|
1042
|
+
return this.previousPayloadTimelinessCommittees[slot % SLOTS_PER_EPOCH];
|
|
1034
1043
|
}
|
|
1035
1044
|
|
|
1036
|
-
|
|
1045
|
+
throw new Error(`Payload Timeliness Committee is not available for slot=${slot}`);
|
|
1037
1046
|
}
|
|
1038
1047
|
|
|
1039
1048
|
getIndexedPayloadAttestation(
|
|
@@ -1099,7 +1108,6 @@ export function createEmptyEpochCacheImmutableData(
|
|
|
1099
1108
|
return {
|
|
1100
1109
|
config: createBeaconConfig(chainConfig, state.genesisValidatorsRoot),
|
|
1101
1110
|
// This is a test state, there's no need to have a global shared cache of keys
|
|
1102
|
-
|
|
1103
|
-
index2pubkey: [],
|
|
1111
|
+
pubkeyCache: createPubkeyCache(),
|
|
1104
1112
|
};
|
|
1105
1113
|
}
|
package/src/cache/pubkeyCache.ts
CHANGED
|
@@ -1,33 +1,74 @@
|
|
|
1
1
|
import {PublicKey} from "@chainsafe/blst";
|
|
2
2
|
import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
|
|
3
|
-
import {phase0} from "@lodestar/types";
|
|
3
|
+
import {ValidatorIndex, phase0} from "@lodestar/types";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Unified pubkey cache coupling index→pubkey and pubkey→index lookups.
|
|
7
|
+
* Both directions are kept in sync atomically via `set()`.
|
|
8
|
+
*/
|
|
9
|
+
export interface PubkeyCache {
|
|
10
|
+
/** Get deserialized PublicKey by validator index */
|
|
11
|
+
get(index: ValidatorIndex): PublicKey | undefined;
|
|
12
|
+
/** Get deserialized PublicKey by validator index or throw if not found */
|
|
13
|
+
getOrThrow(index: ValidatorIndex): PublicKey;
|
|
14
|
+
/** Get validator index by pubkey bytes */
|
|
15
|
+
getIndex(pubkey: Uint8Array): ValidatorIndex | null;
|
|
16
|
+
/** Set both directions atomically. Takes raw pubkey bytes — deserialization is handled internally. */
|
|
17
|
+
set(index: ValidatorIndex, pubkey: Uint8Array): void;
|
|
18
|
+
/** Number of entries */
|
|
19
|
+
readonly size: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
class StandardPubkeyCache implements PubkeyCache {
|
|
23
|
+
private readonly pubkey2index: PubkeyIndexMap;
|
|
24
|
+
private readonly index2pubkey: (PublicKey | undefined)[];
|
|
25
|
+
|
|
26
|
+
constructor(pubkey2index?: PubkeyIndexMap, index2pubkey?: (PublicKey | undefined)[]) {
|
|
27
|
+
this.pubkey2index = pubkey2index ?? new PubkeyIndexMap();
|
|
28
|
+
this.index2pubkey = index2pubkey ?? [];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get size(): number {
|
|
32
|
+
return this.pubkey2index.size;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get(index: ValidatorIndex): PublicKey | undefined {
|
|
36
|
+
return this.index2pubkey[index];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getOrThrow(index: ValidatorIndex): PublicKey {
|
|
40
|
+
const pubkey = this.get(index);
|
|
41
|
+
if (!pubkey) throw Error(`Missing pubkey for validator index ${index}`);
|
|
42
|
+
return pubkey;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getIndex(pubkey: Uint8Array): ValidatorIndex | null {
|
|
46
|
+
return this.pubkey2index.get(pubkey);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
set(index: ValidatorIndex, pubkey: Uint8Array): void {
|
|
50
|
+
this.pubkey2index.set(pubkey, index);
|
|
51
|
+
// Pubkeys must be checked for group + inf. This must be done only once when the validator deposit is processed.
|
|
52
|
+
// Afterwards any public key in the state is considered validated.
|
|
53
|
+
// > Do not do any validation here
|
|
54
|
+
this.index2pubkey[index] = PublicKey.fromBytes(pubkey); // Optimize for aggregation
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function createPubkeyCache(): PubkeyCache {
|
|
59
|
+
return new StandardPubkeyCache();
|
|
60
|
+
}
|
|
6
61
|
|
|
7
62
|
/**
|
|
8
63
|
* Checks the pubkey indices against a state and adds missing pubkeys
|
|
9
64
|
*
|
|
10
|
-
* Mutates `
|
|
65
|
+
* Mutates `pubkeyCache`
|
|
11
66
|
*
|
|
12
|
-
* If pubkey
|
|
67
|
+
* If pubkey cache is empty: SLOW CODE - 🐢
|
|
13
68
|
*/
|
|
14
|
-
export function syncPubkeys(
|
|
15
|
-
validators: phase0.Validator[],
|
|
16
|
-
pubkey2index: PubkeyIndexMap,
|
|
17
|
-
index2pubkey: Index2PubkeyCache
|
|
18
|
-
): void {
|
|
19
|
-
if (pubkey2index.size !== index2pubkey.length) {
|
|
20
|
-
throw new Error(`Pubkey indices have fallen out of sync: ${pubkey2index.size} != ${index2pubkey.length}`);
|
|
21
|
-
}
|
|
22
|
-
|
|
69
|
+
export function syncPubkeys(pubkeyCache: PubkeyCache, validators: phase0.Validator[]): void {
|
|
23
70
|
const newCount = validators.length;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const pubkey = validators[i].pubkey;
|
|
27
|
-
pubkey2index.set(pubkey, i);
|
|
28
|
-
// Pubkeys must be checked for group + inf. This must be done only once when the validator deposit is processed.
|
|
29
|
-
// Afterwards any public key is the state consider validated.
|
|
30
|
-
// > Do not do any validation here
|
|
31
|
-
index2pubkey[i] = PublicKey.fromBytes(pubkey); // Optimize for aggregation
|
|
71
|
+
for (let i = pubkeyCache.size; i < newCount; i++) {
|
|
72
|
+
pubkeyCache.set(i, validators[i].pubkey);
|
|
32
73
|
}
|
|
33
74
|
}
|
package/src/cache/stateCache.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {PublicKey} from "@chainsafe/blst";
|
|
2
1
|
import {BeaconConfig} from "@lodestar/config";
|
|
3
2
|
import {loadState} from "../util/loadState/loadState.js";
|
|
4
3
|
import {EpochCache, EpochCacheImmutableData, EpochCacheOpts} from "./epochCache.js";
|
|
@@ -180,22 +179,19 @@ export function loadCachedBeaconState<T extends CachedBeaconStateAllForks>(
|
|
|
180
179
|
stateBytes,
|
|
181
180
|
seedValidatorsBytes
|
|
182
181
|
);
|
|
183
|
-
const {
|
|
182
|
+
const {pubkeyCache} = cachedSeedState.epochCtx;
|
|
184
183
|
// Get the validators sub tree once for all the loop
|
|
185
184
|
const validators = migratedState.validators;
|
|
186
185
|
for (const validatorIndex of modifiedValidators) {
|
|
187
186
|
const validator = validators.getReadonly(validatorIndex);
|
|
188
|
-
|
|
189
|
-
pubkey2index.set(pubkey, validatorIndex);
|
|
190
|
-
index2pubkey[validatorIndex] = PublicKey.fromBytes(pubkey);
|
|
187
|
+
pubkeyCache.set(validatorIndex, validator.pubkey);
|
|
191
188
|
}
|
|
192
189
|
|
|
193
190
|
return createCachedBeaconState(
|
|
194
191
|
migratedState,
|
|
195
192
|
{
|
|
196
193
|
config: cachedSeedState.config,
|
|
197
|
-
|
|
198
|
-
index2pubkey,
|
|
194
|
+
pubkeyCache,
|
|
199
195
|
},
|
|
200
196
|
{...(opts ?? {}), ...{skipSyncPubkeys: true}}
|
|
201
197
|
) as T;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
|
|
2
1
|
import {CompositeViewDU} from "@chainsafe/ssz";
|
|
3
2
|
import {ValidatorIndex, ssz} from "@lodestar/types";
|
|
4
3
|
import {toPubkeyHex} from "@lodestar/utils";
|
|
@@ -39,9 +38,9 @@ export function getSyncCommitteeCache(validatorIndices: Uint32Array): SyncCommit
|
|
|
39
38
|
|
|
40
39
|
export function computeSyncCommitteeCache(
|
|
41
40
|
syncCommittee: CompositeViewDU<typeof ssz.altair.SyncCommittee>,
|
|
42
|
-
|
|
41
|
+
pubkeyCache: {getIndex(pubkey: Uint8Array): number | null}
|
|
43
42
|
): SyncCommitteeCache {
|
|
44
|
-
const validatorIndices = computeSyncCommitteeValidatorIndices(syncCommittee,
|
|
43
|
+
const validatorIndices = computeSyncCommitteeValidatorIndices(syncCommittee, pubkeyCache);
|
|
45
44
|
const validatorIndexMap = computeValidatorSyncCommitteeIndexMap(validatorIndices);
|
|
46
45
|
return {
|
|
47
46
|
validatorIndices,
|
|
@@ -79,12 +78,12 @@ export function computeValidatorSyncCommitteeIndexMap(
|
|
|
79
78
|
*/
|
|
80
79
|
function computeSyncCommitteeValidatorIndices(
|
|
81
80
|
syncCommittee: CompositeViewDU<typeof ssz.altair.SyncCommittee>,
|
|
82
|
-
|
|
81
|
+
pubkeyCache: {getIndex(pubkey: Uint8Array): number | null}
|
|
83
82
|
): Uint32Array {
|
|
84
83
|
const pubkeys = syncCommittee.pubkeys.getAllReadonly();
|
|
85
84
|
const validatorIndices = new Uint32Array(pubkeys.length);
|
|
86
85
|
for (const [i, pubkey] of pubkeys.entries()) {
|
|
87
|
-
const validatorIndex =
|
|
86
|
+
const validatorIndex = pubkeyCache.getIndex(pubkey);
|
|
88
87
|
if (validatorIndex === null) {
|
|
89
88
|
throw Error(`SyncCommittee pubkey is unknown ${toPubkeyHex(pubkey)}`);
|
|
90
89
|
}
|
package/src/index.ts
CHANGED
|
@@ -25,7 +25,7 @@ export {
|
|
|
25
25
|
createEmptyEpochCacheImmutableData,
|
|
26
26
|
} from "./cache/epochCache.js";
|
|
27
27
|
export {type EpochTransitionCache, beforeProcessEpoch} from "./cache/epochTransitionCache.js";
|
|
28
|
-
export {type
|
|
28
|
+
export {type PubkeyCache, createPubkeyCache, syncPubkeys} from "./cache/pubkeyCache.js";
|
|
29
29
|
// Main state caches
|
|
30
30
|
export {
|
|
31
31
|
type BeaconStateCache,
|