@aztec/sequencer-client 0.0.1-commit.9b94fc1 → 0.0.1-commit.9ee6fcc6

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 (118) hide show
  1. package/dest/client/sequencer-client.d.ts +24 -16
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +73 -32
  4. package/dest/config.d.ts +35 -9
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +106 -44
  7. package/dest/global_variable_builder/global_builder.d.ts +27 -14
  8. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  9. package/dest/global_variable_builder/global_builder.js +65 -54
  10. package/dest/global_variable_builder/index.d.ts +2 -2
  11. package/dest/global_variable_builder/index.d.ts.map +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 +53 -20
  16. package/dest/publisher/config.d.ts.map +1 -1
  17. package/dest/publisher/config.js +124 -39
  18. package/dest/publisher/index.d.ts +2 -1
  19. package/dest/publisher/index.d.ts.map +1 -1
  20. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  21. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  22. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  23. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +59 -0
  24. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  25. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
  26. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  27. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  28. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
  29. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  30. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  31. package/dest/publisher/l1_tx_failed_store/index.js +2 -0
  32. package/dest/publisher/sequencer-publisher-factory.d.ts +15 -6
  33. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  34. package/dest/publisher/sequencer-publisher-factory.js +28 -3
  35. package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
  36. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  37. package/dest/publisher/sequencer-publisher-metrics.js +23 -86
  38. package/dest/publisher/sequencer-publisher.d.ts +79 -49
  39. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  40. package/dest/publisher/sequencer-publisher.js +932 -155
  41. package/dest/sequencer/checkpoint_proposal_job.d.ts +108 -0
  42. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  43. package/dest/sequencer/checkpoint_proposal_job.js +1289 -0
  44. package/dest/sequencer/checkpoint_voter.d.ts +35 -0
  45. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  46. package/dest/sequencer/checkpoint_voter.js +109 -0
  47. package/dest/sequencer/config.d.ts +3 -2
  48. package/dest/sequencer/config.d.ts.map +1 -1
  49. package/dest/sequencer/events.d.ts +47 -0
  50. package/dest/sequencer/events.d.ts.map +1 -0
  51. package/dest/sequencer/events.js +1 -0
  52. package/dest/sequencer/index.d.ts +4 -2
  53. package/dest/sequencer/index.d.ts.map +1 -1
  54. package/dest/sequencer/index.js +3 -1
  55. package/dest/sequencer/metrics.d.ts +42 -6
  56. package/dest/sequencer/metrics.d.ts.map +1 -1
  57. package/dest/sequencer/metrics.js +227 -72
  58. package/dest/sequencer/sequencer.d.ts +125 -134
  59. package/dest/sequencer/sequencer.d.ts.map +1 -1
  60. package/dest/sequencer/sequencer.js +754 -652
  61. package/dest/sequencer/timetable.d.ts +54 -16
  62. package/dest/sequencer/timetable.d.ts.map +1 -1
  63. package/dest/sequencer/timetable.js +147 -62
  64. package/dest/sequencer/types.d.ts +3 -0
  65. package/dest/sequencer/types.d.ts.map +1 -0
  66. package/dest/sequencer/types.js +1 -0
  67. package/dest/sequencer/utils.d.ts +14 -8
  68. package/dest/sequencer/utils.d.ts.map +1 -1
  69. package/dest/sequencer/utils.js +7 -4
  70. package/dest/test/index.d.ts +6 -7
  71. package/dest/test/index.d.ts.map +1 -1
  72. package/dest/test/mock_checkpoint_builder.d.ts +95 -0
  73. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  74. package/dest/test/mock_checkpoint_builder.js +231 -0
  75. package/dest/test/utils.d.ts +53 -0
  76. package/dest/test/utils.d.ts.map +1 -0
  77. package/dest/test/utils.js +104 -0
  78. package/package.json +31 -30
  79. package/src/client/sequencer-client.ts +97 -55
  80. package/src/config.ts +124 -53
  81. package/src/global_variable_builder/global_builder.ts +76 -73
  82. package/src/global_variable_builder/index.ts +1 -1
  83. package/src/index.ts +1 -7
  84. package/src/publisher/config.ts +163 -50
  85. package/src/publisher/index.ts +3 -0
  86. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  87. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +55 -0
  88. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  89. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  90. package/src/publisher/sequencer-publisher-factory.ts +43 -10
  91. package/src/publisher/sequencer-publisher-metrics.ts +19 -71
  92. package/src/publisher/sequencer-publisher.ts +635 -200
  93. package/src/sequencer/README.md +531 -0
  94. package/src/sequencer/checkpoint_proposal_job.ts +1049 -0
  95. package/src/sequencer/checkpoint_voter.ts +130 -0
  96. package/src/sequencer/config.ts +2 -1
  97. package/src/sequencer/events.ts +27 -0
  98. package/src/sequencer/index.ts +3 -1
  99. package/src/sequencer/metrics.ts +282 -82
  100. package/src/sequencer/sequencer.ts +521 -859
  101. package/src/sequencer/timetable.ts +178 -83
  102. package/src/sequencer/types.ts +6 -0
  103. package/src/sequencer/utils.ts +18 -9
  104. package/src/test/index.ts +5 -6
  105. package/src/test/mock_checkpoint_builder.ts +323 -0
  106. package/src/test/utils.ts +167 -0
  107. package/dest/sequencer/block_builder.d.ts +0 -27
  108. package/dest/sequencer/block_builder.d.ts.map +0 -1
  109. package/dest/sequencer/block_builder.js +0 -134
  110. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  111. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  112. package/dest/tx_validator/nullifier_cache.js +0 -24
  113. package/dest/tx_validator/tx_validator_factory.d.ts +0 -17
  114. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  115. package/dest/tx_validator/tx_validator_factory.js +0 -53
  116. package/src/sequencer/block_builder.ts +0 -222
  117. package/src/tx_validator/nullifier_cache.ts +0 -30
  118. 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; buildSlot: 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,7 +11,7 @@ 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';
