@lodestar/beacon-node 1.46.0-dev.3d8f7cf440 → 1.46.0-dev.3e8651f2dc
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 +1 -1
- package/lib/api/impl/beacon/blocks/index.js.map +1 -1
- package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlock.js +11 -3
- 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/produceBlock/produceBlockBody.js +1 -1
- package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
- package/lib/chain/seenCache/seenBlockProposers.d.ts +8 -3
- package/lib/chain/seenCache/seenBlockProposers.d.ts.map +1 -1
- package/lib/chain/seenCache/seenBlockProposers.js +25 -11
- package/lib/chain/seenCache/seenBlockProposers.js.map +1 -1
- package/lib/chain/validation/block.d.ts.map +1 -1
- package/lib/chain/validation/block.js +8 -5
- package/lib/chain/validation/block.js.map +1 -1
- package/lib/metrics/metrics/lodestar.d.ts +1 -0
- package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
- package/lib/metrics/metrics/lodestar.js +4 -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/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 +6 -1
- package/src/chain/blocks/verifyBlock.ts +16 -6
- 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/produceBlock/produceBlockBody.ts +1 -1
- package/src/chain/seenCache/seenBlockProposers.ts +40 -14
- package/src/chain/validation/block.ts +8 -4
- package/src/metrics/metrics/lodestar.ts +4 -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/util/workerEvents.ts +18 -6
|
@@ -23,10 +23,16 @@ export declare function wireEventsOnWorkerThread<EventData>(mainEventName: strin
|
|
|
23
23
|
export declare function wireEventsOnMainThread<EventData>(mainEventName: string, events: StrictEventEmitterSingleArg<EventData>, worker: Pick<Worker, "on" | "postMessage">, metrics: Metrics | null, isWorkerToMain: {
|
|
24
24
|
[K in keyof EventData]: EventDirection;
|
|
25
25
|
}): void;
|
|
26
|
+
/**
|
|
27
|
+
* Terminate a worker thread, bounded to `retryCount * retryMs`.
|
|
28
|
+
*
|
|
29
|
+
* @returns `false` if it could not be terminated, the worker thread is then still running and the
|
|
30
|
+
* caller has to decide how to proceed without it.
|
|
31
|
+
*/
|
|
26
32
|
export declare function terminateWorkerThread({ worker, retryMs, retryCount, logger, }: {
|
|
27
33
|
worker: Thread;
|
|
28
34
|
retryMs: number;
|
|
29
35
|
retryCount: number;
|
|
30
36
|
logger?: Logger;
|
|
31
|
-
}): Promise<
|
|
37
|
+
}): Promise<boolean>;
|
|
32
38
|
//# sourceMappingURL=workerEvents.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workerEvents.d.ts","sourceRoot":"","sources":["../../src/util/workerEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,MAAM,EAAC,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAC,MAAM,EAAC,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAExC,OAAO,EAAC,OAAO,EAAC,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAC,wBAAwB,EAAC,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAC,cAAc,EAAe,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAC,2BAA2B,EAAC,MAAM,mBAAmB,CAAC;AAI9D,MAAM,MAAM,iBAAiB,CAAC,SAAS,IAAI;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,SAAS,CAAC;IACvB,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzB,IAAI,EAAE,SAAS,CAAC,MAAM,SAAS,CAAC,CAAC;CAClC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAChD,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,2BAA2B,CAAC,SAAS,CAAC,EAC9C,UAAU,EAAE,WAAW,EACvB,OAAO,EAAE,wBAAwB,GAAG,IAAI,EACxC,cAAc,EAAE;KAAE,CAAC,IA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,MAAM,SAAS,CAAC,CAAC;CAClC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAChD,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,2BAA2B,CAAC,SAAS,CAAC,EAC9C,UAAU,EAAE,WAAW,EACvB,OAAO,EAAE,wBAAwB,GAAG,IAAI,EACxC,cAAc,EAAE;KAAE,CAAC,IAAI,MAAM,SAAS,GAAG,cAAc;CAAC,GACvD,IAAI,CAuCN;AAED,wBAAgB,sBAAsB,CAAC,SAAS,EAC9C,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,2BAA2B,CAAC,SAAS,CAAC,EAC9C,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,aAAa,CAAC,EAC1C,OAAO,EAAE,OAAO,GAAG,IAAI,EACvB,cAAc,EAAE;KAAE,CAAC,IAAI,MAAM,SAAS,GAAG,cAAc;CAAC,GACvD,IAAI,CAiCN;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CAAC,EAC1C,MAAM,EACN,OAAO,EACP,UAAU,EACV,MAAM,GACP,EAAE;IACD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,OAAO,CAAC,CAyBnB"}
|
package/lib/util/workerEvents.js
CHANGED
|
@@ -70,6 +70,12 @@ export function wireEventsOnMainThread(mainEventName, events, worker, metrics, i
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Terminate a worker thread, bounded to `retryCount * retryMs`.
|
|
75
|
+
*
|
|
76
|
+
* @returns `false` if it could not be terminated, the worker thread is then still running and the
|
|
77
|
+
* caller has to decide how to proceed without it.
|
|
78
|
+
*/
|
|
73
79
|
export async function terminateWorkerThread({ worker, retryMs, retryCount, logger, }) {
|
|
74
80
|
const terminated = new Promise((resolve) => {
|
|
75
81
|
Thread.events(worker).subscribe((event) => {
|
|
@@ -79,12 +85,18 @@ export async function terminateWorkerThread({ worker, retryMs, retryCount, logge
|
|
|
79
85
|
});
|
|
80
86
|
});
|
|
81
87
|
for (let i = 0; i < retryCount; i++) {
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
// `Worker.terminate()` resolves only once the worker thread exits, and the thread can spin
|
|
89
|
+
// forever in `Environment::CleanupHandles()` when a libuv handle on its loop never closes, so
|
|
90
|
+
// it has to be raced too, otherwise `retryCount * retryMs` never applies.
|
|
91
|
+
const result = await Promise.race([
|
|
92
|
+
Thread.terminate(worker).then(() => terminated),
|
|
93
|
+
sleep(retryMs).then(() => false),
|
|
94
|
+
]);
|
|
84
95
|
if (result)
|
|
85
|
-
return;
|
|
86
|
-
logger?.
|
|
96
|
+
return true;
|
|
97
|
+
logger?.debug("Worker thread failed to terminate, retrying...");
|
|
87
98
|
}
|
|
88
|
-
|
|
99
|
+
logger?.debug(`Worker thread failed to terminate in ${retryCount * retryMs}ms`);
|
|
100
|
+
return false;
|
|
89
101
|
}
|
|
90
102
|
//# sourceMappingURL=workerEvents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workerEvents.js","sourceRoot":"","sources":["../../src/util/workerEvents.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,MAAM,EAAC,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EAAC,KAAK,EAAC,MAAM,iBAAiB,CAAC;AAGtC,OAAO,EAAC,cAAc,EAAE,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAGlE,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAStC;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CACtC,aAAqB,EACrB,MAA8C,EAC9C,UAAuB,EACvB,OAAwC,EACxC,cAAwD;IAExD,uCAAuC;IACvC,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,IAAkC,EAAE,EAAE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ACV,MAAM,GAMP;IACC,MAAM,UAAU,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QACzC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;YACxC,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;gBACjC,OAAO,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,2FAA2F;QAC3F,8FAA8F;QAC9F,0EAA0E;QAC1E,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;YAChC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC;YAC/C,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC;SACjC,CAAC,CAAC;QAEH,IAAI,MAAM;YAAE,OAAO,IAAI,CAAC;QAExB,MAAM,EAAE,KAAK,CAAC,gDAAgD,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,EAAE,KAAK,CAAC,wCAAwC,UAAU,GAAG,OAAO,IAAI,CAAC,CAAC;IAChF,OAAO,KAAK,CAAC;AACf,CAAC"}
|
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.46.0-dev.
|
|
14
|
+
"version": "1.46.0-dev.3e8651f2dc",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"@chainsafe/discv5": "^12.0.1",
|
|
106
106
|
"@chainsafe/enr": "^6.0.1",
|
|
107
107
|
"@chainsafe/libp2p-noise": "^17.0.0",
|
|
108
|
-
"@chainsafe/libp2p-quic": "^2.1.
|
|
108
|
+
"@chainsafe/libp2p-quic": "^2.1.3",
|
|
109
109
|
"@chainsafe/persistent-merkle-tree": "^1.3.0",
|
|
110
110
|
"@chainsafe/prometheus-gc-stats": "^1.0.0",
|
|
111
111
|
"@chainsafe/snappy-wasm": "^0.5.0",
|
|
@@ -126,17 +126,17 @@
|
|
|
126
126
|
"@libp2p/peer-id": "^6.0.4",
|
|
127
127
|
"@libp2p/prometheus-metrics": "^5.0.14",
|
|
128
128
|
"@libp2p/tcp": "^11.0.13",
|
|
129
|
-
"@lodestar/api": "^1.46.0-dev.
|
|
130
|
-
"@lodestar/config": "^1.46.0-dev.
|
|
131
|
-
"@lodestar/db": "^1.46.0-dev.
|
|
132
|
-
"@lodestar/fork-choice": "^1.46.0-dev.
|
|
133
|
-
"@lodestar/logger": "^1.46.0-dev.
|
|
134
|
-
"@lodestar/params": "^1.46.0-dev.
|
|
135
|
-
"@lodestar/reqresp": "^1.46.0-dev.
|
|
136
|
-
"@lodestar/state-transition": "^1.46.0-dev.
|
|
137
|
-
"@lodestar/types": "^1.46.0-dev.
|
|
138
|
-
"@lodestar/utils": "^1.46.0-dev.
|
|
139
|
-
"@lodestar/validator": "^1.46.0-dev.
|
|
129
|
+
"@lodestar/api": "^1.46.0-dev.3e8651f2dc",
|
|
130
|
+
"@lodestar/config": "^1.46.0-dev.3e8651f2dc",
|
|
131
|
+
"@lodestar/db": "^1.46.0-dev.3e8651f2dc",
|
|
132
|
+
"@lodestar/fork-choice": "^1.46.0-dev.3e8651f2dc",
|
|
133
|
+
"@lodestar/logger": "^1.46.0-dev.3e8651f2dc",
|
|
134
|
+
"@lodestar/params": "^1.46.0-dev.3e8651f2dc",
|
|
135
|
+
"@lodestar/reqresp": "^1.46.0-dev.3e8651f2dc",
|
|
136
|
+
"@lodestar/state-transition": "^1.46.0-dev.3e8651f2dc",
|
|
137
|
+
"@lodestar/types": "^1.46.0-dev.3e8651f2dc",
|
|
138
|
+
"@lodestar/utils": "^1.46.0-dev.3e8651f2dc",
|
|
139
|
+
"@lodestar/validator": "^1.46.0-dev.3e8651f2dc",
|
|
140
140
|
"@multiformats/multiaddr": "^13.0.1",
|
|
141
141
|
"datastore-core": "^11.0.2",
|
|
142
142
|
"datastore-level": "^12.0.2",
|
|
@@ -158,7 +158,7 @@
|
|
|
158
158
|
"@libp2p/interface-internal": "^3.0.13",
|
|
159
159
|
"@libp2p/logger": "^6.2.2",
|
|
160
160
|
"@libp2p/utils": "^7.0.13",
|
|
161
|
-
"@lodestar/spec-test-util": "^1.46.0-dev.
|
|
161
|
+
"@lodestar/spec-test-util": "^1.46.0-dev.3e8651f2dc",
|
|
162
162
|
"@types/js-yaml": "^4.0.5",
|
|
163
163
|
"@types/qs": "^6.9.7",
|
|
164
164
|
"@types/tmp": "^0.2.3",
|
|
@@ -175,5 +175,5 @@
|
|
|
175
175
|
"beacon",
|
|
176
176
|
"blockchain"
|
|
177
177
|
],
|
|
178
|
-
"gitHead": "
|
|
178
|
+
"gitHead": "efa50dd77363efe05773fa47bcc1e62a06bbbe50"
|
|
179
179
|
}
|
|
@@ -290,7 +290,12 @@ export function getBeaconBlockApi({
|
|
|
290
290
|
if (blockLocallyProduced) {
|
|
291
291
|
try {
|
|
292
292
|
await verifyBlockProposerSignature(chain, signedBlock, blockRoot);
|
|
293
|
-
chain.seenBlockProposers.observeBlockRoot(
|
|
293
|
+
chain.seenBlockProposers.observeBlockRoot(
|
|
294
|
+
slot,
|
|
295
|
+
signedBlock.message.proposerIndex,
|
|
296
|
+
blockRoot,
|
|
297
|
+
signedBlockToSignedHeader(config, signedBlock)
|
|
298
|
+
);
|
|
294
299
|
} catch (e) {
|
|
295
300
|
chain.logger.error(
|
|
296
301
|
"Proposer signature validation failed while publishing the block",
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import {ExecutionStatus, ProtoBlock} from "@lodestar/fork-choice";
|
|
2
2
|
import {ForkName, ForkSeq, isForkPostFulu} from "@lodestar/params";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
DataAvailabilityStatus,
|
|
5
|
+
IBeaconStateView,
|
|
6
|
+
computeEpochAtSlot,
|
|
7
|
+
signedBlockToSignedHeader,
|
|
8
|
+
} from "@lodestar/state-transition";
|
|
9
|
+
import {IndexedAttestation, Slot, deneb, ssz} from "@lodestar/types";
|
|
5
10
|
import {toRootHex} from "@lodestar/utils";
|
|
6
11
|
import {getBlobKzgCommitments} from "../../util/dataColumns.js";
|
|
7
12
|
import type {BeaconChain} from "../chain.js";
|
|
@@ -207,10 +212,15 @@ export async function verifyBlocksInEpoch(
|
|
|
207
212
|
|
|
208
213
|
if (opts.skipVerifyBlockSignatures !== true) {
|
|
209
214
|
for (const block of blocks) {
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
);
|
|
213
|
-
this.seenBlockProposers.observeBlockRoot(
|
|
215
|
+
const {slot, proposerIndex} = block.message;
|
|
216
|
+
const signedBlockHeader = signedBlockToSignedHeader(this.config, block);
|
|
217
|
+
const blockRoot = toRootHex(ssz.phase0.BeaconBlockHeader.hashTreeRoot(signedBlockHeader.message));
|
|
218
|
+
this.seenBlockProposers.observeBlockRoot(slot, proposerIndex, blockRoot, signedBlockHeader);
|
|
219
|
+
// Only produce a slashing while importing the block. A block that is verified before it is published
|
|
220
|
+
// must not be treated as equivocation evidence since it may never be seen by the network
|
|
221
|
+
if (opts.verifyOnly !== true && this.seenBlockProposers.isEquivocating(slot, proposerIndex)) {
|
|
222
|
+
this.processProposerEquivocation(slot, proposerIndex);
|
|
223
|
+
}
|
|
214
224
|
}
|
|
215
225
|
}
|
|
216
226
|
|
package/src/chain/chain.ts
CHANGED
|
@@ -130,6 +130,7 @@ import {CPStateDatastore} from "./stateCache/datastore/types.js";
|
|
|
130
130
|
import {FIFOBlockStateCache} from "./stateCache/fifoBlockStateCache.js";
|
|
131
131
|
import {PersistentCheckpointStateCache} from "./stateCache/persistentCheckpointsCache.js";
|
|
132
132
|
import {CheckpointStateCache} from "./stateCache/types.js";
|
|
133
|
+
import {validateApiProposerSlashing} from "./validation/proposerSlashing.js";
|
|
133
134
|
import {ValidatorMonitor} from "./validatorMonitor.js";
|
|
134
135
|
|
|
135
136
|
/**
|
|
@@ -200,6 +201,8 @@ export class BeaconChain implements IBeaconChain {
|
|
|
200
201
|
readonly seenAggregatedAttestations: SeenAggregatedAttestations;
|
|
201
202
|
readonly seenExecutionPayloadBids = new SeenExecutionPayloadBids();
|
|
202
203
|
readonly seenBlockProposers = new SeenBlockProposers();
|
|
204
|
+
/** Proposer indexes with an in-flight proposer slashing production */
|
|
205
|
+
private readonly producingProposerSlashing = new Set<ValidatorIndex>();
|
|
203
206
|
readonly seenSyncCommitteeMessages = new SeenSyncCommitteeMessages();
|
|
204
207
|
readonly seenContributionAndProof: SeenContributionAndProof;
|
|
205
208
|
readonly seenAttestationDatas: SeenAttestationDatas;
|
|
@@ -1163,6 +1166,63 @@ export class BeaconChain implements IBeaconChain {
|
|
|
1163
1166
|
return this.payloadEnvelopeProcessor.processPayloadEnvelopeJob(payloadInput, opts);
|
|
1164
1167
|
}
|
|
1165
1168
|
|
|
1169
|
+
processProposerEquivocation(blockSlot: Slot, proposerIndex: ValidatorIndex): void {
|
|
1170
|
+
this.produceProposerSlashing(blockSlot, proposerIndex).catch((e) => {
|
|
1171
|
+
this.logger.debug("Error producing proposer slashing", {slot: blockSlot, proposerIndex}, e as Error);
|
|
1172
|
+
});
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
/** Produce a proposer slashing from two conflicting signed block headers observed for the same slot and proposer */
|
|
1176
|
+
private async produceProposerSlashing(blockSlot: Slot, proposerIndex: ValidatorIndex): Promise<void> {
|
|
1177
|
+
if (this.opts.disableProposerSlashings === true || this.producingProposerSlashing.has(proposerIndex)) {
|
|
1178
|
+
return;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
if (this.opPool.hasSeenProposerSlashing(proposerIndex)) {
|
|
1182
|
+
this.logger.debug("Not producing proposer slashing, already in the op pool", {
|
|
1183
|
+
slot: blockSlot,
|
|
1184
|
+
proposerIndex,
|
|
1185
|
+
});
|
|
1186
|
+
return;
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
const headers = this.seenBlockProposers.getEquivocationHeaders(blockSlot, proposerIndex);
|
|
1190
|
+
if (headers === null) {
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
this.producingProposerSlashing.add(proposerIndex);
|
|
1195
|
+
try {
|
|
1196
|
+
const [header1, header2] = headers;
|
|
1197
|
+
// ProposerSlashing uses the bigint variant of the signed block header, see types package for details
|
|
1198
|
+
const proposerSlashing: phase0.ProposerSlashing = {
|
|
1199
|
+
signedHeader1: {
|
|
1200
|
+
message: {...header1.message, slot: BigInt(header1.message.slot)},
|
|
1201
|
+
signature: header1.signature,
|
|
1202
|
+
},
|
|
1203
|
+
signedHeader2: {
|
|
1204
|
+
message: {...header2.message, slot: BigInt(header2.message.slot)},
|
|
1205
|
+
signature: header2.signature,
|
|
1206
|
+
},
|
|
1207
|
+
};
|
|
1208
|
+
|
|
1209
|
+
try {
|
|
1210
|
+
await validateApiProposerSlashing(this, proposerSlashing);
|
|
1211
|
+
} catch (e) {
|
|
1212
|
+
this.logger.debug("Produced proposer slashing is not valid", {slot: blockSlot, proposerIndex}, e as Error);
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
this.opPool.insertProposerSlashing(proposerSlashing);
|
|
1217
|
+
this.emitter.emit(routes.events.EventType.proposerSlashing, proposerSlashing);
|
|
1218
|
+
this.emitter.emit(ChainEvent.publishProposerSlashing, proposerSlashing);
|
|
1219
|
+
this.metrics?.opPool.proposerSlashingsProduced.inc();
|
|
1220
|
+
this.logger.info("Produced proposer slashing from observed equivocation", {slot: blockSlot, proposerIndex});
|
|
1221
|
+
} finally {
|
|
1222
|
+
this.producingProposerSlashing.delete(proposerIndex);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1166
1226
|
getStatus(): Status {
|
|
1167
1227
|
const head = this.forkChoice.getHead();
|
|
1168
1228
|
const finalizedCheckpoint = this.forkChoice.getFinalizedCheckpoint();
|
package/src/chain/emitter.ts
CHANGED
|
@@ -50,6 +50,11 @@ export enum ChainEvent {
|
|
|
50
50
|
* and are ready to be published.
|
|
51
51
|
*/
|
|
52
52
|
publishBlobSidecars = "publishBlobSidecars",
|
|
53
|
+
/**
|
|
54
|
+
* This event signals that a proposer slashing has been produced from an observed equivocation
|
|
55
|
+
* and is ready to be published.
|
|
56
|
+
*/
|
|
57
|
+
publishProposerSlashing = "publishProposerSlashing",
|
|
53
58
|
/**
|
|
54
59
|
* Trigger an update of status so reqresp by peers have current earliestAvailableSlot
|
|
55
60
|
*/
|
|
@@ -110,6 +115,8 @@ export type IChainEvents = ApiEvents & {
|
|
|
110
115
|
|
|
111
116
|
[ChainEvent.publishBlobSidecars]: (sidecars: deneb.BlobSidecar[]) => void;
|
|
112
117
|
|
|
118
|
+
[ChainEvent.publishProposerSlashing]: (proposerSlashing: phase0.ProposerSlashing) => void;
|
|
119
|
+
|
|
113
120
|
[ChainEvent.updateStatus]: () => void;
|
|
114
121
|
|
|
115
122
|
// Sync events that are chain->chain. Initiated from network requests but do not cross the network
|
package/src/chain/interface.ts
CHANGED
|
@@ -262,6 +262,9 @@ export interface IBeaconChain {
|
|
|
262
262
|
/** Process execution payload envelope: verify, import to fork choice, and persist to DB */
|
|
263
263
|
processExecutionPayload(payloadInput: PayloadEnvelopeInput, opts?: ImportPayloadOpts): Promise<void>;
|
|
264
264
|
|
|
265
|
+
/** Produce and publish a proposer slashing from an observed equivocation. Does not throw, only logs errors */
|
|
266
|
+
processProposerEquivocation(blockSlot: Slot, proposerIndex: ValidatorIndex): void;
|
|
267
|
+
|
|
265
268
|
getStatus(): Status;
|
|
266
269
|
|
|
267
270
|
recomputeForkChoiceHead(caller: ForkchoiceCaller): ProtoBlock;
|
package/src/chain/options.ts
CHANGED
|
@@ -37,6 +37,8 @@ export type IChainOptions = BlockProcessOpts &
|
|
|
37
37
|
suggestedFeeRecipient: string;
|
|
38
38
|
graffitiAppend?: boolean;
|
|
39
39
|
maxSkipSlots?: number;
|
|
40
|
+
/** Do not produce proposer slashings from observed equivocations and do not include proposer slashings in produced blocks */
|
|
41
|
+
disableProposerSlashings?: boolean;
|
|
40
42
|
/** Ensure blobs returned by the execution engine are valid */
|
|
41
43
|
sanityCheckExecutionEngineBlobs?: boolean;
|
|
42
44
|
/** Max number of produced blobs by local validators to cache */
|
|
@@ -122,6 +124,7 @@ export const defaultChainOptions: IChainOptions = {
|
|
|
122
124
|
// for gossip block validation, it's unlikely we see a reorg with 32 slots
|
|
123
125
|
// for attestation validation, having this value ensures we don't have to regen states most of the time
|
|
124
126
|
maxSkipSlots: 32,
|
|
127
|
+
disableProposerSlashings: false,
|
|
125
128
|
broadcastValidationStrictness: "warn",
|
|
126
129
|
// should be less than or equal to MIN_SIGNATURE_SETS_TO_BATCH_VERIFY
|
|
127
130
|
// batching too much may block the I/O thread so if useWorker=false, suggest this value to be 32
|
|
@@ -1042,7 +1042,7 @@ export async function produceCommonBlockBody<T extends BlockType>(
|
|
|
1042
1042
|
graffiti,
|
|
1043
1043
|
// Eth1 data voting is no longer required since electra
|
|
1044
1044
|
eth1Data: currentState.eth1Data,
|
|
1045
|
-
proposerSlashings,
|
|
1045
|
+
proposerSlashings: this.opts.disableProposerSlashings === true ? [] : proposerSlashings,
|
|
1046
1046
|
attesterSlashings,
|
|
1047
1047
|
attestations,
|
|
1048
1048
|
// Since electra, deposits are processed by the execution layer,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {computeStartSlotAtEpoch} from "@lodestar/state-transition";
|
|
2
|
-
import {Epoch, RootHex, 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
5
|
/** Two distinct block roots signed by the same proposer for the same slot are sufficient to establish an equivocation */
|
|
@@ -13,13 +13,17 @@ const MAX_BLOCK_ROOTS_PER_PROPOSAL = 2;
|
|
|
13
13
|
* equivocation evidence, but the block may still fail other validation. Such a block must not mark the proposal as
|
|
14
14
|
* known, since that would cause a later valid block for the same slot and proposer to be ignored as a repeat proposal.
|
|
15
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
|
+
*
|
|
16
19
|
* The cache is pruned on finalization and bounds the number of roots stored per proposer and slot
|
|
17
20
|
*/
|
|
18
21
|
export class SeenBlockProposers {
|
|
19
22
|
private readonly proposerIndexesBySlot = new MapDef<Slot, Set<ValidatorIndex>>(() => new Set<ValidatorIndex>());
|
|
20
|
-
private readonly
|
|
21
|
-
|
|
22
|
-
|
|
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()));
|
|
23
27
|
private finalizedSlot: Slot = 0;
|
|
24
28
|
|
|
25
29
|
isKnown(blockSlot: Slot, proposerIndex: ValidatorIndex): boolean {
|
|
@@ -27,27 +31,49 @@ export class SeenBlockProposers {
|
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
hasBlockRoot(blockSlot: Slot, proposerIndex: ValidatorIndex, blockRoot: RootHex): boolean {
|
|
30
|
-
return this.
|
|
34
|
+
return this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.has(blockRoot) === true;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
isEquivocating(blockSlot: Slot, proposerIndex: ValidatorIndex): boolean {
|
|
34
|
-
return (
|
|
38
|
+
return (
|
|
39
|
+
(this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.size ?? 0) >= MAX_BLOCK_ROOTS_PER_PROPOSAL
|
|
40
|
+
);
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
getConflictingBlockRoots(blockSlot: Slot, proposerIndex: ValidatorIndex, blockRoot: RootHex): RootHex[] {
|
|
38
|
-
const
|
|
39
|
-
return
|
|
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];
|
|
40
61
|
}
|
|
41
62
|
|
|
42
63
|
/** Record a block only after its proposer signature has been verified */
|
|
43
|
-
observeBlockRoot(
|
|
64
|
+
observeBlockRoot(
|
|
65
|
+
blockSlot: Slot,
|
|
66
|
+
proposerIndex: ValidatorIndex,
|
|
67
|
+
blockRoot: RootHex,
|
|
68
|
+
signedBlockHeader: phase0.SignedBeaconBlockHeader
|
|
69
|
+
): void {
|
|
44
70
|
if (blockSlot < this.finalizedSlot) {
|
|
45
71
|
throw Error(`blockSlot ${blockSlot} < finalizedSlot ${this.finalizedSlot}`);
|
|
46
72
|
}
|
|
47
73
|
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
50
|
-
|
|
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);
|
|
51
77
|
}
|
|
52
78
|
}
|
|
53
79
|
|
|
@@ -67,9 +93,9 @@ export class SeenBlockProposers {
|
|
|
67
93
|
this.proposerIndexesBySlot.delete(slot);
|
|
68
94
|
}
|
|
69
95
|
}
|
|
70
|
-
for (const slot of this.
|
|
96
|
+
for (const slot of this.signedBlockHeadersBySlot.keys()) {
|
|
71
97
|
if (slot < finalizedSlot) {
|
|
72
|
-
this.
|
|
98
|
+
this.signedBlockHeadersBySlot.delete(slot);
|
|
73
99
|
}
|
|
74
100
|
}
|
|
75
101
|
}
|
|
@@ -23,8 +23,9 @@ import {
|
|
|
23
23
|
getBlockProposerSignatureSet,
|
|
24
24
|
isExecutionBlockBodyType,
|
|
25
25
|
isStatePostBellatrix,
|
|
26
|
+
signedBlockToSignedHeader,
|
|
26
27
|
} from "@lodestar/state-transition";
|
|
27
|
-
import {RootHex, 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
|
}
|
|
@@ -89,7 +93,7 @@ export async function validateGossipBlock(
|
|
|
89
93
|
if (chain.seenBlockProposers.isKnown(blockSlot, proposerIndex)) {
|
|
90
94
|
if (!hasBlockRoot && !chain.seenBlockProposers.isEquivocating(blockSlot, proposerIndex)) {
|
|
91
95
|
await verifyBlockProposerSignature(chain, signedBlock, blockRoot, {verifyOnMainThread: false});
|
|
92
|
-
chain.seenBlockProposers.observeBlockRoot(blockSlot, proposerIndex, blockRoot);
|
|
96
|
+
chain.seenBlockProposers.observeBlockRoot(blockSlot, proposerIndex, blockRoot, signedBlockHeader);
|
|
93
97
|
}
|
|
94
98
|
throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.REPEAT_PROPOSAL, proposerIndex});
|
|
95
99
|
}
|
|
@@ -276,7 +280,7 @@ export async function validateGossipBlock(
|
|
|
276
280
|
|
|
277
281
|
// [REJECT] The proposer signature, signed_beacon_block.signature, is valid with respect to the proposer_index pubkey.
|
|
278
282
|
await verifyBlockProposerSignature(chain, signedBlock, blockRoot);
|
|
279
|
-
chain.seenBlockProposers.observeBlockRoot(blockSlot, proposerIndex, blockRoot);
|
|
283
|
+
chain.seenBlockProposers.observeBlockRoot(blockSlot, proposerIndex, blockRoot, signedBlockHeader);
|
|
280
284
|
|
|
281
285
|
// [REJECT] The block is proposed by the expected proposer_index for the block's slot in the context of the current
|
|
282
286
|
// shuffling (defined by parent_root/slot). If the proposer_index cannot immediately be verified against the expected
|
|
@@ -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",
|
|
@@ -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
|
|