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

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 (101) hide show
  1. package/dest/client/index.d.ts +1 -1
  2. package/dest/client/sequencer-client.d.ts +12 -12
  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 +80 -28
  8. package/dest/global_variable_builder/global_builder.d.ts +22 -16
  9. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  10. package/dest/global_variable_builder/global_builder.js +52 -39
  11. package/dest/global_variable_builder/index.d.ts +1 -1
  12. package/dest/index.d.ts +2 -3
  13. package/dest/index.d.ts.map +1 -1
  14. package/dest/index.js +1 -2
  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-metrics.js +15 -86
  25. package/dest/publisher/sequencer-publisher.d.ts +75 -61
  26. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  27. package/dest/publisher/sequencer-publisher.js +661 -158
  28. package/dest/sequencer/checkpoint_proposal_job.d.ts +79 -0
  29. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  30. package/dest/sequencer/checkpoint_proposal_job.js +1164 -0
  31. package/dest/sequencer/checkpoint_voter.d.ts +35 -0
  32. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  33. package/dest/sequencer/checkpoint_voter.js +109 -0
  34. package/dest/sequencer/config.d.ts +3 -2
  35. package/dest/sequencer/config.d.ts.map +1 -1
  36. package/dest/sequencer/errors.d.ts +1 -1
  37. package/dest/sequencer/errors.d.ts.map +1 -1
  38. package/dest/sequencer/events.d.ts +46 -0
  39. package/dest/sequencer/events.d.ts.map +1 -0
  40. package/dest/sequencer/events.js +1 -0
  41. package/dest/sequencer/index.d.ts +4 -2
  42. package/dest/sequencer/index.d.ts.map +1 -1
  43. package/dest/sequencer/index.js +3 -1
  44. package/dest/sequencer/metrics.d.ts +32 -3
  45. package/dest/sequencer/metrics.d.ts.map +1 -1
  46. package/dest/sequencer/metrics.js +147 -46
  47. package/dest/sequencer/sequencer.d.ts +110 -142
  48. package/dest/sequencer/sequencer.d.ts.map +1 -1
  49. package/dest/sequencer/sequencer.js +716 -504
  50. package/dest/sequencer/timetable.d.ts +54 -14
  51. package/dest/sequencer/timetable.d.ts.map +1 -1
  52. package/dest/sequencer/timetable.js +148 -59
  53. package/dest/sequencer/types.d.ts +3 -0
  54. package/dest/sequencer/types.d.ts.map +1 -0
  55. package/dest/sequencer/types.js +1 -0
  56. package/dest/sequencer/utils.d.ts +14 -8
  57. package/dest/sequencer/utils.d.ts.map +1 -1
  58. package/dest/sequencer/utils.js +7 -4
  59. package/dest/test/index.d.ts +4 -3
  60. package/dest/test/index.d.ts.map +1 -1
  61. package/dest/test/mock_checkpoint_builder.d.ts +92 -0
  62. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  63. package/dest/test/mock_checkpoint_builder.js +208 -0
  64. package/dest/test/utils.d.ts +53 -0
  65. package/dest/test/utils.d.ts.map +1 -0
  66. package/dest/test/utils.js +103 -0
  67. package/package.json +33 -30
  68. package/src/client/sequencer-client.ts +30 -41
  69. package/src/config.ts +86 -32
  70. package/src/global_variable_builder/global_builder.ts +67 -59
  71. package/src/index.ts +1 -7
  72. package/src/publisher/config.ts +20 -9
  73. package/src/publisher/sequencer-publisher-factory.ts +7 -5
  74. package/src/publisher/sequencer-publisher-metrics.ts +16 -72
  75. package/src/publisher/sequencer-publisher.ts +381 -203
  76. package/src/sequencer/README.md +531 -0
  77. package/src/sequencer/checkpoint_proposal_job.ts +843 -0
  78. package/src/sequencer/checkpoint_voter.ts +130 -0
  79. package/src/sequencer/config.ts +2 -1
  80. package/src/sequencer/events.ts +27 -0
  81. package/src/sequencer/index.ts +3 -1
  82. package/src/sequencer/metrics.ts +198 -55
  83. package/src/sequencer/sequencer.ts +465 -696
  84. package/src/sequencer/timetable.ts +173 -79
  85. package/src/sequencer/types.ts +6 -0
  86. package/src/sequencer/utils.ts +18 -9
  87. package/src/test/index.ts +3 -2
  88. package/src/test/mock_checkpoint_builder.ts +295 -0
  89. package/src/test/utils.ts +164 -0
  90. package/dest/sequencer/block_builder.d.ts +0 -27
  91. package/dest/sequencer/block_builder.d.ts.map +0 -1
  92. package/dest/sequencer/block_builder.js +0 -130
  93. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  94. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  95. package/dest/tx_validator/nullifier_cache.js +0 -24
  96. package/dest/tx_validator/tx_validator_factory.d.ts +0 -17
  97. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  98. package/dest/tx_validator/tx_validator_factory.js +0 -53
  99. package/src/sequencer/block_builder.ts +0 -218
  100. package/src/tx_validator/nullifier_cache.ts +0 -30
  101. package/src/tx_validator/tx_validator_factory.ts +0 -132
