@aztec/sequencer-client 0.0.1-commit.21caa21 → 0.0.1-commit.21ecf947b

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 (96) hide show
  1. package/dest/client/sequencer-client.d.ts +12 -12
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +33 -26
  4. package/dest/config.d.ts +12 -6
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +71 -32
  7. package/dest/global_variable_builder/global_builder.d.ts +22 -13
  8. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  9. package/dest/global_variable_builder/global_builder.js +51 -41
  10. package/dest/index.d.ts +2 -3
  11. package/dest/index.d.ts.map +1 -1
  12. package/dest/index.js +1 -2
  13. package/dest/publisher/config.d.ts +7 -4
  14. package/dest/publisher/config.d.ts.map +1 -1
  15. package/dest/publisher/config.js +9 -3
  16. package/dest/publisher/sequencer-publisher-factory.d.ts +5 -4
  17. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  18. package/dest/publisher/sequencer-publisher-factory.js +1 -1
  19. package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
  20. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  21. package/dest/publisher/sequencer-publisher-metrics.js +23 -86
  22. package/dest/publisher/sequencer-publisher.d.ts +56 -42
  23. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  24. package/dest/publisher/sequencer-publisher.js +615 -133
  25. package/dest/sequencer/checkpoint_proposal_job.d.ts +102 -0
  26. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  27. package/dest/sequencer/checkpoint_proposal_job.js +1193 -0
  28. package/dest/sequencer/checkpoint_voter.d.ts +35 -0
  29. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  30. package/dest/sequencer/checkpoint_voter.js +109 -0
  31. package/dest/sequencer/config.d.ts +3 -2
  32. package/dest/sequencer/config.d.ts.map +1 -1
  33. package/dest/sequencer/events.d.ts +46 -0
  34. package/dest/sequencer/events.d.ts.map +1 -0
  35. package/dest/sequencer/events.js +1 -0
  36. package/dest/sequencer/index.d.ts +4 -2
  37. package/dest/sequencer/index.d.ts.map +1 -1
  38. package/dest/sequencer/index.js +3 -1
  39. package/dest/sequencer/metrics.d.ts +27 -3
  40. package/dest/sequencer/metrics.d.ts.map +1 -1
  41. package/dest/sequencer/metrics.js +188 -66
  42. package/dest/sequencer/sequencer.d.ts +109 -131
  43. package/dest/sequencer/sequencer.d.ts.map +1 -1
  44. package/dest/sequencer/sequencer.js +700 -606
  45. package/dest/sequencer/timetable.d.ts +51 -14
  46. package/dest/sequencer/timetable.d.ts.map +1 -1
  47. package/dest/sequencer/timetable.js +145 -59
  48. package/dest/sequencer/types.d.ts +3 -0
  49. package/dest/sequencer/types.d.ts.map +1 -0
  50. package/dest/sequencer/types.js +1 -0
  51. package/dest/sequencer/utils.d.ts +14 -8
  52. package/dest/sequencer/utils.d.ts.map +1 -1
  53. package/dest/sequencer/utils.js +7 -4
  54. package/dest/test/index.d.ts +4 -3
  55. package/dest/test/index.d.ts.map +1 -1
  56. package/dest/test/mock_checkpoint_builder.d.ts +97 -0
  57. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  58. package/dest/test/mock_checkpoint_builder.js +222 -0
  59. package/dest/test/utils.d.ts +53 -0
  60. package/dest/test/utils.d.ts.map +1 -0
  61. package/dest/test/utils.js +104 -0
  62. package/package.json +32 -30
  63. package/src/client/sequencer-client.ts +31 -42
  64. package/src/config.ts +78 -36
  65. package/src/global_variable_builder/global_builder.ts +65 -61
  66. package/src/index.ts +1 -7
  67. package/src/publisher/config.ts +12 -9
  68. package/src/publisher/sequencer-publisher-factory.ts +5 -4
  69. package/src/publisher/sequencer-publisher-metrics.ts +19 -71
  70. package/src/publisher/sequencer-publisher.ts +327 -166
  71. package/src/sequencer/README.md +531 -0
  72. package/src/sequencer/checkpoint_proposal_job.ts +882 -0
  73. package/src/sequencer/checkpoint_voter.ts +130 -0
  74. package/src/sequencer/config.ts +2 -1
  75. package/src/sequencer/events.ts +27 -0
  76. package/src/sequencer/index.ts +3 -1
  77. package/src/sequencer/metrics.ts +236 -76
  78. package/src/sequencer/sequencer.ts +445 -813
  79. package/src/sequencer/timetable.ts +175 -80
  80. package/src/sequencer/types.ts +6 -0
  81. package/src/sequencer/utils.ts +18 -9
  82. package/src/test/index.ts +3 -2
  83. package/src/test/mock_checkpoint_builder.ts +320 -0
  84. package/src/test/utils.ts +167 -0
  85. package/dest/sequencer/block_builder.d.ts +0 -27
  86. package/dest/sequencer/block_builder.d.ts.map +0 -1
  87. package/dest/sequencer/block_builder.js +0 -134
  88. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  89. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  90. package/dest/tx_validator/nullifier_cache.js +0 -24
  91. package/dest/tx_validator/tx_validator_factory.d.ts +0 -17
  92. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  93. package/dest/tx_validator/tx_validator_factory.js +0 -53
  94. package/src/sequencer/block_builder.ts +0 -222
  95. package/src/tx_validator/nullifier_cache.ts +0 -30
  96. 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,6 @@
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';
3
4
  import type { SlotNumber } from '@aztec/foundation/branded-types';
