@aztec/sequencer-client 0.0.1-commit.b655e406 → 0.0.1-commit.c7c42ec

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 (102) hide show
  1. package/dest/client/index.d.ts +1 -1
  2. package/dest/client/sequencer-client.d.ts +10 -9
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +32 -24
  5. package/dest/config.d.ts +12 -5
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +75 -28
  8. package/dest/global_variable_builder/global_builder.d.ts +19 -13
  9. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  10. package/dest/global_variable_builder/global_builder.js +41 -28
  11. package/dest/global_variable_builder/index.d.ts +1 -1
  12. package/dest/index.d.ts +2 -2
  13. package/dest/index.d.ts.map +1 -1
  14. package/dest/index.js +1 -1
  15. package/dest/publisher/config.d.ts +9 -4
  16. package/dest/publisher/config.d.ts.map +1 -1
  17. package/dest/publisher/config.js +14 -3
  18. package/dest/publisher/index.d.ts +1 -1
  19. package/dest/publisher/sequencer-publisher-factory.d.ts +5 -4
  20. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  21. package/dest/publisher/sequencer-publisher-factory.js +1 -1
  22. package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
  23. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  24. package/dest/publisher/sequencer-publisher.d.ts +66 -53
  25. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  26. package/dest/publisher/sequencer-publisher.js +230 -120
  27. package/dest/sequencer/block_builder.d.ts +4 -5
  28. package/dest/sequencer/block_builder.d.ts.map +1 -1
  29. package/dest/sequencer/block_builder.js +9 -10
  30. package/dest/sequencer/checkpoint_builder.d.ts +63 -0
  31. package/dest/sequencer/checkpoint_builder.d.ts.map +1 -0
  32. package/dest/sequencer/checkpoint_builder.js +131 -0
  33. package/dest/sequencer/checkpoint_proposal_job.d.ts +74 -0
  34. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  35. package/dest/sequencer/checkpoint_proposal_job.js +642 -0
  36. package/dest/sequencer/checkpoint_voter.d.ts +34 -0
  37. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  38. package/dest/sequencer/checkpoint_voter.js +85 -0
  39. package/dest/sequencer/config.d.ts +3 -2
  40. package/dest/sequencer/config.d.ts.map +1 -1
  41. package/dest/sequencer/errors.d.ts +1 -1
  42. package/dest/sequencer/errors.d.ts.map +1 -1
  43. package/dest/sequencer/events.d.ts +46 -0
  44. package/dest/sequencer/events.d.ts.map +1 -0
  45. package/dest/sequencer/events.js +1 -0
  46. package/dest/sequencer/index.d.ts +5 -1
  47. package/dest/sequencer/index.d.ts.map +1 -1
  48. package/dest/sequencer/index.js +4 -0
  49. package/dest/sequencer/metrics.d.ts +32 -3
  50. package/dest/sequencer/metrics.d.ts.map +1 -1
  51. package/dest/sequencer/metrics.js +192 -0
  52. package/dest/sequencer/sequencer.d.ts +96 -138
  53. package/dest/sequencer/sequencer.d.ts.map +1 -1
  54. package/dest/sequencer/sequencer.js +247 -479
  55. package/dest/sequencer/timetable.d.ts +54 -14
  56. package/dest/sequencer/timetable.d.ts.map +1 -1
  57. package/dest/sequencer/timetable.js +148 -59
  58. package/dest/sequencer/types.d.ts +3 -0
  59. package/dest/sequencer/types.d.ts.map +1 -0
  60. package/dest/sequencer/types.js +1 -0
  61. package/dest/sequencer/utils.d.ts +14 -8
  62. package/dest/sequencer/utils.d.ts.map +1 -1
  63. package/dest/sequencer/utils.js +7 -4
  64. package/dest/test/index.d.ts +4 -2
  65. package/dest/test/index.d.ts.map +1 -1
  66. package/dest/test/mock_checkpoint_builder.d.ts +83 -0
  67. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  68. package/dest/test/mock_checkpoint_builder.js +179 -0
  69. package/dest/test/utils.d.ts +49 -0
  70. package/dest/test/utils.d.ts.map +1 -0
  71. package/dest/test/utils.js +94 -0
  72. package/dest/tx_validator/nullifier_cache.d.ts +1 -1
  73. package/dest/tx_validator/nullifier_cache.d.ts.map +1 -1
  74. package/dest/tx_validator/tx_validator_factory.d.ts +4 -3
  75. package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -1
  76. package/dest/tx_validator/tx_validator_factory.js +1 -1
  77. package/package.json +31 -30
  78. package/src/client/sequencer-client.ts +28 -38
  79. package/src/config.ts +81 -32
  80. package/src/global_variable_builder/global_builder.ts +56 -48
  81. package/src/index.ts +2 -0
  82. package/src/publisher/config.ts +20 -9
  83. package/src/publisher/sequencer-publisher-factory.ts +7 -5
  84. package/src/publisher/sequencer-publisher-metrics.ts +2 -2
  85. package/src/publisher/sequencer-publisher.ts +328 -161
  86. package/src/sequencer/README.md +531 -0
  87. package/src/sequencer/block_builder.ts +12 -13
  88. package/src/sequencer/checkpoint_builder.ts +217 -0
  89. package/src/sequencer/checkpoint_proposal_job.ts +706 -0
  90. package/src/sequencer/checkpoint_voter.ts +105 -0
  91. package/src/sequencer/config.ts +2 -1
  92. package/src/sequencer/events.ts +27 -0
  93. package/src/sequencer/index.ts +4 -0
  94. package/src/sequencer/metrics.ts +254 -3
  95. package/src/sequencer/sequencer.ts +360 -674
  96. package/src/sequencer/timetable.ts +173 -79
  97. package/src/sequencer/types.ts +6 -0
  98. package/src/sequencer/utils.ts +18 -9
  99. package/src/test/index.ts +3 -1
  100. package/src/test/mock_checkpoint_builder.ts +247 -0
  101. package/src/test/utils.ts +137 -0
  102. package/src/tx_validator/tx_validator_factory.ts +3 -2
