@aztec/txe 0.0.1-commit.7d4e6cd → 0.0.1-commit.7ffbba4

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 (64) hide show
  1. package/dest/constants.d.ts +1 -2
  2. package/dest/constants.d.ts.map +1 -1
  3. package/dest/constants.js +0 -1
  4. package/dest/index.d.ts +1 -1
  5. package/dest/index.d.ts.map +1 -1
  6. package/dest/index.js +88 -54
  7. package/dest/oracle/interfaces.d.ts +29 -28
  8. package/dest/oracle/interfaces.d.ts.map +1 -1
  9. package/dest/oracle/txe_oracle_public_context.d.ts +13 -13
  10. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_public_context.js +16 -16
  12. package/dest/oracle/txe_oracle_top_level_context.d.ts +22 -22
  13. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  14. package/dest/oracle/txe_oracle_top_level_context.js +138 -61
  15. package/dest/rpc_translator.d.ts +86 -81
  16. package/dest/rpc_translator.d.ts.map +1 -1
  17. package/dest/rpc_translator.js +291 -175
  18. package/dest/state_machine/archiver.d.ts +20 -69
  19. package/dest/state_machine/archiver.d.ts.map +1 -1
  20. package/dest/state_machine/archiver.js +36 -178
  21. package/dest/state_machine/dummy_p2p_client.d.ts +16 -12
  22. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  23. package/dest/state_machine/dummy_p2p_client.js +28 -16
  24. package/dest/state_machine/index.d.ts +5 -5
  25. package/dest/state_machine/index.d.ts.map +1 -1
  26. package/dest/state_machine/index.js +35 -12
  27. package/dest/state_machine/mock_epoch_cache.d.ts +8 -6
  28. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  29. package/dest/state_machine/mock_epoch_cache.js +11 -7
  30. package/dest/state_machine/synchronizer.d.ts +3 -3
  31. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  32. package/dest/txe_session.d.ts +11 -6
  33. package/dest/txe_session.d.ts.map +1 -1
  34. package/dest/txe_session.js +101 -26
  35. package/dest/util/encoding.d.ts +17 -17
  36. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  37. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  38. package/dest/util/txe_public_contract_data_source.js +5 -22
  39. package/dest/utils/block_creation.d.ts +4 -4
  40. package/dest/utils/block_creation.d.ts.map +1 -1
  41. package/dest/utils/block_creation.js +18 -4
  42. package/dest/utils/tx_effect_creation.d.ts +2 -3
  43. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  44. package/dest/utils/tx_effect_creation.js +3 -6
  45. package/package.json +16 -16
  46. package/src/constants.ts +0 -1
  47. package/src/index.ts +89 -52
  48. package/src/oracle/interfaces.ts +32 -31
  49. package/src/oracle/txe_oracle_public_context.ts +16 -18
  50. package/src/oracle/txe_oracle_top_level_context.ts +173 -111
  51. package/src/rpc_translator.ts +313 -198
  52. package/src/state_machine/archiver.ts +37 -234
  53. package/src/state_machine/dummy_p2p_client.ts +40 -22
  54. package/src/state_machine/index.ts +49 -11
  55. package/src/state_machine/mock_epoch_cache.ts +11 -11
  56. package/src/state_machine/synchronizer.ts +2 -2
  57. package/src/txe_session.ts +115 -87
  58. package/src/util/txe_public_contract_data_source.ts +10 -36
  59. package/src/utils/block_creation.ts +19 -16
  60. package/src/utils/tx_effect_creation.ts +3 -11
  61. package/dest/util/txe_contract_store.d.ts +0 -12
  62. package/dest/util/txe_contract_store.d.ts.map +0 -1
  63. package/dest/util/txe_contract_store.js +0 -22
  64. package/src/util/txe_contract_store.ts +0 -36