4
5
  import {
5
6
  Attributes,
@@ -10,13 +11,14 @@ import {
10
11
  type TelemetryClient,
11
12
  type Tracer,
12
13
  type UpDownCounter,
13
- ValueType,
14
+ createUpDownCounterWithDefault,
14
15
  } from '@aztec/telemetry-client';
15
16
 
16
17
  import { type Hex, formatUnits } from 'viem';
17
18
 
18
19
  import type { SequencerState } from './utils.js';
19
20
 
21
+ // TODO(palla/mbps): Review all metrics and add any missing ones per checkpoint
20
22
  export class SequencerMetrics {
21
23
  public readonly tracer: Tracer;
22
24
  private meter: Meter;
@@ -40,7 +42,25 @@ export class SequencerMetrics {
40
42
  private blockProposalFailed: UpDownCounter;
41
43
  private blockProposalSuccess: UpDownCounter;
42
44
  private blockProposalPrecheckFailed: UpDownCounter;
45
+ private checkpointSuccess: UpDownCounter;
43
46
  private slashingAttempts: UpDownCounter;
47
+ private checkpointAttestationDelay: 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 fishermanPendingBlobCount: Histogram;
55
+ private fishermanIncludedBlobCount: Histogram;
56
+ private fishermanBlockBlobsFull: UpDownCounter;
57
+ private fishermanMaxBlobCapacity: Histogram;
58
+ private fishermanCalculatedPriorityFee: Histogram;
59
+ private fishermanPriorityFeeDelta: Histogram;
60
+ private fishermanEstimatedCost: Histogram;
61
+ private fishermanEstimatedOverpayment: Histogram;
62
+ private fishermanMinedBlobTxPriorityFee: Histogram;
63
+ private fishermanMinedBlobTxTotalCost: Histogram;
44
64
 
45
65
  private lastSeenSlot?: SlotNumber;
46
66
 
@@ -52,104 +72,114 @@ export class SequencerMetrics {
52
72
  this.meter = client.getMeter(name);
53
73
  this.tracer = client.getTracer(name);
54
74
 
55
- this.blockCounter = this.meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_COUNT);
56
-
57
- this.blockBuildDuration = this.meter.createHistogram(Metrics.SEQUENCER_BLOCK_BUILD_DURATION, {
58
- unit: 'ms',
59
- description: 'Duration to build a block',
60
- valueType: ValueType.INT,
75
+ this.blockCounter = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_BLOCK_COUNT, {
76
+ [Attributes.STATUS]: ['failed', 'built'],
61
77
  });
62
78
 
63
- this.blockBuildManaPerSecond = this.meter.createGauge(Metrics.SEQUENCER_BLOCK_BUILD_MANA_PER_SECOND, {
64
- unit: 'mana/s',
65
- description: 'Mana per second when building a block',
66
- valueType: ValueType.INT,
67
- });
79
+ this.blockBuildDuration = this.meter.createHistogram(Metrics.SEQUENCER_BLOCK_BUILD_DURATION);
68
80
 
69
- this.stateTransitionBufferDuration = this.meter.createHistogram(
70
- Metrics.SEQUENCER_STATE_TRANSITION_BUFFER_DURATION,
71
- {
72
- unit: 'ms',
73
- description:
74
- 'The time difference between when the sequencer needed to transition to a new state and when it actually did.',
75
- valueType: ValueType.INT,
76
- },
77
- );
81
+ this.blockBuildManaPerSecond = this.meter.createGauge(Metrics.SEQUENCER_BLOCK_BUILD_MANA_PER_SECOND);
78
82
 
79
- // Init gauges and counters
80
- this.blockCounter.add(0, {
81
- [Attributes.STATUS]: 'failed',
82
- });
83
- this.blockCounter.add(0, {
84
- [Attributes.STATUS]: 'built',
85
- });
83
+ this.stateTransitionBufferDuration = this.meter.createHistogram(Metrics.SEQUENCER_STATE_TRANSITION_BUFFER_DURATION);
86
84
 
87
- this.rewards = this.meter.createGauge(Metrics.SEQUENCER_CURRENT_BLOCK_REWARDS, {
88
- valueType: ValueType.DOUBLE,
89
- description: 'The rewards earned',
90
- });
85
+ this.checkpointAttestationDelay = this.meter.createHistogram(Metrics.SEQUENCER_CHECKPOINT_ATTESTATION_DELAY);
91
86
 
92
- this.slots = this.meter.createUpDownCounter(Metrics.SEQUENCER_SLOT_COUNT, {
93
- valueType: ValueType.INT,
94
- description: 'The number of slots this sequencer was selected for',
95
- });
87
+ this.rewards = this.meter.createGauge(Metrics.SEQUENCER_CURRENT_BLOCK_REWARDS);
88
+
89
+ this.slots = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_SLOT_COUNT);
96
90
 
97
91
  /**
98
92
  * NOTE: we do not track missed slots as a separate metric. That would be difficult to determine
99
93
  * Instead, use a computed metric, `slots - filledSlots` to get the number of slots a sequencer has missed.
100
94
  */
101
- this.filledSlots = this.meter.createUpDownCounter(Metrics.SEQUENCER_FILLED_SLOT_COUNT, {
102
- valueType: ValueType.INT,
103
- description: 'The number of slots this sequencer has filled',
104
- });
95
+ this.filledSlots = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_FILLED_SLOT_COUNT);
105
96
 
106
- this.timeToCollectAttestations = this.meter.createGauge(Metrics.SEQUENCER_COLLECT_ATTESTATIONS_DURATION, {
107
- description: 'The time spent collecting attestations from committee members',
108
- unit: 'ms',
109
- valueType: ValueType.INT,
110
- });
97
+ this.timeToCollectAttestations = this.meter.createGauge(Metrics.SEQUENCER_COLLECT_ATTESTATIONS_DURATION);
98
+
99
+ this.allowanceToCollectAttestations = this.meter.createGauge(Metrics.SEQUENCER_COLLECT_ATTESTATIONS_TIME_ALLOWANCE);
100
+
101
+ this.requiredAttestions = this.meter.createGauge(Metrics.SEQUENCER_REQUIRED_ATTESTATIONS_COUNT);
102
+
103
+ this.collectedAttestions = this.meter.createGauge(Metrics.SEQUENCER_COLLECTED_ATTESTATIONS_COUNT);
111
104
 
112
- this.allowanceToCollectAttestations = this.meter.createGauge(
113
- Metrics.SEQUENCER_COLLECT_ATTESTATIONS_TIME_ALLOWANCE,
105
+ this.blockProposalFailed = createUpDownCounterWithDefault(
106
+ this.meter,
107
+ Metrics.SEQUENCER_BLOCK_PROPOSAL_FAILED_COUNT,
108
+ );
109
+
110
+ this.blockProposalSuccess = createUpDownCounterWithDefault(
111
+ this.meter,
112
+ Metrics.SEQUENCER_BLOCK_PROPOSAL_SUCCESS_COUNT,
113
+ );
114
+
115
+ this.checkpointSuccess = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_CHECKPOINT_SUCCESS_COUNT);
116
+
117
+ this.blockProposalPrecheckFailed = createUpDownCounterWithDefault(
118
+ this.meter,
119
+ Metrics.SEQUENCER_BLOCK_PROPOSAL_PRECHECK_FAILED_COUNT,
114
120
  {
115
- description: 'Maximum amount of time to collect attestations',
116
- unit: 'ms',
117
- valueType: ValueType.INT,
121
+ [Attributes.ERROR_TYPE]: [
122
+ 'slot_already_taken',
123
+ 'rollup_contract_check_failed',
124
+ 'slot_mismatch',
125
+ 'block_number_mismatch',
126
+ ],
118
127
  },
119
128
  );
120
129
 
121
- this.requiredAttestions = this.meter.createGauge(Metrics.SEQUENCER_REQUIRED_ATTESTATIONS_COUNT, {
122
- valueType: ValueType.INT,
123
- description: 'The minimum number of attestations required to publish a block',
124
- });
130
+ this.slashingAttempts = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_SLASHING_ATTEMPTS_COUNT);
125
131
 
126
- this.collectedAttestions = this.meter.createGauge(Metrics.SEQUENCER_COLLECTED_ATTESTATIONS_COUNT, {
127
- valueType: ValueType.INT,
128
- description: 'The minimum number of attestations required to publish a block',
129
- });
132
+ // Fisherman fee analysis metrics
133
+ this.fishermanWouldBeIncluded = createUpDownCounterWithDefault(
134
+ this.meter,
135
+ Metrics.FISHERMAN_FEE_ANALYSIS_WOULD_BE_INCLUDED,
136
+ {
137
+ [Attributes.OK]: [true, false],
138
+ [Attributes.BLOCK_FULL]: ['true', 'false'],
139
+ },
140
+ );
130
141
 
131
- this.blockProposalFailed = this.meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_PROPOSAL_FAILED_COUNT, {
132
- valueType: ValueType.INT,
133
- description: 'The number of times block proposal failed (including validation builds)',
134
- });
142
+ this.fishermanTimeBeforeBlock = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_TIME_BEFORE_BLOCK);
135
143
 
