@aztec/txe 0.0.1-commit.f295ac2 → 0.0.1-commit.f504929

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 (55) hide show
  1. package/dest/index.d.ts +1 -1
  2. package/dest/index.d.ts.map +1 -1
  3. package/dest/index.js +88 -54
  4. package/dest/oracle/interfaces.d.ts +29 -28
  5. package/dest/oracle/interfaces.d.ts.map +1 -1
  6. package/dest/oracle/txe_oracle_public_context.d.ts +15 -15
  7. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  8. package/dest/oracle/txe_oracle_public_context.js +16 -16
  9. package/dest/oracle/txe_oracle_top_level_context.d.ts +22 -23
  10. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_top_level_context.js +125 -54
  12. package/dest/rpc_translator.d.ts +87 -81
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +287 -170
  15. package/dest/state_machine/archiver.d.ts +2 -2
  16. package/dest/state_machine/archiver.d.ts.map +1 -1
  17. package/dest/state_machine/archiver.js +7 -6
  18. package/dest/state_machine/dummy_p2p_client.d.ts +16 -12
  19. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  20. package/dest/state_machine/dummy_p2p_client.js +28 -16
  21. package/dest/state_machine/index.d.ts +7 -7
  22. package/dest/state_machine/index.d.ts.map +1 -1
  23. package/dest/state_machine/index.js +31 -17
  24. package/dest/state_machine/mock_epoch_cache.d.ts +8 -6
  25. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  26. package/dest/state_machine/mock_epoch_cache.js +9 -6
  27. package/dest/state_machine/synchronizer.d.ts +3 -3
  28. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  29. package/dest/txe_session.d.ts +9 -6
  30. package/dest/txe_session.d.ts.map +1 -1
  31. package/dest/txe_session.js +86 -26
  32. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  33. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  34. package/dest/util/txe_public_contract_data_source.js +5 -22
  35. package/dest/utils/block_creation.d.ts +5 -5
  36. package/dest/utils/block_creation.d.ts.map +1 -1
  37. package/dest/utils/block_creation.js +7 -5
  38. package/package.json +15 -15
  39. package/src/index.ts +89 -52
  40. package/src/oracle/interfaces.ts +32 -31
  41. package/src/oracle/txe_oracle_public_context.ts +18 -20
  42. package/src/oracle/txe_oracle_top_level_context.ts +155 -102
  43. package/src/rpc_translator.ts +303 -177
  44. package/src/state_machine/archiver.ts +6 -8
  45. package/src/state_machine/dummy_p2p_client.ts +40 -22
  46. package/src/state_machine/index.ts +49 -19
  47. package/src/state_machine/mock_epoch_cache.ts +10 -11
  48. package/src/state_machine/synchronizer.ts +2 -2
  49. package/src/txe_session.ts +101 -85
  50. package/src/util/txe_public_contract_data_source.ts +10 -36
  51. package/src/utils/block_creation.ts +8 -6
  52. package/dest/util/txe_contract_store.d.ts +0 -12
  53. package/dest/util/txe_contract_store.d.ts.map +0 -1
  54. package/dest/util/txe_contract_store.js +0 -22
  55. package/src/util/txe_contract_store.ts +0 -36
