@aztec/validator-client 0.0.1-commit.b655e406 → 0.0.1-commit.b8a057fa
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/README.md +327 -0
- package/dest/checkpoint_builder.d.ts +81 -0
- package/dest/checkpoint_builder.d.ts.map +1 -0
- package/dest/checkpoint_builder.js +259 -0
- package/dest/config.d.ts +9 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +60 -13
- package/dest/duties/validation_service.d.ts +44 -16
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +104 -34
- package/dest/factory.d.ts +22 -11
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +19 -6
- package/dest/index.d.ts +3 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -1
- package/dest/key_store/ha_key_store.d.ts +99 -0
- package/dest/key_store/ha_key_store.d.ts.map +1 -0
- package/dest/key_store/ha_key_store.js +208 -0
- package/dest/key_store/index.d.ts +2 -1
- package/dest/key_store/index.d.ts.map +1 -1
- package/dest/key_store/index.js +1 -0
- package/dest/key_store/interface.d.ts +36 -6
- package/dest/key_store/interface.d.ts.map +1 -1
- package/dest/key_store/local_key_store.d.ts +10 -5
- package/dest/key_store/local_key_store.d.ts.map +1 -1
- package/dest/key_store/local_key_store.js +9 -5
- package/dest/key_store/node_keystore_adapter.d.ts +18 -5
- package/dest/key_store/node_keystore_adapter.d.ts.map +1 -1
- package/dest/key_store/node_keystore_adapter.js +18 -4
- package/dest/key_store/web3signer_key_store.d.ts +13 -6
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
- package/dest/key_store/web3signer_key_store.js +41 -46
- package/dest/metrics.d.ts +16 -3
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +58 -30
- package/dest/proposal_handler.d.ts +165 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +1207 -0
- package/dest/validator.d.ts +94 -25
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +534 -95
- package/package.json +24 -14
- package/src/checkpoint_builder.ts +426 -0
- package/src/config.ts +68 -14
- package/src/duties/validation_service.ts +170 -46
- package/src/factory.ts +46 -12
- package/src/index.ts +2 -1
- package/src/key_store/ha_key_store.ts +269 -0
- package/src/key_store/index.ts +1 -0
- package/src/key_store/interface.ts +44 -5
- package/src/key_store/local_key_store.ts +14 -5
- package/src/key_store/node_keystore_adapter.ts +28 -5
- package/src/key_store/web3signer_key_store.ts +61 -64
- package/src/metrics.ts +81 -33
- package/src/proposal_handler.ts +1314 -0
- package/src/validator.ts +762 -142
- package/dest/block_proposal_handler.d.ts +0 -52
- package/dest/block_proposal_handler.d.ts.map +0 -1
- package/dest/block_proposal_handler.js +0 -286
- package/src/block_proposal_handler.ts +0 -343
package/src/validator.ts
CHANGED
|
@@ -1,42 +1,82 @@
|
|
|
1
|
+
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
2
|
+
import { type Blob, getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
1
3
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
4
|
+
import { CheckpointNumber, EpochNumber, IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
6
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
7
|
+
import { Signature } from '@aztec/foundation/eth-signature';
|
|
8
|
+
import { FifoSet } from '@aztec/foundation/fifo-set';
|
|
9
|
+
import { type LogData, type Logger, createLogger } from '@aztec/foundation/log';
|
|
6
10
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
7
11
|
import { sleep } from '@aztec/foundation/sleep';
|
|
8
12
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
9
13
|
import type { KeystoreManager } from '@aztec/node-keystore';
|
|
10
|
-
import type { P2P, PeerId
|
|
14
|
+
import type { DuplicateAttestationInfo, DuplicateProposalInfo, OversizedProposalInfo, P2P, PeerId } from '@aztec/p2p';
|
|
11
15
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
12
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
OffenseType,
|
|
18
|
+
WANT_TO_CLEAR_SLASH_EVENT,
|
|
19
|
+
WANT_TO_SLASH_EVENT,
|
|
20
|
+
type Watcher,
|
|
21
|
+
type WatcherEmitter,
|
|
22
|
+
getOffenseTypeName,
|
|
23
|
+
} from '@aztec/slasher';
|
|
13
24
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
14
|
-
import type { CommitteeAttestationsAndSigners, L2BlockSource } from '@aztec/stdlib/block';
|
|
15
|
-
import type {
|
|
25
|
+
import type { CommitteeAttestationsAndSigners, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
26
|
+
import type { CheckpointReexecutionTracker } from '@aztec/stdlib/checkpoint';
|
|
27
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
28
|
+
import type {
|
|
29
|
+
ITxProvider,
|
|
30
|
+
Validator,
|
|
31
|
+
ValidatorClientFullConfig,
|
|
32
|
+
WorldStateSynchronizer,
|
|
33
|
+
} from '@aztec/stdlib/interfaces/server';
|
|
16
34
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
17
|
-
import
|
|
35
|
+
import {
|
|
36
|
+
type BlockProposal,
|
|
37
|
+
type BlockProposalOptions,
|
|
38
|
+
CheckpointAttestation,
|
|
39
|
+
CheckpointProposal,
|
|
40
|
+
type CheckpointProposalCore,
|
|
41
|
+
type CheckpointProposalOptions,
|
|
42
|
+
type CoordinationSignatureContext,
|
|
43
|
+
} from '@aztec/stdlib/p2p';
|
|
18
44
|
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
19
|
-
import
|
|
45
|
+
import { ConsensusTimetable } from '@aztec/stdlib/timetable';
|
|
46
|
+
import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
|
|
20
47
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
21
48
|
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
49
|
+
import {
|
|
50
|
+
createHASigner,
|
|
51
|
+
createLocalSignerWithProtection,
|
|
52
|
+
createSignerFromSharedDb,
|
|
53
|
+
} from '@aztec/validator-ha-signer/factory';
|
|
54
|
+
import { DutyType, type SigningContext, type SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
55
|
+
import type { ValidatorHASigner } from '@aztec/validator-ha-signer/validator-ha-signer';
|
|
22
56
|
|
|
23
57
|
import { EventEmitter } from 'events';
|
|
24
58
|
import type { TypedDataDefinition } from 'viem';
|
|
25
59
|
|
|
26
|
-
import {
|
|
60
|
+
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
61
|
+
import { DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS } from './config.js';
|
|
27
62
|
import { ValidationService } from './duties/validation_service.js';
|
|
63
|
+
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
64
|
+
import type { ExtendedValidatorKeyStore } from './key_store/interface.js';
|
|
28
65
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
29
66
|
import { ValidatorMetrics } from './metrics.js';
|
|
67
|
+
import {
|
|
68
|
+
type BlockProposalValidationFailureReason,
|
|
69
|
+
type CheckpointProposalValidationFailureResult,
|
|
70
|
+
ProposalHandler,
|
|
71
|
+
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT,
|
|
72
|
+
SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT,
|
|
73
|
+
} from './proposal_handler.js';
|
|
30
74
|
|
|
31
75
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
32
76
|
// Just cap the set to avoid unbounded growth.
|
|
33
77
|
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT: BlockProposalValidationFailureReason[] = [
|
|
37
|
-
'state_mismatch',
|
|
38
|
-
'failed_txs',
|
|
39
|
-
];
|
|
78
|
+
const MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS = 1000;
|
|
79
|
+
const MAX_TRACKED_BAD_ATTESTATIONS = 10_000;
|
|
40
80
|
|
|
41
81
|
/**
|
|
42
82
|
* Validator Client
|
|
@@ -45,37 +85,64 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
45
85
|
public readonly tracer: Tracer;
|
|
46
86
|
private validationService: ValidationService;
|
|
47
87
|
private metrics: ValidatorMetrics;
|
|
48
|
-
|
|
88
|
+
private log: Logger;
|
|
49
89
|
// Whether it has already registered handlers on the p2p client
|
|
50
90
|
private hasRegisteredHandlers = false;
|
|
51
91
|
|
|
52
|
-
|
|
53
|
-
private
|
|
92
|
+
/** Tracks the last block proposal we created, to detect duplicate proposal attempts. */
|
|
93
|
+
private lastProposedBlock?: BlockProposal;
|
|
54
94
|
|
|
55
|
-
|
|
95
|
+
/** Tracks the last checkpoint proposal we created. */
|
|
96
|
+
private lastProposedCheckpoint?: CheckpointProposal;
|
|
97
|
+
|
|
98
|
+
private lastEpochForCommitteeUpdateLoop: EpochNumber | undefined;
|
|
56
99
|
private epochCacheUpdateLoop: RunningPromise;
|
|
100
|
+
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */
|
|
101
|
+
private lastAttestedEpochByAttester: Map<string, EpochNumber> = new Map();
|
|
102
|
+
|
|
103
|
+
private proposersOfInvalidBlocks = FifoSet.withLimit<string>(MAX_PROPOSERS_OF_INVALID_BLOCKS);
|
|
104
|
+
private invalidCheckpointProposalOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS);
|
|
105
|
+
private oversizedProposalOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS);
|
|
106
|
+
private badAttestationOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_BAD_ATTESTATIONS);
|
|
57
107
|
|
|
58
|
-
|
|
108
|
+
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */
|
|
109
|
+
private lastAttestedProposal?: CheckpointProposalCore;
|
|
59
110
|
|
|
60
111
|
protected constructor(
|
|
61
|
-
private keyStore:
|
|
112
|
+
private keyStore: ExtendedValidatorKeyStore,
|
|
62
113
|
private epochCache: EpochCache,
|
|
63
114
|
private p2pClient: P2P,
|
|
64
|
-
private
|
|
115
|
+
private proposalHandler: ProposalHandler,
|
|
116
|
+
private blockSource: L2BlockSource,
|
|
117
|
+
private checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
118
|
+
private worldState: WorldStateSynchronizer,
|
|
119
|
+
private l1ToL2MessageSource: L1ToL2MessageSource,
|
|
65
120
|
private config: ValidatorClientFullConfig,
|
|
121
|
+
private blobClient: BlobClientInterface,
|
|
122
|
+
private slashingProtectionSigner: ValidatorHASigner,
|
|
66
123
|
private dateProvider: DateProvider = new DateProvider(),
|
|
67
124
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
68
|
-
|
|
125
|
+
log = createLogger('validator'),
|
|
69
126
|
) {
|
|
70
127
|
super();
|
|
128
|
+
|
|
129
|
+
// Create child logger with fisherman prefix if in fisherman mode
|
|
130
|
+
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
131
|
+
|
|
71
132
|
this.tracer = telemetry.getTracer('Validator');
|
|
72
133
|
this.metrics = new ValidatorMetrics(telemetry);
|
|
73
134
|
|
|
74
|
-
this.validationService = new ValidationService(
|
|
135
|
+
this.validationService = new ValidationService(
|
|
136
|
+
keyStore,
|
|
137
|
+
this.getSignatureContext(),
|
|
138
|
+
this.log.createChild('validation-service'),
|
|
139
|
+
);
|
|
140
|
+
this.proposalHandler.setCheckpointProposalValidationFailureCallback((proposal, result, proposalInfo) =>
|
|
141
|
+
this.handleInvalidCheckpointProposal(proposal, result, proposalInfo),
|
|
142
|
+
);
|
|
75
143
|
|
|
76
144
|
// Refresh epoch cache every second to trigger alert if participation in committee changes
|
|
77
|
-
this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), log, 1000);
|
|
78
|
-
|
|
145
|
+
this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
|
|
79
146
|
const myAddresses = this.getValidatorAddresses();
|
|
80
147
|
this.log.verbose(`Initialized validator with addresses: ${myAddresses.map(a => a.toString()).join(', ')}`);
|
|
81
148
|
}
|
|
@@ -112,6 +179,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
112
179
|
this.log.trace(`No committee found for slot`);
|
|
113
180
|
return;
|
|
114
181
|
}
|
|
182
|
+
this.metrics.setCurrentEpoch(epoch);
|
|
115
183
|
if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
|
|
116
184
|
const me = this.getValidatorAddresses();
|
|
117
185
|
const committeeSet = new Set(committee.map(v => v.toString()));
|
|
@@ -132,40 +200,97 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
132
200
|
}
|
|
133
201
|
}
|
|
134
202
|
|
|
135
|
-
static new(
|
|
203
|
+
static async new(
|
|
136
204
|
config: ValidatorClientFullConfig,
|
|
137
|
-
|
|
205
|
+
checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
206
|
+
worldState: WorldStateSynchronizer,
|
|
138
207
|
epochCache: EpochCache,
|
|
139
208
|
p2pClient: P2P,
|
|
140
|
-
blockSource: L2BlockSource,
|
|
209
|
+
blockSource: L2BlockSource & L2BlockSink,
|
|
141
210
|
l1ToL2MessageSource: L1ToL2MessageSource,
|
|
142
|
-
txProvider:
|
|
211
|
+
txProvider: ITxProvider,
|
|
143
212
|
keyStoreManager: KeystoreManager,
|
|
213
|
+
blobClient: BlobClientInterface,
|
|
214
|
+
reexecutionTracker: CheckpointReexecutionTracker,
|
|
144
215
|
dateProvider: DateProvider = new DateProvider(),
|
|
145
216
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
217
|
+
slashingProtectionDb?: SlashingProtectionDatabase,
|
|
146
218
|
) {
|
|
147
219
|
const metrics = new ValidatorMetrics(telemetry);
|
|
148
|
-
const
|
|
220
|
+
const consensusTimetable = new ConsensusTimetable({
|
|
221
|
+
l1Constants: epochCache.getL1Constants(),
|
|
222
|
+
blockDuration: config.blockDurationMs / 1000,
|
|
223
|
+
});
|
|
224
|
+
const blockProposalValidator = new BlockProposalValidator(epochCache, consensusTimetable, {
|
|
149
225
|
txsPermitted: !config.disableTransactions,
|
|
226
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock,
|
|
227
|
+
maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
|
|
228
|
+
skipSlotValidation: config.skipProposalSlotValidation,
|
|
229
|
+
signatureContext: {
|
|
230
|
+
chainId: config.l1ChainId,
|
|
231
|
+
rollupAddress: config.rollupAddress,
|
|
232
|
+
},
|
|
233
|
+
clockDisparityMs: config.maxGossipClockDisparityMs ?? DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS,
|
|
150
234
|
});
|
|
151
|
-
const
|
|
152
|
-
|
|
235
|
+
const proposalHandler = new ProposalHandler(
|
|
236
|
+
checkpointsBuilder,
|
|
237
|
+
worldState,
|
|
153
238
|
blockSource,
|
|
154
239
|
l1ToL2MessageSource,
|
|
155
240
|
txProvider,
|
|
156
241
|
blockProposalValidator,
|
|
242
|
+
epochCache,
|
|
243
|
+
consensusTimetable,
|
|
157
244
|
config,
|
|
245
|
+
blobClient,
|
|
246
|
+
reexecutionTracker,
|
|
158
247
|
metrics,
|
|
159
248
|
dateProvider,
|
|
160
249
|
telemetry,
|
|
250
|
+
undefined,
|
|
161
251
|
);
|
|
162
252
|
|
|
253
|
+
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
254
|
+
let slashingProtectionSigner: ValidatorHASigner;
|
|
255
|
+
if (slashingProtectionDb) {
|
|
256
|
+
// Shared database mode: use a pre-existing database (e.g. for testing HA setups).
|
|
257
|
+
({ signer: slashingProtectionSigner } = createSignerFromSharedDb(slashingProtectionDb, config, {
|
|
258
|
+
telemetryClient: telemetry,
|
|
259
|
+
dateProvider,
|
|
260
|
+
}));
|
|
261
|
+
} else if (config.haSigningEnabled) {
|
|
262
|
+
// Multi-node HA mode: use PostgreSQL-backed distributed locking.
|
|
263
|
+
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
264
|
+
const haConfig = {
|
|
265
|
+
...config,
|
|
266
|
+
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000,
|
|
267
|
+
};
|
|
268
|
+
({ signer: slashingProtectionSigner } = await createHASigner(haConfig, {
|
|
269
|
+
telemetryClient: telemetry,
|
|
270
|
+
dateProvider,
|
|
271
|
+
}));
|
|
272
|
+
} else {
|
|
273
|
+
// Single-node mode: use LMDB-backed local signing protection.
|
|
274
|
+
// This prevents double-signing if the node crashes and restarts mid-proposal.
|
|
275
|
+
({ signer: slashingProtectionSigner } = await createLocalSignerWithProtection(config, {
|
|
276
|
+
telemetryClient: telemetry,
|
|
277
|
+
dateProvider,
|
|
278
|
+
}));
|
|
279
|
+
}
|
|
280
|
+
const validatorKeyStore: ExtendedValidatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
|
|
281
|
+
|
|
163
282
|
const validator = new ValidatorClient(
|
|
164
|
-
|
|
283
|
+
validatorKeyStore,
|
|
165
284
|
epochCache,
|
|
166
285
|
p2pClient,
|
|
167
|
-
|
|
286
|
+
proposalHandler,
|
|
287
|
+
blockSource,
|
|
288
|
+
checkpointsBuilder,
|
|
289
|
+
worldState,
|
|
290
|
+
l1ToL2MessageSource,
|
|
168
291
|
config,
|
|
292
|
+
blobClient,
|
|
293
|
+
slashingProtectionSigner,
|
|
169
294
|
dateProvider,
|
|
170
295
|
telemetry,
|
|
171
296
|
);
|
|
@@ -179,22 +304,19 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
179
304
|
.filter(addr => !this.config.disabledValidators.some(disabled => disabled.equals(addr)));
|
|
180
305
|
}
|
|
181
306
|
|
|
182
|
-
public
|
|
183
|
-
return this.
|
|
307
|
+
public getProposalHandler() {
|
|
308
|
+
return this.proposalHandler;
|
|
184
309
|
}
|
|
185
310
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
proposal: BlockProposal,
|
|
189
|
-
blockNumber: number,
|
|
190
|
-
txs: any[],
|
|
191
|
-
l1ToL2Messages: Fr[],
|
|
192
|
-
): Promise<any> {
|
|
193
|
-
return this.blockProposalHandler.reexecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages);
|
|
311
|
+
public signWithAddress(addr: EthAddress, msg: TypedDataDefinition, context: SigningContext) {
|
|
312
|
+
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
194
313
|
}
|
|
195
314
|
|
|
196
|
-
|
|
197
|
-
return
|
|
315
|
+
private getSignatureContext(): CoordinationSignatureContext {
|
|
316
|
+
return {
|
|
317
|
+
chainId: this.config.l1ChainId,
|
|
318
|
+
rollupAddress: this.config.rollupAddress,
|
|
319
|
+
};
|
|
198
320
|
}
|
|
199
321
|
|
|
200
322
|
public getCoinbaseForAttestor(attestor: EthAddress): EthAddress {
|
|
@@ -209,8 +331,27 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
209
331
|
return this.config;
|
|
210
332
|
}
|
|
211
333
|
|
|
334
|
+
public hasProposalEquivocation(slotNumber: SlotNumber): boolean {
|
|
335
|
+
return this.proposalHandler.hasProposalEquivocation(slotNumber);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
public hasInvalidProposals(slotNumber: SlotNumber): boolean {
|
|
339
|
+
return this.proposalHandler.hasInvalidProposals(slotNumber);
|
|
340
|
+
}
|
|
341
|
+
|
|
212
342
|
public updateConfig(config: Partial<ValidatorClientFullConfig>) {
|
|
213
343
|
this.config = { ...this.config, ...config };
|
|
344
|
+
this.proposalHandler.updateConfig(config);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
public reloadKeystore(newManager: KeystoreManager): void {
|
|
348
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
349
|
+
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
350
|
+
this.validationService = new ValidationService(
|
|
351
|
+
this.keyStore,
|
|
352
|
+
this.getSignatureContext(),
|
|
353
|
+
this.log.createChild('validation-service'),
|
|
354
|
+
);
|
|
214
355
|
}
|
|
215
356
|
|
|
216
357
|
public async start() {
|
|
@@ -219,18 +360,15 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
219
360
|
return;
|
|
220
361
|
}
|
|
221
362
|
|
|
363
|
+
await this.keyStore.start();
|
|
364
|
+
|
|
222
365
|
await this.registerHandlers();
|
|
223
366
|
|
|
224
367
|
const myAddresses = this.getValidatorAddresses();
|
|
225
368
|
const inCommittee = await this.epochCache.filterInCommittee('now', myAddresses);
|
|
369
|
+
this.log.info(`Started validator with addresses: ${myAddresses.map(a => a.toString()).join(', ')}`);
|
|
226
370
|
if (inCommittee.length > 0) {
|
|
227
|
-
this.log.info(
|
|
228
|
-
`Started validator with addresses in current validator committee: ${inCommittee
|
|
229
|
-
.map(a => a.toString())
|
|
230
|
-
.join(', ')}`,
|
|
231
|
-
);
|
|
232
|
-
} else {
|
|
233
|
-
this.log.info(`Started validator with addresses: ${myAddresses.map(a => a.toString()).join(', ')}`);
|
|
371
|
+
this.log.info(`Addresses in current validator committee: ${inCommittee.map(a => a.toString()).join(', ')}`);
|
|
234
372
|
}
|
|
235
373
|
this.epochCacheUpdateLoop.start();
|
|
236
374
|
|
|
@@ -239,6 +377,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
239
377
|
|
|
240
378
|
public async stop() {
|
|
241
379
|
await this.epochCacheUpdateLoop.stop();
|
|
380
|
+
await this.keyStore.stop();
|
|
242
381
|
}
|
|
243
382
|
|
|
244
383
|
/** Register handlers on the p2p client */
|
|
@@ -247,9 +386,38 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
247
386
|
this.hasRegisteredHandlers = true;
|
|
248
387
|
this.log.debug(`Registering validator handlers for p2p client`);
|
|
249
388
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
389
|
+
// Block proposal handler - validates but does NOT attest (validators only attest to checkpoints)
|
|
390
|
+
const blockHandler = (block: BlockProposal, proposalSender: PeerId): Promise<boolean> =>
|
|
391
|
+
this.validateBlockProposal(block, proposalSender);
|
|
392
|
+
this.p2pClient.registerBlockProposalHandler(blockHandler);
|
|
393
|
+
|
|
394
|
+
// Checkpoint proposal handler - validates and creates attestations
|
|
395
|
+
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
396
|
+
// and processed separately via the block handler above.
|
|
397
|
+
const checkpointHandler = (
|
|
398
|
+
checkpoint: CheckpointProposalCore,
|
|
399
|
+
proposalSender: PeerId,
|
|
400
|
+
): Promise<CheckpointAttestation[] | undefined> => this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
401
|
+
this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
|
|
402
|
+
|
|
403
|
+
// Duplicate proposal handler - triggers slashing for equivocation
|
|
404
|
+
this.p2pClient.registerDuplicateProposalCallback((info: DuplicateProposalInfo) => {
|
|
405
|
+
this.handleDuplicateProposal(info);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
// Oversized proposal handler - triggers slashing for proposals beyond the per-checkpoint block limit
|
|
409
|
+
this.p2pClient.registerOversizedProposalCallback((info: OversizedProposalInfo) => {
|
|
410
|
+
this.handleOversizedProposal(info);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
// Duplicate attestation handler - triggers slashing for attestation equivocation
|
|
414
|
+
this.p2pClient.registerDuplicateAttestationCallback((info: DuplicateAttestationInfo) => {
|
|
415
|
+
this.handleDuplicateAttestation(info);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
this.p2pClient.registerCheckpointAttestationCallback((attestation: CheckpointAttestation) => {
|
|
419
|
+
this.handleCheckpointAttestation(attestation);
|
|
420
|
+
});
|
|
253
421
|
|
|
254
422
|
const myAddresses = this.getValidatorAddresses();
|
|
255
423
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
@@ -258,44 +426,53 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
258
426
|
}
|
|
259
427
|
}
|
|
260
428
|
|
|
261
|
-
|
|
262
|
-
|
|
429
|
+
/**
|
|
430
|
+
* Validate a block proposal from a peer.
|
|
431
|
+
* Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
|
|
432
|
+
* @returns true if the proposal is valid, false otherwise
|
|
433
|
+
*/
|
|
434
|
+
async validateBlockProposal(proposal: BlockProposal, proposalSender: PeerId): Promise<boolean> {
|
|
435
|
+
const slotNumber = proposal.slotNumber;
|
|
436
|
+
|
|
437
|
+
// Note: During escape hatch, we still want to "validate" proposals for observability,
|
|
438
|
+
// but we intentionally reject them and disable slashing invalid block and attestation flow.
|
|
439
|
+
const escapeHatchOpen = await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber);
|
|
440
|
+
|
|
263
441
|
const proposer = proposal.getSender();
|
|
264
442
|
|
|
265
443
|
// Reject proposals with invalid signatures
|
|
266
444
|
if (!proposer) {
|
|
267
|
-
this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
|
|
268
|
-
return
|
|
445
|
+
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
446
|
+
return false;
|
|
269
447
|
}
|
|
270
448
|
|
|
271
|
-
//
|
|
449
|
+
// Log self-proposals from HA peers (same validator key on different nodes)
|
|
450
|
+
if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
451
|
+
this.log.verbose(`Processing block proposal from HA peer for slot ${slotNumber}`, {
|
|
452
|
+
proposer: proposer.toString(),
|
|
453
|
+
slotNumber,
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// Check if we're in the committee (for metrics purposes)
|
|
272
458
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
273
459
|
const partOfCommittee = inCommittee.length > 0;
|
|
274
460
|
|
|
275
461
|
const proposalInfo = { ...proposal.toBlockInfo(), proposer: proposer.toString() };
|
|
276
|
-
this.log.info(`Received proposal for slot ${slotNumber}`, {
|
|
462
|
+
this.log.info(`Received block proposal for slot ${slotNumber}`, {
|
|
277
463
|
...proposalInfo,
|
|
278
464
|
txHashes: proposal.txHashes.map(t => t.toString()),
|
|
465
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
279
466
|
});
|
|
280
467
|
|
|
281
|
-
// Reexecute
|
|
282
|
-
|
|
283
|
-
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals } = this.config;
|
|
284
|
-
const shouldReexecute =
|
|
285
|
-
(slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute) ||
|
|
286
|
-
(partOfCommittee && validatorReexecute) ||
|
|
287
|
-
alwaysReexecuteBlockProposals;
|
|
288
|
-
|
|
289
|
-
const validationResult = await this.blockProposalHandler.handleBlockProposal(
|
|
290
|
-
proposal,
|
|
291
|
-
proposalSender,
|
|
292
|
-
!!shouldReexecute,
|
|
293
|
-
);
|
|
468
|
+
// Reexecute outside the escape hatch so slashing observers can detect invalid proposals even when penalties are 0.
|
|
469
|
+
const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !escapeHatchOpen);
|
|
294
470
|
|
|
295
471
|
if (!validationResult.isValid) {
|
|
296
|
-
this.log.warn(`Proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
297
|
-
|
|
298
472
|
const reason = validationResult.reason || 'unknown';
|
|
473
|
+
|
|
474
|
+
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
475
|
+
|
|
299
476
|
// Classify failure reason: bad proposal vs node issue
|
|
300
477
|
const badProposalReasons: BlockProposalValidationFailureReason[] = [
|
|
301
478
|
'invalid_proposal',
|
|
@@ -308,34 +485,228 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
308
485
|
if (badProposalReasons.includes(reason as BlockProposalValidationFailureReason)) {
|
|
309
486
|
this.metrics.incFailedAttestationsBadProposal(1, reason, partOfCommittee);
|
|
310
487
|
} else {
|
|
311
|
-
// Node issues so we can't
|
|
488
|
+
// Node issues so we can't validate
|
|
312
489
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
313
490
|
}
|
|
314
491
|
|
|
315
|
-
// Slash invalid block proposals (can happen even when not in committee)
|
|
316
492
|
if (
|
|
493
|
+
!escapeHatchOpen &&
|
|
317
494
|
validationResult.reason &&
|
|
318
|
-
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
|
|
319
|
-
slashBroadcastedInvalidBlockPenalty > 0n
|
|
495
|
+
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
|
|
320
496
|
) {
|
|
321
|
-
this.log.
|
|
497
|
+
this.log.info(`Detected invalid block proposal offense`, {
|
|
498
|
+
...proposalInfo,
|
|
499
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
500
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL),
|
|
501
|
+
});
|
|
322
502
|
this.slashInvalidBlock(proposal);
|
|
503
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
323
504
|
}
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
this.log.info(`Validated block proposal for slot ${slotNumber}`, {
|
|
509
|
+
...proposalInfo,
|
|
510
|
+
inCommittee: partOfCommittee,
|
|
511
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
512
|
+
escapeHatchOpen,
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
if (escapeHatchOpen) {
|
|
516
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, rejecting block proposal`, proposalInfo);
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
return true;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Validate and attest to a checkpoint proposal from a peer.
|
|
525
|
+
* The proposal is received as CheckpointProposalCore (without lastBlock) since
|
|
526
|
+
* the lastBlock is extracted and processed separately via the block handler.
|
|
527
|
+
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
528
|
+
*/
|
|
529
|
+
async attestToCheckpointProposal(
|
|
530
|
+
proposal: CheckpointProposalCore,
|
|
531
|
+
_proposalSender: PeerId,
|
|
532
|
+
): Promise<CheckpointAttestation[] | undefined> {
|
|
533
|
+
const proposalSlotNumber = proposal.slotNumber;
|
|
534
|
+
const proposer = proposal.getSender();
|
|
535
|
+
|
|
536
|
+
// If escape hatch is open for this slot's epoch, do not attest.
|
|
537
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(proposalSlotNumber)) {
|
|
538
|
+
this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
|
|
539
|
+
return undefined;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// Early-out for equivocation: refuses if we've already attested to a higher slot.
|
|
543
|
+
if (!this.shouldAttestToSlot(proposalSlotNumber)) {
|
|
544
|
+
return undefined;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// Ignore proposals from ourselves (may happen in HA setups)
|
|
548
|
+
if (proposer && this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
549
|
+
this.log.debug(`Not attesting to block proposal from self for slot ${proposalSlotNumber}`, {
|
|
550
|
+
proposer: proposer.toString(),
|
|
551
|
+
proposalSlotNumber,
|
|
552
|
+
});
|
|
324
553
|
return undefined;
|
|
325
554
|
}
|
|
326
555
|
|
|
556
|
+
// Check that I have any address in the committee where this checkpoint will land before attesting
|
|
557
|
+
const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
|
|
558
|
+
const partOfCommittee = inCommittee.length > 0;
|
|
559
|
+
|
|
560
|
+
const proposalInfo = {
|
|
561
|
+
proposalSlotNumber,
|
|
562
|
+
archive: proposal.archive.toString(),
|
|
563
|
+
proposer: proposer?.toString(),
|
|
564
|
+
};
|
|
565
|
+
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
566
|
+
...proposalInfo,
|
|
567
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
|
|
571
|
+
// Uses the cached result from the all-nodes callback if available (avoids double validation).
|
|
572
|
+
let checkpointNumber: CheckpointNumber;
|
|
573
|
+
if (this.config.skipCheckpointProposalValidation) {
|
|
574
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
575
|
+
checkpointNumber = CheckpointNumber(0);
|
|
576
|
+
} else {
|
|
577
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
578
|
+
if (!validationResult.isValid) {
|
|
579
|
+
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
580
|
+
return undefined;
|
|
581
|
+
}
|
|
582
|
+
checkpointNumber = validationResult.checkpointNumber;
|
|
583
|
+
}
|
|
584
|
+
|
|
327
585
|
// Check that I have any address in current committee before attesting
|
|
328
|
-
if
|
|
586
|
+
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
587
|
+
if (!partOfCommittee && !this.config.fishermanMode) {
|
|
329
588
|
this.log.verbose(`No validator in the current committee, skipping attestation`, proposalInfo);
|
|
330
589
|
return undefined;
|
|
331
590
|
}
|
|
332
591
|
|
|
333
592
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
334
|
-
this.log.info(
|
|
593
|
+
this.log.info(
|
|
594
|
+
`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`,
|
|
595
|
+
{
|
|
596
|
+
...proposalInfo,
|
|
597
|
+
inCommittee: partOfCommittee,
|
|
598
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
599
|
+
},
|
|
600
|
+
);
|
|
601
|
+
|
|
335
602
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
336
603
|
|
|
337
|
-
//
|
|
338
|
-
|
|
604
|
+
// Track epoch participation per attester: count each (attester, epoch) pair at most once
|
|
605
|
+
const proposalEpoch = getEpochAtSlot(proposalSlotNumber, this.epochCache.getL1Constants());
|
|
606
|
+
for (const attester of inCommittee) {
|
|
607
|
+
const key = attester.toString();
|
|
608
|
+
const lastEpoch = this.lastAttestedEpochByAttester.get(key);
|
|
609
|
+
if (lastEpoch === undefined || proposalEpoch > lastEpoch) {
|
|
610
|
+
this.lastAttestedEpochByAttester.set(key, proposalEpoch);
|
|
611
|
+
this.metrics.incAttestedEpochCount(attester);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// Determine which validators should attest
|
|
616
|
+
let attestors: EthAddress[];
|
|
617
|
+
if (partOfCommittee) {
|
|
618
|
+
attestors = inCommittee;
|
|
619
|
+
} else if (this.config.fishermanMode) {
|
|
620
|
+
// In fisherman mode, create attestations for validation purposes even if not in committee. These won't be broadcast.
|
|
621
|
+
attestors = this.getValidatorAddresses();
|
|
622
|
+
} else {
|
|
623
|
+
attestors = [];
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// Only create attestations if we have attestors
|
|
627
|
+
if (attestors.length === 0) {
|
|
628
|
+
return undefined;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
if (this.config.fishermanMode) {
|
|
632
|
+
// bail out early and don't save attestations to the pool in fisherman mode
|
|
633
|
+
this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
|
|
634
|
+
...proposalInfo,
|
|
635
|
+
attestors: attestors.map(a => a.toString()),
|
|
636
|
+
});
|
|
637
|
+
return undefined;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Checks if we should attest to a slot based on equivocation prevention rules.
|
|
645
|
+
* @returns true if we should attest, false if we should skip
|
|
646
|
+
*/
|
|
647
|
+
private shouldAttestToSlot(slotNumber: SlotNumber): boolean {
|
|
648
|
+
// If attestToEquivocatedProposals is true, always allow
|
|
649
|
+
if (this.config.attestToEquivocatedProposals) {
|
|
650
|
+
return true;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
// Check if incoming slot is strictly greater than last attested
|
|
654
|
+
if (this.lastAttestedProposal && slotNumber <= this.lastAttestedProposal.slotNumber) {
|
|
655
|
+
this.log.warn(
|
|
656
|
+
`Refusing to process a proposal for slot ${slotNumber} given we already attested to a proposal for slot ${this.lastAttestedProposal.slotNumber}`,
|
|
657
|
+
);
|
|
658
|
+
return false;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
return true;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
private async createCheckpointAttestationsFromProposal(
|
|
665
|
+
proposal: CheckpointProposalCore,
|
|
666
|
+
attestors: EthAddress[] = [],
|
|
667
|
+
checkpointNumber: CheckpointNumber,
|
|
668
|
+
): Promise<CheckpointAttestation[] | undefined> {
|
|
669
|
+
// Equivocation check: must happen right before signing to minimize the race window
|
|
670
|
+
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
671
|
+
return undefined;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
|
|
675
|
+
|
|
676
|
+
// Track the proposal we attested to (to prevent equivocation)
|
|
677
|
+
this.lastAttestedProposal = proposal;
|
|
678
|
+
|
|
679
|
+
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
680
|
+
return attestations;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
685
|
+
*/
|
|
686
|
+
protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
|
|
687
|
+
try {
|
|
688
|
+
const lastBlockHeader = (await this.blockSource.getBlockData({ archive: proposal.archive }))?.header;
|
|
689
|
+
if (!lastBlockHeader) {
|
|
690
|
+
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
|
|
695
|
+
if (blocks.length === 0) {
|
|
696
|
+
this.log.warn(`No blocks found for blob upload`, proposalInfo);
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
const blobFields = blocks.flatMap(b => b.toBlobFields());
|
|
701
|
+
const blobs: Blob[] = await getBlobsPerL1Block(blobFields);
|
|
702
|
+
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
703
|
+
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
704
|
+
...proposalInfo,
|
|
705
|
+
numBlobs: blobs.length,
|
|
706
|
+
});
|
|
707
|
+
} catch (err) {
|
|
708
|
+
this.log.warn(`Failed to upload blobs for checkpoint: ${err}`, proposalInfo);
|
|
709
|
+
}
|
|
339
710
|
}
|
|
340
711
|
|
|
341
712
|
private slashInvalidBlock(proposal: BlockProposal) {
|
|
@@ -347,12 +718,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
347
718
|
return;
|
|
348
719
|
}
|
|
349
720
|
|
|
350
|
-
// Trim the set if it's too big.
|
|
351
|
-
if (this.proposersOfInvalidBlocks.size > MAX_PROPOSERS_OF_INVALID_BLOCKS) {
|
|
352
|
-
// remove oldest proposer. `values` is guaranteed to be in insertion order.
|
|
353
|
-
this.proposersOfInvalidBlocks.delete(this.proposersOfInvalidBlocks.values().next().value!);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
721
|
this.proposersOfInvalidBlocks.add(proposer.toString());
|
|
357
722
|
|
|
358
723
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
@@ -360,34 +725,279 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
360
725
|
validator: proposer,
|
|
361
726
|
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
362
727
|
offenseType: OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL,
|
|
363
|
-
epochOrSlot: proposal.slotNumber
|
|
728
|
+
epochOrSlot: BigInt(proposal.slotNumber),
|
|
729
|
+
},
|
|
730
|
+
]);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
private handleInvalidCheckpointProposal(
|
|
734
|
+
proposal: CheckpointProposalCore,
|
|
735
|
+
result: CheckpointProposalValidationFailureResult,
|
|
736
|
+
proposalInfo: LogData,
|
|
737
|
+
): void {
|
|
738
|
+
if (!SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT[result.reason]) {
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// The slot is already marked invalid by the all-nodes checkpoint handler that invokes this callback,
|
|
743
|
+
// so we only emit the proposer slash event here.
|
|
744
|
+
if (this.slashInvalidCheckpointProposal(proposal)) {
|
|
745
|
+
this.log.info(`Detected invalid checkpoint proposal offense`, {
|
|
746
|
+
...proposalInfo,
|
|
747
|
+
reason: result.reason,
|
|
748
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
749
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL),
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
private slashInvalidCheckpointProposal(proposal: CheckpointProposalCore): boolean {
|
|
755
|
+
const proposer = proposal.getSender();
|
|
756
|
+
if (!proposer) {
|
|
757
|
+
this.log.warn(`Cannot slash checkpoint proposal with invalid signature`, {
|
|
758
|
+
slotNumber: proposal.slotNumber,
|
|
759
|
+
archive: proposal.archive.toString(),
|
|
760
|
+
});
|
|
761
|
+
return false;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
const offenseType = OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL;
|
|
765
|
+
const offenseKey = `${proposer.toString()}:${offenseType}:${proposal.slotNumber}`;
|
|
766
|
+
if (!this.invalidCheckpointProposalOffenseKeys.addIfAbsent(offenseKey)) {
|
|
767
|
+
return false;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
771
|
+
{
|
|
772
|
+
validator: proposer,
|
|
773
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
774
|
+
offenseType,
|
|
775
|
+
epochOrSlot: BigInt(proposal.slotNumber),
|
|
776
|
+
},
|
|
777
|
+
]);
|
|
778
|
+
return true;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
private markInvalidProposalSlot(slotNumber: SlotNumber): void {
|
|
782
|
+
this.proposalHandler.markInvalidProposalSlot(slotNumber);
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
private handleCheckpointAttestation(attestation: CheckpointAttestation): void {
|
|
786
|
+
const slotNumber = attestation.slotNumber;
|
|
787
|
+
if (
|
|
788
|
+
!this.proposalHandler.hasInvalidProposals(slotNumber) ||
|
|
789
|
+
this.proposalHandler.hasProposalEquivocation(slotNumber)
|
|
790
|
+
) {
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
const attester = attestation.getSender();
|
|
795
|
+
if (!attester) {
|
|
796
|
+
this.log.warn(`Cannot slash checkpoint attestation with invalid signature`, {
|
|
797
|
+
slotNumber,
|
|
798
|
+
archive: attestation.archive.toString(),
|
|
799
|
+
});
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
this.slashAttestedToInvalidCheckpointProposal(slotNumber, attester);
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
private slashAttestedToInvalidCheckpointProposal(slotNumber: SlotNumber, attester: EthAddress): void {
|
|
807
|
+
const offenseKey = `${attester.toString()}:${OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL}:${slotNumber}`;
|
|
808
|
+
if (!this.badAttestationOffenseKeys.addIfAbsent(offenseKey)) {
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
this.log.info(`Detected attestation to invalid checkpoint proposal offense`, {
|
|
813
|
+
attester: attester.toString(),
|
|
814
|
+
slotNumber,
|
|
815
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
816
|
+
offenseType: getOffenseTypeName(OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL),
|
|
817
|
+
});
|
|
818
|
+
|
|
819
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
820
|
+
{
|
|
821
|
+
validator: attester,
|
|
822
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
823
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
824
|
+
epochOrSlot: BigInt(slotNumber),
|
|
825
|
+
},
|
|
826
|
+
]);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Handle detection of an oversized block proposal: one whose index within its checkpoint lands at or
|
|
831
|
+
* beyond the consensus per-checkpoint block limit. A single signed proposal at an illegal index is
|
|
832
|
+
* self-contained evidence, so emit an invalid-block-proposal slash event for the proposer, deduped per
|
|
833
|
+
* (proposer, slot) since the p2p layer reports every oversized proposal it stores.
|
|
834
|
+
*/
|
|
835
|
+
private handleOversizedProposal(info: OversizedProposalInfo): void {
|
|
836
|
+
const { slot, proposer } = info;
|
|
837
|
+
const offenseType = OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL;
|
|
838
|
+
if (!this.oversizedProposalOffenseKeys.addIfAbsent(`${proposer.toString()}:${offenseType}:${slot}`)) {
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
this.log.info(`Detected oversized block proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
843
|
+
proposer: proposer.toString(),
|
|
844
|
+
slot,
|
|
845
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
846
|
+
offenseType: getOffenseTypeName(offenseType),
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
850
|
+
{
|
|
851
|
+
validator: proposer,
|
|
852
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
853
|
+
offenseType,
|
|
854
|
+
epochOrSlot: BigInt(slot),
|
|
855
|
+
},
|
|
856
|
+
]);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* Handle detection of a duplicate proposal (equivocation).
|
|
861
|
+
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
862
|
+
*/
|
|
863
|
+
private handleDuplicateProposal(info: DuplicateProposalInfo): void {
|
|
864
|
+
const { slot, proposer, type } = info;
|
|
865
|
+
this.proposalHandler.markProposalEquivocation(slot);
|
|
866
|
+
|
|
867
|
+
this.log.info(`Detected duplicate ${type} proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
868
|
+
proposer: proposer.toString(),
|
|
869
|
+
slot,
|
|
870
|
+
type,
|
|
871
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
872
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_PROPOSAL),
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
876
|
+
{
|
|
877
|
+
validator: proposer,
|
|
878
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
879
|
+
offenseType: OffenseType.DUPLICATE_PROPOSAL,
|
|
880
|
+
epochOrSlot: BigInt(slot),
|
|
881
|
+
},
|
|
882
|
+
]);
|
|
883
|
+
|
|
884
|
+
this.emit(WANT_TO_CLEAR_SLASH_EVENT, [
|
|
885
|
+
{
|
|
886
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
887
|
+
epochOrSlot: BigInt(slot),
|
|
888
|
+
},
|
|
889
|
+
]);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* Handle detection of a duplicate attestation (equivocation).
|
|
894
|
+
* Emits a slash event when an attester signs attestations for different proposals at the same slot.
|
|
895
|
+
*/
|
|
896
|
+
private handleDuplicateAttestation(info: DuplicateAttestationInfo): void {
|
|
897
|
+
const { slot, attester } = info;
|
|
898
|
+
|
|
899
|
+
this.log.info(`Detected duplicate attestation offense from ${attester.toString()} at slot ${slot}`, {
|
|
900
|
+
attester: attester.toString(),
|
|
901
|
+
slot,
|
|
902
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
903
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_ATTESTATION),
|
|
904
|
+
});
|
|
905
|
+
|
|
906
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
907
|
+
{
|
|
908
|
+
validator: attester,
|
|
909
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
910
|
+
offenseType: OffenseType.DUPLICATE_ATTESTATION,
|
|
911
|
+
epochOrSlot: BigInt(slot),
|
|
364
912
|
},
|
|
365
913
|
]);
|
|
366
914
|
}
|
|
367
915
|
|
|
368
916
|
async createBlockProposal(
|
|
369
|
-
|
|
370
|
-
|
|
917
|
+
blockHeader: BlockHeader,
|
|
918
|
+
checkpointNumber: CheckpointNumber,
|
|
919
|
+
indexWithinCheckpoint: IndexWithinCheckpoint,
|
|
920
|
+
inHash: Fr,
|
|
371
921
|
archive: Fr,
|
|
372
|
-
stateReference: StateReference,
|
|
373
922
|
txs: Tx[],
|
|
374
923
|
proposerAddress: EthAddress | undefined,
|
|
375
|
-
options: BlockProposalOptions,
|
|
376
|
-
): Promise<BlockProposal
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
924
|
+
options: BlockProposalOptions = {},
|
|
925
|
+
): Promise<BlockProposal> {
|
|
926
|
+
// Validate that we're not creating a proposal for an older or equal position
|
|
927
|
+
if (this.lastProposedBlock) {
|
|
928
|
+
const lastSlot = this.lastProposedBlock.slotNumber;
|
|
929
|
+
const lastIndex = this.lastProposedBlock.indexWithinCheckpoint;
|
|
930
|
+
const newSlot = blockHeader.globalVariables.slotNumber;
|
|
931
|
+
|
|
932
|
+
if (newSlot < lastSlot || (newSlot === lastSlot && indexWithinCheckpoint <= lastIndex)) {
|
|
933
|
+
throw new Error(
|
|
934
|
+
`Cannot create block proposal for slot ${newSlot} index ${indexWithinCheckpoint}: ` +
|
|
935
|
+
`already proposed block for slot ${lastSlot} index ${lastIndex}`,
|
|
936
|
+
);
|
|
937
|
+
}
|
|
380
938
|
}
|
|
381
939
|
|
|
940
|
+
this.log.info(
|
|
941
|
+
`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`,
|
|
942
|
+
);
|
|
382
943
|
const newProposal = await this.validationService.createBlockProposal(
|
|
383
|
-
|
|
944
|
+
blockHeader,
|
|
945
|
+
checkpointNumber,
|
|
946
|
+
indexWithinCheckpoint,
|
|
947
|
+
inHash,
|
|
384
948
|
archive,
|
|
385
|
-
stateReference,
|
|
386
949
|
txs,
|
|
387
950
|
proposerAddress,
|
|
388
|
-
{
|
|
951
|
+
{
|
|
952
|
+
...options,
|
|
953
|
+
broadcastInvalidBlockProposal:
|
|
954
|
+
options.broadcastInvalidBlockProposal || this.config.broadcastInvalidBlockProposal,
|
|
955
|
+
},
|
|
956
|
+
);
|
|
957
|
+
this.lastProposedBlock = newProposal;
|
|
958
|
+
return newProposal;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
async createCheckpointProposal(
|
|
962
|
+
checkpointHeader: CheckpointHeader,
|
|
963
|
+
archive: Fr,
|
|
964
|
+
checkpointNumber: CheckpointNumber,
|
|
965
|
+
feeAssetPriceModifier: bigint,
|
|
966
|
+
lastBlockProposal: BlockProposal | undefined,
|
|
967
|
+
proposerAddress: EthAddress | undefined,
|
|
968
|
+
options: CheckpointProposalOptions = {},
|
|
969
|
+
): Promise<CheckpointProposal> {
|
|
970
|
+
// Validate that we're not creating a proposal for an older or equal slot
|
|
971
|
+
if (this.lastProposedCheckpoint) {
|
|
972
|
+
const lastSlot = this.lastProposedCheckpoint.slotNumber;
|
|
973
|
+
const newSlot = checkpointHeader.slotNumber;
|
|
974
|
+
|
|
975
|
+
if (newSlot <= lastSlot) {
|
|
976
|
+
throw new Error(
|
|
977
|
+
`Cannot create checkpoint proposal for slot ${newSlot}: ` +
|
|
978
|
+
`already proposed checkpoint for slot ${lastSlot}`,
|
|
979
|
+
);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
984
|
+
const newProposal = await this.validationService.createCheckpointProposal(
|
|
985
|
+
checkpointHeader,
|
|
986
|
+
archive,
|
|
987
|
+
checkpointNumber,
|
|
988
|
+
feeAssetPriceModifier,
|
|
989
|
+
lastBlockProposal,
|
|
990
|
+
proposerAddress,
|
|
991
|
+
options,
|
|
389
992
|
);
|
|
390
|
-
this.
|
|
993
|
+
this.lastProposedCheckpoint = newProposal;
|
|
994
|
+
// Self-record this slot's outcome on the re-execution tracker. Proposers don't run their
|
|
995
|
+
// own proposals through `handleCheckpointProposal`, so without this call the proposer's
|
|
996
|
+
// sentinel would see no outcome for slots it proposed and would mis-attribute itself as
|
|
997
|
+
// inactive. We pass the locally-computed `archive` (not `newProposal.archive`, which may
|
|
998
|
+
// be intentionally corrupted under test-only flags); from the proposer's local-view
|
|
999
|
+
// perspective the work it just completed is valid by definition.
|
|
1000
|
+
this.proposalHandler.recordOwnCheckpointProposalAsValid(checkpointHeader.slotNumber, archive, checkpointNumber);
|
|
391
1001
|
return newProposal;
|
|
392
1002
|
}
|
|
393
1003
|
|
|
@@ -398,20 +1008,47 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
398
1008
|
async signAttestationsAndSigners(
|
|
399
1009
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
400
1010
|
proposer: EthAddress,
|
|
1011
|
+
slot: SlotNumber,
|
|
1012
|
+
checkpointNumber: CheckpointNumber,
|
|
401
1013
|
): Promise<Signature> {
|
|
402
|
-
return await this.validationService.signAttestationsAndSigners(
|
|
1014
|
+
return await this.validationService.signAttestationsAndSigners(
|
|
1015
|
+
attestationsAndSigners,
|
|
1016
|
+
proposer,
|
|
1017
|
+
slot,
|
|
1018
|
+
checkpointNumber,
|
|
1019
|
+
);
|
|
403
1020
|
}
|
|
404
1021
|
|
|
405
|
-
async collectOwnAttestations(
|
|
406
|
-
|
|
1022
|
+
async collectOwnAttestations(
|
|
1023
|
+
proposal: CheckpointProposal,
|
|
1024
|
+
checkpointNumber: CheckpointNumber,
|
|
1025
|
+
): Promise<CheckpointAttestation[]> {
|
|
1026
|
+
const slot = proposal.slotNumber;
|
|
407
1027
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
408
1028
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
|
|
409
|
-
|
|
1029
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
|
|
1030
|
+
|
|
1031
|
+
if (!attestations) {
|
|
1032
|
+
return [];
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
1036
|
+
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
1037
|
+
// due to inactivity for missed attestations.
|
|
1038
|
+
void this.p2pClient.broadcastCheckpointAttestations(attestations).catch(err => {
|
|
1039
|
+
this.log.error(`Failed to broadcast self-attestations for slot ${slot}`, err);
|
|
1040
|
+
});
|
|
1041
|
+
return attestations;
|
|
410
1042
|
}
|
|
411
1043
|
|
|
412
|
-
async collectAttestations(
|
|
413
|
-
|
|
414
|
-
|
|
1044
|
+
async collectAttestations(
|
|
1045
|
+
proposal: CheckpointProposal,
|
|
1046
|
+
required: number,
|
|
1047
|
+
deadline: Date,
|
|
1048
|
+
checkpointNumber: CheckpointNumber,
|
|
1049
|
+
): Promise<CheckpointAttestation[]> {
|
|
1050
|
+
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
1051
|
+
const slot = proposal.slotNumber;
|
|
415
1052
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
416
1053
|
|
|
417
1054
|
if (+deadline < this.dateProvider.now()) {
|
|
@@ -421,33 +1058,23 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
421
1058
|
throw new AttestationTimeoutError(0, required, slot);
|
|
422
1059
|
}
|
|
423
1060
|
|
|
424
|
-
await this.collectOwnAttestations(proposal);
|
|
1061
|
+
await this.collectOwnAttestations(proposal, checkpointNumber);
|
|
425
1062
|
|
|
426
|
-
const
|
|
1063
|
+
const proposalPayloadHash = proposal.getPayloadHash();
|
|
427
1064
|
const myAddresses = this.getValidatorAddresses();
|
|
428
1065
|
|
|
429
|
-
let attestations:
|
|
1066
|
+
let attestations: CheckpointAttestation[] = [];
|
|
430
1067
|
while (true) {
|
|
431
|
-
//
|
|
432
|
-
//
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
if (!attestation.payload.equals(proposal.payload)) {
|
|
436
|
-
this.log.warn(
|
|
437
|
-
`Received attestation for slot ${slot} with mismatched payload from ${attestation.getSender()?.toString()}`,
|
|
438
|
-
{ attestationPayload: attestation.payload, proposalPayload: proposal.payload },
|
|
439
|
-
);
|
|
440
|
-
return false;
|
|
441
|
-
}
|
|
442
|
-
return true;
|
|
443
|
-
},
|
|
444
|
-
);
|
|
1068
|
+
// The pool already filters by proposal payload hash; if any attestation slips through with a
|
|
1069
|
+
// mismatched payload hash, drop it defensively. Equivocations are emitted as separate slash
|
|
1070
|
+
// events from libp2p_service.
|
|
1071
|
+
const collectedAttestations = await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalPayloadHash);
|
|
445
1072
|
|
|
446
1073
|
// Log new attestations we collected
|
|
447
1074
|
const oldSenders = attestations.map(attestation => attestation.getSender());
|
|
448
1075
|
for (const collected of collectedAttestations) {
|
|
449
1076
|
const collectedSender = collected.getSender();
|
|
450
|
-
// Skip attestations with invalid signatures
|
|
1077
|
+
// Skip attestations with invalid signatures. Should not happen as we don't add invalid attestations to our pool.
|
|
451
1078
|
if (!collectedSender) {
|
|
452
1079
|
this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
|
|
453
1080
|
continue;
|
|
@@ -476,15 +1103,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
476
1103
|
}
|
|
477
1104
|
}
|
|
478
1105
|
|
|
479
|
-
private async createBlockAttestationsFromProposal(
|
|
480
|
-
proposal: BlockProposal,
|
|
481
|
-
attestors: EthAddress[] = [],
|
|
482
|
-
): Promise<BlockAttestation[]> {
|
|
483
|
-
const attestations = await this.validationService.attestToProposal(proposal, attestors);
|
|
484
|
-
await this.p2pClient.addAttestations(attestations);
|
|
485
|
-
return attestations;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
1106
|
private async handleAuthRequest(peer: PeerId, msg: Buffer): Promise<Buffer> {
|
|
489
1107
|
const authRequest = AuthRequest.fromBuffer(msg);
|
|
490
1108
|
const statusMessage = await this.p2pClient.handleAuthRequestFromPeer(authRequest, peer).catch(_ => undefined);
|
|
@@ -503,7 +1121,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
503
1121
|
}
|
|
504
1122
|
|
|
505
1123
|
const payloadToSign = authRequest.getPayloadToSign();
|
|
506
|
-
|
|
1124
|
+
// AUTH_REQUEST doesn't require HA protection - multiple signatures are safe
|
|
1125
|
+
const context: SigningContext = { dutyType: DutyType.AUTH_REQUEST };
|
|
1126
|
+
const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign, context);
|
|
507
1127
|
const authResponse = new AuthResponse(statusMessage, signature);
|
|
508
1128
|
return authResponse.toBuffer();
|
|
509
1129
|
}
|