136
- this.blockProposalSuccess = this.meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_PROPOSAL_SUCCESS_COUNT, {
137
- valueType: ValueType.INT,
138
- description: 'The number of times block proposal succeeded (including validation builds)',
139
- });
144
+ this.fishermanPendingBlobTxCount = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_PENDING_BLOB_TX_COUNT);
140
145
 
141
- this.blockProposalPrecheckFailed = this.meter.createUpDownCounter(
142
- Metrics.SEQUENCER_BLOCK_PROPOSAL_PRECHECK_FAILED_COUNT,
146
+ this.fishermanIncludedBlobTxCount = this.meter.createHistogram(
147
+ Metrics.FISHERMAN_FEE_ANALYSIS_INCLUDED_BLOB_TX_COUNT,
148
+ );
149
+
150
+ this.fishermanCalculatedPriorityFee = this.meter.createHistogram(
151
+ Metrics.FISHERMAN_FEE_ANALYSIS_CALCULATED_PRIORITY_FEE,
152
+ );
153
+
154
+ this.fishermanPriorityFeeDelta = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_PRIORITY_FEE_DELTA);
155
+
156
+ this.fishermanEstimatedCost = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_ESTIMATED_COST);
157
+
158
+ this.fishermanEstimatedOverpayment = this.meter.createHistogram(
159
+ Metrics.FISHERMAN_FEE_ANALYSIS_ESTIMATED_OVERPAYMENT,
160
+ );
161
+
162
+ this.fishermanMinedBlobTxPriorityFee = this.meter.createHistogram(
163
+ Metrics.FISHERMAN_FEE_ANALYSIS_MINED_BLOB_TX_PRIORITY_FEE,
164
+ );
165
+
166
+ this.fishermanMinedBlobTxTotalCost = this.meter.createHistogram(
167
+ Metrics.FISHERMAN_FEE_ANALYSIS_MINED_BLOB_TX_TOTAL_COST,
168
+ );
169
+
170
+ this.fishermanPendingBlobCount = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_PENDING_BLOB_COUNT);
171
+
172
+ this.fishermanIncludedBlobCount = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_INCLUDED_BLOB_COUNT);
173
+
174
+ this.fishermanBlockBlobsFull = createUpDownCounterWithDefault(
175
+ this.meter,
176
+ Metrics.FISHERMAN_FEE_ANALYSIS_BLOCK_BLOBS_FULL,
143
177
  {
144
- valueType: ValueType.INT,
145
- description: 'The number of times block proposal pre-build checks failed',
178
+ [Attributes.OK]: [true, false],
146
179
  },
147
180
  );
