@aztec/validator-client 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c
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 +285 -0
- package/dest/block_proposal_handler.d.ts +24 -13
- package/dest/block_proposal_handler.d.ts.map +1 -1
- package/dest/block_proposal_handler.js +329 -87
- package/dest/checkpoint_builder.d.ts +66 -0
- package/dest/checkpoint_builder.d.ts.map +1 -0
- package/dest/checkpoint_builder.js +175 -0
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +16 -8
- package/dest/duties/validation_service.d.ts +42 -13
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +111 -28
- package/dest/factory.d.ts +13 -8
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +2 -2
- package/dest/index.d.ts +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- package/dest/key_store/ha_key_store.d.ts +99 -0
- package/dest/key_store/ha_key_store.d.ts.map +1 -0
- package/dest/key_store/ha_key_store.js +208 -0
- package/dest/key_store/index.d.ts +2 -1
- package/dest/key_store/index.d.ts.map +1 -1
- package/dest/key_store/index.js +1 -0
- package/dest/key_store/interface.d.ts +36 -6
- package/dest/key_store/interface.d.ts.map +1 -1
- package/dest/key_store/local_key_store.d.ts +10 -5
- package/dest/key_store/local_key_store.d.ts.map +1 -1
- package/dest/key_store/local_key_store.js +9 -5
- package/dest/key_store/node_keystore_adapter.d.ts +18 -5
- package/dest/key_store/node_keystore_adapter.d.ts.map +1 -1
- package/dest/key_store/node_keystore_adapter.js +18 -4
- package/dest/key_store/web3signer_key_store.d.ts +10 -5
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
- package/dest/key_store/web3signer_key_store.js +9 -5
- package/dest/metrics.d.ts +4 -3
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +34 -30
- package/dest/tx_validator/index.d.ts +3 -0
- package/dest/tx_validator/index.d.ts.map +1 -0
- package/dest/tx_validator/index.js +2 -0
- package/dest/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/tx_validator/nullifier_cache.js +24 -0
- package/dest/tx_validator/tx_validator_factory.d.ts +19 -0
- package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -0
- package/dest/tx_validator/tx_validator_factory.js +54 -0
- package/dest/validator.d.ts +74 -21
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +452 -56
- package/package.json +23 -13
- package/src/block_proposal_handler.ts +253 -59
- package/src/checkpoint_builder.ts +321 -0
- package/src/config.ts +15 -7
- package/src/duties/validation_service.ts +162 -33
- package/src/factory.ts +17 -8
- package/src/index.ts +2 -0
- package/src/key_store/ha_key_store.ts +269 -0
- package/src/key_store/index.ts +1 -0
- package/src/key_store/interface.ts +44 -5
- package/src/key_store/local_key_store.ts +14 -5
- package/src/key_store/node_keystore_adapter.ts +28 -5
- package/src/key_store/web3signer_key_store.ts +18 -5
- package/src/metrics.ts +45 -33
- package/src/tx_validator/index.ts +2 -0
- package/src/tx_validator/nullifier_cache.ts +30 -0
- package/src/tx_validator/tx_validator_factory.ts +154 -0
- package/src/validator.ts +619 -85
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.ff7989d6c",
|
|
4
4
|
"main": "dest/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
20
|
"start": "node --no-warnings ./dest/bin",
|
|
21
|
-
"build": "yarn clean &&
|
|
22
|
-
"build:dev": "
|
|
21
|
+
"build": "yarn clean && ../scripts/tsc.sh",
|
|
22
|
+
"build:dev": "../scripts/tsc.sh --watch",
|
|
23
23
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
24
24
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
25
25
|
},
|
|
@@ -64,25 +64,35 @@
|
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@aztec/
|
|
68
|
-
"@aztec/
|
|
69
|
-
"@aztec/
|
|
70
|
-
"@aztec/
|
|
71
|
-
"@aztec/
|
|
72
|
-
"@aztec/
|
|
73
|
-
"@aztec/
|
|
74
|
-
"@aztec/
|
|
75
|
-
"@aztec/
|
|
67
|
+
"@aztec/blob-client": "0.0.1-commit.ff7989d6c",
|
|
68
|
+
"@aztec/blob-lib": "0.0.1-commit.ff7989d6c",
|
|
69
|
+
"@aztec/constants": "0.0.1-commit.ff7989d6c",
|
|
70
|
+
"@aztec/epoch-cache": "0.0.1-commit.ff7989d6c",
|
|
71
|
+
"@aztec/ethereum": "0.0.1-commit.ff7989d6c",
|
|
72
|
+
"@aztec/foundation": "0.0.1-commit.ff7989d6c",
|
|
73
|
+
"@aztec/node-keystore": "0.0.1-commit.ff7989d6c",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.ff7989d6c",
|
|
75
|
+
"@aztec/p2p": "0.0.1-commit.ff7989d6c",
|
|
76
|
+
"@aztec/protocol-contracts": "0.0.1-commit.ff7989d6c",
|
|
77
|
+
"@aztec/prover-client": "0.0.1-commit.ff7989d6c",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.ff7989d6c",
|
|
79
|
+
"@aztec/slasher": "0.0.1-commit.ff7989d6c",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.ff7989d6c",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.ff7989d6c",
|
|
82
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.ff7989d6c",
|
|
76
83
|
"koa": "^2.16.1",
|
|
77
84
|
"koa-router": "^13.1.1",
|
|
78
85
|
"tslib": "^2.4.0",
|
|
79
86
|
"viem": "npm:@aztec/viem@2.38.2"
|
|
80
87
|
},
|
|
81
88
|
"devDependencies": {
|
|
89
|
+
"@aztec/archiver": "0.0.1-commit.ff7989d6c",
|
|
90
|
+
"@aztec/world-state": "0.0.1-commit.ff7989d6c",
|
|
91
|
+
"@electric-sql/pglite": "^0.3.14",
|
|
82
92
|
"@jest/globals": "^30.0.0",
|
|
83
93
|
"@types/jest": "^30.0.0",
|
|
84
94
|
"@types/node": "^22.15.17",
|
|
85
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
95
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
86
96
|
"jest": "^30.0.0",
|
|
87
97
|
"jest-mock-extended": "^4.0.0",
|
|
88
98
|
"ts-node": "^10.9.1",
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
|
-
import {
|
|
2
|
+
import type { EpochCache } from '@aztec/epoch-cache';
|
|
3
|
+
import { BlockNumber, CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
5
|
import { TimeoutError } from '@aztec/foundation/error';
|
|
4
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
5
6
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
7
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
7
8
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
8
9
|
import type { P2P, PeerId } from '@aztec/p2p';
|
|
9
|
-
import { TxProvider } from '@aztec/p2p';
|
|
10
10
|
import { BlockProposalValidator } from '@aztec/p2p/msg_validators';
|
|
11
|
-
import type { L2Block, L2BlockSource } from '@aztec/stdlib/block';
|
|
12
|
-
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
13
|
-
import type {
|
|
11
|
+
import type { BlockData, L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
12
|
+
import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
13
|
+
import type { ITxProvider, ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
14
14
|
import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
15
|
+
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
16
|
+
import type { CheckpointGlobalVariables, FailedTx, Tx } from '@aztec/stdlib/tx';
|
|
17
17
|
import {
|
|
18
18
|
ReExFailedTxsError,
|
|
19
19
|
ReExStateMismatchError,
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
} from '@aztec/stdlib/validators';
|
|
23
23
|
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
24
24
|
|
|
25
|
+
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
25
26
|
import type { ValidatorMetrics } from './metrics.js';
|
|
26
27
|
|
|
27
28
|
export type BlockProposalValidationFailureReason =
|
|
@@ -29,6 +30,7 @@ export type BlockProposalValidationFailureReason =
|
|
|
29
30
|
| 'parent_block_not_found'
|
|
30
31
|
| 'parent_block_wrong_slot'
|
|
31
32
|
| 'in_hash_mismatch'
|
|
33
|
+
| 'global_variables_mismatch'
|
|
32
34
|
| 'block_number_already_exists'
|
|
33
35
|
| 'txs_not_available'
|
|
34
36
|
| 'state_mismatch'
|
|
@@ -45,28 +47,34 @@ type ReexecuteTransactionsResult = {
|
|
|
45
47
|
|
|
46
48
|
export type BlockProposalValidationSuccessResult = {
|
|
47
49
|
isValid: true;
|
|
48
|
-
blockNumber:
|
|
50
|
+
blockNumber: BlockNumber;
|
|
49
51
|
reexecutionResult?: ReexecuteTransactionsResult;
|
|
50
52
|
};
|
|
51
53
|
|
|
52
54
|
export type BlockProposalValidationFailureResult = {
|
|
53
55
|
isValid: false;
|
|
54
56
|
reason: BlockProposalValidationFailureReason;
|
|
55
|
-
blockNumber?:
|
|
57
|
+
blockNumber?: BlockNumber;
|
|
56
58
|
reexecutionResult?: ReexecuteTransactionsResult;
|
|
57
59
|
};
|
|
58
60
|
|
|
59
61
|
export type BlockProposalValidationResult = BlockProposalValidationSuccessResult | BlockProposalValidationFailureResult;
|
|
60
62
|
|
|
63
|
+
type CheckpointComputationResult =
|
|
64
|
+
| { checkpointNumber: CheckpointNumber; reason?: undefined }
|
|
65
|
+
| { checkpointNumber?: undefined; reason: 'invalid_proposal' | 'global_variables_mismatch' };
|
|
66
|
+
|
|
61
67
|
export class BlockProposalHandler {
|
|
62
68
|
public readonly tracer: Tracer;
|
|
63
69
|
|
|
64
70
|
constructor(
|
|
65
|
-
private
|
|
66
|
-
private
|
|
71
|
+
private checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
72
|
+
private worldState: WorldStateSynchronizer,
|
|
73
|
+
private blockSource: L2BlockSource & L2BlockSink,
|
|
67
74
|
private l1ToL2MessageSource: L1ToL2MessageSource,
|
|
68
|
-
private txProvider:
|
|
75
|
+
private txProvider: ITxProvider,
|
|
69
76
|
private blockProposalValidator: BlockProposalValidator,
|
|
77
|
+
private epochCache: EpochCache,
|
|
70
78
|
private config: ValidatorClientFullConfig,
|
|
71
79
|
private metrics?: ValidatorMetrics,
|
|
72
80
|
private dateProvider: DateProvider = new DateProvider(),
|
|
@@ -80,7 +88,9 @@ export class BlockProposalHandler {
|
|
|
80
88
|
}
|
|
81
89
|
|
|
82
90
|
registerForReexecution(p2pClient: P2P): BlockProposalHandler {
|
|
83
|
-
|
|
91
|
+
// Non-validator handler that re-executes for monitoring but does not attest.
|
|
92
|
+
// Returns boolean indicating whether the proposal was valid.
|
|
93
|
+
const handler = async (proposal: BlockProposal, proposalSender: PeerId): Promise<boolean> => {
|
|
84
94
|
try {
|
|
85
95
|
const result = await this.handleBlockProposal(proposal, proposalSender, true);
|
|
86
96
|
if (result.isValid) {
|
|
@@ -90,16 +100,18 @@ export class BlockProposalHandler {
|
|
|
90
100
|
totalManaUsed: result.reexecutionResult?.totalManaUsed,
|
|
91
101
|
numTxs: result.reexecutionResult?.block?.body?.txEffects?.length ?? 0,
|
|
92
102
|
});
|
|
103
|
+
return true;
|
|
93
104
|
} else {
|
|
94
105
|
this.log.warn(`Non-validator reexecution failed for slot ${proposal.slotNumber}`, {
|
|
95
106
|
blockNumber: result.blockNumber,
|
|
96
107
|
reason: result.reason,
|
|
97
108
|
});
|
|
109
|
+
return false;
|
|
98
110
|
}
|
|
99
111
|
} catch (error) {
|
|
100
112
|
this.log.error('Error processing block proposal in non-validator handler', error);
|
|
113
|
+
return false;
|
|
101
114
|
}
|
|
102
|
-
return undefined; // Non-validator nodes don't return attestations
|
|
103
115
|
};
|
|
104
116
|
|
|
105
117
|
p2pClient.registerBlockProposalHandler(handler);
|
|
@@ -113,7 +125,7 @@ export class BlockProposalHandler {
|
|
|
113
125
|
): Promise<BlockProposalValidationResult> {
|
|
114
126
|
const slotNumber = proposal.slotNumber;
|
|
115
127
|
const proposer = proposal.getSender();
|
|
116
|
-
const config = this.
|
|
128
|
+
const config = this.checkpointsBuilder.getConfig();
|
|
117
129
|
|
|
118
130
|
// Reject proposals with invalid signatures
|
|
119
131
|
if (!proposer) {
|
|
@@ -129,23 +141,23 @@ export class BlockProposalHandler {
|
|
|
129
141
|
|
|
130
142
|
// Check that the proposal is from the current proposer, or the next proposer
|
|
131
143
|
// This should have been handled by the p2p layer, but we double check here out of caution
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
144
|
+
const validationResult = await this.blockProposalValidator.validate(proposal);
|
|
145
|
+
if (validationResult.result !== 'accept') {
|
|
134
146
|
this.log.warn(`Proposal is not valid, skipping processing`, proposalInfo);
|
|
135
147
|
return { isValid: false, reason: 'invalid_proposal' };
|
|
136
148
|
}
|
|
137
149
|
|
|
138
150
|
// Check that the parent proposal is a block we know, otherwise reexecution would fail
|
|
139
|
-
const
|
|
140
|
-
if (
|
|
151
|
+
const parentBlock = await this.getParentBlock(proposal);
|
|
152
|
+
if (parentBlock === undefined) {
|
|
141
153
|
this.log.warn(`Parent block for proposal not found, skipping processing`, proposalInfo);
|
|
142
154
|
return { isValid: false, reason: 'parent_block_not_found' };
|
|
143
155
|
}
|
|
144
156
|
|
|
145
|
-
// Check that the parent block's slot is
|
|
146
|
-
if (
|
|
147
|
-
this.log.warn(`Parent block slot is greater than
|
|
148
|
-
parentBlockSlot:
|
|
157
|
+
// Check that the parent block's slot is not greater than the proposal's slot.
|
|
158
|
+
if (parentBlock !== 'genesis' && parentBlock.header.getSlot() > slotNumber) {
|
|
159
|
+
this.log.warn(`Parent block slot is greater than proposal slot, skipping processing`, {
|
|
160
|
+
parentBlockSlot: parentBlock.header.getSlot().toString(),
|
|
149
161
|
proposalSlot: slotNumber.toString(),
|
|
150
162
|
...proposalInfo,
|
|
151
163
|
});
|
|
@@ -153,7 +165,10 @@ export class BlockProposalHandler {
|
|
|
153
165
|
}
|
|
154
166
|
|
|
155
167
|
// Compute the block number based on the parent block
|
|
156
|
-
const blockNumber =
|
|
168
|
+
const blockNumber =
|
|
169
|
+
parentBlock === 'genesis'
|
|
170
|
+
? BlockNumber(INITIAL_L2_BLOCK_NUM)
|
|
171
|
+
: BlockNumber(parentBlock.header.getBlockNumber() + 1);
|
|
157
172
|
|
|
158
173
|
// Check that this block number does not exist already
|
|
159
174
|
const existingBlock = await this.blockSource.getBlockHeader(blockNumber);
|
|
@@ -169,10 +184,17 @@ export class BlockProposalHandler {
|
|
|
169
184
|
deadline: this.getReexecutionDeadline(slotNumber, config),
|
|
170
185
|
});
|
|
171
186
|
|
|
187
|
+
// Compute the checkpoint number for this block and validate checkpoint consistency
|
|
188
|
+
const checkpointResult = this.computeCheckpointNumber(proposal, parentBlock, proposalInfo);
|
|
189
|
+
if (checkpointResult.reason) {
|
|
190
|
+
return { isValid: false, blockNumber, reason: checkpointResult.reason };
|
|
191
|
+
}
|
|
192
|
+
const checkpointNumber = checkpointResult.checkpointNumber;
|
|
193
|
+
|
|
172
194
|
// Check that I have the same set of l1ToL2Messages as the proposal
|
|
173
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(
|
|
195
|
+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
174
196
|
const computedInHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
175
|
-
const proposalInHash = proposal.
|
|
197
|
+
const proposalInHash = proposal.inHash;
|
|
176
198
|
if (!computedInHash.equals(proposalInHash)) {
|
|
177
199
|
this.log.warn(`L1 to L2 messages in hash mismatch, skipping processing`, {
|
|
178
200
|
proposalInHash: proposalInHash.toString(),
|
|
@@ -191,9 +213,22 @@ export class BlockProposalHandler {
|
|
|
191
213
|
// Try re-executing the transactions in the proposal if needed
|
|
192
214
|
let reexecutionResult;
|
|
193
215
|
if (shouldReexecute) {
|
|
216
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
217
|
+
const epoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
|
|
218
|
+
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch))
|
|
219
|
+
.filter(c => c.checkpointNumber < checkpointNumber)
|
|
220
|
+
.map(c => c.checkpointOutHash);
|
|
221
|
+
|
|
194
222
|
try {
|
|
195
223
|
this.log.verbose(`Re-executing transactions in the proposal`, proposalInfo);
|
|
196
|
-
reexecutionResult = await this.reexecuteTransactions(
|
|
224
|
+
reexecutionResult = await this.reexecuteTransactions(
|
|
225
|
+
proposal,
|
|
226
|
+
blockNumber,
|
|
227
|
+
checkpointNumber,
|
|
228
|
+
txs,
|
|
229
|
+
l1ToL2Messages,
|
|
230
|
+
previousCheckpointOutHashes,
|
|
231
|
+
);
|
|
197
232
|
} catch (error) {
|
|
198
233
|
this.log.error(`Error reexecuting txs while processing block proposal`, error, proposalInfo);
|
|
199
234
|
const reason = this.getReexecuteFailureReason(error);
|
|
@@ -201,14 +236,23 @@ export class BlockProposalHandler {
|
|
|
201
236
|
}
|
|
202
237
|
}
|
|
203
238
|
|
|
204
|
-
this
|
|
239
|
+
// If we succeeded, push this block into the archiver (unless disabled)
|
|
240
|
+
if (reexecutionResult?.block && this.config.skipPushProposedBlocksToArchiver === false) {
|
|
241
|
+
await this.blockSource.addBlock(reexecutionResult?.block);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
this.log.info(
|
|
245
|
+
`Successfully processed block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`,
|
|
246
|
+
proposalInfo,
|
|
247
|
+
);
|
|
248
|
+
|
|
205
249
|
return { isValid: true, blockNumber, reexecutionResult };
|
|
206
250
|
}
|
|
207
251
|
|
|
208
|
-
private async getParentBlock(proposal: BlockProposal): Promise<'genesis' |
|
|
209
|
-
const parentArchive = proposal.
|
|
252
|
+
private async getParentBlock(proposal: BlockProposal): Promise<'genesis' | BlockData | undefined> {
|
|
253
|
+
const parentArchive = proposal.blockHeader.lastArchive.root;
|
|
210
254
|
const slot = proposal.slotNumber;
|
|
211
|
-
const config = this.
|
|
255
|
+
const config = this.checkpointsBuilder.getConfig();
|
|
212
256
|
const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
|
|
213
257
|
|
|
214
258
|
if (parentArchive.equals(genesisArchiveRoot)) {
|
|
@@ -221,12 +265,11 @@ export class BlockProposalHandler {
|
|
|
221
265
|
|
|
222
266
|
try {
|
|
223
267
|
return (
|
|
224
|
-
(await this.blockSource.
|
|
268
|
+
(await this.blockSource.getBlockDataByArchive(parentArchive)) ??
|
|
225
269
|
(timeoutDurationMs <= 0
|
|
226
270
|
? undefined
|
|
227
271
|
: await retryUntil(
|
|
228
|
-
() =>
|
|
229
|
-
this.blockSource.syncImmediate().then(() => this.blockSource.getBlockHeaderByArchive(parentArchive)),
|
|
272
|
+
() => this.blockSource.syncImmediate().then(() => this.blockSource.getBlockDataByArchive(parentArchive)),
|
|
230
273
|
'force archiver sync',
|
|
231
274
|
timeoutDurationMs / 1000,
|
|
232
275
|
0.5,
|
|
@@ -242,10 +285,132 @@ export class BlockProposalHandler {
|
|
|
242
285
|
}
|
|
243
286
|
}
|
|
244
287
|
|
|
288
|
+
private computeCheckpointNumber(
|
|
289
|
+
proposal: BlockProposal,
|
|
290
|
+
parentBlock: 'genesis' | BlockData,
|
|
291
|
+
proposalInfo: object,
|
|
292
|
+
): CheckpointComputationResult {
|
|
293
|
+
if (parentBlock === 'genesis') {
|
|
294
|
+
// First block is in checkpoint 1
|
|
295
|
+
if (proposal.indexWithinCheckpoint !== 0) {
|
|
296
|
+
this.log.warn(`First block proposal has non-zero indexWithinCheckpoint`, proposalInfo);
|
|
297
|
+
return { reason: 'invalid_proposal' };
|
|
298
|
+
}
|
|
299
|
+
return { checkpointNumber: CheckpointNumber.INITIAL };
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (proposal.indexWithinCheckpoint === 0) {
|
|
303
|
+
// If this is the first block in a new checkpoint, increment the checkpoint number
|
|
304
|
+
if (!(proposal.blockHeader.getSlot() > parentBlock.header.getSlot())) {
|
|
305
|
+
this.log.warn(`Slot should be greater than parent block slot for first block in checkpoint`, proposalInfo);
|
|
306
|
+
return { reason: 'invalid_proposal' };
|
|
307
|
+
}
|
|
308
|
+
return { checkpointNumber: CheckpointNumber(parentBlock.checkpointNumber + 1) };
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Otherwise it should follow the previous block in the same checkpoint
|
|
312
|
+
if (proposal.indexWithinCheckpoint !== parentBlock.indexWithinCheckpoint + 1) {
|
|
313
|
+
this.log.warn(`Non-sequential indexWithinCheckpoint`, proposalInfo);
|
|
314
|
+
return { reason: 'invalid_proposal' };
|
|
315
|
+
}
|
|
316
|
+
if (proposal.blockHeader.getSlot() !== parentBlock.header.getSlot()) {
|
|
317
|
+
this.log.warn(`Slot should be equal to parent block slot for non-first block in checkpoint`, proposalInfo);
|
|
318
|
+
return { reason: 'invalid_proposal' };
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// For non-first blocks in a checkpoint, validate global variables match parent (except blockNumber)
|
|
322
|
+
const validationResult = this.validateNonFirstBlockInCheckpoint(proposal, parentBlock, proposalInfo);
|
|
323
|
+
if (validationResult) {
|
|
324
|
+
return validationResult;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return { checkpointNumber: parentBlock.checkpointNumber };
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Validates that a non-first block in a checkpoint has consistent global variables with its parent.
|
|
332
|
+
* For blocks with indexWithinCheckpoint > 0, all global variables except blockNumber must match the parent.
|
|
333
|
+
* @returns A failure result if validation fails, undefined if validation passes
|
|
334
|
+
*/
|
|
335
|
+
private validateNonFirstBlockInCheckpoint(
|
|
336
|
+
proposal: BlockProposal,
|
|
337
|
+
parentBlock: BlockData,
|
|
338
|
+
proposalInfo: object,
|
|
339
|
+
): CheckpointComputationResult | undefined {
|
|
340
|
+
const proposalGlobals = proposal.blockHeader.globalVariables;
|
|
341
|
+
const parentGlobals = parentBlock.header.globalVariables;
|
|
342
|
+
|
|
343
|
+
// All global variables except blockNumber should match the parent
|
|
344
|
+
// blockNumber naturally increments between blocks
|
|
345
|
+
if (!proposalGlobals.chainId.equals(parentGlobals.chainId)) {
|
|
346
|
+
this.log.warn(`Non-first block in checkpoint has mismatched chainId`, {
|
|
347
|
+
...proposalInfo,
|
|
348
|
+
proposalChainId: proposalGlobals.chainId.toString(),
|
|
349
|
+
parentChainId: parentGlobals.chainId.toString(),
|
|
350
|
+
});
|
|
351
|
+
return { reason: 'global_variables_mismatch' };
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (!proposalGlobals.version.equals(parentGlobals.version)) {
|
|
355
|
+
this.log.warn(`Non-first block in checkpoint has mismatched version`, {
|
|
356
|
+
...proposalInfo,
|
|
357
|
+
proposalVersion: proposalGlobals.version.toString(),
|
|
358
|
+
parentVersion: parentGlobals.version.toString(),
|
|
359
|
+
});
|
|
360
|
+
return { reason: 'global_variables_mismatch' };
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (proposalGlobals.slotNumber !== parentGlobals.slotNumber) {
|
|
364
|
+
this.log.warn(`Non-first block in checkpoint has mismatched slotNumber`, {
|
|
365
|
+
...proposalInfo,
|
|
366
|
+
proposalSlotNumber: proposalGlobals.slotNumber,
|
|
367
|
+
parentSlotNumber: parentGlobals.slotNumber,
|
|
368
|
+
});
|
|
369
|
+
return { reason: 'global_variables_mismatch' };
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (proposalGlobals.timestamp !== parentGlobals.timestamp) {
|
|
373
|
+
this.log.warn(`Non-first block in checkpoint has mismatched timestamp`, {
|
|
374
|
+
...proposalInfo,
|
|
375
|
+
proposalTimestamp: proposalGlobals.timestamp.toString(),
|
|
376
|
+
parentTimestamp: parentGlobals.timestamp.toString(),
|
|
377
|
+
});
|
|
378
|
+
return { reason: 'global_variables_mismatch' };
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if (!proposalGlobals.coinbase.equals(parentGlobals.coinbase)) {
|
|
382
|
+
this.log.warn(`Non-first block in checkpoint has mismatched coinbase`, {
|
|
383
|
+
...proposalInfo,
|
|
384
|
+
proposalCoinbase: proposalGlobals.coinbase.toString(),
|
|
385
|
+
parentCoinbase: parentGlobals.coinbase.toString(),
|
|
386
|
+
});
|
|
387
|
+
return { reason: 'global_variables_mismatch' };
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (!proposalGlobals.feeRecipient.equals(parentGlobals.feeRecipient)) {
|
|
391
|
+
this.log.warn(`Non-first block in checkpoint has mismatched feeRecipient`, {
|
|
392
|
+
...proposalInfo,
|
|
393
|
+
proposalFeeRecipient: proposalGlobals.feeRecipient.toString(),
|
|
394
|
+
parentFeeRecipient: parentGlobals.feeRecipient.toString(),
|
|
395
|
+
});
|
|
396
|
+
return { reason: 'global_variables_mismatch' };
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (!proposalGlobals.gasFees.equals(parentGlobals.gasFees)) {
|
|
400
|
+
this.log.warn(`Non-first block in checkpoint has mismatched gasFees`, {
|
|
401
|
+
...proposalInfo,
|
|
402
|
+
proposalGasFees: proposalGlobals.gasFees.toInspect(),
|
|
403
|
+
parentGasFees: parentGlobals.gasFees.toInspect(),
|
|
404
|
+
});
|
|
405
|
+
return { reason: 'global_variables_mismatch' };
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return undefined;
|
|
409
|
+
}
|
|
410
|
+
|
|
245
411
|
private getReexecutionDeadline(slot: SlotNumber, config: { l1GenesisTime: bigint; slotDuration: number }): Date {
|
|
246
412
|
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
|
|
247
|
-
|
|
248
|
-
return new Date(nextSlotTimestampSeconds * 1000 - msNeededForPropagationAndPublishing);
|
|
413
|
+
return new Date(nextSlotTimestampSeconds * 1000);
|
|
249
414
|
}
|
|
250
415
|
|
|
251
416
|
private getReexecuteFailureReason(err: any) {
|
|
@@ -262,12 +427,13 @@ export class BlockProposalHandler {
|
|
|
262
427
|
|
|
263
428
|
async reexecuteTransactions(
|
|
264
429
|
proposal: BlockProposal,
|
|
265
|
-
blockNumber:
|
|
430
|
+
blockNumber: BlockNumber,
|
|
431
|
+
checkpointNumber: CheckpointNumber,
|
|
266
432
|
txs: Tx[],
|
|
267
433
|
l1ToL2Messages: Fr[],
|
|
434
|
+
previousCheckpointOutHashes: Fr[],
|
|
268
435
|
): Promise<ReexecuteTransactionsResult> {
|
|
269
|
-
const {
|
|
270
|
-
const { txHashes } = proposal;
|
|
436
|
+
const { blockHeader, txHashes } = proposal;
|
|
271
437
|
|
|
272
438
|
// If we do not have all of the transactions, then we should fail
|
|
273
439
|
if (txs.length !== txHashes.length) {
|
|
@@ -276,28 +442,52 @@ export class BlockProposalHandler {
|
|
|
276
442
|
throw new TransactionsNotAvailableError(missingTxHashes);
|
|
277
443
|
}
|
|
278
444
|
|
|
279
|
-
// Use the sequencer's block building logic to re-execute the transactions
|
|
280
445
|
const timer = new Timer();
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
446
|
+
const slot = proposal.slotNumber;
|
|
447
|
+
const config = this.checkpointsBuilder.getConfig();
|
|
448
|
+
|
|
449
|
+
// Get prior blocks in this checkpoint (same slot before current block)
|
|
450
|
+
const allBlocksInSlot = await this.blockSource.getBlocksForSlot(slot);
|
|
451
|
+
const priorBlocks = allBlocksInSlot.filter(b => b.number < blockNumber && b.header.getSlot() === slot);
|
|
452
|
+
|
|
453
|
+
// Fork before the block to be built
|
|
454
|
+
const parentBlockNumber = BlockNumber(blockNumber - 1);
|
|
455
|
+
await this.worldState.syncImmediate(parentBlockNumber);
|
|
456
|
+
await using fork = await this.worldState.fork(parentBlockNumber);
|
|
457
|
+
|
|
458
|
+
// Build checkpoint constants from proposal (excludes blockNumber which is per-block)
|
|
459
|
+
const constants: CheckpointGlobalVariables = {
|
|
291
460
|
chainId: new Fr(config.l1ChainId),
|
|
292
461
|
version: new Fr(config.rollupVersion),
|
|
293
|
-
|
|
462
|
+
slotNumber: slot,
|
|
463
|
+
timestamp: blockHeader.globalVariables.timestamp,
|
|
464
|
+
coinbase: blockHeader.globalVariables.coinbase,
|
|
465
|
+
feeRecipient: blockHeader.globalVariables.feeRecipient,
|
|
466
|
+
gasFees: blockHeader.globalVariables.gasFees,
|
|
467
|
+
};
|
|
294
468
|
|
|
295
|
-
|
|
296
|
-
|
|
469
|
+
// Create checkpoint builder with prior blocks
|
|
470
|
+
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
|
|
471
|
+
checkpointNumber,
|
|
472
|
+
constants,
|
|
473
|
+
0n, // only takes effect in the following checkpoint.
|
|
474
|
+
l1ToL2Messages,
|
|
475
|
+
previousCheckpointOutHashes,
|
|
476
|
+
fork,
|
|
477
|
+
priorBlocks,
|
|
478
|
+
this.log.getBindings(),
|
|
479
|
+
);
|
|
480
|
+
|
|
481
|
+
// Build the new block
|
|
482
|
+
const deadline = this.getReexecutionDeadline(slot, config);
|
|
483
|
+
const result = await checkpointBuilder.buildBlock(txs, blockNumber, blockHeader.globalVariables.timestamp, {
|
|
484
|
+
deadline,
|
|
485
|
+
expectedEndState: blockHeader.state,
|
|
297
486
|
});
|
|
298
487
|
|
|
488
|
+
const { block, failedTxs } = result;
|
|
299
489
|
const numFailedTxs = failedTxs.length;
|
|
300
|
-
|
|
490
|
+
|
|
301
491
|
this.log.verbose(`Transaction re-execution complete for slot ${slot}`, {
|
|
302
492
|
numFailedTxs,
|
|
303
493
|
numProposalTxs: txHashes.length,
|
|
@@ -316,11 +506,15 @@ export class BlockProposalHandler {
|
|
|
316
506
|
}
|
|
317
507
|
|
|
318
508
|
// Throw a ReExStateMismatchError error if state updates do not match
|
|
319
|
-
|
|
320
|
-
|
|
509
|
+
// Compare the full block structure (archive and header) from the built block with the proposal
|
|
510
|
+
const archiveMatches = proposal.archive.equals(block.archive.root);
|
|
511
|
+
const headerMatches = proposal.blockHeader.equals(block.header);
|
|
512
|
+
if (!archiveMatches || !headerMatches) {
|
|
321
513
|
this.log.warn(`Re-execution state mismatch for slot ${slot}`, {
|
|
322
|
-
|
|
323
|
-
|
|
514
|
+
expectedArchive: block.archive.root.toString(),
|
|
515
|
+
actualArchive: proposal.archive.toString(),
|
|
516
|
+
expectedHeader: block.header.toInspect(),
|
|
517
|
+
actualHeader: proposal.blockHeader.toInspect(),
|
|
324
518
|
});
|
|
325
519
|
this.metrics?.recordFailedReexecution(proposal);
|
|
326
520
|
throw new ReExStateMismatchError(proposal.archive, block.archive.root);
|