@aztec/validator-client 0.0.1-commit.6d3c34e → 0.0.1-commit.7035c9bd6
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 +94 -24
- package/dest/block_proposal_handler.d.ts +12 -11
- package/dest/block_proposal_handler.d.ts.map +1 -1
- package/dest/block_proposal_handler.js +140 -77
- package/dest/checkpoint_builder.d.ts +35 -26
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +144 -48
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +33 -14
- package/dest/duties/validation_service.d.ts +20 -7
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +69 -22
- package/dest/factory.d.ts +4 -2
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +4 -3
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/key_store/ha_key_store.d.ts +99 -0
- package/dest/key_store/ha_key_store.d.ts.map +1 -0
- package/dest/key_store/ha_key_store.js +208 -0
- package/dest/key_store/index.d.ts +2 -1
- package/dest/key_store/index.d.ts.map +1 -1
- package/dest/key_store/index.js +1 -0
- package/dest/key_store/interface.d.ts +36 -6
- package/dest/key_store/interface.d.ts.map +1 -1
- package/dest/key_store/local_key_store.d.ts +10 -5
- package/dest/key_store/local_key_store.d.ts.map +1 -1
- package/dest/key_store/local_key_store.js +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 -5
- package/dest/validator.d.ts +45 -18
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +276 -107
- package/package.json +21 -17
- package/src/block_proposal_handler.ts +171 -95
- package/src/checkpoint_builder.ts +211 -61
- package/src/config.ts +32 -13
- package/src/duties/validation_service.ts +94 -25
- package/src/factory.ts +5 -0
- package/src/index.ts +0 -1
- package/src/key_store/ha_key_store.ts +269 -0
- package/src/key_store/index.ts +1 -0
- package/src/key_store/interface.ts +44 -5
- package/src/key_store/local_key_store.ts +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 -6
- package/src/validator.ts +354 -130
- package/dest/tx_validator/index.d.ts +0 -3
- package/dest/tx_validator/index.d.ts.map +0 -1
- package/dest/tx_validator/index.js +0 -2
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -53
- package/src/tx_validator/index.ts +0 -2
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -133
package/dest/validator.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
2
|
-
import {
|
|
2
|
+
import { validateFeeAssetPriceModifier } from '@aztec/ethereum/contracts';
|
|
3
|
+
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
4
|
import { TimeoutError } from '@aztec/foundation/error';
|
|
4
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
6
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
@@ -8,11 +9,17 @@ import { sleep } from '@aztec/foundation/sleep';
|
|
|
8
9
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
9
10
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
10
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';
|
|
11
15
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
12
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';
|
|
13
19
|
import { EventEmitter } from 'events';
|
|
14
20
|
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
15
21
|
import { ValidationService } from './duties/validation_service.js';
|
|
22
|
+
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
16
23
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
17
24
|
import { ValidatorMetrics } from './metrics.js';
|
|
18
25
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
@@ -36,6 +43,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
36
43
|
l1ToL2MessageSource;
|
|
37
44
|
config;
|
|
38
45
|
blobClient;
|
|
46
|
+
slashingProtectionSigner;
|
|
39
47
|
dateProvider;
|
|
40
48
|
tracer;
|
|
41
49
|
validationService;
|
|
@@ -43,17 +51,15 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
43
51
|
log;
|
|
44
52
|
// Whether it has already registered handlers on the p2p client
|
|
45
53
|
hasRegisteredHandlers;
|
|
46
|
-
|
|
47
|
-
|
|
54
|
+
/** Tracks the last block proposal we created, to detect duplicate proposal attempts. */ lastProposedBlock;
|
|
55
|
+
/** Tracks the last checkpoint proposal we created. */ lastProposedCheckpoint;
|
|
48
56
|
lastEpochForCommitteeUpdateLoop;
|
|
49
57
|
epochCacheUpdateLoop;
|
|
58
|
+
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */ lastAttestedEpochByAttester;
|
|
50
59
|
proposersOfInvalidBlocks;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
validatedBlockSlots;
|
|
55
|
-
constructor(keyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
56
|
-
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.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.proposersOfInvalidBlocks = new Set(), this.validatedBlockSlots = new Set();
|
|
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();
|
|
57
63
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
58
64
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
59
65
|
this.tracer = telemetry.getTracer('Validator');
|
|
@@ -92,6 +98,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
92
98
|
this.log.trace(`No committee found for slot`);
|
|
93
99
|
return;
|
|
94
100
|
}
|
|
101
|
+
this.metrics.setCurrentEpoch(epoch);
|
|
95
102
|
if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
|
|
96
103
|
const me = this.getValidatorAddresses();
|
|
97
104
|
const committeeSet = new Set(committee.map((v)=>v.toString()));
|
|
@@ -107,13 +114,42 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
107
114
|
this.log.error(`Error updating epoch committee`, err);
|
|
108
115
|
}
|
|
109
116
|
}
|
|
110
|
-
static new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
117
|
+
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), slashingProtectionDb) {
|
|
111
118
|
const metrics = new ValidatorMetrics(telemetry);
|
|
112
119
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
113
|
-
txsPermitted: !config.disableTransactions
|
|
120
|
+
txsPermitted: !config.disableTransactions,
|
|
121
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock
|
|
114
122
|
});
|
|
115
|
-
const blockProposalHandler = new BlockProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, config, metrics, dateProvider, telemetry);
|
|
116
|
-
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);
|
|
117
153
|
return validator;
|
|
118
154
|
}
|
|
119
155
|
getValidatorAddresses() {
|
|
@@ -122,8 +158,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
122
158
|
getBlockProposalHandler() {
|
|
123
159
|
return this.blockProposalHandler;
|
|
124
160
|
}
|
|
125
|
-
signWithAddress(addr, msg) {
|
|
126
|
-
return this.keyStore.signTypedDataWithAddress(addr, msg);
|
|
161
|
+
signWithAddress(addr, msg, context) {
|
|
162
|
+
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
127
163
|
}
|
|
128
164
|
getCoinbaseForAttestor(attestor) {
|
|
129
165
|
return this.keyStore.getCoinbaseAddress(attestor);
|
|
@@ -140,11 +176,17 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
140
176
|
...config
|
|
141
177
|
};
|
|
142
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
|
+
}
|
|
143
184
|
async start() {
|
|
144
185
|
if (this.epochCacheUpdateLoop.isRunning()) {
|
|
145
186
|
this.log.warn(`Validator client already started`);
|
|
146
187
|
return;
|
|
147
188
|
}
|
|
189
|
+
await this.keyStore.start();
|
|
148
190
|
await this.registerHandlers();
|
|
149
191
|
const myAddresses = this.getValidatorAddresses();
|
|
150
192
|
const inCommittee = await this.epochCache.filterInCommittee('now', myAddresses);
|
|
@@ -157,6 +199,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
157
199
|
}
|
|
158
200
|
async stop() {
|
|
159
201
|
await this.epochCacheUpdateLoop.stop();
|
|
202
|
+
await this.keyStore.stop();
|
|
160
203
|
}
|
|
161
204
|
/** Register handlers on the p2p client */ async registerHandlers() {
|
|
162
205
|
if (!this.hasRegisteredHandlers) {
|
|
@@ -170,6 +213,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
170
213
|
// and processed separately via the block handler above.
|
|
171
214
|
const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
172
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
|
+
});
|
|
173
224
|
const myAddresses = this.getValidatorAddresses();
|
|
174
225
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
175
226
|
await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
|
|
@@ -181,12 +232,22 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
181
232
|
* @returns true if the proposal is valid, false otherwise
|
|
182
233
|
*/ async validateBlockProposal(proposal, proposalSender) {
|
|
183
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);
|
|
184
238
|
const proposer = proposal.getSender();
|
|
185
239
|
// Reject proposals with invalid signatures
|
|
186
240
|
if (!proposer) {
|
|
187
241
|
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
188
242
|
return false;
|
|
189
243
|
}
|
|
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
|
+
}
|
|
190
251
|
// Check if we're in the committee (for metrics purposes)
|
|
191
252
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
192
253
|
const partOfCommittee = inCommittee.length > 0;
|
|
@@ -203,10 +264,10 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
203
264
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
204
265
|
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
205
266
|
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
|
|
206
|
-
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute);
|
|
267
|
+
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
|
|
207
268
|
if (!validationResult.isValid) {
|
|
208
|
-
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
209
269
|
const reason = validationResult.reason || 'unknown';
|
|
270
|
+
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
210
271
|
// Classify failure reason: bad proposal vs node issue
|
|
211
272
|
const badProposalReasons = [
|
|
212
273
|
'invalid_proposal',
|
|
@@ -222,7 +283,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
222
283
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
223
284
|
}
|
|
224
285
|
// Slash invalid block proposals (can happen even when not in committee)
|
|
225
|
-
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) {
|
|
226
287
|
this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
|
|
227
288
|
this.slashInvalidBlock(proposal);
|
|
228
289
|
}
|
|
@@ -231,11 +292,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
231
292
|
this.log.info(`Validated block proposal for slot ${slotNumber}`, {
|
|
232
293
|
...proposalInfo,
|
|
233
294
|
inCommittee: partOfCommittee,
|
|
234
|
-
fishermanMode: this.config.fishermanMode || false
|
|
295
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
296
|
+
escapeHatchOpen
|
|
235
297
|
});
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
298
|
+
if (escapeHatchOpen) {
|
|
299
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, rejecting block proposal`, proposalInfo);
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
239
302
|
return true;
|
|
240
303
|
}
|
|
241
304
|
/**
|
|
@@ -244,37 +307,46 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
244
307
|
* the lastBlock is extracted and processed separately via the block handler.
|
|
245
308
|
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
246
309
|
*/ async attestToCheckpointProposal(proposal, _proposalSender) {
|
|
247
|
-
const
|
|
310
|
+
const proposalSlotNumber = proposal.slotNumber;
|
|
248
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
|
+
}
|
|
249
317
|
// Reject proposals with invalid signatures
|
|
250
318
|
if (!proposer) {
|
|
251
|
-
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${
|
|
319
|
+
this.log.warn(`Received checkpoint proposal with invalid signature for proposal slot ${proposalSlotNumber}`);
|
|
252
320
|
return undefined;
|
|
253
321
|
}
|
|
254
|
-
//
|
|
255
|
-
|
|
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
|
+
});
|
|
328
|
+
return undefined;
|
|
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());
|
|
256
337
|
const partOfCommittee = inCommittee.length > 0;
|
|
257
338
|
const proposalInfo = {
|
|
258
|
-
|
|
339
|
+
proposalSlotNumber,
|
|
259
340
|
archive: proposal.archive.toString(),
|
|
260
|
-
proposer: proposer.toString()
|
|
261
|
-
txCount: proposal.txHashes.length
|
|
341
|
+
proposer: proposer.toString()
|
|
262
342
|
};
|
|
263
|
-
this.log.info(`Received checkpoint proposal for slot ${
|
|
343
|
+
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
264
344
|
...proposalInfo,
|
|
265
|
-
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
266
345
|
fishermanMode: this.config.fishermanMode || false
|
|
267
346
|
});
|
|
268
|
-
// TODO(palla/mbps): Remove this once checkpoint validation is stable.
|
|
269
|
-
// Check that we have successfully validated a block for this slot before attesting to the checkpoint.
|
|
270
|
-
if (!this.validatedBlockSlots.has(slotNumber)) {
|
|
271
|
-
this.log.warn(`No validated block found for slot ${slotNumber}, refusing to attest to checkpoint`, proposalInfo);
|
|
272
|
-
return undefined;
|
|
273
|
-
}
|
|
274
347
|
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
this.log.verbose(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
|
|
348
|
+
if (this.config.skipCheckpointProposalValidation) {
|
|
349
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
278
350
|
} else {
|
|
279
351
|
const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
280
352
|
if (!validationResult.isValid) {
|
|
@@ -293,12 +365,22 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
293
365
|
return undefined;
|
|
294
366
|
}
|
|
295
367
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
296
|
-
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${
|
|
368
|
+
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
297
369
|
...proposalInfo,
|
|
298
370
|
inCommittee: partOfCommittee,
|
|
299
371
|
fishermanMode: this.config.fishermanMode || false
|
|
300
372
|
});
|
|
301
373
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
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
|
+
}
|
|
302
384
|
// Determine which validators should attest
|
|
303
385
|
let attestors;
|
|
304
386
|
if (partOfCommittee) {
|
|
@@ -315,17 +397,38 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
315
397
|
}
|
|
316
398
|
if (this.config.fishermanMode) {
|
|
317
399
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
318
|
-
this.log.info(`Creating checkpoint attestations for slot ${
|
|
400
|
+
this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
|
|
319
401
|
...proposalInfo,
|
|
320
402
|
attestors: attestors.map((a)=>a.toString())
|
|
321
403
|
});
|
|
322
404
|
return undefined;
|
|
323
405
|
}
|
|
324
|
-
return this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
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;
|
|
325
422
|
}
|
|
326
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
|
+
}
|
|
327
428
|
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
328
|
-
|
|
429
|
+
// Track the proposal we attested to (to prevent equivocation)
|
|
430
|
+
this.lastAttestedProposal = proposal;
|
|
431
|
+
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
329
432
|
return attestations;
|
|
330
433
|
}
|
|
331
434
|
/**
|
|
@@ -333,7 +436,10 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
333
436
|
* @returns Validation result with isValid flag and reason if invalid.
|
|
334
437
|
*/ async validateCheckpointProposal(proposal, proposalInfo) {
|
|
335
438
|
const slot = proposal.slotNumber;
|
|
336
|
-
|
|
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));
|
|
337
443
|
// Wait for last block to sync by archive
|
|
338
444
|
let lastBlockHeader;
|
|
339
445
|
try {
|
|
@@ -362,18 +468,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
362
468
|
reason: 'last_block_not_found'
|
|
363
469
|
};
|
|
364
470
|
}
|
|
365
|
-
// Get the last full block to determine checkpoint number
|
|
366
|
-
const lastBlock = await this.blockSource.getL2BlockNew(lastBlockHeader.getBlockNumber());
|
|
367
|
-
if (!lastBlock) {
|
|
368
|
-
this.log.warn(`Last block ${lastBlockHeader.getBlockNumber()} not found`, proposalInfo);
|
|
369
|
-
return {
|
|
370
|
-
isValid: false,
|
|
371
|
-
reason: 'last_block_not_found'
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
const checkpointNumber = lastBlock.checkpointNumber;
|
|
375
471
|
// Get all full blocks for the slot and checkpoint
|
|
376
|
-
const blocks = await this.getBlocksForSlot(slot
|
|
472
|
+
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
377
473
|
if (blocks.length === 0) {
|
|
378
474
|
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
379
475
|
return {
|
|
@@ -381,6 +477,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
381
477
|
reason: 'no_blocks_for_slot'
|
|
382
478
|
};
|
|
383
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
|
+
}
|
|
384
488
|
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
385
489
|
...proposalInfo,
|
|
386
490
|
blockNumbers: blocks.map((b)=>b.number)
|
|
@@ -388,14 +492,18 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
388
492
|
// Get checkpoint constants from first block
|
|
389
493
|
const firstBlock = blocks[0];
|
|
390
494
|
const constants = this.extractCheckpointConstants(firstBlock);
|
|
495
|
+
const checkpointNumber = firstBlock.checkpointNumber;
|
|
391
496
|
// Get L1-to-L2 messages for this checkpoint
|
|
392
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);
|
|
393
501
|
// Fork world state at the block before the first block
|
|
394
502
|
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
395
503
|
const fork = await this.worldState.fork(parentBlockNumber);
|
|
396
504
|
try {
|
|
397
505
|
// Create checkpoint builder with all existing blocks
|
|
398
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, l1ToL2Messages, fork, blocks);
|
|
506
|
+
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
|
|
399
507
|
// Complete the checkpoint to get computed values
|
|
400
508
|
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
401
509
|
// Compare checkpoint header with proposal
|
|
@@ -422,6 +530,43 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
422
530
|
reason: 'archive_mismatch'
|
|
423
531
|
};
|
|
424
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
|
+
}
|
|
425
570
|
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
426
571
|
return {
|
|
427
572
|
isValid: true
|
|
@@ -431,36 +576,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
431
576
|
}
|
|
432
577
|
}
|
|
433
578
|
/**
|
|
434
|
-
* Get all full blocks for a given slot and checkpoint by walking backwards from the last block.
|
|
435
|
-
* Returns blocks in ascending order (earliest to latest).
|
|
436
|
-
* TODO(palla/mbps): Add getL2BlocksForSlot() to L2BlockSource interface for efficiency.
|
|
437
|
-
*/ async getBlocksForSlot(slot, lastBlockHeader, checkpointNumber) {
|
|
438
|
-
const blocks = [];
|
|
439
|
-
let currentHeader = lastBlockHeader;
|
|
440
|
-
const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
|
|
441
|
-
while(currentHeader.getSlot() === slot){
|
|
442
|
-
const block = await this.blockSource.getL2BlockNew(currentHeader.getBlockNumber());
|
|
443
|
-
if (!block) {
|
|
444
|
-
this.log.warn(`Block ${currentHeader.getBlockNumber()} not found while getting blocks for slot ${slot}`);
|
|
445
|
-
break;
|
|
446
|
-
}
|
|
447
|
-
if (block.checkpointNumber !== checkpointNumber) {
|
|
448
|
-
break;
|
|
449
|
-
}
|
|
450
|
-
blocks.unshift(block);
|
|
451
|
-
const prevArchive = currentHeader.lastArchive.root;
|
|
452
|
-
if (prevArchive.equals(genesisArchiveRoot)) {
|
|
453
|
-
break;
|
|
454
|
-
}
|
|
455
|
-
const prevHeader = await this.blockSource.getBlockHeaderByArchive(prevArchive);
|
|
456
|
-
if (!prevHeader || prevHeader.getSlot() !== slot) {
|
|
457
|
-
break;
|
|
458
|
-
}
|
|
459
|
-
currentHeader = prevHeader;
|
|
460
|
-
}
|
|
461
|
-
return blocks;
|
|
462
|
-
}
|
|
463
|
-
/**
|
|
464
579
|
* Extract checkpoint global variables from a block.
|
|
465
580
|
*/ extractCheckpointConstants(block) {
|
|
466
581
|
const gv = block.header.globalVariables;
|
|
@@ -468,6 +583,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
468
583
|
chainId: gv.chainId,
|
|
469
584
|
version: gv.version,
|
|
470
585
|
slotNumber: gv.slotNumber,
|
|
586
|
+
timestamp: gv.timestamp,
|
|
471
587
|
coinbase: gv.coinbase,
|
|
472
588
|
feeRecipient: gv.feeRecipient,
|
|
473
589
|
gasFees: gv.gasFees
|
|
@@ -482,19 +598,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
482
598
|
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
483
599
|
return;
|
|
484
600
|
}
|
|
485
|
-
|
|
486
|
-
const lastBlock = await this.blockSource.getL2BlockNew(lastBlockHeader.getBlockNumber());
|
|
487
|
-
if (!lastBlock) {
|
|
488
|
-
this.log.warn(`Failed to get last block for blob upload`, proposalInfo);
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
const blocks = await this.getBlocksForSlot(proposal.slotNumber, lastBlockHeader, lastBlock.checkpointNumber);
|
|
601
|
+
const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
|
|
492
602
|
if (blocks.length === 0) {
|
|
493
603
|
this.log.warn(`No blocks found for blob upload`, proposalInfo);
|
|
494
604
|
return;
|
|
495
605
|
}
|
|
496
606
|
const blobFields = blocks.flatMap((b)=>b.toBlobFields());
|
|
497
|
-
const blobs = getBlobsPerL1Block(blobFields);
|
|
607
|
+
const blobs = await getBlobsPerL1Block(blobFields);
|
|
498
608
|
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
499
609
|
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
500
610
|
...proposalInfo,
|
|
@@ -526,29 +636,81 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
526
636
|
}
|
|
527
637
|
]);
|
|
528
638
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
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
|
+
}
|
|
686
|
+
}
|
|
535
687
|
this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
|
|
536
688
|
const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
537
689
|
...options,
|
|
538
690
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
539
691
|
});
|
|
540
|
-
this.
|
|
692
|
+
this.lastProposedBlock = newProposal;
|
|
541
693
|
return newProposal;
|
|
542
694
|
}
|
|
543
|
-
async createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options) {
|
|
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
|
+
}
|
|
544
704
|
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
545
|
-
|
|
705
|
+
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options);
|
|
706
|
+
this.lastProposedCheckpoint = newProposal;
|
|
707
|
+
return newProposal;
|
|
546
708
|
}
|
|
547
709
|
async broadcastBlockProposal(proposal) {
|
|
548
710
|
await this.p2pClient.broadcastProposal(proposal);
|
|
549
711
|
}
|
|
550
|
-
async signAttestationsAndSigners(attestationsAndSigners, proposer) {
|
|
551
|
-
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
|
|
712
|
+
async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber) {
|
|
713
|
+
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
|
|
552
714
|
}
|
|
553
715
|
async collectOwnAttestations(proposal) {
|
|
554
716
|
const slot = proposal.slotNumber;
|
|
@@ -557,6 +719,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
557
719
|
inCommittee
|
|
558
720
|
});
|
|
559
721
|
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
722
|
+
if (!attestations) {
|
|
723
|
+
return [];
|
|
724
|
+
}
|
|
560
725
|
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
561
726
|
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
562
727
|
// due to inactivity for missed attestations.
|
|
@@ -630,7 +795,11 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
630
795
|
return Buffer.alloc(0);
|
|
631
796
|
}
|
|
632
797
|
const payloadToSign = authRequest.getPayloadToSign();
|
|
633
|
-
|
|
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);
|
|
634
803
|
const authResponse = new AuthResponse(statusMessage, signature);
|
|
635
804
|
return authResponse.toBuffer();
|
|
636
805
|
}
|