@aztec/slasher 0.0.1-commit.c2595eba → 0.0.1-commit.c2eed6949
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 +24 -14
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +13 -1
- package/dest/empire_slasher_client.d.ts +1 -1
- package/dest/empire_slasher_client.d.ts.map +1 -1
- package/dest/empire_slasher_client.js +0 -8
- package/dest/factory/create_facade.d.ts +3 -3
- package/dest/factory/create_facade.d.ts.map +1 -1
- package/dest/factory/create_facade.js +25 -2
- package/dest/factory/create_implementation.d.ts +4 -3
- package/dest/factory/create_implementation.d.ts.map +1 -1
- package/dest/factory/create_implementation.js +11 -7
- package/dest/factory/get_settings.d.ts +2 -2
- package/dest/factory/get_settings.d.ts.map +1 -1
- package/dest/generated/slasher-defaults.d.ts +4 -2
- package/dest/generated/slasher-defaults.d.ts.map +1 -1
- package/dest/generated/slasher-defaults.js +3 -1
- package/dest/slash_offenses_collector.d.ts +5 -2
- package/dest/slash_offenses_collector.d.ts.map +1 -1
- package/dest/slash_offenses_collector.js +3 -7
- package/dest/slasher_client_facade.d.ts +4 -3
- package/dest/slasher_client_facade.d.ts.map +1 -1
- package/dest/slasher_client_facade.js +4 -2
- package/dest/stores/offenses_store.d.ts +1 -1
- package/dest/stores/offenses_store.d.ts.map +1 -1
- package/dest/stores/offenses_store.js +4 -2
- package/dest/stores/payloads_store.d.ts +1 -1
- package/dest/stores/payloads_store.d.ts.map +1 -1
- package/dest/stores/payloads_store.js +6 -3
- package/dest/tally_slasher_client.d.ts +2 -2
- package/dest/tally_slasher_client.d.ts.map +1 -1
- package/dest/tally_slasher_client.js +6 -9
- package/dest/watchers/epoch_prune_watcher.d.ts +6 -5
- package/dest/watchers/epoch_prune_watcher.d.ts.map +1 -1
- package/dest/watchers/epoch_prune_watcher.js +47 -26
- package/package.json +9 -9
- package/src/config.ts +15 -1
- package/src/empire_slasher_client.ts +0 -8
- package/src/factory/create_facade.ts +32 -3
- package/src/factory/create_implementation.ts +29 -4
- package/src/factory/get_settings.ts +2 -2
- package/src/generated/slasher-defaults.ts +3 -1
- package/src/slash_offenses_collector.ts +9 -8
- package/src/slasher_client_facade.ts +3 -1
- package/src/stores/offenses_store.ts +4 -2
- package/src/stores/payloads_store.ts +7 -4
- package/src/tally_slasher_client.ts +8 -10
- package/src/watchers/epoch_prune_watcher.ts +61 -26
|
@@ -5,9 +5,9 @@ import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
|
5
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
6
|
import { createLogger } from '@aztec/foundation/log';
|
|
7
7
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
8
|
-
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
9
8
|
import { AztecLMDBStoreV2 } from '@aztec/kv-store/lmdb-v2';
|
|
10
9
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
10
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
11
11
|
import type { Offense, ProposerSlashAction, SlashPayloadRound } from '@aztec/stdlib/slashing';
|
|
12
12
|
|
|
13
13
|
import { createSlasherImplementation } from './factory/create_implementation.js';
|
|
@@ -32,6 +32,7 @@ export class SlasherClientFacade implements SlasherClientInterface {
|
|
|
32
32
|
private epochCache: EpochCache,
|
|
33
33
|
private dateProvider: DateProvider,
|
|
34
34
|
private kvStore: AztecLMDBStoreV2,
|
|
35
|
+
private rollupRegisteredAtL2Slot: SlotNumber,
|
|
35
36
|
private logger = createLogger('slasher'),
|
|
36
37
|
) {}
|
|
37
38
|
|
|
@@ -88,6 +89,7 @@ export class SlasherClientFacade implements SlasherClientInterface {
|
|
|
88
89
|
this.epochCache,
|
|
89
90
|
this.dateProvider,
|
|
90
91
|
this.kvStore,
|
|
92
|
+
this.rollupRegisteredAtL2Slot,
|
|
91
93
|
this.logger,
|
|
92
94
|
);
|
|
93
95
|
}
|
|
@@ -76,9 +76,11 @@ export class SlasherOffensesStore {
|
|
|
76
76
|
/** Adds a new offense (defaults to pending, but will be slashed if markAsSlashed had been called for it) */
|
|
77
77
|
public async addPendingOffense(offense: Offense): Promise<void> {
|
|
78
78
|
const key = this.getOffenseKey(offense);
|
|
79
|
-
await this.offenses.set(key, serializeOffense(offense));
|
|
80
79
|
const round = getRoundForOffense(offense, this.settings);
|
|
81
|
-
await this.
|
|
80
|
+
await this.kvStore.transactionAsync(async () => {
|
|
81
|
+
await this.offenses.set(key, serializeOffense(offense));
|
|
82
|
+
await this.roundsOffenses.set(this.getRoundKey(round), key);
|
|
83
|
+
});
|
|
82
84
|
this.log.trace(`Adding pending offense ${key} for round ${round}`);
|
|
83
85
|
}
|
|
84
86
|
|
|
@@ -118,10 +118,13 @@ export class SlasherPayloadsStore {
|
|
|
118
118
|
|
|
119
119
|
public async incrementPayloadVotes(payloadAddress: EthAddress, round: bigint): Promise<bigint> {
|
|
120
120
|
const key = this.getPayloadVotesKey(round, payloadAddress);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
let newVotes: bigint;
|
|
122
|
+
await this.kvStore.transactionAsync(async () => {
|
|
123
|
+
const currentVotes = (await this.roundPayloadVotes.getAsync(key)) || 0n;
|
|
124
|
+
newVotes = currentVotes + 1n;
|
|
125
|
+
await this.roundPayloadVotes.set(key, newVotes);
|
|
126
|
+
});
|
|
127
|
+
return newVotes!;
|
|
125
128
|
}
|
|
126
129
|
|
|
127
130
|
public async addPayload(payload: SlashPayloadRound): Promise<void> {
|
|
@@ -5,7 +5,6 @@ import { maxBigint } from '@aztec/foundation/bigint';
|
|
|
5
5
|
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
6
6
|
import { compactArray, partition, times } from '@aztec/foundation/collection';
|
|
7
7
|
import { createLogger } from '@aztec/foundation/log';
|
|
8
|
-
import { sleep } from '@aztec/foundation/sleep';
|
|
9
8
|
import type { DateProvider } from '@aztec/foundation/timer';
|
|
10
9
|
import type { Prettify } from '@aztec/foundation/types';
|
|
11
10
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
@@ -47,7 +46,10 @@ export type TallySlasherSettings = Prettify<
|
|
|
47
46
|
>;
|
|
48
47
|
|
|
49
48
|
export type TallySlasherClientConfig = SlashOffensesCollectorConfig &
|
|
50
|
-
Pick<
|
|
49
|
+
Pick<
|
|
50
|
+
SlasherConfig,
|
|
51
|
+
'slashValidatorsAlways' | 'slashValidatorsNever' | 'slashExecuteRoundsLookBack' | 'slashMaxPayloadSize'
|
|
52
|
+
>;
|
|
51
53
|
|
|
52
54
|
/**
|
|
53
55
|
* The Tally Slasher client is responsible for managing slashable offenses using
|
|
@@ -138,8 +140,6 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
138
140
|
this.roundMonitor.stop();
|
|
139
141
|
await this.offensesCollector.stop();
|
|
140
142
|
|
|
141
|
-
// Sleeping to sidestep viem issue with unwatching events
|
|
142
|
-
await sleep(2000);
|
|
143
143
|
this.log.info('Tally Slasher client stopped');
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -352,24 +352,22 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
|
|
|
352
352
|
return undefined;
|
|
353
353
|
}
|
|
354
354
|
|
|
355
|
-
const offensesToSlashLog = offensesToSlash.map(offense => ({
|
|
356
|
-
...offense,
|
|
357
|
-
amount: offense.amount.toString(),
|
|
358
|
-
}));
|
|
359
355
|
this.log.info(`Voting to slash ${offensesToSlash.length} offenses`, {
|
|
360
356
|
slotNumber,
|
|
361
357
|
currentRound,
|
|
362
358
|
slashedRound,
|
|
363
|
-
offensesToSlash
|
|
359
|
+
offensesToSlash,
|
|
364
360
|
});
|
|
365
361
|
|
|
366
362
|
const committees = await this.collectCommitteesActiveDuringRound(slashedRound);
|
|
367
363
|
const epochsForCommittees = getEpochsForRound(slashedRound, this.settings);
|
|
364
|
+
const { slashMaxPayloadSize } = this.config;
|
|
368
365
|
const votes = getSlashConsensusVotesFromOffenses(
|
|
369
366
|
offensesToSlash,
|
|
370
367
|
committees,
|
|
371
368
|
epochsForCommittees.map(e => BigInt(e)),
|
|
372
|
-
this.settings,
|
|
369
|
+
{ ...this.settings, maxSlashedValidators: slashMaxPayloadSize },
|
|
370
|
+
this.log,
|
|
373
371
|
);
|
|
374
372
|
if (votes.every(v => v === 0)) {
|
|
375
373
|
this.log.warn(`Computed votes for offenses are all zero. Skipping vote.`, {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
-
import { BlockNumber,
|
|
3
|
-
import { merge, pick } from '@aztec/foundation/collection';
|
|
2
|
+
import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { chunkBy, merge, pick } from '@aztec/foundation/collection';
|
|
4
4
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
5
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
6
6
|
import {
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from '@aztec/stdlib/block';
|
|
13
13
|
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
14
14
|
import type {
|
|
15
|
+
ICheckpointBlockBuilder,
|
|
15
16
|
ICheckpointsBuilder,
|
|
16
17
|
ITxProvider,
|
|
17
18
|
MerkleTreeWriteOperations,
|
|
@@ -106,7 +107,7 @@ export class EpochPruneWatcher extends (EventEmitter as new () => WatcherEmitter
|
|
|
106
107
|
{ blocks: epochBlocks.map(b => b.toBlockInfo()) },
|
|
107
108
|
);
|
|
108
109
|
|
|
109
|
-
await this.validateBlocks(epochBlocks);
|
|
110
|
+
await this.validateBlocks(epochBlocks, epochNumber);
|
|
110
111
|
this.log.info(`Pruned epoch ${epochNumber} was valid. Want to slash committee for not having it proven.`);
|
|
111
112
|
await this.emitSlashForEpoch(OffenseType.VALID_EPOCH_PRUNED, epochNumber);
|
|
112
113
|
} catch (error) {
|
|
@@ -121,19 +122,32 @@ export class EpochPruneWatcher extends (EventEmitter as new () => WatcherEmitter
|
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
public async validateBlocks(blocks: L2Block[]): Promise<void> {
|
|
125
|
+
public async validateBlocks(blocks: L2Block[], epochNumber: EpochNumber): Promise<void> {
|
|
125
126
|
if (blocks.length === 0) {
|
|
126
127
|
return;
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
|
|
130
|
-
const
|
|
130
|
+
// Sort blocks by block number and group by checkpoint
|
|
131
|
+
const sortedBlocks = [...blocks].sort((a, b) => a.number - b.number);
|
|
132
|
+
const blocksByCheckpoint = chunkBy(sortedBlocks, b => b.checkpointNumber);
|
|
133
|
+
|
|
134
|
+
// Get prior checkpoints in the epoch (in case this was a partial prune) to extract the out hashes
|
|
135
|
+
const priorCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(epochNumber))
|
|
136
|
+
.filter(c => c.checkpointNumber < sortedBlocks[0].checkpointNumber)
|
|
137
|
+
.map(c => c.checkpointOutHash);
|
|
138
|
+
let previousCheckpointOutHashes: Fr[] = [...priorCheckpointOutHashes];
|
|
139
|
+
|
|
140
|
+
const fork = await this.checkpointsBuilder.getFork(
|
|
141
|
+
BlockNumber(sortedBlocks[0].header.globalVariables.blockNumber - 1),
|
|
142
|
+
);
|
|
131
143
|
try {
|
|
132
|
-
for (const
|
|
133
|
-
await this.
|
|
144
|
+
for (const checkpointBlocks of blocksByCheckpoint) {
|
|
145
|
+
await this.validateCheckpoint(checkpointBlocks, previousCheckpointOutHashes, fork);
|
|
134
146
|
|
|
135
|
-
//
|
|
136
|
-
const checkpointOutHash = computeCheckpointOutHash(
|
|
147
|
+
// Compute checkpoint out hash from all blocks in this checkpoint
|
|
148
|
+
const checkpointOutHash = computeCheckpointOutHash(
|
|
149
|
+
checkpointBlocks.map(b => b.body.txEffects.map(tx => tx.l2ToL1Msgs)),
|
|
150
|
+
);
|
|
137
151
|
previousCheckpointOutHashes = [...previousCheckpointOutHashes, checkpointOutHash];
|
|
138
152
|
}
|
|
139
153
|
} finally {
|
|
@@ -141,45 +155,66 @@ export class EpochPruneWatcher extends (EventEmitter as new () => WatcherEmitter
|
|
|
141
155
|
}
|
|
142
156
|
}
|
|
143
157
|
|
|
144
|
-
|
|
145
|
-
|
|
158
|
+
private async validateCheckpoint(
|
|
159
|
+
checkpointBlocks: L2Block[],
|
|
146
160
|
previousCheckpointOutHashes: Fr[],
|
|
147
161
|
fork: MerkleTreeWriteOperations,
|
|
148
162
|
): Promise<void> {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
// We load txs from the mempool directly, since the TxCollector running in the background has already been
|
|
152
|
-
// trying to fetch them from nodes or via reqresp. If we haven't managed to collect them by now,
|
|
153
|
-
// it's likely that they are not available in the network at all.
|
|
154
|
-
const { txs, missingTxs } = await this.txProvider.getAvailableTxs(txHashes);
|
|
155
|
-
|
|
156
|
-
if (missingTxs && missingTxs.length > 0) {
|
|
157
|
-
throw new TransactionsNotAvailableError(missingTxs);
|
|
158
|
-
}
|
|
163
|
+
const checkpointNumber = checkpointBlocks[0].checkpointNumber;
|
|
164
|
+
this.log.debug(`Validating pruned checkpoint ${checkpointNumber} with ${checkpointBlocks.length} blocks`);
|
|
159
165
|
|
|
160
|
-
|
|
166
|
+
// Get L1ToL2Messages once for the entire checkpoint
|
|
161
167
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
162
|
-
|
|
168
|
+
|
|
169
|
+
// Build checkpoint constants from first block's global variables
|
|
170
|
+
const gv = checkpointBlocks[0].header.globalVariables;
|
|
163
171
|
const constants: CheckpointGlobalVariables = {
|
|
164
172
|
chainId: gv.chainId,
|
|
165
173
|
version: gv.version,
|
|
166
174
|
slotNumber: gv.slotNumber,
|
|
175
|
+
timestamp: gv.timestamp,
|
|
167
176
|
coinbase: gv.coinbase,
|
|
168
177
|
feeRecipient: gv.feeRecipient,
|
|
169
178
|
gasFees: gv.gasFees,
|
|
170
179
|
};
|
|
171
180
|
|
|
172
|
-
//
|
|
181
|
+
// Start checkpoint builder once for all blocks in this checkpoint
|
|
173
182
|
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(
|
|
174
183
|
checkpointNumber,
|
|
175
184
|
constants,
|
|
185
|
+
0n, // feeAssetPriceModifier is not used for validation of the checkpoint content
|
|
176
186
|
l1ToL2Messages,
|
|
177
187
|
previousCheckpointOutHashes,
|
|
178
188
|
fork,
|
|
179
189
|
this.log.getBindings(),
|
|
180
190
|
);
|
|
181
191
|
|
|
182
|
-
|
|
192
|
+
// Validate all blocks in the checkpoint sequentially
|
|
193
|
+
for (const block of checkpointBlocks) {
|
|
194
|
+
await this.validateBlockInCheckpoint(block, checkpointBuilder);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
private async validateBlockInCheckpoint(
|
|
199
|
+
blockFromL1: L2Block,
|
|
200
|
+
checkpointBuilder: ICheckpointBlockBuilder,
|
|
201
|
+
): Promise<void> {
|
|
202
|
+
this.log.debug(`Validating pruned block ${blockFromL1.header.globalVariables.blockNumber}`);
|
|
203
|
+
const txHashes = blockFromL1.body.txEffects.map(txEffect => txEffect.txHash);
|
|
204
|
+
// We load txs from the mempool directly, since the TxCollector running in the background has already been
|
|
205
|
+
// trying to fetch them from nodes or via reqresp. If we haven't managed to collect them by now,
|
|
206
|
+
// it's likely that they are not available in the network at all.
|
|
207
|
+
const { txs, missingTxs } = await this.txProvider.getAvailableTxs(txHashes);
|
|
208
|
+
|
|
209
|
+
if (missingTxs && missingTxs.length > 0) {
|
|
210
|
+
throw new TransactionsNotAvailableError(missingTxs);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const gv = blockFromL1.header.globalVariables;
|
|
214
|
+
const { block, failedTxs, numTxs } = await checkpointBuilder.buildBlock(txs, gv.blockNumber, gv.timestamp, {
|
|
215
|
+
isBuildingProposal: false,
|
|
216
|
+
minValidTxs: 0,
|
|
217
|
+
});
|
|
183
218
|
|
|
184
219
|
if (numTxs !== txs.length) {
|
|
185
220
|
// This should be detected by state mismatch, but this makes it easier to debug.
|