@lodestar/validator 1.49.0-dev.ae6cc426f1 → 1.49.0-dev.c535e94f25
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/services/validatorStore.d.ts +2 -2
- package/lib/services/validatorStore.d.ts.map +1 -1
- package/lib/services/validatorStore.js +12 -7
- package/lib/services/validatorStore.js.map +1 -1
- package/lib/slashingProtection/attestation/index.d.ts.map +1 -1
- package/lib/slashingProtection/attestation/index.js +19 -2
- package/lib/slashingProtection/attestation/index.js.map +1 -1
- package/lib/slashingProtection/block/errors.d.ts +8 -0
- package/lib/slashingProtection/block/errors.d.ts.map +1 -1
- package/lib/slashingProtection/block/errors.js +4 -0
- package/lib/slashingProtection/block/errors.js.map +1 -1
- package/lib/slashingProtection/block/index.d.ts +1 -0
- package/lib/slashingProtection/block/index.d.ts.map +1 -1
- package/lib/slashingProtection/block/index.js +48 -5
- package/lib/slashingProtection/block/index.js.map +1 -1
- package/lib/slashingProtection/index.d.ts +1 -1
- package/lib/slashingProtection/index.d.ts.map +1 -1
- package/lib/slashingProtection/index.js +18 -2
- package/lib/slashingProtection/index.js.map +1 -1
- package/lib/slashingProtection/interchange/errors.d.ts +11 -2
- package/lib/slashingProtection/interchange/errors.d.ts.map +1 -1
- package/lib/slashingProtection/interchange/errors.js +2 -0
- package/lib/slashingProtection/interchange/errors.js.map +1 -1
- package/lib/slashingProtection/interchange/formats/completeV4.js +4 -4
- package/lib/slashingProtection/interchange/formats/completeV4.js.map +1 -1
- package/lib/slashingProtection/interchange/formats/v5.js +4 -4
- package/lib/slashingProtection/interchange/formats/v5.js.map +1 -1
- package/lib/slashingProtection/interface.d.ts +5 -1
- package/lib/slashingProtection/interface.d.ts.map +1 -1
- package/lib/slashingProtection/utils.d.ts +5 -1
- package/lib/slashingProtection/utils.d.ts.map +1 -1
- package/lib/slashingProtection/utils.js +11 -0
- package/lib/slashingProtection/utils.js.map +1 -1
- package/lib/validator.d.ts.map +1 -1
- package/lib/validator.js +1 -1
- package/lib/validator.js.map +1 -1
- package/package.json +12 -12
- package/src/services/validatorStore.ts +15 -8
- package/src/slashingProtection/attestation/index.ts +19 -2
- package/src/slashingProtection/block/errors.ts +9 -0
- package/src/slashingProtection/block/index.ts +48 -6
- package/src/slashingProtection/index.ts +24 -1
- package/src/slashingProtection/interchange/errors.ts +6 -2
- package/src/slashingProtection/interchange/formats/completeV4.ts +4 -4
- package/src/slashingProtection/interchange/formats/v5.ts +4 -4
- package/src/slashingProtection/interface.ts +10 -1
- package/src/slashingProtection/utils.ts +12 -0
- package/src/validator.ts +6 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {fromHex, toPubkeyHex, toRootHex} from "@lodestar/utils";
|
|
2
|
-
import {fromOptionalHexString, numToString, toOptionalHexString} from "../../utils.js";
|
|
2
|
+
import {fromOptionalHexString, numToString, stringToNum, toOptionalHexString} from "../../utils.js";
|
|
3
3
|
import {InterchangeLodestar} from "../types.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -107,12 +107,12 @@ export function parseInterchangeV5(interchange: InterchangeV5): InterchangeLodes
|
|
|
107
107
|
data: interchange.data.map((validator) => ({
|
|
108
108
|
pubkey: fromHex(validator.pubkey),
|
|
109
109
|
signedBlocks: validator.signed_blocks.map((block) => ({
|
|
110
|
-
slot:
|
|
110
|
+
slot: stringToNum(block.slot),
|
|
111
111
|
signingRoot: fromOptionalHexString(block.signing_root),
|
|
112
112
|
})),
|
|
113
113
|
signedAttestations: validator.signed_attestations.map((att) => ({
|
|
114
|
-
sourceEpoch:
|
|
115
|
-
targetEpoch:
|
|
114
|
+
sourceEpoch: stringToNum(att.source_epoch),
|
|
115
|
+
targetEpoch: stringToNum(att.target_epoch),
|
|
116
116
|
signingRoot: fromOptionalHexString(att.signing_root),
|
|
117
117
|
})),
|
|
118
118
|
})),
|
|
@@ -18,7 +18,16 @@ export interface ISlashingProtection {
|
|
|
18
18
|
*/
|
|
19
19
|
hasAttestedInEpoch(pubKey: BLSPubkey, epoch: Epoch): Promise<boolean>;
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Import an EIP-3076 interchange, rejects attestations with a target epoch more than one epoch after `currentEpoch`
|
|
23
|
+
* (or genesis if earlier)
|
|
24
|
+
*/
|
|
25
|
+
importInterchange(
|
|
26
|
+
interchange: Interchange,
|
|
27
|
+
genesisValidatorsRoot: Uint8Array | Root,
|
|
28
|
+
logger?: Logger,
|
|
29
|
+
currentEpoch?: Epoch
|
|
30
|
+
): Promise<void>;
|
|
22
31
|
exportInterchange(
|
|
23
32
|
genesisValidatorsRoot: Uint8Array | Root,
|
|
24
33
|
pubkeys: BLSPubkey[],
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {Epoch, Root, ssz} from "@lodestar/types";
|
|
2
2
|
import {fromHex, toHex, toRootHex} from "@lodestar/utils";
|
|
3
|
+
import {InterchangeError, InterchangeErrorErrorCode} from "./interchange/errors.js";
|
|
3
4
|
|
|
4
5
|
export const blsPubkeyLen = 48;
|
|
5
6
|
export const ZERO_ROOT = ssz.Root.defaultValue();
|
|
@@ -27,6 +28,17 @@ export function numToString(num: number): string {
|
|
|
27
28
|
return String(num);
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Parse a decimal uint string, rejecting values the slashing protection DB range scans cannot see
|
|
33
|
+
*/
|
|
34
|
+
export function stringToNum(str: string): number {
|
|
35
|
+
const num = Number(str);
|
|
36
|
+
if (!/^[0-9]+$/.test(str) || num >= Number.MAX_SAFE_INTEGER) {
|
|
37
|
+
throw new InterchangeError({code: InterchangeErrorErrorCode.INVALID_VALUE, value: str});
|
|
38
|
+
}
|
|
39
|
+
return num;
|
|
40
|
+
}
|
|
41
|
+
|
|
30
42
|
export function minEpoch(epochs: Epoch[]): Epoch | null {
|
|
31
43
|
return epochs.length > 0 ? epochs.reduce((minEpoch, epoch) => (minEpoch < epoch ? minEpoch : epoch)) : null;
|
|
32
44
|
}
|
package/src/validator.ts
CHANGED
|
@@ -430,7 +430,12 @@ export class Validator {
|
|
|
430
430
|
}
|
|
431
431
|
|
|
432
432
|
async importInterchange(interchange: Interchange): Promise<void> {
|
|
433
|
-
return this.slashingProtection.importInterchange(
|
|
433
|
+
return this.slashingProtection.importInterchange(
|
|
434
|
+
interchange,
|
|
435
|
+
this.genesis.genesisValidatorsRoot,
|
|
436
|
+
undefined,
|
|
437
|
+
this.clock.currentEpoch
|
|
438
|
+
);
|
|
434
439
|
}
|
|
435
440
|
|
|
436
441
|
async exportInterchange(pubkeys: BLSPubkey[], formatVersion: InterchangeFormatVersion): Promise<Interchange> {
|