@aztec/txe 0.0.1-commit.96bb3f7 → 0.0.1-commit.96dac018d
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 +1 -2
- package/dest/constants.d.ts.map +1 -1
- package/dest/constants.js +0 -1
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +82 -50
- package/dest/oracle/interfaces.d.ts +6 -5
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +3 -3
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +6 -6
- package/dest/oracle/txe_oracle_top_level_context.d.ts +7 -7
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +118 -41
- package/dest/rpc_translator.d.ts +21 -15
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +91 -54
- package/dest/state_machine/archiver.d.ts +20 -69
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +36 -178
- package/dest/state_machine/dummy_p2p_client.d.ts +16 -12
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +28 -16
- 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 +35 -12
- package/dest/state_machine/mock_epoch_cache.d.ts +8 -6
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +11 -7
- package/dest/state_machine/synchronizer.d.ts +3 -3
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/txe_session.d.ts +11 -6
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +98 -23
- package/dest/util/encoding.d.ts +17 -17
- package/dest/util/txe_public_contract_data_source.d.ts +2 -3
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +5 -22
- package/dest/utils/block_creation.d.ts +4 -4
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +18 -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 +3 -6
- package/package.json +16 -16
- package/src/constants.ts +0 -1
- package/src/index.ts +83 -49
- package/src/oracle/interfaces.ts +8 -3
- package/src/oracle/txe_oracle_public_context.ts +6 -8
- package/src/oracle/txe_oracle_top_level_context.ts +152 -90
- package/src/rpc_translator.ts +96 -55
- package/src/state_machine/archiver.ts +37 -234
- package/src/state_machine/dummy_p2p_client.ts +40 -22
- package/src/state_machine/index.ts +49 -11
- package/src/state_machine/mock_epoch_cache.ts +11 -11
- package/src/state_machine/synchronizer.ts +2 -2
- package/src/txe_session.ts +112 -84
- package/src/util/txe_public_contract_data_source.ts +10 -36
- package/src/utils/block_creation.ts +19 -16
- package/src/utils/tx_effect_creation.ts +3 -11
- package/dest/util/txe_contract_store.d.ts +0 -12
- package/dest/util/txe_contract_store.d.ts.map +0 -1
- package/dest/util/txe_contract_store.js +0 -22
- package/src/util/txe_contract_store.ts +0 -36
package/src/rpc_translator.ts
CHANGED
|
@@ -6,11 +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
11
|
import { type ContractArtifact, EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
12
12
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
13
|
-
import {
|
|
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';
|
|
@@ -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
|
-
|
|
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().
|
|
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(
|
|
370
|
-
const
|
|
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(
|
|
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 ${
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
555
|
+
async utilityTryGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
|
|
544
556
|
const address = addressFromSingle(foreignAddress);
|
|
545
557
|
|
|
546
|
-
const
|
|
558
|
+
const result = await this.handlerAsUtility().utilityTryGetPublicKeysAndPartialAddress(address);
|
|
547
559
|
|
|
548
|
-
return
|
|
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
|
-
|
|
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(
|
|
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 ${
|
|
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
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
foreignLeafValue: ForeignCallSingle,
|
|
662
|
+
async utilityGetNoteHashMembershipWitness(
|
|
663
|
+
foreignAnchorBlockHash: ForeignCallSingle,
|
|
664
|
+
foreignNoteHash: ForeignCallSingle,
|
|
646
665
|
) {
|
|
647
|
-
const
|
|
648
|
-
const
|
|
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().
|
|
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
|
-
`
|
|
688
|
+
`Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`,
|
|
656
689
|
);
|
|
657
690
|
}
|
|
658
|
-
return toForeignCallResult(
|
|
691
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
659
692
|
}
|
|
660
693
|
|
|
661
694
|
async utilityGetLowNullifierMembershipWitness(
|
|
662
|
-
|
|
695
|
+
foreignBlockHash: ForeignCallSingle,
|
|
663
696
|
foreignNullifier: ForeignCallSingle,
|
|
664
697
|
) {
|
|
665
|
-
const
|
|
698
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
666
699
|
const nullifier = fromSingle(foreignNullifier);
|
|
667
700
|
|
|
668
|
-
const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(
|
|
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 ${
|
|
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
|
|
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().
|
|
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
|
-
|
|
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(
|
|
907
|
-
const
|
|
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(
|
|
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
|
|
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().
|
|
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,216 +1,48 @@
|
|
|
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
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 {
|
|
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';
|
|
22
|
-
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';
|
|
23
9
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
24
|
-
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
25
|
-
import type { UInt64 } from '@aztec/stdlib/types';
|
|
26
10
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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)]);
|
|
57
|
-
|
|
58
|
-
return opResults.every(Boolean);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Gets the number of the latest L2 block processed by the block source implementation.
|
|
63
|
-
* @returns The number of the latest L2 block processed by the block source implementation.
|
|
64
|
-
*/
|
|
65
|
-
public getBlockNumber(): Promise<BlockNumber> {
|
|
66
|
-
return this.store.getLatestBlockNumber();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Gets the number of the latest L2 block proven seen by the block source implementation.
|
|
71
|
-
* @returns The number of the latest L2 block proven seen by the block source implementation.
|
|
72
|
-
*/
|
|
73
|
-
public override getProvenBlockNumber(): Promise<BlockNumber> {
|
|
74
|
-
return this.store.getProvenBlockNumber();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Gets a published l2 block. If a negative number is passed, the block returned is the most recent.
|
|
79
|
-
* @param number - The block number to return (inclusive).
|
|
80
|
-
* @returns The requested L2 block.
|
|
81
|
-
*/
|
|
82
|
-
public async getPublishedBlock(number: number): Promise<PublishedL2Block | undefined> {
|
|
83
|
-
// If the number provided is -ve, then return the latest block.
|
|
84
|
-
if (number < 0) {
|
|
85
|
-
number = await this.store.getLatestBlockNumber();
|
|
86
|
-
}
|
|
87
|
-
if (number == 0) {
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
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);
|
|
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);
|
|
100
18
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Gets an l2 block. If a negative number is passed, the block returned is the most recent.
|
|
145
|
-
* @param number - The block number to return (inclusive).
|
|
146
|
-
* @returns The requested L2 block.
|
|
147
|
-
*/
|
|
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);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Gets an l2 block header.
|
|
166
|
-
* @param number - The block number to return or 'latest' for the most recent one.
|
|
167
|
-
* @returns The requested L2 block header.
|
|
168
|
-
*/
|
|
169
|
-
public async getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
170
|
-
if (number === 'latest') {
|
|
171
|
-
number = await this.store.getLatestBlockNumber();
|
|
172
|
-
}
|
|
173
|
-
if (number === 0) {
|
|
174
|
-
return undefined;
|
|
175
|
-
}
|
|
176
|
-
const headers = await this.store.getBlockHeaders(BlockNumber(number), 1);
|
|
177
|
-
return headers.length === 0 ? undefined : headers[0];
|
|
178
|
-
}
|
|
179
|
-
|
|
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"');
|
|
19
|
+
constructor(db: AztecAsyncKVStore) {
|
|
20
|
+
const store = new KVArchiverDataStore(db, 9999, { epochDuration: 32 });
|
|
21
|
+
super(store);
|
|
190
22
|
}
|
|
191
23
|
|
|
192
|
-
public
|
|
193
|
-
|
|
24
|
+
public async addCheckpoints(checkpoints: PublishedCheckpoint[], result?: ValidateCheckpointResult): Promise<void> {
|
|
25
|
+
await this.updater.addCheckpoints(checkpoints, result);
|
|
194
26
|
}
|
|
195
27
|
|
|
196
|
-
public
|
|
197
|
-
throw new Error('TXE Archiver does not implement "
|
|
28
|
+
public getRollupAddress(): Promise<EthAddress> {
|
|
29
|
+
throw new Error('TXE Archiver does not implement "getRollupAddress"');
|
|
198
30
|
}
|
|
199
31
|
|
|
200
|
-
public
|
|
201
|
-
throw new Error('TXE Archiver does not implement "
|
|
32
|
+
public getRegistryAddress(): Promise<EthAddress> {
|
|
33
|
+
throw new Error('TXE Archiver does not implement "getRegistryAddress"');
|
|
202
34
|
}
|
|
203
35
|
|
|
204
|
-
public
|
|
205
|
-
throw new Error('TXE Archiver does not implement "
|
|
36
|
+
public getL1Constants(): Promise<L1RollupConstants> {
|
|
37
|
+
throw new Error('TXE Archiver does not implement "getL1Constants"');
|
|
206
38
|
}
|
|
207
39
|
|
|
208
|
-
public
|
|
209
|
-
|
|
40
|
+
public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
|
|
41
|
+
return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
|
|
210
42
|
}
|
|
211
43
|
|
|
212
|
-
public
|
|
213
|
-
throw new Error('TXE Archiver does not implement "
|
|
44
|
+
public getL1Timestamp(): Promise<bigint | undefined> {
|
|
45
|
+
throw new Error('TXE Archiver does not implement "getL1Timestamp"');
|
|
214
46
|
}
|
|
215
47
|
|
|
216
48
|
public async getL2Tips(): Promise<L2Tips> {
|
|
@@ -227,7 +59,9 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
|
|
|
227
59
|
if (!checkpointedBlock) {
|
|
228
60
|
throw new Error(`L2Tips requested from TXE Archiver but no checkpointed block found for block number ${number}`);
|
|
229
61
|
}
|
|
230
|
-
|
|
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);
|
|
231
65
|
if (checkpoint.length === 0) {
|
|
232
66
|
throw new Error(`L2Tips requested from TXE Archiver but no checkpoint found for block number ${number}`);
|
|
233
67
|
}
|
|
@@ -245,50 +79,19 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
|
|
|
245
79
|
};
|
|
246
80
|
}
|
|
247
81
|
|
|
248
|
-
public
|
|
249
|
-
throw new Error('TXE Archiver does not implement "
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
|
|
253
|
-
return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
public syncImmediate(): Promise<void> {
|
|
257
|
-
throw new Error('TXE Archiver does not implement "syncImmediate"');
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
public getContract(_address: AztecAddress, _timestamp?: UInt64): Promise<ContractInstanceWithAddress | undefined> {
|
|
261
|
-
throw new Error('TXE Archiver does not implement "getContract"');
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
public getRollupAddress(): Promise<EthAddress> {
|
|
265
|
-
throw new Error('TXE Archiver does not implement "getRollupAddress"');
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
public getRegistryAddress(): Promise<EthAddress> {
|
|
269
|
-
throw new Error('TXE Archiver does not implement "getRegistryAddress"');
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
public getL1Timestamp(): Promise<bigint> {
|
|
273
|
-
throw new Error('TXE Archiver does not implement "getL1Timestamp"');
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
public isPendingChainInvalid(): Promise<boolean> {
|
|
277
|
-
return Promise.resolve(false);
|
|
82
|
+
public getL2SlotNumber(): Promise<SlotNumber | undefined> {
|
|
83
|
+
throw new Error('TXE Archiver does not implement "getL2SlotNumber"');
|
|
278
84
|
}
|
|
279
85
|
|
|
280
|
-
public
|
|
281
|
-
|
|
86
|
+
public getL2EpochNumber(): Promise<EpochNumber | undefined> {
|
|
87
|
+
throw new Error('TXE Archiver does not implement "getL2EpochNumber"');
|
|
282
88
|
}
|
|
283
89
|
|
|
284
|
-
|
|
285
|
-
throw new Error('
|
|
286
|
-
}
|
|
287
|
-
getPublishedBlockByArchive(_archive: Fr): Promise<PublishedL2Block | undefined> {
|
|
288
|
-
throw new Error('Method not implemented.');
|
|
90
|
+
public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
|
|
91
|
+
throw new Error('TXE Archiver does not implement "isEpochComplete"');
|
|
289
92
|
}
|
|
290
93
|
|
|
291
|
-
|
|
292
|
-
throw new Error('TXE Archiver does not implement "
|
|
94
|
+
public syncImmediate(): Promise<void> {
|
|
95
|
+
throw new Error('TXE Archiver does not implement "syncImmediate"');
|
|
293
96
|
}
|
|
294
97
|
}
|