@aztec-labs/archiver 6.0.0-rc.3 → 6.0.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.
- package/dest/archiver.d.ts +11 -2
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +94 -2
- package/dest/config.js +1 -1
- package/dest/errors.d.ts +12 -1
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +12 -0
- package/dest/l1/bin/retrieve-calldata.js +7 -5
- package/dest/l1/calldata_retriever.d.ts +5 -2
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +8 -3
- package/dest/l1/data_retrieval.d.ts +2 -1
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +14 -9
- package/dest/l1/validate_trace.d.ts +3 -1
- package/dest/l1/validate_trace.d.ts.map +1 -1
- package/dest/l1/validate_trace.js +8 -3
- package/dest/modules/checkpoint_ingestor.d.ts +71 -0
- package/dest/modules/checkpoint_ingestor.d.ts.map +1 -0
- package/dest/modules/checkpoint_ingestor.js +516 -0
- package/dest/modules/data_store_updater.d.ts +6 -11
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +4 -3
- package/dest/modules/instrumentation.d.ts +8 -4
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +8 -2
- package/dest/modules/l1_synchronizer.d.ts +3 -7
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +84 -420
- package/dest/modules/pending_chain_validation_tracker.d.ts +21 -0
- package/dest/modules/pending_chain_validation_tracker.d.ts.map +1 -0
- package/dest/modules/pending_chain_validation_tracker.js +32 -0
- package/dest/modules/validation.d.ts +2 -2
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +17 -11
- package/dest/store/block_store.d.ts +1 -1
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +8 -2
- package/dest/store/log_store_codec.d.ts +2 -1
- package/dest/store/log_store_codec.d.ts.map +1 -1
- package/dest/store/log_store_codec.js +1 -0
- package/dest/test/fake_l1_state.d.ts +21 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +82 -30
- package/package.json +15 -15
- package/src/archiver.ts +112 -3
- package/src/config.ts +1 -1
- package/src/errors.ts +21 -0
- package/src/l1/README.md +5 -0
- package/src/l1/bin/retrieve-calldata.ts +5 -3
- package/src/l1/calldata_retriever.ts +8 -3
- package/src/l1/data_retrieval.ts +13 -11
- package/src/l1/validate_trace.ts +11 -2
- package/src/modules/checkpoint_ingestor.ts +742 -0
- package/src/modules/data_store_updater.ts +7 -13
- package/src/modules/instrumentation.ts +17 -3
- package/src/modules/l1_synchronizer.ts +116 -563
- package/src/modules/pending_chain_validation_tracker.ts +43 -0
- package/src/modules/validation.ts +13 -9
- package/src/store/block_store.ts +6 -0
- package/src/store/log_store_codec.ts +1 -0
- package/src/test/fake_l1_state.ts +94 -31
|
@@ -5,6 +5,7 @@ import { CheckpointNumber, TreeLeafIndex } from '@aztec-labs/foundation/branded-
|
|
|
5
5
|
import { Buffer32 } from '@aztec-labs/foundation/buffer';
|
|
6
6
|
import { Secp256k1Signer } from '@aztec-labs/foundation/crypto/secp256k1-signer';
|
|
7
7
|
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
8
|
+
import { EthAddress } from '@aztec-labs/foundation/eth-address';
|
|
8
9
|
import { createLogger } from '@aztec-labs/foundation/log';
|
|
9
10
|
import { bufferToHex, hexToBuffer } from '@aztec-labs/foundation/string';
|
|
10
11
|
import { CommitteeAttestation, CommitteeAttestationsAndSigners } from '@aztec-labs/stdlib/block';
|
|
@@ -13,6 +14,7 @@ import { InboxMessagePrefixRef, accumulateInboxRollingHash, updateInboxRollingHa
|
|
|
13
14
|
import { ConsensusPayload, getHashedSignaturePayloadTypedData } from '@aztec-labs/stdlib/p2p';
|
|
14
15
|
import { mockCheckpointAndMessages } from '@aztec-labs/stdlib/testing';
|
|
15
16
|
import { AppendOnlyTreeSnapshot } from '@aztec-labs/stdlib/trees';
|
|
17
|
+
import { Buffer } from 'buffer';
|
|
16
18
|
import { mock } from 'jest-mock-extended';
|
|
17
19
|
import { encodeFunctionData, multicall3Abi, toHex } from 'viem';
|
|
18
20
|
/**
|
|
@@ -144,7 +146,7 @@ import { encodeFunctionData, multicall3Abi, toHex } from 'viem';
|
|
|
144
146
|
// Store the messages internally so they match the checkpoint's inHash
|
|
145
147
|
this.addMessages(checkpointNumber, messagesL1BlockNumber, messages);
|
|
146
148
|
// Create the transaction, blobs, and event hashes
|
|
147
|
-
const { tx, attestationsHash, payloadDigest, verbatimAttestations } = await this.makeRollupTx(checkpoint, signers, options.spareAttestationsBitmapBit ?? false, options.verbatimAttestations);
|
|
149
|
+
const { tx, attestationsHash, payloadDigest, verbatimAttestations, proposer } = await this.makeRollupTx(checkpoint, signers, options.spareAttestationsBitmapBit ?? false, options.verbatimAttestations, options.decoyBundleSigner);
|
|
148
150
|
const blobHashes = await this.makeVersionedBlobHashes(checkpoint);
|
|
149
151
|
const blobs = await this.makeBlobsFromCheckpoint(checkpoint);
|
|
150
152
|
// Store the checkpoint data
|
|
@@ -158,7 +160,8 @@ import { encodeFunctionData, multicall3Abi, toHex } from 'viem';
|
|
|
158
160
|
signers,
|
|
159
161
|
attestationsHash,
|
|
160
162
|
payloadDigest,
|
|
161
|
-
verbatimAttestations
|
|
163
|
+
verbatimAttestations,
|
|
164
|
+
proposer
|
|
162
165
|
});
|
|
163
166
|
// Update last archive for auto-chaining
|
|
164
167
|
this.lastArchive = lastArchive ?? checkpoint.blocks.at(-1).archive;
|
|
@@ -308,6 +311,33 @@ import { encodeFunctionData, multicall3Abi, toHex } from 'viem';
|
|
|
308
311
|
this.updatePendingCheckpointNumber();
|
|
309
312
|
}
|
|
310
313
|
/**
|
|
314
|
+
* Simulates the latest entry for a checkpoint number being invalidated on L1 and the identical checkpoint being
|
|
315
|
+
* proposed again at a later L1 block with a different set of signers. Both entries share the same archive root, and
|
|
316
|
+
* both remain visible as CheckpointProposed events.
|
|
317
|
+
*/ async repostCheckpoint(checkpointNumber, opts) {
|
|
318
|
+
const previous = this.checkpoints.findLast((cpData)=>cpData.checkpointNumber === checkpointNumber);
|
|
319
|
+
if (!previous) {
|
|
320
|
+
throw new Error(`Checkpoint ${checkpointNumber} not found`);
|
|
321
|
+
}
|
|
322
|
+
previous.pruned = true;
|
|
323
|
+
const { tx, attestationsHash, payloadDigest, verbatimAttestations } = await this.makeRollupTx(previous.checkpoint, opts.signers, false);
|
|
324
|
+
this.checkpoints.push({
|
|
325
|
+
...previous,
|
|
326
|
+
pruned: false,
|
|
327
|
+
l1BlockNumber: opts.l1BlockNumber,
|
|
328
|
+
// The tx hash defaults to the archive root, which both entries share, so give the repost its own.
|
|
329
|
+
tx: {
|
|
330
|
+
...tx,
|
|
331
|
+
hash: `0x${opts.l1BlockNumber.toString(16).padStart(64, '0')}`
|
|
332
|
+
},
|
|
333
|
+
signers: opts.signers,
|
|
334
|
+
attestationsHash,
|
|
335
|
+
payloadDigest,
|
|
336
|
+
verbatimAttestations
|
|
337
|
+
});
|
|
338
|
+
this.updatePendingCheckpointNumber();
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
311
341
|
* Moves messages at a given L1 block to a new L1 block.
|
|
312
342
|
* Useful for simulating partial message visibility (messages at higher L1 blocks won't be fetched).
|
|
313
343
|
*/ moveMessagesToL1Block(fromL1Block, toL1Block) {
|
|
@@ -361,6 +391,11 @@ import { encodeFunctionData, multicall3Abi, toHex } from 'viem';
|
|
|
361
391
|
return Promise.resolve(this.getProvenCheckpointNumberAtL1Block(atBlock));
|
|
362
392
|
});
|
|
363
393
|
mockRollup.canPruneAtTime.mockImplementation(()=>Promise.resolve(this.canPruneResult));
|
|
394
|
+
mockRollup.getProposerAt.mockImplementation((timestamp)=>{
|
|
395
|
+
const slot = getSlotAtTimestamp(timestamp, this.config);
|
|
396
|
+
const proposer = this.checkpoints.findLast((cp)=>!cp.pruned && cp.checkpoint.header.slotNumber === slot)?.proposer;
|
|
397
|
+
return Promise.resolve(proposer ?? EthAddress.ZERO);
|
|
398
|
+
});
|
|
364
399
|
// Mock the wrapper method for fetching checkpoint events
|
|
365
400
|
mockRollup.getCheckpointProposedEvents.mockImplementation((fromBlock, toBlock)=>Promise.resolve(this.getCheckpointProposedLogs(fromBlock, toBlock)));
|
|
366
401
|
Object.defineProperty(mockRollup, 'address', {
|
|
@@ -458,6 +493,7 @@ import { encodeFunctionData, multicall3Abi, toHex } from 'viem';
|
|
|
458
493
|
l1BlockNumber: cpData.l1BlockNumber,
|
|
459
494
|
l1BlockHash: Buffer32.fromBigInt(cpData.l1BlockNumber),
|
|
460
495
|
l1TransactionHash: cpData.tx.hash,
|
|
496
|
+
...this.getPositionInL1Block(this.checkpoints, cpData),
|
|
461
497
|
args: {
|
|
462
498
|
checkpointNumber: cpData.checkpointNumber,
|
|
463
499
|
archive: cpData.checkpoint.archive.root,
|
|
@@ -472,6 +508,7 @@ import { encodeFunctionData, multicall3Abi, toHex } from 'viem';
|
|
|
472
508
|
l1BlockNumber: msg.l1BlockNumber,
|
|
473
509
|
l1BlockHash: this.getL1BlockHash(msg.l1BlockNumber),
|
|
474
510
|
l1TransactionHash: `0x${msg.l1BlockNumber.toString(16)}`,
|
|
511
|
+
...this.getPositionInL1Block(this.messages, msg),
|
|
475
512
|
args: {
|
|
476
513
|
index: msg.index,
|
|
477
514
|
leaf: msg.leaf,
|
|
@@ -499,6 +536,7 @@ import { encodeFunctionData, multicall3Abi, toHex } from 'viem';
|
|
|
499
536
|
l1BlockNumber: msg.l1BlockNumber,
|
|
500
537
|
l1BlockHash: this.getL1BlockHash(msg.l1BlockNumber),
|
|
501
538
|
l1TransactionHash: `0x${msg.l1BlockNumber.toString(16)}`,
|
|
539
|
+
...this.getPositionInL1Block(this.messages, msg),
|
|
502
540
|
args: {
|
|
503
541
|
index: msg.index,
|
|
504
542
|
leaf: msg.leaf,
|
|
@@ -508,6 +546,16 @@ import { encodeFunctionData, multicall3Abi, toHex } from 'viem';
|
|
|
508
546
|
}
|
|
509
547
|
};
|
|
510
548
|
}
|
|
549
|
+
/**
|
|
550
|
+
* The transaction and log index of an entry's event within its L1 block, following insertion order among the entries
|
|
551
|
+
* in that block, with one event per transaction.
|
|
552
|
+
*/ getPositionInL1Block(entries, entry) {
|
|
553
|
+
const index = entries.filter((e)=>e.l1BlockNumber === entry.l1BlockNumber).indexOf(entry);
|
|
554
|
+
return {
|
|
555
|
+
l1TransactionIndex: index,
|
|
556
|
+
l1LogIndex: index
|
|
557
|
+
};
|
|
558
|
+
}
|
|
511
559
|
// The fake tracks only leaves, so the emitted message carries placeholder fields; nothing in the archiver
|
|
512
560
|
// consumes them (it stores leaf and consensus metadata only).
|
|
513
561
|
makeFakeMessageSentMessage(index) {
|
|
@@ -525,7 +573,7 @@ import { encodeFunctionData, multicall3Abi, toHex } from 'viem';
|
|
|
525
573
|
index
|
|
526
574
|
};
|
|
527
575
|
}
|
|
528
|
-
async makeRollupTx(checkpoint, signers, spareAttestationsBitmapBit, verbatimAttestationsOverride) {
|
|
576
|
+
async makeRollupTx(checkpoint, signers, spareAttestationsBitmapBit, verbatimAttestationsOverride, decoyBundleSigner) {
|
|
529
577
|
const signatureContext = this.getSignatureContext();
|
|
530
578
|
const consensusPayload = ConsensusPayload.fromCheckpoint(checkpoint, signatureContext);
|
|
531
579
|
const attestationDigest = getHashedSignaturePayloadTypedData(consensusPayload);
|
|
@@ -538,41 +586,44 @@ import { encodeFunctionData, multicall3Abi, toHex } from 'viem';
|
|
|
538
586
|
// don't care about the proposer identity (e.g. sync tests) still produce a
|
|
539
587
|
// valid-looking signature for the attestationsAndSigners struct.
|
|
540
588
|
const proposerSigner = signers[0] ?? Secp256k1Signer.random();
|
|
541
|
-
const attestationsAndSignersSignature = proposerSigner.sign(getHashedSignaturePayloadTypedData(attestationsAndSigners));
|
|
542
589
|
const packedAttestations = attestationsAndSigners.getPackedAttestations();
|
|
543
590
|
const verbatimAttestations = verbatimAttestationsOverride ?? (spareAttestationsBitmapBit ? {
|
|
544
591
|
...packedAttestations,
|
|
545
592
|
signatureIndices: setLastBitmapBit(packedAttestations.signatureIndices)
|
|
546
593
|
} : packedAttestations);
|
|
547
|
-
const
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
594
|
+
const makeProposeCall = (bundleSigner, allowFailure)=>({
|
|
595
|
+
target: this.config.rollupAddress.toString(),
|
|
596
|
+
allowFailure,
|
|
597
|
+
callData: encodeFunctionData({
|
|
598
|
+
abi: RollupAbi,
|
|
599
|
+
functionName: 'propose',
|
|
600
|
+
args: [
|
|
601
|
+
{
|
|
602
|
+
header,
|
|
603
|
+
archive,
|
|
604
|
+
oracleInput: {
|
|
605
|
+
feeAssetPriceModifier: 0n
|
|
606
|
+
},
|
|
607
|
+
bucketHint: 0n
|
|
608
|
+
},
|
|
609
|
+
verbatimAttestations,
|
|
610
|
+
attestationsAndSigners.getSigners().map((signer)=>signer.toString()),
|
|
611
|
+
bundleSigner.sign(getHashedSignaturePayloadTypedData(attestationsAndSigners)).toViemSignature(),
|
|
612
|
+
blobInput
|
|
613
|
+
]
|
|
614
|
+
})
|
|
615
|
+
});
|
|
616
|
+
const calls = [
|
|
617
|
+
...decoyBundleSigner ? [
|
|
618
|
+
makeProposeCall(decoyBundleSigner, true)
|
|
619
|
+
] : [],
|
|
620
|
+
makeProposeCall(proposerSigner, false)
|
|
621
|
+
];
|
|
565
622
|
const multiCallInput = encodeFunctionData({
|
|
566
623
|
abi: multicall3Abi,
|
|
567
624
|
functionName: 'aggregate3',
|
|
568
625
|
args: [
|
|
569
|
-
|
|
570
|
-
{
|
|
571
|
-
target: this.config.rollupAddress.toString(),
|
|
572
|
-
callData: rollupInput,
|
|
573
|
-
allowFailure: false
|
|
574
|
-
}
|
|
575
|
-
]
|
|
626
|
+
calls
|
|
576
627
|
]
|
|
577
628
|
});
|
|
578
629
|
const attestationsHash = Buffer32.fromString(computeAttestationsHash(verbatimAttestations));
|
|
@@ -588,7 +639,8 @@ import { encodeFunctionData, multicall3Abi, toHex } from 'viem';
|
|
|
588
639
|
tx,
|
|
589
640
|
attestationsHash,
|
|
590
641
|
payloadDigest,
|
|
591
|
-
verbatimAttestations
|
|
642
|
+
verbatimAttestations,
|
|
643
|
+
proposer: proposerSigner.address
|
|
592
644
|
};
|
|
593
645
|
}
|
|
594
646
|
getSignatureContext() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec-labs/archiver",
|
|
3
|
-
"version": "6.0.0
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -65,22 +65,22 @@
|
|
|
65
65
|
]
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@aztec-foundation/l1-artifacts": "6.0.0
|
|
69
|
-
"@aztec-labs/blob-client": "6.0.0
|
|
70
|
-
"@aztec-labs/blob-lib": "6.0.0
|
|
71
|
-
"@aztec-labs/constants": "6.0.0
|
|
72
|
-
"@aztec-labs/epoch-cache": "6.0.0
|
|
73
|
-
"@aztec-labs/ethereum": "6.0.0
|
|
74
|
-
"@aztec-labs/foundation": "6.0.0
|
|
75
|
-
"@aztec-labs/kv-store": "6.0.0
|
|
76
|
-
"@aztec-labs/protocol-contracts": "6.0.0
|
|
77
|
-
"@aztec-labs/standard-contracts": "6.0.0
|
|
78
|
-
"@aztec-labs/stdlib": "6.0.0
|
|
79
|
-
"@aztec-labs/telemetry-client": "6.0.0
|
|
68
|
+
"@aztec-foundation/l1-artifacts": "6.0.0",
|
|
69
|
+
"@aztec-labs/blob-client": "6.0.0",
|
|
70
|
+
"@aztec-labs/blob-lib": "6.0.0",
|
|
71
|
+
"@aztec-labs/constants": "6.0.0",
|
|
72
|
+
"@aztec-labs/epoch-cache": "6.0.0",
|
|
73
|
+
"@aztec-labs/ethereum": "6.0.0",
|
|
74
|
+
"@aztec-labs/foundation": "6.0.0",
|
|
75
|
+
"@aztec-labs/kv-store": "6.0.0",
|
|
76
|
+
"@aztec-labs/protocol-contracts": "6.0.0",
|
|
77
|
+
"@aztec-labs/standard-contracts": "6.0.0",
|
|
78
|
+
"@aztec-labs/stdlib": "6.0.0",
|
|
79
|
+
"@aztec-labs/telemetry-client": "6.0.0",
|
|
80
80
|
"lodash.groupby": "^4.6.0",
|
|
81
81
|
"lodash.omit": "^4.5.0",
|
|
82
82
|
"tslib": "^2.5.0",
|
|
83
|
-
"viem": "
|
|
83
|
+
"viem": "2.57.1",
|
|
84
84
|
"zod": "~4.4.3"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
@@ -103,6 +103,6 @@
|
|
|
103
103
|
],
|
|
104
104
|
"types": "./dest/index.d.ts",
|
|
105
105
|
"engines": {
|
|
106
|
-
"node": ">=20.
|
|
106
|
+
"node": ">=20.16"
|
|
107
107
|
}
|
|
108
108
|
}
|
package/src/archiver.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec-l
|
|
|
7
7
|
import { Buffer32 } from '@aztec-labs/foundation/buffer';
|
|
8
8
|
import { merge } from '@aztec-labs/foundation/collection';
|
|
9
9
|
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
10
|
+
import { InterruptError } from '@aztec-labs/foundation/error';
|
|
10
11
|
import { EthAddress } from '@aztec-labs/foundation/eth-address';
|
|
11
12
|
import { type Logger, createLogger } from '@aztec-labs/foundation/log';
|
|
12
13
|
import { type PromiseWithResolvers, promiseWithResolvers } from '@aztec-labs/foundation/promise';
|
|
@@ -77,6 +78,15 @@ type AddProposedCheckpointRequest = {
|
|
|
77
78
|
reject: (err: Error) => void;
|
|
78
79
|
};
|
|
79
80
|
|
|
81
|
+
/** Request to prune the blocks of a checkpoint its proposer abandoned, queued for processing by the sync loop. */
|
|
82
|
+
type PruneAbandonedBlocksRequest = {
|
|
83
|
+
type: 'prune-abandoned';
|
|
84
|
+
afterBlockNumber: BlockNumber;
|
|
85
|
+
firstBlockHash: BlockHash;
|
|
86
|
+
resolve: (pruned: BlockNumber[]) => void;
|
|
87
|
+
reject: (err: Error) => void;
|
|
88
|
+
};
|
|
89
|
+
|
|
80
90
|
export type ArchiverDeps = {
|
|
81
91
|
telemetry?: TelemetryClient;
|
|
82
92
|
blobClient: BlobClientInterface;
|
|
@@ -119,7 +129,7 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
119
129
|
private initialSyncPromise: PromiseWithResolvers<void>;
|
|
120
130
|
|
|
121
131
|
/** Queue of blocks and checkpoints to be added to the store, processed by the sync loop. */
|
|
122
|
-
private inboundQueue: (AddBlockRequest | AddProposedCheckpointRequest)[] = [];
|
|
132
|
+
private inboundQueue: (AddBlockRequest | AddProposedCheckpointRequest | PruneAbandonedBlocksRequest)[] = [];
|
|
123
133
|
|
|
124
134
|
/** Helper to handle updates to the store */
|
|
125
135
|
private readonly updater: ArchiverDataStoreUpdater;
|
|
@@ -324,10 +334,16 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
324
334
|
this.checkpointProposalPresence = checkpointProposalPresence;
|
|
325
335
|
}
|
|
326
336
|
|
|
327
|
-
|
|
337
|
+
/** Triggers an immediate sync without propagating its failure, so fire-and-forget callers never leak a rejection. */
|
|
338
|
+
public async trySyncImmediate(): Promise<void> {
|
|
328
339
|
try {
|
|
329
|
-
|
|
340
|
+
await this.syncImmediate();
|
|
330
341
|
} catch (err) {
|
|
342
|
+
// A trigger still pending when the loop stops is never served; the queued requests are settled by stop().
|
|
343
|
+
if (err instanceof InterruptError) {
|
|
344
|
+
this.log.debug(`Immediate archiver sync not served before stop`);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
331
347
|
this.log.error(`Failed to trigger immediate archiver sync: ${err}`, err);
|
|
332
348
|
}
|
|
333
349
|
}
|
|
@@ -362,6 +378,22 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
362
378
|
return promise.promise;
|
|
363
379
|
}
|
|
364
380
|
|
|
381
|
+
/**
|
|
382
|
+
* Queues the prune of the blocks of a checkpoint its proposer abandoned. It runs in the sync loop, ordered after
|
|
383
|
+
* the blocks queued before it, and resolves with the pruned block numbers once processed.
|
|
384
|
+
* Implements the L2BlockSink interface.
|
|
385
|
+
*/
|
|
386
|
+
public pruneAbandonedProposedBlocks(
|
|
387
|
+
afterBlockNumber: BlockNumber,
|
|
388
|
+
firstBlockHash: BlockHash,
|
|
389
|
+
): Promise<BlockNumber[]> {
|
|
390
|
+
const promise = promiseWithResolvers<BlockNumber[]>();
|
|
391
|
+
this.inboundQueue.push({ afterBlockNumber, firstBlockHash, ...promise, type: 'prune-abandoned' });
|
|
392
|
+
this.log.debug(`Queued prune of abandoned proposed blocks after block ${afterBlockNumber}`);
|
|
393
|
+
void this.trySyncImmediate();
|
|
394
|
+
return promise.promise;
|
|
395
|
+
}
|
|
396
|
+
|
|
365
397
|
/**
|
|
366
398
|
* Processes all queued blocks and checkpoints, adding them to the store.
|
|
367
399
|
* Called at the beginning of each sync iteration.
|
|
@@ -390,6 +422,11 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
390
422
|
|
|
391
423
|
// Process each item individually to properly resolve/reject each promise
|
|
392
424
|
for (const item of queuedItems) {
|
|
425
|
+
// A prune is not a proposal for a slot, so the past-slot check below does not apply to it.
|
|
426
|
+
if (item.type === 'prune-abandoned') {
|
|
427
|
+
await this.pruneAbandonedProposedBlocksNow(item);
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
393
430
|
const { resolve, reject, type } = item;
|
|
394
431
|
const itemSlot = getSlot(item);
|
|
395
432
|
const itemNumber = getNumber(item);
|
|
@@ -432,6 +469,72 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
432
469
|
return blocksAdded;
|
|
433
470
|
}
|
|
434
471
|
|
|
472
|
+
/**
|
|
473
|
+
* Prunes the blocks of a checkpoint its proposer abandoned, announcing it the way the orphan prune does so world
|
|
474
|
+
* state, the tx pool and every other subscriber react to it as to an orphan prune, just without waiting for one.
|
|
475
|
+
*/
|
|
476
|
+
private async pruneAbandonedProposedBlocksNow(request: PruneAbandonedBlocksRequest): Promise<void> {
|
|
477
|
+
const { afterBlockNumber, firstBlockHash, resolve, reject } = request;
|
|
478
|
+
try {
|
|
479
|
+
const refusal = await this.getAbandonedBlocksPruneRefusal(afterBlockNumber, firstBlockHash);
|
|
480
|
+
if (refusal !== undefined) {
|
|
481
|
+
this.log.verbose(`Not pruning abandoned proposed blocks after block ${afterBlockNumber}`, {
|
|
482
|
+
afterBlockNumber,
|
|
483
|
+
firstBlockHash: firstBlockHash.toString(),
|
|
484
|
+
refusal,
|
|
485
|
+
});
|
|
486
|
+
resolve([]);
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
const removed = await this.updater.removeBlocksWithoutProposedCheckpointAfter(afterBlockNumber);
|
|
491
|
+
const slotNumber = removed[0].slot;
|
|
492
|
+
const prunedBlocks = removed.map(block => block.number);
|
|
493
|
+
this.log.warn(`Pruned proposed blocks after block ${afterBlockNumber} abandoned by their proposer`, {
|
|
494
|
+
afterBlockNumber,
|
|
495
|
+
slotNumber,
|
|
496
|
+
prunedBlocks,
|
|
497
|
+
});
|
|
498
|
+
this.instrumentation.recordPrune('abandoned');
|
|
499
|
+
this.events.emit(L2BlockSourceEvents.L2PruneUncheckpointed, {
|
|
500
|
+
type: L2BlockSourceEvents.L2PruneUncheckpointed,
|
|
501
|
+
slotNumber,
|
|
502
|
+
blocks: removed,
|
|
503
|
+
});
|
|
504
|
+
resolve(prunedBlocks);
|
|
505
|
+
} catch (err: any) {
|
|
506
|
+
this.log.error(`Failed to prune abandoned proposed blocks after block ${afterBlockNumber}`, err, {
|
|
507
|
+
afterBlockNumber,
|
|
508
|
+
firstBlockHash: firstBlockHash.toString(),
|
|
509
|
+
});
|
|
510
|
+
reject(err);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Returns why the blocks after `afterBlockNumber` must be kept, or undefined if they are still the caller's
|
|
516
|
+
* abandoned blocks and can be pruned. Runs in the sync loop, so no other archiver write lands between these checks
|
|
517
|
+
* and the removal.
|
|
518
|
+
*/
|
|
519
|
+
private async getAbandonedBlocksPruneRefusal(
|
|
520
|
+
afterBlockNumber: BlockNumber,
|
|
521
|
+
firstBlockHash: BlockHash,
|
|
522
|
+
): Promise<'not-caller-blocks' | 'checkpointed' | 'checkpoint-proposal-received' | undefined> {
|
|
523
|
+
const firstBlock = await this.stores.blocks.getBlockData({ number: BlockNumber(afterBlockNumber + 1) });
|
|
524
|
+
if (firstBlock === undefined || !firstBlock.blockHash.equals(firstBlockHash)) {
|
|
525
|
+
return 'not-caller-blocks';
|
|
526
|
+
}
|
|
527
|
+
if ((await this.stores.blocks.getProposedCheckpointL2BlockNumber()) > afterBlockNumber) {
|
|
528
|
+
return 'checkpointed';
|
|
529
|
+
}
|
|
530
|
+
// Another proposer, such as an HA peer of the caller, may still be proposing these blocks, so they are left to
|
|
531
|
+
// the orphan prune, which waits for the proposal to materialize.
|
|
532
|
+
if (await this.checkpointProposalPresence.hasCheckpointProposalForSlot(firstBlock.header.getSlot())) {
|
|
533
|
+
return 'checkpoint-proposal-received';
|
|
534
|
+
}
|
|
535
|
+
return undefined;
|
|
536
|
+
}
|
|
537
|
+
|
|
435
538
|
public waitForInitialSync() {
|
|
436
539
|
return this.initialSyncPromise.promise;
|
|
437
540
|
}
|
|
@@ -611,6 +714,12 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
611
714
|
this.log.debug('Stopping...');
|
|
612
715
|
await this.runningPromise.stop();
|
|
613
716
|
|
|
717
|
+
// Requests queued while the last sync pass ran are never processed; settle them so their callers do not wait on
|
|
718
|
+
// a loop that will not run again.
|
|
719
|
+
for (const item of this.inboundQueue.splice(0, this.inboundQueue.length)) {
|
|
720
|
+
item.reject(new Error(`Archiver stopped before processing the queued ${item.type} request`));
|
|
721
|
+
}
|
|
722
|
+
|
|
614
723
|
this.log.info('Stopped.');
|
|
615
724
|
return Promise.resolve();
|
|
616
725
|
}
|
package/src/config.ts
CHANGED
|
@@ -71,7 +71,7 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
|
|
|
71
71
|
ethereumAllowNoDebugHosts: {
|
|
72
72
|
env: 'ETHEREUM_ALLOW_NO_DEBUG_HOSTS',
|
|
73
73
|
description: 'Whether to allow starting the archiver without debug/trace method support on Ethereum hosts',
|
|
74
|
-
...booleanConfigHelper(
|
|
74
|
+
...booleanConfigHelper(false),
|
|
75
75
|
},
|
|
76
76
|
archiverSkipHistoricalLogsCheck: {
|
|
77
77
|
env: 'ARCHIVER_SKIP_HISTORICAL_LOGS_CHECK',
|
package/src/errors.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { BlockNumber, CheckpointNumber } from '@aztec-labs/foundation/branded-types';
|
|
2
2
|
import type { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
3
3
|
import type { TxHash } from '@aztec-labs/stdlib/tx';
|
|
4
|
+
import type { Hex } from 'viem';
|
|
4
5
|
|
|
5
6
|
export class NoBlobBodiesFoundError extends Error {
|
|
6
7
|
constructor(l2BlockNum: number) {
|
|
@@ -96,6 +97,26 @@ export class DuplicateTxHashError extends Error {
|
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Thrown when the propose calldata of a checkpoint cannot be recovered from its L1 tx: no known decoder matched the
|
|
102
|
+
* tx, and neither `trace_transaction` nor `debug_traceTransaction` returned a usable trace for it, either because the
|
|
103
|
+
* call failed or because its response could not be parsed.
|
|
104
|
+
*/
|
|
105
|
+
export class CheckpointCalldataUnavailableError extends Error {
|
|
106
|
+
constructor(
|
|
107
|
+
public readonly l1TxHash: Hex,
|
|
108
|
+
public readonly checkpointNumber: CheckpointNumber,
|
|
109
|
+
) {
|
|
110
|
+
super(
|
|
111
|
+
`Cannot extract propose calldata for checkpoint ${checkpointNumber} from L1 tx ${l1TxHash}: neither ` +
|
|
112
|
+
`trace_transaction nor debug_traceTransaction returned a usable trace (each method's error is in the ` +
|
|
113
|
+
`warning logged for this tx). If the L1 RPC lacks these methods, set ETHEREUM_DEBUG_HOSTS to one that ` +
|
|
114
|
+
`serves debug_traceTransaction or trace_transaction with history back to this tx.`,
|
|
115
|
+
);
|
|
116
|
+
this.name = 'CheckpointCalldataUnavailableError';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
99
120
|
export class CheckpointNotFoundError extends Error {
|
|
100
121
|
constructor(checkpointNumber: number) {
|
|
101
122
|
super(`Failed to find expected checkpoint number ${checkpointNumber}`);
|
package/src/l1/README.md
CHANGED
|
@@ -27,6 +27,11 @@ First attempt to decode the transaction as a multicall3 `aggregate3` call:
|
|
|
27
27
|
This approach works regardless of what other calls are in the multicall3 bundle, because hash
|
|
28
28
|
matching identifies the correct propose call without needing an allowlist.
|
|
29
29
|
|
|
30
|
+
Hash matching does not tell which candidate executed. The event hashes cover neither the `signers`
|
|
31
|
+
array nor the attestations-and-signers signature, so a reverted copy of the call can carry any value
|
|
32
|
+
for them. The retriever ignores both fields, and the archiver asks the rollup for a slot's proposer
|
|
33
|
+
(`getProposerAt`) instead of deriving it from calldata.
|
|
34
|
+
|
|
30
35
|
### Direct Propose Call
|
|
31
36
|
|
|
32
37
|
Second attempt to decode the transaction as a direct `propose` call to the rollup contract:
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { RollupAbi } from '@aztec-foundation/l1-artifacts/RollupAbi';
|
|
3
3
|
|
|
4
|
+
import { makeL1HttpTransport } from '@aztec-labs/ethereum/client';
|
|
4
5
|
import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec-labs/ethereum/types';
|
|
5
6
|
import { CheckpointNumber } from '@aztec-labs/foundation/branded-types';
|
|
7
|
+
import { getEnv } from '@aztec-labs/foundation/config/env';
|
|
6
8
|
import { EthAddress } from '@aztec-labs/foundation/eth-address';
|
|
7
9
|
import { createLogger } from '@aztec-labs/foundation/log';
|
|
8
10
|
import { CommitteeAttestation } from '@aztec-labs/stdlib/block';
|
|
9
|
-
import { type Hex, createPublicClient, decodeEventLog, getAbiItem,
|
|
11
|
+
import { type Hex, createPublicClient, decodeEventLog, getAbiItem, toEventSelector } from 'viem';
|
|
10
12
|
import { mainnet } from 'viem/chains';
|
|
11
13
|
|
|
12
14
|
import { CalldataRetriever } from '../calldata_retriever.js';
|
|
@@ -47,7 +49,7 @@ function parseArgs(): ScriptArgs {
|
|
|
47
49
|
const txHash = args[1] as Hex;
|
|
48
50
|
const targetCommitteeSize = args[2] ? parseInt(args[2], 10) : 24;
|
|
49
51
|
|
|
50
|
-
const rpcUrl =
|
|
52
|
+
const rpcUrl = getEnv().ETHEREUM_HOST || getEnv().RPC_URL;
|
|
51
53
|
if (!rpcUrl) {
|
|
52
54
|
// eslint-disable-next-line no-console
|
|
53
55
|
console.error('Error: ETHEREUM_HOST or RPC_URL environment variable must be set');
|
|
@@ -78,7 +80,7 @@ async function main() {
|
|
|
78
80
|
// Create viem public client
|
|
79
81
|
const publicClient = createPublicClient({
|
|
80
82
|
chain: mainnet,
|
|
81
|
-
transport:
|
|
83
|
+
transport: makeL1HttpTransport([rpcUrl]),
|
|
82
84
|
});
|
|
83
85
|
|
|
84
86
|
logger.info('Fetching transaction...');
|
|
@@ -14,8 +14,10 @@ import { EthAddress } from '@aztec-labs/foundation/eth-address';
|
|
|
14
14
|
import type { Logger } from '@aztec-labs/foundation/log';
|
|
15
15
|
import { computeCheckpointPayloadDigest } from '@aztec-labs/stdlib/checkpoint';
|
|
16
16
|
import { CheckpointHeader } from '@aztec-labs/stdlib/rollup';
|
|
17
|
+
import { Buffer } from 'buffer';
|
|
17
18
|
import { type Hex, type Transaction, decodeFunctionData, hexToBytes, multicall3Abi, toFunctionSelector } from 'viem';
|
|
18
19
|
|
|
20
|
+
import { CheckpointCalldataUnavailableError } from '../errors.js';
|
|
19
21
|
import type { ArchiverInstrumentation } from '../modules/instrumentation.js';
|
|
20
22
|
import { getSuccessfulCallsFromDebug } from './debug_tx.js';
|
|
21
23
|
import { getCallsFromSpireProposer } from './spire_proposer.js';
|
|
@@ -126,7 +128,7 @@ export class CalldataRetriever {
|
|
|
126
128
|
`Failed to decode multicall3, direct propose, or Spire proposer for L1 tx ${tx.hash}, falling back to trace for checkpoint ${checkpointNumber}`,
|
|
127
129
|
);
|
|
128
130
|
this.instrumentation?.recordBlockProposalTxTarget(tx.to ?? EthAddress.ZERO.toString(), true);
|
|
129
|
-
const tracedCalldata = await this.extractCalldataViaTrace(tx.hash);
|
|
131
|
+
const tracedCalldata = await this.extractCalldataViaTrace(tx.hash, checkpointNumber);
|
|
130
132
|
const tracedResult = this.tryDecodeAndVerifyPropose(
|
|
131
133
|
tracedCalldata,
|
|
132
134
|
expectedHashes,
|
|
@@ -330,9 +332,11 @@ export class CalldataRetriever {
|
|
|
330
332
|
* This is the definitive fallback that works for any transaction pattern.
|
|
331
333
|
* Tries trace_transaction first, then falls back to debug_traceTransaction.
|
|
332
334
|
* @param txHash - The transaction hash to trace
|
|
335
|
+
* @param checkpointNumber - The checkpoint the tx is expected to propose, for error reporting
|
|
333
336
|
* @returns The propose calldata from the successful call
|
|
337
|
+
* @throws CheckpointCalldataUnavailableError if neither trace_transaction nor debug_traceTransaction succeeds
|
|
334
338
|
*/
|
|
335
|
-
protected async extractCalldataViaTrace(txHash: Hex): Promise<Hex> {
|
|
339
|
+
protected async extractCalldataViaTrace(txHash: Hex, checkpointNumber: CheckpointNumber): Promise<Hex> {
|
|
336
340
|
const rollupAddress = this.rollupAddress;
|
|
337
341
|
const selector = PROPOSE_SELECTOR;
|
|
338
342
|
|
|
@@ -368,7 +372,8 @@ export class CalldataRetriever {
|
|
|
368
372
|
debugError,
|
|
369
373
|
txHash,
|
|
370
374
|
});
|
|
371
|
-
|
|
375
|
+
this.instrumentation?.recordCheckpointCalldataUnavailable();
|
|
376
|
+
throw new CheckpointCalldataUnavailableError(txHash, checkpointNumber);
|
|
372
377
|
}
|
|
373
378
|
}
|
|
374
379
|
|
package/src/l1/data_retrieval.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
type RollupContract,
|
|
17
17
|
type ViemCommitteeAttestations,
|
|
18
18
|
type ViemHeader,
|
|
19
|
+
compareL1LogPosition,
|
|
19
20
|
fetchLogsBisectingRange,
|
|
20
21
|
} from '@aztec-labs/ethereum/contracts';
|
|
21
22
|
import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec-labs/ethereum/types';
|
|
@@ -30,6 +31,7 @@ import { Proof } from '@aztec-labs/stdlib/proofs';
|
|
|
30
31
|
import { CheckpointHeader } from '@aztec-labs/stdlib/rollup';
|
|
31
32
|
import { AppendOnlyTreeSnapshot } from '@aztec-labs/stdlib/trees';
|
|
32
33
|
import { BlockHeader, GlobalVariables, PartialStateReference, StateReference } from '@aztec-labs/stdlib/tx';
|
|
34
|
+
import { Buffer } from 'buffer';
|
|
33
35
|
import { type Hex, decodeFunctionData, getAbiItem, hexToBytes } from 'viem';
|
|
34
36
|
|
|
35
37
|
import { NoBlobBodiesFoundError } from '../errors.js';
|
|
@@ -192,7 +194,7 @@ export async function retrieveCheckpointCalldataFromRollup(
|
|
|
192
194
|
instrumentation: ArchiverInstrumentation,
|
|
193
195
|
logger: Logger = createLogger('archiver'),
|
|
194
196
|
): Promise<RetrievedCheckpointFromCalldata[]> {
|
|
195
|
-
const retrievedCheckpoints:
|
|
197
|
+
const retrievedCheckpoints: RetrievedCheckpointWithLog[] = [];
|
|
196
198
|
|
|
197
199
|
let rollupConstants: { chainId: Fr; version: Fr } | undefined;
|
|
198
200
|
|
|
@@ -232,9 +234,13 @@ export async function retrieveCheckpointCalldataFromRollup(
|
|
|
232
234
|
searchStartBlock = lastLog.l1BlockNumber + 1n;
|
|
233
235
|
} while (searchStartBlock <= searchEndBlock);
|
|
234
236
|
|
|
235
|
-
|
|
237
|
+
// Checkpoints are retrieved in parallel and land in completion order, so restore the order of their L1 logs.
|
|
238
|
+
return retrievedCheckpoints.sort((a, b) => compareL1LogPosition(a.log, b.log)).map(({ checkpoint }) => checkpoint);
|
|
236
239
|
}
|
|
237
240
|
|
|
241
|
+
/** A checkpoint retrieved from calldata, with the L1 log that announced it. */
|
|
242
|
+
type RetrievedCheckpointWithLog = { log: CheckpointProposedLog; checkpoint: RetrievedCheckpointFromCalldata };
|
|
243
|
+
|
|
238
244
|
/**
|
|
239
245
|
* Processes CheckpointProposed logs, fetching only calldata (no blobs).
|
|
240
246
|
* @param rollup - The rollup contract wrapper.
|
|
@@ -244,7 +250,7 @@ export async function retrieveCheckpointCalldataFromRollup(
|
|
|
244
250
|
* @param rollupConstants - The rollup constants (chainId, version).
|
|
245
251
|
* @param instrumentation - The archiver instrumentation instance.
|
|
246
252
|
* @param logger - The logger instance.
|
|
247
|
-
* @returns
|
|
253
|
+
* @returns The calldata-only checkpoints, each with the log that announced it, in completion order.
|
|
248
254
|
*/
|
|
249
255
|
async function processCheckpointProposedLogs(
|
|
250
256
|
rollup: RollupContract,
|
|
@@ -254,8 +260,8 @@ async function processCheckpointProposedLogs(
|
|
|
254
260
|
{ chainId, version }: { chainId: Fr; version: Fr },
|
|
255
261
|
instrumentation: ArchiverInstrumentation,
|
|
256
262
|
logger: Logger,
|
|
257
|
-
): Promise<
|
|
258
|
-
const retrievedCheckpoints:
|
|
263
|
+
): Promise<RetrievedCheckpointWithLog[]> {
|
|
264
|
+
const retrievedCheckpoints: RetrievedCheckpointWithLog[] = [];
|
|
259
265
|
const calldataRetriever = new CalldataRetriever(
|
|
260
266
|
publicClient,
|
|
261
267
|
debugClient,
|
|
@@ -293,12 +299,8 @@ async function processCheckpointProposedLogs(
|
|
|
293
299
|
const l1 = new L1PublishedData(log.l1BlockNumber, timestamp, log.l1BlockHash.toString());
|
|
294
300
|
|
|
295
301
|
retrievedCheckpoints.push({
|
|
296
|
-
|
|
297
|
-
l1,
|
|
298
|
-
chainId,
|
|
299
|
-
version,
|
|
300
|
-
blobHashes,
|
|
301
|
-
parentBeaconBlockRoot,
|
|
302
|
+
log,
|
|
303
|
+
checkpoint: { ...checkpoint, l1, chainId, version, blobHashes, parentBeaconBlockRoot },
|
|
302
304
|
});
|
|
303
305
|
|
|
304
306
|
logger.trace(`Retrieved checkpoint calldata ${checkpointNumber} from L1 tx ${log.l1TransactionHash}`, {
|