@aztec/txe 3.0.0-rc.5 → 4.0.0-nightly.20260107

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 (66) 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 +3 -2
  7. package/dest/oracle/interfaces.d.ts +4 -2
  8. package/dest/oracle/interfaces.d.ts.map +1 -1
  9. package/dest/oracle/txe_oracle_public_context.d.ts +2 -2
  10. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_public_context.js +3 -5
  12. package/dest/oracle/txe_oracle_top_level_context.d.ts +18 -10
  13. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  14. package/dest/oracle/txe_oracle_top_level_context.js +83 -52
  15. package/dest/rpc_translator.d.ts +9 -3
  16. package/dest/rpc_translator.d.ts.map +1 -1
  17. package/dest/rpc_translator.js +33 -3
  18. package/dest/state_machine/archiver.d.ts +19 -7
  19. package/dest/state_machine/archiver.d.ts.map +1 -1
  20. package/dest/state_machine/archiver.js +93 -15
  21. package/dest/state_machine/dummy_p2p_client.d.ts +1 -1
  22. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  23. package/dest/state_machine/dummy_p2p_client.js +3 -1
  24. package/dest/state_machine/global_variable_builder.d.ts +3 -2
  25. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  26. package/dest/state_machine/global_variable_builder.js +12 -0
  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 +13 -19
  30. package/dest/txe_session.d.ts +15 -9
  31. package/dest/txe_session.d.ts.map +1 -1
  32. package/dest/txe_session.js +72 -42
  33. package/dest/util/encoding.d.ts +601 -2
  34. package/dest/util/encoding.d.ts.map +1 -1
  35. package/dest/util/txe_account_store.d.ts +10 -0
  36. package/dest/util/txe_account_store.d.ts.map +1 -0
  37. package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
  38. package/dest/util/txe_contract_store.d.ts +12 -0
  39. package/dest/util/txe_contract_store.d.ts.map +1 -0
  40. package/dest/util/{txe_contract_data_provider.js → txe_contract_store.js} +3 -3
  41. package/dest/util/txe_public_contract_data_source.d.ts +4 -4
  42. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  43. package/dest/util/txe_public_contract_data_source.js +10 -10
  44. package/dest/utils/block_creation.d.ts +16 -2
  45. package/dest/utils/block_creation.d.ts.map +1 -1
  46. package/dest/utils/block_creation.js +22 -1
  47. package/package.json +15 -15
  48. package/src/constants.ts +3 -0
  49. package/src/index.ts +15 -12
  50. package/src/oracle/interfaces.ts +3 -1
  51. package/src/oracle/txe_oracle_public_context.ts +3 -8
  52. package/src/oracle/txe_oracle_top_level_context.ts +125 -76
  53. package/src/rpc_translator.ts +45 -3
  54. package/src/state_machine/archiver.ts +119 -21
  55. package/src/state_machine/dummy_p2p_client.ts +3 -1
  56. package/src/state_machine/global_variable_builder.ts +18 -1
  57. package/src/state_machine/index.ts +18 -17
  58. package/src/txe_session.ts +157 -69
  59. package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
  60. package/src/util/{txe_contract_data_provider.ts → txe_contract_store.ts} +3 -3
  61. package/src/util/txe_public_contract_data_source.ts +9 -9
  62. package/src/utils/block_creation.ts +31 -1
  63. package/dest/util/txe_account_data_provider.d.ts +0 -10
  64. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  65. package/dest/util/txe_contract_data_provider.d.ts +0 -12
  66. package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
@@ -1,12 +1,22 @@
1
- import { ArchiverStoreHelper, KVArchiverDataStore, type PublishedL2Block } from '@aztec/archiver';
1
+ import { ArchiverStoreHelper, KVArchiverDataStore } from '@aztec/archiver';
2
2
  import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
3
3
  import { BlockNumber, CheckpointNumber, EpochNumber, 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';
6
7
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
7
8
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
8
- import type { L2Block, L2BlockSource, L2Tips, ValidateBlockResult } from '@aztec/stdlib/block';
9
- import type { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
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';
10
20
  import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
11
21
  import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
12
22
  import type { BlockHeader } from '@aztec/stdlib/tx';
@@ -20,11 +30,28 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
20
30
  super(new KVArchiverDataStore(db, 9999));
21
31
  }
22
32
 
23
- public override async addBlocks(blocks: PublishedL2Block[]): Promise<boolean> {
24
- const opResults = await Promise.all([
25
- this.store.addLogs(blocks.map(block => block.block)),
26
- this.store.addBlocks(blocks),
27
- ]);
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)]);
28
55
 