@@ -0,0 +1,105 @@
1
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
2
+ import type { EthAddress } from '@aztec/foundation/eth-address';
3
+ import type { Logger } from '@aztec/foundation/log';
4
+ import type { SlasherClientInterface } from '@aztec/slasher';
5
+ import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
6
+ import type { ResolvedSequencerConfig } from '@aztec/stdlib/interfaces/server';
7
+ import type { ValidatorClient } from '@aztec/validator-client';
8
+
9
+ import type { TypedDataDefinition } from 'viem';
10
+
11
+ import type { SequencerPublisher } from '../publisher/sequencer-publisher.js';
12
+ import type { SequencerMetrics } from './metrics.js';
13
+ import type { SequencerRollupConstants } from './types.js';
14
+
15
+ /**
16
+ * Handles governance and slashing voting for a given slot.
17
+ */
18
+ export class CheckpointVoter {
19
+ private slotTimestamp: bigint;
20
+ private signer: (msg: TypedDataDefinition) => Promise<`0x${string}`>;
21
+
22
+ constructor(
23
+ private readonly slot: SlotNumber,
24
+ private readonly publisher: SequencerPublisher,
25
+ private readonly attestorAddress: EthAddress,
26
+ private readonly validatorClient: ValidatorClient,
27
+ private readonly slasherClient: SlasherClientInterface | undefined,
28
+ private readonly l1Constants: SequencerRollupConstants,
29
+ private readonly config: ResolvedSequencerConfig,
30
+ private readonly metrics: SequencerMetrics,
31
+ private readonly log: Logger,
32
+ ) {
33
+ this.slotTimestamp = getTimestampForSlot(this.slot, this.l1Constants);
34
+ this.signer = (msg: TypedDataDefinition) =>
35
+ this.validatorClient.signWithAddress(this.attestorAddress, msg).then(s => s.toString());
36
+ }
37
+
38
+ /**
39
+ * Enqueues governance and slashing votes with the publisher.
40
+ * Returns a tuple of promises that resolve to whether each vote was successfully enqueued.
41
+ */
42
+ enqueueVotes(): [Promise<boolean | undefined>, Promise<boolean | undefined>] {
43
+ try {
44
+ const enqueueGovernancePromise = this.enqueueGovernanceVote();
45
+ const enqueueSlashingPromise = this.enqueueSlashingVote();
46
+
47
+ return [enqueueGovernancePromise, enqueueSlashingPromise];
48
+ } catch (err) {
49
+ this.log.error(`Error enqueueing governance and slashing votes`, err);
50
+ return [Promise.resolve(false), Promise.resolve(false)];
51
+ }
52
+ }
53
+
54
+ private async enqueueGovernanceVote(): Promise<boolean | undefined> {
55
+ const governanceProposerPayload = this.config.governanceProposerPayload;
56
+ if (!governanceProposerPayload || governanceProposerPayload.isZero()) {
57
+ return undefined;
58
+ }
59
+
60
+ this.log.info(`Enqueuing vote for ${governanceProposerPayload} governance for slot ${this.slot}`, {
61
+ slot: this.slot,
62
+ governanceProposerPayload: governanceProposerPayload.toString(),
63
+ });
64
+
65
+ try {
66
+ return await this.publisher.enqueueGovernanceCastSignal(
67
+ governanceProposerPayload,
68
+ this.slot,
69
+ this.slotTimestamp,
70
+ this.attestorAddress,
71
+ this.signer,
72
+ );
73
+ } catch (err) {
74
+ this.log.error(`Error enqueuing governance vote`, err, { slot: this.slot });
75
+ return false;
76
+ }
77
+ }
78
+
79
+ private async enqueueSlashingVote(): Promise<boolean | undefined> {
80
+ try {
81
+ const actions = await this.slasherClient?.getProposerActions(this.slot);
82
+ if (!actions || actions.length === 0) {
83
+ return undefined;
84
+ }
85
+
86
+ this.log.info(`Enqueuing vote for ${actions.length} slashing actions for slot ${this.slot}`, {
87
+ slot: this.slot,
88
+ actionCount: actions.length,
89
+ });
90
+
91
+ this.metrics.recordSlashingAttempt(actions.length);
92
+
93
+ return await this.publisher.enqueueSlashingActions(
94
+ actions,
95
+ this.slot,
96
+ this.slotTimestamp,
97
+ this.attestorAddress,
98
+ this.signer,
99
+ );
100
+ } catch (err) {
101
+ this.log.error(`Error enqueuing slashing vote`, err, { slot: this.slot });
102
+ return false;
103
+ }
104
+ }
105
+ }
@@ -1,4 +1,5 @@
1
- import type { GovernanceProposerContract, RollupContract } from '@aztec/ethereum';
1
+ import type { GovernanceProposerContract } from '@aztec/ethereum/contracts';
2
+ import type { RollupContract } from '@aztec/ethereum/contracts/rollup';
2
3
 
