@aztec/validator-client 0.0.0-test.1 → 0.0.1-fake-ceab37513c
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 +11 -6
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +27 -10
- 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 +9 -4
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +41 -15
- package/dest/validator.d.ts +46 -61
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +242 -164
- 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 +57 -12
- 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 +49 -17
- package/src/validator.ts +359 -232
- 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,143 @@
|
|
|
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
46
|
this.validationService = new ValidationService(keyStore);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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) {
|
|
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
|
+
try {
|
|
59
|
+
validatorKeyStore.getCoinbaseAddress(address);
|
|
60
|
+
validatorKeyStore.getFeeRecipient(address);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
throw new Error(`Failed to retrieve required data for validator address ${address}, error: ${error}`);
|
|
44
63
|
}
|
|
45
|
-
|
|
46
|
-
|
|
64
|
+
const publisherAddresses = validatorKeyStore.getPublisherAddresses(address);
|
|
65
|
+
if (!publisherAddresses.length) {
|
|
66
|
+
throw new Error(`No publisher addresses found for validator address ${address}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
47
69
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
70
|
+
async handleEpochCommitteeUpdate() {
|
|
71
|
+
try {
|
|
72
|
+
const { committee, epoch } = await this.epochCache.getCommittee('next');
|
|
73
|
+
if (!committee) {
|
|
74
|
+
this.log.trace(`No committee found for slot`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
|
|
78
|
+
const me = this.getValidatorAddresses();
|
|
79
|
+
const committeeSet = new Set(committee.map((v)=>v.toString()));
|
|
80
|
+
const inCommittee = me.filter((a)=>committeeSet.has(a.toString()));
|
|
81
|
+
if (inCommittee.length > 0) {
|
|
82
|
+
this.log.info(`Validators ${inCommittee.map((a)=>a.toString()).join(',')} are on the validator committee for epoch ${epoch}`);
|
|
83
|
+
} else {
|
|
84
|
+
this.log.verbose(`Validators ${me.map((a)=>a.toString()).join(', ')} are not on the validator committee for epoch ${epoch}`);
|
|
85
|
+
}
|
|
86
|
+
this.lastEpochForCommitteeUpdateLoop = epoch;
|
|
87
|
+
}
|
|
88
|
+
} catch (err) {
|
|
89
|
+
this.log.error(`Error updating epoch committee`, err);
|
|
51
90
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
91
|
+
}
|
|
92
|
+
static new(config, blockBuilder, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
93
|
+
const metrics = new ValidatorMetrics(telemetry);
|
|
94
|
+
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
95
|
+
txsPermitted: !config.disableTransactions
|
|
96
|
+
});
|
|
97
|
+
const blockProposalHandler = new BlockProposalHandler(blockBuilder, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, config, metrics, dateProvider, telemetry);
|
|
98
|
+
const validator = new ValidatorClient(NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager), epochCache, p2pClient, blockProposalHandler, config, dateProvider, telemetry);
|
|
56
99
|
return validator;
|
|
57
100
|
}
|
|
101
|
+
getValidatorAddresses() {
|
|
102
|
+
return this.keyStore.getAddresses().filter((addr)=>!this.config.disabledValidators.some((disabled)=>disabled.equals(addr)));
|
|
103
|
+
}
|
|
104
|
+
getBlockProposalHandler() {
|
|
105
|
+
return this.blockProposalHandler;
|
|
106
|
+
}
|
|
107
|
+
// Proxy method for backwards compatibility with tests
|
|
108
|
+
reExecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages) {
|
|
109
|
+
return this.blockProposalHandler.reexecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages);
|
|
110
|
+
}
|
|
111
|
+
signWithAddress(addr, msg) {
|
|
112
|
+
return this.keyStore.signTypedDataWithAddress(addr, msg);
|
|
113
|
+
}
|
|
114
|
+
getCoinbaseForAttestor(attestor) {
|
|
115
|
+
return this.keyStore.getCoinbaseAddress(attestor);
|
|
116
|
+
}
|
|
117
|
+
getFeeRecipientForAttestor(attestor) {
|
|
118
|
+
return this.keyStore.getFeeRecipient(attestor);
|
|
119
|
+
}
|
|
120
|
+
getConfig() {
|
|
121
|
+
return this.config;
|
|
122
|
+
}
|
|
123
|
+
updateConfig(config) {
|
|
124
|
+
this.config = {
|
|
125
|
+
...this.config,
|
|
126
|
+
...config
|
|
127
|
+
};
|
|
128
|
+
}
|
|
58
129
|
async start() {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
130
|
+
if (this.epochCacheUpdateLoop.isRunning()) {
|
|
131
|
+
this.log.warn(`Validator client already started`);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
await this.registerHandlers();
|
|
135
|
+
const myAddresses = this.getValidatorAddresses();
|
|
136
|
+
const inCommittee = await this.epochCache.filterInCommittee('now', myAddresses);
|
|
137
|
+
if (inCommittee.length > 0) {
|
|
138
|
+
this.log.info(`Started validator with addresses in current validator committee: ${inCommittee.map((a)=>a.toString()).join(', ')}`);
|
|
65
139
|
} else {
|
|
66
|
-
this.log.info(`Started validator with
|
|
140
|
+
this.log.info(`Started validator with addresses: ${myAddresses.map((a)=>a.toString()).join(', ')}`);
|
|
67
141
|
}
|
|
68
142
|
this.epochCacheUpdateLoop.start();
|
|
69
143
|
return Promise.resolve();
|
|
@@ -71,155 +145,143 @@ import { ValidatorMetrics } from './metrics.js';
|
|
|
71
145
|
async stop() {
|
|
72
146
|
await this.epochCacheUpdateLoop.stop();
|
|
73
147
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
*/ registerBlockBuilder(blockBuilder) {
|
|
85
|
-
this.blockBuilder = blockBuilder;
|
|
148
|
+
/** Register handlers on the p2p client */ async registerHandlers() {
|
|
149
|
+
if (!this.hasRegisteredHandlers) {
|
|
150
|
+
this.hasRegisteredHandlers = true;
|
|
151
|
+
this.log.debug(`Registering validator handlers for p2p client`);
|
|
152
|
+
const handler = (block, proposalSender)=>this.attestToProposal(block, proposalSender);
|
|
153
|
+
this.p2pClient.registerBlockProposalHandler(handler);
|
|
154
|
+
const myAddresses = this.getValidatorAddresses();
|
|
155
|
+
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
156
|
+
await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
|
|
157
|
+
}
|
|
86
158
|
}
|
|
87
|
-
async attestToProposal(proposal) {
|
|
88
|
-
const slotNumber = proposal.slotNumber.
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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`);
|
|
159
|
+
async attestToProposal(proposal, proposalSender) {
|
|
160
|
+
const slotNumber = proposal.slotNumber.toBigInt();
|
|
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}`);
|
|
100
165
|
return undefined;
|
|
101
166
|
}
|
|
102
|
-
// Check that
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
167
|
+
// Check that I have any address in current committee before attesting
|
|
168
|
+
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
169
|
+
const partOfCommittee = inCommittee.length > 0;
|
|
170
|
+
const incFailedAttestation = (reason)=>this.metrics.incFailedAttestations(1, reason, partOfCommittee);
|
|
171
|
+
const proposalInfo = {
|
|
172
|
+
...proposal.toBlockInfo(),
|
|
173
|
+
proposer: proposer.toString()
|
|
174
|
+
};
|
|
175
|
+
this.log.info(`Received proposal for slot ${slotNumber}`, {
|
|
176
|
+
...proposalInfo,
|
|
177
|
+
txHashes: proposal.txHashes.map((t)=>t.toString())
|
|
178
|
+
});
|
|
179
|
+
// Reexecute txs if we are part of the committee so we can attest, or if slashing is enabled so we can slash
|
|
180
|
+
// invalid proposals even when not in the committee, or if we are configured to always reexecute for monitoring purposes.
|
|
181
|
+
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals } = this.config;
|
|
182
|
+
const shouldReexecute = slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals;
|
|
183
|
+
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute);
|
|
184
|
+
if (!validationResult.isValid) {
|
|
185
|
+
this.log.warn(`Proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
186
|
+
incFailedAttestation(validationResult.reason || 'unknown');
|
|
187
|
+
// Slash invalid block proposals
|
|
188
|
+
if (validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
|
|
189
|
+
this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
|
|
190
|
+
this.slashInvalidBlock(proposal);
|
|
191
|
+
}
|
|
106
192
|
return undefined;
|
|
107
193
|
}
|
|
108
|
-
// Check that
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
await this.ensureTransactionsAreAvailable(proposal);
|
|
112
|
-
if (this.config.validatorReexecute) {
|
|
113
|
-
this.log.verbose(`Re-executing transactions in the proposal before attesting`);
|
|
114
|
-
await this.reExecuteTransactions(proposal);
|
|
115
|
-
}
|
|
116
|
-
} catch (error) {
|
|
117
|
-
// If the transactions are not available, then we should not attempt to attest
|
|
118
|
-
if (error instanceof TransactionsNotAvailableError) {
|
|
119
|
-
this.log.error(`Transactions not available, skipping attestation`, error, proposalInfo);
|
|
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);
|
|
124
|
-
}
|
|
194
|
+
// Check that I have any address in current committee before attesting
|
|
195
|
+
if (!partOfCommittee) {
|
|
196
|
+
this.log.verbose(`No validator in the current committee, skipping attestation`, proposalInfo);
|
|
125
197
|
return undefined;
|
|
126
198
|
}
|
|
127
199
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
128
|
-
this.log.info(`Attesting to proposal for slot ${slotNumber}`, proposalInfo);
|
|
200
|
+
this.log.info(`Attesting to proposal for block at slot ${slotNumber}`, proposalInfo);
|
|
201
|
+
this.metrics.incAttestations(inCommittee.length);
|
|
129
202
|
// 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
|
-
}
|
|
203
|
+
return this.createBlockAttestationsFromProposal(proposal, inCommittee);
|
|
166
204
|
}
|
|
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
|
|
205
|
+
slashInvalidBlock(proposal) {
|
|
206
|
+
const proposer = proposal.getSender();
|
|
207
|
+
// Skip if signature is invalid (shouldn't happen since we validate earlier)
|
|
208
|
+
if (!proposer) {
|
|
209
|
+
this.log.warn(`Cannot slash proposal with invalid signature`);
|
|
210
|
+
return;
|
|
183
211
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
212
|
+
// Trim the set if it's too big.
|
|
213
|
+
if (this.proposersOfInvalidBlocks.size > MAX_PROPOSERS_OF_INVALID_BLOCKS) {
|
|
214
|
+
// remove oldest proposer. `values` is guaranteed to be in insertion order.
|
|
215
|
+
this.proposersOfInvalidBlocks.delete(this.proposersOfInvalidBlocks.values().next().value);
|
|
188
216
|
}
|
|
217
|
+
this.proposersOfInvalidBlocks.add(proposer.toString());
|
|
218
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
219
|
+
{
|
|
220
|
+
validator: proposer,
|
|
221
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
222
|
+
offenseType: OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL,
|
|
223
|
+
epochOrSlot: proposal.slotNumber.toBigInt()
|
|
224
|
+
}
|
|
225
|
+
]);
|
|
189
226
|
}
|
|
190
|
-
async createBlockProposal(header, archive, txs) {
|
|
191
|
-
if (this.previousProposal?.slotNumber.equals(header.
|
|
227
|
+
async createBlockProposal(blockNumber, header, archive, stateReference, txs, proposerAddress, options) {
|
|
228
|
+
if (this.previousProposal?.slotNumber.equals(header.slotNumber)) {
|
|
192
229
|
this.log.verbose(`Already made a proposal for the same slot, skipping proposal`);
|
|
193
230
|
return Promise.resolve(undefined);
|
|
194
231
|
}
|
|
195
|
-
const newProposal = await this.validationService.createBlockProposal(header, archive, txs);
|
|
232
|
+
const newProposal = await this.validationService.createBlockProposal(header, archive, stateReference, txs, proposerAddress, options);
|
|
196
233
|
this.previousProposal = newProposal;
|
|
197
234
|
return newProposal;
|
|
198
235
|
}
|
|
199
|
-
broadcastBlockProposal(proposal) {
|
|
200
|
-
this.p2pClient.broadcastProposal(proposal);
|
|
236
|
+
async broadcastBlockProposal(proposal) {
|
|
237
|
+
await this.p2pClient.broadcastProposal(proposal);
|
|
238
|
+
}
|
|
239
|
+
async signAttestationsAndSigners(attestationsAndSigners, proposer) {
|
|
240
|
+
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
|
|
241
|
+
}
|
|
242
|
+
async collectOwnAttestations(proposal) {
|
|
243
|
+
const slot = proposal.payload.header.slotNumber.toBigInt();
|
|
244
|
+
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
245
|
+
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
|
|
246
|
+
inCommittee
|
|
247
|
+
});
|
|
248
|
+
return this.createBlockAttestationsFromProposal(proposal, inCommittee);
|
|
201
249
|
}
|
|
202
|
-
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/7962)
|
|
203
250
|
async collectAttestations(proposal, required, deadline) {
|
|
204
251
|
// Wait and poll the p2pClient's attestation pool for this block until we have enough attestations
|
|
205
|
-
const slot = proposal.payload.header.
|
|
252
|
+
const slot = proposal.payload.header.slotNumber.toBigInt();
|
|
206
253
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
207
254
|
if (+deadline < this.dateProvider.now()) {
|
|
208
255
|
this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
|
|
209
|
-
throw new AttestationTimeoutError(required, slot);
|
|
256
|
+
throw new AttestationTimeoutError(0, required, slot);
|
|
210
257
|
}
|
|
258
|
+
await this.collectOwnAttestations(proposal);
|
|
211
259
|
const proposalId = proposal.archive.toString();
|
|
212
|
-
const
|
|
260
|
+
const myAddresses = this.getValidatorAddresses();
|
|
213
261
|
let attestations = [];
|
|
214
262
|
while(true){
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
263
|
+
// Filter out attestations with a mismatching payload. This should NOT happen since we have verified
|
|
264
|
+
// the proposer signature (ie our own) before accepting the attestation into the pool via the p2p client.
|
|
265
|
+
const collectedAttestations = (await this.p2pClient.getAttestationsForSlot(slot, proposalId)).filter((attestation)=>{
|
|
266
|
+
if (!attestation.payload.equals(proposal.payload)) {
|
|
267
|
+
this.log.warn(`Received attestation for slot ${slot} with mismatched payload from ${attestation.getSender()?.toString()}`, {
|
|
268
|
+
attestationPayload: attestation.payload,
|
|
269
|
+
proposalPayload: proposal.payload
|
|
270
|
+
});
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
return true;
|
|
274
|
+
});
|
|
275
|
+
// Log new attestations we collected
|
|
276
|
+
const oldSenders = attestations.map((attestation)=>attestation.getSender());
|
|
220
277
|
for (const collected of collectedAttestations){
|
|
221
|
-
const collectedSender =
|
|
222
|
-
|
|
278
|
+
const collectedSender = collected.getSender();
|
|
279
|
+
// Skip attestations with invalid signatures
|
|
280
|
+
if (!collectedSender) {
|
|
281
|
+
this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (!myAddresses.some((address)=>address.equals(collectedSender)) && !oldSenders.some((sender)=>sender?.equals(collectedSender))) {
|
|
223
285
|
this.log.debug(`Received attestation for slot ${slot} from ${collectedSender.toString()}`);
|
|
224
286
|
}
|
|
225
287
|
}
|
|
@@ -230,17 +292,33 @@ import { ValidatorMetrics } from './metrics.js';
|
|
|
230
292
|
}
|
|
231
293
|
if (+deadline < this.dateProvider.now()) {
|
|
232
294
|
this.log.error(`Timeout ${deadline.toISOString()} waiting for ${required} attestations for slot ${slot}`);
|
|
233
|
-
throw new AttestationTimeoutError(required, slot);
|
|
295
|
+
throw new AttestationTimeoutError(attestations.length, required, slot);
|
|
234
296
|
}
|
|
235
297
|
this.log.debug(`Collected ${attestations.length} attestations so far`);
|
|
236
298
|
await sleep(this.config.attestationPollingIntervalMs);
|
|
237
299
|
}
|
|
238
300
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
return
|
|
243
|
-
}
|
|
244
|
-
|
|
301
|
+
async createBlockAttestationsFromProposal(proposal, attestors = []) {
|
|
302
|
+
const attestations = await this.validationService.attestToProposal(proposal, attestors);
|
|
303
|
+
await this.p2pClient.addAttestations(attestations);
|
|
304
|
+
return attestations;
|
|
305
|
+
}
|
|
306
|
+
async handleAuthRequest(peer, msg) {
|
|
307
|
+
const authRequest = AuthRequest.fromBuffer(msg);
|
|
308
|
+
const statusMessage = await this.p2pClient.handleAuthRequestFromPeer(authRequest, peer).catch((_)=>undefined);
|
|
309
|
+
if (statusMessage === undefined) {
|
|
310
|
+
return Buffer.alloc(0);
|
|
311
|
+
}
|
|
312
|
+
// Find a validator address that is in the set
|
|
313
|
+
const allRegisteredValidators = await this.epochCache.getRegisteredValidators();
|
|
314
|
+
const addressToUse = this.getValidatorAddresses().find((address)=>allRegisteredValidators.find((v)=>v.equals(address)) !== undefined);
|
|
315
|
+
if (addressToUse === undefined) {
|
|
316
|
+
// We don't have a registered address
|
|
317
|
+
return Buffer.alloc(0);
|
|
318
|
+
}
|
|
319
|
+
const payloadToSign = authRequest.getPayloadToSign();
|
|
320
|
+
const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign);
|
|
321
|
+
const authResponse = new AuthResponse(statusMessage, signature);
|
|
322
|
+
return authResponse.toBuffer();
|
|
245
323
|
}
|
|
246
324
|
}
|
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-ceab37513c",
|
|
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-ceab37513c",
|
|
68
|
+
"@aztec/epoch-cache": "0.0.1-fake-ceab37513c",
|
|
69
|
+
"@aztec/ethereum": "0.0.1-fake-ceab37513c",
|
|
70
|
+
"@aztec/foundation": "0.0.1-fake-ceab37513c",
|
|
71
|
+
"@aztec/node-keystore": "0.0.1-fake-ceab37513c",
|
|
72
|
+
"@aztec/p2p": "0.0.1-fake-ceab37513c",
|
|
73
|
+
"@aztec/prover-client": "0.0.1-fake-ceab37513c",
|
|
74
|
+
"@aztec/slasher": "0.0.1-fake-ceab37513c",
|
|
75
|
+
"@aztec/stdlib": "0.0.1-fake-ceab37513c",
|
|
76
|
+
"@aztec/telemetry-client": "0.0.1-fake-ceab37513c",
|
|
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
|
}
|