29
56
  return opResults.every(Boolean);
30
57
  }
@@ -34,15 +61,15 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
34
61
  * @returns The number of the latest L2 block processed by the block source implementation.
35
62
  */
36
63
  public getBlockNumber(): Promise<BlockNumber> {
37
- return this.store.getSynchedL2BlockNumber();
64
+ return this.store.getLatestBlockNumber();
38
65
  }
39
66
 
40
67
  /**
41
68
  * Gets the number of the latest L2 block proven seen by the block source implementation.
42
69
  * @returns The number of the latest L2 block proven seen by the block source implementation.
43
70
  */
44
- public getProvenBlockNumber(): Promise<BlockNumber> {
45
- return this.store.getSynchedL2BlockNumber();
71
+ public override getProvenBlockNumber(): Promise<BlockNumber> {
72
+ return this.store.getProvenBlockNumber();
46
73
  }
47
74
 
48
75
  /**
@@ -50,16 +77,55 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
50
77
  * @param number - The block number to return (inclusive).
51
78
  * @returns The requested L2 block.
52
79
  */
53
- public override async getPublishedBlock(number: number): Promise<PublishedL2Block | undefined> {
80
+ public async getPublishedBlock(number: number): Promise<PublishedL2Block | undefined> {
54
81
  // If the number provided is -ve, then return the latest block.
55
82
  if (number < 0) {
56
- number = await this.store.getSynchedL2BlockNumber();
83
+ number = await this.store.getLatestBlockNumber();
57
84
  }
58
85
  if (number == 0) {
59
86
  return undefined;
60
87
  }
61
- const blocks = await this.store.getPublishedBlocks(BlockNumber(number), 1);
62
- return blocks.length === 0 ? undefined : blocks[0];
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);
106
+
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;
63
129
  }
64
130
 
65
131
  /**
@@ -67,8 +133,20 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
67
133
  * @param number - The block number to return (inclusive).
68
134
  * @returns The requested L2 block.
69
135
  */
70
- public getBlock(number: number | 'latest'): Promise<L2Block | undefined> {
71
- return this.getPublishedBlock(number != 'latest' ? number : -1).then(block => block?.block);
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);
72
150
  }
73
151
 
74
152
  /**
@@ -78,7 +156,7 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
78
156
  */
79
157
  public async getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
80
158
  if (number === 'latest') {
81
- number = await this.store.getSynchedL2BlockNumber();
159
+ number = await this.store.getLatestBlockNumber();
82
160
  }
83
161
  if (number === 0) {
84
162
  return undefined;
@@ -87,7 +165,7 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
87
165
  return headers.length === 0 ? undefined : headers[0];
88
166
  }
89
167
 
90
- public getBlocks(from: number, limit: number, _proven?: boolean): Promise<L2Block[]> {
168
+ public getBlockRange(from: number, limit: number, _proven?: boolean): Promise<L2Block[]> {
91
169
  return this.getPublishedBlocks(BlockNumber(from), limit).then(blocks => blocks.map(b => b.block));
92
170
  }
93
171
 
@@ -123,8 +201,21 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
123
201
  throw new Error('TXE Archiver does not implement "isEpochComplete"');
124
202
  }
125
203
 
126
- public getL2Tips(): Promise<L2Tips> {
127
- throw new Error('TXE Archiver does not implement "getL2Tips"');
204
+ public async getL2Tips(): Promise<L2Tips> {
205
+ // In TXE there is no possibility of reorgs and no blocks are ever getting proven so we just set 'latest', 'proven'
206
+ // and 'finalized' to the latest block.
207
+ const blockHeader = await this.getBlockHeader('latest');
208
+ if (!blockHeader) {
209
+ throw new Error('L2Tips requested from TXE Archiver but no block header found');
210
+ }
211
+
212
+ const number = blockHeader.globalVariables.blockNumber;
213
+ const hash = (await blockHeader.hash()).toString();
214
+ return {
215
+ latest: { number, hash } as L2BlockId,
216
+ proven: { number, hash } as L2BlockId,
217
+ finalized: { number, hash } as L2BlockId,
218
+ };
128
219
  }
129
220
 
130
221
  public getL1Constants(): Promise<L1RollupConstants> {
@@ -162,4 +253,11 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
162
253
  public override getPendingChainValidationStatus(): Promise<ValidateBlockResult> {
163
254
  return Promise.resolve({ valid: true });
164
255
  }
256
+
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.');
262
+ }
165
263
  }