@@ -38,9 +39,34 @@ export class SequencerMetrics {
38
39
  private filledSlots: UpDownCounter;
39
40
 
40
41
  private blockProposalFailed: UpDownCounter;
41
- private blockProposalSuccess: UpDownCounter;
42
- private blockProposalPrecheckFailed: UpDownCounter;
42
+ private checkpointProposalSuccess: UpDownCounter;
43
+ private checkpointPrecheckFailed: UpDownCounter;
44
+ private checkpointProposalFailed: UpDownCounter;
45
+ private checkpointSuccess: UpDownCounter;
43
46
  private slashingAttempts: UpDownCounter;
47
+ private checkpointAttestationDelay: Histogram;
48
+ private checkpointBuildDuration: Histogram;
49
+ private checkpointBlockCount: Gauge;
50
+ private checkpointTxCount: Gauge;
51
+ private checkpointTotalMana: Gauge;
52
+ private pipelineDepth: Gauge;
53
+ private pipelineDiscards: UpDownCounter;
54
+
55
+ // Fisherman fee analysis metrics
56
+ private fishermanWouldBeIncluded: UpDownCounter;
57
+ private fishermanTimeBeforeBlock: Histogram;
58
+ private fishermanPendingBlobTxCount: Histogram;
59
+ private fishermanIncludedBlobTxCount: Histogram;
60
+ private fishermanPendingBlobCount: Histogram;
61
+ private fishermanIncludedBlobCount: Histogram;
62
+ private fishermanBlockBlobsFull: UpDownCounter;
63
+ private fishermanMaxBlobCapacity: Histogram;
64
+ private fishermanCalculatedPriorityFee: Histogram;
65
+ private fishermanPriorityFeeDelta: Histogram;
66
+ private fishermanEstimatedCost: Histogram;
67
+ private fishermanEstimatedOverpayment: Histogram;
68
+ private fishermanMinedBlobTxPriorityFee: Histogram;
69
+ private fishermanMinedBlobTxTotalCost: Histogram;
44
70
 
45
71
  private lastSeenSlot?: SlotNumber;
46
72
 
@@ -52,104 +78,128 @@ export class SequencerMetrics {
52
78
  this.meter = client.getMeter(name);
53
79
  this.tracer = client.getTracer(name);
54
80
 
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,
81
+ this.blockCounter = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_BLOCK_COUNT, {
82
+ [Attributes.STATUS]: ['failed', 'built'],
61
83
  });
62
84
 
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
- });
85
+ this.blockBuildDuration = this.meter.createHistogram(Metrics.SEQUENCER_BLOCK_BUILD_DURATION);
68
86
 
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
- );
87
+ this.blockBuildManaPerSecond = this.meter.createGauge(Metrics.SEQUENCER_BLOCK_BUILD_MANA_PER_SECOND);
78
88
 
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
- });
89
+ this.stateTransitionBufferDuration = this.meter.createHistogram(Metrics.SEQUENCER_STATE_TRANSITION_BUFFER_DURATION);
86
90
 
