@lodestar/state-transition 1.47.0-dev.a27526c22a → 1.47.0-dev.a3a363b2f7
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/isValidIndexedAttestation.d.ts +2 -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.d.ts.map +1 -1
- package/lib/block/isValidIndexedPayloadAttestation.js +1 -1
- package/lib/block/isValidIndexedPayloadAttestation.js.map +1 -1
- package/lib/block/processAttestationPhase0.d.ts.map +1 -1
- package/lib/block/processAttestationPhase0.js +1 -1
- package/lib/block/processAttestationPhase0.js.map +1 -1
- package/lib/block/processAttestationsAltair.js +2 -2
- package/lib/block/processAttestationsAltair.js.map +1 -1
- package/lib/block/processAttesterSlashing.d.ts +1 -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/processDeposit.d.ts.map +1 -1
- package/lib/block/processDeposit.js +21 -46
- package/lib/block/processDeposit.js.map +1 -1
- package/lib/block/processExecutionPayloadBid.d.ts.map +1 -1
- package/lib/block/processExecutionPayloadBid.js +2 -5
- package/lib/block/processExecutionPayloadBid.js.map +1 -1
- package/lib/block/processProposerSlashing.d.ts +1 -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.d.ts.map +1 -1
- package/lib/block/processVoluntaryExit.js +1 -2
- package/lib/block/processVoluntaryExit.js.map +1 -1
- package/lib/cache/epochCache.d.ts +2 -2
- package/lib/cache/epochCache.d.ts.map +1 -1
- package/lib/cache/epochCache.js +5 -6
- package/lib/cache/epochCache.js.map +1 -1
- package/lib/cache/stateCache.js +1 -1
- package/lib/cache/stateCache.js.map +1 -1
- package/lib/cache/syncCommitteeCache.d.ts +2 -3
- package/lib/cache/syncCommitteeCache.d.ts.map +1 -1
- package/lib/cache/syncCommitteeCache.js.map +1 -1
- package/lib/epoch/processSyncCommitteeUpdates.js +1 -1
- package/lib/epoch/processSyncCommitteeUpdates.js.map +1 -1
- package/lib/index.d.ts +3 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -3
- package/lib/index.js.map +1 -1
- package/lib/lightClient/spec/store.d.ts +1 -1
- package/lib/lightClient/spec/store.d.ts.map +1 -1
- package/lib/lightClient/spec/utils.js +1 -1
- package/lib/lightClient/spec/utils.js.map +1 -1
- package/lib/lightClient/spec/validateLightClientUpdate.js +1 -1
- package/lib/lightClient/spec/validateLightClientUpdate.js.map +1 -1
- package/lib/metrics.d.ts +11 -0
- package/lib/metrics.d.ts.map +1 -1
- package/lib/metrics.js +22 -0
- package/lib/metrics.js.map +1 -1
- package/lib/rewards/attestationsRewards.d.ts +1 -1
- package/lib/rewards/attestationsRewards.d.ts.map +1 -1
- package/lib/rewards/attestationsRewards.js.map +1 -1
- package/lib/rewards/syncCommitteeRewards.d.ts +1 -1
- package/lib/rewards/syncCommitteeRewards.d.ts.map +1 -1
- package/lib/rewards/syncCommitteeRewards.js +3 -1
- package/lib/rewards/syncCommitteeRewards.js.map +1 -1
- package/lib/signatureSets/blsToExecutionChange.d.ts.map +1 -1
- package/lib/signatureSets/blsToExecutionChange.js +1 -2
- package/lib/signatureSets/blsToExecutionChange.js.map +1 -1
- package/lib/signatureSets/executionPayloadEnvelope.d.ts +2 -3
- package/lib/signatureSets/executionPayloadEnvelope.d.ts.map +1 -1
- package/lib/signatureSets/executionPayloadEnvelope.js +6 -7
- package/lib/signatureSets/executionPayloadEnvelope.js.map +1 -1
- package/lib/signatureSets/proposer.d.ts +1 -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 +1 -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 +1 -2
- package/lib/signatureSets/voluntaryExits.d.ts.map +1 -1
- package/lib/signatureSets/voluntaryExits.js +3 -4
- package/lib/signatureSets/voluntaryExits.js.map +1 -1
- package/lib/slot/upgradeStateToGloas.d.ts +2 -1
- package/lib/slot/upgradeStateToGloas.d.ts.map +1 -1
- package/lib/slot/upgradeStateToGloas.js +65 -21
- package/lib/slot/upgradeStateToGloas.js.map +1 -1
- package/lib/stateTransition.js +8 -3
- package/lib/stateTransition.js.map +1 -1
- package/lib/stateView/beaconStateView.d.ts +2 -1
- package/lib/stateView/beaconStateView.d.ts.map +1 -1
- package/lib/stateView/beaconStateView.js +6 -1
- package/lib/stateView/beaconStateView.js.map +1 -1
- package/lib/stateView/computeNewStateRoot.d.ts +6 -0
- package/lib/stateView/computeNewStateRoot.d.ts.map +1 -0
- package/lib/stateView/computeNewStateRoot.js +28 -0
- package/lib/stateView/computeNewStateRoot.js.map +1 -0
- package/lib/stateView/interface.d.ts +17 -2
- package/lib/stateView/interface.d.ts.map +1 -1
- package/lib/stateView/interface.js.map +1 -1
- package/lib/stateView/nativeBeaconStateView.d.ts +2 -1
- package/lib/stateView/nativeBeaconStateView.d.ts.map +1 -1
- package/lib/stateView/nativeBeaconStateView.js +5 -0
- package/lib/stateView/nativeBeaconStateView.js.map +1 -1
- package/lib/stateView/stateViewFactory.d.ts +1 -1
- package/lib/stateView/stateViewFactory.d.ts.map +1 -1
- package/lib/stateView/stateViewFactory.js +2 -13
- package/lib/stateView/stateViewFactory.js.map +1 -1
- package/lib/testUtils/index.d.ts +1 -0
- package/lib/testUtils/index.d.ts.map +1 -1
- package/lib/testUtils/index.js +1 -0
- package/lib/testUtils/index.js.map +1 -1
- package/lib/testUtils/interopPubkeyCache.d.ts +7 -0
- package/lib/testUtils/interopPubkeyCache.d.ts.map +1 -0
- package/lib/testUtils/interopPubkeyCache.js +92 -0
- package/lib/testUtils/interopPubkeyCache.js.map +1 -0
- package/lib/testUtils/state.d.ts.map +1 -1
- package/lib/testUtils/state.js +5 -5
- package/lib/testUtils/state.js.map +1 -1
- package/lib/testUtils/testFileCache.d.ts.map +1 -1
- package/lib/testUtils/testFileCache.js +3 -0
- package/lib/testUtils/testFileCache.js.map +1 -1
- package/lib/testUtils/util.d.ts +1 -1
- package/lib/testUtils/util.d.ts.map +1 -1
- package/lib/testUtils/util.js +27 -35
- package/lib/testUtils/util.js.map +1 -1
- package/lib/util/gloas.d.ts +6 -0
- package/lib/util/gloas.d.ts.map +1 -1
- package/lib/util/gloas.js +25 -11
- package/lib/util/gloas.js.map +1 -1
- package/lib/util/interop.d.ts +1 -1
- package/lib/util/interop.d.ts.map +1 -1
- package/lib/util/interop.js +1 -1
- package/lib/util/interop.js.map +1 -1
- package/lib/util/pendingDepositsLookup.d.ts +12 -0
- package/lib/util/pendingDepositsLookup.d.ts.map +1 -1
- package/lib/util/pendingDepositsLookup.js +19 -1
- package/lib/util/pendingDepositsLookup.js.map +1 -1
- package/lib/util/signatureSets.d.ts +5 -13
- package/lib/util/signatureSets.d.ts.map +1 -1
- package/lib/util/signatureSets.js +30 -39
- package/lib/util/signatureSets.js.map +1 -1
- package/lib/util/syncCommittee.js +1 -1
- package/lib/util/syncCommittee.js.map +1 -1
- package/package.json +11 -12
- package/src/block/isValidIndexedAttestation.ts +2 -8
- package/src/block/isValidIndexedPayloadAttestation.ts +1 -4
- package/src/block/processAttestationPhase0.ts +0 -1
- package/src/block/processAttestationsAltair.ts +2 -2
- package/src/block/processAttesterSlashing.ts +2 -13
- package/src/block/processDeposit.ts +35 -47
- package/src/block/processExecutionPayloadBid.ts +8 -6
- package/src/block/processProposerSlashing.ts +2 -11
- package/src/block/processRandao.ts +1 -1
- package/src/block/processSyncCommittee.ts +1 -1
- package/src/block/processVoluntaryExit.ts +1 -4
- package/src/cache/epochCache.ts +6 -7
- package/src/cache/stateCache.ts +1 -1
- package/src/cache/syncCommitteeCache.ts +3 -2
- package/src/epoch/processSyncCommitteeUpdates.ts +1 -1
- package/src/index.ts +8 -7
- package/src/lightClient/spec/store.ts +1 -1
- package/src/lightClient/spec/utils.ts +1 -1
- package/src/lightClient/spec/validateLightClientUpdate.ts +1 -1
- package/src/metrics.ts +23 -0
- package/src/rewards/attestationsRewards.ts +1 -1
- package/src/rewards/syncCommitteeRewards.ts +4 -2
- package/src/signatureSets/blsToExecutionChange.ts +1 -2
- package/src/signatureSets/executionPayloadEnvelope.ts +14 -15
- package/src/signatureSets/proposer.ts +1 -3
- package/src/signatureSets/randao.ts +2 -3
- package/src/signatureSets/voluntaryExits.ts +2 -5
- package/src/slot/upgradeStateToGloas.ts +75 -24
- package/src/stateTransition.ts +8 -3
- package/src/stateView/beaconStateView.ts +16 -1
- package/src/stateView/computeNewStateRoot.ts +35 -0
- package/src/stateView/interface.ts +24 -1
- package/src/stateView/nativeBeaconStateView.ts +10 -0
- package/src/stateView/stateViewFactory.ts +2 -14
- package/src/testUtils/index.ts +1 -0
- package/src/testUtils/interopPubkeyCache.ts +100 -0
- package/src/testUtils/state.ts +5 -11
- package/src/testUtils/testFileCache.ts +3 -0
- package/src/testUtils/util.ts +26 -38
- package/src/util/gloas.ts +40 -11
- package/src/util/interop.ts +1 -1
- package/src/util/pendingDepositsLookup.ts +20 -1
- package/src/util/signatureSets.ts +34 -51
- package/src/util/syncCommittee.ts +1 -1
- package/lib/cache/pubkeyCache.d.ts +0 -28
- package/lib/cache/pubkeyCache.d.ts.map +0 -1
- package/lib/cache/pubkeyCache.js +0 -49
- package/lib/cache/pubkeyCache.js.map +0 -1
- package/src/cache/pubkeyCache.ts +0 -74
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {BLS_VERIFIER_SET_TYPE, type BlsSignatureSet, verifySignatureSets} from "@chainsafe/lodestar-z/bls-verifier";
|
|
2
2
|
import {Root} from "@lodestar/types";
|
|
3
|
-
import {PubkeyCache} from "../cache/pubkeyCache.js";
|
|
4
3
|
|
|
5
4
|
export enum SignatureSetType {
|
|
6
5
|
single = "single",
|
|
@@ -18,7 +17,7 @@ export enum SignatureSetType {
|
|
|
18
17
|
*/
|
|
19
18
|
export type SingleSignatureSet = {
|
|
20
19
|
type: SignatureSetType.single;
|
|
21
|
-
pubkey:
|
|
20
|
+
pubkey: Uint8Array;
|
|
22
21
|
signingRoot: Root;
|
|
23
22
|
signature: Uint8Array;
|
|
24
23
|
};
|
|
@@ -47,59 +46,39 @@ export type AggregatedSignatureSet = {
|
|
|
47
46
|
|
|
48
47
|
export type ISignatureSet = SingleSignatureSet | IndexedSignatureSet | AggregatedSignatureSet;
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
* Get the pubkey for a signature set, performing aggregation if necessary.
|
|
52
|
-
* Requires pubkeyCache for indexed and aggregate sets.
|
|
53
|
-
*/
|
|
54
|
-
export function getSignatureSetPubkey(signatureSet: ISignatureSet, pubkeyCache: PubkeyCache): PublicKey {
|
|
49
|
+
export function toBlsSignatureSet(signatureSet: ISignatureSet): BlsSignatureSet {
|
|
55
50
|
switch (signatureSet.type) {
|
|
56
51
|
case SignatureSetType.single:
|
|
57
|
-
return
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
return {
|
|
53
|
+
type: BLS_VERIFIER_SET_TYPE.single,
|
|
54
|
+
pubkey: signatureSet.pubkey,
|
|
55
|
+
message: signatureSet.signingRoot,
|
|
56
|
+
signature: signatureSet.signature,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
case SignatureSetType.indexed:
|
|
60
|
+
return {
|
|
61
|
+
type: BLS_VERIFIER_SET_TYPE.indexed,
|
|
62
|
+
index: signatureSet.index,
|
|
63
|
+
message: signatureSet.signingRoot,
|
|
64
|
+
signature: signatureSet.signature,
|
|
65
|
+
};
|
|
62
66
|
|
|
63
67
|
case SignatureSetType.aggregate: {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
default:
|
|
71
|
-
throw Error("Unknown signature set type");
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function verifySignatureSet(signatureSet: SingleSignatureSet, pubkeyCache?: PubkeyCache): boolean;
|
|
76
|
-
export function verifySignatureSet(signatureSet: IndexedSignatureSet, pubkeyCache: PubkeyCache): boolean;
|
|
77
|
-
export function verifySignatureSet(signatureSet: AggregatedSignatureSet, pubkeyCache: PubkeyCache): boolean;
|
|
78
|
-
export function verifySignatureSet(signatureSet: ISignatureSet, pubkeyCache: PubkeyCache): boolean;
|
|
79
|
-
export function verifySignatureSet(signatureSet: ISignatureSet, pubkeyCache?: PubkeyCache): boolean {
|
|
80
|
-
// All signatures are not trusted and must be group checked (p2.subgroup_check)
|
|
81
|
-
const signature = Signature.fromBytes(signatureSet.signature, true);
|
|
82
|
-
|
|
83
|
-
switch (signatureSet.type) {
|
|
84
|
-
case SignatureSetType.single:
|
|
85
|
-
return verify(signatureSet.signingRoot, signatureSet.pubkey, signature);
|
|
86
|
-
|
|
87
|
-
case SignatureSetType.indexed: {
|
|
88
|
-
if (!pubkeyCache) {
|
|
89
|
-
throw Error("pubkeyCache required for indexed signature set");
|
|
68
|
+
const indices = new Uint32Array(signatureSet.indices.length);
|
|
69
|
+
for (const [i, index] of signatureSet.indices.entries()) {
|
|
70
|
+
if (!Number.isInteger(index) || index < 0 || index > 0xffffffff) {
|
|
71
|
+
throw new RangeError(`Invalid validator index ${index}`);
|
|
72
|
+
}
|
|
73
|
+
indices[i] = index;
|
|
90
74
|
}
|
|
91
|
-
const pubkey = pubkeyCache.getOrThrow(signatureSet.index);
|
|
92
|
-
return verify(signatureSet.signingRoot, pubkey, signature);
|
|
93
|
-
}
|
|
94
75
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
102
|
-
return fastAggregateVerify(signatureSet.signingRoot, pubkeys, signature);
|
|
76
|
+
return {
|
|
77
|
+
type: BLS_VERIFIER_SET_TYPE.aggregate,
|
|
78
|
+
indices,
|
|
79
|
+
message: signatureSet.signingRoot,
|
|
80
|
+
signature: signatureSet.signature,
|
|
81
|
+
};
|
|
103
82
|
}
|
|
104
83
|
|
|
105
84
|
default:
|
|
@@ -107,8 +86,12 @@ export function verifySignatureSet(signatureSet: ISignatureSet, pubkeyCache?: Pu
|
|
|
107
86
|
}
|
|
108
87
|
}
|
|
109
88
|
|
|
89
|
+
export function verifySignatureSet(signatureSet: ISignatureSet): boolean {
|
|
90
|
+
return verifySignatureSets([toBlsSignatureSet(signatureSet)]);
|
|
91
|
+
}
|
|
92
|
+
|
|
110
93
|
export function createSingleSignatureSetFromComponents(
|
|
111
|
-
pubkey:
|
|
94
|
+
pubkey: Uint8Array,
|
|
112
95
|
signingRoot: Root,
|
|
113
96
|
signature: Uint8Array
|
|
114
97
|
): SingleSignatureSet {
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { PublicKey } from "@chainsafe/blst";
|
|
2
|
-
import { ValidatorIndex, phase0 } from "@lodestar/types";
|
|
3
|
-
/**
|
|
4
|
-
* Unified pubkey cache coupling index→pubkey and pubkey→index lookups.
|
|
5
|
-
* Both directions are kept in sync atomically via `set()`.
|
|
6
|
-
*/
|
|
7
|
-
export interface PubkeyCache {
|
|
8
|
-
/** Get deserialized PublicKey by validator index */
|
|
9
|
-
get(index: ValidatorIndex): PublicKey | undefined;
|
|
10
|
-
/** Get deserialized PublicKey by validator index or throw if not found */
|
|
11
|
-
getOrThrow(index: ValidatorIndex): PublicKey;
|
|
12
|
-
/** Get validator index by pubkey bytes */
|
|
13
|
-
getIndex(pubkey: Uint8Array): ValidatorIndex | null;
|
|
14
|
-
/** Set both directions atomically. Takes raw pubkey bytes — deserialization is handled internally. */
|
|
15
|
-
set(index: ValidatorIndex, pubkey: Uint8Array): void;
|
|
16
|
-
/** Number of entries */
|
|
17
|
-
readonly size: number;
|
|
18
|
-
}
|
|
19
|
-
export declare function createPubkeyCache(): PubkeyCache;
|
|
20
|
-
/**
|
|
21
|
-
* Checks the pubkey indices against a state and adds missing pubkeys
|
|
22
|
-
*
|
|
23
|
-
* Mutates `pubkeyCache`
|
|
24
|
-
*
|
|
25
|
-
* If pubkey cache is empty: SLOW CODE - 🐢
|
|
26
|
-
*/
|
|
27
|
-
export declare function syncPubkeys(pubkeyCache: PubkeyCache, validators: phase0.Validator[]): void;
|
|
28
|
-
//# sourceMappingURL=pubkeyCache.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pubkeyCache.d.ts","sourceRoot":"","sources":["../../src/cache/pubkeyCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAE1C,OAAO,EAAC,cAAc,EAAE,MAAM,EAAC,MAAM,iBAAiB,CAAC;AAEvD;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,oDAAoD;IACpD,GAAG,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,GAAG,SAAS,CAAC;IAClD,0EAA0E;IAC1E,UAAU,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,CAAC;IAC7C,0CAA0C;IAC1C,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,cAAc,GAAG,IAAI,CAAC;IACpD,sGAAsG;IACtG,GAAG,CAAC,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IACrD,wBAAwB;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAsCD,wBAAgB,iBAAiB,IAAI,WAAW,CAE/C;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,CAAC,SAAS,EAAE,GAAG,IAAI,CAK1F"}
|
package/lib/cache/pubkeyCache.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { PublicKey } from "@chainsafe/blst";
|
|
2
|
-
import { PubkeyIndexMap } from "@chainsafe/pubkey-index-map";
|
|
3
|
-
class StandardPubkeyCache {
|
|
4
|
-
pubkey2index;
|
|
5
|
-
index2pubkey;
|
|
6
|
-
constructor(pubkey2index, index2pubkey) {
|
|
7
|
-
this.pubkey2index = pubkey2index ?? new PubkeyIndexMap();
|
|
8
|
-
this.index2pubkey = index2pubkey ?? [];
|
|
9
|
-
}
|
|
10
|
-
get size() {
|
|
11
|
-
return this.pubkey2index.size;
|
|
12
|
-
}
|
|
13
|
-
get(index) {
|
|
14
|
-
return this.index2pubkey[index];
|
|
15
|
-
}
|
|
16
|
-
getOrThrow(index) {
|
|
17
|
-
const pubkey = this.get(index);
|
|
18
|
-
if (!pubkey)
|
|
19
|
-
throw Error(`Missing pubkey for validator index ${index}`);
|
|
20
|
-
return pubkey;
|
|
21
|
-
}
|
|
22
|
-
getIndex(pubkey) {
|
|
23
|
-
return this.pubkey2index.get(pubkey);
|
|
24
|
-
}
|
|
25
|
-
set(index, pubkey) {
|
|
26
|
-
this.pubkey2index.set(pubkey, index);
|
|
27
|
-
// Pubkeys must be checked for group + inf. This must be done only once when the validator deposit is processed.
|
|
28
|
-
// Afterwards any public key in the state is considered validated.
|
|
29
|
-
// > Do not do any validation here
|
|
30
|
-
this.index2pubkey[index] = PublicKey.fromBytes(pubkey); // Optimize for aggregation
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export function createPubkeyCache() {
|
|
34
|
-
return new StandardPubkeyCache();
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Checks the pubkey indices against a state and adds missing pubkeys
|
|
38
|
-
*
|
|
39
|
-
* Mutates `pubkeyCache`
|
|
40
|
-
*
|
|
41
|
-
* If pubkey cache is empty: SLOW CODE - 🐢
|
|
42
|
-
*/
|
|
43
|
-
export function syncPubkeys(pubkeyCache, validators) {
|
|
44
|
-
const newCount = validators.length;
|
|
45
|
-
for (let i = pubkeyCache.size; i < newCount; i++) {
|
|
46
|
-
pubkeyCache.set(i, validators[i].pubkey);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
//# sourceMappingURL=pubkeyCache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pubkeyCache.js","sourceRoot":"","sources":["../../src/cache/pubkeyCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAC,cAAc,EAAC,MAAM,6BAA6B,CAAC;AAoB3D,MAAM,mBAAmB;IACN,YAAY,CAAiB;IAC7B,YAAY,CAA4B;IAEzD,YAAY,YAA6B,EAAE,YAAwC;QACjF,IAAI,CAAC,YAAY,GAAG,YAAY,IAAI,IAAI,cAAc,EAAE,CAAC;QACzD,IAAI,CAAC,YAAY,GAAG,YAAY,IAAI,EAAE,CAAC;IACzC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;IAChC,CAAC;IAED,GAAG,CAAC,KAAqB;QACvB,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,UAAU,CAAC,KAAqB;QAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC/B,IAAI,CAAC,MAAM;YAAE,MAAM,KAAK,CAAC,sCAAsC,KAAK,EAAE,CAAC,CAAC;QACxE,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,QAAQ,CAAC,MAAkB;QACzB,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,GAAG,CAAC,KAAqB,EAAE,MAAkB;QAC3C,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACrC,gHAAgH;QAChH,kEAAkE;QAClE,kCAAkC;QAClC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,2BAA2B;IACrF,CAAC;CACF;AAED,MAAM,UAAU,iBAAiB;IAC/B,OAAO,IAAI,mBAAmB,EAAE,CAAC;AACnC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,WAAwB,EAAE,UAA8B;IAClF,MAAM,QAAQ,GAAG,UAAU,CAAC,MAAM,CAAC;IACnC,KAAK,IAAI,CAAC,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC;QACjD,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC"}
|
package/src/cache/pubkeyCache.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import {PublicKey} from "@chainsafe/blst";
|
|
2
|
-
import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
|
|
3
|
-
import {ValidatorIndex, phase0} from "@lodestar/types";
|
|
4
|
-
|
|
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
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Checks the pubkey indices against a state and adds missing pubkeys
|
|
64
|
-
*
|
|
65
|
-
* Mutates `pubkeyCache`
|
|
66
|
-
*
|
|
67
|
-
* If pubkey cache is empty: SLOW CODE - 🐢
|
|
68
|
-
*/
|
|
69
|
-
export function syncPubkeys(pubkeyCache: PubkeyCache, validators: phase0.Validator[]): void {
|
|
70
|
-
const newCount = validators.length;
|
|
71
|
-
for (let i = pubkeyCache.size; i < newCount; i++) {
|
|
72
|
-
pubkeyCache.set(i, validators[i].pubkey);
|
|
73
|
-
}
|
|
74
|
-
}
|