@aztec/txe 0.0.1-commit.1142ef1 → 0.0.1-commit.11bf3dd6e
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.
- package/dest/constants.d.ts +1 -2
- package/dest/constants.d.ts.map +1 -1
- package/dest/constants.js +0 -1
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +88 -54
- package/dest/oracle/interfaces.d.ts +29 -28
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +13 -13
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +16 -16
- package/dest/oracle/txe_oracle_top_level_context.d.ts +28 -22
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +165 -71
- package/dest/rpc_translator.d.ts +125 -81
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +426 -179
- package/dest/state_machine/archiver.d.ts +20 -69
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +36 -179
- package/dest/state_machine/dummy_p2p_client.d.ts +18 -13
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +33 -18
- package/dest/state_machine/global_variable_builder.d.ts +9 -4
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +9 -3
- package/dest/state_machine/index.d.ts +7 -5
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +40 -13
- package/dest/state_machine/mock_epoch_cache.d.ts +25 -8
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +46 -9
- package/dest/state_machine/synchronizer.d.ts +6 -6
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +3 -3
- package/dest/txe_session.d.ts +12 -6
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +115 -28
- package/dest/util/encoding.d.ts +88 -18
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +4 -0
- package/dest/util/txe_public_contract_data_source.d.ts +2 -3
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +6 -25
- package/dest/utils/block_creation.d.ts +4 -4
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +18 -4
- package/dest/utils/tx_effect_creation.d.ts +2 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +3 -6
- package/package.json +16 -16
- package/src/constants.ts +0 -1
- package/src/index.ts +89 -52
- package/src/oracle/interfaces.ts +32 -31
- package/src/oracle/txe_oracle_public_context.ts +16 -18
- package/src/oracle/txe_oracle_top_level_context.ts +208 -123
- package/src/rpc_translator.ts +493 -204
- package/src/state_machine/archiver.ts +38 -234
- package/src/state_machine/dummy_p2p_client.ts +46 -24
- package/src/state_machine/global_variable_builder.ts +18 -3
- package/src/state_machine/index.ts +56 -12
- package/src/state_machine/mock_epoch_cache.ts +57 -14
- package/src/state_machine/synchronizer.ts +5 -5
- package/src/txe_session.ts +132 -88
- package/src/util/encoding.ts +5 -0
- package/src/util/txe_public_contract_data_source.ts +10 -38
- package/src/utils/block_creation.ts +19 -16
- package/src/utils/tx_effect_creation.ts +3 -11
- package/dest/util/txe_contract_store.d.ts +0 -12
- package/dest/util/txe_contract_store.d.ts.map +0 -1
- package/dest/util/txe_contract_store.js +0 -22
- package/src/util/txe_contract_store.ts +0 -36
|
@@ -1,216 +1,48 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ArchiverDataSourceBase, ArchiverDataStoreUpdater, KVArchiverDataStore } from '@aztec/archiver';
|
|
2
2
|
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
3
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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);
|
|
100
|
-
|
|
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
|
-
}
|
|
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);
|
|
187
18
|
|
|
188
|
-
|
|
189
|
-
|
|
19
|
+
constructor(db: AztecAsyncKVStore) {
|
|
20
|
+
const store = new KVArchiverDataStore(db, 9999);
|
|
21
|
+
super(store);
|
|
190
22
|
}
|
|
191
23
|
|
|
192
|
-
public
|
|
193
|
-
|
|
24
|
+
public async addCheckpoints(checkpoints: PublishedCheckpoint[], result?: ValidateCheckpointResult): Promise<void> {
|
|
25
|
+
await this.updater.addCheckpoints(checkpoints, result);
|
|
194
26
|
}
|
|
195
27
|
|
|
196
|
-
public
|
|
197
|
-
throw new Error('TXE Archiver does not implement "
|
|
28
|
+
public getRollupAddress(): Promise<EthAddress> {
|
|
29
|
+
throw new Error('TXE Archiver does not implement "getRollupAddress"');
|
|
198
30
|
}
|
|
199
31
|
|
|
200
|
-
public
|
|
201
|
-
throw new Error('TXE Archiver does not implement "
|
|
32
|
+
public getRegistryAddress(): Promise<EthAddress> {
|
|
33
|
+
throw new Error('TXE Archiver does not implement "getRegistryAddress"');
|
|
202
34
|
}
|
|
203
35
|
|
|
204
|
-
public
|
|
205
|
-
throw new Error('TXE Archiver does not implement "
|
|
36
|
+
public getL1Constants(): Promise<L1RollupConstants> {
|
|
37
|
+
throw new Error('TXE Archiver does not implement "getL1Constants"');
|
|
206
38
|
}
|
|
207
39
|
|
|
208
|
-
public
|
|
209
|
-
|
|
40
|
+
public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
|
|
41
|
+
return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
|
|
210
42
|
}
|
|
211
43
|
|
|
212
|
-
public
|
|
213
|
-
throw new Error('TXE Archiver does not implement "
|
|
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
|
-
|
|
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
|
}
|
|
@@ -242,53 +76,23 @@ export class TXEArchiver extends ArchiverStoreHelper implements L2BlockSource {
|
|
|
242
76
|
proven: tipId,
|
|
243
77
|
finalized: tipId,
|
|
244
78
|
checkpointed: tipId,
|
|
79
|
+
proposedCheckpoint: tipId,
|
|
245
80
|
};
|
|
246
81
|
}
|
|
247
82
|
|
|
248
|
-
public
|
|
249
|
-
throw new Error('TXE Archiver does not implement "
|
|
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"');
|
|
83
|
+
public getSyncedL2SlotNumber(): Promise<SlotNumber | undefined> {
|
|
84
|
+
throw new Error('TXE Archiver does not implement "getSyncedL2SlotNumber"');
|
|
258
85
|
}
|
|
259
86
|
|
|
260
|
-
public
|
|
261
|
-
throw new Error('TXE Archiver does not implement "
|
|
87
|
+
public getSyncedL2EpochNumber(): Promise<EpochNumber | undefined> {
|
|
88
|
+
throw new Error('TXE Archiver does not implement "getSyncedL2EpochNumber"');
|
|
262
89
|
}
|
|
263
90
|
|
|
264
|
-
public
|
|
265
|
-
throw new Error('TXE Archiver does not implement "
|
|
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);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
public override getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
|
|
281
|
-
return Promise.resolve({ valid: true });
|
|
282
|
-
}
|
|
283
|
-
|
|
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.');
|
|
91
|
+
public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
|
|
92
|
+
throw new Error('TXE Archiver does not implement "isEpochComplete"');
|
|
289
93
|
}
|
|
290
94
|
|
|
291
|
-
|
|
292
|
-
throw new Error('TXE Archiver does not implement "
|
|
95
|
+
public syncImmediate(): Promise<void> {
|
|
96
|
+
throw new Error('TXE Archiver does not implement "syncImmediate"');
|
|
293
97
|
}
|
|
294
98
|
}
|
|
@@ -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
|
|
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
|
}
|
|
@@ -55,8 +61,12 @@ export class DummyP2P implements P2P {
|
|
|
55
61
|
throw new Error('DummyP2P does not implement "registerBlockProposalHandler"');
|
|
56
62
|
}
|
|
57
63
|
|
|
58
|
-
public
|
|
59
|
-
throw new Error('DummyP2P does not implement "
|
|
64
|
+
public registerValidatorCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
|
|
65
|
+
throw new Error('DummyP2P does not implement "registerValidatorCheckpointProposalHandler"');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public registerAllNodesCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
|
|
69
|
+
throw new Error('DummyP2P does not implement "registerAllNodesCheckpointProposalHandler"');
|
|
60
70
|
}
|
|
61
71
|
|
|
62
72
|
public requestTxs(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
@@ -71,8 +81,8 @@ export class DummyP2P implements P2P {
|
|
|
71
81
|
throw new Error('DummyP2P does not implement "sendTx"');
|
|
72
82
|
}
|
|
73
83
|
|
|
74
|
-
public
|
|
75
|
-
throw new Error('DummyP2P does not implement "
|
|
84
|
+
public handleFailedExecution(_txHashes: TxHash[]): Promise<void> {
|
|
85
|
+
throw new Error('DummyP2P does not implement "handleFailedExecution"');
|
|
76
86
|
}
|
|
77
87
|
|
|
78
88
|
public getTxByHashFromPool(_txHash: TxHash): Promise<Tx | undefined> {
|
|
@@ -97,6 +107,10 @@ export class DummyP2P implements P2P {
|
|
|
97
107
|
throw new Error('DummyP2P does not implement "iteratePendingTxs"');
|
|
98
108
|
}
|
|
99
109
|
|
|
110
|
+
public iterateEligiblePendingTxs(): AsyncIterableIterator<Tx> {
|
|
111
|
+
throw new Error('DummyP2P does not implement "iterateEligiblePendingTxs"');
|
|
112
|
+
}
|
|
113
|
+
|
|
100
114
|
public getPendingTxCount(): Promise<number> {
|
|
101
115
|
throw new Error('DummyP2P does not implement "getPendingTxCount"');
|
|
102
116
|
}
|
|
@@ -125,6 +139,10 @@ export class DummyP2P implements P2P {
|
|
|
125
139
|
throw new Error('DummyP2P does not implement "isP2PClient"');
|
|
126
140
|
}
|
|
127
141
|
|
|
142
|
+
public getTxProvider(): ITxProvider {
|
|
143
|
+
throw new Error('DummyP2P does not implement "getTxProvider"');
|
|
144
|
+
}
|
|
145
|
+
|
|
128
146
|
public getTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
|
|
129
147
|
throw new Error('DummyP2P does not implement "getTxsByHash"');
|
|
130
148
|
}
|
|
@@ -133,8 +151,8 @@ export class DummyP2P implements P2P {
|
|
|
133
151
|
throw new Error('DummyP2P does not implement "getCheckpointAttestationsForSlot"');
|
|
134
152
|
}
|
|
135
153
|
|
|
136
|
-
public
|
|
137
|
-
throw new Error('DummyP2P does not implement "
|
|
154
|
+
public addOwnCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
|
|
155
|
+
throw new Error('DummyP2P does not implement "addOwnCheckpointAttestations"');
|
|
138
156
|
}
|
|
139
157
|
|
|
140
158
|
public getL2BlockHash(_number: number): Promise<string | undefined> {
|
|
@@ -157,14 +175,6 @@ export class DummyP2P implements P2P {
|
|
|
157
175
|
throw new Error('DummyP2P does not implement "sync"');
|
|
158
176
|
}
|
|
159
177
|
|
|
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
178
|
public getTxsByHashFromPool(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
169
179
|
throw new Error('DummyP2P does not implement "getTxsByHashFromPool"');
|
|
170
180
|
}
|
|
@@ -173,10 +183,6 @@ export class DummyP2P implements P2P {
|
|
|
173
183
|
throw new Error('DummyP2P does not implement "hasTxsInPool"');
|
|
174
184
|
}
|
|
175
185
|
|
|
176
|
-
public addTxsToPool(_txs: Tx[]): Promise<number> {
|
|
177
|
-
throw new Error('DummyP2P does not implement "addTxs"');
|
|
178
|
-
}
|
|
179
|
-
|
|
180
186
|
public getSyncedLatestBlockNum(): Promise<number> {
|
|
181
187
|
throw new Error('DummyP2P does not implement "getSyncedLatestBlockNum"');
|
|
182
188
|
}
|
|
@@ -189,8 +195,12 @@ export class DummyP2P implements P2P {
|
|
|
189
195
|
throw new Error('DummyP2P does not implement "getSyncedLatestSlot"');
|
|
190
196
|
}
|
|
191
197
|
|
|
192
|
-
|
|
193
|
-
throw new Error('DummyP2P does not implement "
|
|
198
|
+
protectTxs(_txHashes: TxHash[], _blockHeader: BlockHeader): Promise<TxHash[]> {
|
|
199
|
+
throw new Error('DummyP2P does not implement "protectTxs".');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
prepareForSlot(_slotNumber: SlotNumber): Promise<void> {
|
|
203
|
+
return Promise.resolve();
|
|
194
204
|
}
|
|
195
205
|
|
|
196
206
|
addReqRespSubProtocol(
|
|
@@ -206,4 +216,16 @@ export class DummyP2P implements P2P {
|
|
|
206
216
|
|
|
207
217
|
//This is no-op
|
|
208
218
|
public registerThisValidatorAddresses(_address: EthAddress[]): void {}
|
|
219
|
+
|
|
220
|
+
public registerDuplicateProposalCallback(_callback: P2PDuplicateProposalCallback): void {
|
|
221
|
+
throw new Error('DummyP2P does not implement "registerDuplicateProposalCallback"');
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
public registerDuplicateAttestationCallback(_callback: P2PDuplicateAttestationCallback): void {
|
|
225
|
+
throw new Error('DummyP2P does not implement "registerDuplicateAttestationCallback"');
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
public hasBlockProposalsForSlot(_slot: SlotNumber): Promise<boolean> {
|
|
229
|
+
throw new Error('DummyP2P does not implement "hasBlockProposalsForSlot"');
|
|
230
|
+
}
|
|
209
231
|
}
|
|
@@ -1,15 +1,29 @@
|
|
|
1
|
+
import type { SimulationOverridesPlan } from '@aztec/ethereum/contracts';
|
|
1
2
|
import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { times } from '@aztec/foundation/collection';
|
|
2
4
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
-
import { GasFees } from '@aztec/stdlib/gas';
|
|
6
|
+
import { FEE_ORACLE_LAG, GasFees } from '@aztec/stdlib/gas';
|
|
5
7
|
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
6
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
type CheckpointGlobalVariables,
|
|
10
|
+
type FeeProvider,
|
|
11
|
+
type GlobalVariableBuilder,
|
|
12
|
+
GlobalVariables,
|
|
13
|
+
} from '@aztec/stdlib/tx';
|
|
7
14
|
|
|
8
|
-
|
|
15
|
+
/** Simple FeeProvider for TXE that returns zero fees. */
|
|
16
|
+
export class TXEFeeProvider implements FeeProvider {
|
|
9
17
|
public getCurrentMinFees(): Promise<GasFees> {
|
|
10
18
|
return Promise.resolve(new GasFees(0, 0));
|
|
11
19
|
}
|
|
12
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 {
|
|
13
27
|
public buildGlobalVariables(
|
|
14
28
|
_blockNumber: BlockNumber,
|
|
15
29
|
_coinbase: EthAddress,
|
|
@@ -23,6 +37,7 @@ export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
|
|
|
23
37
|
_coinbase: EthAddress,
|
|
24
38
|
_feeRecipient: AztecAddress,
|
|
25
39
|
_slotNumber: SlotNumber,
|
|
40
|
+
_simulationOverridesPlan?: SimulationOverridesPlan,
|
|
26
41
|
): Promise<CheckpointGlobalVariables> {
|
|
27
42
|
const vars = makeGlobalVariables();
|
|
28
43
|
return Promise.resolve({
|
|
@@ -1,16 +1,19 @@
|
|
|
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
|
|
5
|
-
import {
|
|
6
|
+
import { type AnchorBlockStore, type ContractStore, ContractSyncService, type NoteStore } from '@aztec/pxe/server';
|
|
7
|
+
import { MessageContextService } from '@aztec/pxe/simulator';
|
|
6
8
|
import { L2Block } from '@aztec/stdlib/block';
|
|
7
|
-
import { L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
9
|
+
import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
8
10
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
11
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
9
12
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
10
13
|
|
|
11
14
|
import { TXEArchiver } from './archiver.js';
|
|
12
15
|
import { DummyP2P } from './dummy_p2p_client.js';
|
|
13
|
-
import { TXEGlobalVariablesBuilder } from './global_variable_builder.js';
|
|
16
|
+
import { TXEFeeProvider, TXEGlobalVariablesBuilder } from './global_variable_builder.js';
|
|
14
17
|
import { MockEpochCache } from './mock_epoch_cache.js';
|
|
15
18
|
import { TXESynchronizer } from './synchronizer.js';
|
|
16
19
|
|
|
@@ -23,13 +26,17 @@ export class TXEStateMachine {
|
|
|
23
26
|
public synchronizer: TXESynchronizer,
|
|
24
27
|
public archiver: TXEArchiver,
|
|
25
28
|
public anchorBlockStore: AnchorBlockStore,
|
|
29
|
+
public contractSyncService: ContractSyncService,
|
|
30
|
+
public messageContextService: MessageContextService,
|
|
26
31
|
) {}
|
|
27
32
|
|
|
28
|
-
public static async create(
|
|
29
|
-
|
|
33
|
+
public static async create(
|
|
34
|
+
archiver: TXEArchiver,
|
|
35
|
+
anchorBlockStore: AnchorBlockStore,
|
|
36
|
+
contractStore: ContractStore,
|
|
37
|
+
noteStore: NoteStore,
|
|
38
|
+
) {
|
|
30
39
|
const synchronizer = await TXESynchronizer.create();
|
|
31
|
-
const anchorBlockStore = new AnchorBlockStore(db);
|
|
32
|
-
|
|
33
40
|
const aztecNodeConfig = {} as AztecNodeConfig;
|
|
34
41
|
|
|
35
42
|
const log = createLogger('txe_node');
|
|
@@ -45,21 +52,55 @@ export class TXEStateMachine {
|
|
|
45
52
|
undefined,
|
|
46
53
|
undefined,
|
|
47
54
|
undefined,
|
|
55
|
+
undefined,
|
|
48
56
|
VERSION,
|
|
49
57
|
CHAIN_ID,
|
|
50
58
|
new TXEGlobalVariablesBuilder(),
|
|
59
|
+
new TXEFeeProvider(),
|
|
51
60
|
new MockEpochCache(),
|
|
52
61
|
getPackageVersion() ?? '',
|
|
53
62
|
new TestCircuitVerifier(),
|
|
63
|
+
new TestCircuitVerifier(),
|
|
54
64
|
undefined,
|
|
55
65
|
log,
|
|
56
66
|
);
|
|
57
67
|
|
|
58
|
-
|
|
68
|
+
const contractSyncService = new ContractSyncService(
|
|
69
|
+
node,
|
|
70
|
+
contractStore,
|
|
71
|
+
noteStore,
|
|
72
|
+
createLogger('txe:contract_sync'),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const messageContextService = new MessageContextService(node);
|
|
76
|
+
|
|
77
|
+
return new this(node, synchronizer, archiver, anchorBlockStore, contractSyncService, messageContextService);
|
|
59
78
|
}
|
|
60
79
|
|
|
61
80
|
public async handleL2Block(block: L2Block) {
|
|
62
|
-
|
|
81
|
+
// Create a checkpoint from the block manually.
|
|
82
|
+
// TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
|
|
83
|
+
// This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
|
|
84
|
+
const checkpointNumber = CheckpointNumber.fromBlockNumber(block.number);
|
|
85
|
+
const checkpoint = new Checkpoint(
|
|
86
|
+
block.archive,
|
|
87
|
+
CheckpointHeader.from({
|
|
88
|
+
lastArchiveRoot: block.header.lastArchive.root,
|
|
89
|
+
inHash: Fr.ZERO,
|
|
90
|
+
blobsHash: Fr.ZERO,
|
|
91
|
+
blockHeadersHash: Fr.ZERO,
|
|
92
|
+
epochOutHash: Fr.ZERO,
|
|
93
|
+
slotNumber: block.header.globalVariables.slotNumber,
|
|
94
|
+
timestamp: block.header.globalVariables.timestamp,
|
|
95
|
+
coinbase: block.header.globalVariables.coinbase,
|
|
96
|
+
feeRecipient: block.header.globalVariables.feeRecipient,
|
|
97
|
+
gasFees: block.header.globalVariables.gasFees,
|
|
98
|
+
totalManaUsed: block.header.totalManaUsed,
|
|
99
|
+
}),
|
|
100
|
+
[block],
|
|
101
|
+
checkpointNumber,
|
|
102
|
+
);
|
|
103
|
+
|
|
63
104
|
const publishedCheckpoint = new PublishedCheckpoint(
|
|
64
105
|
checkpoint,
|
|
65
106
|
new L1PublishedData(
|
|
@@ -69,10 +110,13 @@ export class TXEStateMachine {
|
|
|
69
110
|
),
|
|
70
111
|
[],
|
|
71
112
|
);
|
|
113
|
+
// Wipe contract sync cache when anchor block changes (mirrors BlockSynchronizer behavior)
|
|
114
|
+
this.contractSyncService.wipe();
|
|
115
|
+
|
|
72
116
|
await Promise.all([
|
|
73
|
-
this.synchronizer.handleL2Block(block
|
|
117
|
+
this.synchronizer.handleL2Block(block),
|
|
74
118
|
this.archiver.addCheckpoints([publishedCheckpoint], undefined),
|
|
75
|
-
this.anchorBlockStore.setHeader(block.
|
|
119
|
+
this.anchorBlockStore.setHeader(block.header),
|
|
76
120
|
]);
|
|
77
121
|
}
|
|
78
122
|
}
|