@aztec/validator-client 0.0.1-commit.03f7ef2 → 0.0.1-commit.0658669b3
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 +285 -0
- package/dest/block_proposal_handler.d.ts +21 -11
- package/dest/block_proposal_handler.d.ts.map +1 -1
- package/dest/block_proposal_handler.js +327 -85
- package/dest/checkpoint_builder.d.ts +69 -0
- package/dest/checkpoint_builder.d.ts.map +1 -0
- package/dest/checkpoint_builder.js +180 -0
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -8
- package/dest/duties/validation_service.d.ts +41 -12
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +109 -26
- package/dest/factory.d.ts +13 -10
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +2 -2
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- 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 +8 -4
- 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 +10 -5
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
- package/dest/key_store/web3signer_key_store.js +8 -4
- package/dest/metrics.d.ts +4 -3
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +34 -30
- package/dest/validator.d.ts +73 -24
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +451 -78
- package/package.json +21 -13
- package/src/block_proposal_handler.ts +246 -57
- package/src/checkpoint_builder.ts +328 -0
- package/src/config.ts +15 -7
- package/src/duties/validation_service.ts +160 -31
- package/src/factory.ts +17 -11
- package/src/index.ts +1 -0
- 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 +13 -4
- package/src/key_store/node_keystore_adapter.ts +27 -4
- package/src/key_store/web3signer_key_store.ts +17 -4
- package/src/metrics.ts +45 -33
- package/src/validator.ts +614 -115
package/dest/validator.js
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import { getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
2
|
+
import { validateFeeAssetPriceModifier } from '@aztec/ethereum/contracts';
|
|
3
|
+
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { TimeoutError } from '@aztec/foundation/error';
|
|
2
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
3
7
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
4
8
|
import { sleep } from '@aztec/foundation/sleep';
|
|
5
9
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
6
10
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
7
11
|
import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
12
|
+
import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
13
|
+
import { accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
|
|
8
14
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
9
15
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
16
|
+
import { createHASigner } from '@aztec/validator-ha-signer/factory';
|
|
17
|
+
import { DutyType } from '@aztec/validator-ha-signer/types';
|
|
10
18
|
import { EventEmitter } from 'events';
|
|
11
19
|
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
12
20
|
import { ValidationService } from './duties/validation_service.js';
|
|
21
|
+
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
13
22
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
14
23
|
import { ValidatorMetrics } from './metrics.js';
|
|
15
24
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
@@ -27,8 +36,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
27
36
|
epochCache;
|
|
28
37
|
p2pClient;
|
|
29
38
|
blockProposalHandler;
|
|
39
|
+
blockSource;
|
|
40
|
+
checkpointsBuilder;
|
|
41
|
+
worldState;
|
|
42
|
+
l1ToL2MessageSource;
|
|
30
43
|
config;
|
|
31
|
-
|
|
44
|
+
blobClient;
|
|
45
|
+
haSigner;
|
|
32
46
|
dateProvider;
|
|
33
47
|
tracer;
|
|
34
48
|
validationService;
|
|
@@ -36,13 +50,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
36
50
|
log;
|
|
37
51
|
// Whether it has already registered handlers on the p2p client
|
|
38
52
|
hasRegisteredHandlers;
|
|
39
|
-
|
|
40
|
-
|
|
53
|
+
/** Tracks the last block proposal we created, to detect duplicate proposal attempts. */ lastProposedBlock;
|
|
54
|
+
/** Tracks the last checkpoint proposal we created. */ lastProposedCheckpoint;
|
|
41
55
|
lastEpochForCommitteeUpdateLoop;
|
|
42
56
|
epochCacheUpdateLoop;
|
|
43
57
|
proposersOfInvalidBlocks;
|
|
44
|
-
|
|
45
|
-
|
|
58
|
+
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */ lastAttestedProposal;
|
|
59
|
+
constructor(keyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, haSigner, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
60
|
+
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.blockProposalHandler = blockProposalHandler, this.blockSource = blockSource, this.checkpointsBuilder = checkpointsBuilder, this.worldState = worldState, this.l1ToL2MessageSource = l1ToL2MessageSource, this.config = config, this.blobClient = blobClient, this.haSigner = haSigner, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.proposersOfInvalidBlocks = new Set();
|
|
46
61
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
47
62
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
48
63
|
this.tracer = telemetry.getTracer('Validator');
|
|
@@ -96,13 +111,29 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
96
111
|
this.log.error(`Error updating epoch committee`, err);
|
|
97
112
|
}
|
|
98
113
|
}
|
|
99
|
-
static new(config,
|
|
114
|
+
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
100
115
|
const metrics = new ValidatorMetrics(telemetry);
|
|
101
116
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
102
117
|
txsPermitted: !config.disableTransactions
|
|
103
118
|
});
|
|
104
|
-
const blockProposalHandler = new BlockProposalHandler(
|
|
105
|
-
const
|
|
119
|
+
const blockProposalHandler = new BlockProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, metrics, dateProvider, telemetry);
|
|
120
|
+
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
121
|
+
let validatorKeyStore = nodeKeystoreAdapter;
|
|
122
|
+
let haSigner;
|
|
123
|
+
if (config.haSigningEnabled) {
|
|
124
|
+
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
125
|
+
const haConfig = {
|
|
126
|
+
...config,
|
|
127
|
+
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000
|
|
128
|
+
};
|
|
129
|
+
const { signer } = await createHASigner(haConfig, {
|
|
130
|
+
telemetryClient: telemetry,
|
|
131
|
+
dateProvider
|
|
132
|
+
});
|
|
133
|
+
haSigner = signer;
|
|
134
|
+
validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, signer);
|
|
135
|
+
}
|
|
136
|
+
const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, haSigner, dateProvider, telemetry);
|
|
106
137
|
return validator;
|
|
107
138
|
}
|
|
108
139
|
getValidatorAddresses() {
|
|
@@ -111,12 +142,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
111
142
|
getBlockProposalHandler() {
|
|
112
143
|
return this.blockProposalHandler;
|
|
113
144
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return this.blockProposalHandler.reexecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages);
|
|
117
|
-
}
|
|
118
|
-
signWithAddress(addr, msg) {
|
|
119
|
-
return this.keyStore.signTypedDataWithAddress(addr, msg);
|
|
145
|
+
signWithAddress(addr, msg, context) {
|
|
146
|
+
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
120
147
|
}
|
|
121
148
|
getCoinbaseForAttestor(attestor) {
|
|
122
149
|
return this.keyStore.getCoinbaseAddress(attestor);
|
|
@@ -133,11 +160,26 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
133
160
|
...config
|
|
134
161
|
};
|
|
135
162
|
}
|
|
163
|
+
reloadKeystore(newManager) {
|
|
164
|
+
if (this.config.haSigningEnabled && !this.haSigner) {
|
|
165
|
+
this.log.warn('HA signing is enabled in config but was not initialized at startup. ' + 'Restart the node to enable HA signing.');
|
|
166
|
+
} else if (!this.config.haSigningEnabled && this.haSigner) {
|
|
167
|
+
this.log.warn('HA signing was disabled via config update but the HA signer is still active. ' + 'Restart the node to fully disable HA signing.');
|
|
168
|
+
}
|
|
169
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
170
|
+
if (this.haSigner) {
|
|
171
|
+
this.keyStore = new HAKeyStore(newAdapter, this.haSigner);
|
|
172
|
+
} else {
|
|
173
|
+
this.keyStore = newAdapter;
|
|
174
|
+
}
|
|
175
|
+
this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
|
|
176
|
+
}
|
|
136
177
|
async start() {
|
|
137
178
|
if (this.epochCacheUpdateLoop.isRunning()) {
|
|
138
179
|
this.log.warn(`Validator client already started`);
|
|
139
180
|
return;
|
|
140
181
|
}
|
|
182
|
+
await this.keyStore.start();
|
|
141
183
|
await this.registerHandlers();
|
|
142
184
|
const myAddresses = this.getValidatorAddresses();
|
|
143
185
|
const inCommittee = await this.epochCache.filterInCommittee('now', myAddresses);
|
|
@@ -150,46 +192,75 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
150
192
|
}
|
|
151
193
|
async stop() {
|
|
152
194
|
await this.epochCacheUpdateLoop.stop();
|
|
195
|
+
await this.keyStore.stop();
|
|
153
196
|
}
|
|
154
197
|
/** Register handlers on the p2p client */ async registerHandlers() {
|
|
155
198
|
if (!this.hasRegisteredHandlers) {
|
|
156
199
|
this.hasRegisteredHandlers = true;
|
|
157
200
|
this.log.debug(`Registering validator handlers for p2p client`);
|
|
158
|
-
|
|
159
|
-
this.
|
|
201
|
+
// Block proposal handler - validates but does NOT attest (validators only attest to checkpoints)
|
|
202
|
+
const blockHandler = (block, proposalSender)=>this.validateBlockProposal(block, proposalSender);
|
|
203
|
+
this.p2pClient.registerBlockProposalHandler(blockHandler);
|
|
204
|
+
// Checkpoint proposal handler - validates and creates attestations
|
|
205
|
+
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
206
|
+
// and processed separately via the block handler above.
|
|
207
|
+
const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
208
|
+
this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
|
|
209
|
+
// Duplicate proposal handler - triggers slashing for equivocation
|
|
210
|
+
this.p2pClient.registerDuplicateProposalCallback((info)=>{
|
|
211
|
+
this.handleDuplicateProposal(info);
|
|
212
|
+
});
|
|
213
|
+
// Duplicate attestation handler - triggers slashing for attestation equivocation
|
|
214
|
+
this.p2pClient.registerDuplicateAttestationCallback((info)=>{
|
|
215
|
+
this.handleDuplicateAttestation(info);
|
|
216
|
+
});
|
|
160
217
|
const myAddresses = this.getValidatorAddresses();
|
|
161
218
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
162
219
|
await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
|
|
163
220
|
}
|
|
164
221
|
}
|
|
165
|
-
|
|
222
|
+
/**
|
|
223
|
+
* Validate a block proposal from a peer.
|
|
224
|
+
* Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
|
|
225
|
+
* @returns true if the proposal is valid, false otherwise
|
|
226
|
+
*/ async validateBlockProposal(proposal, proposalSender) {
|
|
166
227
|
const slotNumber = proposal.slotNumber;
|
|
228
|
+
// Note: During escape hatch, we still want to "validate" proposals for observability,
|
|
229
|
+
// but we intentionally reject them and disable slashing invalid block and attestation flow.
|
|
230
|
+
const escapeHatchOpen = await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber);
|
|
167
231
|
const proposer = proposal.getSender();
|
|
168
232
|
// Reject proposals with invalid signatures
|
|
169
233
|
if (!proposer) {
|
|
170
|
-
this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
|
|
171
|
-
return
|
|
234
|
+
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
235
|
+
return false;
|
|
172
236
|
}
|
|
173
|
-
//
|
|
237
|
+
// Ignore proposals from ourselves (may happen in HA setups)
|
|
238
|
+
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
239
|
+
this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
|
|
240
|
+
proposer: proposer.toString(),
|
|
241
|
+
slotNumber
|
|
242
|
+
});
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
// Check if we're in the committee (for metrics purposes)
|
|
174
246
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
175
247
|
const partOfCommittee = inCommittee.length > 0;
|
|
176
248
|
const proposalInfo = {
|
|
177
249
|
...proposal.toBlockInfo(),
|
|
178
250
|
proposer: proposer.toString()
|
|
179
251
|
};
|
|
180
|
-
this.log.info(`Received proposal for slot ${slotNumber}`, {
|
|
252
|
+
this.log.info(`Received block proposal for slot ${slotNumber}`, {
|
|
181
253
|
...proposalInfo,
|
|
182
254
|
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
183
255
|
fishermanMode: this.config.fishermanMode || false
|
|
184
256
|
});
|
|
185
|
-
// Reexecute txs if we are part of the committee
|
|
186
|
-
// invalid proposals even when not in the committee, or if we are configured to always reexecute for monitoring purposes.
|
|
257
|
+
// Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
|
|
187
258
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
188
259
|
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
189
|
-
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.
|
|
190
|
-
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute);
|
|
260
|
+
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
|
|
261
|
+
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
|
|
191
262
|
if (!validationResult.isValid) {
|
|
192
|
-
this.log.warn(`
|
|
263
|
+
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
193
264
|
const reason = validationResult.reason || 'unknown';
|
|
194
265
|
// Classify failure reason: bad proposal vs node issue
|
|
195
266
|
const badProposalReasons = [
|
|
@@ -202,43 +273,100 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
202
273
|
if (badProposalReasons.includes(reason)) {
|
|
203
274
|
this.metrics.incFailedAttestationsBadProposal(1, reason, partOfCommittee);
|
|
204
275
|
} else {
|
|
205
|
-
// Node issues so we can't
|
|
276
|
+
// Node issues so we can't validate
|
|
206
277
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
207
278
|
}
|
|
208
279
|
// Slash invalid block proposals (can happen even when not in committee)
|
|
209
|
-
if (validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
|
|
280
|
+
if (!escapeHatchOpen && validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
|
|
210
281
|
this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
|
|
211
282
|
this.slashInvalidBlock(proposal);
|
|
212
283
|
}
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
this.log.info(`Validated block proposal for slot ${slotNumber}`, {
|
|
287
|
+
...proposalInfo,
|
|
288
|
+
inCommittee: partOfCommittee,
|
|
289
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
290
|
+
escapeHatchOpen
|
|
291
|
+
});
|
|
292
|
+
if (escapeHatchOpen) {
|
|
293
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, rejecting block proposal`, proposalInfo);
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Validate and attest to a checkpoint proposal from a peer.
|
|
300
|
+
* The proposal is received as CheckpointProposalCore (without lastBlock) since
|
|
301
|
+
* the lastBlock is extracted and processed separately via the block handler.
|
|
302
|
+
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
303
|
+
*/ async attestToCheckpointProposal(proposal, _proposalSender) {
|
|
304
|
+
const slotNumber = proposal.slotNumber;
|
|
305
|
+
const proposer = proposal.getSender();
|
|
306
|
+
// If escape hatch is open for this slot's epoch, do not attest.
|
|
307
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
|
|
308
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, skipping checkpoint attestation handling`);
|
|
309
|
+
return undefined;
|
|
310
|
+
}
|
|
311
|
+
// Reject proposals with invalid signatures
|
|
312
|
+
if (!proposer) {
|
|
313
|
+
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
314
|
+
return undefined;
|
|
315
|
+
}
|
|
316
|
+
// Ignore proposals from ourselves (may happen in HA setups)
|
|
317
|
+
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
318
|
+
this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
|
|
319
|
+
proposer: proposer.toString(),
|
|
320
|
+
slotNumber
|
|
321
|
+
});
|
|
322
|
+
return undefined;
|
|
323
|
+
}
|
|
324
|
+
// Validate fee asset price modifier is within allowed range
|
|
325
|
+
if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
|
|
326
|
+
this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`);
|
|
213
327
|
return undefined;
|
|
214
328
|
}
|
|
215
329
|
// Check that I have any address in current committee before attesting
|
|
330
|
+
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
331
|
+
const partOfCommittee = inCommittee.length > 0;
|
|
332
|
+
const proposalInfo = {
|
|
333
|
+
slotNumber,
|
|
334
|
+
archive: proposal.archive.toString(),
|
|
335
|
+
proposer: proposer.toString(),
|
|
336
|
+
txCount: proposal.txHashes.length
|
|
337
|
+
};
|
|
338
|
+
this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
|
|
339
|
+
...proposalInfo,
|
|
340
|
+
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
341
|
+
fishermanMode: this.config.fishermanMode || false
|
|
342
|
+
});
|
|
343
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
344
|
+
if (this.config.skipCheckpointProposalValidation) {
|
|
345
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
|
|
346
|
+
} else {
|
|
347
|
+
const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
348
|
+
if (!validationResult.isValid) {
|
|
349
|
+
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
350
|
+
return undefined;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
// Upload blobs to filestore if we can (fire and forget)
|
|
354
|
+
if (this.blobClient.canUpload()) {
|
|
355
|
+
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
356
|
+
}
|
|
357
|
+
// Check that I have any address in current committee before attesting
|
|
216
358
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
217
359
|
if (!partOfCommittee && !this.config.fishermanMode) {
|
|
218
360
|
this.log.verbose(`No validator in the current committee, skipping attestation`, proposalInfo);
|
|
219
361
|
return undefined;
|
|
220
362
|
}
|
|
221
363
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
222
|
-
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} proposal for slot ${slotNumber}`, {
|
|
364
|
+
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${slotNumber}`, {
|
|
223
365
|
...proposalInfo,
|
|
224
366
|
inCommittee: partOfCommittee,
|
|
225
367
|
fishermanMode: this.config.fishermanMode || false
|
|
226
368
|
});
|
|
227
369
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
228
|
-
// Upload blobs to filestore after successful re-execution (fire-and-forget)
|
|
229
|
-
if (validationResult.reexecutionResult?.block && this.fileStoreBlobUploadClient) {
|
|
230
|
-
void Promise.resolve().then(async ()=>{
|
|
231
|
-
try {
|
|
232
|
-
const blobFields = validationResult.reexecutionResult.block.getCheckpointBlobFields();
|
|
233
|
-
const blobs = getBlobsPerL1Block(blobFields);
|
|
234
|
-
await this.fileStoreBlobUploadClient.saveBlobs(blobs, true);
|
|
235
|
-
this.log.debug(`Uploaded ${blobs.length} blobs to filestore from re-execution`, proposalInfo);
|
|
236
|
-
} catch (err) {
|
|
237
|
-
this.log.warn(`Failed to upload blobs from re-execution`, err);
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
// If the above function does not throw an error, then we can attest to the proposal
|
|
242
370
|
// Determine which validators should attest
|
|
243
371
|
let attestors;
|
|
244
372
|
if (partOfCommittee) {
|
|
@@ -255,13 +383,206 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
255
383
|
}
|
|
256
384
|
if (this.config.fishermanMode) {
|
|
257
385
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
258
|
-
this.log.info(`Creating attestations for
|
|
386
|
+
this.log.info(`Creating checkpoint attestations for slot ${slotNumber}`, {
|
|
259
387
|
...proposalInfo,
|
|
260
388
|
attestors: attestors.map((a)=>a.toString())
|
|
261
389
|
});
|
|
262
390
|
return undefined;
|
|
263
391
|
}
|
|
264
|
-
return this.
|
|
392
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Checks if we should attest to a slot based on equivocation prevention rules.
|
|
396
|
+
* @returns true if we should attest, false if we should skip
|
|
397
|
+
*/ shouldAttestToSlot(slotNumber) {
|
|
398
|
+
// If attestToEquivocatedProposals is true, always allow
|
|
399
|
+
if (this.config.attestToEquivocatedProposals) {
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
// Check if incoming slot is strictly greater than last attested
|
|
403
|
+
if (this.lastAttestedProposal && slotNumber <= this.lastAttestedProposal.slotNumber) {
|
|
404
|
+
this.log.warn(`Refusing to process a proposal for slot ${slotNumber} given we already attested to a proposal for slot ${this.lastAttestedProposal.slotNumber}`);
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
return true;
|
|
408
|
+
}
|
|
409
|
+
async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
|
|
410
|
+
// Equivocation check: must happen right before signing to minimize the race window
|
|
411
|
+
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
412
|
+
return undefined;
|
|
413
|
+
}
|
|
414
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
415
|
+
// Track the proposal we attested to (to prevent equivocation)
|
|
416
|
+
this.lastAttestedProposal = proposal;
|
|
417
|
+
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
418
|
+
return attestations;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
422
|
+
* @returns Validation result with isValid flag and reason if invalid.
|
|
423
|
+
*/ async validateCheckpointProposal(proposal, proposalInfo) {
|
|
424
|
+
const slot = proposal.slotNumber;
|
|
425
|
+
// Timeout block syncing at the start of the next slot
|
|
426
|
+
const config = this.checkpointsBuilder.getConfig();
|
|
427
|
+
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
|
|
428
|
+
const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
|
|
429
|
+
// Wait for last block to sync by archive
|
|
430
|
+
let lastBlockHeader;
|
|
431
|
+
try {
|
|
432
|
+
lastBlockHeader = await retryUntil(async ()=>{
|
|
433
|
+
await this.blockSource.syncImmediate();
|
|
434
|
+
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
435
|
+
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, timeoutSeconds, 0.5);
|
|
436
|
+
} catch (err) {
|
|
437
|
+
if (err instanceof TimeoutError) {
|
|
438
|
+
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
439
|
+
return {
|
|
440
|
+
isValid: false,
|
|
441
|
+
reason: 'last_block_not_found'
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
445
|
+
return {
|
|
446
|
+
isValid: false,
|
|
447
|
+
reason: 'block_fetch_error'
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
if (!lastBlockHeader) {
|
|
451
|
+
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
452
|
+
return {
|
|
453
|
+
isValid: false,
|
|
454
|
+
reason: 'last_block_not_found'
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
// Get all full blocks for the slot and checkpoint
|
|
458
|
+
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
459
|
+
if (blocks.length === 0) {
|
|
460
|
+
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
461
|
+
return {
|
|
462
|
+
isValid: false,
|
|
463
|
+
reason: 'no_blocks_for_slot'
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
467
|
+
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
468
|
+
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
469
|
+
return {
|
|
470
|
+
isValid: false,
|
|
471
|
+
reason: 'last_block_archive_mismatch'
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
475
|
+
...proposalInfo,
|
|
476
|
+
blockNumbers: blocks.map((b)=>b.number)
|
|
477
|
+
});
|
|
478
|
+
// Get checkpoint constants from first block
|
|
479
|
+
const firstBlock = blocks[0];
|
|
480
|
+
const constants = this.extractCheckpointConstants(firstBlock);
|
|
481
|
+
const checkpointNumber = firstBlock.checkpointNumber;
|
|
482
|
+
// Get L1-to-L2 messages for this checkpoint
|
|
483
|
+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
484
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
485
|
+
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
486
|
+
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch)).filter((c)=>c.checkpointNumber < checkpointNumber).map((c)=>c.checkpointOutHash);
|
|
487
|
+
// Fork world state at the block before the first block
|
|
488
|
+
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
489
|
+
const fork = await this.worldState.fork(parentBlockNumber);
|
|
490
|
+
try {
|
|
491
|
+
// Create checkpoint builder with all existing blocks
|
|
492
|
+
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
|
|
493
|
+
// Complete the checkpoint to get computed values
|
|
494
|
+
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
495
|
+
// Compare checkpoint header with proposal
|
|
496
|
+
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
497
|
+
this.log.warn(`Checkpoint header mismatch`, {
|
|
498
|
+
...proposalInfo,
|
|
499
|
+
computed: computedCheckpoint.header.toInspect(),
|
|
500
|
+
proposal: proposal.checkpointHeader.toInspect()
|
|
501
|
+
});
|
|
502
|
+
return {
|
|
503
|
+
isValid: false,
|
|
504
|
+
reason: 'checkpoint_header_mismatch'
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
// Compare archive root with proposal
|
|
508
|
+
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
509
|
+
this.log.warn(`Archive root mismatch`, {
|
|
510
|
+
...proposalInfo,
|
|
511
|
+
computed: computedCheckpoint.archive.root.toString(),
|
|
512
|
+
proposal: proposal.archive.toString()
|
|
513
|
+
});
|
|
514
|
+
return {
|
|
515
|
+
isValid: false,
|
|
516
|
+
reason: 'archive_mismatch'
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
520
|
+
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
521
|
+
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
522
|
+
const computedEpochOutHash = accumulateCheckpointOutHashes([
|
|
523
|
+
...previousCheckpointOutHashes,
|
|
524
|
+
checkpointOutHash
|
|
525
|
+
]);
|
|
526
|
+
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
527
|
+
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
528
|
+
this.log.warn(`Epoch out hash mismatch`, {
|
|
529
|
+
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
530
|
+
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
531
|
+
checkpointOutHash: checkpointOutHash.toString(),
|
|
532
|
+
previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
|
|
533
|
+
...proposalInfo
|
|
534
|
+
});
|
|
535
|
+
return {
|
|
536
|
+
isValid: false,
|
|
537
|
+
reason: 'out_hash_mismatch'
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
541
|
+
return {
|
|
542
|
+
isValid: true
|
|
543
|
+
};
|
|
544
|
+
} finally{
|
|
545
|
+
await fork.close();
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Extract checkpoint global variables from a block.
|
|
550
|
+
*/ extractCheckpointConstants(block) {
|
|
551
|
+
const gv = block.header.globalVariables;
|
|
552
|
+
return {
|
|
553
|
+
chainId: gv.chainId,
|
|
554
|
+
version: gv.version,
|
|
555
|
+
slotNumber: gv.slotNumber,
|
|
556
|
+
timestamp: gv.timestamp,
|
|
557
|
+
coinbase: gv.coinbase,
|
|
558
|
+
feeRecipient: gv.feeRecipient,
|
|
559
|
+
gasFees: gv.gasFees
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
564
|
+
*/ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
|
|
565
|
+
try {
|
|
566
|
+
const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
567
|
+
if (!lastBlockHeader) {
|
|
568
|
+
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
|
|
572
|
+
if (blocks.length === 0) {
|
|
573
|
+
this.log.warn(`No blocks found for blob upload`, proposalInfo);
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
const blobFields = blocks.flatMap((b)=>b.toBlobFields());
|
|
577
|
+
const blobs = await getBlobsPerL1Block(blobFields);
|
|
578
|
+
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
579
|
+
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
580
|
+
...proposalInfo,
|
|
581
|
+
numBlobs: blobs.length
|
|
582
|
+
});
|
|
583
|
+
} catch (err) {
|
|
584
|
+
this.log.warn(`Failed to upload blobs for checkpoint: ${err}`, proposalInfo);
|
|
585
|
+
}
|
|
265
586
|
}
|
|
266
587
|
slashInvalidBlock(proposal) {
|
|
267
588
|
const proposer = proposal.getSender();
|
|
@@ -285,50 +606,103 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
285
606
|
}
|
|
286
607
|
]);
|
|
287
608
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
609
|
+
/**
|
|
610
|
+
* Handle detection of a duplicate proposal (equivocation).
|
|
611
|
+
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
612
|
+
*/ handleDuplicateProposal(info) {
|
|
613
|
+
const { slot, proposer, type } = info;
|
|
614
|
+
this.log.warn(`Triggering slash event for duplicate ${type} proposal from ${proposer.toString()} at slot ${slot}`, {
|
|
615
|
+
proposer: proposer.toString(),
|
|
616
|
+
slot,
|
|
617
|
+
type
|
|
618
|
+
});
|
|
619
|
+
// Emit slash event
|
|
620
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
621
|
+
{
|
|
622
|
+
validator: proposer,
|
|
623
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
624
|
+
offenseType: OffenseType.DUPLICATE_PROPOSAL,
|
|
625
|
+
epochOrSlot: BigInt(slot)
|
|
626
|
+
}
|
|
627
|
+
]);
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Handle detection of a duplicate attestation (equivocation).
|
|
631
|
+
* Emits a slash event when an attester signs attestations for different proposals at the same slot.
|
|
632
|
+
*/ handleDuplicateAttestation(info) {
|
|
633
|
+
const { slot, attester } = info;
|
|
634
|
+
this.log.warn(`Triggering slash event for duplicate attestation from ${attester.toString()} at slot ${slot}`, {
|
|
635
|
+
attester: attester.toString(),
|
|
636
|
+
slot
|
|
637
|
+
});
|
|
638
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
639
|
+
{
|
|
640
|
+
validator: attester,
|
|
641
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
642
|
+
offenseType: OffenseType.DUPLICATE_ATTESTATION,
|
|
643
|
+
epochOrSlot: BigInt(slot)
|
|
644
|
+
}
|
|
645
|
+
]);
|
|
646
|
+
}
|
|
647
|
+
async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
|
|
648
|
+
// Validate that we're not creating a proposal for an older or equal position
|
|
649
|
+
if (this.lastProposedBlock) {
|
|
650
|
+
const lastSlot = this.lastProposedBlock.slotNumber;
|
|
651
|
+
const lastIndex = this.lastProposedBlock.indexWithinCheckpoint;
|
|
652
|
+
const newSlot = blockHeader.globalVariables.slotNumber;
|
|
653
|
+
if (newSlot < lastSlot || newSlot === lastSlot && indexWithinCheckpoint <= lastIndex) {
|
|
654
|
+
throw new Error(`Cannot create block proposal for slot ${newSlot} index ${indexWithinCheckpoint}: ` + `already proposed block for slot ${lastSlot} index ${lastIndex}`);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
|
|
658
|
+
const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
297
659
|
...options,
|
|
298
660
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
299
661
|
});
|
|
300
|
-
this.
|
|
662
|
+
this.lastProposedBlock = newProposal;
|
|
301
663
|
return newProposal;
|
|
302
664
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
this.
|
|
306
|
-
|
|
665
|
+
async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options = {}) {
|
|
666
|
+
// Validate that we're not creating a proposal for an older or equal slot
|
|
667
|
+
if (this.lastProposedCheckpoint) {
|
|
668
|
+
const lastSlot = this.lastProposedCheckpoint.slotNumber;
|
|
669
|
+
const newSlot = checkpointHeader.slotNumber;
|
|
670
|
+
if (newSlot <= lastSlot) {
|
|
671
|
+
throw new Error(`Cannot create checkpoint proposal for slot ${newSlot}: ` + `already proposed checkpoint for slot ${lastSlot}`);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
675
|
+
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options);
|
|
676
|
+
this.lastProposedCheckpoint = newProposal;
|
|
677
|
+
return newProposal;
|
|
307
678
|
}
|
|
308
679
|
async broadcastBlockProposal(proposal) {
|
|
309
680
|
await this.p2pClient.broadcastProposal(proposal);
|
|
310
681
|
}
|
|
311
|
-
async signAttestationsAndSigners(attestationsAndSigners, proposer) {
|
|
312
|
-
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
|
|
682
|
+
async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber) {
|
|
683
|
+
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
|
|
313
684
|
}
|
|
314
685
|
async collectOwnAttestations(proposal) {
|
|
315
|
-
const slot = proposal.
|
|
686
|
+
const slot = proposal.slotNumber;
|
|
316
687
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
317
688
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
|
|
318
689
|
inCommittee
|
|
319
690
|
});
|
|
320
|
-
const attestations = await this.
|
|
691
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
692
|
+
if (!attestations) {
|
|
693
|
+
return [];
|
|
694
|
+
}
|
|
321
695
|
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
322
696
|
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
323
697
|
// due to inactivity for missed attestations.
|
|
324
|
-
void this.p2pClient.
|
|
698
|
+
void this.p2pClient.broadcastCheckpointAttestations(attestations).catch((err)=>{
|
|
325
699
|
this.log.error(`Failed to broadcast self-attestations for slot ${slot}`, err);
|
|
326
700
|
});
|
|
327
701
|
return attestations;
|
|
328
702
|
}
|
|
329
703
|
async collectAttestations(proposal, required, deadline) {
|
|
330
|
-
// Wait and poll the p2pClient's attestation pool for this
|
|
331
|
-
const slot = proposal.
|
|
704
|
+
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
705
|
+
const slot = proposal.slotNumber;
|
|
332
706
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
333
707
|
if (+deadline < this.dateProvider.now()) {
|
|
334
708
|
this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
|
|
@@ -339,13 +713,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
339
713
|
const myAddresses = this.getValidatorAddresses();
|
|
340
714
|
let attestations = [];
|
|
341
715
|
while(true){
|
|
342
|
-
// Filter out attestations with a mismatching
|
|
716
|
+
// Filter out attestations with a mismatching archive. This should NOT happen since we have verified
|
|
343
717
|
// the proposer signature (ie our own) before accepting the attestation into the pool via the p2p client.
|
|
344
|
-
const collectedAttestations = (await this.p2pClient.
|
|
345
|
-
if (!attestation.
|
|
346
|
-
this.log.warn(`Received attestation for slot ${slot} with mismatched
|
|
347
|
-
|
|
348
|
-
|
|
718
|
+
const collectedAttestations = (await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalId)).filter((attestation)=>{
|
|
719
|
+
if (!attestation.archive.equals(proposal.archive)) {
|
|
720
|
+
this.log.warn(`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`, {
|
|
721
|
+
attestationArchive: attestation.archive.toString(),
|
|
722
|
+
proposalArchive: proposal.archive.toString()
|
|
349
723
|
});
|
|
350
724
|
return false;
|
|
351
725
|
}
|
|
@@ -377,11 +751,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
377
751
|
await sleep(this.config.attestationPollingIntervalMs);
|
|
378
752
|
}
|
|
379
753
|
}
|
|
380
|
-
async createBlockAttestationsFromProposal(proposal, attestors = []) {
|
|
381
|
-
const attestations = await this.validationService.attestToProposal(proposal, attestors);
|
|
382
|
-
await this.p2pClient.addAttestations(attestations);
|
|
383
|
-
return attestations;
|
|
384
|
-
}
|
|
385
754
|
async handleAuthRequest(peer, msg) {
|
|
386
755
|
const authRequest = AuthRequest.fromBuffer(msg);
|
|
387
756
|
const statusMessage = await this.p2pClient.handleAuthRequestFromPeer(authRequest, peer).catch((_)=>undefined);
|
|
@@ -396,7 +765,11 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
396
765
|
return Buffer.alloc(0);
|
|
397
766
|
}
|
|
398
767
|
const payloadToSign = authRequest.getPayloadToSign();
|
|
399
|
-
|
|
768
|
+
// AUTH_REQUEST doesn't require HA protection - multiple signatures are safe
|
|
769
|
+
const context = {
|
|
770
|
+
dutyType: DutyType.AUTH_REQUEST
|
|
771
|
+
};
|
|
772
|
+
const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign, context);
|
|
400
773
|
const authResponse = new AuthResponse(statusMessage, signature);
|
|
401
774
|
return authResponse.toBuffer();
|
|
402
775
|
}
|