@@ -0,0 +1,130 @@
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
+ import { DutyAlreadySignedError } from '@aztec/validator-ha-signer/errors';
9
+ import { DutyType, type SigningContext } from '@aztec/validator-ha-signer/types';
10
+
11
+ import type { TypedDataDefinition } from 'viem';
12
+
13
+ import type { SequencerPublisher } from '../publisher/sequencer-publisher.js';
14
+ import type { SequencerMetrics } from './metrics.js';
15
+ import type { SequencerRollupConstants } from './types.js';
16
+
17
+ /**
18
+ * Handles governance and slashing voting for a given slot.
19
+ */
20
+ export class CheckpointVoter {
21
+ private slotTimestamp: bigint;
22
+ private governanceSigner: (msg: TypedDataDefinition) => Promise<`0x${string}`>;
23
+ private slashingSigner: (msg: TypedDataDefinition) => Promise<`0x${string}`>;
24
+
25
+ constructor(
26
+ private readonly slot: SlotNumber,
27
+ private readonly publisher: SequencerPublisher,
28
+ private readonly attestorAddress: EthAddress,
29
+ private readonly validatorClient: ValidatorClient,
30
+ private readonly slasherClient: SlasherClientInterface | undefined,
31
+ private readonly l1Constants: SequencerRollupConstants,
32
+ private readonly config: ResolvedSequencerConfig,
33
+ private readonly metrics: SequencerMetrics,
34
+ private readonly log: Logger,
35
+ ) {
36
+ this.slotTimestamp = getTimestampForSlot(this.slot, this.l1Constants);
37
+
38
+ // Create separate signers with appropriate duty contexts for governance and slashing votes
39
+ // These use HA protection to ensure only one node signs per slot/duty
40
+ const governanceContext: SigningContext = { slot: this.slot, dutyType: DutyType.GOVERNANCE_VOTE };
41
+ this.governanceSigner = (msg: TypedDataDefinition) =>
42
+ this.validatorClient.signWithAddress(this.attestorAddress, msg, governanceContext).then(s => s.toString());
43
+
44
+ const slashingContext: SigningContext = { slot: this.slot, dutyType: DutyType.SLASHING_VOTE };
45
+ this.slashingSigner = (msg: TypedDataDefinition) =>
46
+ this.validatorClient.signWithAddress(this.attestorAddress, msg, slashingContext).then(s => s.toString());
47
+ }
48
+
49
+ /**
50
+ * Enqueues governance and slashing votes with the publisher.
51
+ * Returns a tuple of promises that resolve to whether each vote was successfully enqueued.
52
+ */
53
+ enqueueVotes(): [Promise<boolean | undefined>, Promise<boolean | undefined>] {
54
+ try {
55
+ const enqueueGovernancePromise = this.enqueueGovernanceVote();
56
+ const enqueueSlashingPromise = this.enqueueSlashingVote();
57
+
58
+ return [enqueueGovernancePromise, enqueueSlashingPromise];
59
+ } catch (err) {
60
+ this.log.error(`Error enqueueing governance and slashing votes`, err);
61
+ return [Promise.resolve(false), Promise.resolve(false)];
62
+ }
63
+ }
64
+
65
+ private async enqueueGovernanceVote(): Promise<boolean | undefined> {
66
+ const governanceProposerPayload = this.config.governanceProposerPayload;
67
+ if (!governanceProposerPayload || governanceProposerPayload.isZero()) {
68
+ return undefined;
69
+ }
70
+
71
+ this.log.info(`Enqueuing vote for ${governanceProposerPayload} governance for slot ${this.slot}`, {
72
+ slot: this.slot,
73
+ governanceProposerPayload: governanceProposerPayload.toString(),
74
+ });
75
+
76
+ try {
77
+ return await this.publisher.enqueueGovernanceCastSignal(
78
+ governanceProposerPayload,
79
+ this.slot,
80
+ this.slotTimestamp,
81
+ this.attestorAddress,
82
+ this.governanceSigner,
83
+ );
84
+ } catch (err) {
85
+ if (err instanceof DutyAlreadySignedError) {
86
+ this.log.info(`Governance vote already signed by another node`, {
87
+ slot: this.slot,
88
+ signedByNode: err.signedByNode,
89
+ });
90
+ } else {
91
+ this.log.error(`Error enqueueing governance vote`, err);
92
+ }
93
+ return false;
94
+ }
95
+ }
96
+
97
+ private async enqueueSlashingVote(): Promise<boolean | undefined> {
98
+ try {
99
+ const actions = await this.slasherClient?.getProposerActions(this.slot);
100
+ if (!actions || actions.length === 0) {
101
+ return undefined;
102
+ }
103
+
104
+ this.log.info(`Enqueuing vote for ${actions.length} slashing actions for slot ${this.slot}`, {
105
+ slot: this.slot,
106
+ actionCount: actions.length,
107
+ });
108
+
109
+ this.metrics.recordSlashingAttempt(actions.length);
110
+
111
+ return await this.publisher.enqueueSlashingActions(
112
+ actions,
113
+ this.slot,
114
+ this.slotTimestamp,
115
+ this.attestorAddress,
116
+ this.slashingSigner,
117
+ );
118
+ } catch (err) {
119
+ if (err instanceof DutyAlreadySignedError) {
120
+ this.log.info(`Slashing vote already signed by another node`, {
121
+ slot: this.slot,
122
+ signedByNode: err.signedByNode,
123
+ });
124
+ } else {
125
+ this.log.error(`Error enqueueing slashing vote`, err);
126
+ }
127
+ return false;
128
+ }
129
+ }
130
+ }
@@ -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,5 @@
1
- export * from './block_builder.js';
1
+ export * from './checkpoint_proposal_job.js';
2
+ export * from './checkpoint_voter.js';
2
3
  export * from './config.js';
