@aztec/validator-client 0.0.1-commit.d431d1c → 0.0.1-commit.d58ff9d0
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/README.md +64 -19
- package/dest/checkpoint_builder.d.ts +29 -15
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +144 -45
- package/dest/config.d.ts +9 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +49 -13
- package/dest/duties/validation_service.d.ts +12 -13
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +33 -45
- package/dest/factory.d.ts +10 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +19 -6
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/key_store/ha_key_store.d.ts +1 -1
- package/dest/key_store/ha_key_store.d.ts.map +1 -1
- package/dest/key_store/ha_key_store.js +3 -3
- package/dest/key_store/web3signer_key_store.d.ts +10 -2
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
- package/dest/key_store/web3signer_key_store.js +32 -41
- package/dest/metrics.d.ts +16 -3
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +58 -5
- package/dest/proposal_handler.d.ts +165 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +1207 -0
- package/dest/validator.d.ts +65 -25
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +377 -240
- package/package.json +19 -17
- package/src/checkpoint_builder.ts +196 -54
- package/src/config.ts +57 -15
- package/src/duties/validation_service.ts +59 -54
- package/src/factory.ts +29 -4
- package/src/index.ts +1 -2
- package/src/key_store/ha_key_store.ts +3 -3
- package/src/key_store/web3signer_key_store.ts +43 -59
- package/src/metrics.ts +81 -6
- package/src/proposal_handler.ts +1314 -0
- package/src/validator.ts +512 -291
- package/dest/block_proposal_handler.d.ts +0 -65
- package/dest/block_proposal_handler.d.ts.map +0 -1
- package/dest/block_proposal_handler.js +0 -561
- package/dest/tx_validator/index.d.ts +0 -3
- package/dest/tx_validator/index.d.ts.map +0 -1
- package/dest/tx_validator/index.js +0 -2
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -54
- package/src/block_proposal_handler.ts +0 -576
- package/src/tx_validator/index.ts +0 -2
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -135
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/validator-client",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.d58ff9d0",
|
|
4
4
|
"main": "dest/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -64,28 +64,30 @@
|
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@aztec/blob-client": "0.0.1-commit.
|
|
68
|
-
"@aztec/blob-lib": "0.0.1-commit.
|
|
69
|
-
"@aztec/constants": "0.0.1-commit.
|
|
70
|
-
"@aztec/epoch-cache": "0.0.1-commit.
|
|
71
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
72
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
73
|
-
"@aztec/node-keystore": "0.0.1-commit.
|
|
74
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
75
|
-
"@aztec/p2p": "0.0.1-commit.
|
|
76
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
77
|
-
"@aztec/prover-client": "0.0.1-commit.
|
|
78
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
79
|
-
"@aztec/slasher": "0.0.1-commit.
|
|
80
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
81
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
82
|
-
"@aztec/validator-ha-signer": "0.0.1-commit.
|
|
67
|
+
"@aztec/blob-client": "0.0.1-commit.d58ff9d0",
|
|
68
|
+
"@aztec/blob-lib": "0.0.1-commit.d58ff9d0",
|
|
69
|
+
"@aztec/constants": "0.0.1-commit.d58ff9d0",
|
|
70
|
+
"@aztec/epoch-cache": "0.0.1-commit.d58ff9d0",
|
|
71
|
+
"@aztec/ethereum": "0.0.1-commit.d58ff9d0",
|
|
72
|
+
"@aztec/foundation": "0.0.1-commit.d58ff9d0",
|
|
73
|
+
"@aztec/node-keystore": "0.0.1-commit.d58ff9d0",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.d58ff9d0",
|
|
75
|
+
"@aztec/p2p": "0.0.1-commit.d58ff9d0",
|
|
76
|
+
"@aztec/protocol-contracts": "0.0.1-commit.d58ff9d0",
|
|
77
|
+
"@aztec/prover-client": "0.0.1-commit.d58ff9d0",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.d58ff9d0",
|
|
79
|
+
"@aztec/slasher": "0.0.1-commit.d58ff9d0",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.d58ff9d0",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.d58ff9d0",
|
|
82
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.d58ff9d0",
|
|
83
83
|
"koa": "^2.16.1",
|
|
84
84
|
"koa-router": "^13.1.1",
|
|
85
85
|
"tslib": "^2.4.0",
|
|
86
86
|
"viem": "npm:@aztec/viem@2.38.2"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
|
+
"@aztec/archiver": "0.0.1-commit.d58ff9d0",
|
|
90
|
+
"@aztec/world-state": "0.0.1-commit.d58ff9d0",
|
|
89
91
|
"@electric-sql/pglite": "^0.3.14",
|
|
90
92
|
"@jest/globals": "^30.0.0",
|
|
91
93
|
"@types/jest": "^30.0.0",
|
|
@@ -1,53 +1,56 @@
|
|
|
1
|
+
import { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
|
|
2
|
+
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB, MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT } from '@aztec/constants';
|
|
1
3
|
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { merge, pick } from '@aztec/foundation/collection';
|
|
4
|
+
import { merge, pick, sum } from '@aztec/foundation/collection';
|
|
3
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
5
7
|
import { bufferToHex } from '@aztec/foundation/string';
|
|
6
|
-
import { DateProvider,
|
|
7
|
-
import { getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
|
|
8
|
+
import { DateProvider, elapsed } from '@aztec/foundation/timer';
|
|
9
|
+
import { createTxValidatorForBlockBuilding, getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
|
|
8
10
|
import { LightweightCheckpointBuilder } from '@aztec/prover-client/light';
|
|
9
11
|
import {
|
|
12
|
+
type AvmSimulator,
|
|
10
13
|
GuardedMerkleTreeOperations,
|
|
11
14
|
PublicContractsDB,
|
|
12
15
|
PublicProcessor,
|
|
13
16
|
createPublicTxSimulatorForBlockBuilding,
|
|
14
17
|
} from '@aztec/simulator/server';
|
|
15
|
-
import {
|
|
18
|
+
import { L2Block } from '@aztec/stdlib/block';
|
|
16
19
|
import { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
17
20
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
18
21
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
19
22
|
import { Gas } from '@aztec/stdlib/gas';
|
|
20
23
|
import {
|
|
24
|
+
type BlockBuilderOptions,
|
|
21
25
|
type BuildBlockInCheckpointResult,
|
|
22
26
|
type FullNodeBlockBuilderConfig,
|
|
23
27
|
FullNodeBlockBuilderConfigKeys,
|
|
24
28
|
type ICheckpointBlockBuilder,
|
|
25
29
|
type ICheckpointsBuilder,
|
|
30
|
+
InsufficientValidTxsError,
|
|
26
31
|
type MerkleTreeWriteOperations,
|
|
27
32
|
type PublicProcessorLimits,
|
|
28
33
|
type WorldStateSynchronizer,
|
|
29
34
|
} from '@aztec/stdlib/interfaces/server';
|
|
35
|
+
import { type DebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
30
36
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
31
37
|
import { type CheckpointGlobalVariables, GlobalVariables, StateReference, Tx } from '@aztec/stdlib/tx';
|
|
32
38
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
33
|
-
|
|
34
|
-
import { createValidatorForBlockBuilding } from './tx_validator/tx_validator_factory.js';
|
|
39
|
+
import { ForkCheckpoint } from '@aztec/world-state';
|
|
35
40
|
|
|
36
41
|
// Re-export for backward compatibility
|
|
37
42
|
export type { BuildBlockInCheckpointResult } from '@aztec/stdlib/interfaces/server';
|
|
38
43
|
|
|
39
|
-
const log = createLogger('checkpoint-builder');
|
|
40
|
-
|
|
41
|
-
/** Result of building a block within a checkpoint. Extends the base interface with timer. */
|
|
42
|
-
export interface BuildBlockInCheckpointResultWithTimer extends BuildBlockInCheckpointResult {
|
|
43
|
-
blockBuildingTimer: Timer;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
44
|
/**
|
|
47
45
|
* Builder for a single checkpoint. Handles building blocks within the checkpoint
|
|
48
46
|
* and completing it.
|
|
49
47
|
*/
|
|
50
48
|
export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
49
|
+
private log: Logger;
|
|
50
|
+
|
|
51
|
+
/** Persistent contracts DB shared across all blocks in this checkpoint. */
|
|
52
|
+
protected contractsDB: PublicContractsDB;
|
|
53
|
+
|
|
51
54
|
constructor(
|
|
52
55
|
private checkpointBuilder: LightweightCheckpointBuilder,
|
|
53
56
|
private fork: MerkleTreeWriteOperations,
|
|
@@ -55,7 +58,16 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
55
58
|
private contractDataSource: ContractDataSource,
|
|
56
59
|
private dateProvider: DateProvider,
|
|
57
60
|
private telemetryClient: TelemetryClient,
|
|
58
|
-
|
|
61
|
+
private avmSimulator: AvmSimulator,
|
|
62
|
+
bindings?: LoggerBindings,
|
|
63
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
64
|
+
) {
|
|
65
|
+
this.log = createLogger('checkpoint-builder', {
|
|
66
|
+
...bindings,
|
|
67
|
+
instanceId: `checkpoint-${checkpointBuilder.checkpointNumber}`,
|
|
68
|
+
});
|
|
69
|
+
this.contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
|
|
70
|
+
}
|
|
59
71
|
|
|
60
72
|
getConstantData(): CheckpointGlobalVariables {
|
|
61
73
|
return this.checkpointBuilder.constants;
|
|
@@ -63,17 +75,17 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
63
75
|
|
|
64
76
|
/**
|
|
65
77
|
* Builds a single block within this checkpoint.
|
|
78
|
+
* Automatically caps gas and blob field limits based on checkpoint-level budgets and prior blocks.
|
|
66
79
|
*/
|
|
67
80
|
async buildBlock(
|
|
68
81
|
pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
69
82
|
blockNumber: BlockNumber,
|
|
70
83
|
timestamp: bigint,
|
|
71
|
-
opts:
|
|
72
|
-
): Promise<
|
|
73
|
-
const blockBuildingTimer = new Timer();
|
|
84
|
+
opts: BlockBuilderOptions & { expectedEndState?: StateReference },
|
|
85
|
+
): Promise<BuildBlockInCheckpointResult> {
|
|
74
86
|
const slot = this.checkpointBuilder.constants.slotNumber;
|
|
75
87
|
|
|
76
|
-
log.verbose(`Building block ${blockNumber} for slot ${slot} within checkpoint`, {
|
|
88
|
+
this.log.verbose(`Building block ${blockNumber} for slot ${slot} within checkpoint`, {
|
|
77
89
|
slot,
|
|
78
90
|
blockNumber,
|
|
79
91
|
...opts,
|
|
@@ -93,37 +105,67 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
93
105
|
});
|
|
94
106
|
const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, this.fork);
|
|
95
107
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// Add block to checkpoint
|
|
101
|
-
const block = await this.checkpointBuilder.addBlock(globalVariables, processedTxs, {
|
|
102
|
-
expectedEndState: opts.expectedEndState,
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// How much public gas was processed
|
|
106
|
-
const publicGas = processedTxs.reduce((acc, tx) => acc.add(tx.gasUsed.publicGas), Gas.empty());
|
|
107
|
-
|
|
108
|
-
const res = {
|
|
109
|
-
block,
|
|
110
|
-
publicGas,
|
|
111
|
-
publicProcessorDuration,
|
|
112
|
-
numTxs: processedTxs.length,
|
|
113
|
-
failedTxs,
|
|
114
|
-
blockBuildingTimer,
|
|
115
|
-
usedTxs,
|
|
116
|
-
usedTxBlobFields,
|
|
108
|
+
// Cap gas limits amd available blob fields by remaining checkpoint-level budgets
|
|
109
|
+
const cappedOpts: PublicProcessorLimits & { expectedEndState?: StateReference } = {
|
|
110
|
+
...opts,
|
|
111
|
+
...this.capLimitsByCheckpointBudgets(opts),
|
|
117
112
|
};
|
|
118
|
-
|
|
119
|
-
|
|
113
|
+
|
|
114
|
+
// Create a block-level checkpoint on the contracts DB so we can roll back on failure
|
|
115
|
+
this.contractsDB.createCheckpoint();
|
|
116
|
+
// We execute all merkle tree operations on a world state fork checkpoint
|
|
117
|
+
// This enables us to discard all modifications in the event that we fail to successfully process sufficient transactions
|
|
118
|
+
const forkCheckpoint = await ForkCheckpoint.new(this.fork);
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(() =>
|
|
122
|
+
processor.process(pendingTxs, cappedOpts, validator),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
// Throw before updating state if we don't have enough valid txs
|
|
126
|
+
const minValidTxs = opts.minValidTxs ?? 0;
|
|
127
|
+
if (processedTxs.length < minValidTxs) {
|
|
128
|
+
throw new InsufficientValidTxsError(processedTxs.length, minValidTxs, failedTxs);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Commit the fork checkpoint
|
|
132
|
+
await forkCheckpoint.commit();
|
|
133
|
+
|
|
134
|
+
// Add block to checkpoint
|
|
135
|
+
const { block } = await this.checkpointBuilder.addBlock(globalVariables, processedTxs, {
|
|
136
|
+
expectedEndState: opts.expectedEndState,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
this.contractsDB.commitCheckpoint();
|
|
140
|
+
|
|
141
|
+
this.log.debug('Built block within checkpoint', {
|
|
142
|
+
header: block.header.toInspect(),
|
|
143
|
+
processedTxs: processedTxs.map(tx => tx.hash.toString()),
|
|
144
|
+
failedTxs: failedTxs.map(tx => tx.tx.txHash.toString()),
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
block,
|
|
149
|
+
publicProcessorDuration,
|
|
150
|
+
numTxs: processedTxs.length,
|
|
151
|
+
failedTxs,
|
|
152
|
+
usedTxs,
|
|
153
|
+
};
|
|
154
|
+
} catch (err) {
|
|
155
|
+
// Revert all changes to contracts db
|
|
156
|
+
this.contractsDB.revertCheckpoint();
|
|
157
|
+
// If we reached the point of committing the checkpoint, this does nothing
|
|
158
|
+
// Otherwise it reverts any changes made to the fork for this failed block
|
|
159
|
+
await forkCheckpoint.revert();
|
|
160
|
+
throw err;
|
|
161
|
+
}
|
|
120
162
|
}
|
|
121
163
|
|
|
122
164
|
/** Completes the checkpoint and returns it. */
|
|
123
165
|
async completeCheckpoint(): Promise<Checkpoint> {
|
|
124
166
|
const checkpoint = await this.checkpointBuilder.completeCheckpoint();
|
|
125
167
|
|
|
126
|
-
log.verbose(`Completed checkpoint ${checkpoint.number}`, {
|
|
168
|
+
this.log.verbose(`Completed checkpoint ${checkpoint.number}`, {
|
|
127
169
|
checkpointNumber: checkpoint.number,
|
|
128
170
|
numBlocks: checkpoint.blocks.length,
|
|
129
171
|
archiveRoot: checkpoint.archive.root.toString(),
|
|
@@ -137,16 +179,84 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
137
179
|
return this.checkpointBuilder.clone().completeCheckpoint();
|
|
138
180
|
}
|
|
139
181
|
|
|
182
|
+
/**
|
|
183
|
+
* Caps per-block gas and blob field limits by remaining checkpoint-level budgets.
|
|
184
|
+
* When building a proposal (isBuildingProposal=true), computes a fair share of remaining budget
|
|
185
|
+
* across remaining blocks scaled by the multiplier. When validating, only caps by per-block limit
|
|
186
|
+
* and remaining checkpoint budget (no redistribution or multiplier).
|
|
187
|
+
*/
|
|
188
|
+
protected capLimitsByCheckpointBudgets(
|
|
189
|
+
opts: BlockBuilderOptions,
|
|
190
|
+
): Pick<PublicProcessorLimits, 'maxBlockGas' | 'maxBlobFields' | 'maxTransactions'> {
|
|
191
|
+
const existingBlocks = this.checkpointBuilder.getBlocks();
|
|
192
|
+
|
|
193
|
+
// Remaining L2 gas (mana)
|
|
194
|
+
// IMPORTANT: This assumes mana is computed solely based on L2 gas used in transactions.
|
|
195
|
+
// This may change in the future.
|
|
196
|
+
const usedMana = sum(existingBlocks.map(b => b.header.totalManaUsed.toNumber()));
|
|
197
|
+
const remainingMana = this.config.rollupManaLimit - usedMana;
|
|
198
|
+
|
|
199
|
+
// Remaining DA gas
|
|
200
|
+
const usedDAGas = sum(existingBlocks.map(b => b.computeDAGasUsed())) ?? 0;
|
|
201
|
+
const remainingDAGas = MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT - usedDAGas;
|
|
202
|
+
|
|
203
|
+
// Remaining blob fields (block blob fields include both tx data and block-end overhead)
|
|
204
|
+
const usedBlobFields = sum(existingBlocks.map(b => b.toBlobFields().length));
|
|
205
|
+
const totalBlobCapacity = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
206
|
+
const isFirstBlock = existingBlocks.length === 0;
|
|
207
|
+
const blockEndOverhead = getNumBlockEndBlobFields(isFirstBlock);
|
|
208
|
+
const maxBlobFieldsForTxs = totalBlobCapacity - usedBlobFields - blockEndOverhead;
|
|
209
|
+
|
|
210
|
+
// Remaining txs
|
|
211
|
+
const usedTxs = sum(existingBlocks.map(b => b.body.txEffects.length));
|
|
212
|
+
const remainingTxs = Math.max(0, (this.config.maxTxsPerCheckpoint ?? Infinity) - usedTxs);
|
|
213
|
+
|
|
214
|
+
// Cap by per-block limit + remaining checkpoint budget
|
|
215
|
+
let cappedL2Gas = Math.min(opts.maxBlockGas?.l2Gas ?? Infinity, remainingMana);
|
|
216
|
+
let cappedDAGas = Math.min(opts.maxBlockGas?.daGas ?? Infinity, remainingDAGas);
|
|
217
|
+
let cappedBlobFields = Math.min(opts.maxBlobFields ?? Infinity, maxBlobFieldsForTxs);
|
|
218
|
+
let cappedMaxTransactions = Math.min(opts.maxTransactions ?? Infinity, remainingTxs);
|
|
219
|
+
|
|
220
|
+
// Proposer mode: further cap by fair share of remaining budget across remaining blocks
|
|
221
|
+
if (opts.isBuildingProposal) {
|
|
222
|
+
const remainingBlocks = Math.max(1, opts.maxBlocksPerCheckpoint - existingBlocks.length);
|
|
223
|
+
const multiplier = opts.perBlockAllocationMultiplier;
|
|
224
|
+
// DA gas and blob fields use a higher multiplier so the largest contract class deploy fits a block.
|
|
225
|
+
const daMultiplier = opts.perBlockDAAllocationMultiplier ?? multiplier;
|
|
226
|
+
|
|
227
|
+
cappedL2Gas = Math.min(cappedL2Gas, Math.ceil((remainingMana / remainingBlocks) * multiplier));
|
|
228
|
+
cappedDAGas = Math.min(cappedDAGas, Math.ceil((remainingDAGas / remainingBlocks) * daMultiplier));
|
|
229
|
+
cappedBlobFields = Math.min(cappedBlobFields, Math.ceil((maxBlobFieldsForTxs / remainingBlocks) * daMultiplier));
|
|
230
|
+
cappedMaxTransactions = Math.min(cappedMaxTransactions, Math.ceil((remainingTxs / remainingBlocks) * multiplier));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return {
|
|
234
|
+
maxBlockGas: new Gas(cappedDAGas, cappedL2Gas),
|
|
235
|
+
maxBlobFields: cappedBlobFields,
|
|
236
|
+
maxTransactions: Number.isFinite(cappedMaxTransactions) ? cappedMaxTransactions : undefined,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
140
240
|
protected async makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations) {
|
|
141
|
-
const txPublicSetupAllowList =
|
|
142
|
-
|
|
241
|
+
const txPublicSetupAllowList = [
|
|
242
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
243
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
244
|
+
];
|
|
245
|
+
const contractsDB = this.contractsDB;
|
|
143
246
|
const guardedFork = new GuardedMerkleTreeOperations(fork);
|
|
144
247
|
|
|
248
|
+
const bindings = this.log.getBindings();
|
|
249
|
+
// Extract the WSDB fork ID so the C++ AVM can modify the same fork in-place; the simulator reads
|
|
250
|
+
// contract data from `contractsDB`, scoped to this fork for the duration of each simulation.
|
|
251
|
+
const wsdbForkId = fork.getRevision().forkId;
|
|
145
252
|
const publicTxSimulator = createPublicTxSimulatorForBlockBuilding(
|
|
146
|
-
|
|
147
|
-
contractsDB,
|
|
253
|
+
this.avmSimulator,
|
|
148
254
|
globalVariables,
|
|
255
|
+
contractsDB,
|
|
256
|
+
wsdbForkId,
|
|
149
257
|
this.telemetryClient,
|
|
258
|
+
bindings,
|
|
259
|
+
this.debugLogStore?.isEnabled ?? false,
|
|
150
260
|
);
|
|
151
261
|
|
|
152
262
|
const processor = new PublicProcessor(
|
|
@@ -156,15 +266,17 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
156
266
|
publicTxSimulator,
|
|
157
267
|
this.dateProvider,
|
|
158
268
|
this.telemetryClient,
|
|
159
|
-
|
|
269
|
+
createLogger('simulator:public-processor', bindings),
|
|
160
270
|
this.config,
|
|
271
|
+
this.debugLogStore,
|
|
161
272
|
);
|
|
162
273
|
|
|
163
|
-
const validator =
|
|
274
|
+
const validator = createTxValidatorForBlockBuilding(
|
|
164
275
|
fork,
|
|
165
276
|
this.contractDataSource,
|
|
166
277
|
globalVariables,
|
|
167
278
|
txPublicSetupAllowList,
|
|
279
|
+
this.log.getBindings(),
|
|
168
280
|
);
|
|
169
281
|
|
|
170
282
|
return {
|
|
@@ -176,13 +288,19 @@ export class CheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
176
288
|
|
|
177
289
|
/** Factory for creating checkpoint builders. */
|
|
178
290
|
export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
291
|
+
private log: Logger;
|
|
292
|
+
|
|
179
293
|
constructor(
|
|
180
294
|
private config: FullNodeBlockBuilderConfig & Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>,
|
|
181
295
|
private worldState: WorldStateSynchronizer,
|
|
182
296
|
private contractDataSource: ContractDataSource,
|
|
183
297
|
private dateProvider: DateProvider,
|
|
298
|
+
private avmSimulator: AvmSimulator,
|
|
184
299
|
private telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
185
|
-
|
|
300
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
301
|
+
) {
|
|
302
|
+
this.log = createLogger('checkpoint-builder');
|
|
303
|
+
}
|
|
186
304
|
|
|
187
305
|
public getConfig(): FullNodeBlockBuilderConfig {
|
|
188
306
|
return this.config;
|
|
@@ -198,19 +316,22 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
198
316
|
async startCheckpoint(
|
|
199
317
|
checkpointNumber: CheckpointNumber,
|
|
200
318
|
constants: CheckpointGlobalVariables,
|
|
319
|
+
feeAssetPriceModifier: bigint,
|
|
201
320
|
l1ToL2Messages: Fr[],
|
|
202
321
|
previousCheckpointOutHashes: Fr[],
|
|
203
322
|
fork: MerkleTreeWriteOperations,
|
|
323
|
+
bindings?: LoggerBindings,
|
|
204
324
|
): Promise<CheckpointBuilder> {
|
|
205
325
|
const stateReference = await fork.getStateReference();
|
|
206
326
|
const archiveTree = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
207
327
|
|
|
208
|
-
log.verbose(`Building new checkpoint ${checkpointNumber}`, {
|
|
328
|
+
this.log.verbose(`Building new checkpoint ${checkpointNumber}`, {
|
|
209
329
|
checkpointNumber,
|
|
210
330
|
msgCount: l1ToL2Messages.length,
|
|
211
331
|
initialStateReference: stateReference.toInspect(),
|
|
212
332
|
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
213
333
|
constants,
|
|
334
|
+
feeAssetPriceModifier,
|
|
214
335
|
});
|
|
215
336
|
|
|
216
337
|
const lightweightBuilder = await LightweightCheckpointBuilder.startNewCheckpoint(
|
|
@@ -219,6 +340,8 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
219
340
|
l1ToL2Messages,
|
|
220
341
|
previousCheckpointOutHashes,
|
|
221
342
|
fork,
|
|
343
|
+
bindings,
|
|
344
|
+
feeAssetPriceModifier,
|
|
222
345
|
);
|
|
223
346
|
|
|
224
347
|
return new CheckpointBuilder(
|
|
@@ -228,6 +351,9 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
228
351
|
this.contractDataSource,
|
|
229
352
|
this.dateProvider,
|
|
230
353
|
this.telemetryClient,
|
|
354
|
+
this.avmSimulator,
|
|
355
|
+
bindings,
|
|
356
|
+
this.debugLogStore,
|
|
231
357
|
);
|
|
232
358
|
}
|
|
233
359
|
|
|
@@ -237,34 +363,47 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
237
363
|
async openCheckpoint(
|
|
238
364
|
checkpointNumber: CheckpointNumber,
|
|
239
365
|
constants: CheckpointGlobalVariables,
|
|
366
|
+
feeAssetPriceModifier: bigint,
|
|
240
367
|
l1ToL2Messages: Fr[],
|
|
241
368
|
previousCheckpointOutHashes: Fr[],
|
|
242
369
|
fork: MerkleTreeWriteOperations,
|
|
243
|
-
existingBlocks:
|
|
370
|
+
existingBlocks: L2Block[] = [],
|
|
371
|
+
bindings?: LoggerBindings,
|
|
244
372
|
): Promise<CheckpointBuilder> {
|
|
245
373
|
const stateReference = await fork.getStateReference();
|
|
246
374
|
const archiveTree = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
247
375
|
|
|
248
376
|
if (existingBlocks.length === 0) {
|
|
249
|
-
return this.startCheckpoint(
|
|
377
|
+
return this.startCheckpoint(
|
|
378
|
+
checkpointNumber,
|
|
379
|
+
constants,
|
|
380
|
+
feeAssetPriceModifier,
|
|
381
|
+
l1ToL2Messages,
|
|
382
|
+
previousCheckpointOutHashes,
|
|
383
|
+
fork,
|
|
384
|
+
bindings,
|
|
385
|
+
);
|
|
250
386
|
}
|
|
251
387
|
|
|
252
|
-
log.verbose(`Resuming checkpoint ${checkpointNumber} with ${existingBlocks.length} existing blocks`, {
|
|
388
|
+
this.log.verbose(`Resuming checkpoint ${checkpointNumber} with ${existingBlocks.length} existing blocks`, {
|
|
253
389
|
checkpointNumber,
|
|
254
390
|
msgCount: l1ToL2Messages.length,
|
|
255
391
|
existingBlockCount: existingBlocks.length,
|
|
256
392
|
initialStateReference: stateReference.toInspect(),
|
|
257
393
|
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
258
394
|
constants,
|
|
395
|
+
feeAssetPriceModifier,
|
|
259
396
|
});
|
|
260
397
|
|
|
261
398
|
const lightweightBuilder = await LightweightCheckpointBuilder.resumeCheckpoint(
|
|
262
399
|
checkpointNumber,
|
|
263
400
|
constants,
|
|
401
|
+
feeAssetPriceModifier,
|
|
264
402
|
l1ToL2Messages,
|
|
265
403
|
previousCheckpointOutHashes,
|
|
266
404
|
fork,
|
|
267
405
|
existingBlocks,
|
|
406
|
+
bindings,
|
|
268
407
|
);
|
|
269
408
|
|
|
270
409
|
return new CheckpointBuilder(
|
|
@@ -274,6 +413,9 @@ export class FullNodeCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
274
413
|
this.contractDataSource,
|
|
275
414
|
this.dateProvider,
|
|
276
415
|
this.telemetryClient,
|
|
416
|
+
this.avmSimulator,
|
|
417
|
+
bindings,
|
|
418
|
+
this.debugLogStore,
|
|
277
419
|
);
|
|
278
420
|
}
|
|
279
421
|
|
package/src/config.ts
CHANGED
|
@@ -3,15 +3,27 @@ import {
|
|
|
3
3
|
booleanConfigHelper,
|
|
4
4
|
getConfigFromMappings,
|
|
5
5
|
numberConfigHelper,
|
|
6
|
+
optionalNumberConfigHelper,
|
|
7
|
+
pickConfigMappings,
|
|
6
8
|
secretValueConfigHelper,
|
|
7
9
|
} from '@aztec/foundation/config';
|
|
8
10
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
11
|
+
import { type SequencerConfig, sharedSequencerConfigMappings } from '@aztec/stdlib/config';
|
|
12
|
+
import { localSignerConfigMappings, validatorHASignerConfigMappings } from '@aztec/stdlib/ha-signing';
|
|
9
13
|
import type { ValidatorClientConfig } from '@aztec/stdlib/interfaces/server';
|
|
10
|
-
import { validatorHASignerConfigMappings } from '@aztec/validator-ha-signer/config';
|
|
11
14
|
|
|
12
15
|
export type { ValidatorClientConfig };
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Default clock-disparity tolerance (ms) for proposal/attestation receive windows, mirroring the p2p config
|
|
19
|
+
* default. Used by the validator-client validators when the merged node config does not carry the value.
|
|
20
|
+
*/
|
|
21
|
+
export const DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS = 500;
|
|
22
|
+
|
|
23
|
+
export const validatorClientConfigMappings: ConfigMappingsType<
|
|
24
|
+
ValidatorClientConfig & Pick<SequencerConfig, 'blockDurationMs'>
|
|
25
|
+
> = {
|
|
26
|
+
...pickConfigMappings(sharedSequencerConfigMappings, ['blockDurationMs']),
|
|
15
27
|
validatorPrivateKeys: {
|
|
16
28
|
env: 'VALIDATOR_PRIVATE_KEYS',
|
|
17
29
|
description: 'List of private keys of the validators participating in attestation duties',
|
|
@@ -30,6 +42,12 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
|
|
|
30
42
|
.map(address => EthAddress.fromString(address.trim())),
|
|
31
43
|
defaultValue: [],
|
|
32
44
|
},
|
|
45
|
+
l1ChainId: {
|
|
46
|
+
env: 'L1_CHAIN_ID',
|
|
47
|
+
description: 'The chain ID of the ethereum host.',
|
|
48
|
+
parseEnv: (val: string) => +val,
|
|
49
|
+
defaultValue: 31337,
|
|
50
|
+
},
|
|
33
51
|
disableValidator: {
|
|
34
52
|
env: 'VALIDATOR_DISABLED',
|
|
35
53
|
description: 'Do not run the validator',
|
|
@@ -49,11 +67,6 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
|
|
|
49
67
|
description: 'Interval between polling for new attestations',
|
|
50
68
|
...numberConfigHelper(200),
|
|
51
69
|
},
|
|
52
|
-
validatorReexecute: {
|
|
53
|
-
env: 'VALIDATOR_REEXECUTE',
|
|
54
|
-
description: 'Re-execute transactions before attesting',
|
|
55
|
-
...booleanConfigHelper(true),
|
|
56
|
-
},
|
|
57
70
|
alwaysReexecuteBlockProposals: {
|
|
58
71
|
description:
|
|
59
72
|
'Whether to always reexecute block proposals, even for non-validator nodes (useful for monitoring network status).',
|
|
@@ -65,16 +78,43 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
|
|
|
65
78
|
'Whether to run in fisherman mode: validates all proposals and attestations but does not broadcast attestations or participate in consensus.',
|
|
66
79
|
...booleanConfigHelper(false),
|
|
67
80
|
},
|
|
68
|
-
// TODO(palla/mbps): Change default to false once checkpoint validation is stable
|
|
69
81
|
skipCheckpointProposalValidation: {
|
|
70
|
-
description: 'Skip checkpoint proposal validation and always attest (default:
|
|
71
|
-
defaultValue:
|
|
82
|
+
description: 'Skip checkpoint proposal validation and always attest (default: false)',
|
|
83
|
+
defaultValue: false,
|
|
72
84
|
},
|
|
73
|
-
// TODO(palla/mbps): Change default to false once block sync is stable
|
|
74
85
|
skipPushProposedBlocksToArchiver: {
|
|
75
|
-
description: 'Skip pushing re-executed blocks to archiver (default:
|
|
76
|
-
defaultValue:
|
|
86
|
+
description: 'Skip pushing re-executed blocks to archiver (default: false)',
|
|
87
|
+
defaultValue: false,
|
|
88
|
+
},
|
|
89
|
+
attestToEquivocatedProposals: {
|
|
90
|
+
description: 'Agree to attest to equivocated checkpoint proposals (for testing purposes only)',
|
|
91
|
+
...booleanConfigHelper(false),
|
|
92
|
+
},
|
|
93
|
+
skipProposalSlotValidation: {
|
|
94
|
+
description: 'Accept proposal validation regardless of slot timing (for testing only)',
|
|
95
|
+
...booleanConfigHelper(false),
|
|
96
|
+
},
|
|
97
|
+
validateMaxL2BlockGas: {
|
|
98
|
+
env: 'VALIDATOR_MAX_L2_BLOCK_GAS',
|
|
99
|
+
description: 'Maximum L2 block gas for validation. Proposals exceeding this limit are rejected.',
|
|
100
|
+
...optionalNumberConfigHelper(),
|
|
101
|
+
},
|
|
102
|
+
validateMaxDABlockGas: {
|
|
103
|
+
env: 'VALIDATOR_MAX_DA_BLOCK_GAS',
|
|
104
|
+
description: 'Maximum DA block gas for validation. Proposals exceeding this limit are rejected.',
|
|
105
|
+
...optionalNumberConfigHelper(),
|
|
106
|
+
},
|
|
107
|
+
validateMaxTxsPerBlock: {
|
|
108
|
+
env: 'VALIDATOR_MAX_TX_PER_BLOCK',
|
|
109
|
+
description: 'Maximum transactions per block for validation. Proposals exceeding this limit are rejected.',
|
|
110
|
+
...optionalNumberConfigHelper(),
|
|
111
|
+
},
|
|
112
|
+
validateMaxTxsPerCheckpoint: {
|
|
113
|
+
env: 'VALIDATOR_MAX_TX_PER_CHECKPOINT',
|
|
114
|
+
description: 'Maximum transactions per checkpoint for validation. Proposals exceeding this limit are rejected.',
|
|
115
|
+
...optionalNumberConfigHelper(),
|
|
77
116
|
},
|
|
117
|
+
...localSignerConfigMappings,
|
|
78
118
|
...validatorHASignerConfigMappings,
|
|
79
119
|
};
|
|
80
120
|
|
|
@@ -83,6 +123,8 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
|
|
|
83
123
|
* Note: If an environment variable is not set, the default value is used.
|
|
84
124
|
* @returns The validator configuration.
|
|
85
125
|
*/
|
|
86
|
-
export function getProverEnvVars(): ValidatorClientConfig {
|
|
87
|
-
return getConfigFromMappings<ValidatorClientConfig
|
|
126
|
+
export function getProverEnvVars(): ValidatorClientConfig & Pick<SequencerConfig, 'blockDurationMs'> {
|
|
127
|
+
return getConfigFromMappings<ValidatorClientConfig & Pick<SequencerConfig, 'blockDurationMs'>>(
|
|
128
|
+
validatorClientConfigMappings,
|
|
129
|
+
);
|
|
88
130
|
}
|