148
181
 
149
- this.slashingAttempts = this.meter.createUpDownCounter(Metrics.SEQUENCER_SLASHING_ATTEMPTS_COUNT, {
150
- valueType: ValueType.INT,
151
- description: 'The number of slashing action attempts',
152
- });
182
+ this.fishermanMaxBlobCapacity = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_MAX_BLOB_CAPACITY);
153
183
  }
154
184
 
155
185
  public recordRequiredAttestations(requiredAttestationsCount: number, allowanceMs: number) {
@@ -161,6 +191,10 @@ export class SequencerMetrics {
161
191
  this.timeToCollectAttestations.record(0);
162
192
  }
163
193
 
194
+ public recordCheckpointAttestationDelay(duration: number) {
195
+ this.checkpointAttestationDelay.record(duration);
196
+ }
197
+
164
198
  public recordCollectedAttestations(count: number, durationMs: number) {
165
199
  this.collectedAttestions.record(count);
166
200
  this.timeToCollectAttestations.record(Math.ceil(durationMs));
@@ -218,6 +252,10 @@ export class SequencerMetrics {
218
252
  }
219
253
  }
220
254
 
255
+ recordCheckpointSuccess() {
256
+ this.checkpointSuccess.add(1);
257
+ }
258
+
221
259
  recordBlockProposalFailed(reason?: string) {
222
260
  this.blockProposalFailed.add(1, {
223
261
  ...(reason && { [Attributes.ERROR_TYPE]: reason }),
@@ -228,7 +266,9 @@ export class SequencerMetrics {
228
266
  this.blockProposalSuccess.add(1);
229
267
  }
230
268
 
231
- recordBlockProposalPrecheckFailed(checkType: string) {
269
+ recordBlockProposalPrecheckFailed(
270
+ checkType: 'slot_already_taken' | 'rollup_contract_check_failed' | 'slot_mismatch' | 'block_number_mismatch',
271
+ ) {
232
272
  this.blockProposalPrecheckFailed.add(1, {
233
273
  [Attributes.ERROR_TYPE]: checkType,
234
274
  });
@@ -237,4 +277,124 @@ export class SequencerMetrics {
237
277
  recordSlashingAttempt(actionCount: number) {
238
278
  this.slashingAttempts.add(actionCount);
239
279
  }
280
+
281
+ /**
282
+ * Records metrics for a completed fisherman fee analysis
283
+ * @param analysis - The completed fee analysis result
284
+ */
285
+ recordFishermanFeeAnalysis(analysis: L1FeeAnalysisResult) {
286
+ // In fisherman mode, we should always have strategy results
287
+ if (!analysis.computedPrices.strategyResults || analysis.computedPrices.strategyResults.length === 0) {
288
+ // This should never happen in fisherman mode - log an error
289
+ // We don't record metrics without strategy IDs as that defeats the purpose
290
+ throw new Error(
291
+ `No strategy results found in fisherman fee analysis ${analysis.id}. This indicates a bug in the fee analysis.`,
292
+ );
293
+ }
294
+
295
+ // Record metrics for each strategy separately
296
+ for (const strategyResult of analysis.computedPrices.strategyResults) {
297
+ const strategyAttributes = {
298
+ [Attributes.FISHERMAN_FEE_STRATEGY_ID]: strategyResult.strategyId,
299
+ };
300
+
301
+ // Record pending block snapshot data (once per strategy for comparison)
302
+ this.fishermanPendingBlobTxCount.record(analysis.pendingSnapshot.pendingBlobTxCount, strategyAttributes);
303
+ this.fishermanPendingBlobCount.record(analysis.pendingSnapshot.pendingBlobCount, strategyAttributes);
304
+
305
+ // Record mined block data if available
306
+ if (analysis.minedBlock) {
307
+ this.fishermanIncludedBlobTxCount.record(analysis.minedBlock.includedBlobTxCount, strategyAttributes);
308
+ this.fishermanIncludedBlobCount.record(analysis.minedBlock.includedBlobCount, strategyAttributes);
309
+
310
+ // Record actual fees from blob transactions in the mined block
311
+ for (const blobTx of analysis.minedBlock.includedBlobTxs) {
312
+ // Record priority fee per gas in Gwei
313
+ const priorityFeeGwei = Number(blobTx.maxPriorityFeePerGas) / 1e9;
314
+ this.fishermanMinedBlobTxPriorityFee.record(priorityFeeGwei, strategyAttributes);
315
+
316
+ // Calculate total cost in ETH
317
+ // Cost = (gas * (baseFee + priorityFee)) + (blobCount * blobGasPerBlob * blobBaseFee)
318
+ const baseFee = analysis.minedBlock.baseFeePerGas;
319
+ const effectiveGasPrice = baseFee + blobTx.maxPriorityFeePerGas;
320
+
321
+ // Calculate execution cost using actual gas limit from the transaction
322
+ const executionCost = blobTx.gas * effectiveGasPrice;
323
+
324
+ // Calculate blob cost using maxFeePerBlobGas * blobCount * GAS_PER_BLOB
325
+ const blobCost = blobTx.maxFeePerBlobGas * BigInt(blobTx.blobCount) * 131072n; // 128KB per blob
326
+
327
+ const totalCostWei = executionCost + blobCost;
328
+ const totalCostEth = Number(totalCostWei) / 1e18;
329
+
330
+ this.fishermanMinedBlobTxTotalCost.record(totalCostEth, strategyAttributes);
331
+ }
332
+ }
333
+
334
+ // Record the calculated priority fee for this strategy
335
+ const calculatedPriorityFeeGwei = Number(strategyResult.calculatedPriorityFee) / 1e9;
336
+ this.fishermanCalculatedPriorityFee.record(calculatedPriorityFeeGwei, strategyAttributes);
337
+
338
+ // Record analysis results if available
339
+ if (analysis.analysis) {
340
+ this.fishermanTimeBeforeBlock.record(Math.ceil(analysis.analysis.timeBeforeBlockMs), strategyAttributes);
341
+
342
+ // Record whether the block reached 100% blob capacity
343
+ if (analysis.analysis.blockBlobsFull) {
344
+ this.fishermanBlockBlobsFull.add(1, { ...strategyAttributes, [Attributes.OK]: true });
345
+ } else {
346
+ this.fishermanBlockBlobsFull.add(1, { ...strategyAttributes, [Attributes.OK]: false });
347
+ }
348
+
349
+ // Record the max blob capacity for this block
350
+ this.fishermanMaxBlobCapacity.record(analysis.analysis.maxBlobCapacity, strategyAttributes);
351
+
352
+ // Record strategy-specific inclusion result
353
+ if (strategyResult.wouldBeIncluded !== undefined) {
354
+ const inclusionAttributes = {
355
+ ...strategyAttributes,
356
+ [Attributes.BLOCK_FULL]: analysis.analysis.blockBlobsFull ? 'true' : 'false',
357
+ };
358
+
359
+ if (strategyResult.wouldBeIncluded) {
360
+ this.fishermanWouldBeIncluded.add(1, { ...inclusionAttributes, [Attributes.OK]: true });
361
+ } else {
362
+ this.fishermanWouldBeIncluded.add(1, {
363
+ ...inclusionAttributes,
364
+ [Attributes.OK]: false,
365
+ ...(strategyResult.exclusionReason && { [Attributes.ERROR_TYPE]: strategyResult.exclusionReason }),
366
+ });
367
+ }
368
+ }
369
+
370
+ // Record strategy-specific priority fee delta
371
+ if (strategyResult.priorityFeeDelta !== undefined) {
372
+ const priorityFeeDeltaGwei = Number(strategyResult.priorityFeeDelta) / 1e9;
373
+ const deltaAttributes = {
374
+ ...strategyAttributes,
375
+ [Attributes.BLOCK_FULL]: analysis.analysis.blockBlobsFull ? 'true' : 'false',
376
+ };
377
+ this.fishermanPriorityFeeDelta.record(priorityFeeDeltaGwei, deltaAttributes);
378
+ }
379
+
380
+ // Record estimated cost if available
381
+ if (strategyResult.estimatedCostEth !== undefined) {
382
+ const costAttributes = {
383
+ ...strategyAttributes,
384
+ [Attributes.BLOCK_FULL]: analysis.analysis.blockBlobsFull ? 'true' : 'false',
385
+ };
386
+ this.fishermanEstimatedCost.record(strategyResult.estimatedCostEth, costAttributes);
387
+ }
388
+
389
+ // Record estimated overpayment if available
390
+ if (strategyResult.estimatedOverpaymentEth !== undefined) {
391
+ const overpaymentAttributes = {
392
+ ...strategyAttributes,
393
+ [Attributes.BLOCK_FULL]: analysis.analysis.blockBlobsFull ? 'true' : 'false',
394
+ };
395
+ this.fishermanEstimatedOverpayment.record(strategyResult.estimatedOverpaymentEth, overpaymentAttributes);
396
+ }
397
+ }
398
+ }
399
+ }
240
400
  }