4
+ export * from './events.js';
3
5
  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,
@@ -9,13 +11,13 @@ import {
9
11
  type TelemetryClient,
10
12
  type Tracer,
11
13
  type UpDownCounter,
12
- ValueType,
13
14
  } from '@aztec/telemetry-client';
14
15
 
15
16
  import { type Hex, formatUnits } from 'viem';
16
17
 
17
18
  import type { SequencerState } from './utils.js';
18
19
 
20
+ // TODO(palla/mbps): Review all metrics and add any missing ones per checkpoint
19
21
  export class SequencerMetrics {
20
22
  public readonly tracer: Tracer;
21
23
  private meter: Meter;
@@ -36,7 +38,26 @@ export class SequencerMetrics {
36
38
  private slots: UpDownCounter;
37
39
  private filledSlots: UpDownCounter;
38
40
 
39
- private lastSeenSlot?: bigint;
41
+ private blockProposalFailed: UpDownCounter;
42
+ private blockProposalSuccess: UpDownCounter;
43
+ private blockProposalPrecheckFailed: UpDownCounter;
44
+ private checkpointSuccess: UpDownCounter;
45
+ private slashingAttempts: UpDownCounter;
46
+ private checkpointAttestationDelay: Histogram;
47
+
48
+ // Fisherman fee analysis metrics
49
+ private fishermanWouldBeIncluded: UpDownCounter;
50
+ private fishermanTimeBeforeBlock: Histogram;
51
+ private fishermanPendingBlobTxCount: Histogram;
52
+ private fishermanIncludedBlobTxCount: Histogram;
53
+ private fishermanCalculatedPriorityFee: Histogram;
54
+ private fishermanPriorityFeeDelta: Histogram;
55
+ private fishermanEstimatedCost: Histogram;
56
+ private fishermanEstimatedOverpayment: Histogram;
57
+ private fishermanMinedBlobTxPriorityFee: Histogram;
58
+ private fishermanMinedBlobTxTotalCost: Histogram;
59
+
60
+ private lastSeenSlot?: SlotNumber;
40
61
 
41
62
  constructor(
42
63
  client: TelemetryClient,
@@ -48,27 +69,13 @@ export class SequencerMetrics {
48
69
 
49
70
  this.blockCounter = this.meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_COUNT);
50
71
 
51
- this.blockBuildDuration = this.meter.createHistogram(Metrics.SEQUENCER_BLOCK_BUILD_DURATION, {
52
- unit: 'ms',
53
- description: 'Duration to build a block',
54
- valueType: ValueType.INT,
55
- });
72
+ this.blockBuildDuration = this.meter.createHistogram(Metrics.SEQUENCER_BLOCK_BUILD_DURATION);
56
73
 
57
- this.blockBuildManaPerSecond = this.meter.createGauge(Metrics.SEQUENCER_BLOCK_BUILD_MANA_PER_SECOND, {
58
- unit: 'mana/s',
59
- description: 'Mana per second when building a block',
60
- valueType: ValueType.INT,
61
- });
74
+ this.blockBuildManaPerSecond = this.meter.createGauge(Metrics.SEQUENCER_BLOCK_BUILD_MANA_PER_SECOND);
62
75
 
63
- this.stateTransitionBufferDuration = this.meter.createHistogram(
64
- Metrics.SEQUENCER_STATE_TRANSITION_BUFFER_DURATION,
65
- {
66
- unit: 'ms',
67
- description:
68
- 'The time difference between when the sequencer needed to transition to a new state and when it actually did.',
69
- valueType: ValueType.INT,
70
- },
71
- );
76
+ this.stateTransitionBufferDuration = this.meter.createHistogram(Metrics.SEQUENCER_STATE_TRANSITION_BUFFER_DURATION);
77
+
78
+ this.checkpointAttestationDelay = this.meter.createHistogram(Metrics.SEQUENCER_CHECKPOINT_ATTESTATION_DELAY);
72
79
 
73
80
  // Init gauges and counters
74
81
  this.blockCounter.add(0, {
@@ -78,49 +85,66 @@ export class SequencerMetrics {
78
85
  [Attributes.STATUS]: 'built',
79
86
  });
80
87
 
81
- this.rewards = this.meter.createGauge(Metrics.SEQUENCER_CURRENT_BLOCK_REWARDS, {
82
- valueType: ValueType.DOUBLE,
83
- description: 'The rewards earned',
84
- });
88
+ this.rewards = this.meter.createGauge(Metrics.SEQUENCER_CURRENT_BLOCK_REWARDS);
85
89
 
86
- this.slots = this.meter.createUpDownCounter(Metrics.SEQUENCER_SLOT_COUNT, {
87
- valueType: ValueType.INT,
88
- description: 'The number of slots this sequencer was selected for',
89
- });
90
+ this.slots = this.meter.createUpDownCounter(Metrics.SEQUENCER_SLOT_COUNT);
90
91
 
91
92
  /**
92
93
  * NOTE: we do not track missed slots as a separate metric. That would be difficult to determine
93
94
  * Instead, use a computed metric, `slots - filledSlots` to get the number of slots a sequencer has missed.
94
95
  */
95
- this.filledSlots = this.meter.createUpDownCounter(Metrics.SEQUENCER_FILLED_SLOT_COUNT, {
96
- valueType: ValueType.INT,
97
- description: 'The number of slots this sequencer has filled',
98
- });
96
+ this.filledSlots = this.meter.createUpDownCounter(Metrics.SEQUENCER_FILLED_SLOT_COUNT);
99
97
 
100
- this.timeToCollectAttestations = this.meter.createGauge(Metrics.SEQUENCER_COLLECT_ATTESTATIONS_DURATION, {
101
- description: 'The time spent collecting attestations from committee members',
102
- unit: 'ms',
103
- valueType: ValueType.INT,
104
- });
98
+ this.timeToCollectAttestations = this.meter.createGauge(Metrics.SEQUENCER_COLLECT_ATTESTATIONS_DURATION);
105
99
 
106
- this.allowanceToCollectAttestations = this.meter.createGauge(
107
- Metrics.SEQUENCER_COLLECT_ATTESTATIONS_TIME_ALLOWANCE,
108
- {
109
- description: 'Maximum amount of time to collect attestations',
110
- unit: 'ms',
111
- valueType: ValueType.INT,
112
- },
100
+ this.allowanceToCollectAttestations = this.meter.createGauge(Metrics.SEQUENCER_COLLECT_ATTESTATIONS_TIME_ALLOWANCE);
101
+
102
+ this.requiredAttestions = this.meter.createGauge(Metrics.SEQUENCER_REQUIRED_ATTESTATIONS_COUNT);
103
+
104
+ this.collectedAttestions = this.meter.createGauge(Metrics.SEQUENCER_COLLECTED_ATTESTATIONS_COUNT);
105
+
106
+ this.blockProposalFailed = this.meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_PROPOSAL_FAILED_COUNT);
107
+
108
+ this.blockProposalSuccess = this.meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_PROPOSAL_SUCCESS_COUNT);
109
+
110
+ this.checkpointSuccess = this.meter.createUpDownCounter(Metrics.SEQUENCER_CHECKPOINT_SUCCESS_COUNT);
111
+
112
+ this.blockProposalPrecheckFailed = this.meter.createUpDownCounter(
113
+ Metrics.SEQUENCER_BLOCK_PROPOSAL_PRECHECK_FAILED_COUNT,
113
114
  );
114
115
 
115
- this.requiredAttestions = this.meter.createGauge(Metrics.SEQUENCER_REQUIRED_ATTESTATIONS_COUNT, {
116
- valueType: ValueType.INT,
117
- description: 'The minimum number of attestations required to publish a block',
118
- });
116
+ this.slashingAttempts = this.meter.createUpDownCounter(Metrics.SEQUENCER_SLASHING_ATTEMPTS_COUNT);
119
117
 
120
- this.collectedAttestions = this.meter.createGauge(Metrics.SEQUENCER_COLLECTED_ATTESTATIONS_COUNT, {
121
- valueType: ValueType.INT,
122
- description: 'The minimum number of attestations required to publish a block',
123
- });
118
+ // Fisherman fee analysis metrics
119
+ this.fishermanWouldBeIncluded = this.meter.createUpDownCounter(Metrics.FISHERMAN_FEE_ANALYSIS_WOULD_BE_INCLUDED);
120
+
121
+ this.fishermanTimeBeforeBlock = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_TIME_BEFORE_BLOCK);
122
+
123
+ this.fishermanPendingBlobTxCount = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_PENDING_BLOB_TX_COUNT);
124
+
125
+ this.fishermanIncludedBlobTxCount = this.meter.createHistogram(
126
+ Metrics.FISHERMAN_FEE_ANALYSIS_INCLUDED_BLOB_TX_COUNT,
127
+ );
128
+
129
+ this.fishermanCalculatedPriorityFee = this.meter.createHistogram(
130
+ Metrics.FISHERMAN_FEE_ANALYSIS_CALCULATED_PRIORITY_FEE,
131
+ );
132
+
133
+ this.fishermanPriorityFeeDelta = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_PRIORITY_FEE_DELTA);
134
+
135
+ this.fishermanEstimatedCost = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_ESTIMATED_COST);
136
+
137
+ this.fishermanEstimatedOverpayment = this.meter.createHistogram(
138
+ Metrics.FISHERMAN_FEE_ANALYSIS_ESTIMATED_OVERPAYMENT,
139
+ );
140
+
141
+ this.fishermanMinedBlobTxPriorityFee = this.meter.createHistogram(
142
+ Metrics.FISHERMAN_FEE_ANALYSIS_MINED_BLOB_TX_PRIORITY_FEE,
143
+ );
144
+
145
+ this.fishermanMinedBlobTxTotalCost = this.meter.createHistogram(
146
+ Metrics.FISHERMAN_FEE_ANALYSIS_MINED_BLOB_TX_TOTAL_COST,
147
+ );
124
148
  }