3
4
  export { type SequencerConfig } from '@aztec/stdlib/config';
4
5
 
@@ -0,0 +1,27 @@
1
+ import type { BlockNumber, CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
+
3
+ import type { Action } from '../publisher/sequencer-publisher.js';
4
+ import type { SequencerState } from './utils.js';
5
+
6
+ export type SequencerEvents = {
7
+ ['state-changed']: (args: {
8
+ oldState: SequencerState;
9
+ newState: SequencerState;
10
+ secondsIntoSlot?: number;
11
+ slot?: SlotNumber;
12
+ }) => void;
13
+ ['proposer-rollup-check-failed']: (args: { reason: string; slot: SlotNumber }) => void;
14
+ ['block-tx-count-check-failed']: (args: { minTxs: number; availableTxs: number; slot: SlotNumber }) => void;
15
+ ['block-build-failed']: (args: { reason: string; slot: SlotNumber }) => void;
16
+ ['block-proposed']: (args: { blockNumber: BlockNumber; slot: SlotNumber }) => void;
17
+ ['checkpoint-empty']: (args: { slot: SlotNumber }) => void;
18
+ ['checkpoint-publish-failed']: (args: {
19
+ slot: SlotNumber;
20
+ successfulActions?: Action[];
21
+ failedActions?: Action[];
22
+ sentActions?: Action[];
23
+ expiredActions?: Action[];
24
+ }) => void;
25
+ ['checkpoint-published']: (args: { checkpoint: CheckpointNumber; slot: SlotNumber }) => void;
26
+ ['checkpoint-error']: (args: { error: Error }) => void;
27
+ };
@@ -1,3 +1,7 @@
1
1
  export * from './block_builder.js';
2
+ export * from './checkpoint_builder.js';
3
+ export * from './checkpoint_proposal_job.js';
4
+ export * from './checkpoint_voter.js';
2
5
  export * from './config.js';
6
+ export * from './events.js';
3
7
  export * from './sequencer.js';
@@ -1,5 +1,7 @@
1
1
  import { EthAddress } from '@aztec/aztec.js/addresses';
2
- import type { RollupContract } from '@aztec/ethereum';
2
+ import type { RollupContract } from '@aztec/ethereum/contracts';
3
+ import type { L1FeeAnalysisResult } from '@aztec/ethereum/l1-fee-analysis';
4
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
3
5
  import {
4
6
  Attributes,
5
7
  type Gauge,
@@ -16,6 +18,7 @@ import { type Hex, formatUnits } from 'viem';
16
18
 
17
19
  import type { SequencerState } from './utils.js';
18
20
 
21
+ // TODO(palla/mbps): Review all metrics and add any missing ones per checkpoint
19
22
  export class SequencerMetrics {
20
23
  public readonly tracer: Tracer;
21
24
  private meter: Meter;
@@ -36,7 +39,26 @@ export class SequencerMetrics {
36
39
  private slots: UpDownCounter;
37
40
  private filledSlots: UpDownCounter;
38
41
 
39
- private lastSeenSlot?: bigint;
42
+ private blockProposalFailed: UpDownCounter;
43
+ private blockProposalSuccess: UpDownCounter;
44
+ private blockProposalPrecheckFailed: UpDownCounter;
45
+ private checkpointSuccess: UpDownCounter;
46
+ private slashingAttempts: UpDownCounter;
47
+ private blockAttestationDelay: Histogram;
48
+
49
+ // Fisherman fee analysis metrics
50
+ private fishermanWouldBeIncluded: UpDownCounter;
51
+ private fishermanTimeBeforeBlock: Histogram;
52
+ private fishermanPendingBlobTxCount: Histogram;
53
+ private fishermanIncludedBlobTxCount: Histogram;
54
+ private fishermanCalculatedPriorityFee: Histogram;
55
+ private fishermanPriorityFeeDelta: Histogram;
56
+ private fishermanEstimatedCost: Histogram;
57
+ private fishermanEstimatedOverpayment: Histogram;
58
+ private fishermanMinedBlobTxPriorityFee: Histogram;
59
+ private fishermanMinedBlobTxTotalCost: Histogram;
60
+
61
+ private lastSeenSlot?: SlotNumber;
40
62
 
41
63
  constructor(
42
64
  client: TelemetryClient,
@@ -70,6 +92,12 @@ export class SequencerMetrics {
70
92
  },
71
93
  );
72
94
 
95
+ this.blockAttestationDelay = this.meter.createHistogram(Metrics.SEQUENCER_BLOCK_ATTESTATION_DELAY, {
96
+ unit: 'ms',
97
+ description: 'The time difference between block proposal and minimal attestation count reached,',
98
+ valueType: ValueType.INT,
99
+ });
100
+
73
101
  // Init gauges and counters
74
102
  this.blockCounter.add(0, {
75
103
  [Attributes.STATUS]: 'failed',
@@ -121,6 +149,110 @@ export class SequencerMetrics {
121
149
  valueType: ValueType.INT,
122
150
  description: 'The minimum number of attestations required to publish a block',
123
151
  });
152
+
153
+ this.blockProposalFailed = this.meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_PROPOSAL_FAILED_COUNT, {
154
+ valueType: ValueType.INT,
155
+ description: 'The number of times block proposal failed (including validation builds)',
156
+ });
157
+
158
+ this.blockProposalSuccess = this.meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_PROPOSAL_SUCCESS_COUNT, {
159
+ valueType: ValueType.INT,
160
+ description: 'The number of times block proposal succeeded (including validation builds)',
161
+ });
162
+
163
+ this.checkpointSuccess = this.meter.createUpDownCounter(Metrics.SEQUENCER_CHECKPOINT_SUCCESS_COUNT, {
164
+ valueType: ValueType.INT,
165
+ description: 'The number of times checkpoint publishing succeeded',
166
+ });
167
+
168
+ this.blockProposalPrecheckFailed = this.meter.createUpDownCounter(
169
+ Metrics.SEQUENCER_BLOCK_PROPOSAL_PRECHECK_FAILED_COUNT,
170
+ {
171
+ valueType: ValueType.INT,
172
+ description: 'The number of times block proposal pre-build checks failed',
173
+ },
174
+ );
175
+
176
+ this.slashingAttempts = this.meter.createUpDownCounter(Metrics.SEQUENCER_SLASHING_ATTEMPTS_COUNT, {
177
+ valueType: ValueType.INT,
178
+ description: 'The number of slashing action attempts',
179
+ });
180
+
181
+ // Fisherman fee analysis metrics
182
+ this.fishermanWouldBeIncluded = this.meter.createUpDownCounter(Metrics.FISHERMAN_FEE_ANALYSIS_WOULD_BE_INCLUDED, {
183
+ valueType: ValueType.INT,
184
+ description: 'Whether the transaction would have been included in the block',
185
+ });
186
+
187
+ this.fishermanTimeBeforeBlock = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_TIME_BEFORE_BLOCK, {
188
+ unit: 'ms',
189
+ description: 'Time in ms between fee analysis and block being mined',
190
+ valueType: ValueType.INT,
191
+ });
192
+
193
+ this.fishermanPendingBlobTxCount = this.meter.createHistogram(
194
+ Metrics.FISHERMAN_FEE_ANALYSIS_PENDING_BLOB_TX_COUNT,
195
+ {
196
+ description: 'Number of blob transactions seen in the pending block',
197
+ valueType: ValueType.INT,
198
+ },
199
+ );
200
+
201
+ this.fishermanIncludedBlobTxCount = this.meter.createHistogram(
202
+ Metrics.FISHERMAN_FEE_ANALYSIS_INCLUDED_BLOB_TX_COUNT,
203
+ {
204
+ description: 'Number of blob transactions that got included in the mined block',
205
+ valueType: ValueType.INT,
206
+ },
207
+ );
208
+
209
+ this.fishermanCalculatedPriorityFee = this.meter.createHistogram(
210
+ Metrics.FISHERMAN_FEE_ANALYSIS_CALCULATED_PRIORITY_FEE,
211
+ {
212
+ unit: 'gwei',
213
+ description: 'Priority fee calculated by each strategy',
214
+ valueType: ValueType.DOUBLE,
215
+ },
216
+ );
217
+
218
+ this.fishermanPriorityFeeDelta = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_PRIORITY_FEE_DELTA, {
219
+ unit: 'gwei',
220
+ description: 'Difference between our priority fee and minimum included priority fee',
221
+ valueType: ValueType.DOUBLE,
222
+ });
223
+
224
+ this.fishermanEstimatedCost = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_ESTIMATED_COST, {
225
+ unit: 'eth',
226
+ description: 'Estimated total cost in ETH for the transaction with this strategy',
227
+ valueType: ValueType.DOUBLE,
228
+ });
229
+
230
+ this.fishermanEstimatedOverpayment = this.meter.createHistogram(
231
+ Metrics.FISHERMAN_FEE_ANALYSIS_ESTIMATED_OVERPAYMENT,
232
+ {
233
+ unit: 'eth',
234
+ description: 'Estimated overpayment in ETH vs minimum required for inclusion',
235
+ valueType: ValueType.DOUBLE,
236
+ },
237
+ );
238
+
239
+ this.fishermanMinedBlobTxPriorityFee = this.meter.createHistogram(
240
+ Metrics.FISHERMAN_FEE_ANALYSIS_MINED_BLOB_TX_PRIORITY_FEE,
241
+ {
242
+ unit: 'gwei',
243
+ description: 'Priority fee per gas for blob transactions in mined blocks',
244
+ valueType: ValueType.DOUBLE,
245
+ },
246
+ );
247
+
248
+ this.fishermanMinedBlobTxTotalCost = this.meter.createHistogram(
249
+ Metrics.FISHERMAN_FEE_ANALYSIS_MINED_BLOB_TX_TOTAL_COST,
250
+ {
251
+ unit: 'eth',
252
+ description: 'Total cost in ETH for blob transactions in mined blocks',
253
+ valueType: ValueType.DOUBLE,
254
+ },
255
+ );
124
256
  }
