@aztec/txe 0.0.1-commit.d3ec352c → 0.0.1-commit.d431d1c
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 +3 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +2 -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 +5 -3
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +4 -4
- 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 +20 -11
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +99 -62
- package/dest/rpc_translator.d.ts +15 -9
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +68 -28
- package/dest/state_machine/archiver.d.ts +21 -57
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +62 -107
- 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 +4 -3
- 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 +6 -6
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +23 -20
- package/dest/state_machine/mock_epoch_cache.d.ts +4 -5
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +8 -6
- package/dest/state_machine/synchronizer.d.ts +1 -1
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +2 -2
- package/dest/txe_session.d.ts +18 -10
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +90 -45
- package/dest/util/encoding.d.ts +618 -19
- 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 +5 -5
- 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 -5
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +36 -4
- package/dest/utils/tx_effect_creation.d.ts +2 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +4 -7
- package/package.json +16 -16
- package/src/constants.ts +3 -0
- package/src/index.ts +15 -12
- package/src/oracle/interfaces.ts +4 -2
- package/src/oracle/txe_oracle_public_context.ts +5 -10
- package/src/oracle/txe_oracle_top_level_context.ts +148 -88
- package/src/rpc_translator.ts +86 -36
- package/src/state_machine/archiver.ts +60 -130
- package/src/state_machine/dummy_p2p_client.ts +21 -14
- package/src/state_machine/global_variable_builder.ts +19 -2
- package/src/state_machine/index.ts +28 -19
- package/src/state_machine/mock_epoch_cache.ts +8 -10
- package/src/state_machine/synchronizer.ts +1 -2
- package/src/txe_session.ts +179 -76
- 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 +10 -10
- package/src/utils/block_creation.ts +46 -15
- package/src/utils/tx_effect_creation.ts +4 -12
- 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
|
@@ -6,10 +6,11 @@ import {
|
|
|
6
6
|
type IMiscOracle,
|
|
7
7
|
type IPrivateExecutionOracle,
|
|
8
8
|
type IUtilityExecutionOracle,
|
|
9
|
-
|
|
9
|
+
packAsHintedNote,
|
|
10
10
|
} from '@aztec/pxe/simulator';
|
|
11
|
-
import { type ContractArtifact, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
11
|
+
import { type ContractArtifact, EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
12
12
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
13
|
+
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
13
14
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
14
15
|
|
|
15
16
|
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
@@ -30,6 +31,9 @@ import {
|
|
|
30
31
|
toSingle,
|
|
31
32
|
} from './util/encoding.js';
|
|
32
33
|
|
|
34
|
+
const MAX_EVENT_LEN = 12; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_RESERVED_FIELDS
|
|
35
|
+
const MAX_PRIVATE_EVENTS_PER_TXE_QUERY = 5;
|
|
36
|
+
|
|
33
37
|
export class UnavailableOracleError extends Error {
|
|
34
38
|
constructor(oracleName: string) {
|
|
35
39
|
super(`${oracleName} oracles not available with the current handler`);
|
|
@@ -156,6 +160,12 @@ export class RPCTranslator {
|
|
|
156
160
|
|
|
157
161
|
// TXE-specific oracles
|
|
158
162
|
|
|
163
|
+
txeGetDefaultAddress() {
|
|
164
|
+
const defaultAddress = this.handlerAsTxe().txeGetDefaultAddress();
|
|
165
|
+
|
|
166
|
+
return toForeignCallResult([toSingle(defaultAddress)]);
|
|
167
|
+
}
|
|
168
|
+
|
|
159
169
|
async txeGetNextBlockNumber() {
|
|
160
170
|
const nextBlockNumber = await this.handlerAsTxe().txeGetNextBlockNumber();
|
|
161
171
|
|
|
@@ -267,6 +277,39 @@ export class RPCTranslator {
|
|
|
267
277
|
]);
|
|
268
278
|
}
|
|
269
279
|
|
|
280
|
+
async txeGetPrivateEvents(
|
|
281
|
+
foreignSelector: ForeignCallSingle,
|
|
282
|
+
foreignContractAddress: ForeignCallSingle,
|
|
283
|
+
foreignScope: ForeignCallSingle,
|
|
284
|
+
) {
|
|
285
|
+
const selector = EventSelector.fromField(fromSingle(foreignSelector));
|
|
286
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
287
|
+
const scope = addressFromSingle(foreignScope);
|
|
288
|
+
|
|
289
|
+
const events = await this.handlerAsTxe().txeGetPrivateEvents(selector, contractAddress, scope);
|
|
290
|
+
|
|
291
|
+
if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
|
|
292
|
+
throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (events.some(e => e.length > MAX_EVENT_LEN)) {
|
|
296
|
+
throw new Error(`Some private event has length larger than maxLen ${MAX_EVENT_LEN}`);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// This is a workaround as Noir does not currently let us return nested structs with arrays. We instead return a raw
|
|
300
|
+
// multidimensional array in get_private_events_oracle and create the BoundedVecs here.
|
|
301
|
+
const rawArrayStorage = events
|
|
302
|
+
.map(e => e.concat(Array(MAX_EVENT_LEN - e.length).fill(new Fr(0))))
|
|
303
|
+
.concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(Array(MAX_EVENT_LEN).fill(new Fr(0))))
|
|
304
|
+
.flat();
|
|
305
|
+
const eventLengths = events
|
|
306
|
+
.map(e => new Fr(e.length))
|
|
307
|
+
.concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(new Fr(0)));
|
|
308
|
+
const queryLength = new Fr(events.length);
|
|
309
|
+
|
|
310
|
+
return toForeignCallResult([toArray(rawArrayStorage), toArray(eventLengths), toSingle(queryLength)]);
|
|
311
|
+
}
|
|
312
|
+
|
|
270
313
|
privateStoreInExecutionCache(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
|
|
271
314
|
const values = fromArray(foreignValues);
|
|
272
315
|
const hash = fromSingle(foreignHash);
|
|
@@ -304,40 +347,41 @@ export class RPCTranslator {
|
|
|
304
347
|
}
|
|
305
348
|
|
|
306
349
|
async utilityStorageRead(
|
|
350
|
+
foreignBlockHash: ForeignCallSingle,
|
|
307
351
|
foreignContractAddress: ForeignCallSingle,
|
|
308
352
|
foreignStartStorageSlot: ForeignCallSingle,
|
|
309
|
-
foreignBlockNumber: ForeignCallSingle,
|
|
310
353
|
foreignNumberOfElements: ForeignCallSingle,
|
|
311
354
|
) {
|
|
355
|
+
const blockHash = L2BlockHash.fromString(foreignBlockHash);
|
|
312
356
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
313
357
|
const startStorageSlot = fromSingle(foreignStartStorageSlot);
|
|
314
|
-
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
315
358
|
const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
|
|
316
359
|
|
|
317
360
|
const values = await this.handlerAsUtility().utilityStorageRead(
|
|
361
|
+
blockHash,
|
|
318
362
|
contractAddress,
|
|
319
363
|
startStorageSlot,
|
|
320
|
-
blockNumber,
|
|
321
364
|
numberOfElements,
|
|
322
365
|
);
|
|
323
366
|
|
|
324
367
|
return toForeignCallResult([toArray(values)]);
|
|
325
368
|
}
|
|
326
369
|
|
|
327
|
-
async utilityGetPublicDataWitness(
|
|
328
|
-
const
|
|
370
|
+
async utilityGetPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
|
|
371
|
+
const blockHash = L2BlockHash.fromString(foreignBlockHash);
|
|
329
372
|
const leafSlot = fromSingle(foreignLeafSlot);
|
|
330
373
|
|
|
331
|
-
const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(
|
|
374
|
+
const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockHash, leafSlot);
|
|
332
375
|
|
|
333
376
|
if (!witness) {
|
|
334
|
-
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${
|
|
377
|
+
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
|
|
335
378
|
}
|
|
336
379
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
337
380
|
}
|
|
338
381
|
|
|
339
382
|
async utilityGetNotes(
|
|
340
|
-
|
|
383
|
+
foreignOwnerIsSome: ForeignCallSingle,
|
|
384
|
+
foreignOwnerValue: ForeignCallSingle,
|
|
341
385
|
foreignStorageSlot: ForeignCallSingle,
|
|
342
386
|
foreignNumSelects: ForeignCallSingle,
|
|
343
387
|
foreignSelectByIndexes: ForeignCallArray,
|
|
@@ -353,9 +397,12 @@ export class RPCTranslator {
|
|
|
353
397
|
foreignOffset: ForeignCallSingle,
|
|
354
398
|
foreignStatus: ForeignCallSingle,
|
|
355
399
|
foreignMaxNotes: ForeignCallSingle,
|
|
356
|
-
|
|
400
|
+
foreignPackedHintedNoteLength: ForeignCallSingle,
|
|
357
401
|
) {
|
|
358
|
-
|
|
402
|
+
// Parse Option<AztecAddress>: ownerIsSome is 0 for None, 1 for Some
|
|
403
|
+
const owner = fromSingle(foreignOwnerIsSome).toBool()
|
|
404
|
+
? AztecAddress.fromField(fromSingle(foreignOwnerValue))
|
|
405
|
+
: undefined;
|
|
359
406
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
360
407
|
const numSelects = fromSingle(foreignNumSelects).toNumber();
|
|
361
408
|
const selectByIndexes = fromArray(foreignSelectByIndexes).map(fr => fr.toNumber());
|
|
@@ -371,7 +418,7 @@ export class RPCTranslator {
|
|
|
371
418
|
const offset = fromSingle(foreignOffset).toNumber();
|
|
372
419
|
const status = fromSingle(foreignStatus).toNumber();
|
|
373
420
|
const maxNotes = fromSingle(foreignMaxNotes).toNumber();
|
|
374
|
-
const
|
|
421
|
+
const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
|
|
375
422
|
|
|
376
423
|
const noteDatas = await this.handlerAsUtility().utilityGetNotes(
|
|
377
424
|
owner,
|
|
@@ -391,7 +438,17 @@ export class RPCTranslator {
|
|
|
391
438
|
status,
|
|
392
439
|
);
|
|
393
440
|
|
|
394
|
-
const returnDataAsArrayOfArrays = noteDatas.map(
|
|
441
|
+
const returnDataAsArrayOfArrays = noteDatas.map(noteData =>
|
|
442
|
+
packAsHintedNote({
|
|
443
|
+
contractAddress: noteData.contractAddress,
|
|
444
|
+
owner: noteData.owner,
|
|
445
|
+
randomness: noteData.randomness,
|
|
446
|
+
storageSlot: noteData.storageSlot,
|
|
447
|
+
noteNonce: noteData.noteNonce,
|
|
448
|
+
isPending: noteData.isPending,
|
|
449
|
+
note: noteData.note,
|
|
450
|
+
}),
|
|
451
|
+
);
|
|
395
452
|
|
|
396
453
|
// Now we convert each sub-array to an array of ForeignCallSingles
|
|
397
454
|
const returnDataAsArrayOfForeignCallSingleArrays = returnDataAsArrayOfArrays.map(subArray =>
|
|
@@ -400,11 +457,7 @@ export class RPCTranslator {
|
|
|
400
457
|
|
|
401
458
|
// At last we convert the array of arrays to a bounded vec of arrays
|
|
402
459
|
return toForeignCallResult(
|
|
403
|
-
arrayOfArraysToBoundedVecOfArrays(
|
|
404
|
-
returnDataAsArrayOfForeignCallSingleArrays,
|
|
405
|
-
maxNotes,
|
|
406
|
-
packedRetrievedNoteLength,
|
|
407
|
-
),
|
|
460
|
+
arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes, packedHintedNoteLength),
|
|
408
461
|
);
|
|
409
462
|
}
|
|
410
463
|
|
|
@@ -512,17 +565,14 @@ export class RPCTranslator {
|
|
|
512
565
|
);
|
|
513
566
|
}
|
|
514
567
|
|
|
515
|
-
async utilityGetNullifierMembershipWitness(
|
|
516
|
-
|
|
517
|
-
foreignNullifier: ForeignCallSingle,
|
|
518
|
-
) {
|
|
519
|
-
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
568
|
+
async utilityGetNullifierMembershipWitness(foreignBlockHash: ForeignCallSingle, foreignNullifier: ForeignCallSingle) {
|
|
569
|
+
const blockHash = L2BlockHash.fromString(foreignBlockHash);
|
|
520
570
|
const nullifier = fromSingle(foreignNullifier);
|
|
521
571
|
|
|
522
|
-
const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(
|
|
572
|
+
const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockHash, nullifier);
|
|
523
573
|
|
|
524
574
|
if (!witness) {
|
|
525
|
-
throw new Error(`Nullifier membership witness not found at block ${
|
|
575
|
+
throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
|
|
526
576
|
}
|
|
527
577
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
528
578
|
}
|
|
@@ -566,8 +616,8 @@ export class RPCTranslator {
|
|
|
566
616
|
return toForeignCallResult([toSingle(new Fr(isRevertible))]);
|
|
567
617
|
}
|
|
568
618
|
|
|
569
|
-
|
|
570
|
-
const context =
|
|
619
|
+
utilityGetUtilityContext() {
|
|
620
|
+
const context = this.handlerAsUtility().utilityGetUtilityContext();
|
|
571
621
|
|
|
572
622
|
return toForeignCallResult(context.toNoirRepresentation());
|
|
573
623
|
}
|
|
@@ -584,35 +634,35 @@ export class RPCTranslator {
|
|
|
584
634
|
}
|
|
585
635
|
|
|
586
636
|
async utilityGetMembershipWitness(
|
|
587
|
-
|
|
637
|
+
foreignBlockHash: ForeignCallSingle,
|
|
588
638
|
foreignTreeId: ForeignCallSingle,
|
|
589
639
|
foreignLeafValue: ForeignCallSingle,
|
|
590
640
|
) {
|
|
591
|
-
const
|
|
641
|
+
const blockHash = L2BlockHash.fromString(foreignBlockHash);
|
|
592
642
|
const treeId = fromSingle(foreignTreeId).toNumber();
|
|
593
643
|
const leafValue = fromSingle(foreignLeafValue);
|
|
594
644
|
|
|
595
|
-
const witness = await this.handlerAsUtility().utilityGetMembershipWitness(
|
|
645
|
+
const witness = await this.handlerAsUtility().utilityGetMembershipWitness(blockHash, treeId, leafValue);
|
|
596
646
|
|
|
597
647
|
if (!witness) {
|
|
598
648
|
throw new Error(
|
|
599
|
-
`Membership witness in tree ${MerkleTreeId[treeId]} not found for value ${leafValue} at block ${
|
|
649
|
+
`Membership witness in tree ${MerkleTreeId[treeId]} not found for value ${leafValue} at block ${blockHash}.`,
|
|
600
650
|
);
|
|
601
651
|
}
|
|
602
652
|
return toForeignCallResult([toSingle(witness[0]), toArray(witness.slice(1))]);
|
|
603
653
|
}
|
|
604
654
|
|
|
605
655
|
async utilityGetLowNullifierMembershipWitness(
|
|
606
|
-
|
|
656
|
+
foreignBlockHash: ForeignCallSingle,
|
|
607
657
|
foreignNullifier: ForeignCallSingle,
|
|
608
658
|
) {
|
|
609
|
-
const
|
|
659
|
+
const blockHash = L2BlockHash.fromString(foreignBlockHash);
|
|
610
660
|
const nullifier = fromSingle(foreignNullifier);
|
|
611
661
|
|
|
612
|
-
const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(
|
|
662
|
+
const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockHash, nullifier);
|
|
613
663
|
|
|
614
664
|
if (!witness) {
|
|
615
|
-
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${
|
|
665
|
+
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
|
|
616
666
|
}
|
|
617
667
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
618
668
|
}
|
|
@@ -1,169 +1,99 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ArchiverDataSourceBase, ArchiverDataStoreUpdater, KVArchiverDataStore } from '@aztec/archiver';
|
|
2
2
|
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
3
|
-
import {
|
|
3
|
+
import { CheckpointNumber, type EpochNumber, type 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 { Fr } from '@aztec/foundation/fields';
|
|
6
6
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
import type { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
10
|
-
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
7
|
+
import type { CheckpointId, L2BlockId, L2TipId, L2Tips, ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
8
|
+
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
11
9
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
12
|
-
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
13
|
-
import type { UInt64 } from '@aztec/stdlib/types';
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
/**
|
|
12
|
+
* TXE Archiver implementation.
|
|
13
|
+
* Provides most of the endpoints needed by the node for reading from and writing to state,
|
|
14
|
+
* without needing any of the extra overhead that the Archiver itself requires (i.e. an L1 client).
|
|
15
|
+
*/
|
|
16
|
+
export class TXEArchiver extends ArchiverDataSourceBase {
|
|
17
|
+
private readonly updater = new ArchiverDataStoreUpdater(this.store);
|
|
18
|
+
|
|
19
19
|
constructor(db: AztecAsyncKVStore) {
|
|
20
|
-
|
|
20
|
+
const store = new KVArchiverDataStore(db, 9999);
|
|
21
|
+
super(store);
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
]);
|
|
28
|
-
|
|
29
|
-
return opResults.every(Boolean);
|
|
24
|
+
// TXE-specific method for adding checkpoints
|
|
25
|
+
public async addCheckpoints(checkpoints: PublishedCheckpoint[], result?: ValidateCheckpointResult): Promise<boolean> {
|
|
26
|
+
await this.updater.setNewCheckpointData(checkpoints, result);
|
|
27
|
+
return true;
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
* Gets the number of the latest L2 block processed by the block source implementation.
|
|
34
|
-
* @returns The number of the latest L2 block processed by the block source implementation.
|
|
35
|
-
*/
|
|
36
|
-
public getBlockNumber(): Promise<BlockNumber> {
|
|
37
|
-
return this.store.getSynchedL2BlockNumber();
|
|
38
|
-
}
|
|
30
|
+
// Abstract method implementations
|
|
39
31
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* @returns The number of the latest L2 block proven seen by the block source implementation.
|
|
43
|
-
*/
|
|
44
|
-
public getProvenBlockNumber(): Promise<BlockNumber> {
|
|
45
|
-
return this.store.getSynchedL2BlockNumber();
|
|
32
|
+
public getRollupAddress(): Promise<EthAddress> {
|
|
33
|
+
throw new Error('TXE Archiver does not implement "getRollupAddress"');
|
|
46
34
|
}
|
|
47
35
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
* @param number - The block number to return (inclusive).
|
|
51
|
-
* @returns The requested L2 block.
|
|
52
|
-
*/
|
|
53
|
-
public override async getPublishedBlock(number: number): Promise<PublishedL2Block | undefined> {
|
|
54
|
-
// If the number provided is -ve, then return the latest block.
|
|
55
|
-
if (number < 0) {
|
|
56
|
-
number = await this.store.getSynchedL2BlockNumber();
|
|
57
|
-
}
|
|
58
|
-
if (number == 0) {
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
const blocks = await this.store.getPublishedBlocks(BlockNumber(number), 1);
|
|
62
|
-
return blocks.length === 0 ? undefined : blocks[0];
|
|
36
|
+
public getRegistryAddress(): Promise<EthAddress> {
|
|
37
|
+
throw new Error('TXE Archiver does not implement "getRegistryAddress"');
|
|
63
38
|
}
|
|
64
39
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
* @param number - The block number to return (inclusive).
|
|
68
|
-
* @returns The requested L2 block.
|
|
69
|
-
*/
|
|
70
|
-
public getBlock(number: number | 'latest'): Promise<L2Block | undefined> {
|
|
71
|
-
return this.getPublishedBlock(number != 'latest' ? number : -1).then(block => block?.block);
|
|
40
|
+
public getL1Constants(): Promise<L1RollupConstants> {
|
|
41
|
+
throw new Error('TXE Archiver does not implement "getL1Constants"');
|
|
72
42
|
}
|
|
73
43
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
* @param number - The block number to return or 'latest' for the most recent one.
|
|
77
|
-
* @returns The requested L2 block header.
|
|
78
|
-
*/
|
|
79
|
-
public async getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
80
|
-
if (number === 'latest') {
|
|
81
|
-
number = await this.store.getSynchedL2BlockNumber();
|
|
82
|
-
}
|
|
83
|
-
if (number === 0) {
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
const headers = await this.store.getBlockHeaders(BlockNumber(number), 1);
|
|
87
|
-
return headers.length === 0 ? undefined : headers[0];
|
|
44
|
+
public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
|
|
45
|
+
return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
|
|
88
46
|
}
|
|
89
47
|
|
|
90
|
-
public
|
|
91
|
-
|
|
48
|
+
public getL1Timestamp(): Promise<bigint | undefined> {
|
|
49
|
+
throw new Error('TXE Archiver does not implement "getL1Timestamp"');
|
|
92
50
|
}
|
|
93
51
|
|
|
94
|
-
public
|
|
95
|
-
|
|
96
|
-
|
|
52
|
+
public async getL2Tips(): Promise<L2Tips> {
|
|
53
|
+
// In TXE there is no possibility of reorgs and no blocks are ever getting proven so we just set 'latest', 'proven'
|
|
54
|
+
// and 'finalized' to the latest block.
|
|
55
|
+
const blockHeader = await this.getBlockHeader('latest');
|
|
56
|
+
if (!blockHeader) {
|
|
57
|
+
throw new Error('L2Tips requested from TXE Archiver but no block header found');
|
|
58
|
+
}
|
|
97
59
|
|
|
98
|
-
|
|
99
|
-
|
|
60
|
+
const number = blockHeader.globalVariables.blockNumber;
|
|
61
|
+
const hash = (await blockHeader.hash()).toString();
|
|
62
|
+
const checkpointedBlock = await this.getCheckpointedBlock(number);
|
|
63
|
+
if (!checkpointedBlock) {
|
|
64
|
+
throw new Error(`L2Tips requested from TXE Archiver but no checkpointed block found for block number ${number}`);
|
|
65
|
+
}
|
|
66
|
+
const checkpoint = await this.store.getRangeOfCheckpoints(CheckpointNumber(number), 1);
|
|
67
|
+
if (checkpoint.length === 0) {
|
|
68
|
+
throw new Error(`L2Tips requested from TXE Archiver but no checkpoint found for block number ${number}`);
|
|
69
|
+
}
|
|
70
|
+
const blockId: L2BlockId = { number, hash };
|
|
71
|
+
const checkpointId: CheckpointId = {
|
|
72
|
+
number: checkpoint[0].checkpointNumber,
|
|
73
|
+
hash: checkpoint[0].header.hash().toString(),
|
|
74
|
+
};
|
|
75
|
+
const tipId: L2TipId = { block: blockId, checkpoint: checkpointId };
|
|
76
|
+
return {
|
|
77
|
+
proposed: blockId,
|
|
78
|
+
proven: tipId,
|
|
79
|
+
finalized: tipId,
|
|
80
|
+
checkpointed: tipId,
|
|
81
|
+
};
|
|
100
82
|
}
|
|
101
83
|
|
|
102
84
|
public getL2SlotNumber(): Promise<SlotNumber | undefined> {
|
|
103
85
|
throw new Error('TXE Archiver does not implement "getL2SlotNumber"');
|
|
104
86
|
}
|
|
105
87
|
|
|
106
|
-
public getL2EpochNumber(): Promise<EpochNumber> {
|
|
88
|
+
public getL2EpochNumber(): Promise<EpochNumber | undefined> {
|
|
107
89
|
throw new Error('TXE Archiver does not implement "getL2EpochNumber"');
|
|
108
90
|
}
|
|
109
91
|
|
|
110
|
-
public getCheckpointsForEpoch(_epochNumber: EpochNumber): Promise<Checkpoint[]> {
|
|
111
|
-
throw new Error('TXE Archiver does not implement "getCheckpointsForEpoch"');
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
public getBlocksForEpoch(_epochNumber: EpochNumber): Promise<L2Block[]> {
|
|
115
|
-
throw new Error('TXE Archiver does not implement "getBlocksForEpoch"');
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
public getBlockHeadersForEpoch(_epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
119
|
-
throw new Error('TXE Archiver does not implement "getBlockHeadersForEpoch"');
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
public getL1ToL2MessagesForCheckpoint(_checkpointNumber: CheckpointNumber): Promise<Fr[]> {
|
|
123
|
-
throw new Error('TXE Archiver does not implement "getL1ToL2MessagesForCheckpoint"');
|
|
124
|
-
}
|
|
125
|
-
|
|
126
92
|
public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
|
|
127
93
|
throw new Error('TXE Archiver does not implement "isEpochComplete"');
|
|
128
94
|
}
|
|
129
95
|
|
|
130
|
-
public getL2Tips(): Promise<L2Tips> {
|
|
131
|
-
throw new Error('TXE Archiver does not implement "getL2Tips"');
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
public getL1Constants(): Promise<L1RollupConstants> {
|
|
135
|
-
throw new Error('TXE Archiver does not implement "getL2Constants"');
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
|
|
139
|
-
return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
|
|
140
|
-
}
|
|
141
|
-
|
|
142
96
|
public syncImmediate(): Promise<void> {
|
|
143
97
|
throw new Error('TXE Archiver does not implement "syncImmediate"');
|
|
144
98
|
}
|
|
145
|
-
|
|
146
|
-
public getContract(_address: AztecAddress, _timestamp?: UInt64): Promise<ContractInstanceWithAddress | undefined> {
|
|
147
|
-
throw new Error('TXE Archiver does not implement "getContract"');
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
public getRollupAddress(): Promise<EthAddress> {
|
|
151
|
-
throw new Error('TXE Archiver does not implement "getRollupAddress"');
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
public getRegistryAddress(): Promise<EthAddress> {
|
|
155
|
-
throw new Error('TXE Archiver does not implement "getRegistryAddress"');
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
public getL1Timestamp(): Promise<bigint> {
|
|
159
|
-
throw new Error('TXE Archiver does not implement "getL1Timestamp"');
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
public isPendingChainInvalid(): Promise<boolean> {
|
|
163
|
-
return Promise.resolve(false);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
public override getPendingChainValidationStatus(): Promise<ValidateBlockResult> {
|
|
167
|
-
return Promise.resolve({ valid: true });
|
|
168
|
-
}
|
|
169
99
|
}
|
|
@@ -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> {
|
|
@@ -3,10 +3,10 @@ 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
|
|
|
@@ -18,4 +18,21 @@ export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
|
|
|
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
|
}
|