@@ -17,18 +17,14 @@ export class TXEArchiver extends ArchiverDataSourceBase {
17
17
  private readonly updater = new ArchiverDataStoreUpdater(this.store);
18
18
 
19
19
  constructor(db: AztecAsyncKVStore) {
20
- const store = new KVArchiverDataStore(db, 9999);
20
+ const store = new KVArchiverDataStore(db, 9999, { epochDuration: 32 });
21
21
  super(store);
22
22
  }
23
23
 
24
- // TXE-specific method for adding checkpoints
25
- public async addCheckpoints(checkpoints: PublishedCheckpoint[], result?: ValidateCheckpointResult): Promise<boolean> {
26
- await this.updater.setNewCheckpointData(checkpoints, result);
27
- return true;
24
+ public async addCheckpoints(checkpoints: PublishedCheckpoint[], result?: ValidateCheckpointResult): Promise<void> {
25
+ await this.updater.addCheckpoints(checkpoints, result);
28
26
  }
29
27
 
30
- // Abstract method implementations
31
-
32
28
  public getRollupAddress(): Promise<EthAddress> {
33
29
  throw new Error('TXE Archiver does not implement "getRollupAddress"');
34
30
  }
@@ -63,7 +59,9 @@ export class TXEArchiver extends ArchiverDataSourceBase {
63
59
  if (!checkpointedBlock) {
64
60
  throw new Error(`L2Tips requested from TXE Archiver but no checkpointed block found for block number ${number}`);
65
61
  }
66
- 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);
67
65
  if (checkpoint.length === 0) {
68
66
  throw new Error(`L2Tips requested from TXE Archiver but no checkpoint found for block number ${number}`);
69
67
  }
@@ -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 { L2BlockNew } from '@aztec/stdlib/block';
6
+ import { type AnchorBlockStore, type ContractStore, ContractSyncService, type NoteStore } from '@aztec/pxe/server';
7
+ import { L2Block } from '@aztec/stdlib/block';
7
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,18 +61,39 @@ 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
- public async handleL2Block(block: L2BlockNew) {
62
- // Create a checkpoint from the block - L2BlockNew doesn't have toCheckpoint() method
63
- // We need to construct the Checkpoint manually
64
- const checkpoint = await Checkpoint.random(block.checkpointNumber, {
65
- numBlocks: 1,
66
- startBlockNumber: Number(block.number),
67
- });
68
- // Replace the random block with our actual block
69
- checkpoint.blocks = [block];
74
+ public async handleL2Block(block: L2Block) {
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
+ );
70
97
 
71
98
  const publishedCheckpoint = new PublishedCheckpoint(
72
99
  checkpoint,
@@ -77,10 +104,13 @@ export class TXEStateMachine {
77
104
  ),
78
105
  [],
79
106
  );
107
+ // Wipe contract sync cache when anchor block changes (mirrors BlockSynchronizer behavior)
108
+ this.contractSyncService.wipe();
109
+
80
110
  await Promise.all([
81
- this.synchronizer.handleL2Block(block), // L2BlockNew doesn't need toL2Block() conversion
111
+ this.synchronizer.handleL2Block(block),
82
112
  this.archiver.addCheckpoints([publishedCheckpoint], undefined),
83
- this.anchorBlockStore.setHeader(block.header), // Use .header property directly
113
+ this.anchorBlockStore.setHeader(block.header),
84
114
  ]);
85
115
  }
86
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.
@@ -16,11 +17,12 @@ export class MockEpochCache implements EpochCacheInterface {
16
17
  });
17
18
  }
18
19
 
19
- getEpochAndSlotNow(): EpochAndSlot {
20
+ getEpochAndSlotNow(): EpochAndSlot & { nowMs: bigint } {
20
21
  return {
21
22
  epoch: EpochNumber.ZERO,
22
23
  slot: SlotNumber(0),
23
24
  ts: 0n,
25
+ nowMs: 0n,
24
26
  };
25
27
  }
26
28
 
@@ -41,18 +43,11 @@ export class MockEpochCache implements EpochCacheInterface {
41
43
  return 0n;
42
44
  }
43
45
 
44
- getProposerAttesterAddressInCurrentOrNextSlot(): Promise<{
45
- currentProposer: EthAddress | undefined;
46
- nextProposer: EthAddress | undefined;
47
- currentSlot: SlotNumber;
48
- nextSlot: SlotNumber;
49
- }> {
50
- return Promise.resolve({
51
- currentProposer: undefined,
52
- nextProposer: undefined,
46
+ getCurrentAndNextSlot(): { currentSlot: SlotNumber; nextSlot: SlotNumber } {
47
+ return {
53
48
  currentSlot: SlotNumber(0),
54
49
  nextSlot: SlotNumber(0),
55
- });
50
+ };
56
51
  }
57
52
 
58
53
  getProposerAttesterAddressInSlot(_slot: SlotNumber): Promise<EthAddress | undefined> {
@@ -70,4 +65,8 @@ export class MockEpochCache implements EpochCacheInterface {
70
65
  filterInCommittee(_slot: SlotTag, _validators: EthAddress[]): Promise<EthAddress[]> {
71
66
  return Promise.resolve([]);
72
67
  }
68
+
69
+ getL1Constants(): L1RollupConstants {
70
+ return EmptyL1RollupConstants;
71
+ }
73
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),