@aztec/txe 0.0.0-test.1 → 0.0.1-commit.0b941701

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 (100) hide show
  1. package/dest/bin/index.d.ts +1 -1
  2. package/dest/bin/index.js +3 -2
  3. package/dest/constants.d.ts +3 -0
  4. package/dest/constants.d.ts.map +1 -0
  5. package/dest/constants.js +2 -0
  6. package/dest/index.d.ts +1 -1
  7. package/dest/index.d.ts.map +1 -1
  8. package/dest/index.js +81 -51
  9. package/dest/oracle/interfaces.d.ts +57 -0
  10. package/dest/oracle/interfaces.d.ts.map +1 -0
  11. package/dest/oracle/interfaces.js +3 -0
  12. package/dest/oracle/txe_oracle_public_context.d.ts +34 -0
  13. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -0
  14. package/dest/oracle/txe_oracle_public_context.js +123 -0
  15. package/dest/oracle/txe_oracle_top_level_context.d.ts +66 -0
  16. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -0
  17. package/dest/oracle/txe_oracle_top_level_context.js +469 -0
  18. package/dest/rpc_translator.d.ts +252 -0
  19. package/dest/rpc_translator.d.ts.map +1 -0
  20. package/dest/rpc_translator.js +680 -0
  21. package/dest/state_machine/archiver.d.ts +31 -0
  22. package/dest/state_machine/archiver.d.ts.map +1 -0
  23. package/dest/state_machine/archiver.js +85 -0
  24. package/dest/state_machine/dummy_p2p_client.d.ts +55 -0
  25. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -0
  26. package/dest/state_machine/dummy_p2p_client.js +141 -0
  27. package/dest/state_machine/global_variable_builder.d.ts +11 -0
  28. package/dest/state_machine/global_variable_builder.d.ts.map +1 -0
  29. package/dest/state_machine/global_variable_builder.js +22 -0
  30. package/dest/state_machine/index.d.ts +16 -0
  31. package/dest/state_machine/index.d.ts.map +1 -0
  32. package/dest/state_machine/index.js +63 -0
  33. package/dest/state_machine/mock_epoch_cache.d.ts +27 -0
  34. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -0
  35. package/dest/state_machine/mock_epoch_cache.js +54 -0
  36. package/dest/state_machine/synchronizer.d.ts +33 -0
  37. package/dest/state_machine/synchronizer.d.ts.map +1 -0
  38. package/dest/state_machine/synchronizer.js +59 -0
  39. package/dest/txe_session.d.ts +75 -0
  40. package/dest/txe_session.d.ts.map +1 -0
  41. package/dest/txe_session.js +302 -0
  42. package/dest/util/encoding.d.ts +641 -24
  43. package/dest/util/encoding.d.ts.map +1 -1
  44. package/dest/util/encoding.js +66 -11
  45. package/dest/util/expected_failure_error.d.ts +1 -1
  46. package/dest/util/expected_failure_error.d.ts.map +1 -1
  47. package/dest/util/txe_account_store.d.ts +10 -0
  48. package/dest/util/txe_account_store.d.ts.map +1 -0
  49. package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
  50. package/dest/util/txe_contract_store.d.ts +12 -0
  51. package/dest/util/txe_contract_store.d.ts.map +1 -0
  52. package/dest/util/txe_contract_store.js +22 -0
  53. package/dest/util/txe_public_contract_data_source.d.ts +12 -11
  54. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  55. package/dest/util/txe_public_contract_data_source.js +37 -58
  56. package/dest/utils/block_creation.d.ts +28 -0
  57. package/dest/utils/block_creation.d.ts.map +1 -0
  58. package/dest/utils/block_creation.js +56 -0
  59. package/dest/utils/tx_effect_creation.d.ts +5 -0
  60. package/dest/utils/tx_effect_creation.d.ts.map +1 -0
  61. package/dest/utils/tx_effect_creation.js +13 -0
  62. package/package.json +30 -24
  63. package/src/bin/index.ts +3 -2
  64. package/src/constants.ts +3 -0
  65. package/src/index.ts +105 -74
  66. package/src/oracle/interfaces.ts +86 -0
  67. package/src/oracle/txe_oracle_public_context.ts +160 -0
  68. package/src/oracle/txe_oracle_top_level_context.ts +728 -0
  69. package/src/rpc_translator.ts +1091 -0
  70. package/src/state_machine/archiver.ts +95 -0
  71. package/src/state_machine/dummy_p2p_client.ts +209 -0
  72. package/src/state_machine/global_variable_builder.ts +38 -0
  73. package/src/state_machine/index.ts +100 -0
  74. package/src/state_machine/mock_epoch_cache.ts +67 -0
  75. package/src/state_machine/synchronizer.ts +88 -0
  76. package/src/txe_session.ts +545 -0
  77. package/src/util/encoding.ts +85 -11
  78. package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
  79. package/src/util/txe_contract_store.ts +36 -0
  80. package/src/util/txe_public_contract_data_source.ts +43 -58
  81. package/src/utils/block_creation.ts +95 -0
  82. package/src/utils/tx_effect_creation.ts +30 -0
  83. package/dest/node/txe_node.d.ts +0 -358
  84. package/dest/node/txe_node.d.ts.map +0 -1
  85. package/dest/node/txe_node.js +0 -504
  86. package/dest/oracle/txe_oracle.d.ts +0 -152
  87. package/dest/oracle/txe_oracle.d.ts.map +0 -1
  88. package/dest/oracle/txe_oracle.js +0 -833
  89. package/dest/txe_service/txe_service.d.ts +0 -212
  90. package/dest/txe_service/txe_service.d.ts.map +0 -1
  91. package/dest/txe_service/txe_service.js +0 -572
  92. package/dest/util/txe_account_data_provider.d.ts +0 -10
  93. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  94. package/dest/util/txe_world_state_db.d.ts +0 -14
  95. package/dest/util/txe_world_state_db.d.ts.map +0 -1
  96. package/dest/util/txe_world_state_db.js +0 -27
  97. package/src/node/txe_node.ts +0 -725
  98. package/src/oracle/txe_oracle.ts +0 -1241
  99. package/src/txe_service/txe_service.ts +0 -749
  100. package/src/util/txe_world_state_db.ts +0 -38
