@aztec/txe 0.0.1-commit.b655e406 → 0.0.1-commit.b9865e97

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 (167) hide show
  1. package/dest/ContractClassRegistry-PII7Q556.js +3 -0
  2. package/dest/ContractClassRegistry-PII7Q556.js.map +7 -0
  3. package/dest/ContractInstanceRegistry-3MHLGFNZ.js +3 -0
  4. package/dest/ContractInstanceRegistry-3MHLGFNZ.js.map +7 -0
  5. package/dest/FeeJuice-TQV5AQK7.js +3 -0
  6. package/dest/FeeJuice-TQV5AQK7.js.map +7 -0
  7. package/dest/MultiCallEntrypoint-SBJUIJY7.js +3 -0
  8. package/dest/MultiCallEntrypoint-SBJUIJY7.js.map +7 -0
  9. package/dest/SchnorrAccount-MQXPIZ44.js +3 -0
  10. package/dest/SchnorrAccount-MQXPIZ44.js.map +7 -0
  11. package/dest/bin/check_txe_oracle_version.d.ts +2 -0
  12. package/dest/bin/check_txe_oracle_version.d.ts.map +1 -0
  13. package/dest/bin/check_txe_oracle_version.js +61 -0
  14. package/dest/bin/index.d.ts +1 -1
  15. package/dest/bin/index.js +3 -30
  16. package/dest/bin/index.js.map +7 -0
  17. package/dest/bin/oracle_test_server.d.ts +3 -0
  18. package/dest/bin/oracle_test_server.d.ts.map +1 -0
  19. package/dest/bin/oracle_test_server.js +41 -0
  20. package/dest/chunk-BJVAAXNA.js +3 -0
  21. package/dest/chunk-BJVAAXNA.js.map +7 -0
  22. package/dest/chunk-CUSVOJA4.js +304 -0
  23. package/dest/chunk-CUSVOJA4.js.map +7 -0
  24. package/dest/chunk-OYLIPWI6.js +260 -0
  25. package/dest/chunk-OYLIPWI6.js.map +7 -0
  26. package/dest/constants.d.ts +7 -0
  27. package/dest/constants.d.ts.map +1 -0
  28. package/dest/constants.js +10 -0
  29. package/dest/dispatcher_pool.d.ts +67 -0
  30. package/dest/dispatcher_pool.d.ts.map +1 -0
  31. package/dest/dispatcher_pool.js +284 -0
  32. package/dest/index.d.ts +185 -7
  33. package/dest/index.d.ts.map +1 -1
  34. package/dest/index.js +73 -158
  35. package/dest/metafile.json +36863 -0
  36. package/dest/msgpackr_fr_extension.d.ts +2 -0
  37. package/dest/msgpackr_fr_extension.d.ts.map +1 -0
  38. package/dest/msgpackr_fr_extension.js +21 -0
  39. package/dest/oracle/interfaces.d.ts +60 -31
  40. package/dest/oracle/interfaces.d.ts.map +1 -1
  41. package/dest/oracle/test-resolver/fixtures.d.ts +43 -0
  42. package/dest/oracle/test-resolver/fixtures.d.ts.map +1 -0
  43. package/dest/oracle/test-resolver/fixtures.js +39 -0
  44. package/dest/oracle/test-resolver/index.d.ts +9 -0
  45. package/dest/oracle/test-resolver/index.d.ts.map +1 -0
  46. package/dest/oracle/test-resolver/index.js +33 -0
  47. package/dest/oracle/test-resolver/resolver.d.ts +34 -0
  48. package/dest/oracle/test-resolver/resolver.d.ts.map +1 -0
  49. package/dest/oracle/test-resolver/resolver.js +114 -0
  50. package/dest/oracle/txe_oracle_public_context.d.ts +41 -17
  51. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  52. package/dest/oracle/txe_oracle_public_context.js +63 -23
  53. package/dest/oracle/txe_oracle_registry.d.ts +147 -0
  54. package/dest/oracle/txe_oracle_registry.d.ts.map +1 -0
  55. package/dest/oracle/txe_oracle_registry.js +562 -0
  56. package/dest/oracle/txe_oracle_top_level_context.d.ts +57 -28
  57. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  58. package/dest/oracle/txe_oracle_top_level_context.js +341 -130
  59. package/dest/oracle/txe_oracle_version.d.ts +17 -0
  60. package/dest/oracle/txe_oracle_version.d.ts.map +1 -0
  61. package/dest/oracle/txe_oracle_version.js +14 -0
  62. package/dest/oracle/txe_private_execution_oracle.d.ts +17 -0
  63. package/dest/oracle/txe_private_execution_oracle.d.ts.map +1 -0
  64. package/dest/oracle/txe_private_execution_oracle.js +15 -0
  65. package/dest/rpc_server.d.ts +14 -0
  66. package/dest/rpc_server.d.ts.map +1 -0
  67. package/dest/rpc_server.js +78 -0
  68. package/dest/rpc_translator.d.ts +96 -213
  69. package/dest/rpc_translator.d.ts.map +1 -1
  70. package/dest/rpc_translator.js +815 -550
  71. package/dest/server.bundle.js +3 -0
  72. package/dest/server.bundle.js.map +7 -0
  73. package/dest/state_machine/archiver.d.ts +23 -52
  74. package/dest/state_machine/archiver.d.ts.map +1 -1
  75. package/dest/state_machine/archiver.js +77 -99
  76. package/dest/state_machine/dummy_p2p_client.d.ts +28 -15
  77. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  78. package/dest/state_machine/dummy_p2p_client.js +54 -22
  79. package/dest/state_machine/global_variable_builder.d.ts +11 -4
  80. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  81. package/dest/state_machine/global_variable_builder.js +21 -3
  82. package/dest/state_machine/index.d.ts +11 -7
  83. package/dest/state_machine/index.d.ts.map +1 -1
  84. package/dest/state_machine/index.js +60 -25
  85. package/dest/state_machine/mock_epoch_cache.d.ts +29 -12
  86. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  87. package/dest/state_machine/mock_epoch_cache.js +50 -15
  88. package/dest/state_machine/synchronizer.d.ts +6 -5
  89. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  90. package/dest/state_machine/synchronizer.js +9 -8
  91. package/dest/txe_session.d.ts +94 -21
  92. package/dest/txe_session.d.ts.map +1 -1
  93. package/dest/txe_session.js +314 -68
  94. package/dest/utils/block_creation.d.ts +21 -6
  95. package/dest/utils/block_creation.d.ts.map +1 -1
  96. package/dest/utils/block_creation.js +38 -4
  97. package/dest/utils/encoding.d.ts +191 -0
  98. package/dest/utils/encoding.d.ts.map +1 -0
  99. package/dest/{util → utils}/encoding.js +8 -3
  100. package/dest/utils/expected_failure_error.d.ts +4 -0
  101. package/dest/utils/expected_failure_error.d.ts.map +1 -0
  102. package/dest/utils/tx_effect_creation.d.ts +3 -3
  103. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  104. package/dest/utils/tx_effect_creation.js +4 -7
  105. package/dest/utils/txe_account_store.d.ts +10 -0
  106. package/dest/utils/txe_account_store.d.ts.map +1 -0
  107. package/dest/{util/txe_account_data_provider.js → utils/txe_account_store.js} +1 -1
  108. package/dest/utils/txe_artifact_resolver.d.ts +37 -0
  109. package/dest/utils/txe_artifact_resolver.d.ts.map +1 -0
  110. package/dest/utils/txe_artifact_resolver.js +161 -0
  111. package/dest/utils/txe_public_contract_data_source.d.ts +20 -0
  112. package/dest/utils/txe_public_contract_data_source.d.ts.map +1 -0
  113. package/dest/utils/txe_public_contract_data_source.js +48 -0
  114. package/dest/worker.bundle.js +3 -0
  115. package/dest/worker.bundle.js.map +7 -0
  116. package/dest/worker.d.ts +2 -0
  117. package/dest/worker.d.ts.map +1 -0
  118. package/dest/worker.js +92 -0
  119. package/package.json +40 -22
  120. package/src/bin/check_txe_oracle_version.ts +70 -0
  121. package/src/bin/index.ts +11 -2
  122. package/src/bin/oracle_test_server.ts +51 -0
  123. package/src/constants.ts +13 -0
  124. package/src/dispatcher_pool.ts +316 -0
  125. package/src/index.ts +111 -201
  126. package/src/msgpackr_fr_extension.ts +23 -0
  127. package/src/oracle/interfaces.ts +62 -36
  128. package/src/oracle/test-resolver/fixtures.ts +84 -0
  129. package/src/oracle/test-resolver/index.ts +45 -0
  130. package/src/oracle/test-resolver/resolver.ts +165 -0
  131. package/src/oracle/txe_oracle_public_context.ts +81 -28
  132. package/src/oracle/txe_oracle_registry.ts +401 -0
  133. package/src/oracle/txe_oracle_top_level_context.ts +418 -178
  134. package/src/oracle/txe_oracle_version.ts +17 -0
  135. package/src/oracle/txe_private_execution_oracle.ts +30 -0
  136. package/src/rpc_server.ts +87 -0
  137. package/src/rpc_translator.ts +999 -909
  138. package/src/state_machine/archiver.ts +83 -115
  139. package/src/state_machine/dummy_p2p_client.ts +83 -33
  140. package/src/state_machine/global_variable_builder.ts +39 -6
  141. package/src/state_machine/index.ts +82 -24
  142. package/src/state_machine/mock_epoch_cache.ts +63 -23
  143. package/src/state_machine/synchronizer.ts +10 -9
  144. package/src/txe_session.ts +486 -119
  145. package/src/utils/block_creation.ts +49 -14
  146. package/src/{util → utils}/encoding.ts +9 -3
  147. package/src/utils/tx_effect_creation.ts +5 -12
  148. package/src/{util/txe_account_data_provider.ts → utils/txe_account_store.ts} +1 -1
  149. package/src/utils/txe_artifact_resolver.ts +217 -0
  150. package/src/utils/txe_public_contract_data_source.ts +58 -0
  151. package/src/worker.ts +98 -0
  152. package/dest/util/encoding.d.ts +0 -121
  153. package/dest/util/encoding.d.ts.map +0 -1
  154. package/dest/util/expected_failure_error.d.ts +0 -4
  155. package/dest/util/expected_failure_error.d.ts.map +0 -1
  156. package/dest/util/txe_account_data_provider.d.ts +0 -10
  157. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  158. package/dest/util/txe_contract_data_provider.d.ts +0 -12
  159. package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
  160. package/dest/util/txe_contract_data_provider.js +0 -22
  161. package/dest/util/txe_public_contract_data_source.d.ts +0 -20
  162. package/dest/util/txe_public_contract_data_source.d.ts.map +0 -1
  163. package/dest/util/txe_public_contract_data_source.js +0 -67
  164. package/src/util/txe_contract_data_provider.ts +0 -36
  165. package/src/util/txe_public_contract_data_source.ts +0 -85
  166. /package/dest/{util → utils}/expected_failure_error.js +0 -0
  167. /package/src/{util → utils}/expected_failure_error.ts +0 -0
