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