@@ -0,0 +1,95 @@
1
+ import { ArchiverDataSourceBase, ArchiverDataStoreUpdater, KVArchiverDataStore } from '@aztec/archiver';
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';
5
+ import type { EthAddress } from '@aztec/foundation/eth-address';
6
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
7
+ import type { CheckpointId, L2BlockId, L2TipId, L2Tips, ValidateCheckpointResult } from '@aztec/stdlib/block';
8
+ import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
9
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
10
+
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);
18
+
19
+ constructor(db: AztecAsyncKVStore) {
20
+ const store = new KVArchiverDataStore(db, 9999, { epochDuration: 32 });
21
+ super(store);
22
+ }
23
+
24
+ public async addCheckpoints(checkpoints: PublishedCheckpoint[], result?: ValidateCheckpointResult): Promise<void> {
25
+ await this.updater.addCheckpoints(checkpoints, result);
26
+ }
27
+
28
+ public getRollupAddress(): Promise<EthAddress> {
29
+ throw new Error('TXE Archiver does not implement "getRollupAddress"');
30
+ }
31
+
32
+ public getRegistryAddress(): Promise<EthAddress> {
33
+ throw new Error('TXE Archiver does not implement "getRegistryAddress"');
34
+ }
35
+
36
+ public getL1Constants(): Promise<L1RollupConstants> {
37
+ throw new Error('TXE Archiver does not implement "getL1Constants"');
38
+ }
39
+
40
+ public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
41
+ return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
42
+ }
43
+
44
+ public getL1Timestamp(): Promise<bigint | undefined> {
45
+ throw new Error('TXE Archiver does not implement "getL1Timestamp"');
46
+ }
47
+
48
+ public async getL2Tips(): Promise<L2Tips> {
49
+ // In TXE there is no possibility of reorgs and no blocks are ever getting proven so we just set 'latest', 'proven'
50
+ // and 'finalized' to the latest block.
51
+ const blockHeader = await this.getBlockHeader('latest');
52
+ if (!blockHeader) {
53
+ throw new Error('L2Tips requested from TXE Archiver but no block header found');
54
+ }
55
+
56
+ const number = blockHeader.globalVariables.blockNumber;
57
+ const hash = (await blockHeader.hash()).toString();
58
+ const checkpointedBlock = await this.getCheckpointedBlock(number);
59
+ if (!checkpointedBlock) {
60
+ throw new Error(`L2Tips requested from TXE Archiver but no checkpointed block found for block number ${number}`);
61
+ }
62
+ const checkpoint = await this.store.getRangeOfCheckpoints(CheckpointNumber.fromBlockNumber(number), 1);
63
+ if (checkpoint.length === 0) {
64
+ throw new Error(`L2Tips requested from TXE Archiver but no checkpoint found for block number ${number}`);
65
+ }
66
+ const blockId: L2BlockId = { number, hash };
67
+ const checkpointId: CheckpointId = {
68
+ number: checkpoint[0].checkpointNumber,
69
+ hash: checkpoint[0].header.hash().toString(),
70
+ };
71
+ const tipId: L2TipId = { block: blockId, checkpoint: checkpointId };
72
+ return {
73
+ proposed: blockId,
74
+ proven: tipId,
75
+ finalized: tipId,
76
+ checkpointed: tipId,
77
+ };
78
+ }
79
+
80
+ public getL2SlotNumber(): Promise<SlotNumber | undefined> {
81
+ throw new Error('TXE Archiver does not implement "getL2SlotNumber"');
82
+ }
83
+
84
+ public getL2EpochNumber(): Promise<EpochNumber | undefined> {
85
+ throw new Error('TXE Archiver does not implement "getL2EpochNumber"');
86
+ }
87
+
88
+ public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
89
+ throw new Error('TXE Archiver does not implement "isEpochComplete"');
90
+ }
91
+
92
+ public syncImmediate(): Promise<void> {
93
+ throw new Error('TXE Archiver does not implement "syncImmediate"');
94
+ }
95
+ }
@@ -0,0 +1,209 @@
1
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
2
+ import type {
3
+ AuthRequest,
4
+ ENR,
5
+ P2P,
6
+ P2PBlockReceivedCallback,
7
+ P2PCheckpointReceivedCallback,
8
+ P2PConfig,
9
+ P2PSyncState,
10
+ PeerId,
11
+ ReqRespSubProtocol,
12
+ ReqRespSubProtocolHandler,
13
+ ReqRespSubProtocolValidators,
14
+ StatusMessage,
15
+ } from '@aztec/p2p';
16
+ 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';
20
+
21
+ export class DummyP2P implements P2P {
22
+ public validate(_txs: Tx[]): Promise<void> {
23
+ return Promise.resolve();
24
+ }
25
+
26
+ public clear(): Promise<void> {
27
+ throw new Error('DummyP2P does not implement "clear".');
28
+ }
29
+
30
+ public getPendingTxs(): Promise<Tx[]> {
31
+ throw new Error('DummyP2P does not implement "getPendingTxs"');
32
+ }
33
+
34
+ public getEncodedEnr(): Promise<string | undefined> {
35
+ throw new Error('DummyP2P does not implement "getEncodedEnr"');
36
+ }
37
+
38
+ public getPeers(_includePending?: boolean): Promise<PeerInfo[]> {
39
+ throw new Error('DummyP2P does not implement "getPeers"');
40
+ }
41
+
42
+ public broadcastProposal(_proposal: BlockProposal): Promise<void> {
43
+ throw new Error('DummyP2P does not implement "broadcastProposal"');
44
+ }
45
+
46
+ public broadcastCheckpointProposal(_proposal: CheckpointProposal): Promise<void> {
47
+ throw new Error('DummyP2P does not implement "broadcastCheckpointProposal"');
48
+ }
49
+
50
+ public broadcastCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
51
+ throw new Error('DummyP2P does not implement "broadcastCheckpointAttestations"');
52
+ }
53
+
54
+ public registerBlockProposalHandler(_handler: P2PBlockReceivedCallback): void {
55
+ throw new Error('DummyP2P does not implement "registerBlockProposalHandler"');
56
+ }
57
+
58
+ public registerCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
59
+ throw new Error('DummyP2P does not implement "registerCheckpointProposalHandler"');
60
+ }
61
+
62
+ public requestTxs(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
63
+ throw new Error('DummyP2P does not implement "requestTxs"');
64
+ }
65
+
66
+ public requestTxByHash(_txHash: TxHash): Promise<Tx | undefined> {
67
+ throw new Error('DummyP2P does not implement "requestTxByHash"');
68
+ }
69
+
70
+ public sendTx(_tx: Tx): Promise<void> {
71
+ throw new Error('DummyP2P does not implement "sendTx"');
72
+ }
73
+
74
+ public deleteTxs(_txHashes: TxHash[]): Promise<void> {
75
+ throw new Error('DummyP2P does not implement "deleteTxs"');
76
+ }
77
+
78
+ public getTxByHashFromPool(_txHash: TxHash): Promise<Tx | undefined> {
79
+ throw new Error('DummyP2P does not implement "getTxByHashFromPool"');
80
+ }
81
+
82
+ public getTxByHash(_txHash: TxHash): Promise<Tx | undefined> {
83
+ throw new Error('DummyP2P does not implement "getTxByHash"');
84
+ }
85
+
86
+ public getArchivedTxByHash(_txHash: TxHash): Promise<Tx | undefined> {
87
+ throw new Error('DummyP2P does not implement "getArchivedTxByHash"');
88
+ }
89
+
90
+ public getTxStatus(_txHash: TxHash): Promise<'pending' | 'mined' | undefined> {
91
+ // In TXE there is no concept of transactions but we need to implement this because of tagging. We return 'mined'
92
+ // tx status for any tx hash.
93
+ return Promise.resolve('mined');
94
+ }
95
+
96
+ public iteratePendingTxs(): AsyncIterableIterator<Tx> {
97
+ throw new Error('DummyP2P does not implement "iteratePendingTxs"');
98
+ }
99
+
100
+ public getPendingTxCount(): Promise<number> {
101
+ throw new Error('DummyP2P does not implement "getPendingTxCount"');
102
+ }
103
+
104
+ public start(): Promise<void> {
105
+ throw new Error('DummyP2P does not implement "start"');
106
+ }
107
+
108
+ public stop(): Promise<void> {
109
+ throw new Error('DummyP2P does not implement "stop"');
110
+ }
111
+
112
+ public isReady(): boolean {
113
+ throw new Error('DummyP2P does not implement "isReady"');
114
+ }
115
+
116
+ public getStatus(): Promise<P2PSyncState> {
117
+ throw new Error('DummyP2P does not implement "getStatus"');
118
+ }
119
+
120
+ public getEnr(): ENR | undefined {
121
+ throw new Error('DummyP2P does not implement "getEnr"');
122
+ }
123
+
124
+ public isP2PClient(): true {
125
+ throw new Error('DummyP2P does not implement "isP2PClient"');
126
+ }
127
+
128
+ public getTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
129
+ throw new Error('DummyP2P does not implement "getTxsByHash"');
130
+ }
131
+
132
+ public getCheckpointAttestationsForSlot(_slot: SlotNumber, _proposalId?: string): Promise<CheckpointAttestation[]> {
133
+ throw new Error('DummyP2P does not implement "getCheckpointAttestationsForSlot"');
134
+ }
135
+
136
+ public addCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
137
+ throw new Error('DummyP2P does not implement "addCheckpointAttestations"');
138
+ }
139
+
140
+ public getL2BlockHash(_number: number): Promise<string | undefined> {
141
+ throw new Error('DummyP2P does not implement "getL2BlockHash"');
142
+ }
143
+
144
+ public updateP2PConfig(_config: Partial<P2PConfig>): Promise<void> {
145
+ throw new Error('DummyP2P does not implement "updateP2PConfig"');
146
+ }
147
+
148
+ public getL2Tips(): Promise<L2Tips> {
149
+ throw new Error('DummyP2P does not implement "getL2Tips"');
150
+ }
151
+
152
+ public handleBlockStreamEvent(_event: L2BlockStreamEvent): Promise<void> {
153
+ throw new Error('DummyP2P does not implement "handleBlockStreamEvent"');
154
+ }
155
+
156
+ public sync() {
157
+ throw new Error('DummyP2P does not implement "sync"');
158
+ }
159
+
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
+ public getTxsByHashFromPool(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
169
+ throw new Error('DummyP2P does not implement "getTxsByHashFromPool"');
170
+ }
171
+
172
+ public hasTxsInPool(_txHashes: TxHash[]): Promise<boolean[]> {
173
+ throw new Error('DummyP2P does not implement "hasTxsInPool"');
174
+ }
175
+
176
+ public addTxsToPool(_txs: Tx[]): Promise<number> {
177
+ throw new Error('DummyP2P does not implement "addTxs"');
178
+ }
179
+
180
+ public getSyncedLatestBlockNum(): Promise<number> {
181
+ throw new Error('DummyP2P does not implement "getSyncedLatestBlockNum"');
182
+ }
183
+
184
+ public getSyncedProvenBlockNum(): Promise<number> {
185
+ throw new Error('DummyP2P does not implement "getSyncedProvenBlockNum"');
186
+ }
187
+
188
+ public getSyncedLatestSlot(): Promise<bigint> {
189
+ throw new Error('DummyP2P does not implement "getSyncedLatestSlot"');
190
+ }
191
+
192
+ markTxsAsNonEvictable(_: TxHash[]): Promise<void> {
193
+ throw new Error('DummyP2P does not implement "markTxsAsNonEvictable".');
194
+ }
195
+
196
+ addReqRespSubProtocol(
197
+ _subProtocol: ReqRespSubProtocol,
198
+ _handler: ReqRespSubProtocolHandler,
199
+ _validator?: ReqRespSubProtocolValidators[ReqRespSubProtocol],
200
+ ): Promise<void> {
201
+ throw new Error('DummyP2P does not implement "addReqRespSubProtocol".');
202
+ }
203
+ handleAuthRequestFromPeer(_authRequest: AuthRequest, _peerId: PeerId): Promise<StatusMessage> {
204
+ throw new Error('DummyP2P does not implement "handleAuthRequestFromPeer".');
205
+ }
206
+
207
+ //This is no-op
208
+ public registerThisValidatorAddresses(_address: EthAddress[]): void {}
209
+ }
@@ -0,0 +1,38 @@
1
+ import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
2
+ import type { EthAddress } from '@aztec/foundation/eth-address';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import { GasFees } from '@aztec/stdlib/gas';
5
+ import { makeGlobalVariables } from '@aztec/stdlib/testing';
6
+ import { type CheckpointGlobalVariables, type GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
7
+
8
+ export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
9
+ public getCurrentMinFees(): Promise<GasFees> {
10
+ return Promise.resolve(new GasFees(0, 0));
11
+ }
12
+
13
+ public buildGlobalVariables(
14
+ _blockNumber: BlockNumber,
15
+ _coinbase: EthAddress,
16
+ _feeRecipient: AztecAddress,
17
+ _slotNumber?: SlotNumber,
18
+ ): Promise<GlobalVariables> {
19
+ return Promise.resolve(makeGlobalVariables());
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
+ }
38
+ }
@@ -0,0 +1,100 @@
1
+ import { type AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
2
+ import { TestCircuitVerifier } from '@aztec/bb-prover/test';
3
+ import { CheckpointNumber } from '@aztec/foundation/branded-types';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
5
+ import { createLogger } from '@aztec/foundation/log';
6
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
7
+ import { AnchorBlockStore } from '@aztec/pxe/server';
8
+ import { L2Block } from '@aztec/stdlib/block';
9
+ import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
10
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
11
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
12
+ import { getPackageVersion } from '@aztec/stdlib/update-checker';
13
+
14
+ import { TXEArchiver } from './archiver.js';
15
+ import { DummyP2P } from './dummy_p2p_client.js';
16
+ import { TXEGlobalVariablesBuilder } from './global_variable_builder.js';
17
+ import { MockEpochCache } from './mock_epoch_cache.js';
18
+ import { TXESynchronizer } from './synchronizer.js';
19
+
20
+ const VERSION = 1;
21
+ const CHAIN_ID = 1;
22
+
23
+ export class TXEStateMachine {
24
+ constructor(
25
+ public node: AztecNode,
26
+ public synchronizer: TXESynchronizer,
27
+ public archiver: TXEArchiver,
28
+ public anchorBlockStore: AnchorBlockStore,
29
+ ) {}
30
+
31
+ public static async create(db: AztecAsyncKVStore) {
32
+ const archiver = new TXEArchiver(db);
33
+ const synchronizer = await TXESynchronizer.create();
34
+ const anchorBlockStore = new AnchorBlockStore(db);
35
+
36
+ const aztecNodeConfig = {} as AztecNodeConfig;
37
+
38
+ const log = createLogger('txe_node');
39
+ const node = new AztecNodeService(
40
+ aztecNodeConfig,
41
+ new DummyP2P(),
42
+ archiver,
43
+ archiver,
44
+ archiver,
45
+ archiver,
46
+ synchronizer,
47
+ undefined,
48
+ undefined,
49
+ undefined,
50
+ undefined,
51
+ VERSION,
52
+ CHAIN_ID,
53
+ new TXEGlobalVariablesBuilder(),
54
+ new MockEpochCache(),
55
+ getPackageVersion() ?? '',
56
+ new TestCircuitVerifier(),
57
+ undefined,
58
+ log,
59
+ );
60
+
61
+ return new this(node, synchronizer, archiver, anchorBlockStore);
62
+ }
63
+
64
+ public async handleL2Block(block: L2Block) {
65
+ // Create a checkpoint from the block manually
66
+ const checkpoint = new Checkpoint(
67
+ block.archive,
68
+ CheckpointHeader.from({
69
+ lastArchiveRoot: block.header.lastArchive.root,
70
+ inHash: Fr.ZERO,
71
+ blobsHash: Fr.ZERO,
72
+ blockHeadersHash: Fr.ZERO,
73
+ epochOutHash: Fr.ZERO,
74
+ slotNumber: block.header.globalVariables.slotNumber,
75
+ timestamp: block.header.globalVariables.timestamp,
76
+ coinbase: block.header.globalVariables.coinbase,
77
+ feeRecipient: block.header.globalVariables.feeRecipient,
78
+ gasFees: block.header.globalVariables.gasFees,
79
+ totalManaUsed: block.header.totalManaUsed,
80
+ }),
81
+ [block],
82
+ CheckpointNumber.fromBlockNumber(block.number),
83
+ );
84
+
85
+ const publishedCheckpoint = new PublishedCheckpoint(
86
+ checkpoint,
87
+ new L1PublishedData(
88
+ BigInt(block.header.globalVariables.blockNumber),
89
+ block.header.globalVariables.timestamp,
90
+ block.header.globalVariables.blockNumber.toString(),
91
+ ),
92
+ [],
93
+ );
94
+ await Promise.all([
95
+ this.synchronizer.handleL2Block(block),
96
+ this.archiver.addCheckpoints([publishedCheckpoint], undefined),
97
+ this.anchorBlockStore.setHeader(block.header),
98
+ ]);
99
+ }
100
+ }
@@ -0,0 +1,67 @@
1
+ import type { EpochAndSlot, EpochCacheInterface, EpochCommitteeInfo, SlotTag } from '@aztec/epoch-cache';
2
+ import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { EthAddress } from '@aztec/foundation/eth-address';
4
+
5
+ /**
6
+ * Mock implementation of the EpochCacheInterface used to satisfy dependencies of AztecNodeService.
7
+ * Since in TXE we don't validate transactions, mock suffices here.
8
+ */
9
+ export class MockEpochCache implements EpochCacheInterface {
10
+ getCommittee(): Promise<EpochCommitteeInfo> {
11
+ return Promise.resolve({
12
+ committee: undefined,
13
+ seed: 0n,
14
+ epoch: EpochNumber.ZERO,
15
+ isEscapeHatchOpen: false,
16
+ });
17
+ }
18
+
19
+ getEpochAndSlotNow(): EpochAndSlot & { nowMs: bigint } {
20
+ return {
21
+ epoch: EpochNumber.ZERO,
22
+ slot: SlotNumber(0),
23
+ ts: 0n,
24
+ nowMs: 0n,
25
+ };
26
+ }
27
+
28
+ getEpochAndSlotInNextL1Slot(): EpochAndSlot & { now: bigint } {
29
+ return {
30
+ epoch: EpochNumber.ZERO,
31
+ slot: SlotNumber(0),
32
+ ts: 0n,
33
+ now: 0n,
34
+ };
35
+ }
36
+
37
+ getProposerIndexEncoding(_epoch: EpochNumber, _slot: SlotNumber, _seed: bigint): `0x${string}` {
38
+ return '0x00';
39
+ }
40
+
41
+ computeProposerIndex(_slot: SlotNumber, _epoch: EpochNumber, _seed: bigint, _size: bigint): bigint {
42
+ return 0n;
43
+ }
44
+
45
+ getCurrentAndNextSlot(): { currentSlot: SlotNumber; nextSlot: SlotNumber } {
46
+ return {
47
+ currentSlot: SlotNumber(0),
48
+ nextSlot: SlotNumber(0),
49
+ };
50
+ }
51
+
52
+ getProposerAttesterAddressInSlot(_slot: SlotNumber): Promise<EthAddress | undefined> {
53
+ return Promise.resolve(undefined);
54
+ }
55
+
56
+ isInCommittee(_slot: SlotTag, _validator: EthAddress): Promise<boolean> {
57
+ return Promise.resolve(false);
58
+ }
59
+
60
+ getRegisteredValidators(): Promise<EthAddress[]> {
61
+ return Promise.resolve([]);
62
+ }
63
+
64
+ filterInCommittee(_slot: SlotTag, _validators: EthAddress[]): Promise<EthAddress[]> {
65
+ return Promise.resolve([]);
66
+ }
67
+ }
@@ -0,0 +1,88 @@
1
+ import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
+ import type { L2Block } from '@aztec/stdlib/block';
5
+ import type {
6
+ MerkleTreeReadOperations,
7
+ MerkleTreeWriteOperations,
8
+ SnapshotDataKeys,
9
+ WorldStateSynchronizer,
10
+ WorldStateSynchronizerStatus,
11
+ } from '@aztec/stdlib/interfaces/server';
12
+ import { NativeWorldStateService } from '@aztec/world-state/native';
13
+
14
+ export class TXESynchronizer implements WorldStateSynchronizer {
15
+ // This works when set to 1 as well.
16
+ private blockNumber = BlockNumber.ZERO;
17
+
18
+ constructor(public nativeWorldStateService: NativeWorldStateService) {}
19
+
20
+ static async create() {
21
+ const nativeWorldStateService = await NativeWorldStateService.tmp();
22
+
23
+ return new this(nativeWorldStateService);
24
+ }
25
+
26
+ public async handleL2Block(block: L2Block) {
27
+ await this.nativeWorldStateService.handleL2BlockAndMessages(
28
+ block,
29
+ Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero),
30
+ );
31
+
32
+ this.blockNumber = block.header.globalVariables.blockNumber;
33
+ }
34
+
35
+ /**
36
+ * Forces an immediate sync to an optionally provided minimum block number
37
+ * @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
38
+ * @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
39
+ * @returns A promise that resolves with the block number the world state was synced to
40
+ */
41
+ public syncImmediate(_minBlockNumber?: BlockNumber, _skipThrowIfTargetNotReached?: boolean): Promise<BlockNumber> {
42
+ return Promise.resolve(this.blockNumber);
43
+ }
44
+
45
+ /** Returns an instance of MerkleTreeAdminOperations that will not include uncommitted data. */
46
+ public getCommitted(): MerkleTreeReadOperations {
47
+ return this.nativeWorldStateService.getCommitted();
48
+ }
49
+
50
+ /** Forks the world state at the given block number, defaulting to the latest one. */
51
+ public fork(block?: number): Promise<MerkleTreeWriteOperations> {
52
+ return this.nativeWorldStateService.fork(block ? BlockNumber(block) : undefined);
53
+ }
54
+
55
+ /** Gets a handle that allows reading the state as it was at the given block number. */
56
+ public getSnapshot(blockNumber: number): MerkleTreeReadOperations {
57
+ return this.nativeWorldStateService.getSnapshot(BlockNumber(blockNumber));
58
+ }
59
+
60
+ /** Backups the db to the target path. */
61
+ public backupTo(dstPath: string, compact?: boolean): Promise<Record<Exclude<SnapshotDataKeys, 'archiver'>, string>> {
62
+ return this.nativeWorldStateService.backupTo(dstPath, compact);
63
+ }
64
+
65
+ public start(): Promise<void> {
66
+ throw new Error('TXE Synchronizer does not implement "start"');
67
+ }
68
+
69
+ public status(): Promise<WorldStateSynchronizerStatus> {
70
+ throw new Error('TXE Synchronizer does not implement "status"');
71
+ }
72
+
73
+ public stop(): Promise<void> {
74
+ throw new Error('TXE Synchronizer does not implement "stop"');
75
+ }
76
+
77
+ public stopSync(): Promise<void> {
78
+ throw new Error('TXE Synchronizer does not implement "stopSync"');
79
+ }
80
+
81
+ public resumeSync(): void {
82
+ throw new Error('TXE Synchronizer does not implement "resumeSync"');
83
+ }
84
+
85
+ public clear(): Promise<void> {
86
+ throw new Error('TXE Synchronizer does not implement "clear"');
87
+ }
88
+ }