@aztec/txe 0.0.1-commit.c7c42ec → 0.0.1-commit.c949de6bc

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.
Files changed (68) hide show
  1. package/dest/constants.d.ts +3 -0
  2. package/dest/constants.d.ts.map +1 -0
  3. package/dest/constants.js +2 -0
  4. package/dest/index.d.ts +1 -1
  5. package/dest/index.d.ts.map +1 -1
  6. package/dest/index.js +82 -50
  7. package/dest/oracle/interfaces.d.ts +6 -5
  8. package/dest/oracle/interfaces.d.ts.map +1 -1
  9. package/dest/oracle/txe_oracle_public_context.d.ts +3 -3
  10. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_public_context.js +6 -6
  12. package/dest/oracle/txe_oracle_top_level_context.d.ts +8 -7
  13. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  14. package/dest/oracle/txe_oracle_top_level_context.js +123 -38
  15. package/dest/rpc_translator.d.ts +21 -15
  16. package/dest/rpc_translator.d.ts.map +1 -1
  17. package/dest/rpc_translator.js +92 -55
  18. package/dest/state_machine/archiver.d.ts +20 -67
  19. package/dest/state_machine/archiver.d.ts.map +1 -1
  20. package/dest/state_machine/archiver.js +59 -178
  21. package/dest/state_machine/dummy_p2p_client.d.ts +20 -15
  22. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  23. package/dest/state_machine/dummy_p2p_client.js +39 -24
  24. package/dest/state_machine/global_variable_builder.d.ts +2 -2
  25. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  26. package/dest/state_machine/global_variable_builder.js +1 -1
  27. package/dest/state_machine/index.d.ts +5 -5
  28. package/dest/state_machine/index.d.ts.map +1 -1
  29. package/dest/state_machine/index.js +35 -12
  30. package/dest/state_machine/mock_epoch_cache.d.ts +9 -6
  31. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  32. package/dest/state_machine/mock_epoch_cache.js +14 -7
  33. package/dest/state_machine/synchronizer.d.ts +3 -3
  34. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  35. package/dest/txe_session.d.ts +12 -7
  36. package/dest/txe_session.d.ts.map +1 -1
  37. package/dest/txe_session.js +122 -28
  38. package/dest/util/encoding.d.ts +17 -17
  39. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  40. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  41. package/dest/util/txe_public_contract_data_source.js +5 -22
  42. package/dest/utils/block_creation.d.ts +4 -4
  43. package/dest/utils/block_creation.d.ts.map +1 -1
  44. package/dest/utils/block_creation.js +18 -5
  45. package/dest/utils/tx_effect_creation.d.ts +2 -3
  46. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  47. package/dest/utils/tx_effect_creation.js +3 -6
  48. package/package.json +16 -16
  49. package/src/constants.ts +3 -0
  50. package/src/index.ts +83 -49
  51. package/src/oracle/interfaces.ts +8 -3
  52. package/src/oracle/txe_oracle_public_context.ts +6 -8
  53. package/src/oracle/txe_oracle_top_level_context.ts +163 -79
  54. package/src/rpc_translator.ts +97 -56
  55. package/src/state_machine/archiver.ts +54 -220
  56. package/src/state_machine/dummy_p2p_client.ts +55 -32
  57. package/src/state_machine/global_variable_builder.ts +1 -1
  58. package/src/state_machine/index.ts +49 -11
  59. package/src/state_machine/mock_epoch_cache.ts +15 -11
  60. package/src/state_machine/synchronizer.ts +2 -2
  61. package/src/txe_session.ts +151 -71
  62. package/src/util/txe_public_contract_data_source.ts +10 -36
  63. package/src/utils/block_creation.ts +19 -16
  64. package/src/utils/tx_effect_creation.ts +3 -11
  65. package/dest/util/txe_contract_store.d.ts +0 -12
  66. package/dest/util/txe_contract_store.d.ts.map +0 -1
  67. package/dest/util/txe_contract_store.js +0 -22
  68. package/src/util/txe_contract_store.ts +0 -36
@@ -6,11 +6,11 @@ import {
6
6
  type IMiscOracle,
7
7
  type IPrivateExecutionOracle,
8
8
  type IUtilityExecutionOracle,
9
- packAsRetrievedNote,
9
+ packAsHintedNote,
10
10
  } from '@aztec/pxe/simulator';