125
149
 
126
150
  public recordRequiredAttestations(requiredAttestationsCount: number, allowanceMs: number) {
@@ -132,6 +156,10 @@ export class SequencerMetrics {
132
156
  this.timeToCollectAttestations.record(0);
133
157
  }
134
158
 
159
+ public recordCheckpointAttestationDelay(duration: number) {
160
+ this.checkpointAttestationDelay.record(duration);
161
+ }
162
+
135
163
  public recordCollectedAttestations(count: number, durationMs: number) {
136
164
  this.collectedAttestions.record(count);
137
165
  this.timeToCollectAttestations.record(Math.ceil(durationMs));
@@ -157,7 +185,7 @@ export class SequencerMetrics {
157
185
  });
158
186
  }
159
187
 
160
- incOpenSlot(slot: bigint, proposer: string) {
188
+ incOpenSlot(slot: SlotNumber, proposer: string) {
161
189
  // sequencer went through the loop a second time. Noop
162
190
  if (slot === this.lastSeenSlot) {
163
191
  return;
@@ -188,4 +216,119 @@ export class SequencerMetrics {
188
216
  }
189
217
  }
190
218
  }
219
+
220
+ recordCheckpointSuccess() {
221
+ this.checkpointSuccess.add(1);
222
+ }
223
+
224
+ recordBlockProposalFailed(reason?: string) {
225
+ this.blockProposalFailed.add(1, {
226
+ ...(reason && { [Attributes.ERROR_TYPE]: reason }),
227
+ });
228
+ }
229
+
230
+ recordBlockProposalSuccess() {
231
+ this.blockProposalSuccess.add(1);
232
+ }
233
+
234
+ recordBlockProposalPrecheckFailed(checkType: string) {
235
+ this.blockProposalPrecheckFailed.add(1, {
236
+ [Attributes.ERROR_TYPE]: checkType,
237
+ });
238
+ }
239
+
240
+ recordSlashingAttempt(actionCount: number) {
241
+ this.slashingAttempts.add(actionCount);
242
+ }
243
+
244
+ /**
245
+ * Records metrics for a completed fisherman fee analysis
246
+ * @param analysis - The completed fee analysis result
247
+ */
248
+ recordFishermanFeeAnalysis(analysis: L1FeeAnalysisResult) {
249
+ // In fisherman mode, we should always have strategy results
250
+ if (!analysis.computedPrices.strategyResults || analysis.computedPrices.strategyResults.length === 0) {
251
+ // This should never happen in fisherman mode - log an error
252
+ // We don't record metrics without strategy IDs as that defeats the purpose
253
+ throw new Error(
254
+ `No strategy results found in fisherman fee analysis ${analysis.id}. This indicates a bug in the fee analysis.`,
255
+ );
256
+ }
257
+
258
+ // Record metrics for each strategy separately
259
+ for (const strategyResult of analysis.computedPrices.strategyResults) {
260
+ const strategyAttributes = {
261
+ [Attributes.FISHERMAN_FEE_STRATEGY_ID]: strategyResult.strategyId,
262
+ };
263
+
264
+ // Record pending block snapshot data (once per strategy for comparison)
265
+ this.fishermanPendingBlobTxCount.record(analysis.pendingSnapshot.pendingBlobTxCount, strategyAttributes);
266
+
267
+ // Record mined block data if available
268
+ if (analysis.minedBlock) {
269
+ this.fishermanIncludedBlobTxCount.record(analysis.minedBlock.includedBlobTxCount, strategyAttributes);
270
+
271
+ // Record actual fees from blob transactions in the mined block
272
+ for (const blobTx of analysis.minedBlock.includedBlobTxs) {
273
+ // Record priority fee per gas in Gwei
274
+ const priorityFeeGwei = Number(blobTx.maxPriorityFeePerGas) / 1e9;
275
+ this.fishermanMinedBlobTxPriorityFee.record(priorityFeeGwei, strategyAttributes);
276
+
277
+ // Calculate total cost in ETH
278
+ // Cost = (gas * (baseFee + priorityFee)) + (blobCount * blobGasPerBlob * blobBaseFee)
279
+ const baseFee = analysis.minedBlock.baseFeePerGas;
280
+ const effectiveGasPrice = baseFee + blobTx.maxPriorityFeePerGas;
281
+
282
+ // Calculate execution cost using actual gas limit from the transaction
283
+ const executionCost = blobTx.gas * effectiveGasPrice;
284
+
285
+ // Calculate blob cost using maxFeePerBlobGas * blobCount * GAS_PER_BLOB
286
+ const blobCost = blobTx.maxFeePerBlobGas * BigInt(blobTx.blobCount) * 131072n; // 128KB per blob
287
+
288
+ const totalCostWei = executionCost + blobCost;
289
+ const totalCostEth = Number(totalCostWei) / 1e18;
290
+
291
+ this.fishermanMinedBlobTxTotalCost.record(totalCostEth, strategyAttributes);
292
+ }
293
+ }
294
+
295
+ // Record the calculated priority fee for this strategy
296
+ const calculatedPriorityFeeGwei = Number(strategyResult.calculatedPriorityFee) / 1e9;
297
+ this.fishermanCalculatedPriorityFee.record(calculatedPriorityFeeGwei, strategyAttributes);
298
+
299
+ // Record analysis results if available
300
+ if (analysis.analysis) {
301
+ this.fishermanTimeBeforeBlock.record(Math.ceil(analysis.analysis.timeBeforeBlockMs), strategyAttributes);
302
+
303
+ // Record strategy-specific inclusion result
304
+ if (strategyResult.wouldBeIncluded !== undefined) {
305
+ if (strategyResult.wouldBeIncluded) {
306
+ this.fishermanWouldBeIncluded.add(1, { ...strategyAttributes, [Attributes.OK]: true });
307
+ } else {
308
+ this.fishermanWouldBeIncluded.add(1, {
309
+ ...strategyAttributes,
310
+ [Attributes.OK]: false,
311
+ ...(strategyResult.exclusionReason && { [Attributes.ERROR_TYPE]: strategyResult.exclusionReason }),
312
+ });
313
+ }
314
+ }
315
+
316
+ // Record strategy-specific priority fee delta
317
+ if (strategyResult.priorityFeeDelta !== undefined) {
318
+ const priorityFeeDeltaGwei = Number(strategyResult.priorityFeeDelta) / 1e9;
319
+ this.fishermanPriorityFeeDelta.record(priorityFeeDeltaGwei, strategyAttributes);
320
+ }
321
+
322
+ // Record estimated cost if available
323
+ if (strategyResult.estimatedCostEth !== undefined) {
324
+ this.fishermanEstimatedCost.record(strategyResult.estimatedCostEth, strategyAttributes);
325
+ }
326
+
327
+ // Record estimated overpayment if available
328
+ if (strategyResult.estimatedOverpaymentEth !== undefined) {
329
+ this.fishermanEstimatedOverpayment.record(strategyResult.estimatedOverpaymentEth, strategyAttributes);
330
+ }
331
+ }
332
+ }
333
+ }
191
334
  }