@@ -79,7 +79,9 @@ export class DummyP2P implements P2P {
79
79
  }
80
80
 
81
81
  public getTxStatus(_txHash: TxHash): Promise<'pending' | 'mined' | undefined> {
82
- throw new Error('DummyP2P does not implement "getTxStatus"');
82
+ // In TXE there is no concept of transactions but we need to implement this because of tagging. We return 'mined'
83
+ // tx status for any tx hash.
84
+ return Promise.resolve('mined');
83
85
  }
84
86
 
85
87
  public iteratePendingTxs(): AsyncIterableIterator<Tx> {
@@ -3,7 +3,7 @@ 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
9
  public getCurrentBaseFees(): Promise<GasFees> {
@@ -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
  }
@@ -2,8 +2,9 @@ import { type AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
2
2
  import { TestCircuitVerifier } from '@aztec/bb-prover/test';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
5
- import { SyncDataProvider } from '@aztec/pxe/server';
6
- import { type L2Block, PublishedL2Block } from '@aztec/stdlib/block';
5
+ import { AnchorBlockStore } from '@aztec/pxe/server';
6
+ import { L2Block } from '@aztec/stdlib/block';
7
+ import { L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
7
8
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
8
9
  import { getPackageVersion } from '@aztec/stdlib/update-checker';
9
10
 
@@ -21,13 +22,13 @@ export class TXEStateMachine {
21
22
  public node: AztecNode,
22
23
  public synchronizer: TXESynchronizer,
23
24
  public archiver: TXEArchiver,
24
- public syncDataProvider: SyncDataProvider,
25
+ public anchorBlockStore: AnchorBlockStore,
25
26
  ) {}
26
27
 
27
28
  public static async create(db: AztecAsyncKVStore) {
28
29
  const archiver = new TXEArchiver(db);
29
30
  const synchronizer = await TXESynchronizer.create();
30
- const syncDataProvider = new SyncDataProvider(db);
31
+ const anchorBlockStore = new AnchorBlockStore(db);
31
32
 
32
33
  const aztecNodeConfig = {} as AztecNodeConfig;
33
34
 
@@ -54,24 +55,24 @@ export class TXEStateMachine {
54
55
  log,
55
56
  );
56
57
 
57
- return new this(node, synchronizer, archiver, syncDataProvider);
58
+ return new this(node, synchronizer, archiver, anchorBlockStore);
58
59
  }
59
60
 
60
61
  public async handleL2Block(block: L2Block) {
62
+ const checkpoint = block.toCheckpoint();
63
+ const publishedCheckpoint = new PublishedCheckpoint(
64
+ checkpoint,
65
+ new L1PublishedData(
66
+ BigInt(block.header.globalVariables.blockNumber),
67
+ block.header.globalVariables.timestamp,
68
+ block.header.globalVariables.blockNumber.toString(),
69
+ ),
70
+ [],
71
+ );
61
72
  await Promise.all([
62
73
  this.synchronizer.handleL2Block(block.toL2Block()),
63
- this.archiver.addBlocks([
64
- PublishedL2Block.fromFields({
65
- block,
66
- l1: {
67
- blockHash: block.header.globalVariables.blockNumber.toString(),
68
- blockNumber: BigInt(block.header.globalVariables.blockNumber),
69
- timestamp: block.header.globalVariables.timestamp,
70
- },
71
- attestations: [],
72
- }),
73
- ]),
74
- this.syncDataProvider.setHeader(block.getBlockHeader()),
74
+ this.archiver.addCheckpoints([publishedCheckpoint], undefined),
75
+ this.anchorBlockStore.setHeader(block.getBlockHeader()),
75
76
  ]);
76
77
  }
77
78
  }