@aztec/slasher 0.0.1-commit.d431d1c → 0.0.1-commit.d58ff9d0

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.
Files changed (95) hide show
  1. package/README.md +90 -76
  2. package/dest/config.d.ts +1 -1
  3. package/dest/config.d.ts.map +1 -1
  4. package/dest/config.js +41 -29
  5. package/dest/factory/create_facade.d.ts +3 -3
  6. package/dest/factory/create_facade.d.ts.map +1 -1
  7. package/dest/factory/create_facade.js +26 -3
  8. package/dest/factory/create_implementation.d.ts +6 -7
  9. package/dest/factory/create_implementation.d.ts.map +1 -1
  10. package/dest/factory/create_implementation.js +8 -56
  11. package/dest/factory/get_settings.d.ts +4 -4
  12. package/dest/factory/get_settings.d.ts.map +1 -1
  13. package/dest/factory/get_settings.js +3 -3
  14. package/dest/factory/index.d.ts +2 -2
  15. package/dest/factory/index.d.ts.map +1 -1
  16. package/dest/factory/index.js +1 -1
  17. package/dest/generated/slasher-defaults.d.ts +8 -6
  18. package/dest/generated/slasher-defaults.d.ts.map +1 -1
  19. package/dest/generated/slasher-defaults.js +7 -5
  20. package/dest/index.d.ts +6 -4
  21. package/dest/index.d.ts.map +1 -1
  22. package/dest/index.js +5 -3
  23. package/dest/metrics.d.ts +7 -0
  24. package/dest/metrics.d.ts.map +1 -0
  25. package/dest/metrics.js +11 -0
  26. package/dest/null_slasher_client.d.ts +3 -4
  27. package/dest/null_slasher_client.d.ts.map +1 -1
  28. package/dest/null_slasher_client.js +1 -4
  29. package/dest/slash_offenses_collector.d.ts +10 -9
  30. package/dest/slash_offenses_collector.d.ts.map +1 -1
  31. package/dest/slash_offenses_collector.js +50 -30
  32. package/dest/{tally_slasher_client.d.ts → slasher_client.d.ts} +17 -28
  33. package/dest/slasher_client.d.ts.map +1 -0
  34. package/dest/{tally_slasher_client.js → slasher_client.js} +55 -45
  35. package/dest/slasher_client_facade.d.ts +6 -8
  36. package/dest/slasher_client_facade.d.ts.map +1 -1
  37. package/dest/slasher_client_facade.js +6 -9
  38. package/dest/slasher_client_interface.d.ts +7 -21
  39. package/dest/slasher_client_interface.d.ts.map +1 -1
  40. package/dest/slasher_client_interface.js +1 -4
  41. package/dest/stores/offenses_store.d.ts +12 -12
  42. package/dest/stores/offenses_store.d.ts.map +1 -1
  43. package/dest/stores/offenses_store.js +64 -39
  44. package/dest/watcher.d.ts +8 -1
  45. package/dest/watcher.d.ts.map +1 -1
  46. package/dest/watcher.js +1 -0
  47. package/dest/watchers/attestations_block_watcher.d.ts +26 -13
  48. package/dest/watchers/attestations_block_watcher.d.ts.map +1 -1
  49. package/dest/watchers/attestations_block_watcher.js +76 -61
  50. package/dest/watchers/attested_invalid_proposal_watcher.d.ts +42 -0
  51. package/dest/watchers/attested_invalid_proposal_watcher.d.ts.map +1 -0
  52. package/dest/watchers/attested_invalid_proposal_watcher.js +117 -0
  53. package/dest/watchers/broadcasted_invalid_checkpoint_proposal_watcher.d.ts +38 -0
  54. package/dest/watchers/broadcasted_invalid_checkpoint_proposal_watcher.d.ts.map +1 -0
  55. package/dest/watchers/broadcasted_invalid_checkpoint_proposal_watcher.js +138 -0
  56. package/dest/watchers/checkpoint_equivocation_watcher.d.ts +30 -0
  57. package/dest/watchers/checkpoint_equivocation_watcher.d.ts.map +1 -0
  58. package/dest/watchers/checkpoint_equivocation_watcher.js +69 -0
  59. package/dest/watchers/data_withholding_watcher.d.ts +63 -0
  60. package/dest/watchers/data_withholding_watcher.d.ts.map +1 -0
  61. package/dest/watchers/data_withholding_watcher.js +193 -0
  62. package/package.json +10 -10
  63. package/src/config.ts +48 -29
  64. package/src/factory/create_facade.ts +33 -5
  65. package/src/factory/create_implementation.ts +24 -105
  66. package/src/factory/get_settings.ts +8 -8
  67. package/src/factory/index.ts +1 -1
  68. package/src/generated/slasher-defaults.ts +7 -5
  69. package/src/index.ts +5 -3
  70. package/src/metrics.ts +19 -0
  71. package/src/null_slasher_client.ts +2 -6
  72. package/src/slash_offenses_collector.ts +70 -32
  73. package/src/{tally_slasher_client.ts → slasher_client.ts} +72 -54
  74. package/src/slasher_client_facade.ts +6 -11
  75. package/src/slasher_client_interface.ts +6 -21
  76. package/src/stores/offenses_store.ts +76 -48
  77. package/src/watcher.ts +8 -0
  78. package/src/watchers/attestations_block_watcher.ts +88 -82
  79. package/src/watchers/attested_invalid_proposal_watcher.ts +168 -0
  80. package/src/watchers/broadcasted_invalid_checkpoint_proposal_watcher.ts +192 -0
  81. package/src/watchers/checkpoint_equivocation_watcher.ts +96 -0
  82. package/src/watchers/data_withholding_watcher.ts +225 -0
  83. package/dest/empire_slasher_client.d.ts +0 -190
  84. package/dest/empire_slasher_client.d.ts.map +0 -1
  85. package/dest/empire_slasher_client.js +0 -572
  86. package/dest/stores/payloads_store.d.ts +0 -29
  87. package/dest/stores/payloads_store.d.ts.map +0 -1
  88. package/dest/stores/payloads_store.js +0 -125
  89. package/dest/tally_slasher_client.d.ts.map +0 -1
  90. package/dest/watchers/epoch_prune_watcher.d.ts +0 -38
  91. package/dest/watchers/epoch_prune_watcher.d.ts.map +0 -1
  92. package/dest/watchers/epoch_prune_watcher.js +0 -158
  93. package/src/empire_slasher_client.ts +0 -657
  94. package/src/stores/payloads_store.ts +0 -146
  95. package/src/watchers/epoch_prune_watcher.ts +0 -220