87
- this.rewards = this.meter.createGauge(Metrics.SEQUENCER_CURRENT_BLOCK_REWARDS, {
88
- valueType: ValueType.DOUBLE,
89
- description: 'The rewards earned',
90
- });
91
+ this.checkpointAttestationDelay = this.meter.createHistogram(Metrics.SEQUENCER_CHECKPOINT_ATTESTATION_DELAY);
91
92
 
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
- });
93
+ this.rewards = this.meter.createGauge(Metrics.SEQUENCER_CURRENT_SLOT_REWARDS);
94
+
95
+ this.slots = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_SLOT_COUNT);
96
96
 
97
97
  /**
98
98
  * NOTE: we do not track missed slots as a separate metric. That would be difficult to determine
99
99
  * Instead, use a computed metric, `slots - filledSlots` to get the number of slots a sequencer has missed.
100
100
  */
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
- });
101
+ this.filledSlots = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_FILLED_SLOT_COUNT);
105
102
 
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
- });
103
+ this.timeToCollectAttestations = this.meter.createGauge(Metrics.SEQUENCER_COLLECT_ATTESTATIONS_DURATION);
104
+
105
+ this.allowanceToCollectAttestations = this.meter.createGauge(Metrics.SEQUENCER_COLLECT_ATTESTATIONS_TIME_ALLOWANCE);
111
106
 
112
- this.allowanceToCollectAttestations = this.meter.createGauge(
113
- Metrics.SEQUENCER_COLLECT_ATTESTATIONS_TIME_ALLOWANCE,
107
+ this.requiredAttestions = this.meter.createGauge(Metrics.SEQUENCER_REQUIRED_ATTESTATIONS_COUNT);
108
+
109
+ this.collectedAttestions = this.meter.createGauge(Metrics.SEQUENCER_COLLECTED_ATTESTATIONS_COUNT);
110
+
111
+ this.blockProposalFailed = createUpDownCounterWithDefault(
112
+ this.meter,
113
+ Metrics.SEQUENCER_BLOCK_PROPOSAL_FAILED_COUNT,
114
+ );
115
+
116
+ this.checkpointProposalSuccess = createUpDownCounterWithDefault(
117
+ this.meter,
118
+ Metrics.SEQUENCER_CHECKPOINT_PROPOSAL_SUCCESS_COUNT,
119
+ );
120
+
121
+ this.checkpointSuccess = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_CHECKPOINT_SUCCESS_COUNT);
122
+
123
+ this.checkpointPrecheckFailed = createUpDownCounterWithDefault(
124
+ this.meter,
125
+ Metrics.SEQUENCER_CHECKPOINT_PRECHECK_FAILED_COUNT,
114
126
  {
115
- description: 'Maximum amount of time to collect attestations',
116
- unit: 'ms',
117
- valueType: ValueType.INT,
127
+ [Attributes.ERROR_TYPE]: [
128
+ 'slot_already_taken',
129
+ 'rollup_contract_check_failed',
130
+ 'slot_mismatch',
131
+ 'block_number_mismatch',
132
+ ],
118
133
  },
119
134
  );
120
135
 
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
- });
136
+ this.checkpointProposalFailed = createUpDownCounterWithDefault(
137
+ this.meter,
138
+ Metrics.SEQUENCER_CHECKPOINT_PROPOSAL_FAILED_COUNT,
139
+ );
125
140
 
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
- });
141
+ this.checkpointBuildDuration = this.meter.createHistogram(Metrics.SEQUENCER_CHECKPOINT_BUILD_DURATION);
142
+ this.checkpointBlockCount = this.meter.createGauge(Metrics.SEQUENCER_CHECKPOINT_BLOCK_COUNT);
143
+ this.checkpointTxCount = this.meter.createGauge(Metrics.SEQUENCER_CHECKPOINT_TX_COUNT);
144
+ this.checkpointTotalMana = this.meter.createGauge(Metrics.SEQUENCER_CHECKPOINT_TOTAL_MANA);
130
145
 
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
- });
146
+ this.slashingAttempts = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_SLASHING_ATTEMPTS_COUNT);
135
147
 
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
- });
148
+ this.pipelineDepth = this.meter.createGauge(Metrics.SEQUENCER_PIPELINE_DEPTH);
149
+ this.pipelineDiscards = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_PIPELINE_DISCARDS_COUNT);
150
+ this.pipelineDepth.record(0);
140
151
 
