@aztec/validator-client 0.0.0-test.1 → 0.0.1-commit.1142ef1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +256 -0
- package/dest/block_proposal_handler.d.ts +63 -0
- package/dest/block_proposal_handler.d.ts.map +1 -0
- package/dest/block_proposal_handler.js +551 -0
- package/dest/checkpoint_builder.d.ts +70 -0
- package/dest/checkpoint_builder.d.ts.map +1 -0
- package/dest/checkpoint_builder.js +155 -0
- package/dest/config.d.ts +3 -14
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +46 -7
- package/dest/duties/validation_service.d.ts +36 -12
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +69 -16
- package/dest/factory.d.ts +27 -5
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +13 -6
- package/dest/index.d.ts +6 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +5 -1
- package/dest/key_store/index.d.ts +3 -1
- 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 +55 -6
- 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 +41 -11
- package/dest/key_store/local_key_store.d.ts.map +1 -1
- package/dest/key_store/local_key_store.js +64 -17
- 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 +61 -0
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -0
- package/dest/key_store/web3signer_key_store.js +152 -0
- package/dest/metrics.d.ts +12 -5
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +36 -24
- package/dest/tx_validator/index.d.ts +3 -0
- package/dest/tx_validator/index.d.ts.map +1 -0
- package/dest/tx_validator/index.js +2 -0
- package/dest/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/tx_validator/nullifier_cache.js +24 -0
- package/dest/tx_validator/tx_validator_factory.d.ts +18 -0
- package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -0
- package/dest/tx_validator/tx_validator_factory.js +53 -0
- package/dest/validator.d.ts +73 -58
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +557 -166
- package/package.json +33 -21
- package/src/block_proposal_handler.ts +556 -0
- package/src/checkpoint_builder.ts +267 -0
- package/src/config.ts +58 -22
- package/src/duties/validation_service.ts +124 -18
- package/src/factory.ts +64 -11
- package/src/index.ts +5 -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 +68 -18
- package/src/key_store/node_keystore_adapter.ts +375 -0
- package/src/key_store/web3signer_key_store.ts +192 -0
- package/src/metrics.ts +48 -24
- package/src/tx_validator/index.ts +2 -0
- package/src/tx_validator/nullifier_cache.ts +30 -0
- package/src/tx_validator/tx_validator_factory.ts +133 -0
- package/src/validator.ts +749 -218
- 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,156 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { TimeoutError } from '@aztec/foundation/error';
|
|
2
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
3
6
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
4
7
|
import { sleep } from '@aztec/foundation/sleep';
|
|
5
8
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
6
|
-
import { BlockProposalValidator } from '@aztec/p2p
|
|
7
|
-
import {
|
|
9
|
+
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
10
|
+
import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
11
|
+
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
12
|
+
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
13
|
+
import { EventEmitter } from 'events';
|
|
14
|
+
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
8
15
|
import { ValidationService } from './duties/validation_service.js';
|
|
9
|
-
import {
|
|
10
|
-
import { LocalKeyStore } from './key_store/local_key_store.js';
|
|
16
|
+
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
11
17
|
import { ValidatorMetrics } from './metrics.js';
|
|
18
|
+
// We maintain a set of proposers who have proposed invalid blocks.
|
|
19
|
+
// Just cap the set to avoid unbounded growth.
|
|
20
|
+
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
21
|
+
// What errors from the block proposal handler result in slashing
|
|
22
|
+
const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
23
|
+
'state_mismatch',
|
|
24
|
+
'failed_txs'
|
|
25
|
+
];
|
|
12
26
|
/**
|
|
13
27
|
* Validator Client
|
|
14
|
-
*/ export class ValidatorClient extends
|
|
28
|
+
*/ export class ValidatorClient extends EventEmitter {
|
|
15
29
|
keyStore;
|
|
16
30
|
epochCache;
|
|
17
31
|
p2pClient;
|
|
32
|
+
blockProposalHandler;
|
|
33
|
+
blockSource;
|
|
34
|
+
checkpointsBuilder;
|
|
35
|
+
worldState;
|
|
36
|
+
l1ToL2MessageSource;
|
|
18
37
|
config;
|
|
38
|
+
blobClient;
|
|
19
39
|
dateProvider;
|
|
20
|
-
|
|
40
|
+
tracer;
|
|
21
41
|
validationService;
|
|
22
42
|
metrics;
|
|
43
|
+
log;
|
|
44
|
+
// Whether it has already registered handlers on the p2p client
|
|
45
|
+
hasRegisteredHandlers;
|
|
23
46
|
// Used to check if we are sending the same proposal twice
|
|
24
47
|
previousProposal;
|
|
25
|
-
|
|
26
|
-
blockBuilder;
|
|
48
|
+
lastEpochForCommitteeUpdateLoop;
|
|
27
49
|
epochCacheUpdateLoop;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
50
|
+
proposersOfInvalidBlocks;
|
|
51
|
+
// TODO(palla/mbps): Remove this once checkpoint validation is stable and we can validate all blocks properly.
|
|
52
|
+
// Tracks slots for which we have successfully validated a block proposal, so we can attest to checkpoint proposals for those slots.
|
|
53
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
54
|
+
validatedBlockSlots;
|
|
55
|
+
constructor(keyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
56
|
+
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.blockProposalHandler = blockProposalHandler, this.blockSource = blockSource, this.checkpointsBuilder = checkpointsBuilder, this.worldState = worldState, this.l1ToL2MessageSource = l1ToL2MessageSource, this.config = config, this.blobClient = blobClient, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.proposersOfInvalidBlocks = new Set(), this.validatedBlockSlots = new Set();
|
|
57
|
+
// Create child logger with fisherman prefix if in fisherman mode
|
|
58
|
+
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
59
|
+
this.tracer = telemetry.getTracer('Validator');
|
|
32
60
|
this.metrics = new ValidatorMetrics(telemetry);
|
|
33
|
-
this.validationService = new ValidationService(keyStore);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
61
|
+
this.validationService = new ValidationService(keyStore, this.log.createChild('validation-service'));
|
|
62
|
+
// Refresh epoch cache every second to trigger alert if participation in committee changes
|
|
63
|
+
this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
|
|
64
|
+
const myAddresses = this.getValidatorAddresses();
|
|
65
|
+
this.log.verbose(`Initialized validator with addresses: ${myAddresses.map((a)=>a.toString()).join(', ')}`);
|
|
66
|
+
}
|
|
67
|
+
static validateKeyStoreConfiguration(keyStoreManager, logger) {
|
|
68
|
+
const validatorKeyStore = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
69
|
+
const validatorAddresses = validatorKeyStore.getAddresses();
|
|
70
|
+
// Verify that we can retrieve all required data from the key store
|
|
71
|
+
for (const address of validatorAddresses){
|
|
72
|
+
// Functions throw if required data is not available
|
|
73
|
+
let coinbase;
|
|
74
|
+
let feeRecipient;
|
|
75
|
+
try {
|
|
76
|
+
coinbase = validatorKeyStore.getCoinbaseAddress(address);
|
|
77
|
+
feeRecipient = validatorKeyStore.getFeeRecipient(address);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw new Error(`Failed to retrieve required data for validator address ${address}, error: ${error}`);
|
|
44
80
|
}
|
|
45
|
-
|
|
46
|
-
|
|
81
|
+
const publisherAddresses = validatorKeyStore.getPublisherAddresses(address);
|
|
82
|
+
if (!publisherAddresses.length) {
|
|
83
|
+
throw new Error(`No publisher addresses found for validator address ${address}`);
|
|
84
|
+
}
|
|
85
|
+
logger?.debug(`Validator ${address.toString()} configured with coinbase ${coinbase.toString()}, feeRecipient ${feeRecipient.toString()} and publishers ${publisherAddresses.map((x)=>x.toString()).join()}`);
|
|
86
|
+
}
|
|
47
87
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
88
|
+
async handleEpochCommitteeUpdate() {
|
|
89
|
+
try {
|
|
90
|
+
const { committee, epoch } = await this.epochCache.getCommittee('next');
|
|
91
|
+
if (!committee) {
|
|
92
|
+
this.log.trace(`No committee found for slot`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
|
|
96
|
+
const me = this.getValidatorAddresses();
|
|
97
|
+
const committeeSet = new Set(committee.map((v)=>v.toString()));
|
|
98
|
+
const inCommittee = me.filter((a)=>committeeSet.has(a.toString()));
|
|
99
|
+
if (inCommittee.length > 0) {
|
|
100
|
+
this.log.info(`Validators ${inCommittee.map((a)=>a.toString()).join(',')} are on the validator committee for epoch ${epoch}`);
|
|
101
|
+
} else {
|
|
102
|
+
this.log.verbose(`Validators ${me.map((a)=>a.toString()).join(', ')} are not on the validator committee for epoch ${epoch}`);
|
|
103
|
+
}
|
|
104
|
+
this.lastEpochForCommitteeUpdateLoop = epoch;
|
|
105
|
+
}
|
|
106
|
+
} catch (err) {
|
|
107
|
+
this.log.error(`Error updating epoch committee`, err);
|
|
51
108
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
109
|
+
}
|
|
110
|
+
static new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
111
|
+
const metrics = new ValidatorMetrics(telemetry);
|
|
112
|
+
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
113
|
+
txsPermitted: !config.disableTransactions
|
|
114
|
+
});
|
|
115
|
+
const blockProposalHandler = new BlockProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, config, metrics, dateProvider, telemetry);
|
|
116
|
+
const validator = new ValidatorClient(NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager), epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider, telemetry);
|
|
56
117
|
return validator;
|
|
57
118
|
}
|
|
119
|
+
getValidatorAddresses() {
|
|
120
|
+
return this.keyStore.getAddresses().filter((addr)=>!this.config.disabledValidators.some((disabled)=>disabled.equals(addr)));
|
|
121
|
+
}
|
|
122
|
+
getBlockProposalHandler() {
|
|
123
|
+
return this.blockProposalHandler;
|
|
124
|
+
}
|
|
125
|
+
signWithAddress(addr, msg) {
|
|
126
|
+
return this.keyStore.signTypedDataWithAddress(addr, msg);
|
|
127
|
+
}
|
|
128
|
+
getCoinbaseForAttestor(attestor) {
|
|
129
|
+
return this.keyStore.getCoinbaseAddress(attestor);
|
|
130
|
+
}
|
|
131
|
+
getFeeRecipientForAttestor(attestor) {
|
|
132
|
+
return this.keyStore.getFeeRecipient(attestor);
|
|
133
|
+
}
|
|
134
|
+
getConfig() {
|
|
135
|
+
return this.config;
|
|
136
|
+
}
|
|
137
|
+
updateConfig(config) {
|
|
138
|
+
this.config = {
|
|
139
|
+
...this.config,
|
|
140
|
+
...config
|
|
141
|
+
};
|
|
142
|
+
}
|
|
58
143
|
async start() {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
144
|
+
if (this.epochCacheUpdateLoop.isRunning()) {
|
|
145
|
+
this.log.warn(`Validator client already started`);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
await this.registerHandlers();
|
|
149
|
+
const myAddresses = this.getValidatorAddresses();
|
|
150
|
+
const inCommittee = await this.epochCache.filterInCommittee('now', myAddresses);
|
|
151
|
+
this.log.info(`Started validator with addresses: ${myAddresses.map((a)=>a.toString()).join(', ')}`);
|
|
152
|
+
if (inCommittee.length > 0) {
|
|
153
|
+
this.log.info(`Addresses in current validator committee: ${inCommittee.map((a)=>a.toString()).join(', ')}`);
|
|
67
154
|
}
|
|
68
155
|
this.epochCacheUpdateLoop.start();
|
|
69
156
|
return Promise.resolve();
|
|
@@ -71,155 +158,448 @@ import { ValidatorMetrics } from './metrics.js';
|
|
|
71
158
|
async stop() {
|
|
72
159
|
await this.epochCacheUpdateLoop.stop();
|
|
73
160
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
161
|
+
/** Register handlers on the p2p client */ async registerHandlers() {
|
|
162
|
+
if (!this.hasRegisteredHandlers) {
|
|
163
|
+
this.hasRegisteredHandlers = true;
|
|
164
|
+
this.log.debug(`Registering validator handlers for p2p client`);
|
|
165
|
+
// Block proposal handler - validates but does NOT attest (validators only attest to checkpoints)
|
|
166
|
+
const blockHandler = (block, proposalSender)=>this.validateBlockProposal(block, proposalSender);
|
|
167
|
+
this.p2pClient.registerBlockProposalHandler(blockHandler);
|
|
168
|
+
// Checkpoint proposal handler - validates and creates attestations
|
|
169
|
+
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
170
|
+
// and processed separately via the block handler above.
|
|
171
|
+
const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
172
|
+
this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
|
|
173
|
+
const myAddresses = this.getValidatorAddresses();
|
|
174
|
+
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
175
|
+
await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
|
|
176
|
+
}
|
|
79
177
|
}
|
|
80
178
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
179
|
+
* Validate a block proposal from a peer.
|
|
180
|
+
* Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
|
|
181
|
+
* @returns true if the proposal is valid, false otherwise
|
|
182
|
+
*/ async validateBlockProposal(proposal, proposalSender) {
|
|
183
|
+
const slotNumber = proposal.slotNumber;
|
|
184
|
+
const proposer = proposal.getSender();
|
|
185
|
+
// Reject proposals with invalid signatures
|
|
186
|
+
if (!proposer) {
|
|
187
|
+
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
// Check if we're in the committee (for metrics purposes)
|
|
191
|
+
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
192
|
+
const partOfCommittee = inCommittee.length > 0;
|
|
89
193
|
const proposalInfo = {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
archive: proposal.payload.archive.toString(),
|
|
93
|
-
txCount: proposal.payload.txHashes.length,
|
|
94
|
-
txHashes: proposal.payload.txHashes.map((txHash)=>txHash.toString())
|
|
194
|
+
...proposal.toBlockInfo(),
|
|
195
|
+
proposer: proposer.toString()
|
|
95
196
|
};
|
|
96
|
-
this.log.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
this.
|
|
197
|
+
this.log.info(`Received block proposal for slot ${slotNumber}`, {
|
|
198
|
+
...proposalInfo,
|
|
199
|
+
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
200
|
+
fishermanMode: this.config.fishermanMode || false
|
|
201
|
+
});
|
|
202
|
+
// Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
|
|
203
|
+
// In fisherman mode, we always reexecute to validate proposals.
|
|
204
|
+
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
205
|
+
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
|
|
206
|
+
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute);
|
|
207
|
+
if (!validationResult.isValid) {
|
|
208
|
+
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
209
|
+
const reason = validationResult.reason || 'unknown';
|
|
210
|
+
// Classify failure reason: bad proposal vs node issue
|
|
211
|
+
const badProposalReasons = [
|
|
212
|
+
'invalid_proposal',
|
|
213
|
+
'state_mismatch',
|
|
214
|
+
'failed_txs',
|
|
215
|
+
'in_hash_mismatch',
|
|
216
|
+
'parent_block_wrong_slot'
|
|
217
|
+
];
|
|
218
|
+
if (badProposalReasons.includes(reason)) {
|
|
219
|
+
this.metrics.incFailedAttestationsBadProposal(1, reason, partOfCommittee);
|
|
220
|
+
} else {
|
|
221
|
+
// Node issues so we can't validate
|
|
222
|
+
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
223
|
+
}
|
|
224
|
+
// Slash invalid block proposals (can happen even when not in committee)
|
|
225
|
+
if (validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
|
|
226
|
+
this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
|
|
227
|
+
this.slashInvalidBlock(proposal);
|
|
228
|
+
}
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
this.log.info(`Validated block proposal for slot ${slotNumber}`, {
|
|
232
|
+
...proposalInfo,
|
|
233
|
+
inCommittee: partOfCommittee,
|
|
234
|
+
fishermanMode: this.config.fishermanMode || false
|
|
235
|
+
});
|
|
236
|
+
// TODO(palla/mbps): Remove this once checkpoint validation is stable.
|
|
237
|
+
// Track that we successfully validated a block for this slot, so we can attest to checkpoint proposals for it.
|
|
238
|
+
this.validatedBlockSlots.add(slotNumber);
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Validate and attest to a checkpoint proposal from a peer.
|
|
243
|
+
* The proposal is received as CheckpointProposalCore (without lastBlock) since
|
|
244
|
+
* the lastBlock is extracted and processed separately via the block handler.
|
|
245
|
+
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
246
|
+
*/ async attestToCheckpointProposal(proposal, _proposalSender) {
|
|
247
|
+
const slotNumber = proposal.slotNumber;
|
|
248
|
+
const proposer = proposal.getSender();
|
|
249
|
+
// Reject proposals with invalid signatures
|
|
250
|
+
if (!proposer) {
|
|
251
|
+
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
100
252
|
return undefined;
|
|
101
253
|
}
|
|
102
|
-
// Check that
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
254
|
+
// Check that I have any address in current committee before attesting
|
|
255
|
+
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
256
|
+
const partOfCommittee = inCommittee.length > 0;
|
|
257
|
+
const proposalInfo = {
|
|
258
|
+
slotNumber,
|
|
259
|
+
archive: proposal.archive.toString(),
|
|
260
|
+
proposer: proposer.toString(),
|
|
261
|
+
txCount: proposal.txHashes.length
|
|
262
|
+
};
|
|
263
|
+
this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
|
|
264
|
+
...proposalInfo,
|
|
265
|
+
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
266
|
+
fishermanMode: this.config.fishermanMode || false
|
|
267
|
+
});
|
|
268
|
+
// TODO(palla/mbps): Remove this once checkpoint validation is stable.
|
|
269
|
+
// Check that we have successfully validated a block for this slot before attesting to the checkpoint.
|
|
270
|
+
if (!this.validatedBlockSlots.has(slotNumber)) {
|
|
271
|
+
this.log.warn(`No validated block found for slot ${slotNumber}, refusing to attest to checkpoint`, proposalInfo);
|
|
106
272
|
return undefined;
|
|
107
273
|
}
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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);
|
|
274
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
275
|
+
// TODO(palla/mbps): Change default to false once checkpoint validation is stable.
|
|
276
|
+
if (this.config.skipCheckpointProposalValidation !== false) {
|
|
277
|
+
this.log.verbose(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
|
|
278
|
+
} else {
|
|
279
|
+
const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
280
|
+
if (!validationResult.isValid) {
|
|
281
|
+
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
282
|
+
return undefined;
|
|
124
283
|
}
|
|
284
|
+
}
|
|
285
|
+
// Upload blobs to filestore if we can (fire and forget)
|
|
286
|
+
if (this.blobClient.canUpload()) {
|
|
287
|
+
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
288
|
+
}
|
|
289
|
+
// Check that I have any address in current committee before attesting
|
|
290
|
+
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
291
|
+
if (!partOfCommittee && !this.config.fishermanMode) {
|
|
292
|
+
this.log.verbose(`No validator in the current committee, skipping attestation`, proposalInfo);
|
|
125
293
|
return undefined;
|
|
126
294
|
}
|
|
127
295
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
128
|
-
this.log.info(
|
|
129
|
-
|
|
130
|
-
|
|
296
|
+
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${slotNumber}`, {
|
|
297
|
+
...proposalInfo,
|
|
298
|
+
inCommittee: partOfCommittee,
|
|
299
|
+
fishermanMode: this.config.fishermanMode || false
|
|
300
|
+
});
|
|
301
|
+
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
302
|
+
// Determine which validators should attest
|
|
303
|
+
let attestors;
|
|
304
|
+
if (partOfCommittee) {
|
|
305
|
+
attestors = inCommittee;
|
|
306
|
+
} else if (this.config.fishermanMode) {
|
|
307
|
+
// In fisherman mode, create attestations for validation purposes even if not in committee. These won't be broadcast.
|
|
308
|
+
attestors = this.getValidatorAddresses();
|
|
309
|
+
} else {
|
|
310
|
+
attestors = [];
|
|
311
|
+
}
|
|
312
|
+
// Only create attestations if we have attestors
|
|
313
|
+
if (attestors.length === 0) {
|
|
314
|
+
return undefined;
|
|
315
|
+
}
|
|
316
|
+
if (this.config.fishermanMode) {
|
|
317
|
+
// bail out early and don't save attestations to the pool in fisherman mode
|
|
318
|
+
this.log.info(`Creating checkpoint attestations for slot ${slotNumber}`, {
|
|
319
|
+
...proposalInfo,
|
|
320
|
+
attestors: attestors.map((a)=>a.toString())
|
|
321
|
+
});
|
|
322
|
+
return undefined;
|
|
323
|
+
}
|
|
324
|
+
return this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
325
|
+
}
|
|
326
|
+
async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
|
|
327
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
328
|
+
await this.p2pClient.addCheckpointAttestations(attestations);
|
|
329
|
+
return attestations;
|
|
131
330
|
}
|
|
132
331
|
/**
|
|
133
|
-
*
|
|
134
|
-
* @
|
|
135
|
-
*/ async
|
|
136
|
-
const
|
|
137
|
-
const
|
|
138
|
-
//
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
332
|
+
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
333
|
+
* @returns Validation result with isValid flag and reason if invalid.
|
|
334
|
+
*/ async validateCheckpointProposal(proposal, proposalInfo) {
|
|
335
|
+
const slot = proposal.slotNumber;
|
|
336
|
+
const timeoutSeconds = 10;
|
|
337
|
+
// Wait for last block to sync by archive
|
|
338
|
+
let lastBlockHeader;
|
|
339
|
+
try {
|
|
340
|
+
lastBlockHeader = await retryUntil(async ()=>{
|
|
341
|
+
await this.blockSource.syncImmediate();
|
|
342
|
+
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
343
|
+
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, timeoutSeconds, 0.5);
|
|
344
|
+
} catch (err) {
|
|
345
|
+
if (err instanceof TimeoutError) {
|
|
346
|
+
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
347
|
+
return {
|
|
348
|
+
isValid: false,
|
|
349
|
+
reason: 'last_block_not_found'
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
353
|
+
return {
|
|
354
|
+
isValid: false,
|
|
355
|
+
reason: 'block_fetch_error'
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
if (!lastBlockHeader) {
|
|
359
|
+
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
360
|
+
return {
|
|
361
|
+
isValid: false,
|
|
362
|
+
reason: 'last_block_not_found'
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
// Get the last full block to determine checkpoint number
|
|
366
|
+
const lastBlock = await this.blockSource.getL2BlockNew(lastBlockHeader.getBlockNumber());
|
|
367
|
+
if (!lastBlock) {
|
|
368
|
+
this.log.warn(`Last block ${lastBlockHeader.getBlockNumber()} not found`, proposalInfo);
|
|
369
|
+
return {
|
|
370
|
+
isValid: false,
|
|
371
|
+
reason: 'last_block_not_found'
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
const checkpointNumber = lastBlock.checkpointNumber;
|
|
375
|
+
// Get all full blocks for the slot and checkpoint
|
|
376
|
+
const blocks = await this.getBlocksForSlot(slot, lastBlockHeader, checkpointNumber);
|
|
377
|
+
if (blocks.length === 0) {
|
|
378
|
+
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
379
|
+
return {
|
|
380
|
+
isValid: false,
|
|
381
|
+
reason: 'no_blocks_for_slot'
|
|
382
|
+
};
|
|
156
383
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
384
|
+
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
385
|
+
...proposalInfo,
|
|
386
|
+
blockNumbers: blocks.map((b)=>b.number)
|
|
387
|
+
});
|
|
388
|
+
// Get checkpoint constants from first block
|
|
389
|
+
const firstBlock = blocks[0];
|
|
390
|
+
const constants = this.extractCheckpointConstants(firstBlock);
|
|
391
|
+
// Get L1-to-L2 messages for this checkpoint
|
|
392
|
+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
393
|
+
// Fork world state at the block before the first block
|
|
394
|
+
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
395
|
+
const fork = await this.worldState.fork(parentBlockNumber);
|
|
396
|
+
try {
|
|
397
|
+
// Create checkpoint builder with all existing blocks
|
|
398
|
+
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, l1ToL2Messages, fork, blocks);
|
|
399
|
+
// Complete the checkpoint to get computed values
|
|
400
|
+
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
401
|
+
// Compare checkpoint header with proposal
|
|
402
|
+
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
403
|
+
this.log.warn(`Checkpoint header mismatch`, {
|
|
404
|
+
...proposalInfo,
|
|
405
|
+
computed: computedCheckpoint.header.toInspect(),
|
|
406
|
+
proposal: proposal.checkpointHeader.toInspect()
|
|
407
|
+
});
|
|
408
|
+
return {
|
|
409
|
+
isValid: false,
|
|
410
|
+
reason: 'checkpoint_header_mismatch'
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
// Compare archive root with proposal
|
|
414
|
+
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
415
|
+
this.log.warn(`Archive root mismatch`, {
|
|
416
|
+
...proposalInfo,
|
|
417
|
+
computed: computedCheckpoint.archive.root.toString(),
|
|
418
|
+
proposal: proposal.archive.toString()
|
|
419
|
+
});
|
|
420
|
+
return {
|
|
421
|
+
isValid: false,
|
|
422
|
+
reason: 'archive_mismatch'
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
426
|
+
return {
|
|
427
|
+
isValid: true
|
|
428
|
+
};
|
|
429
|
+
} finally{
|
|
430
|
+
await fork.close();
|
|
160
431
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Get all full blocks for a given slot and checkpoint by walking backwards from the last block.
|
|
435
|
+
* Returns blocks in ascending order (earliest to latest).
|
|
436
|
+
* TODO(palla/mbps): Add getL2BlocksForSlot() to L2BlockSource interface for efficiency.
|
|
437
|
+
*/ async getBlocksForSlot(slot, lastBlockHeader, checkpointNumber) {
|
|
438
|
+
const blocks = [];
|
|
439
|
+
let currentHeader = lastBlockHeader;
|
|
440
|
+
const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
|
|
441
|
+
while(currentHeader.getSlot() === slot){
|
|
442
|
+
const block = await this.blockSource.getL2BlockNew(currentHeader.getBlockNumber());
|
|
443
|
+
if (!block) {
|
|
444
|
+
this.log.warn(`Block ${currentHeader.getBlockNumber()} not found while getting blocks for slot ${slot}`);
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
if (block.checkpointNumber !== checkpointNumber) {
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
blocks.unshift(block);
|
|
451
|
+
const prevArchive = currentHeader.lastArchive.root;
|
|
452
|
+
if (prevArchive.equals(genesisArchiveRoot)) {
|
|
453
|
+
break;
|
|
454
|
+
}
|
|
455
|
+
const prevHeader = await this.blockSource.getBlockHeaderByArchive(prevArchive);
|
|
456
|
+
if (!prevHeader || prevHeader.getSlot() !== slot) {
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
currentHeader = prevHeader;
|
|
165
460
|
}
|
|
461
|
+
return blocks;
|
|
166
462
|
}
|
|
167
463
|
/**
|
|
168
|
-
*
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
464
|
+
* Extract checkpoint global variables from a block.
|
|
465
|
+
*/ extractCheckpointConstants(block) {
|
|
466
|
+
const gv = block.header.globalVariables;
|
|
467
|
+
return {
|
|
468
|
+
chainId: gv.chainId,
|
|
469
|
+
version: gv.version,
|
|
470
|
+
slotNumber: gv.slotNumber,
|
|
471
|
+
coinbase: gv.coinbase,
|
|
472
|
+
feeRecipient: gv.feeRecipient,
|
|
473
|
+
gasFees: gv.gasFees
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
478
|
+
*/ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
|
|
479
|
+
try {
|
|
480
|
+
const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
481
|
+
if (!lastBlockHeader) {
|
|
482
|
+
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
// Get the last full block to determine checkpoint number
|
|
486
|
+
const lastBlock = await this.blockSource.getL2BlockNew(lastBlockHeader.getBlockNumber());
|
|
487
|
+
if (!lastBlock) {
|
|
488
|
+
this.log.warn(`Failed to get last block for blob upload`, proposalInfo);
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
const blocks = await this.getBlocksForSlot(proposal.slotNumber, lastBlockHeader, lastBlock.checkpointNumber);
|
|
492
|
+
if (blocks.length === 0) {
|
|
493
|
+
this.log.warn(`No blocks found for blob upload`, proposalInfo);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
const blobFields = blocks.flatMap((b)=>b.toBlobFields());
|
|
497
|
+
const blobs = getBlobsPerL1Block(blobFields);
|
|
498
|
+
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
499
|
+
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
500
|
+
...proposalInfo,
|
|
501
|
+
numBlobs: blobs.length
|
|
502
|
+
});
|
|
503
|
+
} catch (err) {
|
|
504
|
+
this.log.warn(`Failed to upload blobs for checkpoint: ${err}`, proposalInfo);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
slashInvalidBlock(proposal) {
|
|
508
|
+
const proposer = proposal.getSender();
|
|
509
|
+
// Skip if signature is invalid (shouldn't happen since we validate earlier)
|
|
510
|
+
if (!proposer) {
|
|
511
|
+
this.log.warn(`Cannot slash proposal with invalid signature`);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
// Trim the set if it's too big.
|
|
515
|
+
if (this.proposersOfInvalidBlocks.size > MAX_PROPOSERS_OF_INVALID_BLOCKS) {
|
|
516
|
+
// remove oldest proposer. `values` is guaranteed to be in insertion order.
|
|
517
|
+
this.proposersOfInvalidBlocks.delete(this.proposersOfInvalidBlocks.values().next().value);
|
|
518
|
+
}
|
|
519
|
+
this.proposersOfInvalidBlocks.add(proposer.toString());
|
|
520
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
521
|
+
{
|
|
522
|
+
validator: proposer,
|
|
523
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
524
|
+
offenseType: OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL,
|
|
525
|
+
epochOrSlot: BigInt(proposal.slotNumber)
|
|
526
|
+
}
|
|
527
|
+
]);
|
|
528
|
+
}
|
|
529
|
+
async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options) {
|
|
530
|
+
// TODO(palla/mbps): Prevent double proposals properly
|
|
531
|
+
// if (this.previousProposal?.slotNumber === blockHeader.globalVariables.slotNumber) {
|
|
532
|
+
// this.log.verbose(`Already made a proposal for the same slot, skipping proposal`);
|
|
533
|
+
// return Promise.resolve(undefined);
|
|
534
|
+
// }
|
|
535
|
+
this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
|
|
536
|
+
const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
537
|
+
...options,
|
|
538
|
+
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
539
|
+
});
|
|
196
540
|
this.previousProposal = newProposal;
|
|
197
541
|
return newProposal;
|
|
198
542
|
}
|
|
199
|
-
|
|
200
|
-
this.
|
|
543
|
+
async createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options) {
|
|
544
|
+
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
545
|
+
return await this.validationService.createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options);
|
|
546
|
+
}
|
|
547
|
+
async broadcastBlockProposal(proposal) {
|
|
548
|
+
await this.p2pClient.broadcastProposal(proposal);
|
|
549
|
+
}
|
|
550
|
+
async signAttestationsAndSigners(attestationsAndSigners, proposer) {
|
|
551
|
+
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
|
|
552
|
+
}
|
|
553
|
+
async collectOwnAttestations(proposal) {
|
|
554
|
+
const slot = proposal.slotNumber;
|
|
555
|
+
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
556
|
+
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
|
|
557
|
+
inCommittee
|
|
558
|
+
});
|
|
559
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
560
|
+
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
561
|
+
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
562
|
+
// due to inactivity for missed attestations.
|
|
563
|
+
void this.p2pClient.broadcastCheckpointAttestations(attestations).catch((err)=>{
|
|
564
|
+
this.log.error(`Failed to broadcast self-attestations for slot ${slot}`, err);
|
|
565
|
+
});
|
|
566
|
+
return attestations;
|
|
201
567
|
}
|
|
202
|
-
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/7962)
|
|
203
568
|
async collectAttestations(proposal, required, deadline) {
|
|
204
|
-
// Wait and poll the p2pClient's attestation pool for this
|
|
205
|
-
const slot = proposal.
|
|
569
|
+
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
570
|
+
const slot = proposal.slotNumber;
|
|
206
571
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
207
572
|
if (+deadline < this.dateProvider.now()) {
|
|
208
573
|
this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
|
|
209
|
-
throw new AttestationTimeoutError(required, slot);
|
|
574
|
+
throw new AttestationTimeoutError(0, required, slot);
|
|
210
575
|
}
|
|
576
|
+
await this.collectOwnAttestations(proposal);
|
|
211
577
|
const proposalId = proposal.archive.toString();
|
|
212
|
-
const
|
|
578
|
+
const myAddresses = this.getValidatorAddresses();
|
|
213
579
|
let attestations = [];
|
|
214
580
|
while(true){
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
581
|
+
// Filter out attestations with a mismatching archive. This should NOT happen since we have verified
|
|
582
|
+
// the proposer signature (ie our own) before accepting the attestation into the pool via the p2p client.
|
|
583
|
+
const collectedAttestations = (await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalId)).filter((attestation)=>{
|
|
584
|
+
if (!attestation.archive.equals(proposal.archive)) {
|
|
585
|
+
this.log.warn(`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`, {
|
|
586
|
+
attestationArchive: attestation.archive.toString(),
|
|
587
|
+
proposalArchive: proposal.archive.toString()
|
|
588
|
+
});
|
|
589
|
+
return false;
|
|
590
|
+
}
|
|
591
|
+
return true;
|
|
592
|
+
});
|
|
593
|
+
// Log new attestations we collected
|
|
594
|
+
const oldSenders = attestations.map((attestation)=>attestation.getSender());
|
|
220
595
|
for (const collected of collectedAttestations){
|
|
221
|
-
const collectedSender =
|
|
222
|
-
|
|
596
|
+
const collectedSender = collected.getSender();
|
|
597
|
+
// Skip attestations with invalid signatures
|
|
598
|
+
if (!collectedSender) {
|
|
599
|
+
this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
|
|
600
|
+
continue;
|
|
601
|
+
}
|
|
602
|
+
if (!myAddresses.some((address)=>address.equals(collectedSender)) && !oldSenders.some((sender)=>sender?.equals(collectedSender))) {
|
|
223
603
|
this.log.debug(`Received attestation for slot ${slot} from ${collectedSender.toString()}`);
|
|
224
604
|
}
|
|
225
605
|
}
|
|
@@ -230,17 +610,28 @@ import { ValidatorMetrics } from './metrics.js';
|
|
|
230
610
|
}
|
|
231
611
|
if (+deadline < this.dateProvider.now()) {
|
|
232
612
|
this.log.error(`Timeout ${deadline.toISOString()} waiting for ${required} attestations for slot ${slot}`);
|
|
233
|
-
throw new AttestationTimeoutError(required, slot);
|
|
613
|
+
throw new AttestationTimeoutError(attestations.length, required, slot);
|
|
234
614
|
}
|
|
235
|
-
this.log.debug(`Collected ${attestations.length} attestations so far`);
|
|
615
|
+
this.log.debug(`Collected ${attestations.length} of ${required} attestations so far`);
|
|
236
616
|
await sleep(this.config.attestationPollingIntervalMs);
|
|
237
617
|
}
|
|
238
618
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
619
|
+
async handleAuthRequest(peer, msg) {
|
|
620
|
+
const authRequest = AuthRequest.fromBuffer(msg);
|
|
621
|
+
const statusMessage = await this.p2pClient.handleAuthRequestFromPeer(authRequest, peer).catch((_)=>undefined);
|
|
622
|
+
if (statusMessage === undefined) {
|
|
623
|
+
return Buffer.alloc(0);
|
|
624
|
+
}
|
|
625
|
+
// Find a validator address that is in the set
|
|
626
|
+
const allRegisteredValidators = await this.epochCache.getRegisteredValidators();
|
|
627
|
+
const addressToUse = this.getValidatorAddresses().find((address)=>allRegisteredValidators.find((v)=>v.equals(address)) !== undefined);
|
|
628
|
+
if (addressToUse === undefined) {
|
|
629
|
+
// We don't have a registered address
|
|
630
|
+
return Buffer.alloc(0);
|
|
631
|
+
}
|
|
632
|
+
const payloadToSign = authRequest.getPayloadToSign();
|
|
633
|
+
const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign);
|
|
634
|
+
const authResponse = new AuthResponse(statusMessage, signature);
|
|
635
|
+
return authResponse.toBuffer();
|
|
245
636
|
}
|
|
246
637
|
}
|