@aztec/validator-client 0.0.1-commit.4d3c002 → 0.0.1-commit.4d9804df
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 +12 -9
- package/dest/checkpoint_builder.d.ts +6 -4
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +16 -8
- package/dest/config.d.ts +9 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +23 -5
- package/dest/duties/validation_service.d.ts +12 -13
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +32 -38
- package/dest/factory.d.ts +4 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +16 -4
- package/dest/key_store/web3signer_key_store.d.ts +10 -2
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
- package/dest/key_store/web3signer_key_store.js +32 -41
- package/dest/metrics.d.ts +5 -1
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +12 -0
- package/dest/proposal_handler.d.ts +71 -13
- package/dest/proposal_handler.d.ts.map +1 -1
- package/dest/proposal_handler.js +400 -156
- package/dest/validator.d.ts +30 -11
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +215 -62
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +16 -7
- package/src/config.ts +31 -7
- package/src/duties/validation_service.ts +51 -47
- package/src/factory.ts +20 -1
- package/src/key_store/web3signer_key_store.ts +43 -59
- package/src/metrics.ts +18 -0
- package/src/proposal_handler.ts +466 -179
- package/src/validator.ts +281 -80
package/dest/validator.js
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
import { getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
2
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { FifoSet } from '@aztec/foundation/fifo-set';
|
|
2
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
5
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
4
6
|
import { sleep } from '@aztec/foundation/sleep';
|
|
5
7
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
6
8
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
7
|
-
import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
9
|
+
import { OffenseType, WANT_TO_CLEAR_SLASH_EVENT, WANT_TO_SLASH_EVENT, getOffenseTypeName } from '@aztec/slasher';
|
|
8
10
|
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
11
|
+
import { ConsensusTimetable } from '@aztec/stdlib/timetable';
|
|
9
12
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
10
13
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
11
14
|
import { createHASigner, createLocalSignerWithProtection, createSignerFromSharedDb } from '@aztec/validator-ha-signer/factory';
|
|
12
15
|
import { DutyType } from '@aztec/validator-ha-signer/types';
|
|
13
16
|
import { EventEmitter } from 'events';
|
|
17
|
+
import { DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS } from './config.js';
|
|
14
18
|
import { ValidationService } from './duties/validation_service.js';
|
|
15
19
|
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
16
20
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
17
21
|
import { ValidatorMetrics } from './metrics.js';
|
|
18
|
-
import { ProposalHandler } from './proposal_handler.js';
|
|
22
|
+
import { ProposalHandler, SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT, SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT } from './proposal_handler.js';
|
|
19
23
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
20
24
|
// Just cap the set to avoid unbounded growth.
|
|
21
25
|
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
'state_mismatch',
|
|
25
|
-
'failed_txs'
|
|
26
|
-
];
|
|
26
|
+
const MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS = 1000;
|
|
27
|
+
const MAX_TRACKED_BAD_ATTESTATIONS = 10_000;
|
|
27
28
|
/**
|
|
28
29
|
* Validator Client
|
|
29
30
|
*/ export class ValidatorClient extends EventEmitter {
|
|
@@ -51,14 +52,18 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
51
52
|
epochCacheUpdateLoop;
|
|
52
53
|
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */ lastAttestedEpochByAttester;
|
|
53
54
|
proposersOfInvalidBlocks;
|
|
55
|
+
invalidCheckpointProposalOffenseKeys;
|
|
56
|
+
oversizedProposalOffenseKeys;
|
|
57
|
+
badAttestationOffenseKeys;
|
|
54
58
|
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */ lastAttestedProposal;
|
|
55
59
|
constructor(keyStore, epochCache, p2pClient, proposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
56
|
-
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.proposalHandler = proposalHandler, 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 =
|
|
60
|
+
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.proposalHandler = proposalHandler, 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 = FifoSet.withLimit(MAX_PROPOSERS_OF_INVALID_BLOCKS), this.invalidCheckpointProposalOffenseKeys = FifoSet.withLimit(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS), this.oversizedProposalOffenseKeys = FifoSet.withLimit(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS), this.badAttestationOffenseKeys = FifoSet.withLimit(MAX_TRACKED_BAD_ATTESTATIONS);
|
|
57
61
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
58
62
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
59
63
|
this.tracer = telemetry.getTracer('Validator');
|
|
60
64
|
this.metrics = new ValidatorMetrics(telemetry);
|
|
61
|
-
this.validationService = new ValidationService(keyStore, this.log.createChild('validation-service'));
|
|
65
|
+
this.validationService = new ValidationService(keyStore, this.getSignatureContext(), this.log.createChild('validation-service'));
|
|
66
|
+
this.proposalHandler.setCheckpointProposalValidationFailureCallback((proposal, result, proposalInfo)=>this.handleInvalidCheckpointProposal(proposal, result, proposalInfo));
|
|
62
67
|
// Refresh epoch cache every second to trigger alert if participation in committee changes
|
|
63
68
|
this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
|
|
64
69
|
const myAddresses = this.getValidatorAddresses();
|
|
@@ -108,13 +113,24 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
108
113
|
this.log.error(`Error updating epoch committee`, err);
|
|
109
114
|
}
|
|
110
115
|
}
|
|
111
|
-
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), slashingProtectionDb) {
|
|
116
|
+
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, reexecutionTracker, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), slashingProtectionDb) {
|
|
112
117
|
const metrics = new ValidatorMetrics(telemetry);
|
|
113
|
-
const
|
|
118
|
+
const consensusTimetable = new ConsensusTimetable({
|
|
119
|
+
l1Constants: epochCache.getL1Constants(),
|
|
120
|
+
blockDuration: config.blockDurationMs / 1000
|
|
121
|
+
});
|
|
122
|
+
const blockProposalValidator = new BlockProposalValidator(epochCache, consensusTimetable, {
|
|
114
123
|
txsPermitted: !config.disableTransactions,
|
|
115
|
-
maxTxsPerBlock: config.validateMaxTxsPerBlock
|
|
124
|
+
maxTxsPerBlock: config.validateMaxTxsPerBlock,
|
|
125
|
+
maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
|
|
126
|
+
skipSlotValidation: config.skipProposalSlotValidation,
|
|
127
|
+
signatureContext: {
|
|
128
|
+
chainId: config.l1ChainId,
|
|
129
|
+
rollupAddress: config.rollupAddress
|
|
130
|
+
},
|
|
131
|
+
clockDisparityMs: config.maxGossipClockDisparityMs ?? DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS
|
|
116
132
|
});
|
|
117
|
-
const proposalHandler = new ProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, blobClient, metrics, dateProvider, telemetry);
|
|
133
|
+
const proposalHandler = new ProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, consensusTimetable, config, blobClient, reexecutionTracker, metrics, dateProvider, telemetry, undefined);
|
|
118
134
|
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
119
135
|
let slashingProtectionSigner;
|
|
120
136
|
if (slashingProtectionDb) {
|
|
@@ -155,6 +171,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
155
171
|
signWithAddress(addr, msg, context) {
|
|
156
172
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
157
173
|
}
|
|
174
|
+
getSignatureContext() {
|
|
175
|
+
return {
|
|
176
|
+
chainId: this.config.l1ChainId,
|
|
177
|
+
rollupAddress: this.config.rollupAddress
|
|
178
|
+
};
|
|
179
|
+
}
|
|
158
180
|
getCoinbaseForAttestor(attestor) {
|
|
159
181
|
return this.keyStore.getCoinbaseAddress(attestor);
|
|
160
182
|
}
|
|
@@ -164,16 +186,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
164
186
|
getConfig() {
|
|
165
187
|
return this.config;
|
|
166
188
|
}
|
|
189
|
+
hasProposalEquivocation(slotNumber) {
|
|
190
|
+
return this.proposalHandler.hasProposalEquivocation(slotNumber);
|
|
191
|
+
}
|
|
192
|
+
hasInvalidProposals(slotNumber) {
|
|
193
|
+
return this.proposalHandler.hasInvalidProposals(slotNumber);
|
|
194
|
+
}
|
|
167
195
|
updateConfig(config) {
|
|
168
196
|
this.config = {
|
|
169
197
|
...this.config,
|
|
170
198
|
...config
|
|
171
199
|
};
|
|
200
|
+
this.proposalHandler.updateConfig(config);
|
|
172
201
|
}
|
|
173
202
|
reloadKeystore(newManager) {
|
|
174
203
|
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
175
204
|
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
176
|
-
this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
|
|
205
|
+
this.validationService = new ValidationService(this.keyStore, this.getSignatureContext(), this.log.createChild('validation-service'));
|
|
177
206
|
}
|
|
178
207
|
async start() {
|
|
179
208
|
if (this.epochCacheUpdateLoop.isRunning()) {
|
|
@@ -211,10 +240,17 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
211
240
|
this.p2pClient.registerDuplicateProposalCallback((info)=>{
|
|
212
241
|
this.handleDuplicateProposal(info);
|
|
213
242
|
});
|
|
243
|
+
// Oversized proposal handler - triggers slashing for proposals beyond the per-checkpoint block limit
|
|
244
|
+
this.p2pClient.registerOversizedProposalCallback((info)=>{
|
|
245
|
+
this.handleOversizedProposal(info);
|
|
246
|
+
});
|
|
214
247
|
// Duplicate attestation handler - triggers slashing for attestation equivocation
|
|
215
248
|
this.p2pClient.registerDuplicateAttestationCallback((info)=>{
|
|
216
249
|
this.handleDuplicateAttestation(info);
|
|
217
250
|
});
|
|
251
|
+
this.p2pClient.registerCheckpointAttestationCallback((attestation)=>{
|
|
252
|
+
this.handleCheckpointAttestation(attestation);
|
|
253
|
+
});
|
|
218
254
|
const myAddresses = this.getValidatorAddresses();
|
|
219
255
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
220
256
|
await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
|
|
@@ -254,11 +290,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
254
290
|
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
255
291
|
fishermanMode: this.config.fishermanMode || false
|
|
256
292
|
});
|
|
257
|
-
// Reexecute
|
|
258
|
-
|
|
259
|
-
const { slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
260
|
-
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n || partOfCommittee || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
|
|
261
|
-
const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
|
|
293
|
+
// Reexecute outside the escape hatch so slashing observers can detect invalid proposals even when penalties are 0.
|
|
294
|
+
const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !escapeHatchOpen);
|
|
262
295
|
if (!validationResult.isValid) {
|
|
263
296
|
const reason = validationResult.reason || 'unknown';
|
|
264
297
|
this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
|
|
@@ -276,10 +309,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
276
309
|
// Node issues so we can't validate
|
|
277
310
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
278
311
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
312
|
+
if (!escapeHatchOpen && validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)) {
|
|
313
|
+
this.log.info(`Detected invalid block proposal offense`, {
|
|
314
|
+
...proposalInfo,
|
|
315
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
316
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL)
|
|
317
|
+
});
|
|
282
318
|
this.slashInvalidBlock(proposal);
|
|
319
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
283
320
|
}
|
|
284
321
|
return false;
|
|
285
322
|
}
|
|
@@ -308,9 +345,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
308
345
|
this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
|
|
309
346
|
return undefined;
|
|
310
347
|
}
|
|
348
|
+
// Early-out for equivocation: refuses if we've already attested to a higher slot.
|
|
349
|
+
if (!this.shouldAttestToSlot(proposalSlotNumber)) {
|
|
350
|
+
return undefined;
|
|
351
|
+
}
|
|
311
352
|
// Ignore proposals from ourselves (may happen in HA setups)
|
|
312
353
|
if (proposer && this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
313
|
-
this.log.debug(`
|
|
354
|
+
this.log.debug(`Not attesting to block proposal from self for slot ${proposalSlotNumber}`, {
|
|
314
355
|
proposer: proposer.toString(),
|
|
315
356
|
proposalSlotNumber
|
|
316
357
|
});
|
|
@@ -330,14 +371,17 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
330
371
|
});
|
|
331
372
|
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
|
|
332
373
|
// Uses the cached result from the all-nodes callback if available (avoids double validation).
|
|
374
|
+
let checkpointNumber;
|
|
333
375
|
if (this.config.skipCheckpointProposalValidation) {
|
|
334
376
|
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
377
|
+
checkpointNumber = CheckpointNumber(0);
|
|
335
378
|
} else {
|
|
336
379
|
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
337
380
|
if (!validationResult.isValid) {
|
|
338
381
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
339
382
|
return undefined;
|
|
340
383
|
}
|
|
384
|
+
checkpointNumber = validationResult.checkpointNumber;
|
|
341
385
|
}
|
|
342
386
|
// Check that I have any address in current committee before attesting
|
|
343
387
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
@@ -384,7 +428,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
384
428
|
});
|
|
385
429
|
return undefined;
|
|
386
430
|
}
|
|
387
|
-
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
431
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
|
|
388
432
|
}
|
|
389
433
|
/**
|
|
390
434
|
* Checks if we should attest to a slot based on equivocation prevention rules.
|
|
@@ -401,12 +445,12 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
401
445
|
}
|
|
402
446
|
return true;
|
|
403
447
|
}
|
|
404
|
-
async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
|
|
448
|
+
async createCheckpointAttestationsFromProposal(proposal, attestors = [], checkpointNumber) {
|
|
405
449
|
// Equivocation check: must happen right before signing to minimize the race window
|
|
406
450
|
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
407
451
|
return undefined;
|
|
408
452
|
}
|
|
409
|
-
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
453
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
|
|
410
454
|
// Track the proposal we attested to (to prevent equivocation)
|
|
411
455
|
this.lastAttestedProposal = proposal;
|
|
412
456
|
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
@@ -416,7 +460,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
416
460
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
417
461
|
*/ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
|
|
418
462
|
try {
|
|
419
|
-
const lastBlockHeader = await this.blockSource.
|
|
463
|
+
const lastBlockHeader = (await this.blockSource.getBlockData({
|
|
464
|
+
archive: proposal.archive
|
|
465
|
+
}))?.header;
|
|
420
466
|
if (!lastBlockHeader) {
|
|
421
467
|
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
422
468
|
return;
|
|
@@ -444,11 +490,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
444
490
|
this.log.warn(`Cannot slash proposal with invalid signature`);
|
|
445
491
|
return;
|
|
446
492
|
}
|
|
447
|
-
// Trim the set if it's too big.
|
|
448
|
-
if (this.proposersOfInvalidBlocks.size > MAX_PROPOSERS_OF_INVALID_BLOCKS) {
|
|
449
|
-
// remove oldest proposer. `values` is guaranteed to be in insertion order.
|
|
450
|
-
this.proposersOfInvalidBlocks.delete(this.proposersOfInvalidBlocks.values().next().value);
|
|
451
|
-
}
|
|
452
493
|
this.proposersOfInvalidBlocks.add(proposer.toString());
|
|
453
494
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
454
495
|
{
|
|
@@ -459,17 +500,122 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
459
500
|
}
|
|
460
501
|
]);
|
|
461
502
|
}
|
|
503
|
+
handleInvalidCheckpointProposal(proposal, result, proposalInfo) {
|
|
504
|
+
if (!SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT[result.reason]) {
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
// The slot is already marked invalid by the all-nodes checkpoint handler that invokes this callback,
|
|
508
|
+
// so we only emit the proposer slash event here.
|
|
509
|
+
if (this.slashInvalidCheckpointProposal(proposal)) {
|
|
510
|
+
this.log.info(`Detected invalid checkpoint proposal offense`, {
|
|
511
|
+
...proposalInfo,
|
|
512
|
+
reason: result.reason,
|
|
513
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
514
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL)
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
slashInvalidCheckpointProposal(proposal) {
|
|
519
|
+
const proposer = proposal.getSender();
|
|
520
|
+
if (!proposer) {
|
|
521
|
+
this.log.warn(`Cannot slash checkpoint proposal with invalid signature`, {
|
|
522
|
+
slotNumber: proposal.slotNumber,
|
|
523
|
+
archive: proposal.archive.toString()
|
|
524
|
+
});
|
|
525
|
+
return false;
|
|
526
|
+
}
|
|
527
|
+
const offenseType = OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL;
|
|
528
|
+
const offenseKey = `${proposer.toString()}:${offenseType}:${proposal.slotNumber}`;
|
|
529
|
+
if (!this.invalidCheckpointProposalOffenseKeys.addIfAbsent(offenseKey)) {
|
|
530
|
+
return false;
|
|
531
|
+
}
|
|
532
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
533
|
+
{
|
|
534
|
+
validator: proposer,
|
|
535
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
536
|
+
offenseType,
|
|
537
|
+
epochOrSlot: BigInt(proposal.slotNumber)
|
|
538
|
+
}
|
|
539
|
+
]);
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
markInvalidProposalSlot(slotNumber) {
|
|
543
|
+
this.proposalHandler.markInvalidProposalSlot(slotNumber);
|
|
544
|
+
}
|
|
545
|
+
handleCheckpointAttestation(attestation) {
|
|
546
|
+
const slotNumber = attestation.slotNumber;
|
|
547
|
+
if (!this.proposalHandler.hasInvalidProposals(slotNumber) || this.proposalHandler.hasProposalEquivocation(slotNumber)) {
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
const attester = attestation.getSender();
|
|
551
|
+
if (!attester) {
|
|
552
|
+
this.log.warn(`Cannot slash checkpoint attestation with invalid signature`, {
|
|
553
|
+
slotNumber,
|
|
554
|
+
archive: attestation.archive.toString()
|
|
555
|
+
});
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
this.slashAttestedToInvalidCheckpointProposal(slotNumber, attester);
|
|
559
|
+
}
|
|
560
|
+
slashAttestedToInvalidCheckpointProposal(slotNumber, attester) {
|
|
561
|
+
const offenseKey = `${attester.toString()}:${OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL}:${slotNumber}`;
|
|
562
|
+
if (!this.badAttestationOffenseKeys.addIfAbsent(offenseKey)) {
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
this.log.info(`Detected attestation to invalid checkpoint proposal offense`, {
|
|
566
|
+
attester: attester.toString(),
|
|
567
|
+
slotNumber,
|
|
568
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
569
|
+
offenseType: getOffenseTypeName(OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL)
|
|
570
|
+
});
|
|
571
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
572
|
+
{
|
|
573
|
+
validator: attester,
|
|
574
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
575
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
576
|
+
epochOrSlot: BigInt(slotNumber)
|
|
577
|
+
}
|
|
578
|
+
]);
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Handle detection of an oversized block proposal: one whose index within its checkpoint lands at or
|
|
582
|
+
* beyond the consensus per-checkpoint block limit. A single signed proposal at an illegal index is
|
|
583
|
+
* self-contained evidence, so emit an invalid-block-proposal slash event for the proposer, deduped per
|
|
584
|
+
* (proposer, slot) since the p2p layer reports every oversized proposal it stores.
|
|
585
|
+
*/ handleOversizedProposal(info) {
|
|
586
|
+
const { slot, proposer } = info;
|
|
587
|
+
const offenseType = OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL;
|
|
588
|
+
if (!this.oversizedProposalOffenseKeys.addIfAbsent(`${proposer.toString()}:${offenseType}:${slot}`)) {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
this.log.info(`Detected oversized block proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
592
|
+
proposer: proposer.toString(),
|
|
593
|
+
slot,
|
|
594
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
595
|
+
offenseType: getOffenseTypeName(offenseType)
|
|
596
|
+
});
|
|
597
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
598
|
+
{
|
|
599
|
+
validator: proposer,
|
|
600
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
601
|
+
offenseType,
|
|
602
|
+
epochOrSlot: BigInt(slot)
|
|
603
|
+
}
|
|
604
|
+
]);
|
|
605
|
+
}
|
|
462
606
|
/**
|
|
463
607
|
* Handle detection of a duplicate proposal (equivocation).
|
|
464
608
|
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
465
609
|
*/ handleDuplicateProposal(info) {
|
|
466
610
|
const { slot, proposer, type } = info;
|
|
467
|
-
this.
|
|
611
|
+
this.proposalHandler.markProposalEquivocation(slot);
|
|
612
|
+
this.log.info(`Detected duplicate ${type} proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
468
613
|
proposer: proposer.toString(),
|
|
469
614
|
slot,
|
|
470
|
-
type
|
|
615
|
+
type,
|
|
616
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
617
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_PROPOSAL)
|
|
471
618
|
});
|
|
472
|
-
// Emit slash event
|
|
473
619
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
474
620
|
{
|
|
475
621
|
validator: proposer,
|
|
@@ -478,15 +624,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
478
624
|
epochOrSlot: BigInt(slot)
|
|
479
625
|
}
|
|
480
626
|
]);
|
|
627
|
+
this.emit(WANT_TO_CLEAR_SLASH_EVENT, [
|
|
628
|
+
{
|
|
629
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
630
|
+
epochOrSlot: BigInt(slot)
|
|
631
|
+
}
|
|
632
|
+
]);
|
|
481
633
|
}
|
|
482
634
|
/**
|
|
483
635
|
* Handle detection of a duplicate attestation (equivocation).
|
|
484
636
|
* Emits a slash event when an attester signs attestations for different proposals at the same slot.
|
|
485
637
|
*/ handleDuplicateAttestation(info) {
|
|
486
638
|
const { slot, attester } = info;
|
|
487
|
-
this.log.
|
|
639
|
+
this.log.info(`Detected duplicate attestation offense from ${attester.toString()} at slot ${slot}`, {
|
|
488
640
|
attester: attester.toString(),
|
|
489
|
-
slot
|
|
641
|
+
slot,
|
|
642
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
643
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_ATTESTATION)
|
|
490
644
|
});
|
|
491
645
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
492
646
|
{
|
|
@@ -497,7 +651,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
497
651
|
}
|
|
498
652
|
]);
|
|
499
653
|
}
|
|
500
|
-
async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
|
|
654
|
+
async createBlockProposal(blockHeader, checkpointNumber, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
|
|
501
655
|
// Validate that we're not creating a proposal for an older or equal position
|
|
502
656
|
if (this.lastProposedBlock) {
|
|
503
657
|
const lastSlot = this.lastProposedBlock.slotNumber;
|
|
@@ -508,14 +662,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
508
662
|
}
|
|
509
663
|
}
|
|
510
664
|
this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
|
|
511
|
-
const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
665
|
+
const newProposal = await this.validationService.createBlockProposal(blockHeader, checkpointNumber, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
512
666
|
...options,
|
|
513
|
-
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
667
|
+
broadcastInvalidBlockProposal: options.broadcastInvalidBlockProposal || this.config.broadcastInvalidBlockProposal
|
|
514
668
|
});
|
|
515
669
|
this.lastProposedBlock = newProposal;
|
|
516
670
|
return newProposal;
|
|
517
671
|
}
|
|
518
|
-
async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier,
|
|
672
|
+
async createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options = {}) {
|
|
519
673
|
// Validate that we're not creating a proposal for an older or equal slot
|
|
520
674
|
if (this.lastProposedCheckpoint) {
|
|
521
675
|
const lastSlot = this.lastProposedCheckpoint.slotNumber;
|
|
@@ -525,23 +679,30 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
525
679
|
}
|
|
526
680
|
}
|
|
527
681
|
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
528
|
-
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier,
|
|
682
|
+
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAddress, options);
|
|
529
683
|
this.lastProposedCheckpoint = newProposal;
|
|
684
|
+
// Self-record this slot's outcome on the re-execution tracker. Proposers don't run their
|
|
685
|
+
// own proposals through `handleCheckpointProposal`, so without this call the proposer's
|
|
686
|
+
// sentinel would see no outcome for slots it proposed and would mis-attribute itself as
|
|
687
|
+
// inactive. We pass the locally-computed `archive` (not `newProposal.archive`, which may
|
|
688
|
+
// be intentionally corrupted under test-only flags); from the proposer's local-view
|
|
689
|
+
// perspective the work it just completed is valid by definition.
|
|
690
|
+
this.proposalHandler.recordOwnCheckpointProposalAsValid(checkpointHeader.slotNumber, archive, checkpointNumber);
|
|
530
691
|
return newProposal;
|
|
531
692
|
}
|
|
532
693
|
async broadcastBlockProposal(proposal) {
|
|
533
694
|
await this.p2pClient.broadcastProposal(proposal);
|
|
534
695
|
}
|
|
535
|
-
async signAttestationsAndSigners(attestationsAndSigners, proposer, slot,
|
|
536
|
-
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot,
|
|
696
|
+
async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, checkpointNumber) {
|
|
697
|
+
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, checkpointNumber);
|
|
537
698
|
}
|
|
538
|
-
async collectOwnAttestations(proposal) {
|
|
699
|
+
async collectOwnAttestations(proposal, checkpointNumber) {
|
|
539
700
|
const slot = proposal.slotNumber;
|
|
540
701
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
541
702
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
|
|
542
703
|
inCommittee
|
|
543
704
|
});
|
|
544
|
-
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
705
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
|
|
545
706
|
if (!attestations) {
|
|
546
707
|
return [];
|
|
547
708
|
}
|
|
@@ -553,7 +714,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
553
714
|
});
|
|
554
715
|
return attestations;
|
|
555
716
|
}
|
|
556
|
-
async collectAttestations(proposal, required, deadline) {
|
|
717
|
+
async collectAttestations(proposal, required, deadline, checkpointNumber) {
|
|
557
718
|
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
558
719
|
const slot = proposal.slotNumber;
|
|
559
720
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
@@ -561,28 +722,20 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
561
722
|
this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
|
|
562
723
|
throw new AttestationTimeoutError(0, required, slot);
|
|
563
724
|
}
|
|
564
|
-
await this.collectOwnAttestations(proposal);
|
|
565
|
-
const
|
|
725
|
+
await this.collectOwnAttestations(proposal, checkpointNumber);
|
|
726
|
+
const proposalPayloadHash = proposal.getPayloadHash();
|
|
566
727
|
const myAddresses = this.getValidatorAddresses();
|
|
567
728
|
let attestations = [];
|
|
568
729
|
while(true){
|
|
569
|
-
//
|
|
570
|
-
//
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
this.log.warn(`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`, {
|
|
574
|
-
attestationArchive: attestation.archive.toString(),
|
|
575
|
-
proposalArchive: proposal.archive.toString()
|
|
576
|
-
});
|
|
577
|
-
return false;
|
|
578
|
-
}
|
|
579
|
-
return true;
|
|
580
|
-
});
|
|
730
|
+
// The pool already filters by proposal payload hash; if any attestation slips through with a
|
|
731
|
+
// mismatched payload hash, drop it defensively. Equivocations are emitted as separate slash
|
|
732
|
+
// events from libp2p_service.
|
|
733
|
+
const collectedAttestations = await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalPayloadHash);
|
|
581
734
|
// Log new attestations we collected
|
|
582
735
|
const oldSenders = attestations.map((attestation)=>attestation.getSender());
|
|
583
736
|
for (const collected of collectedAttestations){
|
|
584
737
|
const collectedSender = collected.getSender();
|
|
585
|
-
// Skip attestations with invalid signatures
|
|
738
|
+
// Skip attestations with invalid signatures. Should not happen as we don't add invalid attestations to our pool.
|
|
586
739
|
if (!collectedSender) {
|
|
587
740
|
this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
|
|
588
741
|
continue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/validator-client",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.4d9804df",
|
|
4
4
|
"main": "dest/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -64,30 +64,30 @@
|
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@aztec/blob-client": "0.0.1-commit.
|
|
68
|
-
"@aztec/blob-lib": "0.0.1-commit.
|
|
69
|
-
"@aztec/constants": "0.0.1-commit.
|
|
70
|
-
"@aztec/epoch-cache": "0.0.1-commit.
|
|
71
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
72
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
73
|
-
"@aztec/node-keystore": "0.0.1-commit.
|
|
74
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
75
|
-
"@aztec/p2p": "0.0.1-commit.
|
|
76
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
77
|
-
"@aztec/prover-client": "0.0.1-commit.
|
|
78
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
79
|
-
"@aztec/slasher": "0.0.1-commit.
|
|
80
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
81
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
82
|
-
"@aztec/validator-ha-signer": "0.0.1-commit.
|
|
67
|
+
"@aztec/blob-client": "0.0.1-commit.4d9804df",
|
|
68
|
+
"@aztec/blob-lib": "0.0.1-commit.4d9804df",
|
|
69
|
+
"@aztec/constants": "0.0.1-commit.4d9804df",
|
|
70
|
+
"@aztec/epoch-cache": "0.0.1-commit.4d9804df",
|
|
71
|
+
"@aztec/ethereum": "0.0.1-commit.4d9804df",
|
|
72
|
+
"@aztec/foundation": "0.0.1-commit.4d9804df",
|
|
73
|
+
"@aztec/node-keystore": "0.0.1-commit.4d9804df",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.4d9804df",
|
|
75
|
+
"@aztec/p2p": "0.0.1-commit.4d9804df",
|
|
76
|
+
"@aztec/protocol-contracts": "0.0.1-commit.4d9804df",
|
|
77
|
+
"@aztec/prover-client": "0.0.1-commit.4d9804df",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.4d9804df",
|
|
79
|
+
"@aztec/slasher": "0.0.1-commit.4d9804df",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.4d9804df",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.4d9804df",
|
|
82
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.4d9804df",
|
|
83
83
|
"koa": "^2.16.1",
|
|
84
84
|
"koa-router": "^13.1.1",
|
|
85
85
|
"tslib": "^2.4.0",
|
|
86
86
|
"viem": "npm:@aztec/viem@2.38.2"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
|
-
"@aztec/archiver": "0.0.1-commit.
|
|
90
|
-
"@aztec/world-state": "0.0.1-commit.
|
|
89
|
+
"@aztec/archiver": "0.0.1-commit.4d9804df",
|
|
90
|
+
"@aztec/world-state": "0.0.1-commit.4d9804df",
|
|
91
91
|
"@electric-sql/pglite": "^0.3.14",
|
|
92
92
|
"@jest/globals": "^30.0.0",
|
|
93
93
|
"@types/jest": "^30.0.0",
|
|
@@ -9,6 +9,7 @@ import { DateProvider, elapsed } from '@aztec/foundation/timer';
|
|
|
9
9
|
import { createTxValidatorForBlockBuilding, getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
|
|
10
10
|
import { LightweightCheckpointBuilder } from '@aztec/prover-client/light';
|
|
11
11
|
import {
|
|
12
|
+
type AvmSimulator,
|
|
12
13
|
GuardedMerkleTreeOperations,
|
|
13
14
|
PublicContractsDB,
|
|
14
15
|
PublicProcessor,
|
|
@@ -57,6 +58,7 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
57
58
|
private contractDataSource: ContractDataSource,
|
|
58
59
|
private dateProvider: DateProvider,
|
|
59
60
|
private telemetryClient: TelemetryClient,
|
|
61
|
+
private avmSimulator: AvmSimulator,
|
|
60
62
|
bindings?: LoggerBindings,
|
|
61
63
|
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
62
64
|
) {
|
|
@@ -219,10 +221,12 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
219
221
|
if (opts.isBuildingProposal) {
|
|
220
222
|
const remainingBlocks = Math.max(1, opts.maxBlocksPerCheckpoint - existingBlocks.length);
|
|
221
223
|
const multiplier = opts.perBlockAllocationMultiplier;
|
|
224
|
+
// DA gas and blob fields use a higher multiplier so the largest contract class deploy fits a block.
|
|
225
|
+
const daMultiplier = opts.perBlockDAAllocationMultiplier ?? multiplier;
|
|
222
226
|
|
|
223
227
|
cappedL2Gas = Math.min(cappedL2Gas, Math.ceil((remainingMana / remainingBlocks) * multiplier));
|
|
224
|
-
cappedDAGas = Math.min(cappedDAGas, Math.ceil((remainingDAGas / remainingBlocks) *
|
|
225
|
-
cappedBlobFields = Math.min(cappedBlobFields, Math.ceil((maxBlobFieldsForTxs / remainingBlocks) *
|
|
228
|
+
cappedDAGas = Math.min(cappedDAGas, Math.ceil((remainingDAGas / remainingBlocks) * daMultiplier));
|
|
229
|
+
cappedBlobFields = Math.min(cappedBlobFields, Math.ceil((maxBlobFieldsForTxs / remainingBlocks) * daMultiplier));
|
|
226
230
|
cappedMaxTransactions = Math.min(cappedMaxTransactions, Math.ceil((remainingTxs / remainingBlocks) * multiplier));
|
|
227
231
|
}
|
|
228
232
|
|
|
@@ -241,16 +245,18 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
241
245
|
const contractsDB = this.contractsDB;
|
|
242
246
|
const guardedFork = new GuardedMerkleTreeOperations(fork);
|
|
243
247
|
|
|
244
|
-
const collectDebugLogs = this.debugLogStore.isEnabled;
|
|
245
|
-
|
|
246
248
|
const bindings = this.log.getBindings();
|
|
249
|
+
// Extract the WSDB fork ID so the C++ AVM can modify the same fork in-place; the simulator reads
|
|
250
|
+
// contract data from `contractsDB`, scoped to this fork for the duration of each simulation.
|
|
251
|
+
const wsdbForkId = fork.getRevision().forkId;
|
|
247
252
|
const publicTxSimulator = createPublicTxSimulatorForBlockBuilding(
|
|
248
|
-
|
|
249
|
-
contractsDB,
|
|
253
|
+
this.avmSimulator,
|
|
250
254
|
globalVariables,
|
|
255
|
+
contractsDB,
|
|
256
|
+
wsdbForkId,
|
|
251
257
|
this.telemetryClient,
|
|
252
258
|
bindings,
|
|
253
|
-
|
|
259
|
+
this.debugLogStore?.isEnabled ?? false,
|
|
254
260
|
);
|
|
255
261
|
|
|
256
262
|
const processor = new PublicProcessor(
|
|
@@ -289,6 +295,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
289
295
|
private worldState: WorldStateSynchronizer,
|
|
290
296
|
private contractDataSource: ContractDataSource,
|
|
291
297
|
private dateProvider: DateProvider,
|
|
298
|
+
private avmSimulator: AvmSimulator,
|
|
292
299
|
private telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
293
300
|
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
294
301
|
) {
|
|
@@ -344,6 +351,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
344
351
|
this.contractDataSource,
|
|
345
352
|
this.dateProvider,
|
|
346
353
|
this.telemetryClient,
|
|
354
|
+
this.avmSimulator,
|
|
347
355
|
bindings,
|
|
348
356
|
this.debugLogStore,
|
|
349
357
|
);
|
|
@@ -405,6 +413,7 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
405
413
|
this.contractDataSource,
|
|
406
414
|
this.dateProvider,
|
|
407
415
|
this.telemetryClient,
|
|
416
|
+
this.avmSimulator,
|
|
408
417
|
bindings,
|
|
409
418
|
this.debugLogStore,
|
|
410
419
|
);
|