141
- this.blockProposalPrecheckFailed = this.meter.createUpDownCounter(
142
- Metrics.SEQUENCER_BLOCK_PROPOSAL_PRECHECK_FAILED_COUNT,
152
+ // Fisherman fee analysis metrics
153
+ this.fishermanWouldBeIncluded = createUpDownCounterWithDefault(
154
+ this.meter,
155
+ Metrics.FISHERMAN_FEE_ANALYSIS_WOULD_BE_INCLUDED,
143
156
  {
144
- valueType: ValueType.INT,
145
- description: 'The number of times block proposal pre-build checks failed',
157
+ [Attributes.OK]: [true, false],
158
+ [Attributes.BLOCK_FULL]: ['true', 'false'],
146
159
  },
147
160
  );
148
161
 
149
- this.slashingAttempts = this.meter.createUpDownCounter(Metrics.SEQUENCER_SLASHING_ATTEMPTS_COUNT, {
150
- valueType: ValueType.INT,
151
- description: 'The number of slashing action attempts',
152
- });
162
+ this.fishermanTimeBeforeBlock = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_TIME_BEFORE_BLOCK);
163
+
164
+ this.fishermanPendingBlobTxCount = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_PENDING_BLOB_TX_COUNT);
165
+
166
+ this.fishermanIncludedBlobTxCount = this.meter.createHistogram(
167
+ Metrics.FISHERMAN_FEE_ANALYSIS_INCLUDED_BLOB_TX_COUNT,
168
+ );
169
+
170
+ this.fishermanCalculatedPriorityFee = this.meter.createHistogram(
171
+ Metrics.FISHERMAN_FEE_ANALYSIS_CALCULATED_PRIORITY_FEE,
172
+ );
173
+
174
+ this.fishermanPriorityFeeDelta = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_PRIORITY_FEE_DELTA);
175
+
176
+ this.fishermanEstimatedCost = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_ESTIMATED_COST);
177
+
178
+ this.fishermanEstimatedOverpayment = this.meter.createHistogram(
179
+ Metrics.FISHERMAN_FEE_ANALYSIS_ESTIMATED_OVERPAYMENT,
180
+ );
181
+
182
+ this.fishermanMinedBlobTxPriorityFee = this.meter.createHistogram(
183
+ Metrics.FISHERMAN_FEE_ANALYSIS_MINED_BLOB_TX_PRIORITY_FEE,
184
+ );
185
+
186
+ this.fishermanMinedBlobTxTotalCost = this.meter.createHistogram(
187
+ Metrics.FISHERMAN_FEE_ANALYSIS_MINED_BLOB_TX_TOTAL_COST,
188
+ );
189
+
190
+ this.fishermanPendingBlobCount = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_PENDING_BLOB_COUNT);
191
+
192
+ this.fishermanIncludedBlobCount = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_INCLUDED_BLOB_COUNT);
193
+
194
+ this.fishermanBlockBlobsFull = createUpDownCounterWithDefault(
195
+ this.meter,
196
+ Metrics.FISHERMAN_FEE_ANALYSIS_BLOCK_BLOBS_FULL,
197
+ {
198
+ [Attributes.OK]: [true, false],
199
+ },
200
+ );
201
+
202
+ this.fishermanMaxBlobCapacity = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_MAX_BLOB_CAPACITY);
153
203
  }
154
204
 
155
205
  public recordRequiredAttestations(requiredAttestationsCount: number, allowanceMs: number) {
@@ -161,6 +211,10 @@ export class SequencerMetrics {
161
211
  this.timeToCollectAttestations.record(0);
162
212
  }
163
213
 
214
+ public recordCheckpointAttestationDelay(duration: number) {
215
+ this.checkpointAttestationDelay.record(duration);
216
+ }
217
+
164
218
  public recordCollectedAttestations(count: number, durationMs: number) {
165
219
  this.collectedAttestions.record(count);
166
220
  this.timeToCollectAttestations.record(Math.ceil(durationMs));
@@ -186,6 +240,14 @@ export class SequencerMetrics {
186
240
  });
187
241
  }
188
242
 
