@aztec/validator-client 2.1.0-rc.3 → 2.1.0-rc.31
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 +1 -2
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +3 -5
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +3 -1
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
- package/dest/key_store/web3signer_key_store.js +7 -8
- package/dest/metrics.d.ts +6 -4
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +24 -12
- package/dest/validator.d.ts +3 -4
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +54 -12
- package/package.json +12 -12
- package/src/block_proposal_handler.ts +116 -87
- package/src/duties/validation_service.ts +1 -5
- package/src/factory.ts +3 -1
- package/src/key_store/web3signer_key_store.ts +7 -10
- package/src/metrics.ts +34 -14
- package/src/validator.ts +67 -21
package/dest/validator.js
CHANGED
|
@@ -91,7 +91,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
91
91
|
}
|
|
92
92
|
static new(config, blockBuilder, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
93
93
|
const metrics = new ValidatorMetrics(telemetry);
|
|
94
|
-
const blockProposalValidator = new BlockProposalValidator(epochCache
|
|
94
|
+
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
95
|
+
txsPermitted: !config.disableTransactions
|
|
96
|
+
});
|
|
95
97
|
const blockProposalHandler = new BlockProposalHandler(blockBuilder, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, config, metrics, dateProvider, telemetry);
|
|
96
98
|
const validator = new ValidatorClient(NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager), epochCache, p2pClient, blockProposalHandler, config, dateProvider, telemetry);
|
|
97
99
|
return validator;
|
|
@@ -103,8 +105,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
103
105
|
return this.blockProposalHandler;
|
|
104
106
|
}
|
|
105
107
|
// Proxy method for backwards compatibility with tests
|
|
106
|
-
reExecuteTransactions(proposal, txs, l1ToL2Messages) {
|
|
107
|
-
return this.blockProposalHandler.reexecuteTransactions(proposal, txs, l1ToL2Messages);
|
|
108
|
+
reExecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages) {
|
|
109
|
+
return this.blockProposalHandler.reexecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages);
|
|
108
110
|
}
|
|
109
111
|
signWithAddress(addr, msg) {
|
|
110
112
|
return this.keyStore.signTypedDataWithAddress(addr, msg);
|
|
@@ -157,15 +159,19 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
157
159
|
async attestToProposal(proposal, proposalSender) {
|
|
158
160
|
const slotNumber = proposal.slotNumber.toBigInt();
|
|
159
161
|
const proposer = proposal.getSender();
|
|
162
|
+
// Reject proposals with invalid signatures
|
|
163
|
+
if (!proposer) {
|
|
164
|
+
this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
160
167
|
// Check that I have any address in current committee before attesting
|
|
161
168
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
162
169
|
const partOfCommittee = inCommittee.length > 0;
|
|
163
|
-
const incFailedAttestation = (reason)=>this.metrics.incFailedAttestations(1, reason, partOfCommittee);
|
|
164
170
|
const proposalInfo = {
|
|
165
171
|
...proposal.toBlockInfo(),
|
|
166
172
|
proposer: proposer.toString()
|
|
167
173
|
};
|
|
168
|
-
this.log.info(`Received proposal for
|
|
174
|
+
this.log.info(`Received proposal for slot ${slotNumber}`, {
|
|
169
175
|
...proposalInfo,
|
|
170
176
|
txHashes: proposal.txHashes.map((t)=>t.toString())
|
|
171
177
|
});
|
|
@@ -176,8 +182,22 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
176
182
|
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute);
|
|
177
183
|
if (!validationResult.isValid) {
|
|
178
184
|
this.log.warn(`Proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
179
|
-
|
|
180
|
-
//
|
|
185
|
+
const reason = validationResult.reason || 'unknown';
|
|
186
|
+
// Classify failure reason: bad proposal vs node issue
|
|
187
|
+
const badProposalReasons = [
|
|
188
|
+
'invalid_proposal',
|
|
189
|
+
'state_mismatch',
|
|
190
|
+
'failed_txs',
|
|
191
|
+
'in_hash_mismatch',
|
|
192
|
+
'parent_block_wrong_slot'
|
|
193
|
+
];
|
|
194
|
+
if (badProposalReasons.includes(reason)) {
|
|
195
|
+
this.metrics.incFailedAttestationsBadProposal(1, reason, partOfCommittee);
|
|
196
|
+
} else {
|
|
197
|
+
// Node issues so we can't attest
|
|
198
|
+
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
199
|
+
}
|
|
200
|
+
// Slash invalid block proposals (can happen even when not in committee)
|
|
181
201
|
if (validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
|
|
182
202
|
this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
|
|
183
203
|
this.slashInvalidBlock(proposal);
|
|
@@ -190,13 +210,18 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
190
210
|
return undefined;
|
|
191
211
|
}
|
|
192
212
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
193
|
-
this.log.info(`Attesting to proposal for block
|
|
194
|
-
this.metrics.
|
|
213
|
+
this.log.info(`Attesting to proposal for block at slot ${slotNumber}`, proposalInfo);
|
|
214
|
+
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
195
215
|
// If the above function does not throw an error, then we can attest to the proposal
|
|
196
216
|
return this.createBlockAttestationsFromProposal(proposal, inCommittee);
|
|
197
217
|
}
|
|
198
218
|
slashInvalidBlock(proposal) {
|
|
199
219
|
const proposer = proposal.getSender();
|
|
220
|
+
// Skip if signature is invalid (shouldn't happen since we validate earlier)
|
|
221
|
+
if (!proposer) {
|
|
222
|
+
this.log.warn(`Cannot slash proposal with invalid signature`);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
200
225
|
// Trim the set if it's too big.
|
|
201
226
|
if (this.proposersOfInvalidBlocks.size > MAX_PROPOSERS_OF_INVALID_BLOCKS) {
|
|
202
227
|
// remove oldest proposer. `values` is guaranteed to be in insertion order.
|
|
@@ -217,7 +242,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
217
242
|
this.log.verbose(`Already made a proposal for the same slot, skipping proposal`);
|
|
218
243
|
return Promise.resolve(undefined);
|
|
219
244
|
}
|
|
220
|
-
const newProposal = await this.validationService.createBlockProposal(
|
|
245
|
+
const newProposal = await this.validationService.createBlockProposal(header, archive, stateReference, txs, proposerAddress, options);
|
|
221
246
|
this.previousProposal = newProposal;
|
|
222
247
|
return newProposal;
|
|
223
248
|
}
|
|
@@ -248,11 +273,28 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
248
273
|
const myAddresses = this.getValidatorAddresses();
|
|
249
274
|
let attestations = [];
|
|
250
275
|
while(true){
|
|
251
|
-
|
|
276
|
+
// Filter out attestations with a mismatching payload. This should NOT happen since we have verified
|
|
277
|
+
// the proposer signature (ie our own) before accepting the attestation into the pool via the p2p client.
|
|
278
|
+
const collectedAttestations = (await this.p2pClient.getAttestationsForSlot(slot, proposalId)).filter((attestation)=>{
|
|
279
|
+
if (!attestation.payload.equals(proposal.payload)) {
|
|
280
|
+
this.log.warn(`Received attestation for slot ${slot} with mismatched payload from ${attestation.getSender()?.toString()}`, {
|
|
281
|
+
attestationPayload: attestation.payload,
|
|
282
|
+
proposalPayload: proposal.payload
|
|
283
|
+
});
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
return true;
|
|
287
|
+
});
|
|
288
|
+
// Log new attestations we collected
|
|
252
289
|
const oldSenders = attestations.map((attestation)=>attestation.getSender());
|
|
253
290
|
for (const collected of collectedAttestations){
|
|
254
291
|
const collectedSender = collected.getSender();
|
|
255
|
-
|
|
292
|
+
// Skip attestations with invalid signatures
|
|
293
|
+
if (!collectedSender) {
|
|
294
|
+
this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
if (!myAddresses.some((address)=>address.equals(collectedSender)) && !oldSenders.some((sender)=>sender?.equals(collectedSender))) {
|
|
256
298
|
this.log.debug(`Received attestation for slot ${slot} from ${collectedSender.toString()}`);
|
|
257
299
|
}
|
|
258
300
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/validator-client",
|
|
3
|
-
"version": "2.1.0-rc.
|
|
3
|
+
"version": "2.1.0-rc.31",
|
|
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": "2.1.0-rc.
|
|
68
|
-
"@aztec/epoch-cache": "2.1.0-rc.
|
|
69
|
-
"@aztec/ethereum": "2.1.0-rc.
|
|
70
|
-
"@aztec/foundation": "2.1.0-rc.
|
|
71
|
-
"@aztec/node-keystore": "2.1.0-rc.
|
|
72
|
-
"@aztec/p2p": "2.1.0-rc.
|
|
73
|
-
"@aztec/prover-client": "2.1.0-rc.
|
|
74
|
-
"@aztec/slasher": "2.1.0-rc.
|
|
75
|
-
"@aztec/stdlib": "2.1.0-rc.
|
|
76
|
-
"@aztec/telemetry-client": "2.1.0-rc.
|
|
67
|
+
"@aztec/constants": "2.1.0-rc.31",
|
|
68
|
+
"@aztec/epoch-cache": "2.1.0-rc.31",
|
|
69
|
+
"@aztec/ethereum": "2.1.0-rc.31",
|
|
70
|
+
"@aztec/foundation": "2.1.0-rc.31",
|
|
71
|
+
"@aztec/node-keystore": "2.1.0-rc.31",
|
|
72
|
+
"@aztec/p2p": "2.1.0-rc.31",
|
|
73
|
+
"@aztec/prover-client": "2.1.0-rc.31",
|
|
74
|
+
"@aztec/slasher": "2.1.0-rc.31",
|
|
75
|
+
"@aztec/stdlib": "2.1.0-rc.31",
|
|
76
|
+
"@aztec/telemetry-client": "2.1.0-rc.31",
|
|
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;
|
|
@@ -21,7 +21,6 @@ export class ValidationService {
|
|
|
21
21
|
/**
|
|
22
22
|
* Create a block proposal with the given header, archive, and transactions
|
|
23
23
|
*
|
|
24
|
-
* @param blockNumber - The block number this proposal is for
|
|
25
24
|
* @param header - The block header
|
|
26
25
|
* @param archive - The archive of the current block
|
|
27
26
|
* @param txs - TxHash[] ordered list of transactions
|
|
@@ -29,7 +28,6 @@ export class ValidationService {
|
|
|
29
28
|
* @returns A block proposal signing the above information (not the current implementation!!!)
|
|
30
29
|
*/
|
|
31
30
|
async createBlockProposal(
|
|
32
|
-
blockNumber: number,
|
|
33
31
|
header: ProposedBlockHeader,
|
|
34
32
|
archive: Fr,
|
|
35
33
|
stateReference: StateReference,
|
|
@@ -49,7 +47,6 @@ export class ValidationService {
|
|
|
49
47
|
const txHashes = await Promise.all(txs.map(tx => tx.getTxHash()));
|
|
50
48
|
|
|
51
49
|
return BlockProposal.createProposalFromSigner(
|
|
52
|
-
blockNumber,
|
|
53
50
|
new ConsensusPayload(header, archive, stateReference),
|
|
54
51
|
txHashes,
|
|
55
52
|
options.publishFullTxs ? txs : undefined,
|
|
@@ -74,8 +71,7 @@ export class ValidationService {
|
|
|
74
71
|
const signatures = await Promise.all(
|
|
75
72
|
attestors.map(attestor => this.keyStore.signMessageWithAddress(attestor, buf)),
|
|
76
73
|
);
|
|
77
|
-
|
|
78
|
-
return signatures.map(sig => new BlockAttestation(proposal.blockNumber, proposal.payload, sig));
|
|
74
|
+
return signatures.map(sig => new BlockAttestation(proposal.payload, sig, proposal.signature));
|
|
79
75
|
}
|
|
80
76
|
|
|
81
77
|
async signAttestationsAndSigners(
|
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,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
+
import { normalizeSignature } from '@aztec/foundation/crypto';
|
|
2
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
4
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
4
5
|
|
|
@@ -45,11 +46,8 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
|
|
|
45
46
|
* @param typedData - The complete EIP-712 typed data structure (domain, types, primaryType, message)
|
|
46
47
|
* @return signatures
|
|
47
48
|
*/
|
|
48
|
-
public
|
|
49
|
-
|
|
50
|
-
this.addresses.map(address => this.makeJsonRpcSignTypedDataRequest(address, typedData)),
|
|
51
|
-
);
|
|
52
|
-
return signatures;
|
|
49
|
+
public signTypedData(typedData: TypedDataDefinition): Promise<Signature[]> {
|
|
50
|
+
return Promise.all(this.addresses.map(address => this.makeJsonRpcSignTypedDataRequest(address, typedData)));
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
/**
|
|
@@ -73,9 +71,8 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
|
|
|
73
71
|
* @param message - The message to sign
|
|
74
72
|
* @return signatures
|
|
75
73
|
*/
|
|
76
|
-
public
|
|
77
|
-
|
|
78
|
-
return signatures;
|
|
74
|
+
public signMessage(message: Buffer32): Promise<Signature[]> {
|
|
75
|
+
return Promise.all(this.addresses.map(address => this.makeJsonRpcSignRequest(address, message)));
|
|
79
76
|
}
|
|
80
77
|
|
|
81
78
|
/**
|
|
@@ -144,7 +141,7 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
|
|
|
144
141
|
}
|
|
145
142
|
|
|
146
143
|
// Parse the signature from the hex string
|
|
147
|
-
return Signature.fromString(signatureHex as `0x${string}`);
|
|
144
|
+
return normalizeSignature(Signature.fromString(signatureHex as `0x${string}`));
|
|
148
145
|
}
|
|
149
146
|
|
|
150
147
|
private async makeJsonRpcSignTypedDataRequest(
|
|
@@ -190,6 +187,6 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
|
|
|
190
187
|
signatureHex = '0x' + signatureHex;
|
|
191
188
|
}
|
|
192
189
|
|
|
193
|
-
return Signature.fromString(signatureHex as `0x${string}`);
|
|
190
|
+
return normalizeSignature(Signature.fromString(signatureHex as `0x${string}`));
|
|
194
191
|
}
|
|
195
192
|
}
|
package/src/metrics.ts
CHANGED
|
@@ -10,8 +10,9 @@ import {
|
|
|
10
10
|
|
|
11
11
|
export class ValidatorMetrics {
|
|
12
12
|
private failedReexecutionCounter: UpDownCounter;
|
|
13
|
-
private
|
|
14
|
-
private
|
|
13
|
+
private successfulAttestationsCount: UpDownCounter;
|
|
14
|
+
private failedAttestationsBadProposalCount: UpDownCounter;
|
|
15
|
+
private failedAttestationsNodeIssueCount: UpDownCounter;
|
|
15
16
|
|
|
16
17
|
private reexMana: Histogram;
|
|
17
18
|
private reexTx: Histogram;
|
|
@@ -26,15 +27,26 @@ export class ValidatorMetrics {
|
|
|
26
27
|
valueType: ValueType.INT,
|
|
27
28
|
});
|
|
28
29
|
|
|
29
|
-
this.
|
|
30
|
-
description: 'The number of attestations',
|
|
30
|
+
this.successfulAttestationsCount = meter.createUpDownCounter(Metrics.VALIDATOR_ATTESTATION_SUCCESS_COUNT, {
|
|
31
|
+
description: 'The number of successful attestations',
|
|
31
32
|
valueType: ValueType.INT,
|
|
32
33
|
});
|
|
33
34
|
|
|
34
|
-
this.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
this.failedAttestationsBadProposalCount = meter.createUpDownCounter(
|
|
36
|
+
Metrics.VALIDATOR_ATTESTATION_FAILED_BAD_PROPOSAL_COUNT,
|
|
37
|
+
{
|
|
38
|
+
description: 'The number of failed attestations due to invalid block proposals',
|
|
39
|
+
valueType: ValueType.INT,
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
this.failedAttestationsNodeIssueCount = meter.createUpDownCounter(
|
|
44
|
+
Metrics.VALIDATOR_ATTESTATION_FAILED_NODE_ISSUE_COUNT,
|
|
45
|
+
{
|
|
46
|
+
description: 'The number of failed attestations due to node issues (timeout, missing data, etc.)',
|
|
47
|
+
valueType: ValueType.INT,
|
|
48
|
+
},
|
|
49
|
+
);
|
|
38
50
|
|
|
39
51
|
this.reexMana = meter.createHistogram(Metrics.VALIDATOR_RE_EXECUTION_MANA, {
|
|
40
52
|
description: 'The mana consumed by blocks',
|
|
@@ -62,20 +74,28 @@ export class ValidatorMetrics {
|
|
|
62
74
|
}
|
|
63
75
|
|
|
64
76
|
public recordFailedReexecution(proposal: BlockProposal) {
|
|
77
|
+
const proposer = proposal.getSender();
|
|
65
78
|
this.failedReexecutionCounter.add(1, {
|
|
66
79
|
[Attributes.STATUS]: 'failed',
|
|
67
|
-
[Attributes.BLOCK_PROPOSER]:
|
|
80
|
+
[Attributes.BLOCK_PROPOSER]: proposer?.toString() ?? 'unknown',
|
|
68
81
|
});
|
|
69
82
|
}
|
|
70
83
|
|
|
71
|
-
public
|
|
72
|
-
this.
|
|
84
|
+
public incSuccessfulAttestations(num: number) {
|
|
85
|
+
this.successfulAttestationsCount.add(num);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public incFailedAttestationsBadProposal(num: number, reason: string, inCommittee: boolean) {
|
|
89
|
+
this.failedAttestationsBadProposalCount.add(num, {
|
|
90
|
+
[Attributes.ERROR_TYPE]: reason,
|
|
91
|
+
[Attributes.IS_COMMITTEE_MEMBER]: inCommittee,
|
|
92
|
+
});
|
|
73
93
|
}
|
|
74
94
|
|
|
75
|
-
public
|
|
76
|
-
this.
|
|
95
|
+
public incFailedAttestationsNodeIssue(num: number, reason: string, inCommittee: boolean) {
|
|
96
|
+
this.failedAttestationsNodeIssueCount.add(num, {
|
|
77
97
|
[Attributes.ERROR_TYPE]: reason,
|
|
78
|
-
[Attributes.
|
|
98
|
+
[Attributes.IS_COMMITTEE_MEMBER]: inCommittee,
|
|
79
99
|
});
|
|
80
100
|
}
|
|
81
101
|
}
|