@aztec/stdlib 5.0.0-nightly.20260616 → 5.0.0-nightly.20260618
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/block/l2_block_source.d.ts +11 -25
- package/dest/block/l2_block_source.d.ts.map +1 -1
- package/dest/block/l2_block_source.js +0 -1
- package/dest/block/l2_block_stream/interfaces.d.ts +25 -5
- package/dest/block/l2_block_stream/interfaces.d.ts.map +1 -1
- package/dest/block/l2_block_stream/l2_block_stream.d.ts +29 -7
- package/dest/block/l2_block_stream/l2_block_stream.d.ts.map +1 -1
- package/dest/block/l2_block_stream/l2_block_stream.js +165 -152
- package/dest/block/l2_block_stream/l2_tips_store_base.d.ts +10 -2
- package/dest/block/l2_block_stream/l2_tips_store_base.d.ts.map +1 -1
- package/dest/block/l2_block_stream/l2_tips_store_base.js +33 -15
- package/dest/block/test/l2_tips_store_test_suite.d.ts +1 -1
- package/dest/block/test/l2_tips_store_test_suite.d.ts.map +1 -1
- package/dest/block/test/l2_tips_store_test_suite.js +94 -3
- package/dest/checkpoint/index.d.ts +2 -1
- package/dest/checkpoint/index.d.ts.map +1 -1
- package/dest/checkpoint/index.js +1 -0
- package/dest/checkpoint/simulation_overrides.d.ts +61 -0
- package/dest/checkpoint/simulation_overrides.d.ts.map +1 -0
- package/dest/checkpoint/simulation_overrides.js +98 -0
- package/dest/interfaces/aztec-node-debug.d.ts +8 -1
- package/dest/interfaces/aztec-node-debug.d.ts.map +1 -1
- package/dest/interfaces/aztec-node-debug.js +8 -0
- package/dest/interfaces/aztec-node.d.ts +10 -18
- package/dest/interfaces/aztec-node.d.ts.map +1 -1
- package/dest/interfaces/aztec-node.js +6 -14
- package/dest/interfaces/chain_tips.d.ts +8 -47
- package/dest/interfaces/chain_tips.d.ts.map +1 -1
- package/dest/interfaces/chain_tips.js +1 -6
- package/dest/interfaces/checkpoint_parameter.d.ts +3 -3
- package/dest/interfaces/checkpoint_parameter.d.ts.map +1 -1
- package/dest/interfaces/checkpoint_parameter.js +3 -3
- package/dest/interfaces/proving-job.d.ts +70 -70
- package/dest/tests/factories.d.ts +1 -1
- package/dest/tests/factories.d.ts.map +1 -1
- package/dest/tests/factories.js +0 -10
- package/dest/tx/global_variable_builder.d.ts +2 -12
- package/dest/tx/global_variable_builder.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/block/l2_block_source.ts +10 -15
- package/src/block/l2_block_stream/interfaces.ts +25 -5
- package/src/block/l2_block_stream/l2_block_stream.ts +222 -172
- package/src/block/l2_block_stream/l2_tips_store_base.ts +36 -15
- package/src/block/test/l2_tips_store_test_suite.ts +73 -4
- package/src/checkpoint/index.ts +1 -0
- package/src/checkpoint/simulation_overrides.ts +171 -0
- package/src/interfaces/aztec-node-debug.ts +15 -0
- package/src/interfaces/aztec-node.ts +19 -30
- package/src/interfaces/chain_tips.ts +8 -16
- package/src/interfaces/checkpoint_parameter.ts +3 -3
- package/src/tests/factories.ts +0 -4
- package/src/tx/global_variable_builder.ts +1 -17
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { BlockNumber
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { AbortError } from '@aztec/foundation/error';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
5
5
|
import { makeL2BlockId } from '../l2_block_source.js';
|
|
6
|
-
/** Maximum number of checkpoints to prefetch at once during sync. Matches MAX_RPC_CHECKPOINTS_LEN. */ export const CHECKPOINT_PREFETCH_LIMIT = 50;
|
|
7
6
|
/** Creates a stream of events for new blocks, chain tips updates, and reorgs, out of polling an archiver or a node. */ export class L2BlockStream {
|
|
8
7
|
l2BlockSource;
|
|
9
8
|
localData;
|
|
@@ -21,6 +20,9 @@ import { makeL2BlockId } from '../l2_block_source.js';
|
|
|
21
20
|
this.opts = opts;
|
|
22
21
|
this.isSyncing = false;
|
|
23
22
|
this.hasStarted = false;
|
|
23
|
+
if (opts.tipsOnly && (opts.startingBlock !== undefined || opts.batchSize !== undefined || opts.skipFinalized)) {
|
|
24
|
+
throw new Error('tipsOnly is incompatible with startingBlock, batchSize, and skipFinalized: all three are ' + 'block-download options and there is no download loop in tips-only mode.');
|
|
25
|
+
}
|
|
24
26
|
// Note that RunningPromise is in stopped state by default. This promise won't run until someone invokes `start`,
|
|
25
27
|
// which makes it run periodically, or `sync`, which triggers it once.
|
|
26
28
|
// Users of L2BlockStream decide what mode to run it in (_periodically_ vs _manually triggered_).
|
|
@@ -48,7 +50,8 @@ import { makeL2BlockId } from '../l2_block_source.js';
|
|
|
48
50
|
}
|
|
49
51
|
async work() {
|
|
50
52
|
try {
|
|
51
|
-
|
|
53
|
+
// The source tips snapshot is the plan for this pass; it is re-read after the walk-back if a divergence is found.
|
|
54
|
+
let sourceTips = await this.l2BlockSource.getL2Tips();
|
|
52
55
|
const localTips = await this.localData.getL2Tips();
|
|
53
56
|
this.log.trace(`Running L2 block stream`, {
|
|
54
57
|
sourceTips,
|
|
@@ -57,29 +60,52 @@ import { makeL2BlockId } from '../l2_block_source.js';
|
|
|
57
60
|
if (!this.opts.ignoreCheckpoints && localTips.checkpointed === undefined) {
|
|
58
61
|
throw new Error('Local data provider does not expose a checkpointed tip; checkpoint events require one ' + '(set ignoreCheckpoints or provide checkpointed tips).');
|
|
59
62
|
}
|
|
60
|
-
//
|
|
63
|
+
// Baseline for the chain-proposed event; captured before the local store mutates during the pass.
|
|
64
|
+
const prePassProposed = localTips.proposed;
|
|
65
|
+
// Walk back to find a reorg, floored at the local finalized tip (a legitimate reorg can never reach it, since
|
|
66
|
+
// finalized means the proving tx is itself L1-finalized). Seed the cache with ONLY the proposed tip: a stale
|
|
67
|
+
// tier seed at a reorged height equals the local old-fork hash, faking agreement and stopping the walk above the
|
|
68
|
+
// true divergence (an under-deep prune no later pass re-detects), whereas a stale proposed seed only masks the
|
|
69
|
+
// tip for one pass.
|
|
61
70
|
let latestBlockNumber = localTips.proposed.number;
|
|
62
71
|
const sourceCache = new BlockHashCache([
|
|
63
72
|
sourceTips.proposed
|
|
64
73
|
]);
|
|
74
|
+
const walkFloor = localTips.finalized.block.number;
|
|
65
75
|
while(!await this.areBlockHashesEqualAt(latestBlockNumber, {
|
|
66
|
-
sourceCache
|
|
76
|
+
sourceCache,
|
|
77
|
+
sourceProposed: sourceTips.proposed.number
|
|
67
78
|
})){
|
|
68
79
|
if (latestBlockNumber === 0) {
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
// they were configured with different `genesisTimestamp`/prefilled state. Continuing
|
|
72
|
-
// would underflow into negative block numbers and surface as "block hash not found
|
|
73
|
-
// for -1" further down. Fail loudly with a meaningful error instead.
|
|
80
|
+
// Walked back to genesis and the hashes still differ: the two sides disagree on block 0 itself (usually
|
|
81
|
+
// different genesisTimestamp/prefilled state). Fail loudly rather than underflow into negative heights.
|
|
74
82
|
this.log.error(`Genesis block hash mismatch between local store and source`, {
|
|
75
83
|
localBlockHash: await this.localData.getL2BlockHash(BlockNumber.ZERO),
|
|
76
84
|
sourceBlockHash: sourceCache.get(0) ?? await this.getBlockHashFromSource(BlockNumber.ZERO)
|
|
77
85
|
});
|
|
78
86
|
throw new Error('Genesis block hash mismatch between local store and source: refusing to walk past block 0. ' + 'This usually indicates the two sides were configured with different genesis values ' + '(e.g. genesisTimestamp or prefilled public data).');
|
|
79
87
|
}
|
|
88
|
+
if (latestBlockNumber <= walkFloor) {
|
|
89
|
+
// A mismatch at or below the finalized tip cannot be a reorg (it contradicts L1-finalized state), so stop
|
|
90
|
+
// here and prune at most to the finalized tip rather than pruning finalized state on non-reorg evidence.
|
|
91
|
+
this.log.warn(`Block hash mismatch at or below the local finalized tip; stopping the walk-back here`, {
|
|
92
|
+
blockNumber: latestBlockNumber,
|
|
93
|
+
finalizedBlockNumber: walkFloor,
|
|
94
|
+
localBlockHash: await this.localData.getL2BlockHash(latestBlockNumber),
|
|
95
|
+
sourceBlockHash: sourceCache.get(latestBlockNumber) ?? await this.getBlockHashFromSource(latestBlockNumber)
|
|
96
|
+
});
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
80
99
|
latestBlockNumber--;
|
|
81
100
|
}
|
|
101
|
+
let pruned = false;
|
|
82
102
|
if (latestBlockNumber < localTips.proposed.number) {
|
|
103
|
+
// Re-read the source tips after the (possibly slow) walk-back so the prune event carries fresh checkpointed
|
|
104
|
+
// and proven tips, and the prune-target clamp, download plan, and tier reconciliation track the post-prune
|
|
105
|
+
// source chain. Append only the re-read proposed tip: it is a fresh entry that cannot poison the (already
|
|
106
|
+
// finished) walk and serves the prune-event hash lookup below.
|
|
107
|
+
sourceTips = await this.l2BlockSource.getL2Tips();
|
|
108
|
+
sourceCache.add(sourceTips.proposed);
|
|
83
109
|
latestBlockNumber = BlockNumber(Math.min(latestBlockNumber, sourceTips.proposed.number)); // see #13471
|
|
84
110
|
const hash = sourceCache.get(latestBlockNumber) ?? await this.getBlockHashFromSource(latestBlockNumber);
|
|
85
111
|
if (latestBlockNumber !== 0 && !hash) {
|
|
@@ -92,160 +118,39 @@ import { makeL2BlockId } from '../l2_block_source.js';
|
|
|
92
118
|
checkpointed: sourceTips.checkpointed,
|
|
93
119
|
proven: sourceTips.proven
|
|
94
120
|
});
|
|
121
|
+
pruned = true;
|
|
95
122
|
}
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
// Only log this entry once (for sanity)
|
|
102
|
-
if (!this.hasStarted) {
|
|
103
|
-
this.log.verbose(`Starting sync from block number ${latestBlockNumber}`);
|
|
104
|
-
this.hasStarted = true;
|
|
105
|
-
}
|
|
106
|
-
let nextBlockNumber = latestBlockNumber + 1;
|
|
107
|
-
// When checkpoints are ignored the local provider may omit `checkpointed`; in that case the fallback to
|
|
108
|
-
// CheckpointNumber.ZERO is harmless because `nextCheckpointToEmit` is never consumed for emission (Loop 1 and
|
|
109
|
-
// the startingBlock/skipFinalized adjustments below only feed checkpoint emission, which is gated off).
|
|
110
|
-
let nextCheckpointToEmit = CheckpointNumber((localTips.checkpointed?.checkpoint.number ?? CheckpointNumber.ZERO) + 1);
|
|
111
|
-
// When startingBlock is set, also skip ahead for checkpoints.
|
|
112
|
-
if (startingBlock !== undefined && startingBlock >= 1 && nextCheckpointToEmit <= sourceTips.checkpointed.checkpoint.number) {
|
|
113
|
-
if (startingBlock > sourceTips.checkpointed.block.number) {
|
|
114
|
-
// startingBlock is past all checkpointed blocks; skip Loop 1 entirely.
|
|
115
|
-
nextCheckpointToEmit = CheckpointNumber(sourceTips.checkpointed.checkpoint.number + 1);
|
|
116
|
-
} else {
|
|
117
|
-
const startingBlockData = await this.l2BlockSource.getBlockData({
|
|
118
|
-
number: startingBlock
|
|
119
|
-
});
|
|
120
|
-
if (startingBlockData) {
|
|
121
|
-
nextCheckpointToEmit = CheckpointNumber(Math.max(nextCheckpointToEmit, startingBlockData.checkpointNumber));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
if (this.opts.skipFinalized) {
|
|
126
|
-
// When skipping finalized blocks we need to provide reliable reorg detection while fetching as few blocks as
|
|
127
|
-
// possible. Finalized blocks cannot be reorged by definition, so we can skip most of them. We do need the very
|
|
128
|
-
// last finalized block however in order to guarantee that we will eventually find a block in which our local
|
|
129
|
-
// store matches the source.
|
|
130
|
-
// If the last finalized block is behind our local tip, there is nothing to skip.
|
|
131
|
-
nextBlockNumber = Math.max(sourceTips.finalized.block.number, nextBlockNumber);
|
|
132
|
-
// If the next checkpoint to emit is behind the finalized tip then skip forward
|
|
133
|
-
nextCheckpointToEmit = CheckpointNumber(Math.max(nextCheckpointToEmit, sourceTips.finalized.checkpoint.number));
|
|
134
|
-
}
|
|
135
|
-
// Loop 1: Emit checkpoint events for checkpoints whose blocks are already in local storage.
|
|
136
|
-
// This handles the case where blocks were synced as uncheckpointed and later became checkpointed.
|
|
137
|
-
// The guard `lastBlockInCheckpoint.number > localTips.proposed.number` ensures we don't emit
|
|
138
|
-
// checkpoints for blocks we don't have (e.g., when startingBlock skips earlier blocks).
|
|
139
|
-
// Since only one checkpoint can ever be uncheckpointed, this loop should iterate at most once.
|
|
140
|
-
if (!this.opts.ignoreCheckpoints) {
|
|
141
|
-
let loop1Iterations = 0;
|
|
142
|
-
while(nextCheckpointToEmit <= sourceTips.checkpointed.checkpoint.number){
|
|
143
|
-
const checkpoints = await this.l2BlockSource.getCheckpoints({
|
|
144
|
-
from: nextCheckpointToEmit,
|
|
145
|
-
limit: 1
|
|
146
|
-
});
|
|
147
|
-
if (checkpoints.length === 0) {
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
const lastBlockInCheckpoint = checkpoints[0].checkpoint.blocks.at(-1);
|
|
151
|
-
// If this checkpoint has blocks we haven't seen yet, stop - they need to be fetched first
|
|
152
|
-
if (lastBlockInCheckpoint.number > localTips.proposed.number) {
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
loop1Iterations++;
|
|
156
|
-
if (loop1Iterations > 1) {
|
|
157
|
-
this.log.warn(`Emitting multiple checkpoints (${loop1Iterations}) for already-local blocks. ` + `Next checkpoint: ${nextCheckpointToEmit}, source checkpointed: ${sourceTips.checkpointed.checkpoint.number}`);
|
|
158
|
-
}
|
|
159
|
-
const lastBlockHash = await lastBlockInCheckpoint.hash();
|
|
160
|
-
await this.emitEvent({
|
|
161
|
-
type: 'chain-checkpointed',
|
|
162
|
-
checkpoint: checkpoints[0],
|
|
163
|
-
block: makeL2BlockId(lastBlockInCheckpoint.number, lastBlockHash.toString())
|
|
164
|
-
});
|
|
165
|
-
nextCheckpointToEmit = CheckpointNumber(nextCheckpointToEmit + 1);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
// Loop 2: Fetch new checkpointed blocks. For each checkpoint, emit all blocks
|
|
169
|
-
// from that checkpoint that we need, then emit the checkpoint event.
|
|
170
|
-
// We prefetch multiple checkpoints, then process them one by one.
|
|
171
|
-
let prefetchedCheckpoints = [];
|
|
172
|
-
let prefetchIdx = 0;
|
|
173
|
-
let nextCheckpointNumber;
|
|
174
|
-
// Find the starting checkpoint number
|
|
175
|
-
if (nextBlockNumber <= sourceTips.checkpointed.block.number) {
|
|
176
|
-
const blockData = await this.l2BlockSource.getBlockData({
|
|
177
|
-
number: BlockNumber(nextBlockNumber)
|
|
178
|
-
});
|
|
179
|
-
if (blockData) {
|
|
180
|
-
nextCheckpointNumber = blockData.checkpointNumber;
|
|
181
|
-
}
|
|
123
|
+
// Pass atomicity: a prune mid-download leaves the source unable to serve the planned blocks, so the snapshot's
|
|
124
|
+
// tier tips may reference blocks the consumer never saw — skip tier reconciliation in that case. Tips-only mode
|
|
125
|
+
// has no download plan (the snapshot is one atomic getL2Tips read), so it always reconciles.
|
|
126
|
+
if (!this.opts.tipsOnly && !await this.downloadBlocks(latestBlockNumber, sourceTips)) {
|
|
127
|
+
return;
|
|
182
128
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
prefetchedCheckpoints = await this.l2BlockSource.getCheckpoints({
|
|
188
|
-
from: nextCheckpointNumber,
|
|
189
|
-
limit: prefetchLimit
|
|
190
|
-
});
|
|
191
|
-
prefetchIdx = 0;
|
|
192
|
-
if (prefetchedCheckpoints.length === 0) {
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
const checkpoint = prefetchedCheckpoints[prefetchIdx];
|
|
197
|
-
// Get all blocks from this checkpoint that we need, respecting batchSize
|
|
198
|
-
const limit = Math.min(this.opts.batchSize ?? 50, sourceTips.checkpointed.block.number - nextBlockNumber + 1);
|
|
199
|
-
const blocksForCheckpoint = checkpoint.checkpoint.blocks.filter((b)=>b.number >= nextBlockNumber).slice(0, limit);
|
|
200
|
-
if (blocksForCheckpoint.length === 0) {
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
129
|
+
// End-of-pass reconciliation: chain-proposed fires against the pre-pass baseline (a post-prune re-read would
|
|
130
|
+
// equal the source tip and suppress it), then the tiers highest-to-lowest so the finalized <= proven <=
|
|
131
|
+
// checkpointed <= proposed invariant holds mid-pass.
|
|
132
|
+
if (this.blockTipDiffers(prePassProposed, sourceTips.proposed)) {
|
|
203
133
|
await this.emitEvent({
|
|
204
|
-
type: '
|
|
205
|
-
|
|
134
|
+
type: 'chain-proposed',
|
|
135
|
+
block: sourceTips.proposed
|
|
206
136
|
});
|
|
207
|
-
nextBlockNumber = blocksForCheckpoint.at(-1).number + 1;
|
|
208
|
-
// If we've reached the end of this checkpoint, emit the checkpoint event and move to next
|
|
209
|
-
const lastBlockInCheckpoint = checkpoint.checkpoint.blocks.at(-1);
|
|
210
|
-
if (nextBlockNumber > lastBlockInCheckpoint.number) {
|
|
211
|
-
if (!this.opts.ignoreCheckpoints) {
|
|
212
|
-
const lastBlockHash = await lastBlockInCheckpoint.hash();
|
|
213
|
-
await this.emitEvent({
|
|
214
|
-
type: 'chain-checkpointed',
|
|
215
|
-
checkpoint,
|
|
216
|
-
block: makeL2BlockId(lastBlockInCheckpoint.number, lastBlockHash.toString())
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
prefetchIdx++;
|
|
220
|
-
nextCheckpointNumber = CheckpointNumber(nextCheckpointNumber + 1);
|
|
221
|
-
}
|
|
222
137
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const limit = Math.min(this.opts.batchSize ?? 50, sourceTips.proposed.number - nextBlockNumber + 1);
|
|
226
|
-
this.log.trace(`Requesting blocks from ${nextBlockNumber} limit ${limit}`);
|
|
227
|
-
const blocks = await this.l2BlockSource.getBlocks({
|
|
228
|
-
from: BlockNumber(nextBlockNumber),
|
|
229
|
-
limit
|
|
230
|
-
});
|
|
231
|
-
if (blocks.length === 0) {
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
138
|
+
const reconcileTips = pruned ? await this.localData.getL2Tips() : localTips;
|
|
139
|
+
if (!this.opts.ignoreCheckpoints && this.tipDiffers(reconcileTips.checkpointed?.block, sourceTips.checkpointed)) {
|
|
234
140
|
await this.emitEvent({
|
|
235
|
-
type: '
|
|
236
|
-
|
|
141
|
+
type: 'chain-checkpointed',
|
|
142
|
+
block: sourceTips.checkpointed.block,
|
|
143
|
+
checkpoint: sourceTips.checkpointed.checkpoint
|
|
237
144
|
});
|
|
238
|
-
nextBlockNumber = blocks.at(-1).number + 1;
|
|
239
145
|
}
|
|
240
|
-
|
|
241
|
-
if (localTips.proven !== undefined && sourceTips.proven.block.number !== localTips.proven.block.number) {
|
|
146
|
+
if (reconcileTips.proven !== undefined && this.tipDiffers(reconcileTips.proven.block, sourceTips.proven)) {
|
|
242
147
|
await this.emitEvent({
|
|
243
148
|
type: 'chain-proven',
|
|
244
149
|
block: sourceTips.proven.block,
|
|
245
150
|
checkpoint: sourceTips.proven.checkpoint
|
|
246
151
|
});
|
|
247
152
|
}
|
|
248
|
-
if (
|
|
153
|
+
if (reconcileTips.finalized !== undefined && this.tipDiffers(reconcileTips.finalized.block, sourceTips.finalized)) {
|
|
249
154
|
await this.emitEvent({
|
|
250
155
|
type: 'chain-finalized',
|
|
251
156
|
block: sourceTips.finalized.block,
|
|
@@ -260,9 +165,101 @@ import { makeL2BlockId } from '../l2_block_source.js';
|
|
|
260
165
|
}
|
|
261
166
|
}
|
|
262
167
|
/**
|
|
168
|
+
* Downloads every block from the post-prune cursor through the source's proposed tip, emitting `blocks-added`
|
|
169
|
+
* events. The return value gates tier-cursor advancement (pass atomicity): tier tips may only be reconciled when
|
|
170
|
+
* the plan that backs them ran to the proposed tip.
|
|
171
|
+
* @returns `true` if the plan completed (caught up, or delivered the proposed tip with a matching hash); `false` if
|
|
172
|
+
* the source no longer has a promised block, or served a fork at the proposed height mid-pass.
|
|
173
|
+
*/ async downloadBlocks(latestBlockNumber, sourceTips) {
|
|
174
|
+
// The post-prune cursor: the highest block number both sides agree on. Block downloads resume from here.
|
|
175
|
+
let nextBlockNumber = latestBlockNumber + 1;
|
|
176
|
+
// From a fresh local store, fast-forward past history the consumer doesn't care about.
|
|
177
|
+
const startingBlock = this.opts.startingBlock !== undefined ? BlockNumber(this.opts.startingBlock) : undefined;
|
|
178
|
+
if (latestBlockNumber === 0 && startingBlock !== undefined) {
|
|
179
|
+
nextBlockNumber = Math.max(startingBlock, 1);
|
|
180
|
+
}
|
|
181
|
+
if (this.opts.skipFinalized) {
|
|
182
|
+
// Finalized blocks cannot be reorged, so skip them — but keep the last finalized block as the guaranteed point
|
|
183
|
+
// where local and source agree, the floor the walk-back terminates against.
|
|
184
|
+
nextBlockNumber = Math.max(sourceTips.finalized.block.number, nextBlockNumber);
|
|
185
|
+
}
|
|
186
|
+
if (!this.hasStarted) {
|
|
187
|
+
this.log.verbose(`Starting sync from block number ${nextBlockNumber - 1}`);
|
|
188
|
+
this.hasStarted = true;
|
|
189
|
+
}
|
|
190
|
+
let lastDeliveredBlock;
|
|
191
|
+
while(nextBlockNumber <= sourceTips.proposed.number){
|
|
192
|
+
const limit = Math.min(this.opts.batchSize ?? 50, sourceTips.proposed.number - nextBlockNumber + 1);
|
|
193
|
+
this.log.trace(`Requesting blocks from ${nextBlockNumber} limit ${limit}`);
|
|
194
|
+
const blocks = await this.l2BlockSource.getBlocks({
|
|
195
|
+
from: BlockNumber(nextBlockNumber),
|
|
196
|
+
limit
|
|
197
|
+
});
|
|
198
|
+
if (blocks.length === 0) {
|
|
199
|
+
// The source no longer has a block the snapshot promised: the snapshot is provably stale, so report the plan
|
|
200
|
+
// incomplete and skip reconciliation this pass.
|
|
201
|
+
this.log.warn(`Block source returned no blocks for a promised range; skipping reconciliation this pass`, {
|
|
202
|
+
from: nextBlockNumber,
|
|
203
|
+
limit,
|
|
204
|
+
sourceProposed: sourceTips.proposed.number
|
|
205
|
+
});
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
await this.emitEvent({
|
|
209
|
+
type: 'blocks-added',
|
|
210
|
+
blocks
|
|
211
|
+
});
|
|
212
|
+
lastDeliveredBlock = blocks.at(-1);
|
|
213
|
+
nextBlockNumber = lastDeliveredBlock.number + 1;
|
|
214
|
+
}
|
|
215
|
+
if (lastDeliveredBlock === undefined) {
|
|
216
|
+
// Loop never ran: caught up before the plan started, or startingBlock past the tip (A-1061). Trivially complete.
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
// Complete iff the block delivered at the proposed height carries the snapshot's proposed hash; a different hash
|
|
220
|
+
// means a same-height fork swap happened mid-pass, so the snapshot is stale.
|
|
221
|
+
const deliveredHash = (await lastDeliveredBlock.hash()).toString();
|
|
222
|
+
if (deliveredHash !== sourceTips.proposed.hash) {
|
|
223
|
+
this.log.warn(`Delivered proposed-block hash differs from snapshot; skipping reconciliation this pass`, {
|
|
224
|
+
blockNumber: lastDeliveredBlock.number,
|
|
225
|
+
deliveredHash,
|
|
226
|
+
snapshotHash: sourceTips.proposed.hash
|
|
227
|
+
});
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Returns whether the source tip differs from the local one and therefore warrants a tier event. Compares block
|
|
234
|
+
* number and, when both hashes are known, block hash. The hash comparison is skipped when the local hash is
|
|
235
|
+
* undefined or missing: world-state legitimately reports `undefined` hashes for tips ahead of its synced range,
|
|
236
|
+
* and comparing against an undefined hash would re-emit the event on every poll.
|
|
237
|
+
*/ tipDiffers(localBlock, sourceTip) {
|
|
238
|
+
return this.blockTipDiffers(localBlock, sourceTip.block);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Block-only variant of {@link tipDiffers} for the proposed tip (an {@link L2BlockId}, with no checkpoint). Compares
|
|
242
|
+
* block number and, when the local hash is known, block hash. The hash comparison is skipped when the local hash is
|
|
243
|
+
* undefined: world-state reports `undefined` for its proposed hash, and a strict comparison would re-emit
|
|
244
|
+
* `chain-proposed` on every poll for it. ({@link L2TipsStoreBase} consumers always carry a hash, so the leniency is
|
|
245
|
+
* inert for them.)
|
|
246
|
+
*/ blockTipDiffers(localBlock, sourceBlock) {
|
|
247
|
+
if (localBlock === undefined) {
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
if (sourceBlock.number !== localBlock.number) {
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
if (localBlock.hash === undefined) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
return sourceBlock.hash !== localBlock.hash;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
263
259
|
* Returns whether the source and local agree on the block hash at a given height.
|
|
264
260
|
* @param blockNumber - The block number to test.
|
|
265
|
-
* @param args - A cache of data already requested from source
|
|
261
|
+
* @param args - A cache of data already requested from source (to avoid re-requesting it) and the source's
|
|
262
|
+
* advertised proposed tip from the pass snapshot (to detect an incoherent source).
|
|
266
263
|
*/ async areBlockHashesEqualAt(blockNumber, args) {
|
|
267
264
|
const localBlockHash = await this.localData.getL2BlockHash(blockNumber);
|
|
268
265
|
if (!localBlockHash && this.opts.skipFinalized) {
|
|
@@ -273,6 +270,13 @@ import { makeL2BlockId } from '../l2_block_source.js';
|
|
|
273
270
|
this.log.error(`No local block hash for block number ${blockNumber}`);
|
|
274
271
|
throw new AbortError();
|
|
275
272
|
}
|
|
273
|
+
if (!localBlockHash) {
|
|
274
|
+
// A missing local hash compares UNEQUAL: treating both-undefined as equal would stop the walk above the true
|
|
275
|
+
// divergence (an under-deep prune no later pass re-detects). Over-deep is the safe direction, and block 0 always
|
|
276
|
+
// resolves via the store's initialBlockHash so the walk always terminates.
|
|
277
|
+
this.log.trace(`No local block hash for block number ${blockNumber}; treating as unequal`);
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
276
280
|
const sourceBlockHashFromCache = args.sourceCache.get(blockNumber);
|
|
277
281
|
const sourceBlockHash = args.sourceCache.get(blockNumber) ?? await this.getBlockHashFromSource(blockNumber);
|
|
278
282
|
if (!sourceBlockHashFromCache && sourceBlockHash) {
|
|
@@ -281,6 +285,15 @@ import { makeL2BlockId } from '../l2_block_source.js';
|
|
|
281
285
|
hash: sourceBlockHash
|
|
282
286
|
});
|
|
283
287
|
}
|
|
288
|
+
if (!sourceBlockHash && blockNumber !== 0 && blockNumber <= args.sourceProposed) {
|
|
289
|
+
// No source data at or below the source's own proposed tip: the source contradicts itself (mid-reorg unwind or
|
|
290
|
+
// a transient read failure), so skip this pass.
|
|
291
|
+
this.log.warn(`Source has no data for a block at or below its proposed tip; skipping this sync pass`, {
|
|
292
|
+
blockNumber,
|
|
293
|
+
sourceProposed: args.sourceProposed
|
|
294
|
+
});
|
|
295
|
+
throw new AbortError();
|
|
296
|
+
}
|
|
284
297
|
this.log.trace(`Comparing block hashes for block ${blockNumber}`, {
|
|
285
298
|
localBlockHash,
|
|
286
299
|
sourceBlockHash
|
|
@@ -293,7 +306,7 @@ import { makeL2BlockId } from '../l2_block_source.js';
|
|
|
293
306
|
}).then((d)=>d?.header.hash()).then((hash)=>hash?.toString());
|
|
294
307
|
}
|
|
295
308
|
async emitEvent(event) {
|
|
296
|
-
this.log.debug(`Emitting ${event.type} (${event.type === 'blocks-added' ? event.blocks.length : event.type === 'chain-checkpointed' ? event.checkpoint.
|
|
309
|
+
this.log.debug(`Emitting ${event.type} (${event.type === 'blocks-added' ? event.blocks.length : event.type === 'chain-checkpointed' ? event.checkpoint.number : event.block.number})`);
|
|
297
310
|
await this.handler.handleBlockStreamEvent(event);
|
|
298
311
|
if (!this.isRunning() && !this.isSyncing) {
|
|
299
312
|
throw new AbortError();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { BlockHash } from '../block_hash.js';
|
|
3
3
|
import type { L2Block } from '../l2_block.js';
|
|
4
|
-
import { type CheckpointId, type L2BlockTag, type LocalL2Tips } from '../l2_block_source.js';
|
|
4
|
+
import { type CheckpointId, type L2BlockId, type L2BlockTag, type LocalL2Tips } from '../l2_block_source.js';
|
|
5
5
|
import type { L2BlockStreamEvent, L2BlockStreamEventHandler, L2BlockStreamLocalDataProvider } from './interfaces.js';
|
|
6
6
|
/**
|
|
7
7
|
* Abstract base class for L2 tips stores. Provides common event handling logic
|
|
@@ -28,16 +28,24 @@ export declare abstract class L2TipsStoreBase implements L2BlockStreamEventHandl
|
|
|
28
28
|
protected abstract runInTransaction<T>(fn: () => Promise<T>): Promise<T>;
|
|
29
29
|
getL2BlockHash(number: BlockNumber): Promise<string | undefined>;
|
|
30
30
|
getL2Tips(): Promise<LocalL2Tips>;
|
|
31
|
+
/**
|
|
32
|
+
* Records `(number → hash)` witnesses into the block-hash index without moving any tip cursor. In tips-only mode
|
|
33
|
+
* the hash history is sparse (one anchor per tip-moving poll), so a consumer that materializes per-height state
|
|
34
|
+
* should witness those heights or its prunes are over-deep by the gap to the nearest anchor. Witnesses are compared
|
|
35
|
+
* against the source, not trusted, so they cannot cause under-deep prunes; this is always safe to call.
|
|
36
|
+
*/
|
|
37
|
+
recordBlockHashes(blocks: L2BlockId[]): Promise<void>;
|
|
31
38
|
handleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void>;
|
|
32
39
|
protected computeBlockHash(block: L2Block): Promise<string>;
|
|
33
40
|
private getBlockId;
|
|
34
41
|
private getCheckpointId;
|
|
35
42
|
private genesisCheckpointId;
|
|
36
43
|
private handleBlocksAdded;
|
|
44
|
+
private handleChainProposed;
|
|
37
45
|
private handleChainCheckpointed;
|
|
38
46
|
private handleChainPruned;
|
|
39
47
|
private handleChainProven;
|
|
40
48
|
private handleChainFinalized;
|
|
41
49
|
private saveTag;
|
|
42
50
|
}
|
|
43
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
51
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDJfdGlwc19zdG9yZV9iYXNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYmxvY2svbDJfYmxvY2tfc3RyZWFtL2wyX3RpcHNfc3RvcmVfYmF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FFWSxzQkFBc0IsQ0FBQyxLQUFLLEVBQUUsa0JBQWtCLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQXFCNUU7SUFHRCxTQUFTLENBQUMsZ0JBQWdCLENBQUMsS0FBSyxFQUFFLE9BQU8sR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBRTFEO1lBSWEsVUFBVTtZQVlWLGVBQWU7SUFnQjdCLE9BQU8sQ0FBQyxtQkFBbUI7WUFJYixpQkFBaUI7WUFhakIsbUJBQW1CO1lBU25CLHVCQUF1QjtZQVV2QixpQkFBaUI7WUEyQmpCLGlCQUFpQjtZQVVqQixvQkFBb0I7WUFtQnBCLE9BQU87Q0FNdEIifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"l2_tips_store_base.d.ts","sourceRoot":"","sources":["../../../src/block/l2_block_stream/l2_tips_store_base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAoB,MAAM,iCAAiC,CAAC;AAEhF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EACL,KAAK,YAAY,
|
|
1
|
+
{"version":3,"file":"l2_tips_store_base.d.ts","sourceRoot":"","sources":["../../../src/block/l2_block_stream/l2_tips_store_base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAoB,MAAM,iCAAiC,CAAC;AAEhF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,WAAW,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,C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D,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAK5E;IAEM,SAAS,IAAI,OAAO,CAAC,WAAW,CAAC,CAsBvC;IAED;;;;;OAKG;IACU,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAQjE;IAEY,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB5E;IAGD,SAAS,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAE1D;YAIa,UAAU;YAYV,eAAe;IAgB7B,OAAO,CAAC,mBAAmB;YAIb,iBAAiB;YAajB,mBAAmB;YASnB,uBAAuB;YAUvB,iBAAiB;YA2BjB,iBAAiB;YAUjB,oBAAoB;YAmBpB,OAAO;CAMtB"}
|
|
@@ -45,11 +45,28 @@ import { GENESIS_CHECKPOINT_HEADER_HASH } from '../l2_block_source.js';
|
|
|
45
45
|
};
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Records `(number → hash)` witnesses into the block-hash index without moving any tip cursor. In tips-only mode
|
|
50
|
+
* the hash history is sparse (one anchor per tip-moving poll), so a consumer that materializes per-height state
|
|
51
|
+
* should witness those heights or its prunes are over-deep by the gap to the nearest anchor. Witnesses are compared
|
|
52
|
+
* against the source, not trusted, so they cannot cause under-deep prunes; this is always safe to call.
|
|
53
|
+
*/ async recordBlockHashes(blocks) {
|
|
54
|
+
await this.runInTransaction(async ()=>{
|
|
55
|
+
for (const block of blocks){
|
|
56
|
+
if (block.hash) {
|
|
57
|
+
await this.setBlockHash(block.number, block.hash);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
48
62
|
async handleBlockStreamEvent(event) {
|
|
49
63
|
switch(event.type){
|
|
50
64
|
case 'blocks-added':
|
|
51
65
|
await this.handleBlocksAdded(event);
|
|
52
66
|
break;
|
|
67
|
+
case 'chain-proposed':
|
|
68
|
+
await this.handleChainProposed(event);
|
|
69
|
+
break;
|
|
53
70
|
case 'chain-checkpointed':
|
|
54
71
|
await this.handleChainCheckpointed(event);
|
|
55
72
|
break;
|
|
@@ -119,17 +136,21 @@ import { GENESIS_CHECKPOINT_HEADER_HASH } from '../l2_block_source.js';
|
|
|
119
136
|
await this.setTip('proposed', blocks.at(-1).number);
|
|
120
137
|
});
|
|
121
138
|
}
|
|
139
|
+
async handleChainProposed(event) {
|
|
140
|
+
if (event.type !== 'chain-proposed') {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
// Records the proposed tip into the block-hash index the walk-back reads. In tips-only mode this is the sole
|
|
144
|
+
// writer of proposed-tip history, leaving one sparse anchor per tip-moving pass for reorg detection.
|
|
145
|
+
await this.runInTransaction(()=>this.saveTag('proposed', event.block));
|
|
146
|
+
}
|
|
122
147
|
async handleChainCheckpointed(event) {
|
|
123
148
|
if (event.type !== 'chain-checkpointed') {
|
|
124
149
|
return;
|
|
125
150
|
}
|
|
126
151
|
await this.runInTransaction(async ()=>{
|
|
127
|
-
const checkpointId = {
|
|
128
|
-
number: event.checkpoint.checkpoint.number,
|
|
129
|
-
hash: event.checkpoint.checkpoint.hash().toString()
|
|
130
|
-
};
|
|
131
152
|
await this.saveTag('checkpointed', event.block);
|
|
132
|
-
await this.setTipCheckpoint('checkpointed',
|
|
153
|
+
await this.setTipCheckpoint('checkpointed', event.checkpoint);
|
|
133
154
|
});
|
|
134
155
|
}
|
|
135
156
|
async handleChainPruned(event) {
|
|
@@ -137,17 +158,14 @@ import { GENESIS_CHECKPOINT_HEADER_HASH } from '../l2_block_source.js';
|
|
|
137
158
|
return;
|
|
138
159
|
}
|
|
139
160
|
await this.runInTransaction(async ()=>{
|
|
140
|
-
// A prune is a rollback: the proposed tip moves to the prune target unconditionally, but
|
|
141
|
-
//
|
|
142
|
-
//
|
|
143
|
-
// would then throw on.
|
|
161
|
+
// A prune is a rollback: the proposed tip moves to the prune target unconditionally, but checkpoint-bearing
|
|
162
|
+
// cursors may only move backward (advancing one onto an uncheckpointed block would leave it without a recorded
|
|
163
|
+
// checkpoint id, which getCheckpointId throws on).
|
|
144
164
|
await this.saveTag('proposed', event.block);
|
|
145
|
-
// Clamp each checkpoint-bearing cursor down to its OWN source tip when it leads it
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
//
|
|
149
|
-
// boundary, so the clamped cursor always resolves to a recorded id. The source guarantees proven <=
|
|
150
|
-
// checkpointed, so clamping each cursor to its own tip preserves the local proven <= checkpointed invariant.
|
|
165
|
+
// Clamp each checkpoint-bearing cursor down to its OWN source tip when it leads it; the event carries a valid
|
|
166
|
+
// (block, id) pair for each. Clamping the proven cursor onto the (possibly higher) checkpointed tip instead
|
|
167
|
+
// would transiently report unproven blocks as proven. The source guarantees proven <= checkpointed, so per-tip
|
|
168
|
+
// clamping preserves the local invariant.
|
|
151
169
|
for (const { tag, sourceTip } of [
|
|
152
170
|
{
|
|
153
171
|
tag: 'checkpointed',
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { L2TipsStore } from '../l2_block_stream/index.js';
|
|
2
2
|
export declare function testL2TipsStore(makeTipsStore: () => Promise<L2TipsStore>): void;
|
|
3
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDJfdGlwc19zdG9yZV90ZXN0X3N1aXRlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYmxvY2svdGVzdC9sMl90aXBzX3N0b3JlX3Rlc3Rfc3VpdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBZ0JBLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBRS9ELHdCQUFnQixlQUFlLENBQUMsYUFBYSxFQUFFLE1BQU0sT0FBTyxDQUFDLFdBQVcsQ0FBQyxRQSt2QnhFIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"l2_tips_store_test_suite.d.ts","sourceRoot":"","sources":["../../../src/block/test/l2_tips_store_test_suite.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D,wBAAgB,eAAe,CAAC,aAAa,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"l2_tips_store_test_suite.d.ts","sourceRoot":"","sources":["../../../src/block/test/l2_tips_store_test_suite.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D,wBAAgB,eAAe,CAAC,aAAa,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,QA+vBxE"}
|