11
11
  import { type ContractArtifact, EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
12
12
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
13
- import { MerkleTreeId } from '@aztec/stdlib/trees';
13
+ import { BlockHash } from '@aztec/stdlib/block';
14
14
 
15
15
  import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
16
16
  import type { TXESessionStateHandler } from './txe_session.js';
@@ -30,7 +30,7 @@ import {
30
30
  toSingle,
31
31
  } from './util/encoding.js';
32
32
 
33
- const MAX_EVENT_LEN = 12; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_RESERVED_FIELDS
33
+ const MAX_EVENT_LEN = 10; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN
34
34
  const MAX_PRIVATE_EVENTS_PER_TXE_QUERY = 5;
35
35
 
36
36
  export class UnavailableOracleError extends Error {
@@ -285,6 +285,13 @@ export class RPCTranslator {
285
285
  const contractAddress = addressFromSingle(foreignContractAddress);
286
286
  const scope = addressFromSingle(foreignScope);
287
287
 
288
+ // TODO(F-335): Avoid doing the following 2 calls here.
289
+ {
290
+ await this.handlerAsTxe().syncContractNonOracleMethod(contractAddress, scope, this.stateHandler.getCurrentJob());
291
+ // We cycle job to commit the stores after the contract sync.
292
+ await this.stateHandler.cycleJob();
293
+ }
294
+
288
295
  const events = await this.handlerAsTxe().txeGetPrivateEvents(selector, contractAddress, scope);
289
296
 
290
297
  if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
@@ -328,7 +335,7 @@ export class RPCTranslator {
328
335
 
329
336
  // When the argument is a slice, noir automatically adds a length field to oracle call.
330
337
  // When the argument is an array, we add the field length manually to the signature.
331
- utilityDebugLog(
338
+ async utilityLog(
332
339
  foreignLevel: ForeignCallSingle,
333
340
  foreignMessage: ForeignCallArray,
334
341
  _foreignLength: ForeignCallSingle,
@@ -340,40 +347,40 @@ export class RPCTranslator {
340
347
  .join('');
341
348
  const fields = fromArray(foreignFields);
342
349
 
343
- this.handlerAsMisc().utilityDebugLog(level, message, fields);
350
+ await this.handlerAsMisc().utilityLog(level, message, fields);
344
351
 
345
352
  return toForeignCallResult([]);
346
353
  }
347
354
 
348
355
  async utilityStorageRead(
356
+ foreignBlockHash: ForeignCallSingle,
349
357
  foreignContractAddress: ForeignCallSingle,
350
358
  foreignStartStorageSlot: ForeignCallSingle,
351
- foreignBlockNumber: ForeignCallSingle,
352
359
  foreignNumberOfElements: ForeignCallSingle,
353
360
  ) {
361
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
354
362
  const contractAddress = addressFromSingle(foreignContractAddress);
355
363
  const startStorageSlot = fromSingle(foreignStartStorageSlot);
356
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
357
364
  const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
358
365
 
359
366
  const values = await this.handlerAsUtility().utilityStorageRead(
367
+ blockHash,
360
368
  contractAddress,
361
369
  startStorageSlot,
362
- blockNumber,
363
370
  numberOfElements,
364
371
  );
365
372
 
366
373
  return toForeignCallResult([toArray(values)]);
367
374
  }
368
375
 
369
- async utilityGetPublicDataWitness(foreignBlockNumber: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
370
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
376
+ async utilityGetPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
377
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
371
378
  const leafSlot = fromSingle(foreignLeafSlot);
372
379
 
373
- const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockNumber, leafSlot);
380
+ const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockHash, leafSlot);
374
381
 
375
382
  if (!witness) {
376
- throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockNumber}.`);
383
+ throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
377
384
  }
378
385
  return toForeignCallResult(witness.toNoirRepresentation());
379
386
  }
@@ -396,7 +403,7 @@ export class RPCTranslator {
396
403
  foreignOffset: ForeignCallSingle,
397
404
  foreignStatus: ForeignCallSingle,
398
405
  foreignMaxNotes: ForeignCallSingle,
399
- foreignPackedRetrievedNoteLength: ForeignCallSingle,
406
+ foreignPackedHintedNoteLength: ForeignCallSingle,
400
407
  ) {
401
408
  // Parse Option<AztecAddress>: ownerIsSome is 0 for None, 1 for Some
402
409
  const owner = fromSingle(foreignOwnerIsSome).toBool()
@@ -417,7 +424,7 @@ export class RPCTranslator {
417
424
  const offset = fromSingle(foreignOffset).toNumber();
418
425
  const status = fromSingle(foreignStatus).toNumber();
419
426
  const maxNotes = fromSingle(foreignMaxNotes).toNumber();
420
- const packedRetrievedNoteLength = fromSingle(foreignPackedRetrievedNoteLength).toNumber();
427
+ const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
421
428
 
422
429
  const noteDatas = await this.handlerAsUtility().utilityGetNotes(
423
430
  owner,
@@ -438,13 +445,13 @@ export class RPCTranslator {
438
445
  );
439
446
 
440
447
  const returnDataAsArrayOfArrays = noteDatas.map(noteData =>
441
- packAsRetrievedNote({
448
+ packAsHintedNote({
442
449
  contractAddress: noteData.contractAddress,
443
450
  owner: noteData.owner,
444
451
  randomness: noteData.randomness,
445
452
  storageSlot: noteData.storageSlot,
446
453
  noteNonce: noteData.noteNonce,
447
- index: noteData.index,
454
+ isPending: noteData.isPending,
448
455
  note: noteData.note,
449
456
  }),
450
457
  );
@@ -456,11 +463,7 @@ export class RPCTranslator {
456
463
 
457
464
  // At last we convert the array of arrays to a bounded vec of arrays
458
465
  return toForeignCallResult(
459
- arrayOfArraysToBoundedVecOfArrays(
460
- returnDataAsArrayOfForeignCallSingleArrays,
461
- maxNotes,
462
- packedRetrievedNoteLength,
463
- ),
466
+ arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes, packedHintedNoteLength),
464
467
  );
465
468
  }
466
469
 
@@ -516,6 +519,15 @@ export class RPCTranslator {
516
519
  return toForeignCallResult([]);
517
520
  }
518
521
 
522
+ async privateIsNullifierPending(foreignInnerNullifier: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
523
+ const innerNullifier = fromSingle(foreignInnerNullifier);
524
+ const contractAddress = addressFromSingle(foreignContractAddress);
525
+
526
+ const isPending = await this.handlerAsPrivate().privateIsNullifierPending(innerNullifier, contractAddress);
527
+
528
+ return toForeignCallResult([toSingle(new Fr(isPending))]);
529
+ }
530
+
519
531
  async utilityCheckNullifierExists(foreignInnerNullifier: ForeignCallSingle) {
520
532
  const innerNullifier = fromSingle(foreignInnerNullifier);
521
533
 
@@ -540,12 +552,23 @@ export class RPCTranslator {
540
552
  );
541
553
  }
542
554
 
543
- async utilityGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
555
+ async utilityTryGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
544
556
  const address = addressFromSingle(foreignAddress);
545
557
 
546
- const { publicKeys, partialAddress } = await this.handlerAsUtility().utilityGetPublicKeysAndPartialAddress(address);
558
+ const result = await this.handlerAsUtility().utilityTryGetPublicKeysAndPartialAddress(address);
547
559
 
548
- return toForeignCallResult([toArray([...publicKeys.toFields(), partialAddress])]);
560
+ // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
561
+ // with two fields: `some` (a boolean) and `value` (a field array in this case).
562
+ if (result === undefined) {
563
+ // No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
564
+ return toForeignCallResult([toSingle(new Fr(0)), toArray(Array(13).fill(new Fr(0)))]);
565
+ } else {
566
+ // Data was found so we set `some` to 1 and return it along with `value`.
567
+ return toForeignCallResult([
568
+ toSingle(new Fr(1)),
569
+ toArray([...result.publicKeys.toFields(), result.partialAddress]),
570
+ ]);
571
+ }
549
572
  }
550
573
 
551
574
  async utilityGetKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
@@ -568,17 +591,14 @@ export class RPCTranslator {
568
591
  );
569
592
  }
570
593
 
571
- async utilityGetNullifierMembershipWitness(
572
- foreignBlockNumber: ForeignCallSingle,
573
- foreignNullifier: ForeignCallSingle,
574
- ) {
575
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
594
+ async utilityGetNullifierMembershipWitness(foreignBlockHash: ForeignCallSingle, foreignNullifier: ForeignCallSingle) {
595
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
576
596
  const nullifier = fromSingle(foreignNullifier);
577
597
 
578
- const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockNumber, nullifier);
598
+ const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockHash, nullifier);
579
599
 
580
600
  if (!witness) {
581
- throw new Error(`Nullifier membership witness not found at block ${blockNumber}.`);
601
+ throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
582
602
  }
583
603
  return toForeignCallResult(witness.toNoirRepresentation());
584
604
  }
@@ -639,36 +659,49 @@ export class RPCTranslator {
639
659
  return toForeignCallResult(header.toFields().map(toSingle));
640
660
  }
641
661
 
642
- async utilityGetMembershipWitness(
643
- foreignBlockNumber: ForeignCallSingle,
644
- foreignTreeId: ForeignCallSingle,
645
- foreignLeafValue: ForeignCallSingle,
662
+ async utilityGetNoteHashMembershipWitness(
663
+ foreignAnchorBlockHash: ForeignCallSingle,
664
+ foreignNoteHash: ForeignCallSingle,
646
665
  ) {
647
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
648
- const treeId = fromSingle(foreignTreeId).toNumber();
649
- const leafValue = fromSingle(foreignLeafValue);
666
+ const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
667
+ const noteHash = fromSingle(foreignNoteHash);
650
668
 
651
- const witness = await this.handlerAsUtility().utilityGetMembershipWitness(blockNumber, treeId, leafValue);
669
+ const witness = await this.handlerAsUtility().utilityGetNoteHashMembershipWitness(blockHash, noteHash);
670
+
671
+ if (!witness) {
672
+ throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
673
+ }
674
+ return toForeignCallResult(witness.toNoirRepresentation());
675
+ }
676
+
677
+ async utilityGetBlockHashMembershipWitness(
678
+ foreignAnchorBlockHash: ForeignCallSingle,
679
+ foreignBlockHash: ForeignCallSingle,
680
+ ) {
681
+ const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
682
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
683
+
684
+ const witness = await this.handlerAsUtility().utilityGetBlockHashMembershipWitness(anchorBlockHash, blockHash);
652
685
 
653
686
  if (!witness) {
654
687
  throw new Error(
655
- `Membership witness in tree ${MerkleTreeId[treeId]} not found for value ${leafValue} at block ${blockNumber}.`,
688
+ `Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`,
656
689
  );
657
690
  }
658
- return toForeignCallResult([toSingle(witness[0]), toArray(witness.slice(1))]);
691
+ return toForeignCallResult(witness.toNoirRepresentation());
659
692
  }
660
693
 
661
694
  async utilityGetLowNullifierMembershipWitness(
662
- foreignBlockNumber: ForeignCallSingle,
695
+ foreignBlockHash: ForeignCallSingle,
663
696
  foreignNullifier: ForeignCallSingle,
664
697
  ) {
665
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
698
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
666
699
  const nullifier = fromSingle(foreignNullifier);
667
700
 
668
- const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockNumber, nullifier);
701
+ const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockHash, nullifier);
669
702
 
670
703
  if (!witness) {
671
- throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockNumber}.`);
704
+ throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
672
705
  }
673
706
  return toForeignCallResult(witness.toNoirRepresentation());
674
707
  }
@@ -681,7 +714,7 @@ export class RPCTranslator {
681
714
  return toForeignCallResult([]);
682
715
  }
683
716
 
684
- public async utilityValidateEnqueuedNotesAndEvents(
717
+ public async utilityValidateAndStoreEnqueuedNotesAndEvents(
685
718
  foreignContractAddress: ForeignCallSingle,
686
719
  foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
687
720
  foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
@@ -690,7 +723,7 @@ export class RPCTranslator {
690
723
  const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
691
724
  const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
692
725
 
693
- await this.handlerAsUtility().utilityValidateEnqueuedNotesAndEvents(
726
+ await this.handlerAsUtility().utilityValidateAndStoreEnqueuedNotesAndEvents(
694
727
  contractAddress,
695
728
  noteValidationRequestsArrayBaseSlot,
696
729
  eventValidationRequestsArrayBaseSlot,
@@ -823,15 +856,16 @@ export class RPCTranslator {
823
856
 
824
857
  // AVM opcodes
825
858
 
826
- avmOpcodeEmitUnencryptedLog(_foreignMessage: ForeignCallArray) {
859
+ avmOpcodeEmitPublicLog(_foreignMessage: ForeignCallArray) {
827
860
  // TODO(#8811): Implement
828
861
  return toForeignCallResult([]);
829
862
  }
830
863
 
831
- async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle) {
864
+ async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
832
865
  const slot = fromSingle(foreignSlot);
866
+ const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
833
867
 
834
- const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot)).value;
868
+ const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot, contractAddress)).value;
835
869
 
836
870
  return toForeignCallResult([toSingle(new Fr(value))]);
837
871
  }
@@ -903,11 +937,10 @@ export class RPCTranslator {
903
937
  return toForeignCallResult([]);
904
938
  }
905
939
 
906
- async avmOpcodeNullifierExists(foreignInnerNullifier: ForeignCallSingle, foreignTargetAddress: ForeignCallSingle) {
907
- const innerNullifier = fromSingle(foreignInnerNullifier);
908
- const targetAddress = AztecAddress.fromField(fromSingle(foreignTargetAddress));
940
+ async avmOpcodeNullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
941
+ const siloedNullifier = fromSingle(foreignSiloedNullifier);
909
942
 
910
- const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(innerNullifier, targetAddress);
943
+ const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(siloedNullifier);
911
944
 
912
945
  return toForeignCallResult([toSingle(new Fr(exists))]);
913
946
  }
@@ -1012,12 +1045,15 @@ export class RPCTranslator {
1012
1045
  args,
1013
1046
  argsHash,
1014
1047
  isStaticCall,
1048
+ this.stateHandler.getCurrentJob(),
1015
1049
  );
1016
1050
 
1051
+ // TODO(F-335): Avoid doing the following call here.
1052
+ await this.stateHandler.cycleJob();
1017
1053
  return toForeignCallResult([toArray(returnValues)]);
1018
1054
  }
1019
1055
 
1020
- async txeSimulateUtilityFunction(
1056
+ async txeExecuteUtilityFunction(
1021
1057
  foreignTargetContractAddress: ForeignCallSingle,
1022
1058
  foreignFunctionSelector: ForeignCallSingle,
1023
1059
  foreignArgs: ForeignCallArray,
@@ -1026,12 +1062,15 @@ export class RPCTranslator {
1026
1062
  const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
1027
1063
  const args = fromArray(foreignArgs);
1028
1064
 
1029
- const returnValues = await this.handlerAsTxe().txeSimulateUtilityFunction(
1065
+ const returnValues = await this.handlerAsTxe().txeExecuteUtilityFunction(
1030
1066
  targetContractAddress,
1031
1067
  functionSelector,
1032
1068
  args,
1069
+ this.stateHandler.getCurrentJob(),
1033
1070
  );
1034
1071
 
1072
+ // TODO(F-335): Avoid doing the following call here.
1073
+ await this.stateHandler.cycleJob();
1035
1074
  return toForeignCallResult([toArray(returnValues)]);
1036
1075
  }
1037
1076
 
@@ -1048,6 +1087,8 @@ export class RPCTranslator {
1048
1087
 
1049
1088
  const returnValues = await this.handlerAsTxe().txePublicCallNewFlow(from, address, calldata, isStaticCall);
1050
1089
 
1090
+ // TODO(F-335): Avoid doing the following call here.
1091
+ await this.stateHandler.cycleJob();
1051
1092
  return toForeignCallResult([toArray(returnValues)]);
1052
1093
  }
1053
1094
 
@@ -1,204 +1,48 @@
1
- import { ArchiverStoreHelper, KVArchiverDataStore } from '@aztec/archiver';
1
+ import { ArchiverDataSourceBase, ArchiverDataStoreUpdater, KVArchiverDataStore } from '@aztec/archiver';
2
2
  import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
3
- import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { CheckpointNumber, type EpochNumber, type SlotNumber } from '@aztec/foundation/branded-types';
4
4
  import { Fr } from '@aztec/foundation/curves/bn254';
5
5
  import type { EthAddress } from '@aztec/foundation/eth-address';
6
- import { isDefined } from '@aztec/foundation/types';
7
6
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
8
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
9
- import {
10
- CommitteeAttestation,
11
- L2Block,
12
- type L2BlockId,
13
- type L2BlockNew,
14
- type L2BlockSource,
15
- type L2Tips,
16
- PublishedL2Block,
17
- type ValidateBlockResult,
18
- } from '@aztec/stdlib/block';
19
- import { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
20
- 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';
21
9
  import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
22
- import type { BlockHeader } from '@aztec/stdlib/tx';
23
- import type { UInt64 } from '@aztec/stdlib/types';
24
10
 
25
- // We are extending the ArchiverDataStoreHelper here because it provides most of the endpoints needed by the
26
- // node for reading from and writing to state, without needing any of the extra overhead that the Archiver itself
27
- // requires (i.e. an L1 client)
28
- export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
29
- constructor(db: AztecAsyncKVStore) {
30
- super(new KVArchiverDataStore(db, 9999));
31
- }
32
-
33
- public async getBlock(number: BlockNumber): Promise<L2Block | undefined> {
34
- if (number === 0) {
35
- return undefined;
36
- }
37
- const publishedBlocks = await this.getPublishedBlocks(number, 1);
38
- if (publishedBlocks.length === 0) {
39
- return undefined;
40
- }
41
- return publishedBlocks[0].block;
42
- }
43
-
44
- public async getBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<L2Block[]> {
45
- const publishedBlocks = await this.getPublishedBlocks(from, limit, proven);
46
- return publishedBlocks.map(x => x.block);
47
- }
48
-
49
- public override async addCheckpoints(
50
- checkpoints: PublishedCheckpoint[],
51
- _result?: ValidateBlockResult,
52
- ): Promise<boolean> {
53
- const allBlocks = checkpoints.flatMap(ch => ch.checkpoint.blocks);
54
- const opResults = await Promise.all([this.store.addLogs(allBlocks), this.store.addCheckpoints(checkpoints)]);
55
-
56
- return opResults.every(Boolean);
57
- }
58
-
59
- /**
60
- * Gets the number of the latest L2 block processed by the block source implementation.
61
- * @returns The number of the latest L2 block processed by the block source implementation.
62
- */
63
- public getBlockNumber(): Promise<BlockNumber> {
64
- return this.store.getLatestBlockNumber();
65
- }
66
-
67
- /**
68
- * Gets the number of the latest L2 block proven seen by the block source implementation.
69
- * @returns The number of the latest L2 block proven seen by the block source implementation.
70
- */
71
- public override getProvenBlockNumber(): Promise<BlockNumber> {
72
- return this.store.getProvenBlockNumber();
73
- }
74
-
75
- /**
76
- * Gets a published l2 block. If a negative number is passed, the block returned is the most recent.
77
- * @param number - The block number to return (inclusive).
78
- * @returns The requested L2 block.
79
- */
80
- public async getPublishedBlock(number: number): Promise<PublishedL2Block | undefined> {
81
- // If the number provided is -ve, then return the latest block.
82
- if (number < 0) {
83
- number = await this.store.getLatestBlockNumber();
84
- }
85
- if (number == 0) {
86
- return undefined;
87
- }
88
- const publishedBlocks = await this.retrievePublishedBlocks(BlockNumber(number), 1);
89
- return publishedBlocks.length === 0 ? undefined : publishedBlocks[0];
90
- }
91
-
92
- getPublishedBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<PublishedL2Block[]> {
93
- return this.retrievePublishedBlocks(from, limit, proven);
94
- }
95
-
96
- private async retrievePublishedBlocks(
97
- from: BlockNumber,
98
- limit: number,
99
- proven?: boolean,
100
- ): Promise<PublishedL2Block[]> {
101
- const checkpoints = await this.store.getRangeOfCheckpoints(CheckpointNumber(from), limit);
102
- const provenCheckpointNumber = await this.store.getProvenCheckpointNumber();
103
- const blocks = (
104
- await Promise.all(checkpoints.map(ch => this.store.getBlocksForCheckpoint(ch.checkpointNumber)))
105
- ).filter(isDefined);
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);
106
18
 
107
- const olbBlocks: PublishedL2Block[] = [];
108
- for (let i = 0; i < checkpoints.length; i++) {
109
- const blockForCheckpoint = blocks[i][0];
110
- const checkpoint = checkpoints[i];
111
- if (proven === true && checkpoint.checkpointNumber > provenCheckpointNumber) {
112
- continue;
113
- }
114
- const oldCheckpoint = new Checkpoint(
115
- blockForCheckpoint.archive,
116
- checkpoint.header,
117
- [blockForCheckpoint],
118
- checkpoint.checkpointNumber,
119
- );
120
- const oldBlock = L2Block.fromCheckpoint(oldCheckpoint);
121
- const publishedBlock = new PublishedL2Block(
122
- oldBlock,
123
- checkpoint.l1,
124
- checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
125
- );
126
- olbBlocks.push(publishedBlock);
127
- }
128
- return olbBlocks;
129
- }
130
-
131
- /**
132
- * Gets an l2 block. If a negative number is passed, the block returned is the most recent.
133
- * @param number - The block number to return (inclusive).
134
- * @returns The requested L2 block.
135
- */
136
- public getL2Block(number: BlockNumber | 'latest'): Promise<L2Block | undefined> {
137
- return this.getPublishedBlock(number != 'latest' ? number : -1).then(b => b?.block);
138
- }
139
-
140
- /**
141
- * Gets an L2 block (new format).
142
- * @param number - The block number to return.
143
- * @returns The requested L2 block.
144
- */
145
- public getL2BlockNew(number: BlockNumber): Promise<L2BlockNew | undefined> {
146
- if (number === 0) {
147
- return Promise.resolve(undefined);
148
- }
149
- return this.store.getBlock(number);
150
- }
151
-
152
- /**
153
- * Gets an l2 block header.
154
- * @param number - The block number to return or 'latest' for the most recent one.
155
- * @returns The requested L2 block header.
156
- */
157
- public async getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
158
- if (number === 'latest') {
159
- number = await this.store.getLatestBlockNumber();
160
- }
161
- if (number === 0) {
162
- return undefined;
163
- }
164
- const headers = await this.store.getBlockHeaders(BlockNumber(number), 1);
165
- return headers.length === 0 ? undefined : headers[0];
166
- }
167
-
168
- public getBlockRange(from: number, limit: number, _proven?: boolean): Promise<L2Block[]> {
169
- return this.getPublishedBlocks(BlockNumber(from), limit).then(blocks => blocks.map(b => b.block));
170
- }
171
-
172
- public getPublishedCheckpoints(_from: CheckpointNumber, _limit: number): Promise<PublishedCheckpoint[]> {
173
- throw new Error('TXE Archiver does not implement "getPublishedCheckpoints"');
174
- }
175
-
176
- public getCheckpointByArchive(_archive: Fr): Promise<Checkpoint | undefined> {
177
- throw new Error('TXE Archiver does not implement "getCheckpointByArchive"');
19
+ constructor(db: AztecAsyncKVStore) {
20
+ const store = new KVArchiverDataStore(db, 9999, { epochDuration: 32 });
21
+ super(store);
178
22
  }
179
23
 
180
- public getL2SlotNumber(): Promise<SlotNumber | undefined> {
181
- throw new Error('TXE Archiver does not implement "getL2SlotNumber"');
24
+ public async addCheckpoints(checkpoints: PublishedCheckpoint[], result?: ValidateCheckpointResult): Promise<void> {
25
+ await this.updater.addCheckpoints(checkpoints, result);
182
26
  }
183
27
 
184
- public getL2EpochNumber(): Promise<EpochNumber> {
185
- throw new Error('TXE Archiver does not implement "getL2EpochNumber"');
28
+ public getRollupAddress(): Promise<EthAddress> {
29
+ throw new Error('TXE Archiver does not implement "getRollupAddress"');
186
30
  }
187
31
 
188
- public getCheckpointsForEpoch(_epochNumber: EpochNumber): Promise<Checkpoint[]> {
189
- throw new Error('TXE Archiver does not implement "getCheckpointsForEpoch"');
32
+ public getRegistryAddress(): Promise<EthAddress> {
33
+ throw new Error('TXE Archiver does not implement "getRegistryAddress"');
190
34
  }
191
35
 
192
- public getBlocksForEpoch(_epochNumber: EpochNumber): Promise<L2Block[]> {
193
- throw new Error('TXE Archiver does not implement "getBlocksForEpoch"');
36
+ public getL1Constants(): Promise<L1RollupConstants> {
37
+ throw new Error('TXE Archiver does not implement "getL1Constants"');
194
38
  }
195
39
 
196
- public getBlockHeadersForEpoch(_epochNumber: EpochNumber): Promise<BlockHeader[]> {
197
- throw new Error('TXE Archiver does not implement "getBlockHeadersForEpoch"');
40
+ public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
41
+ return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
198
42
  }
199
43
 
200
- public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
201
- throw new Error('TXE Archiver does not implement "isEpochComplete"');
44
+ public getL1Timestamp(): Promise<bigint | undefined> {
45
+ throw new Error('TXE Archiver does not implement "getL1Timestamp"');
202
46
  }
203
47
 
204
48
  public async getL2Tips(): Promise<L2Tips> {
@@ -211,53 +55,43 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
211
55
 
212
56
  const number = blockHeader.globalVariables.blockNumber;
213
57
  const hash = (await blockHeader.hash()).toString();
58
+ const checkpointedBlock = await this.getCheckpointedBlock(number);
59
+ if (!checkpointedBlock) {
60
+ throw new Error(`L2Tips requested from TXE Archiver but no checkpointed block found for block number ${number}`);
61
+ }
62
+ // TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
63
+ // This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
64
+ const checkpoint = await this.store.getRangeOfCheckpoints(CheckpointNumber.fromBlockNumber(number), 1);
65
+ if (checkpoint.length === 0) {
66
+ throw new Error(`L2Tips requested from TXE Archiver but no checkpoint found for block number ${number}`);
67
+ }
68
+ const blockId: L2BlockId = { number, hash };
69
+ const checkpointId: CheckpointId = {
70
+ number: checkpoint[0].checkpointNumber,
71
+ hash: checkpoint[0].header.hash().toString(),
72
+ };
73
+ const tipId: L2TipId = { block: blockId, checkpoint: checkpointId };
214
74
  return {
215
- latest: { number, hash } as L2BlockId,
216
- proven: { number, hash } as L2BlockId,
217
- finalized: { number, hash } as L2BlockId,
75
+ proposed: blockId,
76
+ proven: tipId,
77
+ finalized: tipId,
78
+ checkpointed: tipId,
218
79
  };
219
80
  }
220
81
 
221
- public getL1Constants(): Promise<L1RollupConstants> {
222
- throw new Error('TXE Archiver does not implement "getL2Constants"');
223
- }
224
-
225
- public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
226
- return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
227
- }
228
-
229
- public syncImmediate(): Promise<void> {
230
- throw new Error('TXE Archiver does not implement "syncImmediate"');
231
- }
232
-
233
- public getContract(_address: AztecAddress, _timestamp?: UInt64): Promise<ContractInstanceWithAddress | undefined> {
234
- throw new Error('TXE Archiver does not implement "getContract"');
235
- }
236
-
237
- public getRollupAddress(): Promise<EthAddress> {
238
- throw new Error('TXE Archiver does not implement "getRollupAddress"');
239
- }
240
-
241
- public getRegistryAddress(): Promise<EthAddress> {
242
- throw new Error('TXE Archiver does not implement "getRegistryAddress"');
243
- }
244
-
245
- public getL1Timestamp(): Promise<bigint> {
246
- throw new Error('TXE Archiver does not implement "getL1Timestamp"');
82
+ public getL2SlotNumber(): Promise<SlotNumber | undefined> {
83
+ throw new Error('TXE Archiver does not implement "getL2SlotNumber"');
247
84
  }
248
85
 
249
- public isPendingChainInvalid(): Promise<boolean> {
250
- return Promise.resolve(false);
86
+ public getL2EpochNumber(): Promise<EpochNumber | undefined> {
87
+ throw new Error('TXE Archiver does not implement "getL2EpochNumber"');
251
88
  }
252
89
 
253
- public override getPendingChainValidationStatus(): Promise<ValidateBlockResult> {
254
- return Promise.resolve({ valid: true });
90
+ public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
91
+ throw new Error('TXE Archiver does not implement "isEpochComplete"');
255
92
  }
256
93
 
257
- getPublishedBlockByHash(_blockHash: Fr): Promise<PublishedL2Block | undefined> {
258
- throw new Error('Method not implemented.');
259
- }
260
- getPublishedBlockByArchive(_archive: Fr): Promise<PublishedL2Block | undefined> {
261
- throw new Error('Method not implemented.');
94
+ public syncImmediate(): Promise<void> {
95
+ throw new Error('TXE Archiver does not implement "syncImmediate"');
262
96
  }
263
97
  }