@aztec/archiver 0.0.1-commit.d117d021b → 0.0.1-commit.d1da697d6
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 -6
- package/dest/archiver.d.ts +5 -7
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +56 -20
- package/dest/config.d.ts +3 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +2 -1
- package/dest/errors.d.ts +34 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +45 -16
- package/dest/factory.d.ts +3 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +19 -18
- package/dest/l1/calldata_retriever.d.ts +1 -1
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +2 -1
- package/dest/l1/data_retrieval.d.ts +2 -2
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +13 -14
- package/dest/modules/data_source_base.d.ts +8 -6
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +11 -5
- package/dest/modules/data_store_updater.d.ts +14 -11
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +78 -76
- package/dest/modules/l1_synchronizer.d.ts +4 -3
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +160 -127
- package/dest/modules/validation.d.ts +1 -1
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +2 -2
- package/dest/store/block_store.d.ts +50 -16
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +288 -119
- package/dest/store/contract_class_store.d.ts +2 -3
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +7 -67
- package/dest/store/contract_instance_store.d.ts +1 -1
- package/dest/store/contract_instance_store.d.ts.map +1 -1
- package/dest/store/contract_instance_store.js +6 -2
- package/dest/store/kv_archiver_store.d.ts +45 -22
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +57 -27
- package/dest/store/l2_tips_cache.d.ts +2 -1
- package/dest/store/l2_tips_cache.d.ts.map +1 -1
- package/dest/store/l2_tips_cache.js +25 -5
- package/dest/store/log_store.d.ts +6 -3
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +93 -16
- package/dest/store/message_store.d.ts +5 -1
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +20 -8
- package/dest/test/fake_l1_state.d.ts +16 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +77 -8
- package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +2 -1
- package/dest/test/mock_l2_block_source.d.ts +9 -4
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +32 -7
- package/dest/test/noop_l1_archiver.d.ts +4 -1
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +5 -1
- package/package.json +13 -13
- package/src/archiver.ts +62 -21
- package/src/config.ts +8 -1
- package/src/errors.ts +70 -26
- package/src/factory.ts +19 -14
- package/src/l1/calldata_retriever.ts +2 -1
- package/src/l1/data_retrieval.ts +7 -11
- package/src/modules/data_source_base.ts +26 -7
- package/src/modules/data_store_updater.ts +91 -107
- package/src/modules/l1_synchronizer.ts +174 -156
- package/src/modules/validation.ts +2 -2
- package/src/store/block_store.ts +370 -140
- package/src/store/contract_class_store.ts +8 -106
- package/src/store/contract_instance_store.ts +8 -5
- package/src/store/kv_archiver_store.ts +81 -39
- package/src/store/l2_tips_cache.ts +50 -11
- package/src/store/log_store.ts +126 -27
- package/src/store/message_store.ts +26 -9
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +103 -13
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +46 -5
- package/src/test/noop_l1_archiver.ts +7 -1
|
@@ -42,7 +42,6 @@ export declare class ArchiverL1Synchronizer implements Traceable {
|
|
|
42
42
|
}, blobClient: BlobClientInterface, epochCache: EpochCache, dateProvider: DateProvider, instrumentation: ArchiverInstrumentation, l1Constants: L1RollupConstants & {
|
|
43
43
|
l1StartBlockHash: Buffer32;
|
|
44
44
|
genesisArchiveRoot: Fr;
|
|
45
|
-
rollupManaLimit?: number;
|
|
46
45
|
}, events: ArchiverEmitter, tracer: Tracer, l2TipsCache?: L2TipsCache, log?: Logger);
|
|
47
46
|
/** Sets new config */
|
|
48
47
|
setConfig(newConfig: {
|
|
@@ -57,16 +56,18 @@ export declare class ArchiverL1Synchronizer implements Traceable {
|
|
|
57
56
|
/** Checks that the ethereum node we are connected to has a latest timestamp no more than the allowed drift. Throw if not. */
|
|
58
57
|
testEthereumNodeSynced(): Promise<void>;
|
|
59
58
|
syncFromL1(initialSyncComplete: boolean): Promise<void>;
|
|
59
|
+
private updateFinalizedCheckpoint;
|
|
60
60
|
private pruneUncheckpointedBlocks;
|
|
61
61
|
private canPrune;
|
|
62
62
|
private handleEpochPrune;
|
|
63
63
|
private nextRange;
|
|
64
64
|
private handleL1ToL2Messages;
|
|
65
|
-
private
|
|
65
|
+
private localStateMatches;
|
|
66
|
+
private retrieveAndStoreMessages;
|
|
66
67
|
private rollbackL1ToL2Messages;
|
|
67
68
|
private getL1BlockHash;
|
|
68
69
|
private handleCheckpoints;
|
|
69
70
|
private checkForNewCheckpointsBeforeL1SyncPoint;
|
|
70
71
|
private getCheckpointHeader;
|
|
71
72
|
}
|
|
72
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
73
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDFfc3luY2hyb25pemVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291c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tZQWdEdEIsY0FBYztZQVNkLGlCQUFpQjtZQWtYakIsdUNBQXVDO1lBOEN2QyxtQkFBbUI7Q0FPbEMifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"l1_synchronizer.d.ts","sourceRoot":"","sources":["../../src/modules/l1_synchronizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"l1_synchronizer.d.ts","sourceRoot":"","sources":["../../src/modules/l1_synchronizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,aAAa,EAA2B,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEnG,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAIrF,OAAO,EAAY,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,OAAO,EAAE,YAAY,EAAkB,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EAAE,KAAK,eAAe,EAAsD,MAAM,qBAAqB,CAAC;AAE/G,OAAO,EAAE,KAAK,iBAAiB,EAAwC,MAAM,6BAA6B,CAAC;AAE3G,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,MAAM,EAAyB,MAAM,yBAAyB,CAAC;AAS7F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAI7D,OAAO,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AAM,EAAE,eAAe,EACxC,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,WAAW,EACR,GAAG,GAAE,MAAyC,EAMhE;IAED,sBAAsB;IACf,SAAS,CAAC,SAAS,EAAE;QAC1B,SAAS,EAAE,MAAM,CAAC;QAClB,kCAAkC,CAAC,EAAE,OAAO,CAAC;QAC7C,+BAA+B,EAAE,MAAM,CAAC;KACzC,QAEA;IAED,wDAAwD;IACjD,gBAAgB,IAAI,MAAM,GAAG,SAAS,CAE5C;IAED,qDAAqD;IAC9C,cAAc,IAAI,MAAM,GAAG,SAAS,CAE1C;IAED,6HAA6H;IAChH,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC,CAYnD;IAGY,UAAU,CAAC,mBAAmB,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAwFnE;YAGa,yBAAyB;YAwBzB,yBAAyB;YA0CzB,QAAQ;YAeR,gBAAgB;IA+D9B,OAAO,CAAC,SAAS;YAWH,oBAAoB;YA6DpB,iBAAiB;YAWjB,wBAAwB;YAkCxB,sBAAsB;YAgDtB,cAAc;YASd,iBAAiB;YAkXjB,uCAAuC;YA8CvC,mBAAmB;CAOlC"}
|
|
@@ -371,20 +371,23 @@ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
|
371
371
|
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
372
372
|
}
|
|
373
373
|
var _dec, _dec1, _dec2, _dec3, _initProto;
|
|
374
|
+
import { asyncPool } from '@aztec/foundation/async-pool';
|
|
374
375
|
import { maxBigint } from '@aztec/foundation/bigint';
|
|
375
376
|
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
376
|
-
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
377
|
+
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
|
|
377
378
|
import { pick } from '@aztec/foundation/collection';
|
|
378
379
|
import { createLogger } from '@aztec/foundation/log';
|
|
380
|
+
import { retryTimes } from '@aztec/foundation/retry';
|
|
379
381
|
import { count } from '@aztec/foundation/string';
|
|
380
382
|
import { Timer, elapsed } from '@aztec/foundation/timer';
|
|
381
|
-
import { isDefined } from '@aztec/foundation/types';
|
|
383
|
+
import { isDefined, isErrorClass } from '@aztec/foundation/types';
|
|
382
384
|
import { L2BlockSourceEvents } from '@aztec/stdlib/block';
|
|
383
385
|
import { getEpochAtSlot, getSlotAtNextL1Block } from '@aztec/stdlib/epoch-helpers';
|
|
384
386
|
import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
385
387
|
import { execInSpan, trackSpan } from '@aztec/telemetry-client';
|
|
386
388
|
import { InitialCheckpointNumberNotSequentialError } from '../errors.js';
|
|
387
389
|
import { retrieveCheckpointsFromRollup, retrieveL1ToL2Message, retrieveL1ToL2Messages, retrievedToPublishedCheckpoint } from '../l1/data_retrieval.js';
|
|
390
|
+
import { MessageStoreError } from '../store/message_store.js';
|
|
388
391
|
import { ArchiverDataStoreUpdater } from './data_store_updater.js';
|
|
389
392
|
import { validateCheckpointAttestations } from './validation.js';
|
|
390
393
|
_dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpochPrune'), _dec2 = trackSpan('Archiver.handleL1ToL2Messages'), _dec3 = trackSpan('Archiver.handleCheckpoints');
|
|
@@ -477,12 +480,20 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
477
480
|
}
|
|
478
481
|
}
|
|
479
482
|
async syncFromL1(initialSyncComplete) {
|
|
483
|
+
// In between the various calls to L1, the block number can move meaning some of the following
|
|
484
|
+
// calls will return data for blocks that were not present during earlier calls. To combat this
|
|
485
|
+
// we ensure that all data retrieval methods only retrieve data up to the currentBlockNumber
|
|
486
|
+
// captured at the top of this function.
|
|
480
487
|
const currentL1Block = await this.publicClient.getBlock({
|
|
481
488
|
includeTransactions: false
|
|
482
489
|
});
|
|
483
490
|
const currentL1BlockNumber = currentL1Block.number;
|
|
484
491
|
const currentL1BlockHash = Buffer32.fromString(currentL1Block.hash);
|
|
485
492
|
const currentL1Timestamp = currentL1Block.timestamp;
|
|
493
|
+
const currentL1BlockData = {
|
|
494
|
+
l1BlockNumber: currentL1BlockNumber,
|
|
495
|
+
l1BlockHash: currentL1BlockHash
|
|
496
|
+
};
|
|
486
497
|
if (this.l1BlockHash && currentL1BlockHash.equals(this.l1BlockHash)) {
|
|
487
498
|
this.log.trace(`No new L1 blocks since last sync at L1 block ${this.l1BlockNumber}`);
|
|
488
499
|
return;
|
|
@@ -498,36 +509,16 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
498
509
|
maxAllowedDelay
|
|
499
510
|
});
|
|
500
511
|
}
|
|
501
|
-
// Load sync point for blocks
|
|
502
|
-
const { blocksSynchedTo = this.l1Constants.l1StartBlock
|
|
503
|
-
l1BlockNumber: this.l1Constants.l1StartBlock,
|
|
504
|
-
l1BlockHash: this.l1Constants.l1StartBlockHash
|
|
505
|
-
} } = await this.store.getSynchPoint();
|
|
512
|
+
// Load sync point for blocks defaulting to start block
|
|
513
|
+
const { blocksSynchedTo = this.l1Constants.l1StartBlock } = await this.store.getSynchPoint();
|
|
506
514
|
this.log.debug(`Starting new archiver sync iteration`, {
|
|
507
515
|
blocksSynchedTo,
|
|
508
|
-
|
|
509
|
-
currentL1BlockNumber,
|
|
510
|
-
currentL1BlockHash
|
|
516
|
+
currentL1BlockData
|
|
511
517
|
});
|
|
512
|
-
//
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
* to ensure that data is read exactly once.
|
|
517
|
-
*
|
|
518
|
-
* The first is the problem of eventually consistent ETH service providers like Infura.
|
|
519
|
-
* Each L1 read operation will query data from the last L1 block that it saw emit its kind of data.
|
|
520
|
-
* (so pending L1 to L2 messages will read from the last L1 block that emitted a message and so on)
|
|
521
|
-
* This will mean the archiver will lag behind L1 and will only advance when there's L2-relevant activity on the chain.
|
|
522
|
-
*
|
|
523
|
-
* The second is that in between the various calls to L1, the block number can move meaning some
|
|
524
|
-
* of the following calls will return data for blocks that were not present during earlier calls.
|
|
525
|
-
* To combat this for the time being we simply ensure that all data retrieval methods only retrieve
|
|
526
|
-
* data up to the currentBlockNumber captured at the top of this function. We might want to improve on this
|
|
527
|
-
* in future but for the time being it should give us the guarantees that we need
|
|
528
|
-
*/ // ********** Events that are processed per L1 block **********
|
|
529
|
-
await this.handleL1ToL2Messages(messagesSynchedTo, currentL1BlockNumber);
|
|
530
|
-
// ********** Events that are processed per checkpoint **********
|
|
518
|
+
// Sync L1 to L2 messages. We retry this a few times since there are error conditions that reset the sync point, requiring a new iteration.
|
|
519
|
+
// Note that we cannot just wait for the l1 synchronizer to loop again, since the synchronizer would report as synced up to the current L1
|
|
520
|
+
// block, when that wouldn't be the case, since L1 to L2 messages would need another iteration.
|
|
521
|
+
await retryTimes(()=>this.handleL1ToL2Messages(currentL1BlockData), 'Handling L1 to L2 messages', 3, 0.1);
|
|
531
522
|
if (currentL1BlockNumber > blocksSynchedTo) {
|
|
532
523
|
// First we retrieve new checkpoints and L2 blocks and store them in the DB. This will also update the
|
|
533
524
|
// pending chain validation status, proven checkpoint number, and synched L1 block number.
|
|
@@ -555,6 +546,8 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
555
546
|
}
|
|
556
547
|
this.instrumentation.updateL1BlockHeight(currentL1BlockNumber);
|
|
557
548
|
}
|
|
549
|
+
// Update the finalized L2 checkpoint based on L1 finality.
|
|
550
|
+
await this.updateFinalizedCheckpoint();
|
|
558
551
|
// After syncing has completed, update the current l1 block number and timestamp,
|
|
559
552
|
// otherwise we risk announcing to the world that we've synced to a given point,
|
|
560
553
|
// but the corresponding blocks have not been processed (see #12631).
|
|
@@ -568,6 +561,31 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
568
561
|
l1BlockNumberAtEnd
|
|
569
562
|
});
|
|
570
563
|
}
|
|
564
|
+
/** Query L1 for its finalized block and update the finalized checkpoint accordingly. */ async updateFinalizedCheckpoint() {
|
|
565
|
+
try {
|
|
566
|
+
const finalizedL1Block = await this.publicClient.getBlock({
|
|
567
|
+
blockTag: 'finalized',
|
|
568
|
+
includeTransactions: false
|
|
569
|
+
});
|
|
570
|
+
const finalizedL1BlockNumber = finalizedL1Block.number;
|
|
571
|
+
const finalizedCheckpointNumber = await this.rollup.getProvenCheckpointNumber({
|
|
572
|
+
blockNumber: finalizedL1BlockNumber
|
|
573
|
+
});
|
|
574
|
+
const localFinalizedCheckpointNumber = await this.store.getFinalizedCheckpointNumber();
|
|
575
|
+
if (localFinalizedCheckpointNumber !== finalizedCheckpointNumber) {
|
|
576
|
+
await this.updater.setFinalizedCheckpointNumber(finalizedCheckpointNumber);
|
|
577
|
+
this.log.info(`Updated finalized chain to checkpoint ${finalizedCheckpointNumber}`, {
|
|
578
|
+
finalizedCheckpointNumber,
|
|
579
|
+
finalizedL1BlockNumber
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
} catch (err) {
|
|
583
|
+
// The rollup contract may not exist at the finalized L1 block right after deployment.
|
|
584
|
+
if (!err?.message?.includes('returned no data')) {
|
|
585
|
+
this.log.warn(`Failed to update finalized checkpoint: ${err}`);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
571
589
|
/** Prune all proposed local blocks that should have been checkpointed by now. */ async pruneUncheckpointedBlocks(currentL1Timestamp) {
|
|
572
590
|
const [lastCheckpointedBlockNumber, lastProposedBlockNumber] = await Promise.all([
|
|
573
591
|
this.store.getCheckpointedL2BlockNumber(),
|
|
@@ -578,26 +596,28 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
578
596
|
this.log.trace(`No uncheckpointed blocks to prune.`);
|
|
579
597
|
return;
|
|
580
598
|
}
|
|
581
|
-
// What's the slot
|
|
599
|
+
// What's the slot at the next L1 block? All blocks for slots strictly before this one should've been checkpointed by now.
|
|
600
|
+
const slotAtNextL1Block = getSlotAtNextL1Block(currentL1Timestamp, this.l1Constants);
|
|
582
601
|
const firstUncheckpointedBlockNumber = BlockNumber(lastCheckpointedBlockNumber + 1);
|
|
602
|
+
// What's the slot of the first uncheckpointed block?
|
|
583
603
|
const [firstUncheckpointedBlockHeader] = await this.store.getBlockHeaders(firstUncheckpointedBlockNumber, 1);
|
|
584
604
|
const firstUncheckpointedBlockSlot = firstUncheckpointedBlockHeader?.getSlot();
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
605
|
+
if (firstUncheckpointedBlockSlot === undefined || firstUncheckpointedBlockSlot >= slotAtNextL1Block) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
// Prune provisional blocks from slots that have ended without being checkpointed.
|
|
609
|
+
// This also clears any proposed checkpoint whose blocks are being pruned.
|
|
610
|
+
this.log.warn(`Pruning blocks after block ${lastCheckpointedBlockNumber} due to slot ${firstUncheckpointedBlockSlot} not being checkpointed`, {
|
|
611
|
+
firstUncheckpointedBlockHeader: firstUncheckpointedBlockHeader.toInspect(),
|
|
612
|
+
slotAtNextL1Block
|
|
613
|
+
});
|
|
614
|
+
const prunedBlocks = await this.updater.removeUncheckpointedBlocksAfter(lastCheckpointedBlockNumber);
|
|
615
|
+
if (prunedBlocks.length > 0) {
|
|
616
|
+
this.events.emit(L2BlockSourceEvents.L2PruneUncheckpointed, {
|
|
617
|
+
type: L2BlockSourceEvents.L2PruneUncheckpointed,
|
|
618
|
+
slotNumber: firstUncheckpointedBlockSlot,
|
|
619
|
+
blocks: prunedBlocks
|
|
592
620
|
});
|
|
593
|
-
const prunedBlocks = await this.updater.removeUncheckpointedBlocksAfter(lastCheckpointedBlockNumber);
|
|
594
|
-
if (prunedBlocks.length > 0) {
|
|
595
|
-
this.events.emit(L2BlockSourceEvents.L2PruneUncheckpointed, {
|
|
596
|
-
type: L2BlockSourceEvents.L2PruneUncheckpointed,
|
|
597
|
-
slotNumber: firstUncheckpointedBlockSlot,
|
|
598
|
-
blocks: prunedBlocks
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
621
|
}
|
|
602
622
|
}
|
|
603
623
|
/** Queries the rollup contract on whether a prune can be executed on the immediate next L1 block. */ async canPrune(currentL1BlockNumber, currentL1Timestamp) {
|
|
@@ -628,12 +648,14 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
628
648
|
const pruneFromSlotNumber = header.slotNumber;
|
|
629
649
|
const pruneFromEpochNumber = getEpochAtSlot(pruneFromSlotNumber, this.l1Constants);
|
|
630
650
|
const checkpointsToUnwind = localPendingCheckpointNumber - provenCheckpointNumber;
|
|
631
|
-
|
|
651
|
+
// Fetch checkpoints and blocks in bounded batches to avoid unbounded concurrent
|
|
652
|
+
// promises when the gap between local pending and proven checkpoint numbers is large.
|
|
653
|
+
const BATCH_SIZE = 10;
|
|
654
|
+
const indices = Array.from({
|
|
632
655
|
length: checkpointsToUnwind
|
|
633
|
-
}
|
|
634
|
-
const checkpoints = await
|
|
635
|
-
const
|
|
636
|
-
const newBlocks = blockPromises.filter(isDefined).flat();
|
|
656
|
+
}, (_, i)=>CheckpointNumber(i + pruneFrom));
|
|
657
|
+
const checkpoints = (await asyncPool(BATCH_SIZE, indices, (idx)=>this.store.getCheckpointData(idx))).filter(isDefined);
|
|
658
|
+
const newBlocks = (await asyncPool(BATCH_SIZE, checkpoints, (cp)=>this.store.getBlocksForCheckpoint(CheckpointNumber(cp.checkpointNumber)))).filter(isDefined).flat();
|
|
637
659
|
// Emit an event for listening services to react to the chain prune
|
|
638
660
|
this.events.emit(L2BlockSourceEvents.L2PruneUnproven, {
|
|
639
661
|
type: L2BlockSourceEvents.L2PruneUnproven,
|
|
@@ -667,55 +689,75 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
667
689
|
nextEnd
|
|
668
690
|
];
|
|
669
691
|
}
|
|
670
|
-
async handleL1ToL2Messages(
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
692
|
+
async handleL1ToL2Messages(currentL1Block) {
|
|
693
|
+
// Load the syncpoint, which may have been updated in a previous iteration
|
|
694
|
+
const { messagesSynchedTo = {
|
|
695
|
+
l1BlockNumber: this.l1Constants.l1StartBlock,
|
|
696
|
+
l1BlockHash: this.l1Constants.l1StartBlockHash
|
|
697
|
+
} } = await this.store.getSynchPoint();
|
|
698
|
+
// Nothing to do if L1 block number has not moved forward
|
|
699
|
+
const currentL1BlockNumber = currentL1Block.l1BlockNumber;
|
|
700
|
+
if (currentL1BlockNumber <= messagesSynchedTo.l1BlockNumber) {
|
|
701
|
+
return true;
|
|
674
702
|
}
|
|
675
|
-
//
|
|
676
|
-
const localMessagesInserted = await this.store.getTotalL1ToL2MessageCount();
|
|
677
|
-
const localLastMessage = await this.store.getLastL1ToL2Message();
|
|
703
|
+
// Compare local message store state with the remote. If they match, we just advance the match pointer.
|
|
678
704
|
const remoteMessagesState = await this.inbox.getState({
|
|
679
705
|
blockNumber: currentL1BlockNumber
|
|
680
706
|
});
|
|
681
|
-
this.
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
remoteMessagesState
|
|
685
|
-
|
|
686
|
-
// Compare message count and rolling hash. If they match, no need to retrieve anything.
|
|
687
|
-
if (remoteMessagesState.totalMessagesInserted === localMessagesInserted && remoteMessagesState.messagesRollingHash.equals(localLastMessage?.rollingHash ?? Buffer32.ZERO)) {
|
|
688
|
-
this.log.trace(`No L1 to L2 messages to query between L1 blocks ${messagesSyncPoint.l1BlockNumber} and ${currentL1BlockNumber}.`);
|
|
689
|
-
return;
|
|
707
|
+
const localLastMessage = await this.store.getLastL1ToL2Message();
|
|
708
|
+
if (await this.localStateMatches(localLastMessage, remoteMessagesState)) {
|
|
709
|
+
this.log.trace(`Local L1 to L2 messages are already in sync with remote at L1 block ${currentL1BlockNumber}`);
|
|
710
|
+
await this.store.setMessageSyncState(currentL1Block, remoteMessagesState.treeInProgress);
|
|
711
|
+
return true;
|
|
690
712
|
}
|
|
691
|
-
//
|
|
692
|
-
//
|
|
693
|
-
//
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
this.
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
this.log.warn(`Rolling back L1 to L2 messages due to hash mismatch or msg not found.`, {
|
|
702
|
-
remoteLastMessage,
|
|
703
|
-
messagesSyncPoint,
|
|
704
|
-
localLastMessage
|
|
705
|
-
});
|
|
706
|
-
messagesSyncPoint = await this.rollbackL1ToL2Messages(localLastMessage, messagesSyncPoint);
|
|
707
|
-
this.log.debug(`Rolled back L1 to L2 messages to L1 block ${messagesSyncPoint.l1BlockNumber}.`, {
|
|
708
|
-
messagesSyncPoint
|
|
713
|
+
// If not, then we are out of sync. Most likely there are new messages on the inbox, so we try retrieving them.
|
|
714
|
+
// However, it could also be the case that there was an L1 reorg and our syncpoint is no longer valid.
|
|
715
|
+
// If that's the case, we'd get an exception out of the message store since the rolling hash of the first message
|
|
716
|
+
// we try to insert would not match the one in the db, in which case we rollback to the last common message with L1.
|
|
717
|
+
try {
|
|
718
|
+
await this.retrieveAndStoreMessages(messagesSynchedTo.l1BlockNumber, currentL1BlockNumber);
|
|
719
|
+
} catch (error) {
|
|
720
|
+
if (isErrorClass(error, MessageStoreError)) {
|
|
721
|
+
this.log.warn(`Failed to store L1 to L2 messages retrieved from L1: ${error.message}. Rolling back syncpoint to retry.`, {
|
|
722
|
+
inboxMessage: error.inboxMessage
|
|
709
723
|
});
|
|
724
|
+
await this.rollbackL1ToL2Messages(remoteMessagesState.treeInProgress);
|
|
725
|
+
return false;
|
|
710
726
|
}
|
|
727
|
+
throw error;
|
|
711
728
|
}
|
|
712
|
-
//
|
|
729
|
+
// Note that, if there are no new messages to insert, but there was an L1 reorg that pruned out last messages,
|
|
730
|
+
// we'd notice by comparing our local state with the remote one again, and seeing they don't match even after
|
|
731
|
+
// our sync attempt. In this case, we also rollback our syncpoint, and trigger a retry.
|
|
732
|
+
const localLastMessageAfterSync = await this.store.getLastL1ToL2Message();
|
|
733
|
+
if (!await this.localStateMatches(localLastMessageAfterSync, remoteMessagesState)) {
|
|
734
|
+
this.log.warn(`Local L1 to L2 messages state does not match remote after sync attempt. Rolling back syncpoint to retry.`, {
|
|
735
|
+
localLastMessageAfterSync,
|
|
736
|
+
remoteMessagesState
|
|
737
|
+
});
|
|
738
|
+
await this.rollbackL1ToL2Messages(remoteMessagesState.treeInProgress);
|
|
739
|
+
return false;
|
|
740
|
+
}
|
|
741
|
+
// Advance the syncpoint after a successful sync
|
|
742
|
+
await this.store.setMessageSyncState(currentL1Block, remoteMessagesState.treeInProgress);
|
|
743
|
+
return true;
|
|
744
|
+
}
|
|
745
|
+
/** Checks if the local rolling hash and message count matches the remote state */ async localStateMatches(localLastMessage, remoteState) {
|
|
746
|
+
const localMessageCount = await this.store.getTotalL1ToL2MessageCount();
|
|
747
|
+
this.log.trace(`Comparing local and remote inbox state`, {
|
|
748
|
+
localMessageCount,
|
|
749
|
+
localLastMessage,
|
|
750
|
+
remoteState
|
|
751
|
+
});
|
|
752
|
+
return remoteState.totalMessagesInserted === localMessageCount && remoteState.messagesRollingHash.equals(localLastMessage?.rollingHash ?? Buffer16.ZERO);
|
|
753
|
+
}
|
|
754
|
+
/** Retrieves L1 to L2 messages from L1 in batches and stores them. */ async retrieveAndStoreMessages(fromL1Block, toL1Block) {
|
|
713
755
|
let searchStartBlock = 0n;
|
|
714
|
-
let searchEndBlock =
|
|
756
|
+
let searchEndBlock = fromL1Block;
|
|
715
757
|
let lastMessage;
|
|
716
758
|
let messageCount = 0;
|
|
717
759
|
do {
|
|
718
|
-
[searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock,
|
|
760
|
+
[searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock, toL1Block);
|
|
719
761
|
this.log.trace(`Retrieving L1 to L2 messages in L1 blocks ${searchStartBlock}-${searchEndBlock}`);
|
|
720
762
|
const messages = await retrieveL1ToL2Messages(this.inbox, searchStartBlock, searchEndBlock);
|
|
721
763
|
const timer = new Timer();
|
|
@@ -730,74 +772,65 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
730
772
|
lastMessage = msg;
|
|
731
773
|
messageCount++;
|
|
732
774
|
}
|
|
733
|
-
}while (searchEndBlock <
|
|
734
|
-
// Log stats for messages retrieved (if any).
|
|
775
|
+
}while (searchEndBlock < toL1Block)
|
|
735
776
|
if (messageCount > 0) {
|
|
736
777
|
this.log.info(`Retrieved ${messageCount} new L1 to L2 messages up to message with index ${lastMessage?.index} for checkpoint ${lastMessage?.checkpointNumber}`, {
|
|
737
778
|
lastMessage,
|
|
738
779
|
messageCount
|
|
739
780
|
});
|
|
740
781
|
}
|
|
741
|
-
// Warn if the resulting rolling hash does not match the remote state we had retrieved.
|
|
742
|
-
if (lastMessage && !lastMessage.rollingHash.equals(remoteMessagesState.messagesRollingHash)) {
|
|
743
|
-
this.log.warn(`Last message retrieved rolling hash does not match remote state.`, {
|
|
744
|
-
lastMessage,
|
|
745
|
-
remoteMessagesState
|
|
746
|
-
});
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
async retrieveL1ToL2Message(leaf) {
|
|
750
|
-
const currentL1BlockNumber = await this.publicClient.getBlockNumber();
|
|
751
|
-
let searchStartBlock = 0n;
|
|
752
|
-
let searchEndBlock = this.l1Constants.l1StartBlock - 1n;
|
|
753
|
-
do {
|
|
754
|
-
[searchStartBlock, searchEndBlock] = this.nextRange(searchEndBlock, currentL1BlockNumber);
|
|
755
|
-
const message = await retrieveL1ToL2Message(this.inbox, leaf, searchStartBlock, searchEndBlock);
|
|
756
|
-
if (message) {
|
|
757
|
-
return message;
|
|
758
|
-
}
|
|
759
|
-
}while (searchEndBlock < currentL1BlockNumber)
|
|
760
|
-
return undefined;
|
|
761
782
|
}
|
|
762
|
-
|
|
783
|
+
/**
|
|
784
|
+
* Rolls back local L1 to L2 messages to the last common message with L1, and updates the syncpoint to the L1 block of that message.
|
|
785
|
+
* If no common message is found, rolls back all messages and sets the syncpoint to the start block.
|
|
786
|
+
*/ async rollbackL1ToL2Messages(remoteTreeInProgress) {
|
|
763
787
|
// Slowly go back through our messages until we find the last common message.
|
|
764
788
|
// We could query the logs in batch as an optimization, but the depth of the reorg should not be deep, and this
|
|
765
789
|
// is a very rare case, so it's fine to query one log at a time.
|
|
766
790
|
let commonMsg;
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
791
|
+
let messagesToDelete = 0;
|
|
792
|
+
this.log.verbose(`Searching most recent common L1 to L2 message`);
|
|
793
|
+
for await (const localMsg of this.store.iterateL1ToL2Messages({
|
|
794
|
+
reverse: true
|
|
771
795
|
})){
|
|
772
|
-
const remoteMsg = await
|
|
796
|
+
const remoteMsg = await retrieveL1ToL2Message(this.inbox, localMsg);
|
|
773
797
|
const logCtx = {
|
|
774
798
|
remoteMsg,
|
|
775
|
-
localMsg:
|
|
799
|
+
localMsg: localMsg
|
|
776
800
|
};
|
|
777
|
-
if (remoteMsg && remoteMsg.rollingHash.equals(
|
|
778
|
-
this.log.verbose(`Found most recent common L1 to L2 message at index ${
|
|
801
|
+
if (remoteMsg && remoteMsg.rollingHash.equals(localMsg.rollingHash)) {
|
|
802
|
+
this.log.verbose(`Found most recent common L1 to L2 message at index ${localMsg.index} on L1 block ${localMsg.l1BlockNumber}`, logCtx);
|
|
779
803
|
commonMsg = remoteMsg;
|
|
780
804
|
break;
|
|
781
805
|
} else if (remoteMsg) {
|
|
782
|
-
this.log.debug(`Local L1 to L2 message with index ${
|
|
806
|
+
this.log.debug(`Local L1 to L2 message with index ${localMsg.index} has different rolling hash`, logCtx);
|
|
807
|
+
messagesToDelete++;
|
|
783
808
|
} else {
|
|
784
|
-
this.log.debug(`Local L1 to L2 message with index ${
|
|
809
|
+
this.log.debug(`Local L1 to L2 message with index ${localMsg.index} not found on L1`, logCtx);
|
|
810
|
+
messagesToDelete++;
|
|
785
811
|
}
|
|
786
812
|
}
|
|
787
|
-
// Delete everything after the common message we found.
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
813
|
+
// Delete everything after the common message we found, if anything needs to be deleted.
|
|
814
|
+
// Do not exit early if there are no messages to delete, we still want to update the syncpoint.
|
|
815
|
+
if (messagesToDelete > 0) {
|
|
816
|
+
const lastGoodIndex = commonMsg?.index;
|
|
817
|
+
this.log.warn(`Rolling back all local L1 to L2 messages after index ${lastGoodIndex ?? 'initial'}`);
|
|
818
|
+
await this.store.removeL1ToL2Messages(lastGoodIndex !== undefined ? lastGoodIndex + 1n : 0n);
|
|
819
|
+
}
|
|
791
820
|
// Update the syncpoint so the loop below reprocesses the changed messages. We go to the block before
|
|
792
821
|
// the last common one, so we force reprocessing it, in case new messages were added on that same L1 block
|
|
793
822
|
// after the last common message.
|
|
794
823
|
const syncPointL1BlockNumber = commonMsg ? commonMsg.l1BlockNumber - 1n : this.l1Constants.l1StartBlock;
|
|
795
824
|
const syncPointL1BlockHash = await this.getL1BlockHash(syncPointL1BlockNumber);
|
|
796
|
-
messagesSyncPoint = {
|
|
825
|
+
const messagesSyncPoint = {
|
|
797
826
|
l1BlockNumber: syncPointL1BlockNumber,
|
|
798
827
|
l1BlockHash: syncPointL1BlockHash
|
|
799
828
|
};
|
|
800
|
-
await this.store.
|
|
829
|
+
await this.store.setMessageSyncState(messagesSyncPoint, remoteTreeInProgress);
|
|
830
|
+
this.log.verbose(`Updated messages syncpoint to L1 block ${syncPointL1BlockNumber}`, {
|
|
831
|
+
...messagesSyncPoint,
|
|
832
|
+
remoteTreeInProgress
|
|
833
|
+
});
|
|
801
834
|
return messagesSyncPoint;
|
|
802
835
|
}
|
|
803
836
|
async getL1BlockHash(l1BlockNumber) {
|
|
@@ -1023,7 +1056,7 @@ _dec = trackSpan('Archiver.syncFromL1'), _dec1 = trackSpan('Archiver.handleEpoch
|
|
|
1023
1056
|
if (result.prunedBlocks && result.prunedBlocks.length > 0) {
|
|
1024
1057
|
const prunedCheckpointNumber = result.prunedBlocks[0].checkpointNumber;
|
|
1025
1058
|
const prunedSlotNumber = result.prunedBlocks[0].header.globalVariables.slotNumber;
|
|
1026
|
-
this.log.
|
|
1059
|
+
this.log.info(`Pruned ${result.prunedBlocks.length} mismatching blocks for checkpoint ${prunedCheckpointNumber}`, {
|
|
1027
1060
|
prunedBlocks: result.prunedBlocks.map((b)=>b.toBlockInfo()),
|
|
1028
1061
|
prunedSlotNumber,
|
|
1029
1062
|
prunedCheckpointNumber
|
|
@@ -14,4 +14,4 @@ export declare function getAttestationInfoFromPublishedCheckpoint({ checkpoint,
|
|
|
14
14
|
* Returns true if the attestations are valid and sufficient, false otherwise.
|
|
15
15
|
*/
|
|
16
16
|
export declare function validateCheckpointAttestations(publishedCheckpoint: PublishedCheckpoint, epochCache: EpochCache, constants: Pick<L1RollupConstants, 'epochDuration'>, logger?: Logger): Promise<ValidateCheckpointResult>;
|
|
17
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
17
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsaWRhdGlvbi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL21vZHVsZXMvdmFsaWRhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUdyRCxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUNwRCxPQUFPLEVBQ0wsS0FBSyxlQUFlLEVBRXBCLEtBQUssd0JBQXdCLEVBRTlCLE1BQU0scUJBQXFCLENBQUM7QUFDN0IsT0FBTyxLQUFLLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUNwRSxPQUFPLEVBQUUsS0FBSyxpQkFBaUIsRUFBaUMsTUFBTSw2QkFBNkIsQ0FBQztBQUdwRyxZQUFZLEVBQUUsd0JBQXdCLEVBQUUsQ0FBQztBQUV6Qzs7O0dBR0c7QUFDSCx3QkFBZ0IseUNBQXlDLENBQUMsRUFDeEQsVUFBVSxFQUNWLFlBQVksRUFDYixFQUFFLG1CQUFtQixHQUFHLGVBQWUsRUFBRSxDQUd6QztBQUVEOzs7R0FHRztBQUNILHdCQUFzQiw4QkFBOEIsQ0FDbEQsbUJBQW1CLEVBQUUsbUJBQW1CLEVBQ3hDLFVBQVUsRUFBRSxVQUFVLEVBQ3RCLFNBQVMsRUFBRSxJQUFJLENBQUMsaUJBQWlCLEVBQUUsZUFBZSxDQUFDLEVBQ25ELE1BQU0sQ0FBQyxFQUFFLE1BQU0sR0FDZCxPQUFPLENBQUMsd0JBQXdCLENBQUMsQ0EyRm5DIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/modules/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,wBAAwB,EAE9B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,KAAK,iBAAiB,
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/modules/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,wBAAwB,EAE9B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,KAAK,iBAAiB,EAAiC,MAAM,6BAA6B,CAAC;AAGpG,YAAY,EAAE,wBAAwB,EAAE,CAAC;AAEzC;;;GAGG;AACH,wBAAgB,yCAAyC,CAAC,EACxD,UAAU,EACV,YAAY,EACb,EAAE,mBAAmB,GAAG,eAAe,EAAE,CAGzC;AAED;;;GAGG;AACH,wBAAsB,8BAA8B,CAClD,mBAAmB,EAAE,mBAAmB,EACxC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,CAAC,EACnD,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,wBAAwB,CAAC,CA2FnC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { compactArray } from '@aztec/foundation/collection';
|
|
2
2
|
import { getAttestationInfoFromPayload } from '@aztec/stdlib/block';
|
|
3
|
-
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
3
|
+
import { computeQuorum, getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
4
4
|
import { ConsensusPayload } from '@aztec/stdlib/p2p';
|
|
5
5
|
/**
|
|
6
6
|
* Extracts attestation information from a published checkpoint.
|
|
@@ -46,7 +46,7 @@ import { ConsensusPayload } from '@aztec/stdlib/p2p';
|
|
|
46
46
|
valid: true
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
const requiredAttestationCount =
|
|
49
|
+
const requiredAttestationCount = computeQuorum(committee.length);
|
|
50
50
|
const failedValidationResult = (reason)=>({
|
|
51
51
|
valid: false,
|
|
52
52
|
reason,
|