@aztec/validator-client 0.0.0-test.0 → 0.0.1-fake-c83136db25
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 +52 -0
- package/dest/block_proposal_handler.d.ts.map +1 -0
- package/dest/block_proposal_handler.js +286 -0
- package/dest/config.d.ts +2 -13
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +31 -7
- package/dest/duties/validation_service.d.ts +16 -8
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +35 -11
- package/dest/factory.d.ts +21 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +13 -6
- package/dest/index.d.ts +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -1
- package/dest/key_store/index.d.ts +2 -0
- package/dest/key_store/index.d.ts.map +1 -1
- package/dest/key_store/index.js +2 -0
- package/dest/key_store/interface.d.ts +54 -5
- package/dest/key_store/interface.d.ts.map +1 -1
- package/dest/key_store/interface.js +3 -3
- package/dest/key_store/local_key_store.d.ts +40 -10
- package/dest/key_store/local_key_store.d.ts.map +1 -1
- package/dest/key_store/local_key_store.js +63 -16
- package/dest/key_store/node_keystore_adapter.d.ts +138 -0
- package/dest/key_store/node_keystore_adapter.d.ts.map +1 -0
- package/dest/key_store/node_keystore_adapter.js +316 -0
- package/dest/key_store/web3signer_key_store.d.ts +67 -0
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -0
- package/dest/key_store/web3signer_key_store.js +153 -0
- package/dest/metrics.d.ts +11 -4
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +50 -15
- package/dest/validator.d.ts +48 -61
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +265 -165
- package/package.json +25 -19
- package/src/block_proposal_handler.ts +343 -0
- package/src/config.ts +42 -22
- package/src/duties/validation_service.ts +69 -14
- package/src/factory.ts +56 -11
- package/src/index.ts +3 -1
- package/src/key_store/index.ts +2 -0
- package/src/key_store/interface.ts +61 -5
- package/src/key_store/local_key_store.ts +67 -17
- package/src/key_store/node_keystore_adapter.ts +375 -0
- package/src/key_store/web3signer_key_store.ts +195 -0
- package/src/metrics.ts +66 -17
- package/src/validator.ts +384 -233
- package/dest/errors/index.d.ts +0 -2
- package/dest/errors/index.d.ts.map +0 -1
- package/dest/errors/index.js +0 -1
- package/dest/errors/validator.error.d.ts +0 -29
- package/dest/errors/validator.error.d.ts.map +0 -1
- package/dest/errors/validator.error.js +0 -45
- package/src/errors/index.ts +0 -1
- package/src/errors/validator.error.ts +0 -55
package/dest/validator.js
CHANGED
|
@@ -1,69 +1,146 @@
|
|
|
1
|
-
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
2
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
4
3
|
import { sleep } from '@aztec/foundation/sleep';
|
|
5
4
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
6
|
-
import { BlockProposalValidator } from '@aztec/p2p
|
|
7
|
-
import {
|
|
5
|
+
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
6
|
+
import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
7
|
+
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
8
|
+
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
9
|
+
import { EventEmitter } from 'events';
|
|
10
|
+
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
8
11
|
import { ValidationService } from './duties/validation_service.js';
|
|
9
|
-
import {
|
|
10
|
-
import { LocalKeyStore } from './key_store/local_key_store.js';
|
|
12
|
+
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
11
13
|
import { ValidatorMetrics } from './metrics.js';
|
|
14
|
+
// We maintain a set of proposers who have proposed invalid blocks.
|
|
15
|
+
// Just cap the set to avoid unbounded growth.
|
|
16
|
+
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
17
|
+
// What errors from the block proposal handler result in slashing
|
|
18
|
+
const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
19
|
+
'state_mismatch',
|
|
20
|
+
'failed_txs'
|
|
21
|
+
];
|
|
12
22
|
/**
|
|
13
23
|
* Validator Client
|
|
14
|
-
*/ export class ValidatorClient extends
|
|
24
|
+
*/ export class ValidatorClient extends EventEmitter {
|
|
15
25
|
keyStore;
|
|
16
26
|
epochCache;
|
|
17
27
|
p2pClient;
|
|
28
|
+
blockProposalHandler;
|
|
18
29
|
config;
|
|
19
30
|
dateProvider;
|
|
20
31
|
log;
|
|
32
|
+
tracer;
|
|
21
33
|
validationService;
|
|
22
34
|
metrics;
|
|
35
|
+
// Whether it has already registered handlers on the p2p client
|
|
36
|
+
hasRegisteredHandlers;
|
|
23
37
|
// Used to check if we are sending the same proposal twice
|
|
24
38
|
previousProposal;
|
|
25
|
-
|
|
26
|
-
blockBuilder;
|
|
39
|
+
lastEpochForCommitteeUpdateLoop;
|
|
27
40
|
epochCacheUpdateLoop;
|
|
28
|
-
|
|
29
|
-
constructor(keyStore, epochCache, p2pClient, config, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
30
|
-
|
|
31
|
-
|
|
41
|
+
proposersOfInvalidBlocks;
|
|
42
|
+
constructor(keyStore, epochCache, p2pClient, blockProposalHandler, config, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
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
|
+
this.tracer = telemetry.getTracer('Validator');
|
|
32
45
|
this.metrics = new ValidatorMetrics(telemetry);
|
|
33
|
-
this.validationService = new ValidationService(keyStore);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
this.validationService = new ValidationService(keyStore, log.createChild('validation-service'));
|
|
47
|
+
// Refresh epoch cache every second to trigger alert if participation in committee changes
|
|
48
|
+
this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), log, 1000);
|
|
49
|
+
const myAddresses = this.getValidatorAddresses();
|
|
50
|
+
this.log.verbose(`Initialized validator with addresses: ${myAddresses.map((a)=>a.toString()).join(', ')}`);
|
|
51
|
+
}
|
|
52
|
+
static validateKeyStoreConfiguration(keyStoreManager, logger) {
|
|
53
|
+
const validatorKeyStore = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
54
|
+
const validatorAddresses = validatorKeyStore.getAddresses();
|
|
55
|
+
// Verify that we can retrieve all required data from the key store
|
|
56
|
+
for (const address of validatorAddresses){
|
|
57
|
+
// Functions throw if required data is not available
|
|
58
|
+
let coinbase;
|
|
59
|
+
let feeRecipient;
|
|
60
|
+
try {
|
|
61
|
+
coinbase = validatorKeyStore.getCoinbaseAddress(address);
|
|
62
|
+
feeRecipient = validatorKeyStore.getFeeRecipient(address);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
throw new Error(`Failed to retrieve required data for validator address ${address}, error: ${error}`);
|
|
44
65
|
}
|
|
45
|
-
|
|
46
|
-
|
|
66
|
+
const publisherAddresses = validatorKeyStore.getPublisherAddresses(address);
|
|
67
|
+
if (!publisherAddresses.length) {
|
|
68
|
+
throw new Error(`No publisher addresses found for validator address ${address}`);
|
|
69
|
+
}
|
|
70
|
+
logger?.debug(`Validator ${address.toString()} configured with coinbase ${coinbase.toString()}, feeRecipient ${feeRecipient.toString()} and publishers ${publisherAddresses.map((x)=>x.toString()).join()}`);
|
|
71
|
+
}
|
|
47
72
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
73
|
+
async handleEpochCommitteeUpdate() {
|
|
74
|
+
try {
|
|
75
|
+
const { committee, epoch } = await this.epochCache.getCommittee('next');
|
|
76
|
+
if (!committee) {
|
|
77
|
+
this.log.trace(`No committee found for slot`);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
|
|
81
|
+
const me = this.getValidatorAddresses();
|
|
82
|
+
const committeeSet = new Set(committee.map((v)=>v.toString()));
|
|
83
|
+
const inCommittee = me.filter((a)=>committeeSet.has(a.toString()));
|
|
84
|
+
if (inCommittee.length > 0) {
|
|
85
|
+
this.log.info(`Validators ${inCommittee.map((a)=>a.toString()).join(',')} are on the validator committee for epoch ${epoch}`);
|
|
86
|
+
} else {
|
|
87
|
+
this.log.verbose(`Validators ${me.map((a)=>a.toString()).join(', ')} are not on the validator committee for epoch ${epoch}`);
|
|
88
|
+
}
|
|
89
|
+
this.lastEpochForCommitteeUpdateLoop = epoch;
|
|
90
|
+
}
|
|
91
|
+
} catch (err) {
|
|
92
|
+
this.log.error(`Error updating epoch committee`, err);
|
|
51
93
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
94
|
+
}
|
|
95
|
+
static new(config, blockBuilder, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
96
|
+
const metrics = new ValidatorMetrics(telemetry);
|
|
97
|
+
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
98
|
+
txsPermitted: !config.disableTransactions
|
|
99
|
+
});
|
|
100
|
+
const blockProposalHandler = new BlockProposalHandler(blockBuilder, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, config, metrics, dateProvider, telemetry);
|
|
101
|
+
const validator = new ValidatorClient(NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager), epochCache, p2pClient, blockProposalHandler, config, dateProvider, telemetry);
|
|
56
102
|
return validator;
|
|
57
103
|
}
|
|
104
|
+
getValidatorAddresses() {
|
|
105
|
+
return this.keyStore.getAddresses().filter((addr)=>!this.config.disabledValidators.some((disabled)=>disabled.equals(addr)));
|
|
106
|
+
}
|
|
107
|
+
getBlockProposalHandler() {
|
|
108
|
+
return this.blockProposalHandler;
|
|
109
|
+
}
|
|
110
|
+
// Proxy method for backwards compatibility with tests
|
|
111
|
+
reExecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages) {
|
|
112
|
+
return this.blockProposalHandler.reexecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages);
|
|
113
|
+
}
|
|
114
|
+
signWithAddress(addr, msg) {
|
|
115
|
+
return this.keyStore.signTypedDataWithAddress(addr, msg);
|
|
116
|
+
}
|
|
117
|
+
getCoinbaseForAttestor(attestor) {
|
|
118
|
+
return this.keyStore.getCoinbaseAddress(attestor);
|
|
119
|
+
}
|
|
120
|
+
getFeeRecipientForAttestor(attestor) {
|
|
121
|
+
return this.keyStore.getFeeRecipient(attestor);
|
|
122
|
+
}
|
|
123
|
+
getConfig() {
|
|
124
|
+
return this.config;
|
|
125
|
+
}
|
|
126
|
+
updateConfig(config) {
|
|
127
|
+
this.config = {
|
|
128
|
+
...this.config,
|
|
129
|
+
...config
|
|
130
|
+
};
|
|
131
|
+
}
|
|
58
132
|
async start() {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
133
|
+
if (this.epochCacheUpdateLoop.isRunning()) {
|
|
134
|
+
this.log.warn(`Validator client already started`);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
await this.registerHandlers();
|
|
138
|
+
const myAddresses = this.getValidatorAddresses();
|
|
139
|
+
const inCommittee = await this.epochCache.filterInCommittee('now', myAddresses);
|
|
140
|
+
if (inCommittee.length > 0) {
|
|
141
|
+
this.log.info(`Started validator with addresses in current validator committee: ${inCommittee.map((a)=>a.toString()).join(', ')}`);
|
|
65
142
|
} else {
|
|
66
|
-
this.log.info(`Started validator with
|
|
143
|
+
this.log.info(`Started validator with addresses: ${myAddresses.map((a)=>a.toString()).join(', ')}`);
|
|
67
144
|
}
|
|
68
145
|
this.epochCacheUpdateLoop.start();
|
|
69
146
|
return Promise.resolve();
|
|
@@ -71,155 +148,162 @@ import { ValidatorMetrics } from './metrics.js';
|
|
|
71
148
|
async stop() {
|
|
72
149
|
await this.epochCacheUpdateLoop.stop();
|
|
73
150
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
* We reuse the sequencer's block building functionality for re-execution
|
|
84
|
-
*/ registerBlockBuilder(blockBuilder) {
|
|
85
|
-
this.blockBuilder = blockBuilder;
|
|
86
|
-
}
|
|
87
|
-
async attestToProposal(proposal) {
|
|
88
|
-
const slotNumber = proposal.slotNumber.toNumber();
|
|
89
|
-
const proposalInfo = {
|
|
90
|
-
slotNumber,
|
|
91
|
-
blockNumber: proposal.payload.header.globalVariables.blockNumber.toNumber(),
|
|
92
|
-
archive: proposal.payload.archive.toString(),
|
|
93
|
-
txCount: proposal.payload.txHashes.length,
|
|
94
|
-
txHashes: proposal.payload.txHashes.map((txHash)=>txHash.toString())
|
|
95
|
-
};
|
|
96
|
-
this.log.verbose(`Received request to attest for slot ${slotNumber}`);
|
|
97
|
-
// Check that I am in the committee
|
|
98
|
-
if (!await this.epochCache.isInCommittee(this.keyStore.getAddress())) {
|
|
99
|
-
this.log.verbose(`Not in the committee, skipping attestation`);
|
|
100
|
-
return undefined;
|
|
151
|
+
/** Register handlers on the p2p client */ async registerHandlers() {
|
|
152
|
+
if (!this.hasRegisteredHandlers) {
|
|
153
|
+
this.hasRegisteredHandlers = true;
|
|
154
|
+
this.log.debug(`Registering validator handlers for p2p client`);
|
|
155
|
+
const handler = (block, proposalSender)=>this.attestToProposal(block, proposalSender);
|
|
156
|
+
this.p2pClient.registerBlockProposalHandler(handler);
|
|
157
|
+
const myAddresses = this.getValidatorAddresses();
|
|
158
|
+
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
159
|
+
await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
|
|
101
160
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
161
|
+
}
|
|
162
|
+
async attestToProposal(proposal, proposalSender) {
|
|
163
|
+
const slotNumber = proposal.slotNumber.toBigInt();
|
|
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}`);
|
|
106
168
|
return undefined;
|
|
107
169
|
}
|
|
108
|
-
// Check that
|
|
109
|
-
this.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
170
|
+
// Check that I have any address in current committee before attesting
|
|
171
|
+
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
172
|
+
const partOfCommittee = inCommittee.length > 0;
|
|
173
|
+
const proposalInfo = {
|
|
174
|
+
...proposal.toBlockInfo(),
|
|
175
|
+
proposer: proposer.toString()
|
|
176
|
+
};
|
|
177
|
+
this.log.info(`Received proposal for slot ${slotNumber}`, {
|
|
178
|
+
...proposalInfo,
|
|
179
|
+
txHashes: proposal.txHashes.map((t)=>t.toString())
|
|
180
|
+
});
|
|
181
|
+
// Reexecute txs if we are part of the committee so we can attest, or if slashing is enabled so we can slash
|
|
182
|
+
// invalid proposals even when not in the committee, or if we are configured to always reexecute for monitoring purposes.
|
|
183
|
+
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals } = this.config;
|
|
184
|
+
const shouldReexecute = slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals;
|
|
185
|
+
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute);
|
|
186
|
+
if (!validationResult.isValid) {
|
|
187
|
+
this.log.warn(`Proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
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
|
+
}
|
|
115
205
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
this.
|
|
120
|
-
} else {
|
|
121
|
-
// This branch most commonly be hit if the transactions are available, but the re-execution fails
|
|
122
|
-
// Catch all error handler
|
|
123
|
-
this.log.error(`Failed to attest to proposal`, error, proposalInfo);
|
|
206
|
+
// Slash invalid block proposals (can happen even when not in committee)
|
|
207
|
+
if (validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
|
|
208
|
+
this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
|
|
209
|
+
this.slashInvalidBlock(proposal);
|
|
124
210
|
}
|
|
125
211
|
return undefined;
|
|
126
212
|
}
|
|
213
|
+
// Check that I have any address in current committee before attesting
|
|
214
|
+
if (!partOfCommittee) {
|
|
215
|
+
this.log.verbose(`No validator in the current committee, skipping attestation`, proposalInfo);
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
127
218
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
128
219
|
this.log.info(`Attesting to proposal for slot ${slotNumber}`, proposalInfo);
|
|
220
|
+
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
129
221
|
// If the above function does not throw an error, then we can attest to the proposal
|
|
130
|
-
return this.
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Re-execute the transactions in the proposal and check that the state updates match the header state
|
|
134
|
-
* @param proposal - The proposal to re-execute
|
|
135
|
-
*/ async reExecuteTransactions(proposal) {
|
|
136
|
-
const { header, txHashes } = proposal.payload;
|
|
137
|
-
const txs = (await Promise.all(txHashes.map((tx)=>this.p2pClient.getTxByHash(tx)))).filter((tx)=>tx !== undefined);
|
|
138
|
-
// If we cannot request all of the transactions, then we should fail
|
|
139
|
-
if (txs.length !== txHashes.length) {
|
|
140
|
-
throw new TransactionsNotAvailableError(txHashes);
|
|
141
|
-
}
|
|
142
|
-
// Assertion: This check will fail if re-execution is not enabled
|
|
143
|
-
if (this.blockBuilder === undefined) {
|
|
144
|
-
throw new BlockBuilderNotProvidedError();
|
|
145
|
-
}
|
|
146
|
-
// Use the sequencer's block building logic to re-execute the transactions
|
|
147
|
-
const stopTimer = this.metrics.reExecutionTimer();
|
|
148
|
-
const { block, numFailedTxs } = await this.blockBuilder(txs, header.globalVariables, {
|
|
149
|
-
validateOnly: true
|
|
150
|
-
});
|
|
151
|
-
stopTimer();
|
|
152
|
-
this.log.verbose(`Transaction re-execution complete`);
|
|
153
|
-
if (numFailedTxs > 0) {
|
|
154
|
-
await this.metrics.recordFailedReexecution(proposal);
|
|
155
|
-
throw new ReExFailedTxsError(numFailedTxs);
|
|
156
|
-
}
|
|
157
|
-
if (block.body.txEffects.length !== txHashes.length) {
|
|
158
|
-
await this.metrics.recordFailedReexecution(proposal);
|
|
159
|
-
throw new ReExTimeoutError();
|
|
160
|
-
}
|
|
161
|
-
// This function will throw an error if state updates do not match
|
|
162
|
-
if (!block.archive.root.equals(proposal.archive)) {
|
|
163
|
-
await this.metrics.recordFailedReexecution(proposal);
|
|
164
|
-
throw new ReExStateMismatchError();
|
|
165
|
-
}
|
|
222
|
+
return this.createBlockAttestationsFromProposal(proposal, inCommittee);
|
|
166
223
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
* @param proposal - The proposal to attest to
|
|
174
|
-
*/ async ensureTransactionsAreAvailable(proposal) {
|
|
175
|
-
const txHashes = proposal.payload.txHashes;
|
|
176
|
-
const transactionStatuses = await Promise.all(txHashes.map((txHash)=>this.p2pClient.getTxStatus(txHash)));
|
|
177
|
-
const missingTxs = txHashes.filter((_, index)=>![
|
|
178
|
-
'pending',
|
|
179
|
-
'mined'
|
|
180
|
-
].includes(transactionStatuses[index] ?? ''));
|
|
181
|
-
if (missingTxs.length === 0) {
|
|
182
|
-
return; // All transactions are available
|
|
224
|
+
slashInvalidBlock(proposal) {
|
|
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;
|
|
183
230
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
231
|
+
// Trim the set if it's too big.
|
|
232
|
+
if (this.proposersOfInvalidBlocks.size > MAX_PROPOSERS_OF_INVALID_BLOCKS) {
|
|
233
|
+
// remove oldest proposer. `values` is guaranteed to be in insertion order.
|
|
234
|
+
this.proposersOfInvalidBlocks.delete(this.proposersOfInvalidBlocks.values().next().value);
|
|
188
235
|
}
|
|
236
|
+
this.proposersOfInvalidBlocks.add(proposer.toString());
|
|
237
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
238
|
+
{
|
|
239
|
+
validator: proposer,
|
|
240
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
241
|
+
offenseType: OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL,
|
|
242
|
+
epochOrSlot: proposal.slotNumber.toBigInt()
|
|
243
|
+
}
|
|
244
|
+
]);
|
|
189
245
|
}
|
|
190
|
-
async createBlockProposal(header, archive, txs) {
|
|
191
|
-
if (this.previousProposal?.slotNumber.equals(header.
|
|
246
|
+
async createBlockProposal(blockNumber, header, archive, stateReference, txs, proposerAddress, options) {
|
|
247
|
+
if (this.previousProposal?.slotNumber.equals(header.slotNumber)) {
|
|
192
248
|
this.log.verbose(`Already made a proposal for the same slot, skipping proposal`);
|
|
193
249
|
return Promise.resolve(undefined);
|
|
194
250
|
}
|
|
195
|
-
const newProposal = await this.validationService.createBlockProposal(header, archive, txs
|
|
251
|
+
const newProposal = await this.validationService.createBlockProposal(header, archive, stateReference, txs, proposerAddress, {
|
|
252
|
+
...options,
|
|
253
|
+
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
254
|
+
});
|
|
196
255
|
this.previousProposal = newProposal;
|
|
197
256
|
return newProposal;
|
|
198
257
|
}
|
|
199
|
-
broadcastBlockProposal(proposal) {
|
|
200
|
-
this.p2pClient.broadcastProposal(proposal);
|
|
258
|
+
async broadcastBlockProposal(proposal) {
|
|
259
|
+
await this.p2pClient.broadcastProposal(proposal);
|
|
260
|
+
}
|
|
261
|
+
async signAttestationsAndSigners(attestationsAndSigners, proposer) {
|
|
262
|
+
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
|
|
263
|
+
}
|
|
264
|
+
async collectOwnAttestations(proposal) {
|
|
265
|
+
const slot = proposal.payload.header.slotNumber.toBigInt();
|
|
266
|
+
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
267
|
+
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
|
|
268
|
+
inCommittee
|
|
269
|
+
});
|
|
270
|
+
return this.createBlockAttestationsFromProposal(proposal, inCommittee);
|
|
201
271
|
}
|
|
202
|
-
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/7962)
|
|
203
272
|
async collectAttestations(proposal, required, deadline) {
|
|
204
273
|
// Wait and poll the p2pClient's attestation pool for this block until we have enough attestations
|
|
205
|
-
const slot = proposal.payload.header.
|
|
274
|
+
const slot = proposal.payload.header.slotNumber.toBigInt();
|
|
206
275
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
207
276
|
if (+deadline < this.dateProvider.now()) {
|
|
208
277
|
this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
|
|
209
|
-
throw new AttestationTimeoutError(required, slot);
|
|
278
|
+
throw new AttestationTimeoutError(0, required, slot);
|
|
210
279
|
}
|
|
280
|
+
await this.collectOwnAttestations(proposal);
|
|
211
281
|
const proposalId = proposal.archive.toString();
|
|
212
|
-
const
|
|
282
|
+
const myAddresses = this.getValidatorAddresses();
|
|
213
283
|
let attestations = [];
|
|
214
284
|
while(true){
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
|
298
|
+
const oldSenders = attestations.map((attestation)=>attestation.getSender());
|
|
220
299
|
for (const collected of collectedAttestations){
|
|
221
|
-
const collectedSender =
|
|
222
|
-
|
|
300
|
+
const collectedSender = collected.getSender();
|
|
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))) {
|
|
223
307
|
this.log.debug(`Received attestation for slot ${slot} from ${collectedSender.toString()}`);
|
|
224
308
|
}
|
|
225
309
|
}
|
|
@@ -230,17 +314,33 @@ import { ValidatorMetrics } from './metrics.js';
|
|
|
230
314
|
}
|
|
231
315
|
if (+deadline < this.dateProvider.now()) {
|
|
232
316
|
this.log.error(`Timeout ${deadline.toISOString()} waiting for ${required} attestations for slot ${slot}`);
|
|
233
|
-
throw new AttestationTimeoutError(required, slot);
|
|
317
|
+
throw new AttestationTimeoutError(attestations.length, required, slot);
|
|
234
318
|
}
|
|
235
|
-
this.log.debug(`Collected ${attestations.length} attestations so far`);
|
|
319
|
+
this.log.debug(`Collected ${attestations.length} of ${required} attestations so far`);
|
|
236
320
|
await sleep(this.config.attestationPollingIntervalMs);
|
|
237
321
|
}
|
|
238
322
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
return
|
|
243
|
-
}
|
|
244
|
-
|
|
323
|
+
async createBlockAttestationsFromProposal(proposal, attestors = []) {
|
|
324
|
+
const attestations = await this.validationService.attestToProposal(proposal, attestors);
|
|
325
|
+
await this.p2pClient.addAttestations(attestations);
|
|
326
|
+
return attestations;
|
|
327
|
+
}
|
|
328
|
+
async handleAuthRequest(peer, msg) {
|
|
329
|
+
const authRequest = AuthRequest.fromBuffer(msg);
|
|
330
|
+
const statusMessage = await this.p2pClient.handleAuthRequestFromPeer(authRequest, peer).catch((_)=>undefined);
|
|
331
|
+
if (statusMessage === undefined) {
|
|
332
|
+
return Buffer.alloc(0);
|
|
333
|
+
}
|
|
334
|
+
// Find a validator address that is in the set
|
|
335
|
+
const allRegisteredValidators = await this.epochCache.getRegisteredValidators();
|
|
336
|
+
const addressToUse = this.getValidatorAddresses().find((address)=>allRegisteredValidators.find((v)=>v.equals(address)) !== undefined);
|
|
337
|
+
if (addressToUse === undefined) {
|
|
338
|
+
// We don't have a registered address
|
|
339
|
+
return Buffer.alloc(0);
|
|
340
|
+
}
|
|
341
|
+
const payloadToSign = authRequest.getPayloadToSign();
|
|
342
|
+
const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign);
|
|
343
|
+
const authResponse = new AuthResponse(statusMessage, signature);
|
|
344
|
+
return authResponse.toBuffer();
|
|
245
345
|
}
|
|
246
346
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/validator-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1-fake-c83136db25",
|
|
4
4
|
"main": "dest/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -21,8 +21,6 @@
|
|
|
21
21
|
"build": "yarn clean && tsc -b",
|
|
22
22
|
"build:dev": "tsc -b --watch",
|
|
23
23
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
24
|
-
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
|
|
25
|
-
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
|
|
26
24
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
27
25
|
},
|
|
28
26
|
"inherits": [
|
|
@@ -59,28 +57,36 @@
|
|
|
59
57
|
"testTimeout": 120000,
|
|
60
58
|
"setupFiles": [
|
|
61
59
|
"../../foundation/src/jest/setup.mjs"
|
|
60
|
+
],
|
|
61
|
+
"testEnvironment": "../../foundation/src/jest/env.mjs",
|
|
62
|
+
"setupFilesAfterEnv": [
|
|
63
|
+
"../../foundation/src/jest/setupAfterEnv.mjs"
|
|
62
64
|
]
|
|
63
65
|
},
|
|
64
66
|
"dependencies": {
|
|
65
|
-
"@aztec/
|
|
66
|
-
"@aztec/
|
|
67
|
-
"@aztec/
|
|
68
|
-
"@aztec/
|
|
69
|
-
"@aztec/
|
|
70
|
-
"@aztec/
|
|
71
|
-
"
|
|
72
|
-
"
|
|
67
|
+
"@aztec/constants": "0.0.1-fake-c83136db25",
|
|
68
|
+
"@aztec/epoch-cache": "0.0.1-fake-c83136db25",
|
|
69
|
+
"@aztec/ethereum": "0.0.1-fake-c83136db25",
|
|
70
|
+
"@aztec/foundation": "0.0.1-fake-c83136db25",
|
|
71
|
+
"@aztec/node-keystore": "0.0.1-fake-c83136db25",
|
|
72
|
+
"@aztec/p2p": "0.0.1-fake-c83136db25",
|
|
73
|
+
"@aztec/prover-client": "0.0.1-fake-c83136db25",
|
|
74
|
+
"@aztec/slasher": "0.0.1-fake-c83136db25",
|
|
75
|
+
"@aztec/stdlib": "0.0.1-fake-c83136db25",
|
|
76
|
+
"@aztec/telemetry-client": "0.0.1-fake-c83136db25",
|
|
77
|
+
"koa": "^2.16.1",
|
|
78
|
+
"koa-router": "^13.1.1",
|
|
73
79
|
"tslib": "^2.4.0",
|
|
74
|
-
"viem": "2.
|
|
80
|
+
"viem": "npm:@spalladino/viem@2.38.2-eip7594.0"
|
|
75
81
|
},
|
|
76
82
|
"devDependencies": {
|
|
77
|
-
"@jest/globals": "^
|
|
78
|
-
"@types/jest": "^
|
|
79
|
-
"@types/node": "^
|
|
80
|
-
"jest": "^
|
|
81
|
-
"jest-mock-extended": "^
|
|
83
|
+
"@jest/globals": "^30.0.0",
|
|
84
|
+
"@types/jest": "^30.0.0",
|
|
85
|
+
"@types/node": "^22.15.17",
|
|
86
|
+
"jest": "^30.0.0",
|
|
87
|
+
"jest-mock-extended": "^4.0.0",
|
|
82
88
|
"ts-node": "^10.9.1",
|
|
83
|
-
"typescript": "^5.
|
|
89
|
+
"typescript": "^5.3.3"
|
|
84
90
|
},
|
|
85
91
|
"files": [
|
|
86
92
|
"dest",
|
|
@@ -89,6 +95,6 @@
|
|
|
89
95
|
],
|
|
90
96
|
"types": "./dest/index.d.ts",
|
|
91
97
|
"engines": {
|
|
92
|
-
"node": ">=
|
|
98
|
+
"node": ">=20.10"
|
|
93
99
|
}
|
|
94
100
|
}
|