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