@aztec/sequencer-client 0.87.2 → 0.87.3-nightly.20250528

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 (37) hide show
  1. package/dest/client/sequencer-client.d.ts +2 -1
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +3 -0
  4. package/dest/global_variable_builder/global_builder.d.ts +4 -1
  5. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  6. package/dest/global_variable_builder/global_builder.js +14 -2
  7. package/dest/index.d.ts +1 -2
  8. package/dest/index.d.ts.map +1 -1
  9. package/dest/index.js +1 -2
  10. package/dest/publisher/sequencer-publisher.d.ts +4 -4
  11. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  12. package/dest/publisher/sequencer-publisher.js +14 -6
  13. package/dest/sequencer/sequencer.d.ts +5 -12
  14. package/dest/sequencer/sequencer.d.ts.map +1 -1
  15. package/dest/sequencer/sequencer.js +26 -34
  16. package/dest/sequencer/utils.d.ts +2 -2
  17. package/dest/sequencer/utils.d.ts.map +1 -1
  18. package/dest/sequencer/utils.js +6 -4
  19. package/package.json +26 -25
  20. package/src/client/sequencer-client.ts +5 -1
  21. package/src/global_variable_builder/global_builder.ts +16 -2
  22. package/src/index.ts +1 -2
  23. package/src/publisher/sequencer-publisher.ts +22 -13
  24. package/src/sequencer/sequencer.ts +32 -42
  25. package/src/sequencer/utils.ts +14 -6
  26. package/dest/slasher/factory.d.ts +0 -7
  27. package/dest/slasher/factory.d.ts.map +0 -1
  28. package/dest/slasher/factory.js +0 -8
  29. package/dest/slasher/index.d.ts +0 -3
  30. package/dest/slasher/index.d.ts.map +0 -1
  31. package/dest/slasher/index.js +0 -2
  32. package/dest/slasher/slasher_client.d.ts +0 -75
  33. package/dest/slasher/slasher_client.d.ts.map +0 -1
  34. package/dest/slasher/slasher_client.js +0 -135
  35. package/src/slasher/factory.ts +0 -15
  36. package/src/slasher/index.ts +0 -2
  37. package/src/slasher/slasher_client.ts +0 -199
