@aztec/sequencer-client 0.67.1-devnet → 0.68.0

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.
@@ -283,6 +283,7 @@ export class Sequencer {
283
283
  const pendingTxs = await this.p2pClient.getPendingTxs();
284
284
 
285
285
  if (!this.shouldProposeBlock(historicalHeader, { pendingTxsCount: pendingTxs.length })) {
286
+ await this.claimEpochProofRightIfAvailable(slot);
286
287
  return;
287
288
  }
288
289
 
@@ -315,6 +316,7 @@ export class Sequencer {
315
316
 
316
317
  // Bail if we don't have enough valid txs
317
318
  if (!this.shouldProposeBlock(historicalHeader, { validTxsCount: validTxs.length })) {
319
+ await this.claimEpochProofRightIfAvailable(slot);
318
320
  return;
319
321
  }
320
322
 
@@ -428,7 +430,7 @@ export class Sequencer {
428
430
  );
429
431
 
430
432
  // We need to have at least minTxsPerBLock txs.
431
- if (args.pendingTxsCount != undefined && args.pendingTxsCount < this.minTxsPerBLock) {
433
+ if (args.pendingTxsCount !== undefined && args.pendingTxsCount < this.minTxsPerBLock) {
432
434
  this.log.verbose(
433
435
  `Not creating block because not enough txs in the pool (got ${args.pendingTxsCount} min ${this.minTxsPerBLock})`,
434
436
  );
@@ -436,7 +438,7 @@ export class Sequencer {
436
438
  }
437
439
 
438
440
  // Bail if we don't have enough valid txs
439
- if (args.validTxsCount != undefined && args.validTxsCount < this.minTxsPerBLock) {
441
+ if (args.validTxsCount !== undefined && args.validTxsCount < this.minTxsPerBLock) {
440
442
  this.log.verbose(
441
443
  `Not creating block because not enough valid txs loaded from the pool (got ${args.validTxsCount} min ${this.minTxsPerBLock})`,
442
444
  );
@@ -499,7 +501,12 @@ export class Sequencer {
499
501
  const orchestratorFork = await this.worldState.fork();
500
502
 
501
503
  try {
502
- const processor = this.publicProcessorFactory.create(publicProcessorFork, historicalHeader, newGlobalVariables);
504
+ const processor = this.publicProcessorFactory.create(
505
+ publicProcessorFork,
506
+ historicalHeader,
507
+ newGlobalVariables,
508
+ true,
509
+ );
503
510
  const blockBuildingTimer = new Timer();
504
511
  const blockBuilder = this.blockBuilderFactory.create(orchestratorFork);
505
512
  await blockBuilder.startNewBlock(newGlobalVariables, l1ToL2Messages);
@@ -512,7 +519,12 @@ export class Sequencer {
512
519
  this.log.verbose(`Dropping failed txs ${Tx.getHashes(failedTxData).join(', ')}`);
513
520
  await this.p2pClient.deleteTxs(Tx.getHashes(failedTxData));
514
521
  }
522
+
523
+ const start = process.hrtime.bigint();
515
524
  await blockBuilder.addTxs(processedTxs);
525
+ const end = process.hrtime.bigint();
526
+ const duration = Number(end - start) / 1_000;
527
+ this.metrics.recordBlockBuilderTreeInsertions(duration);
516
528
 
517
529
  await interrupt?.(processedTxs);
518
530
 
@@ -701,7 +713,7 @@ export class Sequencer {
701
713
  // Find out which epoch we are currently in
702
714
  const epochToProve = await this.publisher.getClaimableEpoch();
703
715
  if (epochToProve === undefined) {
704
- this.log.debug(`No epoch to prove`);
716
+ this.log.trace(`No epoch to prove at slot ${slotNumber}`);
705
717
  return undefined;
706
718
  }
707
719
 
@@ -714,7 +726,10 @@ export class Sequencer {
714
726
  });
715
727
  // ensure these quotes are still valid for the slot and have the contract validate them
716
728
  const validQuotesPromise = Promise.all(
717
- quotes.filter(x => x.payload.validUntilSlot >= slotNumber).map(x => this.publisher.validateProofQuote(x)),
729
+ quotes
730
+ .filter(x => x.payload.validUntilSlot >= slotNumber)
731
+ .filter(x => x.payload.epochToProve === epochToProve)
732
+ .map(x => this.publisher.validateProofQuote(x)),
718
733
  );
719
734
 
720
735
  const validQuotes = (await validQuotesPromise).filter((q): q is EpochProofQuote => !!q);
@@ -727,7 +742,7 @@ export class Sequencer {
727
742
  (a: EpochProofQuote, b: EpochProofQuote) => a.payload.basisPointFee - b.payload.basisPointFee,
728
743
  );
729
744
  const quote = sortedQuotes[0];
730
- this.log.info(`Selected proof quote for proof claim`, quote.payload);
745
+ this.log.info(`Selected proof quote for proof claim`, { quote: quote.toInspect() });
731
746
  return quote;
732
747
  } catch (err) {
733
748
  this.log.error(`Failed to create proof claim for previous epoch`, err, { slotNumber });
@@ -787,6 +802,29 @@ export class Sequencer {
787
802
  return toReturn;
788
803
  }
789
804
 
805
+ @trackSpan(
806
+ 'Sequencer.claimEpochProofRightIfAvailable',
807
+ slotNumber => ({ [Attributes.SLOT_NUMBER]: Number(slotNumber) }),
808
+ epoch => ({ [Attributes.EPOCH_NUMBER]: Number(epoch) }),
809
+ )
810
+ /** Collects an epoch proof quote if there is an epoch to prove, and submits it to the L1 contract. */
811
+ protected async claimEpochProofRightIfAvailable(slotNumber: bigint) {
812
+ const proofQuote = await this.createProofClaimForPreviousEpoch(slotNumber);
813
+ if (proofQuote === undefined) {
814
+ return;
815
+ }
816
+
817
+ const epoch = proofQuote.payload.epochToProve;
818
+ const ctx = { slotNumber, epoch, quote: proofQuote.toInspect() };
819
+ this.log.verbose(`Claiming proof right for epoch ${epoch}`, ctx);
820
+ const success = await this.publisher.claimEpochProofRight(proofQuote);
821
+ if (!success) {
822
+ throw new Error(`Failed to claim proof right for epoch ${epoch}`);
823
+ }
824
+ this.log.info(`Claimed proof right for epoch ${epoch}`, ctx);
825
+ return epoch;
826
+ }
827
+
790
828
  /**
791
829
  * Returns whether all dependencies have caught up.
792
830
  * We don't check against the previous block submitted since it may have been reorg'd out.