@@ -1,216 +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
- 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
- // We are extending the ArchiverDataStoreHelper here because it provides most of the endpoints needed by the
28
- // node for reading from and writing to state, without needing any of the extra overhead that the Archiver itself
29
- // requires (i.e. an L1 client)
30
- export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
31
- constructor(db: AztecAsyncKVStore) {
32
- super(new KVArchiverDataStore(db, 9999));
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
- if (proven === true) {
102
- const provenBlockNumber = await this.store.getProvenBlockNumber();
103
- return blocks.filter(b => b.number <= provenBlockNumber);
104
- }
105
- return blocks;
106
- }
107
-
108
- private async retrievePublishedBlocks(
109
- from: BlockNumber,
110
- limit: number,
111
- proven?: boolean,
112
- ): Promise<PublishedL2Block[]> {
113
- const checkpoints = await this.store.getRangeOfCheckpoints(CheckpointNumber(from), limit);
114
- const provenCheckpointNumber = await this.store.getProvenCheckpointNumber();
115
- const blocks = (
116
- await Promise.all(checkpoints.map(ch => this.store.getBlocksForCheckpoint(ch.checkpointNumber)))
117
- ).filter(isDefined);
118
-
119
- const olbBlocks: PublishedL2Block[] = [];
120
- for (let i = 0; i < checkpoints.length; i++) {
121
- const blockForCheckpoint = blocks[i][0];
122
- const checkpoint = checkpoints[i];
123
- if (proven === true && checkpoint.checkpointNumber > provenCheckpointNumber) {
124
- continue;
125
- }
126
- const oldCheckpoint = new Checkpoint(
127
- blockForCheckpoint.archive,
128
- checkpoint.header,
129
- [blockForCheckpoint],
130
- checkpoint.checkpointNumber,
131
- );
132
- const oldBlock = L2Block.fromCheckpoint(oldCheckpoint);
133
- const publishedBlock = new PublishedL2Block(
134
- oldBlock,
135
- checkpoint.l1,
136
- checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
137
- );
138
- olbBlocks.push(publishedBlock);
139
- }
140
- return olbBlocks;
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 getL2SlotNumber(): Promise<SlotNumber | undefined> {
193
- 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);
194
26
  }
195
27
 
196
- public getL2EpochNumber(): Promise<EpochNumber> {
197
- throw new Error('TXE Archiver does not implement "getL2EpochNumber"');
28
+ public getRollupAddress(): Promise<EthAddress> {
29
+ throw new Error('TXE Archiver does not implement "getRollupAddress"');
198
30
  }
199
31
 
200
- public getCheckpointsForEpoch(_epochNumber: EpochNumber): Promise<Checkpoint[]> {
201
- throw new Error('TXE Archiver does not implement "getCheckpointsForEpoch"');
32
+ public getRegistryAddress(): Promise<EthAddress> {
33
+ throw new Error('TXE Archiver does not implement "getRegistryAddress"');
202
34
  }
203
35
 
204
- public getBlocksForEpoch(_epochNumber: EpochNumber): Promise<L2Block[]> {
205
- throw new Error('TXE Archiver does not implement "getBlocksForEpoch"');
36
+ public getL1Constants(): Promise<L1RollupConstants> {
37
+ throw new Error('TXE Archiver does not implement "getL1Constants"');
206
38
  }
207
39
 
208
- public getBlockHeadersForEpoch(_epochNumber: EpochNumber): Promise<BlockHeader[]> {
209
- 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) });
210
42
  }
211
43
 
