@aztec/txe 0.0.1-commit.9593d84 → 0.0.1-commit.96bb3f7
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/constants.d.ts +4 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +3 -0
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -2
- package/dest/oracle/interfaces.d.ts +9 -6
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +5 -5
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +4 -6
- package/dest/oracle/txe_oracle_top_level_context.d.ts +21 -12
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +93 -62
- package/dest/rpc_translator.d.ts +11 -5
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +57 -15
- package/dest/state_machine/archiver.d.ts +29 -11
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +128 -17
- package/dest/state_machine/dummy_p2p_client.d.ts +8 -7
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +16 -11
- package/dest/state_machine/global_variable_builder.d.ts +6 -5
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +13 -1
- package/dest/state_machine/index.d.ts +5 -5
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +14 -20
- package/dest/state_machine/mock_epoch_cache.d.ts +2 -1
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +3 -0
- package/dest/state_machine/synchronizer.d.ts +5 -4
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +5 -4
- package/dest/txe_session.d.ts +19 -13
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +76 -45
- package/dest/util/encoding.d.ts +610 -11
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +1 -1
- package/dest/util/txe_account_store.d.ts +10 -0
- package/dest/util/txe_account_store.d.ts.map +1 -0
- package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
- package/dest/util/txe_contract_store.d.ts +12 -0
- package/dest/util/txe_contract_store.d.ts.map +1 -0
- package/dest/util/{txe_contract_data_provider.js → txe_contract_store.js} +3 -3
- package/dest/util/txe_public_contract_data_source.d.ts +7 -6
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +11 -11
- package/dest/utils/block_creation.d.ts +19 -4
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +24 -4
- package/dest/utils/tx_effect_creation.d.ts +4 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +1 -1
- package/package.json +17 -17
- package/src/constants.ts +4 -0
- package/src/index.ts +15 -12
- package/src/oracle/interfaces.ts +8 -5
- package/src/oracle/txe_oracle_public_context.ts +6 -11
- package/src/oracle/txe_oracle_top_level_context.ts +139 -88
- package/src/rpc_translator.ts +82 -12
- package/src/state_machine/archiver.ts +168 -26
- package/src/state_machine/dummy_p2p_client.ts +21 -14
- package/src/state_machine/global_variable_builder.ts +21 -4
- package/src/state_machine/index.ts +19 -18
- package/src/state_machine/mock_epoch_cache.ts +4 -0
- package/src/state_machine/synchronizer.ts +8 -7
- package/src/txe_session.ts +166 -75
- package/src/util/encoding.ts +1 -1
- package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
- package/src/util/{txe_contract_data_provider.ts → txe_contract_store.ts} +3 -3
- package/src/util/txe_public_contract_data_source.ts +13 -12
- package/src/utils/block_creation.ts +36 -5
- package/src/utils/tx_effect_creation.ts +3 -2
- package/dest/util/txe_account_data_provider.d.ts +0 -10
- package/dest/util/txe_account_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.d.ts +0 -12
- package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
package/src/rpc_translator.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { ContractInstanceWithAddress } from '@aztec/aztec.js/contracts';
|
|
2
2
|
import { Fr, Point } from '@aztec/aztec.js/fields';
|
|
3
3
|
import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX } from '@aztec/constants';
|
|
4
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
4
5
|
import {
|
|
5
6
|
type IMiscOracle,
|
|
6
7
|
type IPrivateExecutionOracle,
|
|
7
8
|
type IUtilityExecutionOracle,
|
|
8
9
|
packAsRetrievedNote,
|
|
9
10
|
} from '@aztec/pxe/simulator';
|
|
10
|
-
import { type ContractArtifact, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
11
|
+
import { type ContractArtifact, EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
11
12
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
12
13
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
13
14
|
|
|
@@ -29,6 +30,9 @@ import {
|
|
|
29
30
|
toSingle,
|
|
30
31
|
} from './util/encoding.js';
|
|
31
32
|
|
|
33
|
+
const MAX_EVENT_LEN = 12; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_RESERVED_FIELDS
|
|
34
|
+
const MAX_PRIVATE_EVENTS_PER_TXE_QUERY = 5;
|
|
35
|
+
|
|
32
36
|
export class UnavailableOracleError extends Error {
|
|
33
37
|
constructor(oracleName: string) {
|
|
34
38
|
super(`${oracleName} oracles not available with the current handler`);
|
|
@@ -117,7 +121,7 @@ export class RPCTranslator {
|
|
|
117
121
|
: undefined;
|
|
118
122
|
|
|
119
123
|
const anchorBlockNumber = fromSingle(foreignAnchorBlockNumberIsSome).toBool()
|
|
120
|
-
? fromSingle(foreignAnchorBlockNumberValue).toNumber()
|
|
124
|
+
? BlockNumber(fromSingle(foreignAnchorBlockNumberValue).toNumber())
|
|
121
125
|
: undefined;
|
|
122
126
|
|
|
123
127
|
const privateContextInputs = await this.stateHandler.enterPrivateState(contractAddress, anchorBlockNumber);
|
|
@@ -155,6 +159,12 @@ export class RPCTranslator {
|
|
|
155
159
|
|
|
156
160
|
// TXE-specific oracles
|
|
157
161
|
|
|
162
|
+
txeGetDefaultAddress() {
|
|
163
|
+
const defaultAddress = this.handlerAsTxe().txeGetDefaultAddress();
|
|
164
|
+
|
|
165
|
+
return toForeignCallResult([toSingle(defaultAddress)]);
|
|
166
|
+
}
|
|
167
|
+
|
|
158
168
|
async txeGetNextBlockNumber() {
|
|
159
169
|
const nextBlockNumber = await this.handlerAsTxe().txeGetNextBlockNumber();
|
|
160
170
|
|
|
@@ -266,6 +276,39 @@ export class RPCTranslator {
|
|
|
266
276
|
]);
|
|
267
277
|
}
|
|
268
278
|
|
|
279
|
+
async txeGetPrivateEvents(
|
|
280
|
+
foreignSelector: ForeignCallSingle,
|
|
281
|
+
foreignContractAddress: ForeignCallSingle,
|
|
282
|
+
foreignScope: ForeignCallSingle,
|
|
283
|
+
) {
|
|
284
|
+
const selector = EventSelector.fromField(fromSingle(foreignSelector));
|
|
285
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
286
|
+
const scope = addressFromSingle(foreignScope);
|
|
287
|
+
|
|
288
|
+
const events = await this.handlerAsTxe().txeGetPrivateEvents(selector, contractAddress, scope);
|
|
289
|
+
|
|
290
|
+
if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
|
|
291
|
+
throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (events.some(e => e.length > MAX_EVENT_LEN)) {
|
|
295
|
+
throw new Error(`Some private event has length larger than maxLen ${MAX_EVENT_LEN}`);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// This is a workaround as Noir does not currently let us return nested structs with arrays. We instead return a raw
|
|
299
|
+
// multidimensional array in get_private_events_oracle and create the BoundedVecs here.
|
|
300
|
+
const rawArrayStorage = events
|
|
301
|
+
.map(e => e.concat(Array(MAX_EVENT_LEN - e.length).fill(new Fr(0))))
|
|
302
|
+
.concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(Array(MAX_EVENT_LEN).fill(new Fr(0))))
|
|
303
|
+
.flat();
|
|
304
|
+
const eventLengths = events
|
|
305
|
+
.map(e => new Fr(e.length))
|
|
306
|
+
.concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(new Fr(0)));
|
|
307
|
+
const queryLength = new Fr(events.length);
|
|
308
|
+
|
|
309
|
+
return toForeignCallResult([toArray(rawArrayStorage), toArray(eventLengths), toSingle(queryLength)]);
|
|
310
|
+
}
|
|
311
|
+
|
|
269
312
|
privateStoreInExecutionCache(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
|
|
270
313
|
const values = fromArray(foreignValues);
|
|
271
314
|
const hash = fromSingle(foreignHash);
|
|
@@ -310,7 +353,7 @@ export class RPCTranslator {
|
|
|
310
353
|
) {
|
|
311
354
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
312
355
|
const startStorageSlot = fromSingle(foreignStartStorageSlot);
|
|
313
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
356
|
+
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
314
357
|
const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
|
|
315
358
|
|
|
316
359
|
const values = await this.handlerAsUtility().utilityStorageRead(
|
|
@@ -324,7 +367,7 @@ export class RPCTranslator {
|
|
|
324
367
|
}
|
|
325
368
|
|
|
326
369
|
async utilityGetPublicDataWitness(foreignBlockNumber: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
|
|
327
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
370
|
+
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
328
371
|
const leafSlot = fromSingle(foreignLeafSlot);
|
|
329
372
|
|
|
330
373
|
const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockNumber, leafSlot);
|
|
@@ -336,6 +379,8 @@ export class RPCTranslator {
|
|
|
336
379
|
}
|
|
337
380
|
|
|
338
381
|
async utilityGetNotes(
|
|
382
|
+
foreignOwnerIsSome: ForeignCallSingle,
|
|
383
|
+
foreignOwnerValue: ForeignCallSingle,
|
|
339
384
|
foreignStorageSlot: ForeignCallSingle,
|
|
340
385
|
foreignNumSelects: ForeignCallSingle,
|
|
341
386
|
foreignSelectByIndexes: ForeignCallArray,
|
|
@@ -353,6 +398,10 @@ export class RPCTranslator {
|
|
|
353
398
|
foreignMaxNotes: ForeignCallSingle,
|
|
354
399
|
foreignPackedRetrievedNoteLength: ForeignCallSingle,
|
|
355
400
|
) {
|
|
401
|
+
// Parse Option<AztecAddress>: ownerIsSome is 0 for None, 1 for Some
|
|
402
|
+
const owner = fromSingle(foreignOwnerIsSome).toBool()
|
|
403
|
+
? AztecAddress.fromField(fromSingle(foreignOwnerValue))
|
|
404
|
+
: undefined;
|
|
356
405
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
357
406
|
const numSelects = fromSingle(foreignNumSelects).toNumber();
|
|
358
407
|
const selectByIndexes = fromArray(foreignSelectByIndexes).map(fr => fr.toNumber());
|
|
@@ -371,6 +420,7 @@ export class RPCTranslator {
|
|
|
371
420
|
const packedRetrievedNoteLength = fromSingle(foreignPackedRetrievedNoteLength).toNumber();
|
|
372
421
|
|
|
373
422
|
const noteDatas = await this.handlerAsUtility().utilityGetNotes(
|
|
423
|
+
owner,
|
|
374
424
|
storageSlot,
|
|
375
425
|
numSelects,
|
|
376
426
|
selectByIndexes,
|
|
@@ -387,7 +437,17 @@ export class RPCTranslator {
|
|
|
387
437
|
status,
|
|
388
438
|
);
|
|
389
439
|
|
|
390
|
-
const returnDataAsArrayOfArrays = noteDatas.map(
|
|
440
|
+
const returnDataAsArrayOfArrays = noteDatas.map(noteData =>
|
|
441
|
+
packAsRetrievedNote({
|
|
442
|
+
contractAddress: noteData.contractAddress,
|
|
443
|
+
owner: noteData.owner,
|
|
444
|
+
randomness: noteData.randomness,
|
|
445
|
+
storageSlot: noteData.storageSlot,
|
|
446
|
+
noteNonce: noteData.noteNonce,
|
|
447
|
+
index: noteData.index,
|
|
448
|
+
note: noteData.note,
|
|
449
|
+
}),
|
|
450
|
+
);
|
|
391
451
|
|
|
392
452
|
// Now we convert each sub-array to an array of ForeignCallSingles
|
|
393
453
|
const returnDataAsArrayOfForeignCallSingleArrays = returnDataAsArrayOfArrays.map(subArray =>
|
|
@@ -405,6 +465,7 @@ export class RPCTranslator {
|
|
|
405
465
|
}
|
|
406
466
|
|
|
407
467
|
privateNotifyCreatedNote(
|
|
468
|
+
foreignOwner: ForeignCallSingle,
|
|
408
469
|
foreignStorageSlot: ForeignCallSingle,
|
|
409
470
|
foreignRandomness: ForeignCallSingle,
|
|
410
471
|
foreignNoteTypeId: ForeignCallSingle,
|
|
@@ -412,6 +473,7 @@ export class RPCTranslator {
|
|
|
412
473
|
foreignNoteHash: ForeignCallSingle,
|
|
413
474
|
foreignCounter: ForeignCallSingle,
|
|
414
475
|
) {
|
|
476
|
+
const owner = addressFromSingle(foreignOwner);
|
|
415
477
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
416
478
|
const randomness = fromSingle(foreignRandomness);
|
|
417
479
|
const noteTypeId = NoteSelector.fromField(fromSingle(foreignNoteTypeId));
|
|
@@ -419,7 +481,15 @@ export class RPCTranslator {
|
|
|
419
481
|
const noteHash = fromSingle(foreignNoteHash);
|
|
420
482
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
421
483
|
|
|
422
|
-
this.handlerAsPrivate().privateNotifyCreatedNote(
|
|
484
|
+
this.handlerAsPrivate().privateNotifyCreatedNote(
|
|
485
|
+
owner,
|
|
486
|
+
storageSlot,
|
|
487
|
+
randomness,
|
|
488
|
+
noteTypeId,
|
|
489
|
+
note,
|
|
490
|
+
noteHash,
|
|
491
|
+
counter,
|
|
492
|
+
);
|
|
423
493
|
|
|
424
494
|
return toForeignCallResult([]);
|
|
425
495
|
}
|
|
@@ -502,7 +572,7 @@ export class RPCTranslator {
|
|
|
502
572
|
foreignBlockNumber: ForeignCallSingle,
|
|
503
573
|
foreignNullifier: ForeignCallSingle,
|
|
504
574
|
) {
|
|
505
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
575
|
+
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
506
576
|
const nullifier = fromSingle(foreignNullifier);
|
|
507
577
|
|
|
508
578
|
const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockNumber, nullifier);
|
|
@@ -552,14 +622,14 @@ export class RPCTranslator {
|
|
|
552
622
|
return toForeignCallResult([toSingle(new Fr(isRevertible))]);
|
|
553
623
|
}
|
|
554
624
|
|
|
555
|
-
|
|
556
|
-
const context =
|
|
625
|
+
utilityGetUtilityContext() {
|
|
626
|
+
const context = this.handlerAsUtility().utilityGetUtilityContext();
|
|
557
627
|
|
|
558
628
|
return toForeignCallResult(context.toNoirRepresentation());
|
|
559
629
|
}
|
|
560
630
|
|
|
561
631
|
async utilityGetBlockHeader(foreignBlockNumber: ForeignCallSingle) {
|
|
562
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
632
|
+
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
563
633
|
|
|
564
634
|
const header = await this.handlerAsUtility().utilityGetBlockHeader(blockNumber);
|
|
565
635
|
|
|
@@ -574,7 +644,7 @@ export class RPCTranslator {
|
|
|
574
644
|
foreignTreeId: ForeignCallSingle,
|
|
575
645
|
foreignLeafValue: ForeignCallSingle,
|
|
576
646
|
) {
|
|
577
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
647
|
+
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
578
648
|
const treeId = fromSingle(foreignTreeId).toNumber();
|
|
579
649
|
const leafValue = fromSingle(foreignLeafValue);
|
|
580
650
|
|
|
@@ -592,7 +662,7 @@ export class RPCTranslator {
|
|
|
592
662
|
foreignBlockNumber: ForeignCallSingle,
|
|
593
663
|
foreignNullifier: ForeignCallSingle,
|
|
594
664
|
) {
|
|
595
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
665
|
+
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
596
666
|
const nullifier = fromSingle(foreignNullifier);
|
|
597
667
|
|
|
598
668
|
const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockNumber, nullifier);
|
|
@@ -1,11 +1,24 @@
|
|
|
1
|
-
import { ArchiverStoreHelper, KVArchiverDataStore
|
|
1
|
+
import { ArchiverStoreHelper, KVArchiverDataStore } from '@aztec/archiver';
|
|
2
2
|
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
3
|
-
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
5
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
|
-
import {
|
|
6
|
+
import { isDefined } from '@aztec/foundation/types';
|
|
6
7
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
7
8
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
|
-
import
|
|
9
|
+
import {
|
|
10
|
+
type CheckpointId,
|
|
11
|
+
CommitteeAttestation,
|
|
12
|
+
L2Block,
|
|
13
|
+
type L2BlockId,
|
|
14
|
+
type L2BlockNew,
|
|
15
|
+
type L2BlockSource,
|
|
16
|
+
type L2TipId,
|
|
17
|
+
type L2Tips,
|
|
18
|
+
PublishedL2Block,
|
|
19
|
+
type ValidateCheckpointResult,
|
|
20
|
+
} from '@aztec/stdlib/block';
|
|
21
|
+
import { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
9
22
|
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
10
23
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
11
24
|
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
@@ -19,11 +32,28 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
|
|
|
19
32
|
super(new KVArchiverDataStore(db, 9999));
|
|
20
33
|
}
|
|
21
34
|
|
|
22
|
-
public
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
35
|
+
public async getBlock(number: BlockNumber): Promise<L2Block | undefined> {
|
|
36
|
+
if (number === 0) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
const publishedBlocks = await this.getPublishedBlocks(number, 1);
|
|
40
|
+
if (publishedBlocks.length === 0) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
return publishedBlocks[0].block;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public async getBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<L2Block[]> {
|
|
47
|
+
const publishedBlocks = await this.getPublishedBlocks(from, limit, proven);
|
|
48
|
+
return publishedBlocks.map(x => x.block);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public override async addCheckpoints(
|
|
52
|
+
checkpoints: PublishedCheckpoint[],
|
|
53
|
+
_result?: ValidateCheckpointResult,
|
|
54
|
+
): Promise<boolean> {
|
|
55
|
+
const allBlocks = checkpoints.flatMap(ch => ch.checkpoint.blocks);
|
|
56
|
+
const opResults = await Promise.all([this.store.addLogs(allBlocks), this.store.addCheckpoints(checkpoints)]);
|
|
27
57
|
|
|
28
58
|
return opResults.every(Boolean);
|
|
29
59
|
}
|
|
@@ -32,16 +62,16 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
|
|
|
32
62
|
* Gets the number of the latest L2 block processed by the block source implementation.
|
|
33
63
|
* @returns The number of the latest L2 block processed by the block source implementation.
|
|
34
64
|
*/
|
|
35
|
-
public getBlockNumber(): Promise<
|
|
36
|
-
return this.store.
|
|
65
|
+
public getBlockNumber(): Promise<BlockNumber> {
|
|
66
|
+
return this.store.getLatestBlockNumber();
|
|
37
67
|
}
|
|
38
68
|
|
|
39
69
|
/**
|
|
40
70
|
* Gets the number of the latest L2 block proven seen by the block source implementation.
|
|
41
71
|
* @returns The number of the latest L2 block proven seen by the block source implementation.
|
|
42
72
|
*/
|
|
43
|
-
public getProvenBlockNumber(): Promise<
|
|
44
|
-
return this.store.
|
|
73
|
+
public override getProvenBlockNumber(): Promise<BlockNumber> {
|
|
74
|
+
return this.store.getProvenBlockNumber();
|
|
45
75
|
}
|
|
46
76
|
|
|
47
77
|
/**
|
|
@@ -49,16 +79,65 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
|
|
|
49
79
|
* @param number - The block number to return (inclusive).
|
|
50
80
|
* @returns The requested L2 block.
|
|
51
81
|
*/
|
|
52
|
-
public
|
|
82
|
+
public async getPublishedBlock(number: number): Promise<PublishedL2Block | undefined> {
|
|
53
83
|
// If the number provided is -ve, then return the latest block.
|
|
54
84
|
if (number < 0) {
|
|
55
|
-
number = await this.store.
|
|
85
|
+
number = await this.store.getLatestBlockNumber();
|
|
56
86
|
}
|
|
57
87
|
if (number == 0) {
|
|
58
88
|
return undefined;
|
|
59
89
|
}
|
|
60
|
-
const
|
|
61
|
-
return
|
|
90
|
+
const publishedBlocks = await this.retrievePublishedBlocks(BlockNumber(number), 1);
|
|
91
|
+
return publishedBlocks.length === 0 ? undefined : publishedBlocks[0];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getPublishedBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<PublishedL2Block[]> {
|
|
95
|
+
return this.retrievePublishedBlocks(from, limit, proven);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async getL2BlocksNew(from: BlockNumber, limit: number, proven?: boolean): Promise<L2BlockNew[]> {
|
|
99
|
+
const blocks = await this.store.getBlocks(from, limit);
|
|
100
|
+
|
|
101
|
+
if (proven === true) {
|
|
102
|
+
const provenBlockNumber = await this.store.getProvenBlockNumber();
|
|
103
|
+
return blocks.filter(b => b.number <= provenBlockNumber);
|
|
104
|
+
}
|
|
105
|
+
return blocks;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private async retrievePublishedBlocks(
|
|
109
|
+
from: BlockNumber,
|
|
110
|
+
limit: number,
|
|
111
|
+
proven?: boolean,
|
|
112
|
+
): Promise<PublishedL2Block[]> {
|
|
113
|
+
const checkpoints = await this.store.getRangeOfCheckpoints(CheckpointNumber(from), limit);
|
|
114
|
+
const provenCheckpointNumber = await this.store.getProvenCheckpointNumber();
|
|
115
|
+
const blocks = (
|
|
116
|
+
await Promise.all(checkpoints.map(ch => this.store.getBlocksForCheckpoint(ch.checkpointNumber)))
|
|
117
|
+
).filter(isDefined);
|
|
118
|
+
|
|
119
|
+
const olbBlocks: PublishedL2Block[] = [];
|
|
120
|
+
for (let i = 0; i < checkpoints.length; i++) {
|
|
121
|
+
const blockForCheckpoint = blocks[i][0];
|
|
122
|
+
const checkpoint = checkpoints[i];
|
|
123
|
+
if (proven === true && checkpoint.checkpointNumber > provenCheckpointNumber) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const oldCheckpoint = new Checkpoint(
|
|
127
|
+
blockForCheckpoint.archive,
|
|
128
|
+
checkpoint.header,
|
|
129
|
+
[blockForCheckpoint],
|
|
130
|
+
checkpoint.checkpointNumber,
|
|
131
|
+
);
|
|
132
|
+
const oldBlock = L2Block.fromCheckpoint(oldCheckpoint);
|
|
133
|
+
const publishedBlock = new PublishedL2Block(
|
|
134
|
+
oldBlock,
|
|
135
|
+
checkpoint.l1,
|
|
136
|
+
checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
|
|
137
|
+
);
|
|
138
|
+
olbBlocks.push(publishedBlock);
|
|
139
|
+
}
|
|
140
|
+
return olbBlocks;
|
|
62
141
|
}
|
|
63
142
|
|
|
64
143
|
/**
|
|
@@ -66,8 +145,20 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
|
|
|
66
145
|
* @param number - The block number to return (inclusive).
|
|
67
146
|
* @returns The requested L2 block.
|
|
68
147
|
*/
|
|
69
|
-
public
|
|
70
|
-
return this.getPublishedBlock(number != 'latest' ? number : -1).then(
|
|
148
|
+
public getL2Block(number: BlockNumber | 'latest'): Promise<L2Block | undefined> {
|
|
149
|
+
return this.getPublishedBlock(number != 'latest' ? number : -1).then(b => b?.block);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Gets an L2 block (new format).
|
|
154
|
+
* @param number - The block number to return.
|
|
155
|
+
* @returns The requested L2 block.
|
|
156
|
+
*/
|
|
157
|
+
public getL2BlockNew(number: BlockNumber): Promise<L2BlockNew | undefined> {
|
|
158
|
+
if (number === 0) {
|
|
159
|
+
return Promise.resolve(undefined);
|
|
160
|
+
}
|
|
161
|
+
return this.store.getBlock(number);
|
|
71
162
|
}
|
|
72
163
|
|
|
73
164
|
/**
|
|
@@ -77,17 +168,25 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
|
|
|
77
168
|
*/
|
|
78
169
|
public async getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
79
170
|
if (number === 'latest') {
|
|
80
|
-
number = await this.store.
|
|
171
|
+
number = await this.store.getLatestBlockNumber();
|
|
81
172
|
}
|
|
82
173
|
if (number === 0) {
|
|
83
174
|
return undefined;
|
|
84
175
|
}
|
|
85
|
-
const headers = await this.store.getBlockHeaders(number, 1);
|
|
176
|
+
const headers = await this.store.getBlockHeaders(BlockNumber(number), 1);
|
|
86
177
|
return headers.length === 0 ? undefined : headers[0];
|
|
87
178
|
}
|
|
88
179
|
|
|
89
|
-
public
|
|
90
|
-
return this.getPublishedBlocks(from, limit).then(blocks => blocks.map(b => b.block));
|
|
180
|
+
public getBlockRange(from: number, limit: number, _proven?: boolean): Promise<L2Block[]> {
|
|
181
|
+
return this.getPublishedBlocks(BlockNumber(from), limit).then(blocks => blocks.map(b => b.block));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public getPublishedCheckpoints(_from: CheckpointNumber, _limit: number): Promise<PublishedCheckpoint[]> {
|
|
185
|
+
throw new Error('TXE Archiver does not implement "getPublishedCheckpoints"');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public getCheckpointByArchive(_archive: Fr): Promise<Checkpoint | undefined> {
|
|
189
|
+
throw new Error('TXE Archiver does not implement "getCheckpointByArchive"');
|
|
91
190
|
}
|
|
92
191
|
|
|
93
192
|
public getL2SlotNumber(): Promise<SlotNumber | undefined> {
|
|
@@ -98,6 +197,10 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
|
|
|
98
197
|
throw new Error('TXE Archiver does not implement "getL2EpochNumber"');
|
|
99
198
|
}
|
|
100
199
|
|
|
200
|
+
public getCheckpointsForEpoch(_epochNumber: EpochNumber): Promise<Checkpoint[]> {
|
|
201
|
+
throw new Error('TXE Archiver does not implement "getCheckpointsForEpoch"');
|
|
202
|
+
}
|
|
203
|
+
|
|
101
204
|
public getBlocksForEpoch(_epochNumber: EpochNumber): Promise<L2Block[]> {
|
|
102
205
|
throw new Error('TXE Archiver does not implement "getBlocksForEpoch"');
|
|
103
206
|
}
|
|
@@ -110,8 +213,36 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
|
|
|
110
213
|
throw new Error('TXE Archiver does not implement "isEpochComplete"');
|
|
111
214
|
}
|
|
112
215
|
|
|
113
|
-
public getL2Tips(): Promise<L2Tips> {
|
|
114
|
-
|
|
216
|
+
public async getL2Tips(): Promise<L2Tips> {
|
|
217
|
+
// In TXE there is no possibility of reorgs and no blocks are ever getting proven so we just set 'latest', 'proven'
|
|
218
|
+
// and 'finalized' to the latest block.
|
|
219
|
+
const blockHeader = await this.getBlockHeader('latest');
|
|
220
|
+
if (!blockHeader) {
|
|
221
|
+
throw new Error('L2Tips requested from TXE Archiver but no block header found');
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const number = blockHeader.globalVariables.blockNumber;
|
|
225
|
+
const hash = (await blockHeader.hash()).toString();
|
|
226
|
+
const checkpointedBlock = await this.getCheckpointedBlock(number);
|
|
227
|
+
if (!checkpointedBlock) {
|
|
228
|
+
throw new Error(`L2Tips requested from TXE Archiver but no checkpointed block found for block number ${number}`);
|
|
229
|
+
}
|
|
230
|
+
const checkpoint = await this.store.getRangeOfCheckpoints(CheckpointNumber(number), 1);
|
|
231
|
+
if (checkpoint.length === 0) {
|
|
232
|
+
throw new Error(`L2Tips requested from TXE Archiver but no checkpoint found for block number ${number}`);
|
|
233
|
+
}
|
|
234
|
+
const blockId: L2BlockId = { number, hash };
|
|
235
|
+
const checkpointId: CheckpointId = {
|
|
236
|
+
number: checkpoint[0].checkpointNumber,
|
|
237
|
+
hash: checkpoint[0].header.hash().toString(),
|
|
238
|
+
};
|
|
239
|
+
const tipId: L2TipId = { block: blockId, checkpoint: checkpointId };
|
|
240
|
+
return {
|
|
241
|
+
proposed: blockId,
|
|
242
|
+
proven: tipId,
|
|
243
|
+
finalized: tipId,
|
|
244
|
+
checkpointed: tipId,
|
|
245
|
+
};
|
|
115
246
|
}
|
|
116
247
|
|
|
117
248
|
public getL1Constants(): Promise<L1RollupConstants> {
|
|
@@ -146,7 +277,18 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
|
|
|
146
277
|
return Promise.resolve(false);
|
|
147
278
|
}
|
|
148
279
|
|
|
149
|
-
public override getPendingChainValidationStatus(): Promise<
|
|
280
|
+
public override getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
|
|
150
281
|
return Promise.resolve({ valid: true });
|
|
151
282
|
}
|
|
283
|
+
|
|
284
|
+
getPublishedBlockByHash(_blockHash: Fr): Promise<PublishedL2Block | undefined> {
|
|
285
|
+
throw new Error('Method not implemented.');
|
|
286
|
+
}
|
|
287
|
+
getPublishedBlockByArchive(_archive: Fr): Promise<PublishedL2Block | undefined> {
|
|
288
|
+
throw new Error('Method not implemented.');
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
getCheckpointedBlocks(_from: BlockNumber, _limit: number, _proven?: boolean): Promise<never[]> {
|
|
292
|
+
throw new Error('TXE Archiver does not implement "getCheckpointedBlocks"');
|
|
293
|
+
}
|
|
152
294
|
}
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
ENR,
|
|
5
5
|
P2P,
|
|
6
6
|
P2PBlockReceivedCallback,
|
|
7
|
+
P2PCheckpointReceivedCallback,
|
|
7
8
|
P2PConfig,
|
|
8
9
|
P2PSyncState,
|
|
9
10
|
PeerId,
|
|
@@ -14,14 +15,10 @@ import type {
|
|
|
14
15
|
} from '@aztec/p2p';
|
|
15
16
|
import type { EthAddress, L2BlockStreamEvent, L2Tips } from '@aztec/stdlib/block';
|
|
16
17
|
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
17
|
-
import type {
|
|
18
|
+
import type { BlockProposal, CheckpointAttestation, CheckpointProposal } from '@aztec/stdlib/p2p';
|
|
18
19
|
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
19
20
|
|
|
20
21
|
export class DummyP2P implements P2P {
|
|
21
|
-
public broadcastAttestations(_attestations: BlockAttestation[]): Promise<void> {
|
|
22
|
-
return Promise.resolve();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
22
|
public validate(_txs: Tx[]): Promise<void> {
|
|
26
23
|
return Promise.resolve();
|
|
27
24
|
}
|
|
@@ -46,10 +43,22 @@ export class DummyP2P implements P2P {
|
|
|
46
43
|
throw new Error('DummyP2P does not implement "broadcastProposal"');
|
|
47
44
|
}
|
|
48
45
|
|
|
46
|
+
public broadcastCheckpointProposal(_proposal: CheckpointProposal): Promise<void> {
|
|
47
|
+
throw new Error('DummyP2P does not implement "broadcastCheckpointProposal"');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public broadcastCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
|
|
51
|
+
throw new Error('DummyP2P does not implement "broadcastCheckpointAttestations"');
|
|
52
|
+
}
|
|
53
|
+
|
|
49
54
|
public registerBlockProposalHandler(_handler: P2PBlockReceivedCallback): void {
|
|
50
55
|
throw new Error('DummyP2P does not implement "registerBlockProposalHandler"');
|
|
51
56
|
}
|
|
52
57
|
|
|
58
|
+
public registerCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
|
|
59
|
+
throw new Error('DummyP2P does not implement "registerCheckpointProposalHandler"');
|
|
60
|
+
}
|
|
61
|
+
|
|
53
62
|
public requestTxs(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
54
63
|
throw new Error('DummyP2P does not implement "requestTxs"');
|
|
55
64
|
}
|
|
@@ -79,7 +88,9 @@ export class DummyP2P implements P2P {
|
|
|
79
88
|
}
|
|
80
89
|
|
|
81
90
|
public getTxStatus(_txHash: TxHash): Promise<'pending' | 'mined' | undefined> {
|
|
82
|
-
|
|
91
|
+
// In TXE there is no concept of transactions but we need to implement this because of tagging. We return 'mined'
|
|
92
|
+
// tx status for any tx hash.
|
|
93
|
+
return Promise.resolve('mined');
|
|
83
94
|
}
|
|
84
95
|
|
|
85
96
|
public iteratePendingTxs(): AsyncIterableIterator<Tx> {
|
|
@@ -118,16 +129,12 @@ export class DummyP2P implements P2P {
|
|
|
118
129
|
throw new Error('DummyP2P does not implement "getTxsByHash"');
|
|
119
130
|
}
|
|
120
131
|
|
|
121
|
-
public
|
|
122
|
-
throw new Error('DummyP2P does not implement "
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
public deleteAttestation(_attestation: BlockAttestation): Promise<void> {
|
|
126
|
-
return Promise.resolve();
|
|
132
|
+
public getCheckpointAttestationsForSlot(_slot: SlotNumber, _proposalId?: string): Promise<CheckpointAttestation[]> {
|
|
133
|
+
throw new Error('DummyP2P does not implement "getCheckpointAttestationsForSlot"');
|
|
127
134
|
}
|
|
128
135
|
|
|
129
|
-
public
|
|
130
|
-
throw new Error('DummyP2P does not implement "
|
|
136
|
+
public addCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
|
|
137
|
+
throw new Error('DummyP2P does not implement "addCheckpointAttestations"');
|
|
131
138
|
}
|
|
132
139
|
|
|
133
140
|
public getL2BlockHash(_number: number): Promise<string | undefined> {
|
|
@@ -1,21 +1,38 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
5
5
|
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
6
|
-
import { type GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
|
|
6
|
+
import { type CheckpointGlobalVariables, type GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
|
|
7
7
|
|
|
8
8
|
export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
|
|
9
|
-
public
|
|
9
|
+
public getCurrentMinFees(): Promise<GasFees> {
|
|
10
10
|
return Promise.resolve(new GasFees(0, 0));
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
public buildGlobalVariables(
|
|
14
|
-
_blockNumber:
|
|
14
|
+
_blockNumber: BlockNumber,
|
|
15
15
|
_coinbase: EthAddress,
|
|
16
16
|
_feeRecipient: AztecAddress,
|
|
17
17
|
_slotNumber?: SlotNumber,
|
|
18
18
|
): Promise<GlobalVariables> {
|
|
19
19
|
return Promise.resolve(makeGlobalVariables());
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
public buildCheckpointGlobalVariables(
|
|
23
|
+
_coinbase: EthAddress,
|
|
24
|
+
_feeRecipient: AztecAddress,
|
|
25
|
+
_slotNumber: SlotNumber,
|
|
26
|
+
): Promise<CheckpointGlobalVariables> {
|
|
27
|
+
const vars = makeGlobalVariables();
|
|
28
|
+
return Promise.resolve({
|
|
29
|
+
chainId: vars.chainId,
|
|
30
|
+
version: vars.version,
|
|
31
|
+
slotNumber: vars.slotNumber,
|
|
32
|
+
timestamp: vars.timestamp,
|
|
33
|
+
coinbase: vars.coinbase,
|
|
34
|
+
feeRecipient: vars.feeRecipient,
|
|
35
|
+
gasFees: vars.gasFees,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
21
38
|
}
|