243
+ recordPipelineDepth(depth: number) {
244
+ this.pipelineDepth.record(depth);
245
+ }
246
+
247
+ recordPipelineDiscard(count = 1) {
248
+ this.pipelineDiscards.add(count);
249
+ }
250
+
189
251
  incOpenSlot(slot: SlotNumber, proposer: string) {
190
252
  // sequencer went through the loop a second time. Noop
191
253
  if (slot === this.lastSeenSlot) {
@@ -218,23 +280,161 @@ export class SequencerMetrics {
218
280
  }
219
281
  }
220
282
 
283
+ recordCheckpointSuccess() {
284
+ this.checkpointSuccess.add(1);
285
+ }
286
+
221
287
  recordBlockProposalFailed(reason?: string) {
222
288
  this.blockProposalFailed.add(1, {
223
289
  ...(reason && { [Attributes.ERROR_TYPE]: reason }),
224
290
  });
225
291
  }
226
292
 
227
- recordBlockProposalSuccess() {
228
- this.blockProposalSuccess.add(1);
293
+ recordCheckpointProposalSuccess() {
294
+ this.checkpointProposalSuccess.add(1);
295
+ }
296
+
297
+ recordCheckpointPrecheckFailed(
298
+ checkType: 'slot_already_taken' | 'rollup_contract_check_failed' | 'slot_mismatch' | 'block_number_mismatch',
299
+ ) {
300
+ this.checkpointPrecheckFailed.add(1, { [Attributes.ERROR_TYPE]: checkType });
229
301
  }
230
302
 
231
- recordBlockProposalPrecheckFailed(checkType: string) {
232
- this.blockProposalPrecheckFailed.add(1, {
233
- [Attributes.ERROR_TYPE]: checkType,
303
+ recordCheckpointProposalFailed(reason?: string) {
304
+ this.checkpointProposalFailed.add(1, {
305
+ ...(reason && { [Attributes.ERROR_TYPE]: reason }),
234
306
  });
235
307
  }
236
308
 
309
+ /** Records aggregate metrics for a completed checkpoint build. */
310
+ recordCheckpointBuild(durationMs: number, blockCount: number, txCount: number, totalMana: number) {
311
+ this.checkpointBuildDuration.record(Math.ceil(durationMs));
312
+ this.checkpointBlockCount.record(blockCount);
313
+ this.checkpointTxCount.record(txCount);
314
+ this.checkpointTotalMana.record(totalMana);
315
+ }
316
+
237
317
  recordSlashingAttempt(actionCount: number) {
238
318
  this.slashingAttempts.add(actionCount);
239
319
  }
320
+
321
+ /**
322
+ * Records metrics for a completed fisherman fee analysis
323
+ * @param analysis - The completed fee analysis result
324
+ */
325
+ recordFishermanFeeAnalysis(analysis: L1FeeAnalysisResult) {
326
+ // In fisherman mode, we should always have strategy results
327
+ if (!analysis.computedPrices.strategyResults || analysis.computedPrices.strategyResults.length === 0) {
328
+ // This should never happen in fisherman mode - log an error
329
+ // We don't record metrics without strategy IDs as that defeats the purpose
330
+ throw new Error(
331
+ `No strategy results found in fisherman fee analysis ${analysis.id}. This indicates a bug in the fee analysis.`,
332
+ );
333
+ }
334
+
335
+ // Record metrics for each strategy separately
336
+ for (const strategyResult of analysis.computedPrices.strategyResults) {
337
+ const strategyAttributes = {
338
+ [Attributes.FISHERMAN_FEE_STRATEGY_ID]: strategyResult.strategyId,
339
+ };
340
+
341
+ // Record pending block snapshot data (once per strategy for comparison)
342
+ this.fishermanPendingBlobTxCount.record(analysis.pendingSnapshot.pendingBlobTxCount, strategyAttributes);
343
+ this.fishermanPendingBlobCount.record(analysis.pendingSnapshot.pendingBlobCount, strategyAttributes);
344
+
345
+ // Record mined block data if available
346
+ if (analysis.minedBlock) {
347
+ this.fishermanIncludedBlobTxCount.record(analysis.minedBlock.includedBlobTxCount, strategyAttributes);
348
+ this.fishermanIncludedBlobCount.record(analysis.minedBlock.includedBlobCount, strategyAttributes);
349
+
350
+ // Record actual fees from blob transactions in the mined block
351
+ for (const blobTx of analysis.minedBlock.includedBlobTxs) {
352
+ // Record priority fee per gas in Gwei
353
+ const priorityFeeGwei = Number(blobTx.maxPriorityFeePerGas) / 1e9;
354
+ this.fishermanMinedBlobTxPriorityFee.record(priorityFeeGwei, strategyAttributes);
355
+
356
+ // Calculate total cost in ETH
357
+ // Cost = (gas * (baseFee + priorityFee)) + (blobCount * blobGasPerBlob * blobBaseFee)
358
+ const baseFee = analysis.minedBlock.baseFeePerGas;
359
+ const effectiveGasPrice = baseFee + blobTx.maxPriorityFeePerGas;
360
+
361
+ // Calculate execution cost using actual gas limit from the transaction
362
+ const executionCost = blobTx.gas * effectiveGasPrice;
363
+
364
+ // Calculate blob cost using maxFeePerBlobGas * blobCount * GAS_PER_BLOB
365
+ const blobCost = blobTx.maxFeePerBlobGas * BigInt(blobTx.blobCount) * 131072n; // 128KB per blob
366
+
367
+ const totalCostWei = executionCost + blobCost;
368
+ const totalCostEth = Number(totalCostWei) / 1e18;
369
+
370
+ this.fishermanMinedBlobTxTotalCost.record(totalCostEth, strategyAttributes);
371
+ }
372
+ }
373
+
374
+ // Record the calculated priority fee for this strategy
375
+ const calculatedPriorityFeeGwei = Number(strategyResult.calculatedPriorityFee) / 1e9;
376
+ this.fishermanCalculatedPriorityFee.record(calculatedPriorityFeeGwei, strategyAttributes);
377
+
378
+ // Record analysis results if available
379
+ if (analysis.analysis) {
380
+ this.fishermanTimeBeforeBlock.record(Math.ceil(analysis.analysis.timeBeforeBlockMs), strategyAttributes);
381
+
382
+ // Record whether the block reached 100% blob capacity
383
+ if (analysis.analysis.blockBlobsFull) {
384
+ this.fishermanBlockBlobsFull.add(1, { ...strategyAttributes, [Attributes.OK]: true });
385
+ } else {
386
+ this.fishermanBlockBlobsFull.add(1, { ...strategyAttributes, [Attributes.OK]: false });
387
+ }
388
+
389
+ // Record the max blob capacity for this block
390
+ this.fishermanMaxBlobCapacity.record(analysis.analysis.maxBlobCapacity, strategyAttributes);
391
+
392
+ // Record strategy-specific inclusion result
393
+ if (strategyResult.wouldBeIncluded !== undefined) {
394
+ const inclusionAttributes = {
395
+ ...strategyAttributes,
396
+ [Attributes.BLOCK_FULL]: analysis.analysis.blockBlobsFull ? 'true' : 'false',
397
+ };
398
+
399
+ if (strategyResult.wouldBeIncluded) {
400
+ this.fishermanWouldBeIncluded.add(1, { ...inclusionAttributes, [Attributes.OK]: true });
401
+ } else {
402
+ this.fishermanWouldBeIncluded.add(1, {
403
+ ...inclusionAttributes,
404
+ [Attributes.OK]: false,
405
+ ...(strategyResult.exclusionReason && { [Attributes.ERROR_TYPE]: strategyResult.exclusionReason }),
406
+ });
407
+ }
408
+ }
409
+
410
+ // Record strategy-specific priority fee delta
411
+ if (strategyResult.priorityFeeDelta !== undefined) {
412
+ const priorityFeeDeltaGwei = Number(strategyResult.priorityFeeDelta) / 1e9;
413
+ const deltaAttributes = {
414
+ ...strategyAttributes,
415
+ [Attributes.BLOCK_FULL]: analysis.analysis.blockBlobsFull ? 'true' : 'false',
416
+ };
417
+ this.fishermanPriorityFeeDelta.record(priorityFeeDeltaGwei, deltaAttributes);
418
+ }
419
+
420
+ // Record estimated cost if available
421
+ if (strategyResult.estimatedCostEth !== undefined) {
422
+ const costAttributes = {
423
+ ...strategyAttributes,
424
+ [Attributes.BLOCK_FULL]: analysis.analysis.blockBlobsFull ? 'true' : 'false',
425
+ };
426
+ this.fishermanEstimatedCost.record(strategyResult.estimatedCostEth, costAttributes);
427
+ }
428
+
429
+ // Record estimated overpayment if available
430
+ if (strategyResult.estimatedOverpaymentEth !== undefined) {
431
+ const overpaymentAttributes = {
432
+ ...strategyAttributes,
433
+ [Attributes.BLOCK_FULL]: analysis.analysis.blockBlobsFull ? 'true' : 'false',
434
+ };
435
+ this.fishermanEstimatedOverpayment.record(strategyResult.estimatedOverpaymentEth, overpaymentAttributes);
436
+ }
437
+ }
438
+ }
439
+ }
240
440
  }