@@ -1,151 +1,119 @@
1
- import { ArchiverStoreHelper, KVArchiverDataStore, type PublishedL2Block } from '@aztec/archiver';
1
+ import { ArchiverDataSourceBase, ArchiverDataStoreUpdater, createArchiverDataStores } from '@aztec/archiver';
2
2
  import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
3
+ import { CheckpointNumber, type EpochNumber, type SlotNumber } from '@aztec/foundation/branded-types';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
5
  import type { EthAddress } from '@aztec/foundation/eth-address';
4
- import { Fr } from '@aztec/foundation/fields';
5
6
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
6
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
7
- import type { L2Block, L2BlockSource, L2Tips, ValidateBlockResult } from '@aztec/stdlib/block';
8
- import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
9
- import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
10
- import type { BlockHeader } from '@aztec/stdlib/tx';
11
- import type { UInt64 } from '@aztec/stdlib/types';
12
-
13
- // We are extending the ArchiverDataStoreHelper here because it provides most of the endpoints needed by the
14
- // node for reading from and writing to state, without needing any of the extra overhead that the Archiver itself
15
- // requires (i.e. an L1 client)
16
- export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
7
+ import {
8
+ type CheckpointId,
9
+ GENESIS_BLOCK_HEADER_HASH,
10
+ type L2BlockId,
11
+ type L2TipId,
12
+ type L2Tips,
13
+ type ValidateCheckpointResult,
14
+ } from '@aztec/stdlib/block';
15
+ import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
16
+ import { EmptyL1RollupConstants, type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
17
+ import { BlockHeader } from '@aztec/stdlib/tx';
18
+
19
+ /**
20
+ * TXE Archiver implementation.
21
+ * Provides most of the endpoints needed by the node for reading from and writing to state,
22
+ * without needing any of the extra overhead that the Archiver itself requires (i.e. an L1 client).
23
+ */
24
+ export class TXEArchiver extends ArchiverDataSourceBase {
25
+ private readonly updater = new ArchiverDataStoreUpdater(this.stores);
26
+
17
27
  constructor(db: AztecAsyncKVStore) {
18
- super(new KVArchiverDataStore(db, 9999));
28
+ super(
29
+ createArchiverDataStores(db, GENESIS_BLOCK_HEADER_HASH),
30
+ undefined,
31
+ BlockHeader.empty(),
32
+ GENESIS_BLOCK_HEADER_HASH,
33
+ new Fr(GENESIS_ARCHIVE_ROOT),
34
+ );
19
35
  }
20
36
 
21
- public override async addBlocks(blocks: PublishedL2Block[]): Promise<boolean> {
22
- const opResults = await Promise.all([
23
- this.store.addLogs(blocks.map(block => block.block)),
24
- this.store.addBlocks(blocks),
25
- ]);
37
+ public async addCheckpoints(checkpoints: PublishedCheckpoint[], result?: ValidateCheckpointResult): Promise<void> {
38
+ await this.updater.addCheckpoints(checkpoints, result);
39
+ }
26
40
 
27
- return opResults.every(Boolean);
41
+ public getRollupAddress(): Promise<EthAddress> {
42
+ throw new Error('TXE Archiver does not implement "getRollupAddress"');
28
43
  }
29
44
 
30
- /**
31
- * Gets the number of the latest L2 block processed by the block source implementation.
32
- * @returns The number of the latest L2 block processed by the block source implementation.
33
- */
34
- public getBlockNumber(): Promise<number> {
35
- return this.store.getSynchedL2BlockNumber();
45
+ public getRegistryAddress(): Promise<EthAddress> {
46
+ throw new Error('TXE Archiver does not implement "getRegistryAddress"');
36
47
  }
37
48
 
38
- /**
39
- * Gets the number of the latest L2 block proven seen by the block source implementation.
40
- * @returns The number of the latest L2 block proven seen by the block source implementation.
41
- */
42
- public getProvenBlockNumber(): Promise<number> {
43
- return this.store.getSynchedL2BlockNumber();
49
+ public getL1Constants(): Promise<L1RollupConstants> {
50
+ // The TXE has no L1, so it serves the empty constants (epochDuration=1) used throughout the TXE state machine
51
+ // (see mock_epoch_cache). The node calls this when assembling a mined tx receipt to derive the epoch number.
52
+ return Promise.resolve(EmptyL1RollupConstants);
44
53
  }
45
54
 
46
- /**
47
- * Gets a published l2 block. If a negative number is passed, the block returned is the most recent.
48
- * @param number - The block number to return (inclusive).
49
- * @returns The requested L2 block.
50
- */
51
- public override async getPublishedBlock(number: number): Promise<PublishedL2Block | undefined> {
52
- // If the number provided is -ve, then return the latest block.
53
- if (number < 0) {
54
- number = await this.store.getSynchedL2BlockNumber();
55
- }
56
- if (number == 0) {
57
- return undefined;
58
- }
59
- const blocks = await this.store.getPublishedBlocks(number, 1);
60
- return blocks.length === 0 ? undefined : blocks[0];
55
+ public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
56
+ return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
61
57
  }
62
58
 
63
- /**
64
- * Gets an l2 block. If a negative number is passed, the block returned is the most recent.
65
- * @param number - The block number to return (inclusive).
66
- * @returns The requested L2 block.
67
- */
68
- public getBlock(number: number | 'latest'): Promise<L2Block | undefined> {
69
- return this.getPublishedBlock(number != 'latest' ? number : -1).then(block => block?.block);
59
+ public getL1Timestamp(): Promise<bigint | undefined> {
60
+ throw new Error('TXE Archiver does not implement "getL1Timestamp"');
70
61
  }
71
62
 
72
- /**
73
- * Gets an l2 block header.
74
- * @param number - The block number to return or 'latest' for the most recent one.
75
- * @returns The requested L2 block header.
76
- */
77
- public async getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
78
- if (number === 'latest') {
79
- number = await this.store.getSynchedL2BlockNumber();
63
+ public async getL2Tips(): Promise<L2Tips> {
64
+ // In TXE there is no possibility of reorgs and no blocks are ever getting proven so we just set 'latest', 'proven'
65
+ // and 'finalized' to the latest block.
66
+ const latestBlockNumber = await this.stores.blocks.getLatestL2BlockNumber();
67
+ if (latestBlockNumber === 0) {
68
+ throw new Error('L2Tips requested from TXE Archiver but no block found');
80
69
  }
81
- if (number === 0) {
82
- return undefined;
70
+ const latestBlockData = await this.stores.blocks.getBlockData({ number: latestBlockNumber });
71
+ if (!latestBlockData) {
72
+ throw new Error('L2Tips requested from TXE Archiver but no block header found');
83
73
  }
84
- const headers = await this.store.getBlockHeaders(number, 1);
85
- return headers.length === 0 ? undefined : headers[0];
86
- }
87
74
 
88
- public getBlocks(from: number, limit: number, _proven?: boolean): Promise<L2Block[]> {
89
- return this.getPublishedBlocks(from, limit).then(blocks => blocks.map(b => b.block));
90
- }
91
-
92
- public getL2SlotNumber(): Promise<bigint> {
93
- throw new Error('TXE Archiver does not implement "getL2SlotNumber"');
94
- }
75
+ const number = latestBlockData.header.globalVariables.blockNumber;
76
+ const hash = latestBlockData.blockHash.toString();
95
77
 
96
- public getL2EpochNumber(): Promise<bigint> {
97
- throw new Error('TXE Archiver does not implement "getL2EpochNumber"');
78
+ // TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
79
+ // This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
80
+ const checkpoint = await this.stores.blocks.getRangeOfCheckpoints(CheckpointNumber.fromBlockNumber(number), 1);
81
+ if (checkpoint.length === 0) {
82
+ throw new Error(`L2Tips requested from TXE Archiver but no checkpoint found for block number ${number}`);
83
+ }
84
+ const blockId: L2BlockId = { number, hash };
85
+ const checkpointId: CheckpointId = {
86
+ number: checkpoint[0].checkpointNumber,
87
+ hash: checkpoint[0].header.hash().toString(),
88
+ };
89
+ const tipId: L2TipId = { block: blockId, checkpoint: checkpointId };
90
+ return {
91
+ proposed: blockId,
92
+ proven: tipId,
93
+ finalized: tipId,
94
+ checkpointed: tipId,
95
+ proposedCheckpoint: tipId,
96
+ };
98
97
  }
99
98
 
100
- public getBlocksForEpoch(_epochNumber: bigint): Promise<L2Block[]> {
101
- throw new Error('TXE Archiver does not implement "getBlocksForEpoch"');
99
+ public getSyncedL2SlotNumber(): Promise<SlotNumber | undefined> {
100
+ throw new Error('TXE Archiver does not implement "getSyncedL2SlotNumber"');
102
101
  }
103
102
 
104
- public getBlockHeadersForEpoch(_epochNumber: bigint): Promise<BlockHeader[]> {
105
- throw new Error('TXE Archiver does not implement "getBlockHeadersForEpoch"');
103
+ public getSyncedL2EpochNumber(): Promise<EpochNumber | undefined> {
104
+ throw new Error('TXE Archiver does not implement "getSyncedL2EpochNumber"');
106
105
  }
107
106
 
108
- public isEpochComplete(_epochNumber: bigint): Promise<boolean> {
107
+ public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
109
108
  throw new Error('TXE Archiver does not implement "isEpochComplete"');
110
109
  }
111
110
 
112
- public getL2Tips(): Promise<L2Tips> {
113
- throw new Error('TXE Archiver does not implement "getL2Tips"');
114
- }
115
-
116
- public getL1Constants(): Promise<L1RollupConstants> {
117
- throw new Error('TXE Archiver does not implement "getL2Constants"');
118
- }
119
-
120
- public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
121
- return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
122
- }
123
-
124
111
  public syncImmediate(): Promise<void> {
125
112
  throw new Error('TXE Archiver does not implement "syncImmediate"');
126
113
  }
127
114
 
128
- public getContract(_address: AztecAddress, _timestamp?: UInt64): Promise<ContractInstanceWithAddress | undefined> {
129
- throw new Error('TXE Archiver does not implement "getContract"');
130
- }
131
-
132
- public getRollupAddress(): Promise<EthAddress> {
133
- throw new Error('TXE Archiver does not implement "getRollupAddress"');
134
- }
135
-
136
- public getRegistryAddress(): Promise<EthAddress> {
137
- throw new Error('TXE Archiver does not implement "getRegistryAddress"');
138
- }
139
-
140
- public getL1Timestamp(): Promise<bigint> {
141
- throw new Error('TXE Archiver does not implement "getL1Timestamp"');
142
- }
143
-
144
- public isPendingChainInvalid(): Promise<boolean> {
145
- return Promise.resolve(false);
146
- }
147
-
148
- public override getPendingChainValidationStatus(): Promise<ValidateBlockResult> {
149
- return Promise.resolve({ valid: true });
115
+ public getL2ToL1MembershipWitness(): Promise<undefined> {
116
+ // TXE doesn't drive the L2-to-L1 message flow through this archiver.
117
+ return Promise.resolve(undefined);
150
118
  }
151
119
  }
@@ -1,23 +1,33 @@
1
+ import type { CheckpointProposalHash, SlotNumber } from '@aztec/foundation/branded-types';
1
2
  import type {
2
3
  AuthRequest,
3
4
  ENR,
4
5
  P2P,
5
6
  P2PBlockReceivedCallback,
7
+ P2PCheckpointAttestationCallback,
8
+ P2PCheckpointReceivedCallback,
6
9
  P2PConfig,
10
+ P2PDuplicateAttestationCallback,
11
+ P2PDuplicateProposalCallback,
7
12
  P2PSyncState,
8
13
  PeerId,
9
14
  ReqRespSubProtocol,
10
15
  ReqRespSubProtocolHandler,
11
- ReqRespSubProtocolValidators,
12
16
  StatusMessage,
13
17
  } from '@aztec/p2p';
14
18
  import type { EthAddress, L2BlockStreamEvent, L2Tips } from '@aztec/stdlib/block';
15
- import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
16
- import type { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
17
- import type { Tx, TxHash } from '@aztec/stdlib/tx';
19
+ import type { ITxProvider, PeerInfo } from '@aztec/stdlib/interfaces/server';
20
+ import type {
21
+ BlockProposal,
22
+ CheckpointAttestation,
23
+ CheckpointProposal,
24
+ CheckpointProposalCore,
25
+ TopicType,
26
+ } from '@aztec/stdlib/p2p';
27
+ import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
18
28
 
19
29
  export class DummyP2P implements P2P {
20
- public validate(_txs: Tx[]): Promise<void> {
30
+ public validateTxsReceivedInBlockProposal(_txs: Tx[]): Promise<void> {
21
31
  return Promise.resolve();
22
32
  }
23
33
 
@@ -37,14 +47,34 @@ export class DummyP2P implements P2P {
37
47
  throw new Error('DummyP2P does not implement "getPeers"');
38
48
  }
39
49
 
50
+ public getGossipMeshPeerCount(_topicType: TopicType): Promise<number> {
51
+ return Promise.resolve(0);
52
+ }
53
+
40
54
  public broadcastProposal(_proposal: BlockProposal): Promise<void> {
41
55
  throw new Error('DummyP2P does not implement "broadcastProposal"');
42
56
  }
43
57
 
58
+ public broadcastCheckpointProposal(_proposal: CheckpointProposal): Promise<void> {
59
+ throw new Error('DummyP2P does not implement "broadcastCheckpointProposal"');
60
+ }
61
+
62
+ public broadcastCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
63
+ throw new Error('DummyP2P does not implement "broadcastCheckpointAttestations"');
64
+ }
65
+
44
66
  public registerBlockProposalHandler(_handler: P2PBlockReceivedCallback): void {
45
67
  throw new Error('DummyP2P does not implement "registerBlockProposalHandler"');
46
68
  }
47
69
 
70
+ public registerValidatorCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
71
+ throw new Error('DummyP2P does not implement "registerValidatorCheckpointProposalHandler"');
72
+ }
73
+
74
+ public registerAllNodesCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
75
+ throw new Error('DummyP2P does not implement "registerAllNodesCheckpointProposalHandler"');
76
+ }
77
+
48
78
  public requestTxs(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
49
79
  throw new Error('DummyP2P does not implement "requestTxs"');
50
80
  }
@@ -57,8 +87,8 @@ export class DummyP2P implements P2P {
57
87
  throw new Error('DummyP2P does not implement "sendTx"');
58
88
  }
59
89
 
60
- public deleteTxs(_txHashes: TxHash[]): Promise<void> {
61
- throw new Error('DummyP2P does not implement "deleteTxs"');
90
+ public handleFailedExecution(_txHashes: TxHash[]): Promise<void> {
91
+ throw new Error('DummyP2P does not implement "handleFailedExecution"');
62
92
  }
63
93
 
64
94
  public getTxByHashFromPool(_txHash: TxHash): Promise<Tx | undefined> {
@@ -74,13 +104,19 @@ export class DummyP2P implements P2P {
74
104
  }
75
105
 
76
106
  public getTxStatus(_txHash: TxHash): Promise<'pending' | 'mined' | undefined> {
77
- throw new Error('DummyP2P does not implement "getTxStatus"');
107
+ // In TXE there is no concept of transactions but we need to implement this because of tagging. We return 'mined'
108
+ // tx status for any tx hash.
109
+ return Promise.resolve('mined');
78
110
  }
79
111
 
80
112
  public iteratePendingTxs(): AsyncIterableIterator<Tx> {
81
113
  throw new Error('DummyP2P does not implement "iteratePendingTxs"');
82
114
  }
83
115
 
116
+ public iterateEligiblePendingTxs(): AsyncIterableIterator<Tx> {
117
+ throw new Error('DummyP2P does not implement "iterateEligiblePendingTxs"');
118
+ }
119
+
84
120
  public getPendingTxCount(): Promise<number> {
85
121
  throw new Error('DummyP2P does not implement "getPendingTxCount"');
86
122
  }
@@ -109,20 +145,30 @@ export class DummyP2P implements P2P {
109
145
  throw new Error('DummyP2P does not implement "isP2PClient"');
110
146
  }
111
147
 
148
+ public getTxProvider(): ITxProvider {
149
+ throw new Error('DummyP2P does not implement "getTxProvider"');
150
+ }
151
+
112
152
  public getTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
113
153
  throw new Error('DummyP2P does not implement "getTxsByHash"');
114
154
  }
115
155
 
116
- public getAttestationsForSlot(_slot: bigint, _proposalId?: string): Promise<BlockAttestation[]> {
117
- throw new Error('DummyP2P does not implement "getAttestationForSlot"');
156
+ public getCheckpointAttestationsForSlot(
157
+ _slot: SlotNumber,
158
+ _proposalPayloadHash?: CheckpointProposalHash,
159
+ ): Promise<CheckpointAttestation[]> {
160
+ throw new Error('DummyP2P does not implement "getCheckpointAttestationsForSlot"');
118
161
  }
119
162
 
120
- public deleteAttestation(_attestation: BlockAttestation): Promise<void> {
121
- return Promise.resolve();
163
+ public addOwnCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
164
+ throw new Error('DummyP2P does not implement "addOwnCheckpointAttestations"');
122
165
  }
123
166
 
124
- public addAttestations(_attestations: BlockAttestation[]): Promise<void> {
125
- throw new Error('DummyP2P does not implement "addAttestations"');
167
+ public getProposalsForSlot(_slot: SlotNumber): Promise<{
168
+ blockProposals: BlockProposal[];
169
+ checkpointProposals: CheckpointProposalCore[];
170
+ }> {
171
+ return Promise.resolve({ blockProposals: [], checkpointProposals: [] });
126
172
  }
127
173
 
128
174
  public getL2BlockHash(_number: number): Promise<string | undefined> {
@@ -145,14 +191,6 @@ export class DummyP2P implements P2P {
145
191
  throw new Error('DummyP2P does not implement "sync"');
146
192
  }
147
193
 
148
- public requestTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
149
- throw new Error('DummyP2P does not implement "requestTxsByHash"');
150
- }
151
-
152
- public getTxs(_filter: 'all' | 'pending' | 'mined'): Promise<Tx[]> {
153
- throw new Error('DummyP2P does not implement "getTxs"');
154
- }
155
-
156
194
  public getTxsByHashFromPool(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
157
195
  throw new Error('DummyP2P does not implement "getTxsByHashFromPool"');
158
196
  }
@@ -161,10 +199,6 @@ export class DummyP2P implements P2P {
161
199
  throw new Error('DummyP2P does not implement "hasTxsInPool"');
162
200
  }
163
201
 
164
- public addTxsToPool(_txs: Tx[]): Promise<number> {
165
- throw new Error('DummyP2P does not implement "addTxs"');
166
- }
167
-
168
202
  public getSyncedLatestBlockNum(): Promise<number> {
169
203
  throw new Error('DummyP2P does not implement "getSyncedLatestBlockNum"');
170
204
  }
@@ -177,15 +211,15 @@ export class DummyP2P implements P2P {
177
211
  throw new Error('DummyP2P does not implement "getSyncedLatestSlot"');
178
212
  }
179
213
 
180
- markTxsAsNonEvictable(_: TxHash[]): Promise<void> {
181
- throw new Error('DummyP2P does not implement "markTxsAsNonEvictable".');
214
+ protectTxs(_txHashes: TxHash[], _blockHeader: BlockHeader): Promise<TxHash[]> {
215
+ throw new Error('DummyP2P does not implement "protectTxs".');
216
+ }
217
+
218
+ prepareForSlot(_slotNumber: SlotNumber): Promise<void> {
219
+ return Promise.resolve();
182
220
  }
183
221
 
184
- addReqRespSubProtocol(
185
- _subProtocol: ReqRespSubProtocol,
186
- _handler: ReqRespSubProtocolHandler,
187
- _validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
188
- ): Promise<void> {
222
+ addReqRespSubProtocol(_subProtocol: ReqRespSubProtocol, _handler: ReqRespSubProtocolHandler): Promise<void> {
189
223
  throw new Error('DummyP2P does not implement "addReqRespSubProtocol".');
190
224
  }
191
225
  handleAuthRequestFromPeer(_authRequest: AuthRequest, _peerId: PeerId): Promise<StatusMessage> {
@@ -194,4 +228,20 @@ export class DummyP2P implements P2P {
194
228
 
195
229
  //This is no-op
196
230
  public registerThisValidatorAddresses(_address: EthAddress[]): void {}
231
+
232
+ public registerDuplicateProposalCallback(_callback: P2PDuplicateProposalCallback): void {
233
+ throw new Error('DummyP2P does not implement "registerDuplicateProposalCallback"');
234
+ }
235
+
236
+ public registerDuplicateAttestationCallback(_callback: P2PDuplicateAttestationCallback): void {
237
+ throw new Error('DummyP2P does not implement "registerDuplicateAttestationCallback"');
238
+ }
239
+
240
+ public registerCheckpointAttestationCallback(_callback: P2PCheckpointAttestationCallback): void {
241
+ throw new Error('DummyP2P does not implement "registerCheckpointAttestationCallback"');
242
+ }
243
+
244
+ public hasBlockProposalsForSlot(_slot: SlotNumber): Promise<boolean> {
245
+ throw new Error('DummyP2P does not implement "hasBlockProposalsForSlot"');
246
+ }
197
247
  }
@@ -1,20 +1,53 @@
1
+ import type { SimulationOverridesPlan } from '@aztec/ethereum/contracts';
2
+ import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { times } from '@aztec/foundation/collection';
1
4
  import type { EthAddress } from '@aztec/foundation/eth-address';
2
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
- import { GasFees } from '@aztec/stdlib/gas';
6
+ import { FEE_ORACLE_LAG, GasFees } from '@aztec/stdlib/gas';
4
7
  import { makeGlobalVariables } from '@aztec/stdlib/testing';
5
- import { type GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
8
+ import {
9
+ type CheckpointGlobalVariables,
10
+ type FeeProvider,
11
+ type GlobalVariableBuilder,
12
+ GlobalVariables,
13
+ } from '@aztec/stdlib/tx';
6
14
 
7
- export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
8
- public getCurrentBaseFees(): Promise<GasFees> {
15
+ /** Simple FeeProvider for TXE that returns zero fees. */
16
+ export class TXEFeeProvider implements FeeProvider {
17
+ public getCurrentMinFees(): Promise<GasFees> {
9
18
  return Promise.resolve(new GasFees(0, 0));
10
19
  }
11
20
 
21
+ public getPredictedMinFees(): Promise<GasFees[]> {
22
+ return Promise.resolve(times(FEE_ORACLE_LAG, () => new GasFees(0, 0)));
23
+ }
24
+ }
25
+
26
+ export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
12
27
  public buildGlobalVariables(
13
- _blockNumber: number,
28
+ _blockNumber: BlockNumber,
14
29
  _coinbase: EthAddress,
15
30
  _feeRecipient: AztecAddress,
16
- _slotNumber?: bigint,
31
+ _slotNumber?: SlotNumber,
17
32
  ): Promise<GlobalVariables> {
18
33
  return Promise.resolve(makeGlobalVariables());
19
34
  }
35
+
36
+ public buildCheckpointGlobalVariables(
37
+ _coinbase: EthAddress,
38
+ _feeRecipient: AztecAddress,
39
+ _slotNumber: SlotNumber,
40
+ _simulationOverridesPlan?: SimulationOverridesPlan,
41
+ ): Promise<CheckpointGlobalVariables> {
42
+ const vars = makeGlobalVariables();
43
+ return Promise.resolve({
44
+ chainId: vars.chainId,
45
+ version: vars.version,
46
+ slotNumber: vars.slotNumber,
47
+ timestamp: vars.timestamp,
48
+ coinbase: vars.coinbase,
49
+ feeRecipient: vars.feeRecipient,
50
+ gasFees: vars.gasFees,
51
+ });
52
+ }
20
53
  }
@@ -1,34 +1,44 @@
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 { SyncDataProvider } from '@aztec/pxe/server';
6
- import { type L2Block, PublishedL2Block } from '@aztec/stdlib/block';
6
+ import { type AnchorBlockStore, type ContractStore, ContractSyncService, type NoteStore } from '@aztec/pxe/server';
7
+ import { MessageContextService } from '@aztec/pxe/simulator';
8
+ import { L2Block, type L2TipsProvider } from '@aztec/stdlib/block';
9
+ import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
7
10
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
8
- import { getPackageVersion } from '@aztec/stdlib/update-checker';
11
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
9
12
 
10
13
  import { TXEArchiver } from './archiver.js';
11
14
  import { DummyP2P } from './dummy_p2p_client.js';
12
- import { TXEGlobalVariablesBuilder } from './global_variable_builder.js';
15
+ import { TXEFeeProvider, TXEGlobalVariablesBuilder } from './global_variable_builder.js';
13
16
  import { MockEpochCache } from './mock_epoch_cache.js';
14
17
  import { TXESynchronizer } from './synchronizer.js';
15
18
 
16
19
  const VERSION = 1;
17
20
  const CHAIN_ID = 1;
21
+ // Hardcoded so the bundled TXE doesn't try to read stdlib's package.json at a relative path
22
+ // that becomes invalid once bundled
23
+ const PACKAGE_VERSION = 'txe';
18
24
 
19
25
  export class TXEStateMachine {
20
26
  constructor(
21
27
  public node: AztecNode,
22
28
  public synchronizer: TXESynchronizer,
23
29
  public archiver: TXEArchiver,
24
- public syncDataProvider: SyncDataProvider,
30
+ public anchorBlockStore: AnchorBlockStore,
31
+ public contractSyncService: ContractSyncService,
32
+ public messageContextService: MessageContextService,
25
33
  ) {}
26
34
 
27
- public static async create(db: AztecAsyncKVStore) {
28
- const archiver = new TXEArchiver(db);
35
+ public static async create(
36
+ archiver: TXEArchiver,
37
+ anchorBlockStore: AnchorBlockStore,
38
+ contractStore: ContractStore,
39
+ noteStore: NoteStore,
40
+ ) {
29
41
  const synchronizer = await TXESynchronizer.create();
30
- const syncDataProvider = new SyncDataProvider(db);
31
-
32
42
  const aztecNodeConfig = {} as AztecNodeConfig;
33
43
 
34
44
  const log = createLogger('txe_node');
@@ -44,34 +54,82 @@ export class TXEStateMachine {
44
54
  undefined,
45
55
  undefined,
46
56
  undefined,
57
+ async () => {},
47
58
  VERSION,
48
59
  CHAIN_ID,
49
60
  new TXEGlobalVariablesBuilder(),
61
+ new TXEFeeProvider(),
50
62
  new MockEpochCache(),
51
- getPackageVersion() ?? '',
63
+ PACKAGE_VERSION,
64
+ new TestCircuitVerifier(),
52
65
  new TestCircuitVerifier(),
53
66
  undefined,
54
67
  log,
55
68
  );
56
69
 
57
- return new this(node, synchronizer, archiver, syncDataProvider);
70
+ const contractSyncService = new ContractSyncService(
71
+ node,
72
+ contractStore,
73
+ noteStore,
74
+ createLogger('txe:contract_sync'),
75
+ );
76
+
77
+ const messageContextService = new MessageContextService(node);
78
+
79
+ return new this(node, synchronizer, archiver, anchorBlockStore, contractSyncService, messageContextService);
80
+ }
81
+
82
+ /** Returns an {@link L2TipsProvider} backed by this node's chain tips. */
83
+ public get l2TipsProvider(): L2TipsProvider {
84
+ const node = this.node;
85
+ return {
86
+ getL2Tips: async () => {
87
+ const tips = await node.getChainTips();
88
+ return { ...tips, proposedCheckpoint: tips.checkpointed };
89
+ },
90
+ };
58
91
  }
59
92
 
60
93
  public async handleL2Block(block: L2Block) {
94
+ // Create a checkpoint from the block manually.
95
+ // TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
96
+ // This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
97
+ const checkpointNumber = CheckpointNumber.fromBlockNumber(block.number);
98
+ const checkpoint = new Checkpoint(
99
+ block.archive,
100
+ CheckpointHeader.from({
101
+ lastArchiveRoot: block.header.lastArchive.root,
102
+ inHash: Fr.ZERO,
103
+ blobsHash: Fr.ZERO,
104
+ blockHeadersHash: Fr.ZERO,
105
+ epochOutHash: Fr.ZERO,
106
+ slotNumber: block.header.globalVariables.slotNumber,
107
+ timestamp: block.header.globalVariables.timestamp,
108
+ coinbase: block.header.globalVariables.coinbase,
109
+ feeRecipient: block.header.globalVariables.feeRecipient,
110
+ gasFees: block.header.globalVariables.gasFees,
111
+ totalManaUsed: block.header.totalManaUsed,
112
+ }),
113
+ [block],
114
+ checkpointNumber,
115
+ );
116
+
117
+ const publishedCheckpoint = new PublishedCheckpoint(
118
+ checkpoint,
119
+ new L1PublishedData(
120
+ BigInt(block.header.globalVariables.blockNumber),
121
+ block.header.globalVariables.timestamp,
122
+ block.header.globalVariables.blockNumber.toString(),
123
+ ),
124
+ [],
125
+ );
126
+ // Wipe contract sync cache when anchor block changes (mirrors BlockSynchronizer behavior)
127
+ this.contractSyncService.wipe();
128
+
61
129
  await Promise.all([
62
130
  this.synchronizer.handleL2Block(block),
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()),
131
+ this.archiver.addCheckpoints([publishedCheckpoint], undefined),
132
+ this.anchorBlockStore.setHeader(block.header),
75
133
  ]);
76
134
  }
77
135
  }