125
257
 
126
258
  public recordRequiredAttestations(requiredAttestationsCount: number, allowanceMs: number) {
@@ -132,6 +264,10 @@ export class SequencerMetrics {
132
264
  this.timeToCollectAttestations.record(0);
133
265
  }
134
266
 
267
+ public recordBlockAttestationDelay(duration: number) {
268
+ this.blockAttestationDelay.record(duration);
269
+ }
270
+
135
271
  public recordCollectedAttestations(count: number, durationMs: number) {
136
272
  this.collectedAttestions.record(count);
137
273
  this.timeToCollectAttestations.record(Math.ceil(durationMs));
@@ -157,7 +293,7 @@ export class SequencerMetrics {
157
293
  });
158
294
  }
159
295
 
160
- incOpenSlot(slot: bigint, proposer: string) {
296
+ incOpenSlot(slot: SlotNumber, proposer: string) {
161
297
  // sequencer went through the loop a second time. Noop
162
298
  if (slot === this.lastSeenSlot) {
163
299
  return;
@@ -188,4 +324,119 @@ export class SequencerMetrics {
188
324
  }
189
325
  }
190
326
  }
327
+
328
+ recordCheckpointSuccess() {
329
+ this.checkpointSuccess.add(1);
330
+ }
331
+
332
+ recordBlockProposalFailed(reason?: string) {
333
+ this.blockProposalFailed.add(1, {
334
+ ...(reason && { [Attributes.ERROR_TYPE]: reason }),
335
+ });
336
+ }
337
+
338
+ recordBlockProposalSuccess() {
339
+ this.blockProposalSuccess.add(1);
340
+ }
341
+
342
+ recordBlockProposalPrecheckFailed(checkType: string) {
343
+ this.blockProposalPrecheckFailed.add(1, {
344
+ [Attributes.ERROR_TYPE]: checkType,
345
+ });
346
+ }
347
+
348
+ recordSlashingAttempt(actionCount: number) {
349
+ this.slashingAttempts.add(actionCount);
350
+ }
351
+
352
+ /**
353
+ * Records metrics for a completed fisherman fee analysis
354
+ * @param analysis - The completed fee analysis result
355
+ */
356
+ recordFishermanFeeAnalysis(analysis: L1FeeAnalysisResult) {
357
+ // In fisherman mode, we should always have strategy results
358
+ if (!analysis.computedPrices.strategyResults || analysis.computedPrices.strategyResults.length === 0) {
359
+ // This should never happen in fisherman mode - log an error
360
+ // We don't record metrics without strategy IDs as that defeats the purpose
361
+ throw new Error(
362
+ `No strategy results found in fisherman fee analysis ${analysis.id}. This indicates a bug in the fee analysis.`,
363
+ );
364
+ }
365
+
366
+ // Record metrics for each strategy separately
367
+ for (const strategyResult of analysis.computedPrices.strategyResults) {
368
+ const strategyAttributes = {
369
+ [Attributes.FISHERMAN_FEE_STRATEGY_ID]: strategyResult.strategyId,
370
+ };
371
+
372
+ // Record pending block snapshot data (once per strategy for comparison)
373
+ this.fishermanPendingBlobTxCount.record(analysis.pendingSnapshot.pendingBlobTxCount, strategyAttributes);
374
+
375
+ // Record mined block data if available
376
+ if (analysis.minedBlock) {
377
+ this.fishermanIncludedBlobTxCount.record(analysis.minedBlock.includedBlobTxCount, strategyAttributes);
378
+
379
+ // Record actual fees from blob transactions in the mined block
380
+ for (const blobTx of analysis.minedBlock.includedBlobTxs) {
381
+ // Record priority fee per gas in Gwei
382
+ const priorityFeeGwei = Number(blobTx.maxPriorityFeePerGas) / 1e9;
383
+ this.fishermanMinedBlobTxPriorityFee.record(priorityFeeGwei, strategyAttributes);
384
+
385
+ // Calculate total cost in ETH
386
+ // Cost = (gas * (baseFee + priorityFee)) + (blobCount * blobGasPerBlob * blobBaseFee)
387
+ const baseFee = analysis.minedBlock.baseFeePerGas;
388
+ const effectiveGasPrice = baseFee + blobTx.maxPriorityFeePerGas;
389
+
390
+ // Calculate execution cost using actual gas limit from the transaction
391
+ const executionCost = blobTx.gas * effectiveGasPrice;
392
+
393
+ // Calculate blob cost using maxFeePerBlobGas * blobCount * GAS_PER_BLOB
394
+ const blobCost = blobTx.maxFeePerBlobGas * BigInt(blobTx.blobCount) * 131072n; // 128KB per blob
395
+
396
+ const totalCostWei = executionCost + blobCost;
397
+ const totalCostEth = Number(totalCostWei) / 1e18;
398
+
399
+ this.fishermanMinedBlobTxTotalCost.record(totalCostEth, strategyAttributes);
400
+ }
401
+ }
402
+
403
+ // Record the calculated priority fee for this strategy
404
+ const calculatedPriorityFeeGwei = Number(strategyResult.calculatedPriorityFee) / 1e9;
405
+ this.fishermanCalculatedPriorityFee.record(calculatedPriorityFeeGwei, strategyAttributes);
406
+
407
+ // Record analysis results if available
408
+ if (analysis.analysis) {
409
+ this.fishermanTimeBeforeBlock.record(Math.ceil(analysis.analysis.timeBeforeBlockMs), strategyAttributes);
410
+
411
+ // Record strategy-specific inclusion result
412
+ if (strategyResult.wouldBeIncluded !== undefined) {
413
+ if (strategyResult.wouldBeIncluded) {
414
+ this.fishermanWouldBeIncluded.add(1, { ...strategyAttributes, [Attributes.OK]: true });
415
+ } else {
416
+ this.fishermanWouldBeIncluded.add(1, {
417
+ ...strategyAttributes,
418
+ [Attributes.OK]: false,
419
+ ...(strategyResult.exclusionReason && { [Attributes.ERROR_TYPE]: strategyResult.exclusionReason }),
420
+ });
421
+ }
422
+ }
423
+
424
+ // Record strategy-specific priority fee delta
425
+ if (strategyResult.priorityFeeDelta !== undefined) {
426
+ const priorityFeeDeltaGwei = Number(strategyResult.priorityFeeDelta) / 1e9;
427
+ this.fishermanPriorityFeeDelta.record(priorityFeeDeltaGwei, strategyAttributes);
428
+ }
429
+
430
+ // Record estimated cost if available
431
+ if (strategyResult.estimatedCostEth !== undefined) {
432
+ this.fishermanEstimatedCost.record(strategyResult.estimatedCostEth, strategyAttributes);
433
+ }
434
+
435
+ // Record estimated overpayment if available
436
+ if (strategyResult.estimatedOverpaymentEth !== undefined) {
437
+ this.fishermanEstimatedOverpayment.record(strategyResult.estimatedOverpaymentEth, strategyAttributes);
438
+ }
439
+ }
440
+ }
441
+ }
191
442
  }