@aztec/simulator 0.0.1-commit.ff7989d6c → 0.0.1-commit.fff30aa
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/private/circuit_recording/circuit_recorder.js +2 -2
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +6 -5
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +10 -10
- package/dest/public/fixtures/utils.d.ts +2 -2
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +6 -6
- package/dest/public/hinting_db_sources.d.ts +4 -4
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +6 -5
- package/dest/public/public_db_sources.d.ts +3 -3
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +9 -9
- package/dest/public/public_processor/guarded_merkle_tree.d.ts +4 -4
- package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
- package/dest/public/public_processor/guarded_merkle_tree.js +4 -4
- package/dest/public/public_processor/public_processor.d.ts +5 -4
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +42 -38
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +1 -1
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +2 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +2 -3
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +2 -2
- package/dest/public/public_tx_simulator/factories.d.ts +2 -2
- package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/factories.js +2 -2
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +2 -8
- package/dest/public/public_tx_simulator/public_tx_simulator.js +4 -4
- package/package.json +16 -16
- package/src/private/circuit_recording/circuit_recorder.ts +2 -2
- package/src/public/fixtures/public_tx_simulation_tester.ts +24 -6
- package/src/public/fixtures/utils.ts +13 -8
- package/src/public/hinting_db_sources.ts +8 -6
- package/src/public/public_db_sources.ts +11 -13
- package/src/public/public_processor/guarded_merkle_tree.ts +5 -5
- package/src/public/public_processor/public_processor.ts +50 -43
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +2 -1
- package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +2 -3
- package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +2 -2
- package/src/public/public_tx_simulator/factories.ts +2 -1
- package/src/public/public_tx_simulator/public_tx_context.ts +2 -8
- package/src/public/public_tx_simulator/public_tx_simulator.ts +5 -5
|
@@ -2,10 +2,8 @@ import {
|
|
|
2
2
|
CONTRACT_CLASS_PUBLISHED_MAGIC_VALUE,
|
|
3
3
|
CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS,
|
|
4
4
|
CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
DEFAULT_TEARDOWN_DA_GAS_LIMIT,
|
|
8
|
-
DEFAULT_TEARDOWN_L2_GAS_LIMIT,
|
|
5
|
+
MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT,
|
|
6
|
+
MAX_PROCESSABLE_L2_GAS,
|
|
9
7
|
PRIVATE_LOG_SIZE_IN_FIELDS,
|
|
10
8
|
} from '@aztec/constants';
|
|
11
9
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
@@ -14,7 +12,13 @@ import { CONTRACT_INSTANCE_PUBLISHED_EVENT_TAG } from '@aztec/protocol-contracts
|
|
|
14
12
|
import { bufferAsFields } from '@aztec/stdlib/abi';
|
|
15
13
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
16
14
|
import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
17
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
FALLBACK_TEARDOWN_DA_GAS_LIMIT,
|
|
17
|
+
FALLBACK_TEARDOWN_L2_GAS_LIMIT,
|
|
18
|
+
Gas,
|
|
19
|
+
GasFees,
|
|
20
|
+
GasSettings,
|
|
21
|
+
} from '@aztec/stdlib/gas';
|
|
18
22
|
import { siloNullifier } from '@aztec/stdlib/hash';
|
|
19
23
|
import {
|
|
20
24
|
LogHash,
|
|
@@ -62,13 +66,14 @@ export async function createTxForPublicCalls(
|
|
|
62
66
|
feePayer = AztecAddress.zero(),
|
|
63
67
|
gasUsedByPrivate: Gas = Gas.empty(),
|
|
64
68
|
globals: GlobalVariables = GlobalVariables.empty(),
|
|
69
|
+
gasLimits?: Gas,
|
|
65
70
|
): Promise<Tx> {
|
|
66
71
|
assert(
|
|
67
72
|
setupCallRequests.length > 0 || appCallRequests.length > 0 || teardownCallRequest !== undefined,
|
|
68
73
|
"Can't create public tx with no enqueued calls",
|
|
69
74
|
);
|
|
70
75
|
// use max limits
|
|
71
|
-
|
|
76
|
+
gasLimits = gasLimits ?? new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
|
|
72
77
|
|
|
73
78
|
const forPublic = PartialPrivateTailPublicInputsForPublic.empty();
|
|
74
79
|
|
|
@@ -128,7 +133,7 @@ export async function createTxForPublicCalls(
|
|
|
128
133
|
|
|
129
134
|
const maxFeesPerGas = feePayer.isZero() ? GasFees.empty() : new GasFees(10, 10);
|
|
130
135
|
const teardownGasLimits = teardownCallRequest
|
|
131
|
-
? new Gas(
|
|
136
|
+
? new Gas(FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT)
|
|
132
137
|
: Gas.empty();
|
|
133
138
|
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, maxFeesPerGas, GasFees.empty());
|
|
134
139
|
const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
|
|
@@ -163,7 +168,7 @@ export async function createTxForPrivateOnly(
|
|
|
163
168
|
gasUsedByPrivate: Gas = new Gas(10, 10),
|
|
164
169
|
): Promise<Tx> {
|
|
165
170
|
// use max limits
|
|
166
|
-
const gasLimits = new Gas(
|
|
171
|
+
const gasLimits = new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
|
|
167
172
|
|
|
168
173
|
const forRollup = PartialPrivateTailPublicInputsForRollup.empty();
|
|
169
174
|
|
|
@@ -410,12 +410,12 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
|
|
|
410
410
|
}
|
|
411
411
|
}
|
|
412
412
|
|
|
413
|
-
public async createCheckpoint(): Promise<
|
|
413
|
+
public async createCheckpoint(): Promise<number> {
|
|
414
414
|
const actionCounter = this.checkpointActionCounter++;
|
|
415
415
|
const oldCheckpointId = this.getCurrentCheckpointId();
|
|
416
416
|
const treesStateHash = await this.getTreesStateHash();
|
|
417
417
|
|
|
418
|
-
await this.db.createCheckpoint();
|
|
418
|
+
const depth = await this.db.createCheckpoint();
|
|
419
419
|
this.checkpointStack.push(this.nextCheckpointId++);
|
|
420
420
|
const newCheckpointId = this.getCurrentCheckpointId();
|
|
421
421
|
|
|
@@ -424,14 +424,16 @@ export class HintingMerkleWriteOperations implements MerkleTreeWriteOperations {
|
|
|
424
424
|
HintingMerkleWriteOperations.log.trace(
|
|
425
425
|
`[createCheckpoint:${actionCounter}] Checkpoint evolved ${oldCheckpointId} -> ${newCheckpointId} at trees state ${treesStateHash}.`,
|
|
426
426
|
);
|
|
427
|
+
|
|
428
|
+
return depth;
|
|
427
429
|
}
|
|
428
430
|
|
|
429
|
-
public
|
|
430
|
-
throw new Error('
|
|
431
|
+
public commitAllCheckpointsTo(_depth: number): Promise<void> {
|
|
432
|
+
throw new Error('commitAllCheckpointsTo is not supported in HintingMerkleWriteOperations.');
|
|
431
433
|
}
|
|
432
434
|
|
|
433
|
-
public
|
|
434
|
-
throw new Error('
|
|
435
|
+
public revertAllCheckpointsTo(_depth: number): Promise<void> {
|
|
436
|
+
throw new Error('revertAllCheckpointsTo is not supported in HintingMerkleWriteOperations.');
|
|
435
437
|
}
|
|
436
438
|
|
|
437
439
|
public async commitCheckpoint(): Promise<void> {
|
|
@@ -55,10 +55,10 @@ export class PublicContractsDB implements PublicContractsDBInterface {
|
|
|
55
55
|
this.log = createLogger('simulator:contracts-data-source', bindings);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
public
|
|
58
|
+
public addContracts(contractDeploymentData: ContractDeploymentData): void {
|
|
59
59
|
const currentState = this.getCurrentState();
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
this.addContractClassesFromEvents(
|
|
62
62
|
ContractClassPublishedEvent.extractContractClassEvents(contractDeploymentData.getContractClassLogs()),
|
|
63
63
|
currentState,
|
|
64
64
|
);
|
|
@@ -69,10 +69,10 @@ export class PublicContractsDB implements PublicContractsDBInterface {
|
|
|
69
69
|
);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
public
|
|
72
|
+
public addNewContracts(tx: Tx): void {
|
|
73
73
|
const contractDeploymentData = AllContractDeploymentData.fromTx(tx);
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
this.addContracts(contractDeploymentData.getNonRevertibleContractDeploymentData());
|
|
75
|
+
this.addContracts(contractDeploymentData.getRevertibleContractDeploymentData());
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/**
|
|
@@ -174,17 +174,15 @@ export class PublicContractsDB implements PublicContractsDBInterface {
|
|
|
174
174
|
return await this.dataSource.getDebugFunctionName(address, selector);
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
private
|
|
177
|
+
private addContractClassesFromEvents(
|
|
178
178
|
contractClassEvents: ContractClassPublishedEvent[],
|
|
179
179
|
state: ContractsDbCheckpoint,
|
|
180
180
|
) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}),
|
|
187
|
-
);
|
|
181
|
+
for (const event of contractClassEvents) {
|
|
182
|
+
this.log.debug(`Adding class ${event.contractClassId.toString()} to contract state`);
|
|
183
|
+
const contractClass = event.toContractClassPublic();
|
|
184
|
+
state.addClass(event.contractClassId, contractClass);
|
|
185
|
+
}
|
|
188
186
|
}
|
|
189
187
|
|
|
190
188
|
private addContractInstancesFromEvents(
|
|
@@ -134,7 +134,7 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
|
|
|
134
134
|
): Promise<(BlockNumber | undefined)[]> {
|
|
135
135
|
return this.guardAndPush(() => this.target.getBlockNumbersForLeafIndices(treeId, leafIndices));
|
|
136
136
|
}
|
|
137
|
-
createCheckpoint(): Promise<
|
|
137
|
+
createCheckpoint(): Promise<number> {
|
|
138
138
|
return this.guardAndPush(() => this.target.createCheckpoint());
|
|
139
139
|
}
|
|
140
140
|
commitCheckpoint(): Promise<void> {
|
|
@@ -143,11 +143,11 @@ export class GuardedMerkleTreeOperations implements MerkleTreeWriteOperations {
|
|
|
143
143
|
revertCheckpoint(): Promise<void> {
|
|
144
144
|
return this.guardAndPush(() => this.target.revertCheckpoint());
|
|
145
145
|
}
|
|
146
|
-
|
|
147
|
-
return this.guardAndPush(() => this.target.
|
|
146
|
+
commitAllCheckpointsTo(depth: number): Promise<void> {
|
|
147
|
+
return this.guardAndPush(() => this.target.commitAllCheckpointsTo(depth));
|
|
148
148
|
}
|
|
149
|
-
|
|
150
|
-
return this.guardAndPush(() => this.target.
|
|
149
|
+
revertAllCheckpointsTo(depth: number): Promise<void> {
|
|
150
|
+
return this.guardAndPush(() => this.target.revertAllCheckpointsTo(depth));
|
|
151
151
|
}
|
|
152
152
|
findSiblingPaths<ID extends MerkleTreeId>(
|
|
153
153
|
treeId: ID,
|
|
@@ -25,7 +25,7 @@ import type {
|
|
|
25
25
|
PublicProcessorValidator,
|
|
26
26
|
SequencerConfig,
|
|
27
27
|
} from '@aztec/stdlib/interfaces/server';
|
|
28
|
-
import type
|
|
28
|
+
import { type DebugLog, type DebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
29
29
|
import { ProvingRequestType } from '@aztec/stdlib/proofs';
|
|
30
30
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
31
31
|
import {
|
|
@@ -140,6 +140,7 @@ export class PublicProcessor implements Traceable {
|
|
|
140
140
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
141
141
|
private log: Logger,
|
|
142
142
|
private opts: Pick<SequencerConfig, 'fakeProcessingDelayPerTxMs' | 'fakeThrowAfterProcessingTxCount'> = {},
|
|
143
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
143
144
|
) {
|
|
144
145
|
this.metrics = new PublicProcessorMetrics(telemetryClient, 'PublicProcessor');
|
|
145
146
|
}
|
|
@@ -159,8 +160,8 @@ export class PublicProcessor implements Traceable {
|
|
|
159
160
|
txs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
160
161
|
limits: PublicProcessorLimits = {},
|
|
161
162
|
validator: PublicProcessorValidator = {},
|
|
162
|
-
): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[],
|
|
163
|
-
const { maxTransactions,
|
|
163
|
+
): Promise<[ProcessedTx[], FailedTx[], Tx[], NestedProcessReturnValues[], DebugLog[]]> {
|
|
164
|
+
const { maxTransactions, deadline, maxBlockGas, maxBlobFields, isBuildingProposal } = limits;
|
|
164
165
|
const { preprocessValidator, nullifierCache } = validator;
|
|
165
166
|
const result: ProcessedTx[] = [];
|
|
166
167
|
const usedTxs: Tx[] = [];
|
|
@@ -187,22 +188,23 @@ export class PublicProcessor implements Traceable {
|
|
|
187
188
|
break;
|
|
188
189
|
}
|
|
189
190
|
|
|
190
|
-
// Skip this tx if it'd exceed max block size
|
|
191
191
|
const txHash = tx.getTxHash().toString();
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
192
|
+
|
|
193
|
+
// Skip this tx if its estimated blob fields would exceed the limit.
|
|
194
|
+
// Only done during proposal building: during re-execution we must process the exact txs from the proposal.
|
|
195
|
+
const txBlobFields = tx.getPrivateTxEffectsSizeInFields();
|
|
196
|
+
if (isBuildingProposal && maxBlobFields !== undefined && totalBlobFields + txBlobFields > maxBlobFields) {
|
|
197
|
+
this.log.warn(
|
|
198
|
+
`Skipping tx ${txHash} with ${txBlobFields} fields from private side effects due to blob fields limit`,
|
|
199
|
+
{ txHash, txBlobFields, totalBlobFields, maxBlobFields },
|
|
200
|
+
);
|
|
200
201
|
continue;
|
|
201
202
|
}
|
|
202
203
|
|
|
203
|
-
// Skip this tx if its gas limit would exceed the block gas limit
|
|
204
|
+
// Skip this tx if its gas limit would exceed the block gas limit (either da or l2).
|
|
205
|
+
// Only done during proposal building: during re-execution we must process the exact txs from the proposal.
|
|
204
206
|
const txGasLimit = tx.data.constants.txContext.gasSettings.gasLimits;
|
|
205
|
-
if (maxBlockGas !== undefined && totalBlockGas.add(txGasLimit).gtAny(maxBlockGas)) {
|
|
207
|
+
if (isBuildingProposal && maxBlockGas !== undefined && totalBlockGas.add(txGasLimit).gtAny(maxBlockGas)) {
|
|
206
208
|
this.log.warn(`Skipping processing of tx ${txHash} due to block gas limit`, {
|
|
207
209
|
txHash,
|
|
208
210
|
txGasLimit,
|
|
@@ -251,23 +253,9 @@ export class PublicProcessor implements Traceable {
|
|
|
251
253
|
}
|
|
252
254
|
|
|
253
255
|
const txBlobFields = processedTx.txEffect.getNumBlobFields();
|
|
254
|
-
|
|
255
|
-
// If the actual size of this tx would exceed block size, skip it
|
|
256
256
|
const txSize = txBlobFields * Fr.SIZE_IN_BYTES;
|
|
257
|
-
if (maxBlockSize !== undefined && totalSizeInBytes + txSize > maxBlockSize) {
|
|
258
|
-
this.log.debug(`Skipping processed tx ${txHash} sized ${txSize} due to max block size.`, {
|
|
259
|
-
txHash,
|
|
260
|
-
sizeInBytes: txSize,
|
|
261
|
-
totalSizeInBytes,
|
|
262
|
-
maxBlockSize,
|
|
263
|
-
});
|
|
264
|
-
// Need to revert the checkpoint here and don't go any further
|
|
265
|
-
await checkpoint.revert();
|
|
266
|
-
this.contractsDB.revertCheckpoint();
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
257
|
|
|
270
|
-
// If the actual blob fields of this tx would exceed the limit, skip it
|
|
258
|
+
// If the actual blob fields of this tx would exceed the limit, skip it.
|
|
271
259
|
// Note: maxBlobFields already accounts for block end blob fields and previous blocks in checkpoint.
|
|
272
260
|
if (maxBlobFields !== undefined && totalBlobFields + txBlobFields > maxBlobFields) {
|
|
273
261
|
this.log.debug(
|
|
@@ -285,6 +273,25 @@ export class PublicProcessor implements Traceable {
|
|
|
285
273
|
continue;
|
|
286
274
|
}
|
|
287
275
|
|
|
276
|
+
// During re-execution, check if the actual gas used by this tx would push the block over the gas limit.
|
|
277
|
+
// Unlike the proposal-building check (which uses declared gas limits pessimistically before processing),
|
|
278
|
+
// this uses actual gas and stops processing when the limit is exceeded.
|
|
279
|
+
if (
|
|
280
|
+
!isBuildingProposal &&
|
|
281
|
+
maxBlockGas !== undefined &&
|
|
282
|
+
totalBlockGas.add(processedTx.gasUsed.totalGas).gtAny(maxBlockGas)
|
|
283
|
+
) {
|
|
284
|
+
this.log.warn(`Stopping re-execution since tx ${txHash} would push block gas over limit`, {
|
|
285
|
+
txHash,
|
|
286
|
+
txGas: processedTx.gasUsed.totalGas,
|
|
287
|
+
totalBlockGas,
|
|
288
|
+
maxBlockGas,
|
|
289
|
+
});
|
|
290
|
+
await checkpoint.revert();
|
|
291
|
+
this.contractsDB.revertCheckpoint();
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
|
|
288
295
|
// FIXME(fcarreiro): it's ugly to have to notify the validator of nullifiers.
|
|
289
296
|
// I'd rather pass the validators the processedTx as well and let them deal with it.
|
|
290
297
|
nullifierCache?.addNullifiers(processedTx.txEffect.nullifiers.map(n => n.toBuffer()));
|
|
@@ -293,10 +300,15 @@ export class PublicProcessor implements Traceable {
|
|
|
293
300
|
returns = returns.concat(returnValues);
|
|
294
301
|
debugLogs.push(...txDebugLogs);
|
|
295
302
|
|
|
303
|
+
this.debugLogStore.storeLogs(processedTx.hash.toString(), txDebugLogs);
|
|
304
|
+
|
|
296
305
|
totalPublicGas = totalPublicGas.add(processedTx.gasUsed.publicGas);
|
|
297
306
|
totalBlockGas = totalBlockGas.add(processedTx.gasUsed.totalGas);
|
|
298
307
|
totalSizeInBytes += txSize;
|
|
299
308
|
totalBlobFields += txBlobFields;
|
|
309
|
+
|
|
310
|
+
// Commit the tx-level contracts checkpoint on success
|
|
311
|
+
this.contractsDB.commitCheckpoint();
|
|
300
312
|
} catch (err: any) {
|
|
301
313
|
if (err?.name === 'PublicProcessorTimeoutError') {
|
|
302
314
|
this.log.warn(`Stopping tx processing due to timeout.`);
|
|
@@ -316,14 +328,10 @@ export class PublicProcessor implements Traceable {
|
|
|
316
328
|
// 1. At least one outstanding checkpoint that has not been committed (the one created before we processed the tx).
|
|
317
329
|
// 2. Possible state updates on that checkpoint or any others created during execution.
|
|
318
330
|
|
|
319
|
-
//
|
|
320
|
-
//
|
|
321
|
-
//
|
|
322
|
-
await checkpoint.
|
|
323
|
-
|
|
324
|
-
// Now we want to revert any/all remaining checkpoints, destroying any outstanding state updates.
|
|
325
|
-
// This needs to be done directly on the underlying fork as the guarded fork has been stopped.
|
|
326
|
-
await this.guardedMerkleTree.getUnderlyingFork().revertAllCheckpoints();
|
|
331
|
+
// Revert all checkpoints at or above this checkpoint's depth (inclusive), destroying any outstanding state
|
|
332
|
+
// updates from this tx and any nested checkpoints created during execution. This preserves any checkpoints
|
|
333
|
+
// created by callers below our depth.
|
|
334
|
+
await checkpoint.revertToCheckpoint();
|
|
327
335
|
|
|
328
336
|
// Revert any contracts added to the DB for the tx.
|
|
329
337
|
this.contractsDB.revertCheckpoint();
|
|
@@ -335,9 +343,9 @@ export class PublicProcessor implements Traceable {
|
|
|
335
343
|
break;
|
|
336
344
|
}
|
|
337
345
|
|
|
338
|
-
// Roll back state to start of TX before proceeding to next TX
|
|
339
|
-
|
|
340
|
-
await
|
|
346
|
+
// Roll back state to start of TX before proceeding to next TX.
|
|
347
|
+
// Reverts all checkpoints at or above this checkpoint's depth, preserving any caller checkpoints below.
|
|
348
|
+
await checkpoint.revertToCheckpoint();
|
|
341
349
|
this.contractsDB.revertCheckpoint();
|
|
342
350
|
const errorMessage = err instanceof Error || err instanceof AssertionError ? err.message : 'Unknown error';
|
|
343
351
|
this.log.warn(`Failed to process tx ${txHash.toString()}: ${errorMessage} ${err?.stack}`);
|
|
@@ -349,7 +357,6 @@ export class PublicProcessor implements Traceable {
|
|
|
349
357
|
} finally {
|
|
350
358
|
// Base case is we always commit the checkpoint. Using the ForkCheckpoint means this has no effect if the tx was previously reverted
|
|
351
359
|
await checkpoint.commit();
|
|
352
|
-
this.contractsDB.commitCheckpointOkIfNone();
|
|
353
360
|
}
|
|
354
361
|
}
|
|
355
362
|
|
|
@@ -365,7 +372,7 @@ export class PublicProcessor implements Traceable {
|
|
|
365
372
|
totalSizeInBytes,
|
|
366
373
|
});
|
|
367
374
|
|
|
368
|
-
return [result, failed, usedTxs, returns,
|
|
375
|
+
return [result, failed, usedTxs, returns, debugLogs];
|
|
369
376
|
}
|
|
370
377
|
|
|
371
378
|
private async checkWorldStateUnchanged(
|
|
@@ -541,7 +548,7 @@ export class PublicProcessor implements Traceable {
|
|
|
541
548
|
// Fee payment insertion has already been done. Do the rest.
|
|
542
549
|
await this.doTreeInsertionsForPrivateOnlyTx(processedTx);
|
|
543
550
|
|
|
544
|
-
|
|
551
|
+
this.contractsDB.addNewContracts(tx);
|
|
545
552
|
|
|
546
553
|
return [processedTx, undefined, []];
|
|
547
554
|
}
|
|
@@ -52,6 +52,7 @@ export class ContractProviderForCpp implements ContractProvider {
|
|
|
52
52
|
return serializeWithMessagePack(contractClass);
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
+
// eslint-disable-next-line require-await
|
|
55
56
|
public addContracts = async (contractDeploymentDataBuffer: Buffer): Promise<void> => {
|
|
56
57
|
this.log.trace(`Contract provider callback: addContracts`);
|
|
57
58
|
|
|
@@ -62,7 +63,7 @@ export class ContractProviderForCpp implements ContractProvider {
|
|
|
62
63
|
|
|
63
64
|
// Add contracts to the contracts DB
|
|
64
65
|
this.log.trace(`Calling contractsDB.addContracts`);
|
|
65
|
-
|
|
66
|
+
this.contractsDB.addContracts(contractDeploymentData);
|
|
66
67
|
};
|
|
67
68
|
|
|
68
69
|
public getBytecodeCommitment = async (classId: string): Promise<Buffer | undefined> => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Logger, type LoggerBindings, createLogger
|
|
1
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { sleep } from '@aztec/foundation/sleep';
|
|
3
3
|
import { type CancellationToken, avmSimulate, cancelSimulation, createCancellationToken } from '@aztec/native';
|
|
4
4
|
import { ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
@@ -100,8 +100,7 @@ export class CppPublicTxSimulator extends PublicTxSimulator implements PublicTxS
|
|
|
100
100
|
inputBuffer,
|
|
101
101
|
contractProvider,
|
|
102
102
|
wsCppHandle,
|
|
103
|
-
|
|
104
|
-
// TODO: re-enable logging
|
|
103
|
+
this.log.level,
|
|
105
104
|
undefined,
|
|
106
105
|
this.cancellationToken,
|
|
107
106
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Logger, type LoggerBindings, createLogger
|
|
1
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { avmSimulateWithHintedDbs } from '@aztec/native';
|
|
3
3
|
import {
|
|
4
4
|
AvmCircuitInputs,
|
|
@@ -75,7 +75,7 @@ export class CppPublicTxSimulatorHintedDbs extends PublicTxSimulator implements
|
|
|
75
75
|
|
|
76
76
|
let resultBuffer: Buffer;
|
|
77
77
|
try {
|
|
78
|
-
resultBuffer = await avmSimulateWithHintedDbs(inputBuffer,
|
|
78
|
+
resultBuffer = await avmSimulateWithHintedDbs(inputBuffer, this.log.level);
|
|
79
79
|
} catch (error: any) {
|
|
80
80
|
throw new SimulationError(`C++ hinted simulation failed: ${error.message}`, []);
|
|
81
81
|
}
|
|
@@ -19,10 +19,11 @@ export function createPublicTxSimulatorForBlockBuilding(
|
|
|
19
19
|
globalVariables: GlobalVariables,
|
|
20
20
|
telemetryClient: TelemetryClient,
|
|
21
21
|
bindings?: LoggerBindings,
|
|
22
|
+
collectDebugLogs = false,
|
|
22
23
|
) {
|
|
23
24
|
const config = PublicSimulatorConfig.from({
|
|
24
25
|
skipFeeEnforcement: false,
|
|
25
|
-
collectDebugLogs
|
|
26
|
+
collectDebugLogs,
|
|
26
27
|
collectHints: false,
|
|
27
28
|
collectPublicInputs: false,
|
|
28
29
|
collectStatistics: false,
|
|
@@ -174,14 +174,8 @@ export class PublicTxContext {
|
|
|
174
174
|
}
|
|
175
175
|
if (phase === TxExecutionPhase.SETUP) {
|
|
176
176
|
this.log.warn(`Setup phase reverted! The transaction will be thrown out.`);
|
|
177
|
-
} else if (phase === TxExecutionPhase.APP_LOGIC) {
|
|
178
|
-
this.revertCode = RevertCode.
|
|
179
|
-
} else if (phase === TxExecutionPhase.TEARDOWN) {
|
|
180
|
-
if (this.revertCode.equals(RevertCode.APP_LOGIC_REVERTED)) {
|
|
181
|
-
this.revertCode = RevertCode.BOTH_REVERTED;
|
|
182
|
-
} else {
|
|
183
|
-
this.revertCode = RevertCode.TEARDOWN_REVERTED;
|
|
184
|
-
}
|
|
177
|
+
} else if (phase === TxExecutionPhase.APP_LOGIC || phase === TxExecutionPhase.TEARDOWN) {
|
|
178
|
+
this.revertCode = RevertCode.REVERTED;
|
|
185
179
|
}
|
|
186
180
|
}
|
|
187
181
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { ProtocolContractAddress, ProtocolContractsList } from '@aztec/protocol-contracts';
|
|
@@ -199,8 +199,8 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
199
199
|
|
|
200
200
|
// Such transactions should be filtered by GasTxValidator.
|
|
201
201
|
assert(
|
|
202
|
-
context.getActualGasUsed().l2Gas <=
|
|
203
|
-
`Transaction consumes ${context.getActualGasUsed().l2Gas} L2 gas, which exceeds the
|
|
202
|
+
context.getActualGasUsed().l2Gas <= MAX_PROCESSABLE_L2_GAS,
|
|
203
|
+
`Transaction consumes ${context.getActualGasUsed().l2Gas} L2 gas, which exceeds the maximum processable gas of ${MAX_PROCESSABLE_L2_GAS}`,
|
|
204
204
|
);
|
|
205
205
|
await this.payFee(context);
|
|
206
206
|
|
|
@@ -401,7 +401,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
401
401
|
// However, things work as expected because later calls to getters on the hintingContractsDB
|
|
402
402
|
// will pick up the new contracts and will generate the necessary hints.
|
|
403
403
|
// So, a consumer of the hints will always see the new contracts.
|
|
404
|
-
|
|
404
|
+
this.contractsDB.addContracts(context.nonRevertibleContractDeploymentData);
|
|
405
405
|
}
|
|
406
406
|
|
|
407
407
|
/**
|
|
@@ -486,7 +486,7 @@ export class PublicTxSimulator implements PublicTxSimulatorInterface {
|
|
|
486
486
|
// However, things work as expected because later calls to getters on the hintingContractsDB
|
|
487
487
|
// will pick up the new contracts and will generate the necessary hints.
|
|
488
488
|
// So, a consumer of the hints will always see the new contracts.
|
|
489
|
-
|
|
489
|
+
this.contractsDB.addContracts(context.revertibleContractDeploymentData);
|
|
490
490
|
}
|
|
491
491
|
|
|
492
492
|
private async payFee(context: PublicTxContext) {
|