212
- public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
213
- 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"');
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
- const checkpoint = await this.store.getRangeOfCheckpoints(CheckpointNumber(number), 1);
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 getL1Constants(): Promise<L1RollupConstants> {
249
- throw new Error('TXE Archiver does not implement "getL2Constants"');
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 override getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
281
- return Promise.resolve({ valid: true });
86
+ public getL2EpochNumber(): Promise<EpochNumber | undefined> {
87
+ throw new Error('TXE Archiver does not implement "getL2EpochNumber"');
282
88
  }
283
89
 
284
- getPublishedBlockByHash(_blockHash: Fr): Promise<PublishedL2Block | undefined> {
285
- throw new Error('Method not implemented.');
286
- }
287
- getPublishedBlockByArchive(_archive: Fr): Promise<PublishedL2Block | undefined> {
288
- throw new Error('Method not implemented.');
90
+ public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
91
+ throw new Error('TXE Archiver does not implement "isEpochComplete"');
289
92
  }
290
93
 
291
- getCheckpointedBlocks(_from: BlockNumber, _limit: number, _proven?: boolean): Promise<never[]> {
292
- throw new Error('TXE Archiver does not implement "getCheckpointedBlocks"');
94
+ public syncImmediate(): Promise<void> {
95
+ throw new Error('TXE Archiver does not implement "syncImmediate"');
293
96
  }
294
97
  }
@@ -6,6 +6,8 @@ import type {
6
6
  P2PBlockReceivedCallback,
7
7
  P2PCheckpointReceivedCallback,
8
8
  P2PConfig,
9
+ P2PDuplicateAttestationCallback,
10
+ P2PDuplicateProposalCallback,
9
11
  P2PSyncState,
10
12
  PeerId,
11
13
  ReqRespSubProtocol,
@@ -14,12 +16,12 @@ import type {
14
16
  StatusMessage,
15
17
  } from '@aztec/p2p';
16
18
  import type { EthAddress, L2BlockStreamEvent, L2Tips } from '@aztec/stdlib/block';
17
- import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
18
- import type { BlockProposal, CheckpointAttestation, CheckpointProposal } from '@aztec/stdlib/p2p';
19
- import type { Tx, TxHash } from '@aztec/stdlib/tx';
19
+ import type { ITxProvider, PeerInfo } from '@aztec/stdlib/interfaces/server';
20
+ import type { BlockProposal, CheckpointAttestation, CheckpointProposal, TopicType } from '@aztec/stdlib/p2p';
21
+ import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
20
22
 
21
23
  export class DummyP2P implements P2P {
22
- public validate(_txs: Tx[]): Promise<void> {
24
+ public validateTxsReceivedInBlockProposal(_txs: Tx[]): Promise<void> {
23
25
  return Promise.resolve();
24
26
  }
25
27
 
@@ -39,6 +41,10 @@ export class DummyP2P implements P2P {
39
41
  throw new Error('DummyP2P does not implement "getPeers"');
40
42
  }
41
43
 
44
+ public getGossipMeshPeerCount(_topicType: TopicType): Promise<number> {
45
+ return Promise.resolve(0);
46
+ }
47
+
42
48
  public broadcastProposal(_proposal: BlockProposal): Promise<void> {
43
49
  throw new Error('DummyP2P does not implement "broadcastProposal"');
44
50
  }
@@ -71,8 +77,8 @@ export class DummyP2P implements P2P {
71
77
  throw new Error('DummyP2P does not implement "sendTx"');
72
78
  }
73
79
 
74
- public deleteTxs(_txHashes: TxHash[]): Promise<void> {
75
- throw new Error('DummyP2P does not implement "deleteTxs"');
80
+ public handleFailedExecution(_txHashes: TxHash[]): Promise<void> {
81
+ throw new Error('DummyP2P does not implement "handleFailedExecution"');
76
82
  }
77
83
 
78
84
  public getTxByHashFromPool(_txHash: TxHash): Promise<Tx | undefined> {
@@ -97,6 +103,10 @@ export class DummyP2P implements P2P {
97
103
  throw new Error('DummyP2P does not implement "iteratePendingTxs"');
98
104
  }
99
105
 
106
+ public iterateEligiblePendingTxs(): AsyncIterableIterator<Tx> {
107
+ throw new Error('DummyP2P does not implement "iterateEligiblePendingTxs"');
108
+ }
109
+
100
110
  public getPendingTxCount(): Promise<number> {
101
111
  throw new Error('DummyP2P does not implement "getPendingTxCount"');
102
112
  }
@@ -125,6 +135,10 @@ export class DummyP2P implements P2P {
125
135
  throw new Error('DummyP2P does not implement "isP2PClient"');
126
136
  }
127
137
 
138
+ public getTxProvider(): ITxProvider {
139
+ throw new Error('DummyP2P does not implement "getTxProvider"');
140
+ }
141
+
128
142
  public getTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
129
143
  throw new Error('DummyP2P does not implement "getTxsByHash"');
130
144
  }
@@ -133,8 +147,8 @@ export class DummyP2P implements P2P {
133
147
  throw new Error('DummyP2P does not implement "getCheckpointAttestationsForSlot"');
134
148
  }
135
149
 
136
- public addCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
137
- throw new Error('DummyP2P does not implement "addCheckpointAttestations"');
150
+ public addOwnCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
151
+ throw new Error('DummyP2P does not implement "addOwnCheckpointAttestations"');
138
152
  }
139
153
 
140
154
  public getL2BlockHash(_number: number): Promise<string | undefined> {
@@ -157,14 +171,6 @@ export class DummyP2P implements P2P {
157
171
  throw new Error('DummyP2P does not implement "sync"');
158
172
  }
159
173
 
160
- public requestTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
161
- throw new Error('DummyP2P does not implement "requestTxsByHash"');
162
- }
163
-
164
- public getTxs(_filter: 'all' | 'pending' | 'mined'): Promise<Tx[]> {
165
- throw new Error('DummyP2P does not implement "getTxs"');
166
- }
167
-
168
174
  public getTxsByHashFromPool(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
169
175
  throw new Error('DummyP2P does not implement "getTxsByHashFromPool"');
170
176
  }
@@ -173,10 +179,6 @@ export class DummyP2P implements P2P {
173
179
  throw new Error('DummyP2P does not implement "hasTxsInPool"');
174
180
  }
175
181
 
176
- public addTxsToPool(_txs: Tx[]): Promise<number> {
177
- throw new Error('DummyP2P does not implement "addTxs"');
178
- }
179
-
180
182
  public getSyncedLatestBlockNum(): Promise<number> {
181
183
  throw new Error('DummyP2P does not implement "getSyncedLatestBlockNum"');
182
184
  }
@@ -189,8 +191,12 @@ export class DummyP2P implements P2P {
189
191
  throw new Error('DummyP2P does not implement "getSyncedLatestSlot"');
190
192
  }
191
193
 
192
- markTxsAsNonEvictable(_: TxHash[]): Promise<void> {
193
- throw new Error('DummyP2P does not implement "markTxsAsNonEvictable".');
194
+ protectTxs(_txHashes: TxHash[], _blockHeader: BlockHeader): Promise<TxHash[]> {
195
+ throw new Error('DummyP2P does not implement "protectTxs".');
196
+ }
197
+
198
+ prepareForSlot(_slotNumber: SlotNumber): Promise<void> {
199
+ return Promise.resolve();
194
200
  }
195
201
 
196
202
  addReqRespSubProtocol(
@@ -206,4 +212,16 @@ export class DummyP2P implements P2P {
206
212
 
207
213
  //This is no-op
208
214
  public registerThisValidatorAddresses(_address: EthAddress[]): void {}
215
+
216
+ public registerDuplicateProposalCallback(_callback: P2PDuplicateProposalCallback): void {
217
+ throw new Error('DummyP2P does not implement "registerDuplicateProposalCallback"');
218
+ }
219
+
220
+ public registerDuplicateAttestationCallback(_callback: P2PDuplicateAttestationCallback): void {
221
+ throw new Error('DummyP2P does not implement "registerDuplicateAttestationCallback"');
222
+ }
223
+
224
+ public hasBlockProposalsForSlot(_slot: SlotNumber): Promise<boolean> {
225
+ throw new Error('DummyP2P does not implement "hasBlockProposalsForSlot"');
226
+ }
209
227
  }
@@ -1,11 +1,13 @@
1
1
  import { type AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
2
2
  import { TestCircuitVerifier } from '@aztec/bb-prover/test';
3
+ import { CheckpointNumber } from '@aztec/foundation/branded-types';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
5
  import { createLogger } from '@aztec/foundation/log';
4
- import type { AztecAsyncKVStore } from '@aztec/kv-store';
5
- import { AnchorBlockStore } from '@aztec/pxe/server';
6
+ import { type AnchorBlockStore, type ContractStore, ContractSyncService, type NoteStore } from '@aztec/pxe/server';
6
7
  import { L2Block } from '@aztec/stdlib/block';
7
- import { L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
8
+ import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
8
9
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
10
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
9
11
  import { getPackageVersion } from '@aztec/stdlib/update-checker';
10
12
 
11
13
  import { TXEArchiver } from './archiver.js';
@@ -23,13 +25,16 @@ export class TXEStateMachine {
23
25
  public synchronizer: TXESynchronizer,
24
26
  public archiver: TXEArchiver,
25
27
  public anchorBlockStore: AnchorBlockStore,
28
+ public contractSyncService: ContractSyncService,
26
29
  ) {}
27
30
 
28
- public static async create(db: AztecAsyncKVStore) {
29
- const archiver = new TXEArchiver(db);
31
+ public static async create(
32
+ archiver: TXEArchiver,
33
+ anchorBlockStore: AnchorBlockStore,
34
+ contractStore: ContractStore,
35
+ noteStore: NoteStore,
36
+ ) {
30
37
  const synchronizer = await TXESynchronizer.create();
31
- const anchorBlockStore = new AnchorBlockStore(db);
32
-
33
38
  const aztecNodeConfig = {} as AztecNodeConfig;
34
39
 
35
40
  const log = createLogger('txe_node');
@@ -45,6 +50,7 @@ export class TXEStateMachine {
45
50
  undefined,
46
51
  undefined,
47
52
  undefined,
53
+ undefined,
48
54
  VERSION,
49
55
  CHAIN_ID,
50
56
  new TXEGlobalVariablesBuilder(),
@@ -55,11 +61,40 @@ export class TXEStateMachine {
55
61
  log,
56
62
  );
57
63
 
58
- return new this(node, synchronizer, archiver, anchorBlockStore);
64
+ const contractSyncService = new ContractSyncService(
65
+ node,
66
+ contractStore,
67
+ noteStore,
68
+ createLogger('txe:contract_sync'),
69
+ );
70
+
71
+ return new this(node, synchronizer, archiver, anchorBlockStore, contractSyncService);
59
72
  }
60
73
 
61
74
  public async handleL2Block(block: L2Block) {
62
- const checkpoint = block.toCheckpoint();
75
+ // Create a checkpoint from the block manually.
76
+ // TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
77
+ // This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
78
+ const checkpointNumber = CheckpointNumber.fromBlockNumber(block.number);
79
+ const checkpoint = new Checkpoint(
80
+ block.archive,
81
+ CheckpointHeader.from({
82
+ lastArchiveRoot: block.header.lastArchive.root,
83
+ inHash: Fr.ZERO,
84
+ blobsHash: Fr.ZERO,
85
+ blockHeadersHash: Fr.ZERO,
86
+ epochOutHash: Fr.ZERO,
87
+ slotNumber: block.header.globalVariables.slotNumber,
88
+ timestamp: block.header.globalVariables.timestamp,
89
+ coinbase: block.header.globalVariables.coinbase,
90
+ feeRecipient: block.header.globalVariables.feeRecipient,
91
+ gasFees: block.header.globalVariables.gasFees,
92
+ totalManaUsed: block.header.totalManaUsed,
93
+ }),
94
+ [block],
95
+ checkpointNumber,
96
+ );
97
+
63
98
  const publishedCheckpoint = new PublishedCheckpoint(
64
99
  checkpoint,
65
100
  new L1PublishedData(
@@ -69,10 +104,13 @@ export class TXEStateMachine {
69
104
  ),
70
105
  [],
71
106
  );
107
+ // Wipe contract sync cache when anchor block changes (mirrors BlockSynchronizer behavior)
108
+ this.contractSyncService.wipe();
109
+
72
110
  await Promise.all([
73
- this.synchronizer.handleL2Block(block.toL2Block()),
111
+ this.synchronizer.handleL2Block(block),
74
112
  this.archiver.addCheckpoints([publishedCheckpoint], undefined),
75
- this.anchorBlockStore.setHeader(block.getBlockHeader()),
113
+ this.anchorBlockStore.setHeader(block.header),
76
114
  ]);
77
115
  }
78
116
  }
@@ -1,6 +1,7 @@
1
1
  import type { EpochAndSlot, EpochCacheInterface, EpochCommitteeInfo, SlotTag } from '@aztec/epoch-cache';
2
2
  import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
3
3
  import { EthAddress } from '@aztec/foundation/eth-address';
4
+ import { EmptyL1RollupConstants, type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
4
5
 
5
6
  /**
6
7
  * Mock implementation of the EpochCacheInterface used to satisfy dependencies of AztecNodeService.
@@ -12,14 +13,16 @@ export class MockEpochCache implements EpochCacheInterface {
12
13
  committee: undefined,
13
14
  seed: 0n,
14
15
  epoch: EpochNumber.ZERO,
16
+ isEscapeHatchOpen: false,
15
17
  });
16
18
  }
17
19
 
18
- getEpochAndSlotNow(): EpochAndSlot {
20
+ getEpochAndSlotNow(): EpochAndSlot & { nowMs: bigint } {
19
21
  return {
20
22
  epoch: EpochNumber.ZERO,
21
23
  slot: SlotNumber(0),
22
24
  ts: 0n,
25
+ nowMs: 0n,
23
26
  };
24
27
  }
25
28
 
@@ -40,18 +43,11 @@ export class MockEpochCache implements EpochCacheInterface {
40
43
  return 0n;
41
44
  }
42
45
 
43
- getProposerAttesterAddressInCurrentOrNextSlot(): Promise<{
44
- currentProposer: EthAddress | undefined;
45
- nextProposer: EthAddress | undefined;
46
- currentSlot: SlotNumber;
47
- nextSlot: SlotNumber;
48
- }> {
49
- return Promise.resolve({
50
- currentProposer: undefined,
51
- nextProposer: undefined,
46
+ getCurrentAndNextSlot(): { currentSlot: SlotNumber; nextSlot: SlotNumber } {
47
+ return {
52
48
  currentSlot: SlotNumber(0),
53
49
  nextSlot: SlotNumber(0),
54
- });
50
+ };
55
51
  }
56
52
 
57
53
  getProposerAttesterAddressInSlot(_slot: SlotNumber): Promise<EthAddress | undefined> {
@@ -69,4 +65,8 @@ export class MockEpochCache implements EpochCacheInterface {
69
65
  filterInCommittee(_slot: SlotTag, _validators: EthAddress[]): Promise<EthAddress[]> {
70
66
  return Promise.resolve([]);
71
67
  }
68
+
69
+ getL1Constants(): L1RollupConstants {
70
+ return EmptyL1RollupConstants;
71
+ }
72
72
  }
@@ -1,7 +1,7 @@
1
1
  import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
2
  import { BlockNumber } from '@aztec/foundation/branded-types';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
- import type { L2BlockNew } from '@aztec/stdlib/block';
4
+ import type { L2Block } from '@aztec/stdlib/block';
5
5
  import type {
6
6
  MerkleTreeReadOperations,
7
7
  MerkleTreeWriteOperations,
@@ -23,7 +23,7 @@ export class TXESynchronizer implements WorldStateSynchronizer {
23
23
  return new this(nativeWorldStateService);
24
24
  }
25
25
 
26
- public async handleL2Block(block: L2BlockNew) {
26
+ public async handleL2Block(block: L2Block) {
27
27
  await this.nativeWorldStateService.handleL2BlockAndMessages(
28
28
  block,
29
29
  Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero),