@aztec/validator-client 0.0.1-commit.fcb71a6 → 0.0.1-commit.ff7989d6c
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 +66 -0
- package/dest/checkpoint_builder.d.ts.map +1 -0
- package/dest/checkpoint_builder.js +175 -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 +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -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/tx_validator/index.d.ts +3 -0
- package/dest/tx_validator/index.d.ts.map +1 -0
- package/dest/tx_validator/index.js +2 -0
- package/dest/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/tx_validator/nullifier_cache.js +24 -0
- package/dest/tx_validator/tx_validator_factory.d.ts +19 -0
- package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -0
- package/dest/tx_validator/tx_validator_factory.js +54 -0
- package/dest/validator.d.ts +73 -24
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +452 -91
- package/package.json +21 -13
- package/src/block_proposal_handler.ts +246 -57
- package/src/checkpoint_builder.ts +321 -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 +2 -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/tx_validator/index.ts +2 -0
- package/src/tx_validator/nullifier_cache.ts +30 -0
- package/src/tx_validator/tx_validator_factory.ts +154 -0
- package/src/validator.ts +615 -120
package/dest/validator.js
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
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';
|
|
8
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
9
7
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
10
8
|
import { sleep } from '@aztec/foundation/sleep';
|
|
11
9
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
12
10
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
13
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';
|
|
14
14
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
15
|
-
import {
|
|
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';
|
|
16
18
|
import { EventEmitter } from 'events';
|
|
17
19
|
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
18
20
|
import { ValidationService } from './duties/validation_service.js';
|
|
21
|
+
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
19
22
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
20
23
|
import { ValidatorMetrics } from './metrics.js';
|
|
21
24
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
@@ -33,8 +36,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
33
36
|
epochCache;
|
|
34
37
|
p2pClient;
|
|
35
38
|
blockProposalHandler;
|
|
39
|
+
blockSource;
|
|
40
|
+
checkpointsBuilder;
|
|
41
|
+
worldState;
|
|
42
|
+
l1ToL2MessageSource;
|
|
36
43
|
config;
|
|
37
|
-
|
|
44
|
+
blobClient;
|
|
45
|
+
haSigner;
|
|
38
46
|
dateProvider;
|
|
39
47
|
tracer;
|
|
40
48
|
validationService;
|
|
@@ -42,13 +50,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
42
50
|
log;
|
|
43
51
|
// Whether it has already registered handlers on the p2p client
|
|
44
52
|
hasRegisteredHandlers;
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
/** Tracks the last block proposal we created, to detect duplicate proposal attempts. */ lastProposedBlock;
|
|
54
|
+
/** Tracks the last checkpoint proposal we created. */ lastProposedCheckpoint;
|
|
47
55
|
lastEpochForCommitteeUpdateLoop;
|
|
48
56
|
epochCacheUpdateLoop;
|
|
49
57
|
proposersOfInvalidBlocks;
|
|
50
|
-
|
|
51
|
-
|
|
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();
|
|
52
61
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
53
62
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
54
63
|
this.tracer = telemetry.getTracer('Validator');
|
|
@@ -102,13 +111,29 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
102
111
|
this.log.error(`Error updating epoch committee`, err);
|
|
103
112
|
}
|
|
104
113
|
}
|
|
105
|
-
static new(config,
|
|
114
|
+
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
106
115
|
const metrics = new ValidatorMetrics(telemetry);
|
|
107
116
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
108
117
|
txsPermitted: !config.disableTransactions
|
|
109
118
|
});
|
|
110
|
-
const blockProposalHandler = new BlockProposalHandler(
|
|
111
|
-
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);
|
|
112
137
|
return validator;
|
|
113
138
|
}
|
|
114
139
|
getValidatorAddresses() {
|
|
@@ -117,12 +142,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
117
142
|
getBlockProposalHandler() {
|
|
118
143
|
return this.blockProposalHandler;
|
|
119
144
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return this.blockProposalHandler.reexecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages);
|
|
123
|
-
}
|
|
124
|
-
signWithAddress(addr, msg) {
|
|
125
|
-
return this.keyStore.signTypedDataWithAddress(addr, msg);
|
|
145
|
+
signWithAddress(addr, msg, context) {
|
|
146
|
+
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
126
147
|
}
|
|
127
148
|
getCoinbaseForAttestor(attestor) {
|
|
128
149
|
return this.keyStore.getCoinbaseAddress(attestor);
|
|
@@ -139,11 +160,26 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
139
160
|
...config
|
|
140
161
|
};
|
|
141
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
|
+
}
|
|
142
177
|
async start() {
|
|
143
178
|
if (this.epochCacheUpdateLoop.isRunning()) {
|
|
144
179
|
this.log.warn(`Validator client already started`);
|
|
145
180
|
return;
|
|
146
181
|
}
|
|
182
|
+
await this.keyStore.start();
|
|
147
183
|
await this.registerHandlers();
|
|
148
184
|
const myAddresses = this.getValidatorAddresses();
|
|
149
185
|
const inCommittee = await this.epochCache.filterInCommittee('now', myAddresses);
|
|
@@ -156,46 +192,75 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
156
192
|
}
|
|
157
193
|
async stop() {
|
|
158
194
|
await this.epochCacheUpdateLoop.stop();
|
|
195
|
+
await this.keyStore.stop();
|
|
159
196
|
}
|
|
160
197
|
/** Register handlers on the p2p client */ async registerHandlers() {
|
|
161
198
|
if (!this.hasRegisteredHandlers) {
|
|
162
199
|
this.hasRegisteredHandlers = true;
|
|
163
200
|
this.log.debug(`Registering validator handlers for p2p client`);
|
|
164
|
-
|
|
165
|
-
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
|
+
});
|
|
166
217
|
const myAddresses = this.getValidatorAddresses();
|
|
167
218
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
168
219
|
await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
|
|
169
220
|
}
|
|
170
221
|
}
|
|
171
|
-
|
|
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) {
|
|
172
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);
|
|
173
231
|
const proposer = proposal.getSender();
|
|
174
232
|
// Reject proposals with invalid signatures
|
|
175
233
|
if (!proposer) {
|
|
176
|
-
this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
|
|
177
|
-
return
|
|
234
|
+
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
235
|
+
return false;
|
|
178
236
|
}
|
|
179
|
-
//
|
|
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)
|
|
180
246
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
181
247
|
const partOfCommittee = inCommittee.length > 0;
|
|
182
248
|
const proposalInfo = {
|
|
183
249
|
...proposal.toBlockInfo(),
|
|
184
250
|
proposer: proposer.toString()
|
|
185
251
|
};
|
|
186
|
-
this.log.info(`Received proposal for slot ${slotNumber}`, {
|
|
252
|
+
this.log.info(`Received block proposal for slot ${slotNumber}`, {
|
|
187
253
|
...proposalInfo,
|
|
188
254
|
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
189
255
|
fishermanMode: this.config.fishermanMode || false
|
|
190
256
|
});
|
|
191
|
-
// Reexecute txs if we are part of the committee
|
|
192
|
-
// 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.
|
|
193
258
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
194
259
|
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
195
|
-
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.
|
|
196
|
-
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);
|
|
197
262
|
if (!validationResult.isValid) {
|
|
198
|
-
this.log.warn(`
|
|
263
|
+
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
199
264
|
const reason = validationResult.reason || 'unknown';
|
|
200
265
|
// Classify failure reason: bad proposal vs node issue
|
|
201
266
|
const badProposalReasons = [
|
|
@@ -208,16 +273,87 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
208
273
|
if (badProposalReasons.includes(reason)) {
|
|
209
274
|
this.metrics.incFailedAttestationsBadProposal(1, reason, partOfCommittee);
|
|
210
275
|
} else {
|
|
211
|
-
// Node issues so we can't
|
|
276
|
+
// Node issues so we can't validate
|
|
212
277
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
213
278
|
}
|
|
214
279
|
// Slash invalid block proposals (can happen even when not in committee)
|
|
215
|
-
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) {
|
|
216
281
|
this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
|
|
217
282
|
this.slashInvalidBlock(proposal);
|
|
218
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}`);
|
|
219
314
|
return undefined;
|
|
220
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}`);
|
|
327
|
+
return undefined;
|
|
328
|
+
}
|
|
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
|
+
}
|
|
221
357
|
// Check that I have any address in current committee before attesting
|
|
222
358
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
223
359
|
if (!partOfCommittee && !this.config.fishermanMode) {
|
|
@@ -225,26 +361,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
225
361
|
return undefined;
|
|
226
362
|
}
|
|
227
363
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
228
|
-
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} proposal for slot ${slotNumber}`, {
|
|
364
|
+
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${slotNumber}`, {
|
|
229
365
|
...proposalInfo,
|
|
230
366
|
inCommittee: partOfCommittee,
|
|
231
367
|
fishermanMode: this.config.fishermanMode || false
|
|
232
368
|
});
|
|
233
369
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
234
|
-
// Upload blobs to filestore after successful re-execution (fire-and-forget)
|
|
235
|
-
if (validationResult.reexecutionResult?.block && this.fileStoreBlobUploadClient) {
|
|
236
|
-
void Promise.resolve().then(async ()=>{
|
|
237
|
-
try {
|
|
238
|
-
const blobFields = validationResult.reexecutionResult.block.getCheckpointBlobFields();
|
|
239
|
-
const blobs = getBlobsPerL1Block(blobFields);
|
|
240
|
-
await this.fileStoreBlobUploadClient.saveBlobs(blobs, true);
|
|
241
|
-
this.log.debug(`Uploaded ${blobs.length} blobs to filestore from re-execution`, proposalInfo);
|
|
242
|
-
} catch (err) {
|
|
243
|
-
this.log.warn(`Failed to upload blobs from re-execution`, err);
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
// If the above function does not throw an error, then we can attest to the proposal
|
|
248
370
|
// Determine which validators should attest
|
|
249
371
|
let attestors;
|
|
250
372
|
if (partOfCommittee) {
|
|
@@ -261,13 +383,206 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
261
383
|
}
|
|
262
384
|
if (this.config.fishermanMode) {
|
|
263
385
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
264
|
-
this.log.info(`Creating attestations for
|
|
386
|
+
this.log.info(`Creating checkpoint attestations for slot ${slotNumber}`, {
|
|
265
387
|
...proposalInfo,
|
|
266
388
|
attestors: attestors.map((a)=>a.toString())
|
|
267
389
|
});
|
|
268
390
|
return undefined;
|
|
269
391
|
}
|
|
270
|
-
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
|
+
}
|
|
271
586
|
}
|
|
272
587
|
slashInvalidBlock(proposal) {
|
|
273
588
|
const proposer = proposal.getSender();
|
|
@@ -291,50 +606,103 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
291
606
|
}
|
|
292
607
|
]);
|
|
293
608
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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, {
|
|
303
659
|
...options,
|
|
304
660
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
305
661
|
});
|
|
306
|
-
this.
|
|
662
|
+
this.lastProposedBlock = newProposal;
|
|
307
663
|
return newProposal;
|
|
308
664
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
this.
|
|
312
|
-
|
|
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;
|
|
313
678
|
}
|
|
314
679
|
async broadcastBlockProposal(proposal) {
|
|
315
680
|
await this.p2pClient.broadcastProposal(proposal);
|
|
316
681
|
}
|
|
317
|
-
async signAttestationsAndSigners(attestationsAndSigners, proposer) {
|
|
318
|
-
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
|
|
682
|
+
async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber) {
|
|
683
|
+
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
|
|
319
684
|
}
|
|
320
685
|
async collectOwnAttestations(proposal) {
|
|
321
|
-
const slot = proposal.
|
|
686
|
+
const slot = proposal.slotNumber;
|
|
322
687
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
323
688
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
|
|
324
689
|
inCommittee
|
|
325
690
|
});
|
|
326
|
-
const attestations = await this.
|
|
691
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
692
|
+
if (!attestations) {
|
|
693
|
+
return [];
|
|
694
|
+
}
|
|
327
695
|
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
328
696
|
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
329
697
|
// due to inactivity for missed attestations.
|
|
330
|
-
void this.p2pClient.
|
|
698
|
+
void this.p2pClient.broadcastCheckpointAttestations(attestations).catch((err)=>{
|
|
331
699
|
this.log.error(`Failed to broadcast self-attestations for slot ${slot}`, err);
|
|
332
700
|
});
|
|
333
701
|
return attestations;
|
|
334
702
|
}
|
|
335
703
|
async collectAttestations(proposal, required, deadline) {
|
|
336
|
-
// Wait and poll the p2pClient's attestation pool for this
|
|
337
|
-
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;
|
|
338
706
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
339
707
|
if (+deadline < this.dateProvider.now()) {
|
|
340
708
|
this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
|
|
@@ -345,13 +713,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
345
713
|
const myAddresses = this.getValidatorAddresses();
|
|
346
714
|
let attestations = [];
|
|
347
715
|
while(true){
|
|
348
|
-
// Filter out attestations with a mismatching
|
|
716
|
+
// Filter out attestations with a mismatching archive. This should NOT happen since we have verified
|
|
349
717
|
// the proposer signature (ie our own) before accepting the attestation into the pool via the p2p client.
|
|
350
|
-
const collectedAttestations = (await this.p2pClient.
|
|
351
|
-
if (!attestation.
|
|
352
|
-
this.log.warn(`Received attestation for slot ${slot} with mismatched
|
|
353
|
-
|
|
354
|
-
|
|
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()
|
|
355
723
|
});
|
|
356
724
|
return false;
|
|
357
725
|
}
|
|
@@ -383,11 +751,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
383
751
|
await sleep(this.config.attestationPollingIntervalMs);
|
|
384
752
|
}
|
|
385
753
|
}
|
|
386
|
-
async createBlockAttestationsFromProposal(proposal, attestors = []) {
|
|
387
|
-
const attestations = await this.validationService.attestToProposal(proposal, attestors);
|
|
388
|
-
await this.p2pClient.addAttestations(attestations);
|
|
389
|
-
return attestations;
|
|
390
|
-
}
|
|
391
754
|
async handleAuthRequest(peer, msg) {
|
|
392
755
|
const authRequest = AuthRequest.fromBuffer(msg);
|
|
393
756
|
const statusMessage = await this.p2pClient.handleAuthRequestFromPeer(authRequest, peer).catch((_)=>undefined);
|
|
@@ -402,14 +765,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
402
765
|
return Buffer.alloc(0);
|
|
403
766
|
}
|
|
404
767
|
const payloadToSign = authRequest.getPayloadToSign();
|
|
405
|
-
|
|
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);
|
|
406
773
|
const authResponse = new AuthResponse(statusMessage, signature);
|
|
407
774
|
return authResponse.toBuffer();
|
|
408
775
|
}
|
|
409
776
|
}
|
|
410
|
-
_ts_decorate([
|
|
411
|
-
trackSpan('validator.attestToProposal', (proposal, proposalSender)=>({
|
|
412
|
-
[Attributes.BLOCK_HASH]: proposal.payload.header.hash.toString(),
|
|
413
|
-
[Attributes.PEER_ID]: proposalSender.toString()
|
|
414
|
-
}))
|
|
415
|
-
], ValidatorClient.prototype, "attestToProposal", null);
|