@@ -1,199 +0,0 @@
1
- import {
2
- type L1ContractsConfig,
3
- type L1ReaderConfig,
4
- type ViemPublicClient,
5
- createEthereumChain,
6
- } from '@aztec/ethereum';
7
- import { EthAddress } from '@aztec/foundation/eth-address';
8
- import { createLogger } from '@aztec/foundation/log';
9
- import { SlashFactoryAbi } from '@aztec/l1-artifacts';
10
- import {
11
- type L2BlockId,
12
- type L2BlockSourceEvent,
13
- type L2BlockSourceEventEmitter,
14
- L2BlockSourceEvents,
15
- } from '@aztec/stdlib/block';
16
- import { type TelemetryClient, WithTracer, getTelemetryClient } from '@aztec/telemetry-client';
17
-
18
- import { type GetContractReturnType, createPublicClient, fallback, getAddress, getContract, http } from 'viem';
19
-
20
- /**
21
- * Enum defining the possible states of the Slasher client.
22
- */
23
- export enum SlasherClientState {
24
- IDLE,
25
- RUNNING,
26
- STOPPED,
27
- }
28
-
29
- /**
30
- * The synchronization status of the Slasher client.
31
- */
32
- export interface SlasherSyncState {
33
- /**
34
- * The current state of the slasher client.
35
- */
36
- state: SlasherClientState;
37
- /**
38
- * The block number that the slasher client is synced to.
39
- */
40
- syncedToL2Block: L2BlockId;
41
- }
42
-
43
- export interface SlasherConfig {
44
- blockCheckIntervalMS: number;
45
- blockRequestBatchSize: number;
46
- }
47
-
48
- type SlashEvent = {
49
- epoch: bigint;
50
- amount: bigint;
51
- lifetime: bigint;
52
- };
53
-
54
- /**
55
- * @notice A Hypomeiones slasher client implementation
56
- *
57
- * Hypomeiones: a class of individuals in ancient Sparta who were considered inferior or lesser citizens compared
58
- * to the full Spartan citizens.
59
- *
60
- * The implementation here is less than ideal. It exists, not to be the end all be all, but to show that
61
- * slashing can be done with this mechanism.
62
- *
63
- * The implementation is VERY brute in the sense that it only looks for pruned blocks and then tries to slash
64
- * the full committee of that.
65
- * If it sees a prune, it will mark the full epoch as "to be slashed".
66
- *
67
- * Also, it is not particularly smart around what it should if there were to be multiple slashing events.
68
- *
69
- * A few improvements:
70
- * - Only vote on the proposal if it is possible to reach, e.g., if 6 votes are needed and only 4 slots are left don't vote.
71
- * - Stop voting on a payload once it is processed.
72
- * - Only vote on the proposal if it have not already been executed
73
- * - Caveat, we need to fully decide if it is acceptable to have the same payload address multiple times. In the current
74
- * slash factory that could mean slashing the same committee for the same error multiple times.
75
- * - Decide how to deal with multiple slashing events in the same round.
76
- * - This could be that multiple epochs are pruned in the same round, but with the current naive implementation we could end up
77
- * slashing only the first, because the "lifetime" of the second would have passed after that vote
78
- */
79
- export class SlasherClient extends WithTracer {
80
- private slashEvents: SlashEvent[] = [];
81
-
82
- protected slashFactoryContract?: GetContractReturnType<typeof SlashFactoryAbi, ViemPublicClient> = undefined;
83
-
84
- // The amount to slash for a prune.
85
- // Note that we set it to 0, such that no actual slashing will happen, but the event will be fired,
86
- // showing that the slashing mechanism is working.
87
- private slashingAmount: bigint = 0n;
88
-
89
- constructor(
90
- private config: SlasherConfig & L1ContractsConfig & L1ReaderConfig,
91
- private l2BlockSource: L2BlockSourceEventEmitter,
92
- telemetry: TelemetryClient = getTelemetryClient(),
93
- private log = createLogger('slasher'),
94
- ) {
95
- super(telemetry, 'slasher');
96
-
97
- if (config.l1Contracts.slashFactoryAddress && !config.l1Contracts.slashFactoryAddress.equals(EthAddress.ZERO)) {
98
- const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
99
- const publicClient = createPublicClient({
100
- chain: chain.chainInfo,
101
- transport: fallback(chain.rpcUrls.map(url => http(url))),
102
- pollingInterval: config.viemPollingIntervalMS,
103
- });
104
-
105
- this.slashFactoryContract = getContract({
106
- address: getAddress(config.l1Contracts.slashFactoryAddress.toString()),
107
- abi: SlashFactoryAbi,
108
- client: publicClient,
109
- });
110
- } else {
111
- this.log.warn('No slash factory address found, slashing will not be enabled');
112
- }
113
-
114
- this.log.info(`Slasher client initialized`);
115
- }
116
-
117
- public start() {
118
- this.log.info('Starting Slasher client...');
119
- this.l2BlockSource.on(L2BlockSourceEvents.L2PruneDetected, this.handlePruneL2Blocks.bind(this));
120
- }
121
-
122
- // This is where we should put a bunch of the improvements mentioned earlier.
123
- public async getSlashPayload(slotNumber: bigint): Promise<EthAddress | undefined> {
124
- if (!this.slashFactoryContract) {
125
- return undefined;
126
- }
127
-
128
- // As long as the slot is greater than the lifetime, we want to keep deleting the first element
129
- // since it will not make sense to include anymore.
130
- while (this.slashEvents.length > 0 && this.slashEvents[0].lifetime < slotNumber) {
131
- this.slashEvents.shift();
132
- }
133
-
134
- if (this.slashEvents.length == 0) {
135
- return undefined;
136
- }
137
-
138
- const slashEvent = this.slashEvents[0];
139
-
140
- const [payloadAddress, isDeployed] = await this.slashFactoryContract.read.getAddressAndIsDeployed([
141
- slashEvent.epoch,
142
- slashEvent.amount,
143
- ]);
144
-
145
- if (!isDeployed) {
146
- // The proposal cannot be executed until it is deployed
147
- this.log.verbose(
148
- `Voting on not yet deployed payload for epoch ${slashEvent.epoch} and amount ${slashEvent.amount} at: ${payloadAddress}`,
149
- );
150
- }
151
-
152
- return EthAddress.fromString(payloadAddress);
153
- }
154
-
155
- public handleBlockStreamEvent(event: L2BlockSourceEvent): Promise<void> {
156
- this.log.debug(`Handling block stream event ${event.type}`);
157
- switch (event.type as L2BlockSourceEvents) {
158
- case L2BlockSourceEvents.L2PruneDetected:
159
- this.handlePruneL2Blocks(event);
160
- break;
161
- default: {
162
- break;
163
- }
164
- }
165
- return Promise.resolve();
166
- }
167
-
168
- /**
169
- * Allows consumers to stop the instance of the slasher client.
170
- * 'ready' will now return 'false' and the running promise that keeps the client synced is interrupted.
171
- */
172
- public stop() {
173
- this.log.debug('Stopping Slasher client...');
174
- this.l2BlockSource.removeListener(L2BlockSourceEvents.L2PruneDetected, this.handlePruneL2Blocks.bind(this));
175
- this.log.info('Slasher client stopped.');
176
- }
177
-
178
- private handlePruneL2Blocks(event: L2BlockSourceEvent): void {
179
- // We do not try to slash if the penalty is 0
180
- if (this.slashingAmount == 0n) {
181
- return;
182
- }
183
-
184
- const { slotNumber, epochNumber } = event;
185
- this.log.info(`Detected chain prune. Punishing the validators at epoch ${epochNumber}`, event);
186
-
187
- // Set the lifetime such that we have a full round that we could vote throughout.
188
- const slotsIntoRound = slotNumber % BigInt(this.config.slashingRoundSize);
189
- const toNext = slotsIntoRound == 0n ? 0n : BigInt(this.config.slashingRoundSize) - slotsIntoRound;
190
-
191
- const lifetime = slotNumber + toNext + BigInt(this.config.slashingRoundSize);
192
-
193
- this.slashEvents.push({
194
- epoch: epochNumber,
195
- amount: this.slashingAmount,
196
- lifetime,
197
- });
198
- }
199
- }