@aztec/validator-client 2.1.0-rc.9 → 3.0.0-devnet.2
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/block_proposal_handler.d.ts +23 -18
- package/dest/block_proposal_handler.d.ts.map +1 -1
- package/dest/block_proposal_handler.js +89 -60
- package/dest/duties/validation_service.d.ts +9 -7
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +15 -10
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +3 -1
- package/dest/metrics.d.ts +6 -4
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +23 -13
- package/dest/validator.d.ts +10 -9
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +68 -17
- package/package.json +12 -12
- package/src/block_proposal_handler.ts +116 -87
- package/src/duties/validation_service.ts +21 -15
- package/src/factory.ts +3 -1
- package/src/metrics.ts +32 -14
- package/src/validator.ts +86 -31
package/dest/validator.js
CHANGED
|
@@ -43,21 +43,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
43
43
|
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.blockProposalHandler = blockProposalHandler, this.config = config, this.dateProvider = dateProvider, this.log = log, this.hasRegisteredHandlers = false, this.proposersOfInvalidBlocks = new Set();
|
|
44
44
|
this.tracer = telemetry.getTracer('Validator');
|
|
45
45
|
this.metrics = new ValidatorMetrics(telemetry);
|
|
46
|
-
this.validationService = new ValidationService(keyStore);
|
|
46
|
+
this.validationService = new ValidationService(keyStore, log.createChild('validation-service'));
|
|
47
47
|
// Refresh epoch cache every second to trigger alert if participation in committee changes
|
|
48
48
|
this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), log, 1000);
|
|
49
49
|
const myAddresses = this.getValidatorAddresses();
|
|
50
50
|
this.log.verbose(`Initialized validator with addresses: ${myAddresses.map((a)=>a.toString()).join(', ')}`);
|
|
51
51
|
}
|
|
52
|
-
static validateKeyStoreConfiguration(keyStoreManager) {
|
|
52
|
+
static validateKeyStoreConfiguration(keyStoreManager, logger) {
|
|
53
53
|
const validatorKeyStore = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
54
54
|
const validatorAddresses = validatorKeyStore.getAddresses();
|
|
55
55
|
// Verify that we can retrieve all required data from the key store
|
|
56
56
|
for (const address of validatorAddresses){
|
|
57
57
|
// Functions throw if required data is not available
|
|
58
|
+
let coinbase;
|
|
59
|
+
let feeRecipient;
|
|
58
60
|
try {
|
|
59
|
-
validatorKeyStore.getCoinbaseAddress(address);
|
|
60
|
-
validatorKeyStore.getFeeRecipient(address);
|
|
61
|
+
coinbase = validatorKeyStore.getCoinbaseAddress(address);
|
|
62
|
+
feeRecipient = validatorKeyStore.getFeeRecipient(address);
|
|
61
63
|
} catch (error) {
|
|
62
64
|
throw new Error(`Failed to retrieve required data for validator address ${address}, error: ${error}`);
|
|
63
65
|
}
|
|
@@ -65,6 +67,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
65
67
|
if (!publisherAddresses.length) {
|
|
66
68
|
throw new Error(`No publisher addresses found for validator address ${address}`);
|
|
67
69
|
}
|
|
70
|
+
logger?.debug(`Validator ${address.toString()} configured with coinbase ${coinbase.toString()}, feeRecipient ${feeRecipient.toString()} and publishers ${publisherAddresses.map((x)=>x.toString()).join()}`);
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
73
|
async handleEpochCommitteeUpdate() {
|
|
@@ -91,7 +94,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
91
94
|
}
|
|
92
95
|
static new(config, blockBuilder, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
93
96
|
const metrics = new ValidatorMetrics(telemetry);
|
|
94
|
-
const blockProposalValidator = new BlockProposalValidator(epochCache
|
|
97
|
+
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
98
|
+
txsPermitted: !config.disableTransactions
|
|
99
|
+
});
|
|
95
100
|
const blockProposalHandler = new BlockProposalHandler(blockBuilder, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, config, metrics, dateProvider, telemetry);
|
|
96
101
|
const validator = new ValidatorClient(NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager), epochCache, p2pClient, blockProposalHandler, config, dateProvider, telemetry);
|
|
97
102
|
return validator;
|
|
@@ -103,8 +108,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
103
108
|
return this.blockProposalHandler;
|
|
104
109
|
}
|
|
105
110
|
// Proxy method for backwards compatibility with tests
|
|
106
|
-
reExecuteTransactions(proposal, txs, l1ToL2Messages) {
|
|
107
|
-
return this.blockProposalHandler.reexecuteTransactions(proposal, txs, l1ToL2Messages);
|
|
111
|
+
reExecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages) {
|
|
112
|
+
return this.blockProposalHandler.reexecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages);
|
|
108
113
|
}
|
|
109
114
|
signWithAddress(addr, msg) {
|
|
110
115
|
return this.keyStore.signTypedDataWithAddress(addr, msg);
|
|
@@ -157,15 +162,19 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
157
162
|
async attestToProposal(proposal, proposalSender) {
|
|
158
163
|
const slotNumber = proposal.slotNumber.toBigInt();
|
|
159
164
|
const proposer = proposal.getSender();
|
|
165
|
+
// Reject proposals with invalid signatures
|
|
166
|
+
if (!proposer) {
|
|
167
|
+
this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
160
170
|
// Check that I have any address in current committee before attesting
|
|
161
171
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
162
172
|
const partOfCommittee = inCommittee.length > 0;
|
|
163
|
-
const incFailedAttestation = (reason)=>this.metrics.incFailedAttestations(1, reason, partOfCommittee);
|
|
164
173
|
const proposalInfo = {
|
|
165
174
|
...proposal.toBlockInfo(),
|
|
166
175
|
proposer: proposer.toString()
|
|
167
176
|
};
|
|
168
|
-
this.log.info(`Received proposal for
|
|
177
|
+
this.log.info(`Received proposal for slot ${slotNumber}`, {
|
|
169
178
|
...proposalInfo,
|
|
170
179
|
txHashes: proposal.txHashes.map((t)=>t.toString())
|
|
171
180
|
});
|
|
@@ -176,8 +185,25 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
176
185
|
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute);
|
|
177
186
|
if (!validationResult.isValid) {
|
|
178
187
|
this.log.warn(`Proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
179
|
-
|
|
180
|
-
|
|
188
|
+
// Only track attestation failure metrics if we're actually in the committee
|
|
189
|
+
if (partOfCommittee) {
|
|
190
|
+
const reason = validationResult.reason || 'unknown';
|
|
191
|
+
// Classify failure reason: bad proposal vs node issue
|
|
192
|
+
const badProposalReasons = [
|
|
193
|
+
'invalid_proposal',
|
|
194
|
+
'state_mismatch',
|
|
195
|
+
'failed_txs',
|
|
196
|
+
'in_hash_mismatch',
|
|
197
|
+
'parent_block_wrong_slot'
|
|
198
|
+
];
|
|
199
|
+
if (badProposalReasons.includes(reason)) {
|
|
200
|
+
this.metrics.incFailedAttestationsBadProposal(1, reason);
|
|
201
|
+
} else {
|
|
202
|
+
// Node issues: parent_block_not_found, block_number_already_exists, txs_not_available, timeout, unknown_error
|
|
203
|
+
this.metrics.incFailedAttestationsNodeIssue(1, reason);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Slash invalid block proposals (can happen even when not in committee)
|
|
181
207
|
if (validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
|
|
182
208
|
this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
|
|
183
209
|
this.slashInvalidBlock(proposal);
|
|
@@ -190,13 +216,18 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
190
216
|
return undefined;
|
|
191
217
|
}
|
|
192
218
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
193
|
-
this.log.info(`Attesting to proposal for
|
|
194
|
-
this.metrics.
|
|
219
|
+
this.log.info(`Attesting to proposal for slot ${slotNumber}`, proposalInfo);
|
|
220
|
+
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
195
221
|
// If the above function does not throw an error, then we can attest to the proposal
|
|
196
222
|
return this.createBlockAttestationsFromProposal(proposal, inCommittee);
|
|
197
223
|
}
|
|
198
224
|
slashInvalidBlock(proposal) {
|
|
199
225
|
const proposer = proposal.getSender();
|
|
226
|
+
// Skip if signature is invalid (shouldn't happen since we validate earlier)
|
|
227
|
+
if (!proposer) {
|
|
228
|
+
this.log.warn(`Cannot slash proposal with invalid signature`);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
200
231
|
// Trim the set if it's too big.
|
|
201
232
|
if (this.proposersOfInvalidBlocks.size > MAX_PROPOSERS_OF_INVALID_BLOCKS) {
|
|
202
233
|
// remove oldest proposer. `values` is guaranteed to be in insertion order.
|
|
@@ -217,7 +248,10 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
217
248
|
this.log.verbose(`Already made a proposal for the same slot, skipping proposal`);
|
|
218
249
|
return Promise.resolve(undefined);
|
|
219
250
|
}
|
|
220
|
-
const newProposal = await this.validationService.createBlockProposal(
|
|
251
|
+
const newProposal = await this.validationService.createBlockProposal(header, archive, stateReference, txs, proposerAddress, {
|
|
252
|
+
...options,
|
|
253
|
+
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
254
|
+
});
|
|
221
255
|
this.previousProposal = newProposal;
|
|
222
256
|
return newProposal;
|
|
223
257
|
}
|
|
@@ -248,11 +282,28 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
248
282
|
const myAddresses = this.getValidatorAddresses();
|
|
249
283
|
let attestations = [];
|
|
250
284
|
while(true){
|
|
251
|
-
|
|
285
|
+
// Filter out attestations with a mismatching payload. This should NOT happen since we have verified
|
|
286
|
+
// the proposer signature (ie our own) before accepting the attestation into the pool via the p2p client.
|
|
287
|
+
const collectedAttestations = (await this.p2pClient.getAttestationsForSlot(slot, proposalId)).filter((attestation)=>{
|
|
288
|
+
if (!attestation.payload.equals(proposal.payload)) {
|
|
289
|
+
this.log.warn(`Received attestation for slot ${slot} with mismatched payload from ${attestation.getSender()?.toString()}`, {
|
|
290
|
+
attestationPayload: attestation.payload,
|
|
291
|
+
proposalPayload: proposal.payload
|
|
292
|
+
});
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
return true;
|
|
296
|
+
});
|
|
297
|
+
// Log new attestations we collected
|
|
252
298
|
const oldSenders = attestations.map((attestation)=>attestation.getSender());
|
|
253
299
|
for (const collected of collectedAttestations){
|
|
254
300
|
const collectedSender = collected.getSender();
|
|
255
|
-
|
|
301
|
+
// Skip attestations with invalid signatures
|
|
302
|
+
if (!collectedSender) {
|
|
303
|
+
this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
if (!myAddresses.some((address)=>address.equals(collectedSender)) && !oldSenders.some((sender)=>sender?.equals(collectedSender))) {
|
|
256
307
|
this.log.debug(`Received attestation for slot ${slot} from ${collectedSender.toString()}`);
|
|
257
308
|
}
|
|
258
309
|
}
|
|
@@ -265,7 +316,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
265
316
|
this.log.error(`Timeout ${deadline.toISOString()} waiting for ${required} attestations for slot ${slot}`);
|
|
266
317
|
throw new AttestationTimeoutError(attestations.length, required, slot);
|
|
267
318
|
}
|
|
268
|
-
this.log.debug(`Collected ${attestations.length} attestations so far`);
|
|
319
|
+
this.log.debug(`Collected ${attestations.length} of ${required} attestations so far`);
|
|
269
320
|
await sleep(this.config.attestationPollingIntervalMs);
|
|
270
321
|
}
|
|
271
322
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/validator-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-devnet.2",
|
|
4
4
|
"main": "dest/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -64,20 +64,20 @@
|
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@aztec/constants": "
|
|
68
|
-
"@aztec/epoch-cache": "
|
|
69
|
-
"@aztec/ethereum": "
|
|
70
|
-
"@aztec/foundation": "
|
|
71
|
-
"@aztec/node-keystore": "
|
|
72
|
-
"@aztec/p2p": "
|
|
73
|
-
"@aztec/prover-client": "
|
|
74
|
-
"@aztec/slasher": "
|
|
75
|
-
"@aztec/stdlib": "
|
|
76
|
-
"@aztec/telemetry-client": "
|
|
67
|
+
"@aztec/constants": "3.0.0-devnet.2",
|
|
68
|
+
"@aztec/epoch-cache": "3.0.0-devnet.2",
|
|
69
|
+
"@aztec/ethereum": "3.0.0-devnet.2",
|
|
70
|
+
"@aztec/foundation": "3.0.0-devnet.2",
|
|
71
|
+
"@aztec/node-keystore": "3.0.0-devnet.2",
|
|
72
|
+
"@aztec/p2p": "3.0.0-devnet.2",
|
|
73
|
+
"@aztec/prover-client": "3.0.0-devnet.2",
|
|
74
|
+
"@aztec/slasher": "3.0.0-devnet.2",
|
|
75
|
+
"@aztec/stdlib": "3.0.0-devnet.2",
|
|
76
|
+
"@aztec/telemetry-client": "3.0.0-devnet.2",
|
|
77
77
|
"koa": "^2.16.1",
|
|
78
78
|
"koa-router": "^13.1.1",
|
|
79
79
|
"tslib": "^2.4.0",
|
|
80
|
-
"viem": "2.
|
|
80
|
+
"viem": "npm:@spalladino/viem@2.38.2-eip7594.0"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
83
|
"@jest/globals": "^30.0.0",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
|
+
import { TimeoutError } from '@aztec/foundation/error';
|
|
2
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
5
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
@@ -7,12 +8,12 @@ import type { P2P, PeerId } from '@aztec/p2p';
|
|
|
7
8
|
import { TxProvider } from '@aztec/p2p';
|
|
8
9
|
import { BlockProposalValidator } from '@aztec/p2p/msg_validators';
|
|
9
10
|
import { computeInHashFromL1ToL2Messages } from '@aztec/prover-client/helpers';
|
|
10
|
-
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
11
|
+
import type { L2Block, L2BlockSource } from '@aztec/stdlib/block';
|
|
11
12
|
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
12
13
|
import type { IFullNodeBlockBuilder, ValidatorClientFullConfig } from '@aztec/stdlib/interfaces/server';
|
|
13
14
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
14
15
|
import { type BlockProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
|
|
15
|
-
import { type FailedTx, GlobalVariables, type Tx } from '@aztec/stdlib/tx';
|
|
16
|
+
import { BlockHeader, type FailedTx, GlobalVariables, type Tx } from '@aztec/stdlib/tx';
|
|
16
17
|
import {
|
|
17
18
|
ReExFailedTxsError,
|
|
18
19
|
ReExStateMismatchError,
|
|
@@ -26,7 +27,7 @@ import type { ValidatorMetrics } from './metrics.js';
|
|
|
26
27
|
export type BlockProposalValidationFailureReason =
|
|
27
28
|
| 'invalid_proposal'
|
|
28
29
|
| 'parent_block_not_found'
|
|
29
|
-
| '
|
|
30
|
+
| 'parent_block_wrong_slot'
|
|
30
31
|
| 'in_hash_mismatch'
|
|
31
32
|
| 'block_number_already_exists'
|
|
32
33
|
| 'txs_not_available'
|
|
@@ -35,16 +36,27 @@ export type BlockProposalValidationFailureReason =
|
|
|
35
36
|
| 'timeout'
|
|
36
37
|
| 'unknown_error';
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
type ReexecuteTransactionsResult = {
|
|
40
|
+
block: L2Block;
|
|
41
|
+
failedTxs: FailedTx[];
|
|
42
|
+
reexecutionTimeMs: number;
|
|
43
|
+
totalManaUsed: number;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type BlockProposalValidationSuccessResult = {
|
|
47
|
+
isValid: true;
|
|
48
|
+
blockNumber: number;
|
|
49
|
+
reexecutionResult?: ReexecuteTransactionsResult;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type BlockProposalValidationFailureResult = {
|
|
53
|
+
isValid: false;
|
|
54
|
+
reason: BlockProposalValidationFailureReason;
|
|
55
|
+
blockNumber?: number;
|
|
56
|
+
reexecutionResult?: ReexecuteTransactionsResult;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type BlockProposalValidationResult = BlockProposalValidationSuccessResult | BlockProposalValidationFailureResult;
|
|
48
60
|
|
|
49
61
|
export class BlockProposalHandler {
|
|
50
62
|
public readonly tracer: Tracer;
|
|
@@ -68,16 +80,16 @@ export class BlockProposalHandler {
|
|
|
68
80
|
const handler = async (proposal: BlockProposal, proposalSender: PeerId) => {
|
|
69
81
|
try {
|
|
70
82
|
const result = await this.handleBlockProposal(proposal, proposalSender, true);
|
|
71
|
-
if (result.isValid
|
|
83
|
+
if (result.isValid) {
|
|
72
84
|
this.log.info(`Non-validator reexecution completed for slot ${proposal.slotNumber.toBigInt()}`, {
|
|
73
|
-
blockNumber:
|
|
74
|
-
reexecutionTimeMs: result.reexecutionResult
|
|
75
|
-
totalManaUsed: result.reexecutionResult
|
|
76
|
-
numTxs: result.reexecutionResult
|
|
85
|
+
blockNumber: result.blockNumber,
|
|
86
|
+
reexecutionTimeMs: result.reexecutionResult?.reexecutionTimeMs,
|
|
87
|
+
totalManaUsed: result.reexecutionResult?.totalManaUsed,
|
|
88
|
+
numTxs: result.reexecutionResult?.block?.body?.txEffects?.length ?? 0,
|
|
77
89
|
});
|
|
78
90
|
} else {
|
|
79
91
|
this.log.warn(`Non-validator reexecution failed for slot ${proposal.slotNumber.toBigInt()}`, {
|
|
80
|
-
blockNumber:
|
|
92
|
+
blockNumber: result.blockNumber,
|
|
81
93
|
reason: result.reason,
|
|
82
94
|
});
|
|
83
95
|
}
|
|
@@ -97,8 +109,14 @@ export class BlockProposalHandler {
|
|
|
97
109
|
shouldReexecute: boolean,
|
|
98
110
|
): Promise<BlockProposalValidationResult> {
|
|
99
111
|
const slotNumber = proposal.slotNumber.toBigInt();
|
|
100
|
-
const blockNumber = proposal.blockNumber;
|
|
101
112
|
const proposer = proposal.getSender();
|
|
113
|
+
const config = this.blockBuilder.getConfig();
|
|
114
|
+
|
|
115
|
+
// Reject proposals with invalid signatures
|
|
116
|
+
if (!proposer) {
|
|
117
|
+
this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
|
|
118
|
+
return { isValid: false, reason: 'invalid_proposal' };
|
|
119
|
+
}
|
|
102
120
|
|
|
103
121
|
const proposalInfo = { ...proposal.toBlockInfo(), proposer: proposer.toString() };
|
|
104
122
|
this.log.info(`Processing proposal for slot ${slotNumber}`, {
|
|
@@ -114,52 +132,40 @@ export class BlockProposalHandler {
|
|
|
114
132
|
return { isValid: false, reason: 'invalid_proposal' };
|
|
115
133
|
}
|
|
116
134
|
|
|
117
|
-
// Collect txs from the proposal. We start doing this as early as possible,
|
|
118
|
-
// and we do it even if we don't plan to re-execute the txs, so that we have them
|
|
119
|
-
// if another node needs them.
|
|
120
|
-
const config = this.blockBuilder.getConfig();
|
|
121
|
-
const { txs, missingTxs } = await this.txProvider.getTxsForBlockProposal(proposal, {
|
|
122
|
-
pinnedPeer: proposalSender,
|
|
123
|
-
deadline: this.getReexecutionDeadline(proposal, config),
|
|
124
|
-
});
|
|
125
|
-
|
|
126
135
|
// Check that the parent proposal is a block we know, otherwise reexecution would fail
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
timeoutDurationMs <= 0
|
|
133
|
-
? undefined
|
|
134
|
-
: await retryUntil(
|
|
135
|
-
async () => {
|
|
136
|
-
const block = await this.blockSource.getBlock(blockNumber - 1);
|
|
137
|
-
if (block) {
|
|
138
|
-
return block;
|
|
139
|
-
}
|
|
140
|
-
await this.blockSource.syncImmediate();
|
|
141
|
-
return await this.blockSource.getBlock(blockNumber - 1);
|
|
142
|
-
},
|
|
143
|
-
'Force Archiver Sync',
|
|
144
|
-
timeoutDurationMs / 1000,
|
|
145
|
-
0.5,
|
|
146
|
-
);
|
|
136
|
+
const parentBlockHeader = await this.getParentBlock(proposal);
|
|
137
|
+
if (parentBlockHeader === undefined) {
|
|
138
|
+
this.log.warn(`Parent block for proposal not found, skipping processing`, proposalInfo);
|
|
139
|
+
return { isValid: false, reason: 'parent_block_not_found' };
|
|
140
|
+
}
|
|
147
141
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
142
|
+
// Check that the parent block's slot is less than the proposal's slot (should not happen, but we check anyway)
|
|
143
|
+
if (parentBlockHeader !== 'genesis' && parentBlockHeader.getSlot() >= slotNumber) {
|
|
144
|
+
this.log.warn(`Parent block slot is greater than or equal to proposal slot, skipping processing`, {
|
|
145
|
+
parentBlockSlot: parentBlockHeader.getSlot().toString(),
|
|
146
|
+
proposalSlot: slotNumber.toString(),
|
|
147
|
+
...proposalInfo,
|
|
148
|
+
});
|
|
149
|
+
return { isValid: false, reason: 'parent_block_wrong_slot' };
|
|
150
|
+
}
|
|
152
151
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
152
|
+
// Compute the block number based on the parent block
|
|
153
|
+
const blockNumber = parentBlockHeader === 'genesis' ? INITIAL_L2_BLOCK_NUM : parentBlockHeader.getBlockNumber() + 1;
|
|
154
|
+
|
|
155
|
+
// Check that this block number does not exist already
|
|
156
|
+
const existingBlock = await this.blockSource.getBlockHeader(blockNumber);
|
|
157
|
+
if (existingBlock) {
|
|
158
|
+
this.log.warn(`Block number ${blockNumber} already exists, skipping processing`, proposalInfo);
|
|
159
|
+
return { isValid: false, blockNumber, reason: 'block_number_already_exists' };
|
|
161
160
|
}
|
|
162
161
|
|
|
162
|
+
// Collect txs from the proposal. We start doing this as early as possible,
|
|
163
|
+
// and we do it even if we don't plan to re-execute the txs, so that we have them if another node needs them.
|
|
164
|
+
const { txs, missingTxs } = await this.txProvider.getTxsForBlockProposal(proposal, blockNumber, {
|
|
165
|
+
pinnedPeer: proposalSender,
|
|
166
|
+
deadline: this.getReexecutionDeadline(slotNumber, config),
|
|
167
|
+
});
|
|
168
|
+
|
|
163
169
|
// Check that I have the same set of l1ToL2Messages as the proposal
|
|
164
170
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(blockNumber);
|
|
165
171
|
const computedInHash = await computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
@@ -170,20 +176,13 @@ export class BlockProposalHandler {
|
|
|
170
176
|
computedInHash: computedInHash.toString(),
|
|
171
177
|
...proposalInfo,
|
|
172
178
|
});
|
|
173
|
-
return { isValid: false, reason: 'in_hash_mismatch' };
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Check that this block number does not exist already
|
|
177
|
-
const existingBlock = await this.blockSource.getBlockHeader(blockNumber);
|
|
178
|
-
if (existingBlock) {
|
|
179
|
-
this.log.warn(`Block number ${blockNumber} already exists, skipping processing`, proposalInfo);
|
|
180
|
-
return { isValid: false, reason: 'block_number_already_exists' };
|
|
179
|
+
return { isValid: false, blockNumber, reason: 'in_hash_mismatch' };
|
|
181
180
|
}
|
|
182
181
|
|
|
183
182
|
// Check that all of the transactions in the proposal are available
|
|
184
183
|
if (missingTxs.length > 0) {
|
|
185
184
|
this.log.warn(`Missing ${missingTxs.length} txs to process proposal`, { ...proposalInfo, missingTxs });
|
|
186
|
-
return { isValid: false, reason: 'txs_not_available' };
|
|
185
|
+
return { isValid: false, blockNumber, reason: 'txs_not_available' };
|
|
187
186
|
}
|
|
188
187
|
|
|
189
188
|
// Try re-executing the transactions in the proposal if needed
|
|
@@ -191,23 +190,57 @@ export class BlockProposalHandler {
|
|
|
191
190
|
if (shouldReexecute) {
|
|
192
191
|
try {
|
|
193
192
|
this.log.verbose(`Re-executing transactions in the proposal`, proposalInfo);
|
|
194
|
-
reexecutionResult = await this.reexecuteTransactions(proposal, txs, l1ToL2Messages);
|
|
193
|
+
reexecutionResult = await this.reexecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages);
|
|
195
194
|
} catch (error) {
|
|
196
195
|
this.log.error(`Error reexecuting txs while processing block proposal`, error, proposalInfo);
|
|
197
196
|
const reason = this.getReexecuteFailureReason(error);
|
|
198
|
-
return { isValid: false, reason, reexecutionResult };
|
|
197
|
+
return { isValid: false, blockNumber, reason, reexecutionResult };
|
|
199
198
|
}
|
|
200
199
|
}
|
|
201
200
|
|
|
202
201
|
this.log.info(`Successfully processed proposal for slot ${slotNumber}`, proposalInfo);
|
|
203
|
-
return { isValid: true, reexecutionResult };
|
|
202
|
+
return { isValid: true, blockNumber, reexecutionResult };
|
|
204
203
|
}
|
|
205
204
|
|
|
206
|
-
private
|
|
207
|
-
proposal
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const
|
|
205
|
+
private async getParentBlock(proposal: BlockProposal): Promise<'genesis' | BlockHeader | undefined> {
|
|
206
|
+
const parentArchive = proposal.payload.header.lastArchiveRoot;
|
|
207
|
+
const slot = proposal.slotNumber.toBigInt();
|
|
208
|
+
const config = this.blockBuilder.getConfig();
|
|
209
|
+
const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
|
|
210
|
+
|
|
211
|
+
if (parentArchive.equals(genesisArchiveRoot)) {
|
|
212
|
+
return 'genesis';
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const deadline = this.getReexecutionDeadline(slot, config);
|
|
216
|
+
const currentTime = this.dateProvider.now();
|
|
217
|
+
const timeoutDurationMs = deadline.getTime() - currentTime;
|
|
218
|
+
|
|
219
|
+
try {
|
|
220
|
+
return (
|
|
221
|
+
(await this.blockSource.getBlockHeaderByArchive(parentArchive)) ??
|
|
222
|
+
(timeoutDurationMs <= 0
|
|
223
|
+
? undefined
|
|
224
|
+
: await retryUntil(
|
|
225
|
+
() =>
|
|
226
|
+
this.blockSource.syncImmediate().then(() => this.blockSource.getBlockHeaderByArchive(parentArchive)),
|
|
227
|
+
'force archiver sync',
|
|
228
|
+
timeoutDurationMs / 1000,
|
|
229
|
+
0.5,
|
|
230
|
+
))
|
|
231
|
+
);
|
|
232
|
+
} catch (err) {
|
|
233
|
+
if (err instanceof TimeoutError) {
|
|
234
|
+
this.log.debug(`Timed out getting parent block by archive root`, { parentArchive });
|
|
235
|
+
} else {
|
|
236
|
+
this.log.error('Error getting parent block by archive root', err, { parentArchive });
|
|
237
|
+
}
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
private getReexecutionDeadline(slot: bigint, config: { l1GenesisTime: bigint; slotDuration: number }): Date {
|
|
243
|
+
const nextSlotTimestampSeconds = Number(getTimestampForSlot(slot + 1n, config));
|
|
211
244
|
const msNeededForPropagationAndPublishing = this.config.validatorReexecuteDeadlineMs;
|
|
212
245
|
return new Date(nextSlotTimestampSeconds * 1000 - msNeededForPropagationAndPublishing);
|
|
213
246
|
}
|
|
@@ -219,21 +252,17 @@ export class BlockProposalHandler {
|
|
|
219
252
|
return 'failed_txs';
|
|
220
253
|
} else if (err instanceof ReExTimeoutError) {
|
|
221
254
|
return 'timeout';
|
|
222
|
-
} else
|
|
255
|
+
} else {
|
|
223
256
|
return 'unknown_error';
|
|
224
257
|
}
|
|
225
258
|
}
|
|
226
259
|
|
|
227
260
|
async reexecuteTransactions(
|
|
228
261
|
proposal: BlockProposal,
|
|
262
|
+
blockNumber: number,
|
|
229
263
|
txs: Tx[],
|
|
230
264
|
l1ToL2Messages: Fr[],
|
|
231
|
-
): Promise<{
|
|
232
|
-
block: any;
|
|
233
|
-
failedTxs: FailedTx[];
|
|
234
|
-
reexecutionTimeMs: number;
|
|
235
|
-
totalManaUsed: number;
|
|
236
|
-
}> {
|
|
265
|
+
): Promise<ReexecuteTransactionsResult> {
|
|
237
266
|
const { header } = proposal.payload;
|
|
238
267
|
const { txHashes } = proposal;
|
|
239
268
|
|
|
@@ -254,14 +283,14 @@ export class BlockProposalHandler {
|
|
|
254
283
|
coinbase: proposal.payload.header.coinbase, // set arbitrarily by the proposer
|
|
255
284
|
feeRecipient: proposal.payload.header.feeRecipient, // set arbitrarily by the proposer
|
|
256
285
|
gasFees: proposal.payload.header.gasFees, // validated by the rollup contract
|
|
257
|
-
blockNumber
|
|
286
|
+
blockNumber, // computed from the parent block and checked it does not exist in archiver
|
|
258
287
|
timestamp: header.timestamp, // checked in the rollup contract against the slot number
|
|
259
288
|
chainId: new Fr(config.l1ChainId),
|
|
260
289
|
version: new Fr(config.rollupVersion),
|
|
261
290
|
});
|
|
262
291
|
|
|
263
292
|
const { block, failedTxs } = await this.blockBuilder.buildBlock(txs, l1ToL2Messages, globalVariables, {
|
|
264
|
-
deadline: this.getReexecutionDeadline(proposal, config),
|
|
293
|
+
deadline: this.getReexecutionDeadline(proposal.payload.header.slotNumber.toBigInt(), config),
|
|
265
294
|
});
|
|
266
295
|
|
|
267
296
|
const numFailedTxs = failedTxs.length;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
2
|
import { keccak256 } from '@aztec/foundation/crypto';
|
|
3
3
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
-
import { Signature } from '@aztec/foundation/eth-signature';
|
|
5
|
-
import
|
|
4
|
+
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
5
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
6
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
7
|
+
import { unfreeze } from '@aztec/foundation/types';
|
|
6
8
|
import type { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
7
9
|
import {
|
|
8
10
|
BlockAttestation,
|
|
@@ -11,26 +13,30 @@ import {
|
|
|
11
13
|
ConsensusPayload,
|
|
12
14
|
SignatureDomainSeparator,
|
|
13
15
|
} from '@aztec/stdlib/p2p';
|
|
14
|
-
import type {
|
|
16
|
+
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
17
|
+
import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
|
|
18
|
+
import { StateReference, type Tx } from '@aztec/stdlib/tx';
|
|
15
19
|
|
|
16
20
|
import type { ValidatorKeyStore } from '../key_store/interface.js';
|
|
17
21
|
|
|
18
22
|
export class ValidationService {
|
|
19
|
-
constructor(
|
|
23
|
+
constructor(
|
|
24
|
+
private keyStore: ValidatorKeyStore,
|
|
25
|
+
private log = createLogger('validator:validation-service'),
|
|
26
|
+
) {}
|
|
20
27
|
|
|
21
28
|
/**
|
|
22
29
|
* Create a block proposal with the given header, archive, and transactions
|
|
23
30
|
*
|
|
24
|
-
* @param blockNumber - The block number this proposal is for
|
|
25
31
|
* @param header - The block header
|
|
26
32
|
* @param archive - The archive of the current block
|
|
27
33
|
* @param txs - TxHash[] ordered list of transactions
|
|
34
|
+
* @param options - Block proposal options (including broadcastInvalidBlockProposal for testing)
|
|
28
35
|
*
|
|
29
36
|
* @returns A block proposal signing the above information (not the current implementation!!!)
|
|
30
37
|
*/
|
|
31
38
|
async createBlockProposal(
|
|
32
|
-
|
|
33
|
-
header: ProposedBlockHeader,
|
|
39
|
+
header: CheckpointHeader,
|
|
34
40
|
archive: Fr,
|
|
35
41
|
stateReference: StateReference,
|
|
36
42
|
txs: Tx[],
|
|
@@ -48,8 +54,13 @@ export class ValidationService {
|
|
|
48
54
|
// TODO: check if this is calculated earlier / can not be recomputed
|
|
49
55
|
const txHashes = await Promise.all(txs.map(tx => tx.getTxHash()));
|
|
50
56
|
|
|
57
|
+
// For testing: corrupt the state reference to trigger state_mismatch validation failure
|
|
58
|
+
if (options.broadcastInvalidBlockProposal) {
|
|
59
|
+
unfreeze(stateReference.partial).noteHashTree = AppendOnlyTreeSnapshot.random();
|
|
60
|
+
this.log.warn(`Creating INVALID block proposal for slot ${header.slotNumber.toBigInt()}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
51
63
|
return BlockProposal.createProposalFromSigner(
|
|
52
|
-
blockNumber,
|
|
53
64
|
new ConsensusPayload(header, archive, stateReference),
|
|
54
65
|
txHashes,
|
|
55
66
|
options.publishFullTxs ? txs : undefined,
|
|
@@ -74,18 +85,13 @@ export class ValidationService {
|
|
|
74
85
|
const signatures = await Promise.all(
|
|
75
86
|
attestors.map(attestor => this.keyStore.signMessageWithAddress(attestor, buf)),
|
|
76
87
|
);
|
|
77
|
-
|
|
78
|
-
return signatures.map(sig => new BlockAttestation(proposal.blockNumber, proposal.payload, sig));
|
|
88
|
+
return signatures.map(sig => new BlockAttestation(proposal.payload, sig, proposal.signature));
|
|
79
89
|
}
|
|
80
90
|
|
|
81
91
|
async signAttestationsAndSigners(
|
|
82
92
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
83
|
-
proposer: EthAddress
|
|
93
|
+
proposer: EthAddress,
|
|
84
94
|
): Promise<Signature> {
|
|
85
|
-
if (proposer === undefined) {
|
|
86
|
-
return Signature.empty();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
95
|
const buf = Buffer32.fromBuffer(
|
|
90
96
|
keccak256(attestationsAndSigners.getPayloadToSign(SignatureDomainSeparator.attestationsAndSigners)),
|
|
91
97
|
);
|
package/src/factory.ts
CHANGED
|
@@ -24,7 +24,9 @@ export function createBlockProposalHandler(
|
|
|
24
24
|
},
|
|
25
25
|
) {
|
|
26
26
|
const metrics = new ValidatorMetrics(deps.telemetry);
|
|
27
|
-
const blockProposalValidator = new BlockProposalValidator(deps.epochCache
|
|
27
|
+
const blockProposalValidator = new BlockProposalValidator(deps.epochCache, {
|
|
28
|
+
txsPermitted: !config.disableTransactions,
|
|
29
|
+
});
|
|
28
30
|
return new BlockProposalHandler(
|
|
29
31
|
deps.blockBuilder,
|
|
30
32
|
deps.blockSource,
|