@lodestar/beacon-node 1.36.0-rc.1 → 1.36.0-rc.3
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/chain/errors/blobSidecarError.d.ts +5 -0
- package/lib/chain/errors/blobSidecarError.d.ts.map +1 -1
- package/lib/chain/errors/blobSidecarError.js.map +1 -1
- package/lib/chain/errors/dataColumnSidecarError.d.ts +4 -0
- package/lib/chain/errors/dataColumnSidecarError.d.ts.map +1 -1
- package/lib/chain/errors/dataColumnSidecarError.js.map +1 -1
- package/lib/chain/options.d.ts.map +1 -1
- package/lib/chain/options.js +2 -1
- 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/blobSidecar.d.ts +4 -1
- package/lib/chain/validation/blobSidecar.d.ts.map +1 -1
- package/lib/chain/validation/blobSidecar.js +46 -11
- package/lib/chain/validation/blobSidecar.js.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.d.ts +4 -1
- package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.js +33 -5
- package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
- package/lib/network/gossip/gossipsub.d.ts.map +1 -1
- package/lib/network/gossip/gossipsub.js +6 -1
- package/lib/network/gossip/gossipsub.js.map +1 -1
- package/lib/network/gossip/interface.d.ts +2 -0
- package/lib/network/gossip/interface.d.ts.map +1 -1
- package/lib/network/peers/discover.js +2 -2
- package/lib/network/peers/discover.js.map +1 -1
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +14 -0
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/network/processor/gossipValidatorFn.d.ts.map +1 -1
- package/lib/network/processor/gossipValidatorFn.js +3 -2
- package/lib/network/processor/gossipValidatorFn.js.map +1 -1
- package/lib/network/processor/types.d.ts +2 -0
- package/lib/network/processor/types.d.ts.map +1 -1
- package/lib/sync/unknownBlock.js +1 -1
- package/lib/sync/unknownBlock.js.map +1 -1
- package/lib/sync/utils/downloadByRange.d.ts +1 -2
- package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRange.js +4 -2
- package/lib/sync/utils/downloadByRange.js.map +1 -1
- package/lib/sync/utils/downloadByRoot.d.ts +8 -14
- package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRoot.js +18 -33
- package/lib/sync/utils/downloadByRoot.js.map +1 -1
- package/package.json +15 -15
- package/src/chain/errors/blobSidecarError.ts +12 -2
- package/src/chain/errors/dataColumnSidecarError.ts +11 -2
- package/src/chain/options.ts +2 -0
- package/src/chain/stateCache/persistentCheckpointsCache.ts +45 -2
- package/src/chain/validation/blobSidecar.ts +54 -10
- package/src/chain/validation/dataColumnSidecar.ts +43 -4
- package/src/network/gossip/gossipsub.ts +7 -1
- package/src/network/gossip/interface.ts +2 -0
- package/src/network/peers/discover.ts +2 -2
- package/src/network/processor/gossipHandlers.ts +15 -0
- package/src/network/processor/gossipValidatorFn.ts +15 -2
- package/src/network/processor/types.ts +2 -0
- package/src/sync/unknownBlock.ts +1 -1
- package/src/sync/utils/downloadByRange.ts +15 -6
- package/src/sync/utils/downloadByRoot.ts +22 -56
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-rc.
|
|
14
|
+
"version": "1.36.0-rc.3",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
"@chainsafe/pubkey-index-map": "^3.0.0",
|
|
130
130
|
"@chainsafe/ssz": "^1.2.2",
|
|
131
131
|
"@chainsafe/threads": "^1.11.3",
|
|
132
|
-
"@crate-crypto/node-eth-kzg": "0.
|
|
132
|
+
"@crate-crypto/node-eth-kzg": "0.9.1",
|
|
133
133
|
"@ethersproject/abi": "^5.7.0",
|
|
134
134
|
"@fastify/bearer-auth": "^10.0.1",
|
|
135
135
|
"@fastify/cors": "^10.0.1",
|
|
@@ -144,19 +144,19 @@
|
|
|
144
144
|
"@libp2p/peer-id": "^5.1.0",
|
|
145
145
|
"@libp2p/prometheus-metrics": "^4.3.15",
|
|
146
146
|
"@libp2p/tcp": "^10.1.8",
|
|
147
|
-
"@lodestar/api": "1.36.0-rc.
|
|
147
|
+
"@lodestar/api": "1.36.0-rc.3",
|
|
148
148
|
"@lodestar/bun": "git+https://github.com/ChainSafe/lodestar-bun.git",
|
|
149
|
-
"@lodestar/config": "1.36.0-rc.
|
|
150
|
-
"@lodestar/db": "1.36.0-rc.
|
|
151
|
-
"@lodestar/fork-choice": "1.36.0-rc.
|
|
152
|
-
"@lodestar/light-client": "1.36.0-rc.
|
|
153
|
-
"@lodestar/logger": "1.36.0-rc.
|
|
154
|
-
"@lodestar/params": "1.36.0-rc.
|
|
155
|
-
"@lodestar/reqresp": "1.36.0-rc.
|
|
156
|
-
"@lodestar/state-transition": "1.36.0-rc.
|
|
157
|
-
"@lodestar/types": "1.36.0-rc.
|
|
158
|
-
"@lodestar/utils": "1.36.0-rc.
|
|
159
|
-
"@lodestar/validator": "1.36.0-rc.
|
|
149
|
+
"@lodestar/config": "1.36.0-rc.3",
|
|
150
|
+
"@lodestar/db": "1.36.0-rc.3",
|
|
151
|
+
"@lodestar/fork-choice": "1.36.0-rc.3",
|
|
152
|
+
"@lodestar/light-client": "1.36.0-rc.3",
|
|
153
|
+
"@lodestar/logger": "1.36.0-rc.3",
|
|
154
|
+
"@lodestar/params": "1.36.0-rc.3",
|
|
155
|
+
"@lodestar/reqresp": "1.36.0-rc.3",
|
|
156
|
+
"@lodestar/state-transition": "1.36.0-rc.3",
|
|
157
|
+
"@lodestar/types": "1.36.0-rc.3",
|
|
158
|
+
"@lodestar/utils": "1.36.0-rc.3",
|
|
159
|
+
"@lodestar/validator": "1.36.0-rc.3",
|
|
160
160
|
"@multiformats/multiaddr": "^12.1.3",
|
|
161
161
|
"datastore-core": "^10.0.2",
|
|
162
162
|
"datastore-fs": "^10.0.6",
|
|
@@ -192,5 +192,5 @@
|
|
|
192
192
|
"beacon",
|
|
193
193
|
"blockchain"
|
|
194
194
|
],
|
|
195
|
-
"gitHead": "
|
|
195
|
+
"gitHead": "130f166c819fc72cd3e71d4562049c7f887e49bc"
|
|
196
196
|
}
|
|
@@ -50,9 +50,19 @@ export type BlobSidecarErrorType =
|
|
|
50
50
|
| {code: BlobSidecarErrorCode.FUTURE_SLOT; blockSlot: Slot; currentSlot: Slot}
|
|
51
51
|
| {code: BlobSidecarErrorCode.WOULD_REVERT_FINALIZED_SLOT; blockSlot: Slot; finalizedSlot: Slot}
|
|
52
52
|
| {code: BlobSidecarErrorCode.ALREADY_KNOWN; root: RootHex}
|
|
53
|
-
| {
|
|
53
|
+
| {
|
|
54
|
+
code: BlobSidecarErrorCode.PARENT_UNKNOWN;
|
|
55
|
+
parentRoot: RootHex;
|
|
56
|
+
slot: Slot;
|
|
57
|
+
blockRoot: RootHex;
|
|
58
|
+
}
|
|
54
59
|
| {code: BlobSidecarErrorCode.NOT_LATER_THAN_PARENT; parentSlot: Slot; slot: Slot}
|
|
55
|
-
| {
|
|
60
|
+
| {
|
|
61
|
+
code: BlobSidecarErrorCode.PROPOSAL_SIGNATURE_INVALID;
|
|
62
|
+
blockRoot: RootHex;
|
|
63
|
+
slot: Slot;
|
|
64
|
+
index: number;
|
|
65
|
+
}
|
|
56
66
|
| {code: BlobSidecarErrorCode.INCLUSION_PROOF_INVALID; slot: Slot; blobIdx: number}
|
|
57
67
|
| {code: BlobSidecarErrorCode.INCORRECT_PROPOSER; proposerIndex: ValidatorIndex};
|
|
58
68
|
|
|
@@ -58,8 +58,17 @@ export type DataColumnSidecarErrorType =
|
|
|
58
58
|
| {code: DataColumnSidecarErrorCode.ALREADY_KNOWN; columnIndex: number; slot: Slot}
|
|
59
59
|
| {code: DataColumnSidecarErrorCode.FUTURE_SLOT; blockSlot: Slot; currentSlot: Slot}
|
|
60
60
|
| {code: DataColumnSidecarErrorCode.WOULD_REVERT_FINALIZED_SLOT; blockSlot: Slot; finalizedSlot: Slot}
|
|
61
|
-
| {
|
|
62
|
-
|
|
61
|
+
| {
|
|
62
|
+
code: DataColumnSidecarErrorCode.PARENT_UNKNOWN;
|
|
63
|
+
parentRoot: RootHex;
|
|
64
|
+
slot: Slot;
|
|
65
|
+
}
|
|
66
|
+
| {
|
|
67
|
+
code: DataColumnSidecarErrorCode.PROPOSAL_SIGNATURE_INVALID;
|
|
68
|
+
slot: Slot;
|
|
69
|
+
blockRoot: RootHex;
|
|
70
|
+
index: number;
|
|
71
|
+
}
|
|
63
72
|
| {code: DataColumnSidecarErrorCode.NOT_LATER_THAN_PARENT; parentSlot: Slot; slot: Slot}
|
|
64
73
|
| {code: DataColumnSidecarErrorCode.INCLUSION_PROOF_INVALID; slot: Slot; columnIndex: number}
|
|
65
74
|
| {code: DataColumnSidecarErrorCode.INVALID_KZG_PROOF; slot: Slot; columnIndex: number}
|
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";
|
|
@@ -132,4 +133,5 @@ export const defaultChainOptions: IChainOptions = {
|
|
|
132
133
|
nHistoricalStatesFileDataStore: true,
|
|
133
134
|
maxBlockStates: DEFAULT_MAX_BLOCK_STATES,
|
|
134
135
|
maxCPStateEpochsInMemory: DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY,
|
|
136
|
+
maxCPStateEpochsOnDisk: DEFAULT_MAX_CP_STATE_ON_DISK,
|
|
135
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)
|
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
import {
|
|
9
9
|
computeEpochAtSlot,
|
|
10
10
|
computeStartSlotAtEpoch,
|
|
11
|
-
|
|
11
|
+
getBlockHeaderProposerSignatureSetByHeaderSlot,
|
|
12
|
+
getBlockHeaderProposerSignatureSetByParentStateSlot,
|
|
12
13
|
} from "@lodestar/state-transition";
|
|
13
14
|
import {BlobIndex, Root, Slot, SubnetID, deneb, ssz} from "@lodestar/types";
|
|
14
15
|
import {toRootHex, verifyMerkleBranch} from "@lodestar/utils";
|
|
@@ -100,7 +101,12 @@ export async function validateGossipBlobSidecar(
|
|
|
100
101
|
// descend from the finalized root.
|
|
101
102
|
// (Non-Lighthouse): Since we prune all blocks non-descendant from finalized checking the `db.block` database won't be useful to guard
|
|
102
103
|
// against known bad fork blocks, so we throw PARENT_UNKNOWN for cases (1) and (2)
|
|
103
|
-
throw new BlobSidecarGossipError(GossipAction.IGNORE, {
|
|
104
|
+
throw new BlobSidecarGossipError(GossipAction.IGNORE, {
|
|
105
|
+
code: BlobSidecarErrorCode.PARENT_UNKNOWN,
|
|
106
|
+
parentRoot,
|
|
107
|
+
blockRoot: blockHex,
|
|
108
|
+
slot: blobSlot,
|
|
109
|
+
});
|
|
104
110
|
}
|
|
105
111
|
|
|
106
112
|
// [REJECT] The blob is from a higher slot than its parent.
|
|
@@ -120,15 +126,23 @@ export async function validateGossipBlobSidecar(
|
|
|
120
126
|
const blockState = await chain.regen
|
|
121
127
|
.getBlockSlotState(parentRoot, blobSlot, {dontTransferCache: true}, RegenCaller.validateGossipBlock)
|
|
122
128
|
.catch(() => {
|
|
123
|
-
throw new BlobSidecarGossipError(GossipAction.IGNORE, {
|
|
129
|
+
throw new BlobSidecarGossipError(GossipAction.IGNORE, {
|
|
130
|
+
code: BlobSidecarErrorCode.PARENT_UNKNOWN,
|
|
131
|
+
parentRoot,
|
|
132
|
+
blockRoot: blockHex,
|
|
133
|
+
slot: blobSlot,
|
|
134
|
+
});
|
|
124
135
|
});
|
|
125
136
|
|
|
126
137
|
// [REJECT] The proposer signature, signed_beacon_block.signature, is valid with respect to the proposer_index pubkey.
|
|
127
|
-
const signatureSet =
|
|
138
|
+
const signatureSet = getBlockHeaderProposerSignatureSetByParentStateSlot(blockState, blobSidecar.signedBlockHeader);
|
|
128
139
|
// Don't batch so verification is not delayed
|
|
129
140
|
if (!(await chain.bls.verifySignatureSets([signatureSet], {verifyOnMainThread: true}))) {
|
|
130
141
|
throw new BlobSidecarGossipError(GossipAction.REJECT, {
|
|
131
142
|
code: BlobSidecarErrorCode.PROPOSAL_SIGNATURE_INVALID,
|
|
143
|
+
blockRoot: blockHex,
|
|
144
|
+
index: blobSidecar.index,
|
|
145
|
+
slot: blobSlot,
|
|
132
146
|
});
|
|
133
147
|
}
|
|
134
148
|
|
|
@@ -175,8 +189,12 @@ export async function validateGossipBlobSidecar(
|
|
|
175
189
|
* Validate some blob sidecars in a block
|
|
176
190
|
*
|
|
177
191
|
* Requires the block to be known to the node
|
|
192
|
+
*
|
|
193
|
+
* NOTE: chain is optional to skip signature verification. Helpful for testing purposes and so that can control whether
|
|
194
|
+
* signature gets checked depending on the reqresp method that is being checked
|
|
178
195
|
*/
|
|
179
196
|
export async function validateBlockBlobSidecars(
|
|
197
|
+
chain: IBeaconChain | null,
|
|
180
198
|
blockSlot: Slot,
|
|
181
199
|
blockRoot: Root,
|
|
182
200
|
blockBlobCount: number,
|
|
@@ -196,7 +214,8 @@ export async function validateBlockBlobSidecars(
|
|
|
196
214
|
}
|
|
197
215
|
|
|
198
216
|
// Hash the first sidecar block header and compare the rest via (cheaper) equality
|
|
199
|
-
const
|
|
217
|
+
const firstSidecarSignedBlockHeader = blobSidecars[0].signedBlockHeader;
|
|
218
|
+
const firstSidecarBlockHeader = firstSidecarSignedBlockHeader.message;
|
|
200
219
|
const firstBlockRoot = ssz.phase0.BeaconBlockHeader.hashTreeRoot(firstSidecarBlockHeader);
|
|
201
220
|
if (Buffer.compare(blockRoot, firstBlockRoot) !== 0) {
|
|
202
221
|
throw new BlobSidecarValidationError(
|
|
@@ -211,17 +230,42 @@ export async function validateBlockBlobSidecars(
|
|
|
211
230
|
);
|
|
212
231
|
}
|
|
213
232
|
|
|
233
|
+
if (chain !== null) {
|
|
234
|
+
const headState = await chain.getHeadState();
|
|
235
|
+
const signatureSet = getBlockHeaderProposerSignatureSetByHeaderSlot(headState, firstSidecarSignedBlockHeader);
|
|
236
|
+
|
|
237
|
+
if (
|
|
238
|
+
!(await chain.bls.verifySignatureSets([signatureSet], {
|
|
239
|
+
batchable: true,
|
|
240
|
+
priority: true,
|
|
241
|
+
verifyOnMainThread: false,
|
|
242
|
+
}))
|
|
243
|
+
) {
|
|
244
|
+
throw new BlobSidecarValidationError({
|
|
245
|
+
code: BlobSidecarErrorCode.PROPOSAL_SIGNATURE_INVALID,
|
|
246
|
+
blockRoot: toRootHex(blockRoot),
|
|
247
|
+
slot: blockSlot,
|
|
248
|
+
index: blobSidecars[0].index,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
214
253
|
const commitments = [];
|
|
215
254
|
const blobs = [];
|
|
216
255
|
const proofs = [];
|
|
217
|
-
for (
|
|
218
|
-
const
|
|
219
|
-
|
|
256
|
+
for (let i = 0; i < blobSidecars.length; i++) {
|
|
257
|
+
const blobSidecar = blobSidecars[i];
|
|
258
|
+
const blobIndex = blobSidecar.index;
|
|
259
|
+
|
|
260
|
+
if (
|
|
261
|
+
i !== 0 &&
|
|
262
|
+
!ssz.phase0.SignedBeaconBlockHeader.equals(blobSidecar.signedBlockHeader, firstSidecarSignedBlockHeader)
|
|
263
|
+
) {
|
|
220
264
|
throw new BlobSidecarValidationError(
|
|
221
265
|
{
|
|
222
266
|
code: BlobSidecarErrorCode.INCORRECT_BLOCK,
|
|
223
267
|
slot: blockSlot,
|
|
224
|
-
blobIdx,
|
|
268
|
+
blobIdx: blobIndex,
|
|
225
269
|
expected: toRootHex(blockRoot),
|
|
226
270
|
actual: "unknown - compared via equality",
|
|
227
271
|
},
|
|
@@ -234,7 +278,7 @@ export async function validateBlockBlobSidecars(
|
|
|
234
278
|
{
|
|
235
279
|
code: BlobSidecarErrorCode.INCLUSION_PROOF_INVALID,
|
|
236
280
|
slot: blockSlot,
|
|
237
|
-
blobIdx,
|
|
281
|
+
blobIdx: blobIndex,
|
|
238
282
|
},
|
|
239
283
|
"BlobSidecar inclusion proof invalid"
|
|
240
284
|
);
|
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
computeEpochAtSlot,
|
|
9
9
|
computeStartSlotAtEpoch,
|
|
10
|
-
|
|
10
|
+
getBlockHeaderProposerSignatureSetByHeaderSlot,
|
|
11
|
+
getBlockHeaderProposerSignatureSetByParentStateSlot,
|
|
11
12
|
} from "@lodestar/state-transition";
|
|
12
13
|
import {Root, Slot, SubnetID, fulu, ssz} from "@lodestar/types";
|
|
13
14
|
import {toRootHex, verifyMerkleBranch} from "@lodestar/utils";
|
|
@@ -86,6 +87,7 @@ export async function validateGossipDataColumnSidecar(
|
|
|
86
87
|
throw new DataColumnSidecarGossipError(GossipAction.IGNORE, {
|
|
87
88
|
code: DataColumnSidecarErrorCode.PARENT_UNKNOWN,
|
|
88
89
|
parentRoot,
|
|
90
|
+
slot: blockHeader.slot,
|
|
89
91
|
});
|
|
90
92
|
}
|
|
91
93
|
|
|
@@ -108,6 +110,7 @@ export async function validateGossipDataColumnSidecar(
|
|
|
108
110
|
throw new DataColumnSidecarGossipError(GossipAction.IGNORE, {
|
|
109
111
|
code: DataColumnSidecarErrorCode.PARENT_UNKNOWN,
|
|
110
112
|
parentRoot,
|
|
113
|
+
slot: blockHeader.slot,
|
|
111
114
|
});
|
|
112
115
|
});
|
|
113
116
|
|
|
@@ -128,15 +131,23 @@ export async function validateGossipDataColumnSidecar(
|
|
|
128
131
|
}
|
|
129
132
|
|
|
130
133
|
// 5) [REJECT] The proposer signature of sidecar.signed_block_header, is valid with respect to the block_header.proposer_index pubkey.
|
|
131
|
-
const signatureSet =
|
|
134
|
+
const signatureSet = getBlockHeaderProposerSignatureSetByParentStateSlot(
|
|
135
|
+
blockState,
|
|
136
|
+
dataColumnSidecar.signedBlockHeader
|
|
137
|
+
);
|
|
132
138
|
// Don't batch so verification is not delayed
|
|
133
139
|
if (
|
|
134
140
|
!(await chain.bls.verifySignatureSets([signatureSet], {
|
|
135
141
|
verifyOnMainThread: blockHeader.slot > chain.forkChoice.getHead().slot,
|
|
136
142
|
}))
|
|
137
143
|
) {
|
|
144
|
+
const blockRoot = ssz.phase0.BeaconBlockHeader.hashTreeRoot(dataColumnSidecar.signedBlockHeader.message);
|
|
145
|
+
const blockRootHex = toRootHex(blockRoot);
|
|
138
146
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
139
147
|
code: DataColumnSidecarErrorCode.PROPOSAL_SIGNATURE_INVALID,
|
|
148
|
+
blockRoot: blockRootHex,
|
|
149
|
+
index: dataColumnSidecar.index,
|
|
150
|
+
slot: blockHeader.slot,
|
|
140
151
|
});
|
|
141
152
|
}
|
|
142
153
|
|
|
@@ -271,8 +282,12 @@ export function verifyDataColumnSidecarInclusionProof(dataColumnSidecar: fulu.Da
|
|
|
271
282
|
* Validate a subset of data column sidecars in a block
|
|
272
283
|
*
|
|
273
284
|
* Requires the block to be known to the node
|
|
285
|
+
*
|
|
286
|
+
* NOTE: chain is optional to skip signature verification. Helpful for testing purposes and so that can control whether
|
|
287
|
+
* signature gets checked depending on the reqresp method that is being checked
|
|
274
288
|
*/
|
|
275
289
|
export async function validateBlockDataColumnSidecars(
|
|
290
|
+
chain: IBeaconChain | null,
|
|
276
291
|
blockSlot: Slot,
|
|
277
292
|
blockRoot: Root,
|
|
278
293
|
blockBlobCount: number,
|
|
@@ -294,7 +309,8 @@ export async function validateBlockDataColumnSidecars(
|
|
|
294
309
|
);
|
|
295
310
|
}
|
|
296
311
|
// Hash the first sidecar block header and compare the rest via (cheaper) equality
|
|
297
|
-
const
|
|
312
|
+
const firstSidecarSignedBlockHeader = dataColumnSidecars[0].signedBlockHeader;
|
|
313
|
+
const firstSidecarBlockHeader = firstSidecarSignedBlockHeader.message;
|
|
298
314
|
const firstBlockRoot = ssz.phase0.BeaconBlockHeader.hashTreeRoot(firstSidecarBlockHeader);
|
|
299
315
|
if (Buffer.compare(blockRoot, firstBlockRoot) !== 0) {
|
|
300
316
|
throw new DataColumnSidecarValidationError(
|
|
@@ -309,6 +325,26 @@ export async function validateBlockDataColumnSidecars(
|
|
|
309
325
|
);
|
|
310
326
|
}
|
|
311
327
|
|
|
328
|
+
if (chain !== null) {
|
|
329
|
+
const headState = await chain.getHeadState();
|
|
330
|
+
const signatureSet = getBlockHeaderProposerSignatureSetByHeaderSlot(headState, firstSidecarSignedBlockHeader);
|
|
331
|
+
|
|
332
|
+
if (
|
|
333
|
+
!(await chain.bls.verifySignatureSets([signatureSet], {
|
|
334
|
+
batchable: true,
|
|
335
|
+
priority: true,
|
|
336
|
+
verifyOnMainThread: false,
|
|
337
|
+
}))
|
|
338
|
+
) {
|
|
339
|
+
throw new DataColumnSidecarValidationError({
|
|
340
|
+
code: DataColumnSidecarErrorCode.PROPOSAL_SIGNATURE_INVALID,
|
|
341
|
+
blockRoot: toRootHex(blockRoot),
|
|
342
|
+
slot: blockSlot,
|
|
343
|
+
index: dataColumnSidecars[0].index,
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
312
348
|
const commitments: Uint8Array[] = [];
|
|
313
349
|
const cellIndices: number[] = [];
|
|
314
350
|
const cells: Uint8Array[] = [];
|
|
@@ -316,7 +352,10 @@ export async function validateBlockDataColumnSidecars(
|
|
|
316
352
|
for (let i = 0; i < dataColumnSidecars.length; i++) {
|
|
317
353
|
const columnSidecar = dataColumnSidecars[i];
|
|
318
354
|
|
|
319
|
-
if (
|
|
355
|
+
if (
|
|
356
|
+
i !== 0 &&
|
|
357
|
+
!ssz.phase0.SignedBeaconBlockHeader.equals(firstSidecarSignedBlockHeader, columnSidecar.signedBlockHeader)
|
|
358
|
+
) {
|
|
320
359
|
throw new DataColumnSidecarValidationError({
|
|
321
360
|
code: DataColumnSidecarErrorCode.INCORRECT_HEADER_ROOT,
|
|
322
361
|
slot: blockSlot,
|
|
@@ -296,6 +296,10 @@ export class Eth2Gossipsub extends GossipSub {
|
|
|
296
296
|
// Get seenTimestamp before adding the message to the queue or add async delays
|
|
297
297
|
const seenTimestampSec = Date.now() / 1000;
|
|
298
298
|
|
|
299
|
+
const peerIdStr = propagationSource.toString();
|
|
300
|
+
const clientAgent = this.peersData.getPeerKind(peerIdStr) ?? "Unknown";
|
|
301
|
+
const clientVersion = this.peersData.getAgentVersion(peerIdStr);
|
|
302
|
+
|
|
299
303
|
// Use setTimeout to yield to the macro queue
|
|
300
304
|
// Without this we'll have huge event loop lag
|
|
301
305
|
// See https://github.com/ChainSafe/lodestar/issues/5604
|
|
@@ -305,7 +309,9 @@ export class Eth2Gossipsub extends GossipSub {
|
|
|
305
309
|
msg,
|
|
306
310
|
msgId,
|
|
307
311
|
// Hot path, use cached .toString() version
|
|
308
|
-
propagationSource:
|
|
312
|
+
propagationSource: peerIdStr,
|
|
313
|
+
clientVersion,
|
|
314
|
+
clientAgent,
|
|
309
315
|
seenTimestampSec,
|
|
310
316
|
startProcessUnixSec: null,
|
|
311
317
|
});
|
|
@@ -391,8 +391,8 @@ export class PeerDiscovery {
|
|
|
391
391
|
// tcp multiaddr is known to be be present, checked inside the worker
|
|
392
392
|
const multiaddrTCP = enr.getLocationMultiaddr(ENRKey.tcp);
|
|
393
393
|
if (!multiaddrTCP) {
|
|
394
|
-
this.logger.
|
|
395
|
-
this.metrics?.discovery.discoveredStatus.inc({status: DiscoveredPeerStatus.
|
|
394
|
+
this.logger.warn("Discv5 worker sent enr without tcp multiaddr", {enr: enr.encodeTxt()});
|
|
395
|
+
this.metrics?.discovery.discoveredStatus.inc({status: DiscoveredPeerStatus.no_multiaddrs});
|
|
396
396
|
return;
|
|
397
397
|
}
|
|
398
398
|
// Are this fields mandatory?
|
|
@@ -296,6 +296,21 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
|
|
|
296
296
|
const slot = dataColumnBlockHeader.slot;
|
|
297
297
|
const blockRootHex = toRootHex(ssz.phase0.BeaconBlockHeader.hashTreeRoot(dataColumnBlockHeader));
|
|
298
298
|
|
|
299
|
+
// check to see if block has already been processed and BlockInput has been deleted (column received via reqresp or other means)
|
|
300
|
+
if (chain.forkChoice.hasBlockHex(blockRootHex)) {
|
|
301
|
+
metrics?.peerDas.dataColumnSidecarProcessingSkip.inc();
|
|
302
|
+
logger.debug("Already processed block for column sidecar, skipping processing", {
|
|
303
|
+
slot,
|
|
304
|
+
blockRoot: blockRootHex,
|
|
305
|
+
index: dataColumnSidecar.index,
|
|
306
|
+
});
|
|
307
|
+
throw new DataColumnSidecarGossipError(GossipAction.IGNORE, {
|
|
308
|
+
code: DataColumnSidecarErrorCode.ALREADY_KNOWN,
|
|
309
|
+
columnIndex: dataColumnSidecar.index,
|
|
310
|
+
slot,
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
299
314
|
// first check if we should even process this column (we may have already processed it via getBlobsV2)
|
|
300
315
|
{
|
|
301
316
|
const blockInput = chain.seenBlockInputCache.get(blockRootHex);
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
GossipValidatorBatchFn,
|
|
12
12
|
GossipValidatorFn,
|
|
13
13
|
} from "../gossip/interface.js";
|
|
14
|
+
import {prettyPrintPeerIdStr} from "../util.ts";
|
|
14
15
|
|
|
15
16
|
export type ValidatorFnModules = {
|
|
16
17
|
config: ChainForkConfig;
|
|
@@ -99,7 +100,15 @@ export function getGossipValidatorBatchFn(
|
|
|
99
100
|
export function getGossipValidatorFn(gossipHandlers: GossipHandlers, modules: ValidatorFnModules): GossipValidatorFn {
|
|
100
101
|
const {logger, metrics} = modules;
|
|
101
102
|
|
|
102
|
-
return async function gossipValidatorFn({
|
|
103
|
+
return async function gossipValidatorFn({
|
|
104
|
+
topic,
|
|
105
|
+
msg,
|
|
106
|
+
propagationSource,
|
|
107
|
+
clientAgent,
|
|
108
|
+
clientVersion,
|
|
109
|
+
seenTimestampSec,
|
|
110
|
+
msgSlot,
|
|
111
|
+
}) {
|
|
103
112
|
const type = topic.type;
|
|
104
113
|
|
|
105
114
|
try {
|
|
@@ -134,7 +143,11 @@ export function getGossipValidatorFn(gossipHandlers: GossipHandlers, modules: Va
|
|
|
134
143
|
|
|
135
144
|
case GossipAction.REJECT:
|
|
136
145
|
metrics?.networkProcessor.gossipValidationReject.inc({topic: type});
|
|
137
|
-
logger.debug(
|
|
146
|
+
logger.debug(
|
|
147
|
+
`Gossip validation ${type} rejected`,
|
|
148
|
+
{peerId: prettyPrintPeerIdStr(propagationSource), clientAgent, clientVersion},
|
|
149
|
+
e
|
|
150
|
+
);
|
|
138
151
|
return TopicValidatorResult.Reject;
|
|
139
152
|
}
|
|
140
153
|
}
|
|
@@ -15,6 +15,8 @@ export type PendingGossipsubMessage = {
|
|
|
15
15
|
msgSlot?: Slot;
|
|
16
16
|
msgId: string;
|
|
17
17
|
propagationSource: PeerIdStr;
|
|
18
|
+
clientAgent: string;
|
|
19
|
+
clientVersion: string;
|
|
18
20
|
seenTimestampSec: number;
|
|
19
21
|
startProcessUnixSec: number | null;
|
|
20
22
|
// specific properties for IndexedGossipQueueMinSize, for beacon_attestation topic only
|
package/src/sync/unknownBlock.ts
CHANGED
|
@@ -532,7 +532,7 @@ export class BlockInputSync {
|
|
|
532
532
|
const downloadResult = await downloadByRoot({
|
|
533
533
|
config: this.config,
|
|
534
534
|
network: this.network,
|
|
535
|
-
|
|
535
|
+
chain: this.chain,
|
|
536
536
|
emitter: this.chain.emitter,
|
|
537
537
|
peerMeta,
|
|
538
538
|
cacheItem,
|
|
@@ -37,7 +37,6 @@ export type DownloadByRangeResponses = {
|
|
|
37
37
|
|
|
38
38
|
export type DownloadAndCacheByRangeProps = DownloadByRangeRequests & {
|
|
39
39
|
config: ChainForkConfig;
|
|
40
|
-
cache: SeenBlockInput;
|
|
41
40
|
network: INetwork;
|
|
42
41
|
logger: Logger;
|
|
43
42
|
peerIdStr: string;
|
|
@@ -203,7 +202,7 @@ export async function downloadByRange({
|
|
|
203
202
|
blocksRequest,
|
|
204
203
|
blobsRequest,
|
|
205
204
|
columnsRequest,
|
|
206
|
-
}:
|
|
205
|
+
}: DownloadAndCacheByRangeProps): Promise<WarnResult<ValidatedResponses, DownloadByRangeError>> {
|
|
207
206
|
let response: DownloadByRangeResponses;
|
|
208
207
|
try {
|
|
209
208
|
response = await requestByRange({
|
|
@@ -555,9 +554,13 @@ export async function validateBlobsByRangeResponse(
|
|
|
555
554
|
}
|
|
556
555
|
|
|
557
556
|
validateSidecarsPromises.push(
|
|
558
|
-
validateBlockBlobSidecars(
|
|
559
|
-
|
|
560
|
-
|
|
557
|
+
validateBlockBlobSidecars(
|
|
558
|
+
null, // do not pass chain here so we do not validate header signature
|
|
559
|
+
block.message.slot,
|
|
560
|
+
blockRoot,
|
|
561
|
+
blockKzgCommitments.length,
|
|
562
|
+
blockBlobSidecars
|
|
563
|
+
).then(() => ({blockRoot, blobSidecars: blockBlobSidecars}))
|
|
561
564
|
);
|
|
562
565
|
}
|
|
563
566
|
|
|
@@ -768,7 +771,13 @@ export async function validateColumnsByRangeResponse(
|
|
|
768
771
|
}
|
|
769
772
|
|
|
770
773
|
validationPromises.push(
|
|
771
|
-
validateBlockDataColumnSidecars(
|
|
774
|
+
validateBlockDataColumnSidecars(
|
|
775
|
+
null, // do not pass chain here so we do not validate header signature
|
|
776
|
+
slot,
|
|
777
|
+
blockRoot,
|
|
778
|
+
blobCount,
|
|
779
|
+
columnSidecars
|
|
780
|
+
).then(() => ({
|
|
772
781
|
blockRoot,
|
|
773
782
|
columnSidecars,
|
|
774
783
|
}))
|