@lodestar/beacon-node 1.46.0-dev.9be1d27b00 → 1.46.0-dev.a03686d0dc
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 +37 -15
- package/lib/api/impl/beacon/blocks/index.js.map +1 -1
- package/lib/api/impl/validator/index.d.ts.map +1 -1
- package/lib/api/impl/validator/index.js +15 -6
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/chain/blocks/importBlock.d.ts.map +1 -1
- package/lib/chain/blocks/importBlock.js +3 -3
- package/lib/chain/blocks/importBlock.js.map +1 -1
- package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
- package/lib/chain/blocks/importExecutionPayload.js +3 -4
- package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
- package/lib/chain/blocks/index.d.ts.map +1 -1
- package/lib/chain/blocks/index.js +6 -0
- package/lib/chain/blocks/index.js.map +1 -1
- package/lib/chain/blocks/utils/chainSegment.d.ts.map +1 -1
- package/lib/chain/blocks/utils/chainSegment.js +31 -25
- package/lib/chain/blocks/utils/chainSegment.js.map +1 -1
- package/lib/chain/blocks/utils/polarBearBanner.d.ts +2 -0
- package/lib/chain/blocks/utils/polarBearBanner.d.ts.map +1 -0
- package/lib/chain/blocks/utils/polarBearBanner.js +51 -0
- package/lib/chain/blocks/utils/polarBearBanner.js.map +1 -0
- package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlock.js +21 -1
- package/lib/chain/blocks/verifyBlock.js.map +1 -1
- package/lib/chain/chain.d.ts +5 -0
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +55 -0
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/emitter.d.ts +6 -0
- package/lib/chain/emitter.d.ts.map +1 -1
- package/lib/chain/emitter.js +5 -0
- package/lib/chain/emitter.js.map +1 -1
- package/lib/chain/interface.d.ts +2 -0
- package/lib/chain/interface.d.ts.map +1 -1
- package/lib/chain/options.d.ts +2 -0
- package/lib/chain/options.d.ts.map +1 -1
- package/lib/chain/options.js +1 -0
- package/lib/chain/options.js.map +1 -1
- package/lib/chain/prepareNextSlot.d.ts.map +1 -1
- package/lib/chain/prepareNextSlot.js +107 -29
- package/lib/chain/prepareNextSlot.js.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.js +6 -6
- package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
- package/lib/chain/seenCache/seenBlockProposers.d.ts +20 -4
- package/lib/chain/seenCache/seenBlockProposers.d.ts.map +1 -1
- package/lib/chain/seenCache/seenBlockProposers.js +49 -2
- package/lib/chain/seenCache/seenBlockProposers.js.map +1 -1
- package/lib/chain/validation/block.d.ts +4 -1
- package/lib/chain/validation/block.d.ts.map +1 -1
- package/lib/chain/validation/block.js +32 -18
- package/lib/chain/validation/block.js.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.js +21 -16
- package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
- package/lib/metrics/metrics/lodestar.d.ts +14 -0
- package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
- package/lib/metrics/metrics/lodestar.js +38 -0
- package/lib/metrics/metrics/lodestar.js.map +1 -1
- package/lib/network/core/networkCore.d.ts.map +1 -1
- package/lib/network/core/networkCore.js +12 -1
- package/lib/network/core/networkCore.js.map +1 -1
- package/lib/network/core/networkCoreWorkerHandler.d.ts.map +1 -1
- package/lib/network/core/networkCoreWorkerHandler.js +20 -3
- package/lib/network/core/networkCoreWorkerHandler.js.map +1 -1
- package/lib/network/network.d.ts +1 -0
- package/lib/network/network.d.ts.map +1 -1
- package/lib/network/network.js +11 -1
- package/lib/network/network.js.map +1 -1
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +8 -0
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/network/reqresp/score.d.ts.map +1 -1
- package/lib/network/reqresp/score.js +20 -3
- package/lib/network/reqresp/score.js.map +1 -1
- package/lib/sync/range/batch.d.ts.map +1 -1
- package/lib/sync/range/batch.js +15 -3
- package/lib/sync/range/batch.js.map +1 -1
- package/lib/sync/range/utils/hashBlocks.d.ts +16 -4
- package/lib/sync/range/utils/hashBlocks.d.ts.map +1 -1
- package/lib/sync/range/utils/hashBlocks.js +49 -18
- package/lib/sync/range/utils/hashBlocks.js.map +1 -1
- package/lib/util/clock.d.ts +2 -7
- package/lib/util/clock.d.ts.map +1 -1
- package/lib/util/clock.js +2 -7
- package/lib/util/clock.js.map +1 -1
- package/lib/util/workerEvents.d.ts +7 -1
- package/lib/util/workerEvents.d.ts.map +1 -1
- package/lib/util/workerEvents.js +17 -5
- package/lib/util/workerEvents.js.map +1 -1
- package/package.json +15 -15
- package/src/api/impl/beacon/blocks/index.ts +65 -16
- package/src/api/impl/validator/index.ts +19 -6
- package/src/chain/blocks/importBlock.ts +3 -2
- package/src/chain/blocks/importExecutionPayload.ts +8 -4
- package/src/chain/blocks/index.ts +7 -0
- package/src/chain/blocks/utils/chainSegment.ts +35 -28
- package/src/chain/blocks/utils/polarBearBanner.ts +50 -0
- package/src/chain/blocks/verifyBlock.ts +28 -2
- package/src/chain/chain.ts +60 -0
- package/src/chain/emitter.ts +7 -0
- package/src/chain/interface.ts +3 -0
- package/src/chain/options.ts +3 -0
- package/src/chain/prepareNextSlot.ts +140 -39
- package/src/chain/produceBlock/produceBlockBody.ts +11 -6
- package/src/chain/seenCache/seenBlockProposers.ts +72 -5
- package/src/chain/validation/block.ts +41 -19
- package/src/chain/validation/dataColumnSidecar.ts +27 -17
- package/src/metrics/metrics/lodestar.ts +39 -0
- package/src/network/core/networkCore.ts +13 -1
- package/src/network/core/networkCoreWorkerHandler.ts +18 -3
- package/src/network/network.ts +16 -1
- package/src/network/processor/gossipHandlers.ts +7 -0
- package/src/network/reqresp/score.ts +22 -3
- package/src/sync/range/batch.ts +20 -3
- package/src/sync/range/utils/hashBlocks.ts +56 -21
- package/src/util/clock.ts +2 -7
- package/src/util/workerEvents.ts +18 -6
|
@@ -1,21 +1,83 @@
|
|
|
1
1
|
import {computeStartSlotAtEpoch} from "@lodestar/state-transition";
|
|
2
|
-
import {Epoch, Slot, ValidatorIndex} from "@lodestar/types";
|
|
2
|
+
import {Epoch, RootHex, Slot, ValidatorIndex, phase0} from "@lodestar/types";
|
|
3
3
|
import {MapDef} from "@lodestar/utils";
|
|
4
4
|
|
|
5
|
+
/** Two distinct block roots signed by the same proposer for the same slot are sufficient to establish an equivocation */
|
|
6
|
+
const MAX_BLOCK_ROOTS_PER_PROPOSAL = 2;
|
|
7
|
+
|
|
5
8
|
/**
|
|
6
9
|
* Keeps a cache to filter block proposals from the same validator in the same slot.
|
|
7
10
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
11
|
+
* Block roots with a signature verified against the block's proposer index are tracked separately from proposals
|
|
12
|
+
* accepted by gossip validation or block import. A root from a block signed by its declared proposer is potential
|
|
13
|
+
* equivocation evidence, but the block may still fail other validation. Such a block must not mark the proposal as
|
|
14
|
+
* known, since that would cause a later valid block for the same slot and proposer to be ignored as a repeat proposal.
|
|
15
|
+
*
|
|
16
|
+
* The signed block header of each observed root is kept so a proposer slashing can be produced from the two
|
|
17
|
+
* conflicting headers once an equivocation is established.
|
|
18
|
+
*
|
|
19
|
+
* The cache is pruned on finalization and bounds the number of roots stored per proposer and slot
|
|
10
20
|
*/
|
|
11
21
|
export class SeenBlockProposers {
|
|
12
22
|
private readonly proposerIndexesBySlot = new MapDef<Slot, Set<ValidatorIndex>>(() => new Set<ValidatorIndex>());
|
|
13
|
-
private
|
|
23
|
+
private readonly signedBlockHeadersBySlot = new MapDef<
|
|
24
|
+
Slot,
|
|
25
|
+
MapDef<ValidatorIndex, Map<RootHex, phase0.SignedBeaconBlockHeader>>
|
|
26
|
+
>(() => new MapDef<ValidatorIndex, Map<RootHex, phase0.SignedBeaconBlockHeader>>(() => new Map()));
|
|
27
|
+
private finalizedSlot: Slot = 0;
|
|
14
28
|
|
|
15
29
|
isKnown(blockSlot: Slot, proposerIndex: ValidatorIndex): boolean {
|
|
16
30
|
return this.proposerIndexesBySlot.get(blockSlot)?.has(proposerIndex) === true;
|
|
17
31
|
}
|
|
18
32
|
|
|
33
|
+
hasBlockRoot(blockSlot: Slot, proposerIndex: ValidatorIndex, blockRoot: RootHex): boolean {
|
|
34
|
+
return this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.has(blockRoot) === true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
isEquivocating(blockSlot: Slot, proposerIndex: ValidatorIndex): boolean {
|
|
38
|
+
return (
|
|
39
|
+
(this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.size ?? 0) >= MAX_BLOCK_ROOTS_PER_PROPOSAL
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getConflictingBlockRoots(blockSlot: Slot, proposerIndex: ValidatorIndex, blockRoot: RootHex): RootHex[] {
|
|
44
|
+
const signedBlockHeaderByRoot = this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex);
|
|
45
|
+
return signedBlockHeaderByRoot === undefined
|
|
46
|
+
? []
|
|
47
|
+
: Array.from(signedBlockHeaderByRoot.keys()).filter((root) => root !== blockRoot);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Return the two signed block headers that establish an equivocation, or null if there is none */
|
|
51
|
+
getEquivocationHeaders(
|
|
52
|
+
blockSlot: Slot,
|
|
53
|
+
proposerIndex: ValidatorIndex
|
|
54
|
+
): [phase0.SignedBeaconBlockHeader, phase0.SignedBeaconBlockHeader] | null {
|
|
55
|
+
const signedBlockHeaderByRoot = this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex);
|
|
56
|
+
if (signedBlockHeaderByRoot === undefined || signedBlockHeaderByRoot.size < MAX_BLOCK_ROOTS_PER_PROPOSAL) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const [signedHeader1, signedHeader2] = signedBlockHeaderByRoot.values();
|
|
60
|
+
return [signedHeader1, signedHeader2];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Record a block only after its proposer signature has been verified */
|
|
64
|
+
observeBlockRoot(
|
|
65
|
+
blockSlot: Slot,
|
|
66
|
+
proposerIndex: ValidatorIndex,
|
|
67
|
+
blockRoot: RootHex,
|
|
68
|
+
signedBlockHeader: phase0.SignedBeaconBlockHeader
|
|
69
|
+
): void {
|
|
70
|
+
if (blockSlot < this.finalizedSlot) {
|
|
71
|
+
throw Error(`blockSlot ${blockSlot} < finalizedSlot ${this.finalizedSlot}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const signedBlockHeaderByRoot = this.signedBlockHeadersBySlot.getOrDefault(blockSlot).getOrDefault(proposerIndex);
|
|
75
|
+
if (signedBlockHeaderByRoot.size < MAX_BLOCK_ROOTS_PER_PROPOSAL && !signedBlockHeaderByRoot.has(blockRoot)) {
|
|
76
|
+
signedBlockHeaderByRoot.set(blockRoot, signedBlockHeader);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Mark a block as known from gossip or another block import path */
|
|
19
81
|
add(blockSlot: Slot, proposerIndex: ValidatorIndex): void {
|
|
20
82
|
if (blockSlot < this.finalizedSlot) {
|
|
21
83
|
throw Error(`blockSlot ${blockSlot} < finalizedSlot ${this.finalizedSlot}`);
|
|
@@ -31,9 +93,14 @@ export class SeenBlockProposers {
|
|
|
31
93
|
this.proposerIndexesBySlot.delete(slot);
|
|
32
94
|
}
|
|
33
95
|
}
|
|
96
|
+
for (const slot of this.signedBlockHeadersBySlot.keys()) {
|
|
97
|
+
if (slot < finalizedSlot) {
|
|
98
|
+
this.signedBlockHeadersBySlot.delete(slot);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
34
101
|
}
|
|
35
102
|
|
|
36
|
-
seenAtEpoch(epoch:
|
|
103
|
+
seenAtEpoch(epoch: Epoch, index: ValidatorIndex): boolean {
|
|
37
104
|
const fromSlot = computeStartSlotAtEpoch(epoch);
|
|
38
105
|
const toSlot = computeStartSlotAtEpoch(epoch + 1);
|
|
39
106
|
|
|
@@ -23,8 +23,9 @@ import {
|
|
|
23
23
|
getBlockProposerSignatureSet,
|
|
24
24
|
isExecutionBlockBodyType,
|
|
25
25
|
isStatePostBellatrix,
|
|
26
|
+
signedBlockToSignedHeader,
|
|
26
27
|
} from "@lodestar/state-transition";
|
|
27
|
-
import {SignedBeaconBlock, deneb, gloas, isGloasBeaconBlock} from "@lodestar/types";
|
|
28
|
+
import {RootHex, SignedBeaconBlock, deneb, gloas, isGloasBeaconBlock, ssz} from "@lodestar/types";
|
|
28
29
|
import {byteArrayEquals, sleep, toRootHex} from "@lodestar/utils";
|
|
29
30
|
import {BlockErrorCode, BlockGossipError, GossipAction} from "../errors/index.js";
|
|
30
31
|
import {IBeaconChain} from "../interface.js";
|
|
@@ -75,7 +76,10 @@ export async function validateGossipBlock(
|
|
|
75
76
|
// reboot if the `observed_block_producers` cache is empty. In that case, without this
|
|
76
77
|
// check, we will load the parent and state from disk only to find out later that we
|
|
77
78
|
// already know this block.
|
|
78
|
-
|
|
79
|
+
// A block's hash tree root is identical to its header's, so the root is derived from the header
|
|
80
|
+
// which is also used as potential equivocation evidence
|
|
81
|
+
const signedBlockHeader = signedBlockToSignedHeader(config, signedBlock);
|
|
82
|
+
const blockRoot = toRootHex(ssz.phase0.BeaconBlockHeader.hashTreeRoot(signedBlockHeader.message));
|
|
79
83
|
if (chain.forkChoice.getBlockHexDefaultStatus(blockRoot) !== null) {
|
|
80
84
|
throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.ALREADY_KNOWN, root: blockRoot});
|
|
81
85
|
}
|
|
@@ -85,7 +89,12 @@ export async function validateGossipBlock(
|
|
|
85
89
|
|
|
86
90
|
// [IGNORE] The block is the first block with valid signature received for the proposer for the slot, signed_beacon_block.message.slot.
|
|
87
91
|
const proposerIndex = block.proposerIndex;
|
|
92
|
+
const hasBlockRoot = chain.seenBlockProposers.hasBlockRoot(blockSlot, proposerIndex, blockRoot);
|
|
88
93
|
if (chain.seenBlockProposers.isKnown(blockSlot, proposerIndex)) {
|
|
94
|
+
if (!hasBlockRoot && !chain.seenBlockProposers.isEquivocating(blockSlot, proposerIndex)) {
|
|
95
|
+
await verifyBlockProposerSignature(chain, signedBlock, blockRoot, {verifyOnMainThread: false});
|
|
96
|
+
chain.seenBlockProposers.observeBlockRoot(blockSlot, proposerIndex, blockRoot, signedBlockHeader);
|
|
97
|
+
}
|
|
89
98
|
throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.REPEAT_PROPOSAL, proposerIndex});
|
|
90
99
|
}
|
|
91
100
|
|
|
@@ -270,18 +279,8 @@ export async function validateGossipBlock(
|
|
|
270
279
|
}
|
|
271
280
|
|
|
272
281
|
// [REJECT] The proposer signature, signed_beacon_block.signature, is valid with respect to the proposer_index pubkey.
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
// Don't batch so verification is not delayed
|
|
276
|
-
if (!(await chain.bls.verifySignatureSets([signatureSet], {verifyOnMainThread: true}))) {
|
|
277
|
-
throw new BlockGossipError(GossipAction.REJECT, {
|
|
278
|
-
code: BlockErrorCode.PROPOSAL_SIGNATURE_INVALID,
|
|
279
|
-
blockSlot,
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
chain.seenBlockInputCache.markVerifiedProposerSignature(blockSlot, blockRoot, signedBlock.signature);
|
|
284
|
-
}
|
|
282
|
+
await verifyBlockProposerSignature(chain, signedBlock, blockRoot);
|
|
283
|
+
chain.seenBlockProposers.observeBlockRoot(blockSlot, proposerIndex, blockRoot, signedBlockHeader);
|
|
285
284
|
|
|
286
285
|
// [REJECT] The block is proposed by the expected proposer_index for the block's slot in the context of the current
|
|
287
286
|
// shuffling (defined by parent_root/slot). If the proposer_index cannot immediately be verified against the expected
|
|
@@ -291,11 +290,6 @@ export async function validateGossipBlock(
|
|
|
291
290
|
throw new BlockGossipError(GossipAction.REJECT, {code: BlockErrorCode.INCORRECT_PROPOSER, proposerIndex});
|
|
292
291
|
}
|
|
293
292
|
|
|
294
|
-
// Check again in case there two blocks are processed concurrently
|
|
295
|
-
if (chain.seenBlockProposers.isKnown(blockSlot, proposerIndex)) {
|
|
296
|
-
throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.REPEAT_PROPOSAL, proposerIndex});
|
|
297
|
-
}
|
|
298
|
-
|
|
299
293
|
// Simple implementation of a pending block queue. Keeping the block here recycles the queue logic, and keeps the
|
|
300
294
|
// gossip validation promise without any extra infrastructure.
|
|
301
295
|
// Do the sleep at the end, since regen and signature validation can already take longer than `msToBlockSlot`.
|
|
@@ -305,7 +299,35 @@ export async function validateGossipBlock(
|
|
|
305
299
|
await sleep(msToBlockSlot);
|
|
306
300
|
}
|
|
307
301
|
|
|
302
|
+
// Check again after all async validation and the early-block delay so concurrent proposals cannot both pass
|
|
303
|
+
if (chain.seenBlockProposers.isKnown(blockSlot, proposerIndex)) {
|
|
304
|
+
throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.REPEAT_PROPOSAL, proposerIndex});
|
|
305
|
+
}
|
|
306
|
+
|
|
308
307
|
chain.seenBlockProposers.add(blockSlot, proposerIndex);
|
|
309
308
|
|
|
310
309
|
return {skippedSlots};
|
|
311
310
|
}
|
|
311
|
+
|
|
312
|
+
export async function verifyBlockProposerSignature(
|
|
313
|
+
chain: IBeaconChain,
|
|
314
|
+
signedBlock: SignedBeaconBlock,
|
|
315
|
+
blockRoot: RootHex,
|
|
316
|
+
opts: {verifyOnMainThread?: boolean} = {}
|
|
317
|
+
): Promise<void> {
|
|
318
|
+
const blockSlot = signedBlock.message.slot;
|
|
319
|
+
if (chain.seenBlockInputCache.isVerifiedProposerSignature(blockSlot, blockRoot, signedBlock.signature)) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const signatureSet = getBlockProposerSignatureSet(chain.config, signedBlock);
|
|
324
|
+
// Don't batch so verification is not delayed
|
|
325
|
+
if (!(await chain.bls.verifySignatureSets([signatureSet], {verifyOnMainThread: opts.verifyOnMainThread ?? true}))) {
|
|
326
|
+
throw new BlockGossipError(GossipAction.REJECT, {
|
|
327
|
+
code: BlockErrorCode.PROPOSAL_SIGNATURE_INVALID,
|
|
328
|
+
blockSlot,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
chain.seenBlockInputCache.markVerifiedProposerSignature(blockSlot, blockRoot, signedBlock.signature);
|
|
333
|
+
}
|
|
@@ -2,15 +2,16 @@ import {ChainConfig, ChainForkConfig} from "@lodestar/config";
|
|
|
2
2
|
import {
|
|
3
3
|
KZG_COMMITMENTS_INCLUSION_PROOF_DEPTH,
|
|
4
4
|
KZG_COMMITMENTS_SUBTREE_INDEX,
|
|
5
|
+
MIN_SEED_LOOKAHEAD,
|
|
5
6
|
NUMBER_OF_COLUMNS,
|
|
7
|
+
isForkPostFulu,
|
|
6
8
|
} from "@lodestar/params";
|
|
7
9
|
import {
|
|
8
10
|
computeEpochAtSlot,
|
|
9
11
|
computeStartSlotAtEpoch,
|
|
10
12
|
getBlockHeaderProposerSignatureSetByHeaderSlot,
|
|
11
|
-
getBlockHeaderProposerSignatureSetByParentStateSlot,
|
|
12
13
|
} from "@lodestar/state-transition";
|
|
13
|
-
import {DataColumnSidecar, Root, Slot, SubnetID, fulu, gloas, ssz} from "@lodestar/types";
|
|
14
|
+
import {DataColumnSidecar, Root, Slot, SubnetID, ValidatorIndex, fulu, gloas, ssz} from "@lodestar/types";
|
|
14
15
|
import {byteArrayEquals, toRootHex, verifyMerkleBranch} from "@lodestar/utils";
|
|
15
16
|
import {BeaconMetrics} from "../../metrics/metrics/beacon.js";
|
|
16
17
|
import {Metrics} from "../../metrics/metrics.js";
|
|
@@ -104,19 +105,23 @@ export async function validateGossipFuluDataColumnSidecar(
|
|
|
104
105
|
});
|
|
105
106
|
}
|
|
106
107
|
|
|
107
|
-
// getBlockSlotState also checks for whether the current finalized checkpoint is an ancestor of the block.
|
|
108
|
-
// As a result, we throw an IGNORE (whereas the spec says we should REJECT for this scenario).
|
|
109
|
-
// this is something we should change this in the future to make the code airtight to the spec.
|
|
110
108
|
// 7) [REJECT] The sidecar's block's parent passes validation.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
109
|
+
// Post-fulu, we can use parent state to get expected proposer index thanks to proposer lookahead
|
|
110
|
+
const parentEpoch = computeEpochAtSlot(parentBlock.slot);
|
|
111
|
+
const blockEpoch = computeEpochAtSlot(blockHeader.slot);
|
|
112
|
+
const getProposerIndex = async (): Promise<ValidatorIndex> => {
|
|
113
|
+
if (isForkPostFulu(chain.config.getForkName(parentBlock.slot)) && blockEpoch - parentEpoch <= MIN_SEED_LOOKAHEAD) {
|
|
114
|
+
const parentState = await chain.regen.getState(parentBlock.stateRoot, RegenCaller.validateGossipDataColumn);
|
|
115
|
+
return parentState.getBeaconProposer(blockHeader.slot);
|
|
116
|
+
}
|
|
117
|
+
const blockState = await chain.regen.getBlockSlotState(
|
|
118
|
+
parentBlock,
|
|
119
|
+
blockHeader.slot,
|
|
120
|
+
{dontTransferCache: true},
|
|
121
|
+
RegenCaller.validateGossipDataColumn
|
|
122
|
+
);
|
|
123
|
+
return blockState.getBeaconProposer(blockHeader.slot);
|
|
124
|
+
};
|
|
120
125
|
|
|
121
126
|
// 13) [REJECT] The sidecar is proposed by the expected proposer_index for the block's slot in the context of the current
|
|
122
127
|
// shuffling (defined by block_header.parent_root/block_header.slot). If the proposer_index cannot
|
|
@@ -124,7 +129,13 @@ export async function validateGossipFuluDataColumnSidecar(
|
|
|
124
129
|
// while proposers for the block's branch are calculated -- in such a case do not REJECT, instead IGNORE
|
|
125
130
|
// this message.
|
|
126
131
|
const proposerIndex = blockHeader.proposerIndex;
|
|
127
|
-
const expectedProposerIndex =
|
|
132
|
+
const expectedProposerIndex = await getProposerIndex().catch(() => {
|
|
133
|
+
throw new DataColumnSidecarGossipError(GossipAction.IGNORE, {
|
|
134
|
+
code: DataColumnSidecarErrorCode.PARENT_UNKNOWN,
|
|
135
|
+
parentRoot,
|
|
136
|
+
slot: blockHeader.slot,
|
|
137
|
+
});
|
|
138
|
+
});
|
|
128
139
|
|
|
129
140
|
if (proposerIndex !== expectedProposerIndex) {
|
|
130
141
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
@@ -137,9 +148,8 @@ export async function validateGossipFuluDataColumnSidecar(
|
|
|
137
148
|
// 5) [REJECT] The proposer signature of sidecar.signed_block_header, is valid with respect to the block_header.proposer_index pubkey.
|
|
138
149
|
const signature = dataColumnSidecar.signedBlockHeader.signature;
|
|
139
150
|
if (!chain.seenBlockInputCache.isVerifiedProposerSignature(blockHeader.slot, blockRootHex, signature)) {
|
|
140
|
-
const signatureSet =
|
|
151
|
+
const signatureSet = getBlockHeaderProposerSignatureSetByHeaderSlot(
|
|
141
152
|
chain.config,
|
|
142
|
-
blockState.slot,
|
|
143
153
|
dataColumnSidecar.signedBlockHeader
|
|
144
154
|
);
|
|
145
155
|
|
|
@@ -1179,6 +1179,10 @@ export function createLodestarMetrics(
|
|
|
1179
1179
|
name: "lodestar_oppool_proposer_slashing_pool_size",
|
|
1180
1180
|
help: "Current size of the ProposerSlashingPool",
|
|
1181
1181
|
}),
|
|
1182
|
+
proposerSlashingsProduced: register.counter({
|
|
1183
|
+
name: "lodestar_oppool_proposer_slashings_produced_total",
|
|
1184
|
+
help: "Total number of proposer slashings produced from observed equivocations",
|
|
1185
|
+
}),
|
|
1182
1186
|
voluntaryExitPoolSize: register.gauge({
|
|
1183
1187
|
name: "lodestar_oppool_voluntary_exit_pool_size",
|
|
1184
1188
|
help: "Current size of the VoluntaryExitPool",
|
|
@@ -1708,6 +1712,41 @@ export function createLodestarMetrics(
|
|
|
1708
1712
|
}),
|
|
1709
1713
|
},
|
|
1710
1714
|
|
|
1715
|
+
// Pre-verify builder-deposit signatures in the epochs before the Gloas fork (prepareNextSlot).
|
|
1716
|
+
builderDepositPreVerify: {
|
|
1717
|
+
duration: register.histogram({
|
|
1718
|
+
name: "lodestar_builder_deposit_preverify_duration_seconds",
|
|
1719
|
+
help: "Duration of one preVerifyBuilderDepositsPreGloas call (BLS batch verify + scan)",
|
|
1720
|
+
buckets: [1, 2, 3, 4],
|
|
1721
|
+
}),
|
|
1722
|
+
pendingDeposits: register.gauge({
|
|
1723
|
+
name: "lodestar_builder_deposit_preverify_pending_deposits",
|
|
1724
|
+
help: "Current state.pendingDeposits length (backlog to drain before the fork)",
|
|
1725
|
+
}),
|
|
1726
|
+
cachedDeposits: register.gauge({
|
|
1727
|
+
name: "lodestar_builder_deposit_preverify_cached_deposits",
|
|
1728
|
+
help: "Deposit signatures verified & cached so far this pre-fork window (valid + invalid)",
|
|
1729
|
+
}),
|
|
1730
|
+
scannedDeposits: register.gauge({
|
|
1731
|
+
name: "lodestar_builder_deposit_preverify_scanned_deposits",
|
|
1732
|
+
help: "Pending deposits examined by the last pre-verify call (< pending_deposits ⇒ cap hit)",
|
|
1733
|
+
}),
|
|
1734
|
+
builderPubkeys: register.gauge({
|
|
1735
|
+
name: "lodestar_builder_deposit_preverify_builder_pubkeys",
|
|
1736
|
+
help: "Distinct builder pubkeys tracked this window (validator deposits for these are pre-verified)",
|
|
1737
|
+
}),
|
|
1738
|
+
validSignatures: register.counter<{type: "builder" | "validator"}>({
|
|
1739
|
+
name: "lodestar_builder_deposit_preverify_valid_signatures_total",
|
|
1740
|
+
help: "Cumulative deposit signatures whose BLS verification passed (VALID), by credential type",
|
|
1741
|
+
labelNames: ["type"],
|
|
1742
|
+
}),
|
|
1743
|
+
invalidSignatures: register.counter<{type: "builder" | "validator"}>({
|
|
1744
|
+
name: "lodestar_builder_deposit_preverify_invalid_signatures_total",
|
|
1745
|
+
help: "Cumulative deposit signatures whose BLS verification failed (INVALID), by credential type",
|
|
1746
|
+
labelNames: ["type"],
|
|
1747
|
+
}),
|
|
1748
|
+
},
|
|
1749
|
+
|
|
1711
1750
|
// reprocess attestations
|
|
1712
1751
|
reprocessApiAttestations: {
|
|
1713
1752
|
total: register.gauge({
|
|
@@ -70,6 +70,15 @@ export type BaseNetworkInit = {
|
|
|
70
70
|
initialCustodyGroupCount: number;
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
+
/** Counts of what is still keeping this thread's event loop alive, e.g. `TCPWrap=3,Timeout=1` */
|
|
74
|
+
function formatActiveResources(): string {
|
|
75
|
+
const counts = new Map<string, number>();
|
|
76
|
+
for (const resource of process.getActiveResourcesInfo()) {
|
|
77
|
+
counts.set(resource, (counts.get(resource) ?? 0) + 1);
|
|
78
|
+
}
|
|
79
|
+
return Array.from(counts, ([name, count]) => `${name}=${count}`).join(",");
|
|
80
|
+
}
|
|
81
|
+
|
|
73
82
|
/**
|
|
74
83
|
* This class is meant to work both:
|
|
75
84
|
* - In a libp2p worker
|
|
@@ -289,7 +298,10 @@ export class NetworkCore implements INetworkCore {
|
|
|
289
298
|
this.attnetsService.close();
|
|
290
299
|
this.syncnetsService.close();
|
|
291
300
|
await this.libp2p.stop();
|
|
292
|
-
this
|
|
301
|
+
// Diagnostic for the shutdown hang, this thread can spin in `Environment::CleanupHandles()` on
|
|
302
|
+
// a handle that never closes and `Worker.terminate()` then never resolves. Diffing this list
|
|
303
|
+
// between a clean and a stuck shutdown should narrow down which handle it is
|
|
304
|
+
this.logger.debug("network lib2p closed", {activeResources: formatActiveResources()});
|
|
293
305
|
|
|
294
306
|
this.closed = true;
|
|
295
307
|
}
|
|
@@ -10,6 +10,7 @@ import {BeaconConfig, chainConfigToJson} from "@lodestar/config";
|
|
|
10
10
|
import type {LoggerNode} from "@lodestar/logger/node";
|
|
11
11
|
import {ResponseIncoming, ResponseOutgoing} from "@lodestar/reqresp";
|
|
12
12
|
import {Status} from "@lodestar/types";
|
|
13
|
+
import {withTimeout} from "@lodestar/utils";
|
|
13
14
|
import {Metrics} from "../../metrics/index.js";
|
|
14
15
|
import {AsyncIterableBridgeCaller, AsyncIterableBridgeHandler} from "../../util/asyncIterableToEvents.js";
|
|
15
16
|
import {PeerIdStr, peerIdFromString} from "../../util/peerId.js";
|
|
@@ -58,6 +59,10 @@ type WorkerNetworkCoreModules = WorkerNetworkCoreInitModules & {
|
|
|
58
59
|
|
|
59
60
|
const NETWORK_WORKER_EXIT_TIMEOUT_MS = 1000;
|
|
60
61
|
const NETWORK_WORKER_EXIT_RETRY_COUNT = 3;
|
|
62
|
+
/** `getApi().close()` is an unbounded RPC into the worker and runs before `BeaconNode.close()`
|
|
63
|
+
* archives chain state to disk, so it is bounded here. Set well above the ~2-4s a close takes on
|
|
64
|
+
* mainnet, tripping it leaves libp2p half torn down */
|
|
65
|
+
const NETWORK_CORE_CLOSE_TIMEOUT_MS = 5000;
|
|
61
66
|
|
|
62
67
|
/**
|
|
63
68
|
* NetworkCore implementation using a Worker thread
|
|
@@ -165,15 +170,25 @@ export class WorkerNetworkCore implements INetworkCore {
|
|
|
165
170
|
|
|
166
171
|
async close(): Promise<void> {
|
|
167
172
|
this.modules.logger.debug("closing network core running in network worker");
|
|
168
|
-
|
|
173
|
+
try {
|
|
174
|
+
await withTimeout(async () => this.getApi().close(), NETWORK_CORE_CLOSE_TIMEOUT_MS);
|
|
175
|
+
} catch (e) {
|
|
176
|
+
this.modules.logger.debug("Error closing network core", {}, e as Error);
|
|
177
|
+
}
|
|
169
178
|
this.modules.logger.debug("terminating network worker");
|
|
170
|
-
await terminateWorkerThread({
|
|
179
|
+
const terminated = await terminateWorkerThread({
|
|
171
180
|
worker: this.getApi(),
|
|
172
181
|
retryCount: NETWORK_WORKER_EXIT_RETRY_COUNT,
|
|
173
182
|
retryMs: NETWORK_WORKER_EXIT_TIMEOUT_MS,
|
|
174
183
|
logger: this.modules.logger,
|
|
175
184
|
});
|
|
176
|
-
|
|
185
|
+
if (terminated) {
|
|
186
|
+
this.modules.logger.debug("terminated network worker");
|
|
187
|
+
} else {
|
|
188
|
+
// Nothing more to do, `process.exit()` joins the thread regardless so the process still waits
|
|
189
|
+
// on it. What matters is returning, so the caller can archive state and close the db
|
|
190
|
+
this.modules.logger.debug("Network worker did not terminate in time, continuing shutdown without it");
|
|
191
|
+
}
|
|
177
192
|
}
|
|
178
193
|
|
|
179
194
|
async test(): Promise<void> {
|
package/src/network/network.ts
CHANGED
|
@@ -147,6 +147,7 @@ export class Network implements INetwork {
|
|
|
147
147
|
this.chain.emitter.on(ChainEvent.updateTargetCustodyGroupCount, this.onTargetGroupCountUpdated);
|
|
148
148
|
this.chain.emitter.on(ChainEvent.publishDataColumns, this.onPublishDataColumns);
|
|
149
149
|
this.chain.emitter.on(ChainEvent.publishBlobSidecars, this.onPublishBlobSidecars);
|
|
150
|
+
this.chain.emitter.on(ChainEvent.publishProposerSlashing, this.onPublishProposerSlashing);
|
|
150
151
|
this.chain.emitter.on(ChainEvent.updateStatus, this.onUpdateStatus);
|
|
151
152
|
}
|
|
152
153
|
|
|
@@ -244,6 +245,7 @@ export class Network implements INetwork {
|
|
|
244
245
|
this.chain.emitter.off(ChainEvent.updateTargetCustodyGroupCount, this.onTargetGroupCountUpdated);
|
|
245
246
|
this.chain.emitter.off(ChainEvent.publishDataColumns, this.onPublishDataColumns);
|
|
246
247
|
this.chain.emitter.off(ChainEvent.publishBlobSidecars, this.onPublishBlobSidecars);
|
|
248
|
+
this.chain.emitter.off(ChainEvent.publishProposerSlashing, this.onPublishProposerSlashing);
|
|
247
249
|
this.chain.emitter.off(ChainEvent.updateStatus, this.onUpdateStatus);
|
|
248
250
|
await this.core.close();
|
|
249
251
|
|
|
@@ -455,7 +457,8 @@ export class Network implements INetwork {
|
|
|
455
457
|
|
|
456
458
|
return this.publishGossip<GossipType.proposer_slashing>(
|
|
457
459
|
{type: GossipType.proposer_slashing, boundary},
|
|
458
|
-
proposerSlashing
|
|
460
|
+
proposerSlashing,
|
|
461
|
+
{ignoreDuplicatePublishError: true}
|
|
459
462
|
);
|
|
460
463
|
}
|
|
461
464
|
|
|
@@ -877,6 +880,18 @@ export class Network implements INetwork {
|
|
|
877
880
|
return promiseAllMaybeAsync(sidecars.map((sidecar) => () => this.publishBlobSidecar(sidecar)));
|
|
878
881
|
};
|
|
879
882
|
|
|
883
|
+
private onPublishProposerSlashing = async (proposerSlashing: phase0.ProposerSlashing): Promise<void> => {
|
|
884
|
+
try {
|
|
885
|
+
await this.publishProposerSlashing(proposerSlashing);
|
|
886
|
+
} catch (e) {
|
|
887
|
+
this.logger.debug(
|
|
888
|
+
"Error publishing proposer slashing",
|
|
889
|
+
{proposerIndex: proposerSlashing.signedHeader1.message.proposerIndex},
|
|
890
|
+
e as Error
|
|
891
|
+
);
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
|
|
880
895
|
private onUpdateStatus = async (): Promise<void> => {
|
|
881
896
|
await this.core.updateStatus(this.chain.getStatus());
|
|
882
897
|
};
|
|
@@ -257,6 +257,13 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
|
|
|
257
257
|
chain.seenPayloadEnvelopeInputCache.prune(blockRootHex);
|
|
258
258
|
}
|
|
259
259
|
throw e;
|
|
260
|
+
} finally {
|
|
261
|
+
// The block received from the network may have established an equivocation, either by conflicting
|
|
262
|
+
// with a previously observed block root (REPEAT_PROPOSAL) or with a root observed during validation
|
|
263
|
+
const proposerIndex = signedBlock.message.proposerIndex;
|
|
264
|
+
if (chain.seenBlockProposers.isEquivocating(slot, proposerIndex)) {
|
|
265
|
+
chain.processProposerEquivocation(slot, proposerIndex);
|
|
266
|
+
}
|
|
260
267
|
}
|
|
261
268
|
}
|
|
262
269
|
|
|
@@ -33,9 +33,28 @@ export function onOutgoingReqRespError(e: RequestError, method: ReqRespMethod):
|
|
|
33
33
|
|
|
34
34
|
case RequestErrorCode.DIAL_TIMEOUT:
|
|
35
35
|
case RequestErrorCode.DIAL_ERROR:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
// `RequestError` renders `e.message` as just the error code (see `renderErrorMessage`), so the
|
|
37
|
+
// multistream "protocol selection failed" text is only on the wrapped inner error, which is
|
|
38
|
+
// available on `DIAL_ERROR` via `e.type.error` (`DIAL_TIMEOUT` carries no inner error).
|
|
39
|
+
if (
|
|
40
|
+
e.type.code === RequestErrorCode.DIAL_ERROR &&
|
|
41
|
+
e.type.error.message.includes(multiStreamSelectErrorCodes.protocolSelectionFailed)
|
|
42
|
+
) {
|
|
43
|
+
// Peer does not support the protocol, a real incompatibility rather than a transient
|
|
44
|
+
// failure, so keep the stronger penalty (Fatal for Ping, as before).
|
|
45
|
+
return method === ReqRespMethod.Ping ? PeerAction.Fatal : PeerAction.LowToleranceError;
|
|
46
|
+
}
|
|
47
|
+
switch (method) {
|
|
48
|
+
// Ping and Status are liveness probes; their dial timeouts are dominated by transient
|
|
49
|
+
// network congestion rather than peer misbehavior, so penalize leniently to avoid
|
|
50
|
+
// self-inflicted peer starvation (https://github.com/ChainSafe/lodestar/issues/9562),
|
|
51
|
+
// while still applying some penalty so genuinely dead peers eventually free the slot.
|
|
52
|
+
case ReqRespMethod.Ping:
|
|
53
|
+
case ReqRespMethod.Status:
|
|
54
|
+
return PeerAction.HighToleranceError;
|
|
55
|
+
default:
|
|
56
|
+
return PeerAction.LowToleranceError;
|
|
57
|
+
}
|
|
39
58
|
// TODO: Detect SSZDecodeError and return PeerAction.Fatal
|
|
40
59
|
|
|
41
60
|
case RequestErrorCode.RESP_TIMEOUT:
|
package/src/sync/range/batch.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {LodestarError, byteArrayEquals, prettyPrintIndices, toRootHex} from "@lo
|
|
|
5
5
|
import {isBlockInputColumns} from "../../chain/blocks/blockInput/blockInput.js";
|
|
6
6
|
import {IBlockInput} from "../../chain/blocks/blockInput/types.js";
|
|
7
7
|
import {isDaOutOfRange} from "../../chain/blocks/blockInput/utils.js";
|
|
8
|
+
import {PayloadError, PayloadErrorCode} from "../../chain/blocks/importExecutionPayload.js";
|
|
8
9
|
import {PayloadEnvelopeInput} from "../../chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.js";
|
|
9
10
|
import {BlockError, BlockErrorCode} from "../../chain/errors/index.js";
|
|
10
11
|
import {ZERO_HASH} from "../../constants/constants.js";
|
|
@@ -592,7 +593,7 @@ export class Batch {
|
|
|
592
593
|
if (allComplete) {
|
|
593
594
|
const attempt: Attempt = {
|
|
594
595
|
peers: this.getSuccessfulPeers(),
|
|
595
|
-
hash: hashBlocks(blocks,
|
|
596
|
+
hash: hashBlocks(blocks, payloadEnvelopes),
|
|
596
597
|
};
|
|
597
598
|
this.state = {status: BatchStatus.AwaitingProcessing, blocks, payloadEnvelopes: newPayloadEnvelopes, attempt};
|
|
598
599
|
} else {
|
|
@@ -702,7 +703,7 @@ export class Batch {
|
|
|
702
703
|
throw new BatchError(this.wrongStatusErrorType(BatchStatus.Processing));
|
|
703
704
|
}
|
|
704
705
|
|
|
705
|
-
if (err
|
|
706
|
+
if (isExecutionEngineError(err)) {
|
|
706
707
|
this.onExecutionEngineError(this.state.attempt);
|
|
707
708
|
} else {
|
|
708
709
|
this.onProcessingError(this.state.attempt);
|
|
@@ -717,7 +718,7 @@ export class Batch {
|
|
|
717
718
|
throw new BatchError(this.wrongStatusErrorType(BatchStatus.AwaitingValidation));
|
|
718
719
|
}
|
|
719
720
|
|
|
720
|
-
if (err
|
|
721
|
+
if (isExecutionEngineError(err)) {
|
|
721
722
|
this.onExecutionEngineError(this.state.attempt);
|
|
722
723
|
} else {
|
|
723
724
|
this.onProcessingError(this.state.attempt);
|
|
@@ -787,3 +788,19 @@ type BatchErrorMetadata = {
|
|
|
787
788
|
};
|
|
788
789
|
|
|
789
790
|
export class BatchError extends LodestarError<BatchErrorType & BatchErrorMetadata> {}
|
|
791
|
+
|
|
792
|
+
function isExecutionEngineError(err: Error): boolean {
|
|
793
|
+
if (!(err instanceof BlockError)) {
|
|
794
|
+
return false;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
if (err.type.code === BlockErrorCode.EXECUTION_ENGINE_ERROR) {
|
|
798
|
+
return true;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
return (
|
|
802
|
+
err.type.code === BlockErrorCode.BEACON_CHAIN_ERROR &&
|
|
803
|
+
err.type.error instanceof PayloadError &&
|
|
804
|
+
err.type.error.type.code === PayloadErrorCode.EXECUTION_ENGINE_ERROR
|
|
805
|
+
);
|
|
806
|
+
}
|
|
@@ -1,27 +1,62 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {RootHex,
|
|
3
|
-
import {toRootHex} from "@lodestar/utils";
|
|
1
|
+
import {digest} from "@chainsafe/as-sha256";
|
|
2
|
+
import {RootHex, Slot, ssz} from "@lodestar/types";
|
|
3
|
+
import {fromHex, toRootHex} from "@lodestar/utils";
|
|
4
4
|
import {IBlockInput} from "../../../chain/blocks/blockInput/types.js";
|
|
5
|
+
import {PayloadEnvelopeInput} from "../../../chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.js";
|
|
6
|
+
|
|
7
|
+
const ROOT_SIZE = 32;
|
|
8
|
+
const SIGNATURE_SIZE = 96;
|
|
9
|
+
/** Every block and every payload envelope contributes a fixed-size (root, signature) entry */
|
|
10
|
+
const ENTRY_SIZE = ROOT_SIZE + SIGNATURE_SIZE;
|
|
11
|
+
/** uint32 LE counts of block and envelope entries, so the variable-length sections are self-describing */
|
|
12
|
+
const COUNT_SIZE = 4;
|
|
13
|
+
const HEADER_SIZE = COUNT_SIZE * 2;
|
|
5
14
|
|
|
6
15
|
/**
|
|
7
|
-
*
|
|
16
|
+
* Root uniquely identifying a batch attempt (its blocks AND payloads). Used for peer scoring and to
|
|
17
|
+
* compare if two attempts are equivalent.
|
|
18
|
+
*
|
|
19
|
+
* Signatures are part of the id for BOTH blocks and payload envelopes, not just their message roots:
|
|
20
|
+
* a peer serving a correct message with a garbage signature would otherwise produce the same id as
|
|
21
|
+
* the honest attempt and escape scoring in `SyncChain.advanceChain`. Signatures are not verified at
|
|
22
|
+
* download time, only during processChainSegment (block signatures in verifyBlocksSignatures,
|
|
23
|
+
* envelope signatures in importExecutionPayload).
|
|
24
|
+
*
|
|
25
|
+
* Entries are written as raw bytes into a single exactly-sized buffer and digested once, so an
|
|
26
|
+
* `Attempt` retains 32 bytes rather than the ~16 KB a full 32-slot gloas batch would need if the
|
|
27
|
+
* roots and signatures were concatenated as hex. sha256 (not a 64-bit hash) because a peer that
|
|
28
|
+
* could force a collision with the winning attempt would escape peer scoring.
|
|
8
29
|
*/
|
|
9
|
-
export function hashBlocks(blocks: IBlockInput[],
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
export function hashBlocks(blocks: IBlockInput[], payloadEnvelopes: Map<Slot, PayloadEnvelopeInput> | null): RootHex {
|
|
31
|
+
// Envelopes without a payload carry no attributable data, so they are skipped entirely. A `null`
|
|
32
|
+
// map and a map whose entries all lack a payload are therefore equivalent, which is intended.
|
|
33
|
+
const envelopes =
|
|
34
|
+
payloadEnvelopes && payloadEnvelopes.size > 0
|
|
35
|
+
? Array.from(payloadEnvelopes.entries())
|
|
36
|
+
.filter(([, envelope]) => envelope.hasPayloadEnvelope())
|
|
37
|
+
.sort(([slotA], [slotB]) => slotA - slotB)
|
|
38
|
+
: [];
|
|
39
|
+
|
|
40
|
+
const buf = Buffer.allocUnsafe(HEADER_SIZE + (blocks.length + envelopes.length) * ENTRY_SIZE);
|
|
41
|
+
buf.writeUInt32LE(blocks.length, 0);
|
|
42
|
+
buf.writeUInt32LE(envelopes.length, COUNT_SIZE);
|
|
43
|
+
let offset = HEADER_SIZE;
|
|
44
|
+
|
|
45
|
+
for (const block of blocks) {
|
|
46
|
+
buf.set(fromHex(block.blockRootHex), offset);
|
|
47
|
+
offset += ROOT_SIZE;
|
|
48
|
+
buf.set(block.getBlock().signature, offset);
|
|
49
|
+
offset += SIGNATURE_SIZE;
|
|
26
50
|
}
|
|
51
|
+
|
|
52
|
+
for (const [, envelope] of envelopes) {
|
|
53
|
+
const signedEnvelope = envelope.getPayloadEnvelope();
|
|
54
|
+
// envelope's root is cached thanks to cachePermanentRootStruct, so this avoids re-hashing
|
|
55
|
+
buf.set(ssz.gloas.ExecutionPayloadEnvelope.hashTreeRoot(signedEnvelope.message), offset);
|
|
56
|
+
offset += ROOT_SIZE;
|
|
57
|
+
buf.set(signedEnvelope.signature, offset);
|
|
58
|
+
offset += SIGNATURE_SIZE;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return toRootHex(digest(buf));
|
|
27
62
|
}
|