@lodestar/beacon-node 1.36.0-dev.9dbc67b579 → 1.36.0-dev.9f2bb12ea7
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/api/impl/beacon/blocks/index.d.ts.map +1 -1
- package/lib/api/impl/beacon/blocks/index.js +41 -22
- package/lib/api/impl/beacon/blocks/index.js.map +1 -1
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +5 -4
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/errors/dataColumnSidecarError.d.ts +17 -14
- package/lib/chain/errors/dataColumnSidecarError.d.ts.map +1 -1
- package/lib/chain/errors/dataColumnSidecarError.js +4 -0
- package/lib/chain/errors/dataColumnSidecarError.js.map +1 -1
- package/lib/chain/options.d.ts +0 -2
- package/lib/chain/options.d.ts.map +1 -1
- package/lib/chain/options.js +2 -2
- package/lib/chain/options.js.map +1 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +16 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.js +31 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.js +32 -15
- package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
- package/lib/network/core/networkCore.d.ts.map +1 -1
- package/lib/network/core/networkCore.js +5 -1
- package/lib/network/core/networkCore.js.map +1 -1
- package/lib/network/core/networkCoreWorker.js +6 -1
- package/lib/network/core/networkCoreWorker.js.map +1 -1
- package/lib/network/core/networkCoreWorkerHandler.js +1 -1
- package/lib/network/core/networkCoreWorkerHandler.js.map +1 -1
- package/lib/network/events.d.ts +1 -0
- package/lib/network/events.d.ts.map +1 -1
- package/lib/network/gossip/encoding.js +1 -1
- package/lib/network/gossip/encoding.js.map +1 -1
- package/lib/network/gossip/snappy_bun.d.ts +3 -0
- package/lib/network/gossip/snappy_bun.d.ts.map +1 -0
- package/lib/network/gossip/snappy_bun.js +3 -0
- package/lib/network/gossip/snappy_bun.js.map +1 -0
- package/lib/network/metadata.d.ts +1 -1
- package/lib/network/metadata.d.ts.map +1 -1
- package/lib/network/metadata.js +1 -0
- package/lib/network/metadata.js.map +1 -1
- package/lib/network/options.d.ts +0 -1
- package/lib/network/options.d.ts.map +1 -1
- package/lib/network/options.js.map +1 -1
- package/lib/network/processor/gossipHandlers.js +1 -1
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/network/reqresp/ReqRespBeaconNode.d.ts.map +1 -1
- package/lib/network/reqresp/ReqRespBeaconNode.js +3 -1
- package/lib/network/reqresp/ReqRespBeaconNode.js.map +1 -1
- package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts +2 -1
- package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/beaconBlocksByRange.js +11 -2
- package/lib/network/reqresp/handlers/beaconBlocksByRange.js.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts +2 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +9 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.d.ts +2 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js +9 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js.map +1 -1
- package/lib/network/reqresp/handlers/index.js +6 -6
- package/lib/network/reqresp/handlers/index.js.map +1 -1
- package/lib/network/reqresp/types.d.ts +1 -0
- package/lib/network/reqresp/types.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRange.d.ts +58 -13
- package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRange.js +201 -82
- package/lib/sync/utils/downloadByRange.js.map +1 -1
- package/lib/util/blobs.d.ts +1 -1
- package/lib/util/blobs.d.ts.map +1 -1
- package/lib/util/blobs.js +53 -20
- package/lib/util/blobs.js.map +1 -1
- package/package.json +19 -14
- package/src/api/impl/beacon/blocks/index.ts +47 -25
- package/src/chain/chain.ts +5 -5
- package/src/chain/errors/dataColumnSidecarError.ts +20 -14
- package/src/chain/options.ts +2 -3
- package/src/chain/stateCache/persistentCheckpointsCache.ts +45 -2
- package/src/chain/validation/dataColumnSidecar.ts +34 -16
- package/src/network/core/networkCore.ts +5 -1
- package/src/network/core/networkCoreWorker.ts +7 -2
- package/src/network/core/networkCoreWorkerHandler.ts +1 -1
- package/src/network/events.ts +1 -1
- package/src/network/gossip/encoding.ts +1 -1
- package/src/network/gossip/snappy_bun.ts +2 -0
- package/src/network/metadata.ts +3 -1
- package/src/network/options.ts +0 -1
- package/src/network/processor/gossipHandlers.ts +1 -1
- package/src/network/reqresp/ReqRespBeaconNode.ts +3 -1
- package/src/network/reqresp/handlers/beaconBlocksByRange.ts +15 -2
- package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +13 -1
- package/src/network/reqresp/handlers/dataColumnSidecarsByRoot.ts +13 -1
- package/src/network/reqresp/handlers/index.ts +6 -6
- package/src/network/reqresp/types.ts +1 -0
- package/src/sync/utils/downloadByRange.ts +259 -103
- package/src/util/blobs.ts +64 -20
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.36.0-dev.
|
|
14
|
+
"version": "1.36.0-dev.9f2bb12ea7",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
@@ -83,6 +83,10 @@
|
|
|
83
83
|
"#datastore-wrapper": {
|
|
84
84
|
"bun": "./src/network/peers/datastore_bun.ts",
|
|
85
85
|
"default": "datastore-level"
|
|
86
|
+
},
|
|
87
|
+
"#snappy": {
|
|
88
|
+
"bun": "./src/network/gossip/snappy_bun.ts",
|
|
89
|
+
"default": "snappyjs"
|
|
86
90
|
}
|
|
87
91
|
},
|
|
88
92
|
"files": [
|
|
@@ -140,18 +144,19 @@
|
|
|
140
144
|
"@libp2p/peer-id": "^5.1.0",
|
|
141
145
|
"@libp2p/prometheus-metrics": "^4.3.15",
|
|
142
146
|
"@libp2p/tcp": "^10.1.8",
|
|
143
|
-
"@lodestar/api": "1.36.0-dev.
|
|
144
|
-
"@lodestar/
|
|
145
|
-
"@lodestar/
|
|
146
|
-
"@lodestar/
|
|
147
|
-
"@lodestar/
|
|
148
|
-
"@lodestar/
|
|
149
|
-
"@lodestar/
|
|
150
|
-
"@lodestar/
|
|
151
|
-
"@lodestar/
|
|
152
|
-
"@lodestar/
|
|
153
|
-
"@lodestar/
|
|
154
|
-
"@lodestar/
|
|
147
|
+
"@lodestar/api": "1.36.0-dev.9f2bb12ea7",
|
|
148
|
+
"@lodestar/bun": "git+https://github.com/ChainSafe/lodestar-bun.git",
|
|
149
|
+
"@lodestar/config": "1.36.0-dev.9f2bb12ea7",
|
|
150
|
+
"@lodestar/db": "1.36.0-dev.9f2bb12ea7",
|
|
151
|
+
"@lodestar/fork-choice": "1.36.0-dev.9f2bb12ea7",
|
|
152
|
+
"@lodestar/light-client": "1.36.0-dev.9f2bb12ea7",
|
|
153
|
+
"@lodestar/logger": "1.36.0-dev.9f2bb12ea7",
|
|
154
|
+
"@lodestar/params": "1.36.0-dev.9f2bb12ea7",
|
|
155
|
+
"@lodestar/reqresp": "1.36.0-dev.9f2bb12ea7",
|
|
156
|
+
"@lodestar/state-transition": "1.36.0-dev.9f2bb12ea7",
|
|
157
|
+
"@lodestar/types": "1.36.0-dev.9f2bb12ea7",
|
|
158
|
+
"@lodestar/utils": "1.36.0-dev.9f2bb12ea7",
|
|
159
|
+
"@lodestar/validator": "1.36.0-dev.9f2bb12ea7",
|
|
155
160
|
"@multiformats/multiaddr": "^12.1.3",
|
|
156
161
|
"datastore-core": "^10.0.2",
|
|
157
162
|
"datastore-fs": "^10.0.6",
|
|
@@ -187,5 +192,5 @@
|
|
|
187
192
|
"beacon",
|
|
188
193
|
"blockchain"
|
|
189
194
|
],
|
|
190
|
-
"gitHead": "
|
|
195
|
+
"gitHead": "c7d8a024f794f71d2d91d371c68201273356a226"
|
|
191
196
|
}
|
|
@@ -654,18 +654,21 @@ export function getBeaconBlockApi({
|
|
|
654
654
|
);
|
|
655
655
|
}
|
|
656
656
|
|
|
657
|
-
const
|
|
657
|
+
for (const index of indices ?? []) {
|
|
658
|
+
if (index < 0 || index >= blobCount) {
|
|
659
|
+
throw new ApiError(400, `Invalid blob index ${index}, must be between 0 and ${blobCount - 1}`);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
const indicesToReconstruct = indices ?? Array.from({length: blobCount}, (_, i) => i);
|
|
664
|
+
const blobs = await reconstructBlobs(dataColumnSidecars, indicesToReconstruct);
|
|
658
665
|
const signedBlockHeader = signedBlockToSignedHeader(config, block);
|
|
659
|
-
const requestedIndices = indices ?? Array.from({length: blobKzgCommitments.length}, (_, i) => i);
|
|
660
666
|
|
|
661
667
|
data = await Promise.all(
|
|
662
|
-
|
|
668
|
+
indicesToReconstruct.map(async (index, i) => {
|
|
663
669
|
// Reconstruct blob sidecar from blob
|
|
664
670
|
const kzgCommitment = blobKzgCommitments[index];
|
|
665
|
-
|
|
666
|
-
throw new ApiError(400, `Blob index ${index} not found in block`);
|
|
667
|
-
}
|
|
668
|
-
const blob = blobs[index];
|
|
671
|
+
const blob = blobs[i]; // Use i since blobs only contains requested indices
|
|
669
672
|
const kzgProof = await kzg.asyncComputeBlobKzgProof(blob, kzgCommitment);
|
|
670
673
|
const kzgCommitmentInclusionProof = computePreFuluKzgCommitmentsInclusionProof(
|
|
671
674
|
fork,
|
|
@@ -724,7 +727,8 @@ export function getBeaconBlockApi({
|
|
|
724
727
|
);
|
|
725
728
|
}
|
|
726
729
|
|
|
727
|
-
const
|
|
730
|
+
const blobKzgCommitments = (block.message.body as deneb.BeaconBlockBody).blobKzgCommitments;
|
|
731
|
+
const blobCount = blobKzgCommitments.length;
|
|
728
732
|
|
|
729
733
|
if (blobCount > 0) {
|
|
730
734
|
let dataColumnSidecars = await fromAsync(db.dataColumnSidecar.valuesStream(blockRoot));
|
|
@@ -739,7 +743,25 @@ export function getBeaconBlockApi({
|
|
|
739
743
|
);
|
|
740
744
|
}
|
|
741
745
|
|
|
742
|
-
|
|
746
|
+
let indicesToReconstruct: number[];
|
|
747
|
+
if (versionedHashes) {
|
|
748
|
+
const blockVersionedHashes = blobKzgCommitments.map((commitment) =>
|
|
749
|
+
toHex(kzgCommitmentToVersionedHash(commitment))
|
|
750
|
+
);
|
|
751
|
+
indicesToReconstruct = [];
|
|
752
|
+
for (const requestedHash of versionedHashes) {
|
|
753
|
+
const index = blockVersionedHashes.findIndex((hash) => hash === requestedHash);
|
|
754
|
+
if (index === -1) {
|
|
755
|
+
throw new ApiError(400, `Versioned hash ${requestedHash} not found in block`);
|
|
756
|
+
}
|
|
757
|
+
indicesToReconstruct.push(index);
|
|
758
|
+
}
|
|
759
|
+
indicesToReconstruct.sort((a, b) => a - b);
|
|
760
|
+
} else {
|
|
761
|
+
indicesToReconstruct = Array.from({length: blobCount}, (_, i) => i);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
blobs = await reconstructBlobs(dataColumnSidecars, indicesToReconstruct);
|
|
743
765
|
} else {
|
|
744
766
|
blobs = [];
|
|
745
767
|
}
|
|
@@ -757,27 +779,27 @@ export function getBeaconBlockApi({
|
|
|
757
779
|
}
|
|
758
780
|
|
|
759
781
|
blobs = blobSidecars.sort((a, b) => a.index - b.index).map(({blob}) => blob);
|
|
760
|
-
} else {
|
|
761
|
-
blobs = [];
|
|
762
|
-
}
|
|
763
782
|
|
|
764
|
-
|
|
765
|
-
|
|
783
|
+
if (blobs.length && versionedHashes) {
|
|
784
|
+
const kzgCommitments = (block as deneb.SignedBeaconBlock).message.body.blobKzgCommitments;
|
|
766
785
|
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
786
|
+
const blockVersionedHashes = kzgCommitments.map((commitment) =>
|
|
787
|
+
toHex(kzgCommitmentToVersionedHash(commitment))
|
|
788
|
+
);
|
|
770
789
|
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
790
|
+
const requestedIndices: number[] = [];
|
|
791
|
+
for (const requestedHash of versionedHashes) {
|
|
792
|
+
const index = blockVersionedHashes.findIndex((hash) => hash === requestedHash);
|
|
793
|
+
if (index === -1) {
|
|
794
|
+
throw new ApiError(400, `Versioned hash ${requestedHash} not found in block`);
|
|
795
|
+
}
|
|
796
|
+
requestedIndices.push(index);
|
|
776
797
|
}
|
|
777
|
-
requestedIndices.push(index);
|
|
778
|
-
}
|
|
779
798
|
|
|
780
|
-
|
|
799
|
+
blobs = requestedIndices.sort((a, b) => a - b).map((index) => blobs[index]);
|
|
800
|
+
}
|
|
801
|
+
} else {
|
|
802
|
+
blobs = [];
|
|
781
803
|
}
|
|
782
804
|
|
|
783
805
|
return {
|
package/src/chain/chain.ts
CHANGED
|
@@ -271,8 +271,7 @@ export class BeaconChain implements IBeaconChain {
|
|
|
271
271
|
this.seenAttestationDatas = new SeenAttestationDatas(metrics, this.opts?.attDataCacheSlotDistance);
|
|
272
272
|
|
|
273
273
|
const nodeId = computeNodeIdFromPrivateKey(privateKey);
|
|
274
|
-
const initialCustodyGroupCount =
|
|
275
|
-
opts.initialCustodyGroupCount ?? (opts.supernode ? config.NUMBER_OF_CUSTODY_GROUPS : config.CUSTODY_REQUIREMENT);
|
|
274
|
+
const initialCustodyGroupCount = opts.initialCustodyGroupCount ?? config.CUSTODY_REQUIREMENT;
|
|
276
275
|
this.metrics?.peerDas.targetCustodyGroupCount.set(initialCustodyGroupCount);
|
|
277
276
|
this.custodyConfig = new CustodyConfig({
|
|
278
277
|
nodeId,
|
|
@@ -1241,9 +1240,10 @@ export class BeaconChain implements IBeaconChain {
|
|
|
1241
1240
|
}
|
|
1242
1241
|
|
|
1243
1242
|
private async updateValidatorsCustodyRequirement(finalizedCheckpoint: CheckpointWithHex): Promise<void> {
|
|
1244
|
-
if (this.
|
|
1245
|
-
//
|
|
1246
|
-
// of all custody groups
|
|
1243
|
+
if (this.custodyConfig.targetCustodyGroupCount === this.config.NUMBER_OF_CUSTODY_GROUPS) {
|
|
1244
|
+
// Custody requirements can only be increased, we can disable dynamic custody updates
|
|
1245
|
+
// if the node already maintains custody of all custody groups in case it is configured
|
|
1246
|
+
// as a supernode or has validators attached with a total effective balance of at least 4096 ETH.
|
|
1247
1247
|
return;
|
|
1248
1248
|
}
|
|
1249
1249
|
|
|
@@ -12,10 +12,14 @@ export enum DataColumnSidecarErrorCode {
|
|
|
12
12
|
|
|
13
13
|
// Validation errors when validating against an existing block
|
|
14
14
|
|
|
15
|
+
/** Block and sidecars header root mismatch */
|
|
16
|
+
INCORRECT_HEADER_ROOT = "DATA_COLUMN_SIDECAR_ERROR_INCORRECT_HEADER_ROOT",
|
|
15
17
|
/** Block and sidecars data column count mismatch */
|
|
16
18
|
INCORRECT_SIDECAR_COUNT = "DATA_COLUMN_SIDECAR_ERROR_INCORRECT_SIDECAR_COUNT",
|
|
17
19
|
/** Sidecar doesn't match block */
|
|
18
20
|
INCORRECT_BLOCK = "DATA_COLUMN_SIDECAR_ERROR_INCORRECT_BLOCK",
|
|
21
|
+
/** Sidecar cell count not as expected */
|
|
22
|
+
INCORRECT_CELL_COUNT = "DATA_COLUMN_SIDECAR_ERROR_INCORRECT_CELL_COUNT",
|
|
19
23
|
/** Sidecar kzg proof count not as expected */
|
|
20
24
|
INCORRECT_KZG_COMMITMENTS_COUNT = "DATA_COLUMN_SIDECAR_ERROR_INCORRECT_KZG_COMMITMENTS_COUNT",
|
|
21
25
|
/** Sidecar kzg proof count not as expected */
|
|
@@ -35,49 +39,51 @@ export enum DataColumnSidecarErrorCode {
|
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
export type DataColumnSidecarErrorType =
|
|
38
|
-
| {code: DataColumnSidecarErrorCode.INVALID_INDEX; slot: Slot;
|
|
39
|
-
| {code: DataColumnSidecarErrorCode.NO_COMMITMENTS; slot: Slot;
|
|
42
|
+
| {code: DataColumnSidecarErrorCode.INVALID_INDEX; slot: Slot; columnIndex: number}
|
|
43
|
+
| {code: DataColumnSidecarErrorCode.NO_COMMITMENTS; slot: Slot; columnIndex: number}
|
|
40
44
|
| {
|
|
41
45
|
code: DataColumnSidecarErrorCode.MISMATCHED_LENGTHS;
|
|
42
46
|
columnLength: number;
|
|
43
47
|
commitmentsLength: number;
|
|
44
48
|
proofsLength: number;
|
|
45
49
|
}
|
|
46
|
-
| {code: DataColumnSidecarErrorCode.INVALID_SUBNET;
|
|
50
|
+
| {code: DataColumnSidecarErrorCode.INVALID_SUBNET; columnIndex: number; gossipSubnet: SubnetID}
|
|
47
51
|
| {
|
|
48
52
|
code: DataColumnSidecarErrorCode.TOO_MANY_KZG_COMMITMENTS;
|
|
49
53
|
slot: number;
|
|
50
|
-
|
|
54
|
+
columnIndex: number;
|
|
51
55
|
count: number;
|
|
52
56
|
limit: number;
|
|
53
57
|
}
|
|
54
|
-
| {code: DataColumnSidecarErrorCode.ALREADY_KNOWN;
|
|
58
|
+
| {code: DataColumnSidecarErrorCode.ALREADY_KNOWN; columnIndex: number; slot: Slot}
|
|
55
59
|
| {code: DataColumnSidecarErrorCode.FUTURE_SLOT; blockSlot: Slot; currentSlot: Slot}
|
|
56
60
|
| {code: DataColumnSidecarErrorCode.WOULD_REVERT_FINALIZED_SLOT; blockSlot: Slot; finalizedSlot: Slot}
|
|
57
61
|
| {code: DataColumnSidecarErrorCode.PARENT_UNKNOWN; parentRoot: RootHex}
|
|
58
62
|
| {code: DataColumnSidecarErrorCode.PROPOSAL_SIGNATURE_INVALID}
|
|
59
63
|
| {code: DataColumnSidecarErrorCode.NOT_LATER_THAN_PARENT; parentSlot: Slot; slot: Slot}
|
|
60
|
-
| {code: DataColumnSidecarErrorCode.INCLUSION_PROOF_INVALID; slot: Slot;
|
|
61
|
-
| {code: DataColumnSidecarErrorCode.INVALID_KZG_PROOF; slot: Slot;
|
|
64
|
+
| {code: DataColumnSidecarErrorCode.INCLUSION_PROOF_INVALID; slot: Slot; columnIndex: number}
|
|
65
|
+
| {code: DataColumnSidecarErrorCode.INVALID_KZG_PROOF; slot: Slot; columnIndex: number}
|
|
62
66
|
| {code: DataColumnSidecarErrorCode.INCORRECT_SIDECAR_COUNT; slot: number; expected: number; actual: number}
|
|
63
67
|
| {
|
|
64
68
|
code: DataColumnSidecarErrorCode.INCORRECT_BLOCK;
|
|
65
69
|
slot: number;
|
|
66
|
-
|
|
70
|
+
columnIndex: number;
|
|
67
71
|
expected: string;
|
|
68
72
|
actual: string;
|
|
69
73
|
}
|
|
70
74
|
| {
|
|
71
|
-
code: DataColumnSidecarErrorCode.
|
|
75
|
+
code: DataColumnSidecarErrorCode.INCORRECT_HEADER_ROOT;
|
|
72
76
|
slot: number;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
actual: number;
|
|
77
|
+
expected: string;
|
|
78
|
+
actual: string;
|
|
76
79
|
}
|
|
77
80
|
| {
|
|
78
|
-
code:
|
|
81
|
+
code:
|
|
82
|
+
| DataColumnSidecarErrorCode.INCORRECT_CELL_COUNT
|
|
83
|
+
| DataColumnSidecarErrorCode.INCORRECT_KZG_COMMITMENTS_COUNT
|
|
84
|
+
| DataColumnSidecarErrorCode.INCORRECT_KZG_PROOF_COUNT;
|
|
79
85
|
slot: number;
|
|
80
|
-
|
|
86
|
+
columnIndex: number;
|
|
81
87
|
expected: number;
|
|
82
88
|
actual: number;
|
|
83
89
|
}
|
package/src/chain/options.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {ShufflingCacheOpts} from "./shufflingCache.js";
|
|
|
8
8
|
import {DEFAULT_MAX_BLOCK_STATES, FIFOBlockStateCacheOpts} from "./stateCache/fifoBlockStateCache.js";
|
|
9
9
|
import {
|
|
10
10
|
DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY,
|
|
11
|
+
DEFAULT_MAX_CP_STATE_ON_DISK,
|
|
11
12
|
PersistentCheckpointStateCacheOpts,
|
|
12
13
|
} from "./stateCache/persistentCheckpointsCache.js";
|
|
13
14
|
import {ValidatorMonitorOpts} from "./validatorMonitor.js";
|
|
@@ -41,8 +42,6 @@ export type IChainOptions = BlockProcessOpts &
|
|
|
41
42
|
maxCachedBlobSidecars?: number;
|
|
42
43
|
/** Max number of produced block roots (blinded or full) cached for broadcast validations */
|
|
43
44
|
maxCachedProducedRoots?: number;
|
|
44
|
-
/** Subscribe to and custody all data column sidecar subnets */
|
|
45
|
-
supernode?: boolean;
|
|
46
45
|
initialCustodyGroupCount?: number;
|
|
47
46
|
broadcastValidationStrictness?: string;
|
|
48
47
|
minSameMessageSignatureSetsToBatch: number;
|
|
@@ -118,7 +117,6 @@ export const defaultChainOptions: IChainOptions = {
|
|
|
118
117
|
archiveMode: DEFAULT_ARCHIVE_MODE,
|
|
119
118
|
pruneHistory: false,
|
|
120
119
|
emitPayloadAttributes: false,
|
|
121
|
-
supernode: false,
|
|
122
120
|
// for gossip block validation, it's unlikely we see a reorg with 32 slots
|
|
123
121
|
// for attestation validation, having this value ensures we don't have to regen states most of the time
|
|
124
122
|
maxSkipSlots: 32,
|
|
@@ -135,4 +133,5 @@ export const defaultChainOptions: IChainOptions = {
|
|
|
135
133
|
nHistoricalStatesFileDataStore: true,
|
|
136
134
|
maxBlockStates: DEFAULT_MAX_BLOCK_STATES,
|
|
137
135
|
maxCPStateEpochsInMemory: DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY,
|
|
136
|
+
maxCPStateEpochsOnDisk: DEFAULT_MAX_CP_STATE_ON_DISK,
|
|
138
137
|
};
|
|
@@ -17,8 +17,10 @@ import {MapTracker} from "./mapMetrics.js";
|
|
|
17
17
|
import {BlockStateCache, CacheItemType, CheckpointHex, CheckpointStateCache} from "./types.js";
|
|
18
18
|
|
|
19
19
|
export type PersistentCheckpointStateCacheOpts = {
|
|
20
|
-
/** Keep max n
|
|
20
|
+
/** Keep max n state epochs in memory, persist the rest to disk */
|
|
21
21
|
maxCPStateEpochsInMemory?: number;
|
|
22
|
+
/** Keep max n state epochs on disk */
|
|
23
|
+
maxCPStateEpochsOnDisk?: number;
|
|
22
24
|
};
|
|
23
25
|
|
|
24
26
|
type PersistentCheckpointStateCacheModules = {
|
|
@@ -58,6 +60,14 @@ type LoadedStateBytesData = {persistedKey: DatastoreKey; stateBytes: Uint8Array}
|
|
|
58
60
|
*/
|
|
59
61
|
export const DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY = 3;
|
|
60
62
|
|
|
63
|
+
/**
|
|
64
|
+
* By default we don't prune any persistent checkpoint states as it's not safe to delete them during
|
|
65
|
+
* long non-finality as we don't know the state of the chain and there could be a deep (hundreds of epochs) reorg
|
|
66
|
+
* if there two competing chains with similar weight but we wouldn't have a close enough state to pivot to this chain
|
|
67
|
+
* and instead require a resync from last finalized checkpoint state which could be very far in the past.
|
|
68
|
+
*/
|
|
69
|
+
export const DEFAULT_MAX_CP_STATE_ON_DISK = Infinity;
|
|
70
|
+
|
|
61
71
|
// TODO GLOAS: re-evaluate this timing
|
|
62
72
|
const PROCESS_CHECKPOINT_STATES_BPS = 6667;
|
|
63
73
|
|
|
@@ -104,6 +114,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
|
|
|
104
114
|
private preComputedCheckpoint: string | null = null;
|
|
105
115
|
private preComputedCheckpointHits: number | null = null;
|
|
106
116
|
private readonly maxEpochsInMemory: number;
|
|
117
|
+
private readonly maxEpochsOnDisk: number;
|
|
107
118
|
private readonly datastore: CPStateDatastore;
|
|
108
119
|
private readonly blockStateCache: BlockStateCache;
|
|
109
120
|
private readonly bufferPool?: BufferPool | null;
|
|
@@ -139,10 +150,16 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
|
|
|
139
150
|
this.logger = logger;
|
|
140
151
|
this.clock = clock;
|
|
141
152
|
this.signal = signal;
|
|
153
|
+
|
|
142
154
|
if (opts.maxCPStateEpochsInMemory !== undefined && opts.maxCPStateEpochsInMemory < 0) {
|
|
143
155
|
throw new Error("maxEpochsInMemory must be >= 0");
|
|
144
156
|
}
|
|
157
|
+
if (opts.maxCPStateEpochsOnDisk !== undefined && opts.maxCPStateEpochsOnDisk < 0) {
|
|
158
|
+
throw new Error("maxCPStateEpochsOnDisk must be >= 0");
|
|
159
|
+
}
|
|
160
|
+
|
|
145
161
|
this.maxEpochsInMemory = opts.maxCPStateEpochsInMemory ?? DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY;
|
|
162
|
+
this.maxEpochsOnDisk = opts.maxCPStateEpochsOnDisk ?? DEFAULT_MAX_CP_STATE_ON_DISK;
|
|
146
163
|
// Specify different datastore for testing
|
|
147
164
|
this.datastore = datastore;
|
|
148
165
|
this.blockStateCache = blockStateCache;
|
|
@@ -324,6 +341,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
|
|
|
324
341
|
this.logger.verbose("Added checkpoint state to memory", {epoch: cp.epoch, rootHex: cpHex.rootHex});
|
|
325
342
|
}
|
|
326
343
|
this.epochIndex.getOrDefault(cp.epoch).add(cpHex.rootHex);
|
|
344
|
+
this.prunePersistedStates();
|
|
327
345
|
}
|
|
328
346
|
|
|
329
347
|
/**
|
|
@@ -766,13 +784,38 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
|
|
|
766
784
|
this.cache.delete(key);
|
|
767
785
|
}
|
|
768
786
|
this.epochIndex.delete(epoch);
|
|
769
|
-
this.logger.verbose("Pruned
|
|
787
|
+
this.logger.verbose("Pruned checkpoint states for epoch", {
|
|
770
788
|
epoch,
|
|
771
789
|
persistCount,
|
|
772
790
|
rootHexes: Array.from(rootHexes).join(","),
|
|
773
791
|
});
|
|
774
792
|
}
|
|
775
793
|
|
|
794
|
+
/**
|
|
795
|
+
* Prune persisted checkpoint states from disk.
|
|
796
|
+
* Note that this should handle all possible errors and not throw.
|
|
797
|
+
*/
|
|
798
|
+
private prunePersistedStates(): void {
|
|
799
|
+
// epochsOnDisk epochsInMemory
|
|
800
|
+
// |----------------------------------------------------------|----------------------|
|
|
801
|
+
const maxTrackedEpochs = this.maxEpochsOnDisk + this.maxEpochsInMemory;
|
|
802
|
+
if (this.epochIndex.size <= maxTrackedEpochs) {
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
const sortedEpochs = Array.from(this.epochIndex.keys()).sort((a, b) => a - b);
|
|
807
|
+
const pruneEpochs = sortedEpochs.slice(0, sortedEpochs.length - maxTrackedEpochs);
|
|
808
|
+
for (const epoch of pruneEpochs) {
|
|
809
|
+
this.deleteAllEpochItems(epoch).catch((e) =>
|
|
810
|
+
this.logger.debug(
|
|
811
|
+
"Error delete all epoch items",
|
|
812
|
+
{epoch, maxEpochsOnDisk: this.maxEpochsOnDisk, maxEpochsInMemory: this.maxEpochsInMemory},
|
|
813
|
+
e as Error
|
|
814
|
+
)
|
|
815
|
+
);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
|
|
776
819
|
/**
|
|
777
820
|
* Serialize validators to bytes leveraging the buffer pool to save memory allocation.
|
|
778
821
|
* - As monitored on holesky as of Jan 2024, it helps save ~500ms state reload time (4.3s vs 3.8s)
|
|
@@ -39,7 +39,7 @@ export async function validateGossipDataColumnSidecar(
|
|
|
39
39
|
if (computeSubnetForDataColumnSidecar(chain.config, dataColumnSidecar) !== gossipSubnet) {
|
|
40
40
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
41
41
|
code: DataColumnSidecarErrorCode.INVALID_SUBNET,
|
|
42
|
-
|
|
42
|
+
columnIndex: dataColumnSidecar.index,
|
|
43
43
|
gossipSubnet: gossipSubnet,
|
|
44
44
|
});
|
|
45
45
|
}
|
|
@@ -156,7 +156,7 @@ export async function validateGossipDataColumnSidecar(
|
|
|
156
156
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
157
157
|
code: DataColumnSidecarErrorCode.INCLUSION_PROOF_INVALID,
|
|
158
158
|
slot: dataColumnSidecar.signedBlockHeader.message.slot,
|
|
159
|
-
|
|
159
|
+
columnIndex: dataColumnSidecar.index,
|
|
160
160
|
});
|
|
161
161
|
}
|
|
162
162
|
|
|
@@ -173,7 +173,7 @@ export async function validateGossipDataColumnSidecar(
|
|
|
173
173
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
174
174
|
code: DataColumnSidecarErrorCode.INVALID_KZG_PROOF,
|
|
175
175
|
slot: blockHeader.slot,
|
|
176
|
-
|
|
176
|
+
columnIndex: dataColumnSidecar.index,
|
|
177
177
|
});
|
|
178
178
|
} finally {
|
|
179
179
|
kzgProofTimer?.();
|
|
@@ -193,7 +193,7 @@ function verifyDataColumnSidecar(config: ChainForkConfig, dataColumnSidecar: ful
|
|
|
193
193
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
194
194
|
code: DataColumnSidecarErrorCode.INVALID_INDEX,
|
|
195
195
|
slot: dataColumnSidecar.signedBlockHeader.message.slot,
|
|
196
|
-
|
|
196
|
+
columnIndex: dataColumnSidecar.index,
|
|
197
197
|
});
|
|
198
198
|
}
|
|
199
199
|
|
|
@@ -201,7 +201,7 @@ function verifyDataColumnSidecar(config: ChainForkConfig, dataColumnSidecar: ful
|
|
|
201
201
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
202
202
|
code: DataColumnSidecarErrorCode.NO_COMMITMENTS,
|
|
203
203
|
slot: dataColumnSidecar.signedBlockHeader.message.slot,
|
|
204
|
-
|
|
204
|
+
columnIndex: dataColumnSidecar.index,
|
|
205
205
|
});
|
|
206
206
|
}
|
|
207
207
|
|
|
@@ -212,7 +212,7 @@ function verifyDataColumnSidecar(config: ChainForkConfig, dataColumnSidecar: ful
|
|
|
212
212
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
213
213
|
code: DataColumnSidecarErrorCode.TOO_MANY_KZG_COMMITMENTS,
|
|
214
214
|
slot: dataColumnSidecar.signedBlockHeader.message.slot,
|
|
215
|
-
|
|
215
|
+
columnIndex: dataColumnSidecar.index,
|
|
216
216
|
count: dataColumnSidecar.kzgCommitments.length,
|
|
217
217
|
limit: maxBlobsPerBlock,
|
|
218
218
|
});
|
|
@@ -293,7 +293,6 @@ export async function validateBlockDataColumnSidecars(
|
|
|
293
293
|
"Block has no blob commitments but data column sidecars were provided"
|
|
294
294
|
);
|
|
295
295
|
}
|
|
296
|
-
|
|
297
296
|
// Hash the first sidecar block header and compare the rest via (cheaper) equality
|
|
298
297
|
const firstSidecarBlockHeader = dataColumnSidecars[0].signedBlockHeader.message;
|
|
299
298
|
const firstBlockRoot = ssz.phase0.BeaconBlockHeader.hashTreeRoot(firstSidecarBlockHeader);
|
|
@@ -302,7 +301,7 @@ export async function validateBlockDataColumnSidecars(
|
|
|
302
301
|
{
|
|
303
302
|
code: DataColumnSidecarErrorCode.INCORRECT_BLOCK,
|
|
304
303
|
slot: blockSlot,
|
|
305
|
-
|
|
304
|
+
columnIndex: 0,
|
|
306
305
|
expected: toRootHex(blockRoot),
|
|
307
306
|
actual: toRootHex(firstBlockRoot),
|
|
308
307
|
},
|
|
@@ -317,33 +316,52 @@ export async function validateBlockDataColumnSidecars(
|
|
|
317
316
|
for (let i = 0; i < dataColumnSidecars.length; i++) {
|
|
318
317
|
const columnSidecar = dataColumnSidecars[i];
|
|
319
318
|
|
|
319
|
+
if (!ssz.phase0.BeaconBlockHeader.equals(firstSidecarBlockHeader, columnSidecar.signedBlockHeader.message)) {
|
|
320
|
+
throw new DataColumnSidecarValidationError({
|
|
321
|
+
code: DataColumnSidecarErrorCode.INCORRECT_HEADER_ROOT,
|
|
322
|
+
slot: blockSlot,
|
|
323
|
+
expected: toRootHex(blockRoot),
|
|
324
|
+
actual: toRootHex(ssz.phase0.BeaconBlockHeader.hashTreeRoot(columnSidecar.signedBlockHeader.message)),
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
320
328
|
if (columnSidecar.index >= NUMBER_OF_COLUMNS) {
|
|
321
329
|
throw new DataColumnSidecarValidationError(
|
|
322
330
|
{
|
|
323
331
|
code: DataColumnSidecarErrorCode.INVALID_INDEX,
|
|
324
332
|
slot: blockSlot,
|
|
325
|
-
|
|
333
|
+
columnIndex: columnSidecar.index,
|
|
326
334
|
},
|
|
327
335
|
"DataColumnSidecar has invalid index"
|
|
328
336
|
);
|
|
329
337
|
}
|
|
330
338
|
|
|
331
|
-
if (columnSidecar.
|
|
339
|
+
if (columnSidecar.column.length !== blockBlobCount) {
|
|
332
340
|
throw new DataColumnSidecarValidationError({
|
|
333
|
-
code: DataColumnSidecarErrorCode.
|
|
341
|
+
code: DataColumnSidecarErrorCode.INCORRECT_CELL_COUNT,
|
|
334
342
|
slot: blockSlot,
|
|
335
|
-
|
|
343
|
+
columnIndex: columnSidecar.index,
|
|
336
344
|
expected: blockBlobCount,
|
|
345
|
+
actual: columnSidecar.column.length,
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (columnSidecar.column.length !== columnSidecar.kzgCommitments.length) {
|
|
350
|
+
throw new DataColumnSidecarValidationError({
|
|
351
|
+
code: DataColumnSidecarErrorCode.INCORRECT_KZG_COMMITMENTS_COUNT,
|
|
352
|
+
slot: blockSlot,
|
|
353
|
+
columnIndex: columnSidecar.index,
|
|
354
|
+
expected: columnSidecar.column.length,
|
|
337
355
|
actual: columnSidecar.kzgCommitments.length,
|
|
338
356
|
});
|
|
339
357
|
}
|
|
340
358
|
|
|
341
|
-
if (columnSidecar.
|
|
359
|
+
if (columnSidecar.column.length !== columnSidecar.kzgProofs.length) {
|
|
342
360
|
throw new DataColumnSidecarValidationError({
|
|
343
361
|
code: DataColumnSidecarErrorCode.INCORRECT_KZG_PROOF_COUNT,
|
|
344
362
|
slot: blockSlot,
|
|
345
|
-
|
|
346
|
-
expected: columnSidecar.
|
|
363
|
+
columnIndex: columnSidecar.index,
|
|
364
|
+
expected: columnSidecar.column.length,
|
|
347
365
|
actual: columnSidecar.kzgProofs.length,
|
|
348
366
|
});
|
|
349
367
|
}
|
|
@@ -353,7 +371,7 @@ export async function validateBlockDataColumnSidecars(
|
|
|
353
371
|
{
|
|
354
372
|
code: DataColumnSidecarErrorCode.INCLUSION_PROOF_INVALID,
|
|
355
373
|
slot: blockSlot,
|
|
356
|
-
|
|
374
|
+
columnIndex: columnSidecar.index,
|
|
357
375
|
},
|
|
358
376
|
"DataColumnSidecar has invalid inclusion proof"
|
|
359
377
|
);
|
|
@@ -553,7 +553,11 @@ export class NetworkCore implements INetworkCore {
|
|
|
553
553
|
// On fork boundary transition
|
|
554
554
|
if (epoch === nextBoundaryEpoch) {
|
|
555
555
|
// updateEth2Field() MUST be called with clock epoch, onEpoch event is emitted in response to clock events
|
|
556
|
-
this.metadata.updateEth2Field(epoch);
|
|
556
|
+
const {forkDigest} = this.metadata.updateEth2Field(epoch);
|
|
557
|
+
// Update local status to reflect the new fork digest, otherwise we will disconnect peers that re-status us
|
|
558
|
+
// right after the fork transition due to incompatible forks as our fork digest is stale since we only
|
|
559
|
+
// update it once we import a new head or when emitting update status event.
|
|
560
|
+
this.statusCache.update({...this.statusCache.get(), forkDigest});
|
|
557
561
|
this.reqResp.registerProtocolsAtBoundary(nextBoundary);
|
|
558
562
|
}
|
|
559
563
|
|
|
@@ -98,8 +98,13 @@ const core = await NetworkCore.init({
|
|
|
98
98
|
metricsRegistry: metricsRegister,
|
|
99
99
|
events,
|
|
100
100
|
clock,
|
|
101
|
-
getReqRespHandler: (method) => (req, peerId) =>
|
|
102
|
-
reqRespBridgeRespCaller.getAsyncIterable({
|
|
101
|
+
getReqRespHandler: (method) => (req, peerId, peerClient) =>
|
|
102
|
+
reqRespBridgeRespCaller.getAsyncIterable({
|
|
103
|
+
method,
|
|
104
|
+
req,
|
|
105
|
+
peerId: peerIdToString(peerId),
|
|
106
|
+
peerClient,
|
|
107
|
+
}),
|
|
103
108
|
activeValidatorCount: workerData.activeValidatorCount,
|
|
104
109
|
initialStatus: workerData.initialStatus,
|
|
105
110
|
initialCustodyGroupCount: workerData.initialCustodyGroupCount,
|
|
@@ -73,7 +73,7 @@ export class WorkerNetworkCore implements INetworkCore {
|
|
|
73
73
|
// Handles ReqResp response from worker and calls async generator in main thread
|
|
74
74
|
this.reqRespBridgeRespHandler = new AsyncIterableBridgeHandler(
|
|
75
75
|
getReqRespBridgeRespEvents(this.reqRespBridgeEventBus),
|
|
76
|
-
(data) => modules.getReqRespHandler(data.method)(data.req, peerIdFromString(data.peerId))
|
|
76
|
+
(data) => modules.getReqRespHandler(data.method)(data.req, peerIdFromString(data.peerId), data.peerClient)
|
|
77
77
|
);
|
|
78
78
|
|
|
79
79
|
wireEventsOnMainThread<NetworkEventData>(
|
package/src/network/events.ts
CHANGED
|
@@ -29,7 +29,7 @@ export type NetworkEventData = {
|
|
|
29
29
|
clientAgent: string;
|
|
30
30
|
};
|
|
31
31
|
[NetworkEvent.peerDisconnected]: {peer: PeerIdStr};
|
|
32
|
-
[NetworkEvent.reqRespRequest]: {request: RequestTypedContainer; peer: PeerId};
|
|
32
|
+
[NetworkEvent.reqRespRequest]: {request: RequestTypedContainer; peer: PeerId; peerClient: string};
|
|
33
33
|
[NetworkEvent.pendingGossipsubMessage]: PendingGossipsubMessage;
|
|
34
34
|
[NetworkEvent.gossipMessageValidationResult]: {
|
|
35
35
|
msgId: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Message} from "@libp2p/interface";
|
|
2
|
-
import {compress, uncompress} from "snappyjs";
|
|
3
2
|
import xxhashFactory from "xxhash-wasm";
|
|
3
|
+
import {compress, uncompress} from "#snappy";
|
|
4
4
|
import {digest} from "@chainsafe/as-sha256";
|
|
5
5
|
import {RPC} from "@chainsafe/libp2p-gossipsub/message";
|
|
6
6
|
import {DataTransform} from "@chainsafe/libp2p-gossipsub/types";
|
package/src/network/metadata.ts
CHANGED
|
@@ -126,7 +126,7 @@ export class MetadataController {
|
|
|
126
126
|
* 2. Network MUST call this method on fork transition.
|
|
127
127
|
* Current Clock implementation ensures no race conditions, epoch is correct if re-fetched
|
|
128
128
|
*/
|
|
129
|
-
updateEth2Field(epoch: Epoch):
|
|
129
|
+
updateEth2Field(epoch: Epoch): phase0.ENRForkID {
|
|
130
130
|
const config = this.networkConfig.config;
|
|
131
131
|
const enrForkId = getENRForkID(config, epoch);
|
|
132
132
|
const {forkDigest, nextForkVersion, nextForkEpoch} = enrForkId;
|
|
@@ -143,6 +143,8 @@ export class MetadataController {
|
|
|
143
143
|
: ssz.ForkDigest.defaultValue();
|
|
144
144
|
this.onSetValue(ENRKey.nfd, nextForkDigest);
|
|
145
145
|
this.logger.debug("Updated nfd field in ENR", {nextForkDigest: toHex(nextForkDigest)});
|
|
146
|
+
|
|
147
|
+
return enrForkId;
|
|
146
148
|
}
|
|
147
149
|
}
|
|
148
150
|
|
package/src/network/options.ts
CHANGED
|
@@ -307,7 +307,7 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
|
|
|
307
307
|
});
|
|
308
308
|
throw new DataColumnSidecarGossipError(GossipAction.IGNORE, {
|
|
309
309
|
code: DataColumnSidecarErrorCode.ALREADY_KNOWN,
|
|
310
|
-
|
|
310
|
+
columnIndex: dataColumnSidecar.index,
|
|
311
311
|
slot,
|
|
312
312
|
});
|
|
313
313
|
}
|