@@ -1,125 +0,0 @@
1
- import { deserializeSlashPayload, serializeSlashPayload } from '@aztec/stdlib/slashing';
2
- export class SlasherPayloadsStore {
3
- kvStore;
4
- settings;
5
- /** Map from payload address to payload data */ payloads;
6
- /** Map from `round:payload` to votes */ roundPayloadVotes;
7
- constructor(kvStore, settings){
8
- this.kvStore = kvStore;
9
- this.settings = settings;
10
- this.payloads = kvStore.openMap('slash-payloads');
11
- this.roundPayloadVotes = kvStore.openMap('round-payload-votes');
12
- }
13
- async getPayloadsForRound(round) {
14
- const payloads = [];
15
- const votes = await this.getVotesForRound(round);
16
- for (const [address, votesCount] of votes){
17
- const payload = await this.getPayload(address);
18
- if (payload) {
19
- payloads.push({
20
- ...payload,
21
- votes: votesCount,
22
- round
23
- });
24
- }
25
- }
26
- return payloads;
27
- }
28
- async getPayloadAtRound(payloadAddress, round) {
29
- const address = payloadAddress.toString();
30
- const buffer = await this.payloads.getAsync(address);
31
- if (!buffer) {
32
- return undefined;
33
- }
34
- const data = deserializeSlashPayload(buffer);
35
- const votes = await this.roundPayloadVotes.getAsync(this.getPayloadVotesKey(round, address)) ?? 0n;
36
- return {
37
- ...data,
38
- votes,
39
- round
40
- };
41
- }
42
- async getVotesForRound(round) {
43
- const votes = [];
44
- for await (const [fullKey, roundVotes] of this.roundPayloadVotes.entriesAsync(this.getPayloadVotesKeyRangeForRound(round))){
45
- // Extract just the address part from the key (remove "round:" prefix)
46
- const address = fullKey.split(':')[1];
47
- votes.push([
48
- address,
49
- roundVotes
50
- ]);
51
- }
52
- return votes;
53
- }
54
- getRoundKey(round) {
55
- return round.toString().padStart(16, '0');
56
- }
57
- getPayloadVotesKey(round, payloadAddress) {
58
- return `${this.getRoundKey(round)}:${payloadAddress.toString()}`;
59
- }
60
- getPayloadVotesKeyRangeForRound(round) {
61
- const start = `${this.getRoundKey(round)}:`;
62
- const end = `${this.getRoundKey(round)}:Z`; // 'Z' sorts after any hex address, 0x-prefixed or not
63
- return {
64
- start,
65
- end
66
- };
67
- }
68
- /**
69
- * Purge vote payload data for expired rounds. Does not delete actual payload data.
70
- */ async clearExpiredPayloads(currentRound) {
71
- const lifetimeInRounds = this.settings?.slashingPayloadLifetimeInRounds ?? 0;
72
- if (lifetimeInRounds <= 0) {
73
- return; // No lifetime configured
74
- }
75
- const expiredBefore = currentRound - BigInt(lifetimeInRounds);
76
- if (expiredBefore < 0) {
77
- return; // Not enough rounds have passed to expire anything
78
- }
79
- // Collect expired payload votes by scanning round-payload keys
80
- const expiredPayloads = [];
81
- const expiredVoteKeys = [];
82
- for await (const key of this.roundPayloadVotes.keysAsync({
83
- end: `${this.getRoundKey(expiredBefore)}:Z`
84
- })){
85
- const [roundStr, payloadAddress] = key.split(':');
86
- if (BigInt(roundStr) <= expiredBefore) {
87
- expiredVoteKeys.push(key);
88
- expiredPayloads.push(payloadAddress);
89
- }
90
- }
91
- if (expiredVoteKeys.length === 0) {
92
- return; // No expired payloads to clean up
93
- }
94
- // Remove expired payload vote records
95
- // Note that we do not delete payload data since these could be repurposed in future votes
96
- await this.kvStore.transactionAsync(async ()=>{
97
- for (const key of expiredVoteKeys){
98
- await this.roundPayloadVotes.delete(key);
99
- }
100
- });
101
- }
102
- async incrementPayloadVotes(payloadAddress, round) {
103
- const key = this.getPayloadVotesKey(round, payloadAddress);
104
- const currentVotes = await this.roundPayloadVotes.getAsync(key) || 0n;
105
- const newVotes = currentVotes + 1n;
106
- await this.roundPayloadVotes.set(key, newVotes);
107
- return newVotes;
108
- }
109
- async addPayload(payload) {
110
- const address = payload.address.toString();
111
- await this.kvStore.transactionAsync(async ()=>{
112
- await this.payloads.set(address, serializeSlashPayload(payload));
113
- await this.roundPayloadVotes.set(this.getPayloadVotesKey(payload.round, address), payload.votes);
114
- });
115
- }
116
- async getPayload(payloadAddress) {
117
- const address = payloadAddress.toString();
118
- const buffer = await this.payloads.getAsync(address);
119
- return buffer ? deserializeSlashPayload(buffer) : undefined;
120
- }
121
- async hasPayload(payload) {
122
- const address = payload.toString();
123
- return await this.payloads.getAsync(address) !== undefined;
124
- }
125
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"tally_slasher_client.d.ts","sourceRoot":"","sources":["../src/tally_slasher_client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE3G,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAI7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;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,EAAE,UAAU,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAqFtG;IAED,mFAAmF;IACnF,OAAO,CAAC,kCAAkC;IAQ1C;;;OAGG;IACI,gBAAgB,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAEtD;IAED;;;;;OAKG;IACU,sBAAsB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAOtE;IAED,0CAA0C;IACnC,kBAAkB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,CAE9C;IAED;;;;;;;OAOG;IACH,OAAO,CAAC,eAAe;CAIxB"}
@@ -1,38 +0,0 @@
1
- import { EpochCache } from '@aztec/epoch-cache';
2
- import type { Fr } from '@aztec/foundation/curves/bn254';
3
- import { L2BlockNew, type L2BlockSourceEventEmitter } from '@aztec/stdlib/block';
4
- import type { ICheckpointsBuilder, ITxProvider, MerkleTreeWriteOperations, SlasherConfig } from '@aztec/stdlib/interfaces/server';
5
- import { type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
6
- import { type Watcher, type WatcherEmitter } from '../watcher.js';
7
- declare const EpochPruneWatcherPenaltiesConfigKeys: readonly ["slashPrunePenalty", "slashDataWithholdingPenalty"];
8
- type EpochPruneWatcherPenalties = Pick<SlasherConfig, (typeof EpochPruneWatcherPenaltiesConfigKeys)[number]>;
9
- declare const EpochPruneWatcher_base: new () => WatcherEmitter;
10
- /**
11
- * This watcher is responsible for detecting chain prunes and creating slashing arguments for the committee.
12
- * It only wants to slash if:
13
- * - the transactions are not available
14
- * - OR the archive roots match when re-building all the blocks in the epoch (i.e. the epoch *could* have been proven)
15
- */
16
- export declare class EpochPruneWatcher extends EpochPruneWatcher_base implements Watcher {
17
- private l2BlockSource;
18
- private l1ToL2MessageSource;
19
- private epochCache;
20
- private txProvider;
21
- private checkpointsBuilder;
22
- private log;
23
- private boundHandlePruneL2Blocks;
24
- private penalties;
25
- constructor(l2BlockSource: L2BlockSourceEventEmitter, l1ToL2MessageSource: L1ToL2MessageSource, epochCache: EpochCache, txProvider: Pick<ITxProvider, 'getAvailableTxs'>, checkpointsBuilder: ICheckpointsBuilder, penalties: EpochPruneWatcherPenalties);
26
- start(): Promise<void>;
27
- stop(): Promise<void>;
28
- updateConfig(config: Partial<SlasherConfig>): void;
29
- private handlePruneL2Blocks;
30
- private emitSlashForEpoch;
31
- private processPruneL2Blocks;
32
- validateBlocks(blocks: L2BlockNew[]): Promise<void>;
33
- validateBlock(blockFromL1: L2BlockNew, previousCheckpointOutHashes: Fr[], fork: MerkleTreeWriteOperations): Promise<void>;
34
- private getValidatorsForEpoch;
35
- private validatorsToSlashingArgs;
36
- }
37
- export {};
38
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXBvY2hfcHJ1bmVfd2F0Y2hlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3dhdGNoZXJzL2Vwb2NoX3BydW5lX3dhdGNoZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLG9CQUFvQixDQUFDO0FBR2hELE9BQU8sS0FBSyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXpELE9BQU8sRUFFTCxVQUFVLEVBQ1YsS0FBSyx5QkFBeUIsRUFHL0IsTUFBTSxxQkFBcUIsQ0FBQztBQUU3QixPQUFPLEtBQUssRUFDVixtQkFBbUIsRUFDbkIsV0FBVyxFQUNYLHlCQUF5QixFQUN6QixhQUFhLEVBQ2QsTUFBTSxpQ0FBaUMsQ0FBQztBQUN6QyxPQUFPLEVBQUUsS0FBSyxtQkFBbUIsRUFBNEIsTUFBTSx5QkFBeUIsQ0FBQztBQVk3RixPQUFPLEVBQTZDLEtBQUssT0FBTyxFQUFFLEtBQUssY0FBYyxFQUFFLE1BQU0sZUFBZSxDQU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ACxC,mBAAmB,EAAE,mBAAmB,EACxC,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,IAAI,CAAC,WAAW,EAAE,iBAAiB,CAAC,EAChD,kBAAkB,EAAE,mBAAmB,EAC/C,SAAS,EAAE,0BAA0B,EAOtC;IAEM,KAAK,kBAGX;IAEM,IAAI,kBAGV;IAEM,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAGxD;IAED,OAAO,CAAC,mBAAmB;YAOb,iBAAiB;YAWjB,oBAAoB;IAwBrB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAkB/D;IAEY,aAAa,CACxB,WAAW,EAAE,UAAU,EACvB,2BAA2B,EAAE,EAAE,EAAE,EACjC,IAAI,EAAE,yBAAyB,GAC9B,OAAO,CAAC,IAAI,CAAC,CA6Cf;YAEa,qBAAqB;IASnC,OAAO,CAAC,wBAAwB;CAgBjC"}
@@ -1,158 +0,0 @@
1
- import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
2
- import { merge, pick } from '@aztec/foundation/collection';
3
- import { createLogger } from '@aztec/foundation/log';
4
- import { L2BlockSourceEvents } from '@aztec/stdlib/block';
5
- import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
6
- import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
7
- import { OffenseType, getOffenseTypeName } from '@aztec/stdlib/slashing';
8
- import { ReExFailedTxsError, ReExStateMismatchError, TransactionsNotAvailableError, ValidatorError } from '@aztec/stdlib/validators';
9
- import EventEmitter from 'node:events';
10
- import { WANT_TO_SLASH_EVENT } from '../watcher.js';
11
- const EpochPruneWatcherPenaltiesConfigKeys = [
12
- 'slashPrunePenalty',
13
- 'slashDataWithholdingPenalty'
14
- ];
15
- /**
16
- * This watcher is responsible for detecting chain prunes and creating slashing arguments for the committee.
17
- * It only wants to slash if:
18
- * - the transactions are not available
19
- * - OR the archive roots match when re-building all the blocks in the epoch (i.e. the epoch *could* have been proven)
20
- */ export class EpochPruneWatcher extends EventEmitter {
21
- l2BlockSource;
22
- l1ToL2MessageSource;
23
- epochCache;
24
- txProvider;
25
- checkpointsBuilder;
26
- log;
27
- // Store bound function reference for proper listener removal
28
- boundHandlePruneL2Blocks;
29
- penalties;
30
- constructor(l2BlockSource, l1ToL2MessageSource, epochCache, txProvider, checkpointsBuilder, penalties){
31
- super(), this.l2BlockSource = l2BlockSource, this.l1ToL2MessageSource = l1ToL2MessageSource, this.epochCache = epochCache, this.txProvider = txProvider, this.checkpointsBuilder = checkpointsBuilder, this.log = createLogger('epoch-prune-watcher'), this.boundHandlePruneL2Blocks = this.handlePruneL2Blocks.bind(this);
32
- this.penalties = pick(penalties, ...EpochPruneWatcherPenaltiesConfigKeys);
33
- this.log.verbose(`EpochPruneWatcher initialized with penalties: valid epoch pruned=${penalties.slashPrunePenalty} data withholding=${penalties.slashDataWithholdingPenalty}`);
34
- }
35
- start() {
36
- this.l2BlockSource.events.on(L2BlockSourceEvents.L2PruneUnproven, this.boundHandlePruneL2Blocks);
37
- return Promise.resolve();
38
- }
39
- stop() {
40
- this.l2BlockSource.events.removeListener(L2BlockSourceEvents.L2PruneUnproven, this.boundHandlePruneL2Blocks);
41
- return Promise.resolve();
42
- }
43
- updateConfig(config) {
44
- this.penalties = merge(this.penalties, pick(config, ...EpochPruneWatcherPenaltiesConfigKeys));
45
- this.log.verbose('EpochPruneWatcher config updated', this.penalties);
46
- }
47
- handlePruneL2Blocks(event) {
48
- const { blocks, epochNumber } = event;
49
- void this.processPruneL2Blocks(blocks, epochNumber).catch((err)=>this.log.error('Error processing pruned L2 blocks', err, {
50
- epochNumber
51
- }));
52
- }
53
- async emitSlashForEpoch(offense, epochNumber) {
54
- const validators = await this.getValidatorsForEpoch(epochNumber);
55
- if (validators.length === 0) {
56
- this.log.warn(`No validators found for epoch ${epochNumber} (cannot slash for ${getOffenseTypeName(offense)})`);
57
- return;
58
- }
59
- const args = this.validatorsToSlashingArgs(validators, offense, epochNumber);
60
- this.log.verbose(`Created slash for ${getOffenseTypeName(offense)} at epoch ${epochNumber}`, args);
61
- this.emit(WANT_TO_SLASH_EVENT, args);
62
- }
63
- async processPruneL2Blocks(blocks, epochNumber) {
64
- try {
65
- const l1Constants = this.epochCache.getL1Constants();
66
- const epochBlocks = blocks.filter((b)=>getEpochAtSlot(b.header.getSlot(), l1Constants) === epochNumber);
67
- this.log.info(`Detected chain prune. Validating epoch ${epochNumber} with blocks ${epochBlocks[0]?.number} to ${epochBlocks[epochBlocks.length - 1]?.number}.`, {
68
- blocks: epochBlocks.map((b)=>b.toBlockInfo())
69
- });
70
- await this.validateBlocks(epochBlocks);
71
- this.log.info(`Pruned epoch ${epochNumber} was valid. Want to slash committee for not having it proven.`);
72
- await this.emitSlashForEpoch(OffenseType.VALID_EPOCH_PRUNED, epochNumber);
73
- } catch (error) {
74
- if (error instanceof TransactionsNotAvailableError) {
75
- this.log.info(`Data for pruned epoch ${epochNumber} was not available. Will want to slash.`, {
76
- message: error.message
77
- });
78
- await this.emitSlashForEpoch(OffenseType.DATA_WITHHOLDING, epochNumber);
79
- } else {
80
- this.log.error(`Error while validating pruned epoch ${epochNumber}. Will not want to slash.`, error);
81
- }
82
- }
83
- }
84
- async validateBlocks(blocks) {
85
- if (blocks.length === 0) {
86
- return;
87
- }
88
- let previousCheckpointOutHashes = [];
89
- const fork = await this.checkpointsBuilder.getFork(BlockNumber(blocks[0].header.globalVariables.blockNumber - 1));
90
- try {
91
- for (const block of blocks){
92
- await this.validateBlock(block, previousCheckpointOutHashes, fork);
93
- // TODO(mbps): This assumes one block per checkpoint, which is only true for now.
94
- const checkpointOutHash = computeCheckpointOutHash([
95
- block.body.txEffects.map((tx)=>tx.l2ToL1Msgs)
96
- ]);
97
- previousCheckpointOutHashes = [
98
- ...previousCheckpointOutHashes,
99
- checkpointOutHash
100
- ];
101
- }
102
- } finally{
103
- await fork.close();
104
- }
105
- }
106
- async validateBlock(blockFromL1, previousCheckpointOutHashes, fork) {
107
- this.log.debug(`Validating pruned block ${blockFromL1.header.globalVariables.blockNumber}`);
108
- const txHashes = blockFromL1.body.txEffects.map((txEffect)=>txEffect.txHash);
109
- // We load txs from the mempool directly, since the TxCollector running in the background has already been
110
- // trying to fetch them from nodes or via reqresp. If we haven't managed to collect them by now,
111
- // it's likely that they are not available in the network at all.
112
- const { txs, missingTxs } = await this.txProvider.getAvailableTxs(txHashes);
113
- if (missingTxs && missingTxs.length > 0) {
114
- throw new TransactionsNotAvailableError(missingTxs);
115
- }
116
- const checkpointNumber = CheckpointNumber.fromBlockNumber(blockFromL1.number);
117
- const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
118
- const gv = blockFromL1.header.globalVariables;
119
- const constants = {
120
- chainId: gv.chainId,
121
- version: gv.version,
122
- slotNumber: gv.slotNumber,
123
- coinbase: gv.coinbase,
124
- feeRecipient: gv.feeRecipient,
125
- gasFees: gv.gasFees
126
- };
127
- // Use checkpoint builder to validate the block
128
- const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(checkpointNumber, constants, l1ToL2Messages, previousCheckpointOutHashes, fork);
129
- const { block, failedTxs, numTxs } = await checkpointBuilder.buildBlock(txs, gv.blockNumber, gv.timestamp, {});
130
- if (numTxs !== txs.length) {
131
- // This should be detected by state mismatch, but this makes it easier to debug.
132
- throw new ValidatorError(`Built block with ${numTxs} txs, expected ${txs.length}`);
133
- }
134
- if (failedTxs.length > 0) {
135
- throw new ReExFailedTxsError(failedTxs.length);
136
- }
137
- if (!block.archive.root.equals(blockFromL1.archive.root)) {
138
- throw new ReExStateMismatchError(blockFromL1.archive.root, block.archive.root);
139
- }
140
- }
141
- async getValidatorsForEpoch(epochNumber) {
142
- const { committee } = await this.epochCache.getCommitteeForEpoch(epochNumber);
143
- if (!committee) {
144
- this.log.trace(`No committee found for epoch ${epochNumber}`);
145
- return [];
146
- }
147
- return committee;
148
- }
149
- validatorsToSlashingArgs(validators, offenseType, epochOrSlot) {
150
- const penalty = offenseType === OffenseType.DATA_WITHHOLDING ? this.penalties.slashDataWithholdingPenalty : this.penalties.slashPrunePenalty;
151
- return validators.map((v)=>({
152
- validator: v,
153
- amount: penalty,
154
- offenseType,
155
- epochOrSlot: BigInt(epochOrSlot)
156
- }));
157
- }
158
- }