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

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 (119) hide show
  1. package/dest/client/index.d.ts +1 -1
  2. package/dest/client/sequencer-client.d.ts +21 -16
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +75 -28
  5. package/dest/config.d.ts +35 -9
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +113 -42
  8. package/dest/global_variable_builder/global_builder.d.ts +20 -16
  9. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  10. package/dest/global_variable_builder/global_builder.js +54 -40
  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 +43 -20
  16. package/dest/publisher/config.d.ts.map +1 -1
  17. package/dest/publisher/config.js +109 -34
  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 +103 -69
  39. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  40. package/dest/publisher/sequencer-publisher.js +999 -190
  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/errors.d.ts +1 -1
  50. package/dest/sequencer/errors.d.ts.map +1 -1
  51. package/dest/sequencer/events.d.ts +47 -0
  52. package/dest/sequencer/events.d.ts.map +1 -0
  53. package/dest/sequencer/events.js +1 -0
  54. package/dest/sequencer/index.d.ts +4 -2
  55. package/dest/sequencer/index.d.ts.map +1 -1
  56. package/dest/sequencer/index.js +3 -1
  57. package/dest/sequencer/metrics.d.ts +48 -3
  58. package/dest/sequencer/metrics.d.ts.map +1 -1
  59. package/dest/sequencer/metrics.js +243 -50
  60. package/dest/sequencer/sequencer.d.ts +127 -144
  61. package/dest/sequencer/sequencer.d.ts.map +1 -1
  62. package/dest/sequencer/sequencer.js +770 -545
  63. package/dest/sequencer/timetable.d.ts +54 -16
  64. package/dest/sequencer/timetable.d.ts.map +1 -1
  65. package/dest/sequencer/timetable.js +147 -62
  66. package/dest/sequencer/types.d.ts +3 -0
  67. package/dest/sequencer/types.d.ts.map +1 -0
  68. package/dest/sequencer/types.js +1 -0
  69. package/dest/sequencer/utils.d.ts +14 -8
  70. package/dest/sequencer/utils.d.ts.map +1 -1
  71. package/dest/sequencer/utils.js +7 -4
  72. package/dest/test/index.d.ts +6 -7
  73. package/dest/test/index.d.ts.map +1 -1
  74. package/dest/test/mock_checkpoint_builder.d.ts +95 -0
  75. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  76. package/dest/test/mock_checkpoint_builder.js +231 -0
  77. package/dest/test/utils.d.ts +53 -0
  78. package/dest/test/utils.d.ts.map +1 -0
  79. package/dest/test/utils.js +104 -0
  80. package/package.json +32 -30
  81. package/src/client/sequencer-client.ts +100 -52
  82. package/src/config.ts +132 -51
  83. package/src/global_variable_builder/global_builder.ts +69 -60
  84. package/src/index.ts +1 -7
  85. package/src/publisher/config.ts +139 -50
  86. package/src/publisher/index.ts +3 -0
  87. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  88. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +55 -0
  89. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  90. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  91. package/src/publisher/sequencer-publisher-factory.ts +45 -11
  92. package/src/publisher/sequencer-publisher-metrics.ts +19 -71
  93. package/src/publisher/sequencer-publisher.ts +717 -248
  94. package/src/sequencer/README.md +531 -0
  95. package/src/sequencer/checkpoint_proposal_job.ts +1049 -0
  96. package/src/sequencer/checkpoint_voter.ts +130 -0
  97. package/src/sequencer/config.ts +2 -1
  98. package/src/sequencer/events.ts +27 -0
  99. package/src/sequencer/index.ts +3 -1
  100. package/src/sequencer/metrics.ts +310 -61
  101. package/src/sequencer/sequencer.ts +541 -735
  102. package/src/sequencer/timetable.ts +178 -83
  103. package/src/sequencer/types.ts +6 -0
  104. package/src/sequencer/utils.ts +18 -9
  105. package/src/test/index.ts +5 -6
  106. package/src/test/mock_checkpoint_builder.ts +323 -0
  107. package/src/test/utils.ts +167 -0
  108. package/dest/sequencer/block_builder.d.ts +0 -27
  109. package/dest/sequencer/block_builder.d.ts.map +0 -1
  110. package/dest/sequencer/block_builder.js +0 -130
  111. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  112. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  113. package/dest/tx_validator/nullifier_cache.js +0 -24
  114. package/dest/tx_validator/tx_validator_factory.d.ts +0 -17
  115. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  116. package/dest/tx_validator/tx_validator_factory.js +0 -53
  117. package/src/sequencer/block_builder.ts +0 -218
  118. package/src/tx_validator/nullifier_cache.ts +0 -30
  119. 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,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,7 +11,7 @@ import {
9
11
  type TelemetryClient,
10
12
  type Tracer,
11
13
  type UpDownCounter,
12
- ValueType,
14
+ createUpDownCounterWithDefault,
13
15
  } from '@aztec/telemetry-client';
14
16
 
15
17
  import { type Hex, formatUnits } from 'viem';
@@ -36,7 +38,37 @@ 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 checkpointProposalSuccess: UpDownCounter;
43
+ private checkpointPrecheckFailed: UpDownCounter;
44
+ private checkpointProposalFailed: UpDownCounter;
45
+ private checkpointSuccess: UpDownCounter;
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;
70
+
71
+ private lastSeenSlot?: SlotNumber;
40
72
 
41
73
  constructor(
42
74
  client: TelemetryClient,
@@ -46,81 +78,128 @@ export class SequencerMetrics {
46
78
  this.meter = client.getMeter(name);
47
79
  this.tracer = client.getTracer(name);
48
80
 
49
- this.blockCounter = this.meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_COUNT);
50
-
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,
81
+ this.blockCounter = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_BLOCK_COUNT, {
82
+ [Attributes.STATUS]: ['failed', 'built'],
55
83
  });
56
84
 
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
- });
85
+ this.blockBuildDuration = this.meter.createHistogram(Metrics.SEQUENCER_BLOCK_BUILD_DURATION);
62
86
 
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
- );
87
+ this.blockBuildManaPerSecond = this.meter.createGauge(Metrics.SEQUENCER_BLOCK_BUILD_MANA_PER_SECOND);
72
88
 
73
- // Init gauges and counters
74
- this.blockCounter.add(0, {
75
- [Attributes.STATUS]: 'failed',
76
- });
77
- this.blockCounter.add(0, {
78
- [Attributes.STATUS]: 'built',
79
- });
89
+ this.stateTransitionBufferDuration = this.meter.createHistogram(Metrics.SEQUENCER_STATE_TRANSITION_BUFFER_DURATION);
80
90
 
81
- this.rewards = this.meter.createGauge(Metrics.SEQUENCER_CURRENT_BLOCK_REWARDS, {
82
- valueType: ValueType.DOUBLE,
83
- description: 'The rewards earned',
84
- });
91
+ this.checkpointAttestationDelay = this.meter.createHistogram(Metrics.SEQUENCER_CHECKPOINT_ATTESTATION_DELAY);
85
92
 
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
- });
93
+ this.rewards = this.meter.createGauge(Metrics.SEQUENCER_CURRENT_SLOT_REWARDS);
94
+
95
+ this.slots = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_SLOT_COUNT);
90
96
 
91
97
  /**
92
98
  * NOTE: we do not track missed slots as a separate metric. That would be difficult to determine
93
99
  * Instead, use a computed metric, `slots - filledSlots` to get the number of slots a sequencer has missed.
94
100
  */
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
- });
101
+ this.filledSlots = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_FILLED_SLOT_COUNT);
99
102
 
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
- });
103
+ this.timeToCollectAttestations = this.meter.createGauge(Metrics.SEQUENCER_COLLECT_ATTESTATIONS_DURATION);
104
+
105
+ this.allowanceToCollectAttestations = this.meter.createGauge(Metrics.SEQUENCER_COLLECT_ATTESTATIONS_TIME_ALLOWANCE);
105
106
 
106
- this.allowanceToCollectAttestations = this.meter.createGauge(
107
- 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,
108
126
  {
109
- description: 'Maximum amount of time to collect attestations',
110
- unit: 'ms',
111
- valueType: ValueType.INT,
127
+ [Attributes.ERROR_TYPE]: [
128
+ 'slot_already_taken',
129
+ 'rollup_contract_check_failed',
130
+ 'slot_mismatch',
131
+ 'block_number_mismatch',
132
+ ],
112
133
  },
113
134
  );
114
135
 
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
- });
136
+ this.checkpointProposalFailed = createUpDownCounterWithDefault(
137
+ this.meter,
138
+ Metrics.SEQUENCER_CHECKPOINT_PROPOSAL_FAILED_COUNT,
139
+ );
119
140
 
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
- });
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);
145
+
146
+ this.slashingAttempts = createUpDownCounterWithDefault(this.meter, Metrics.SEQUENCER_SLASHING_ATTEMPTS_COUNT);
147
+
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);
151
+
152
+ // Fisherman fee analysis metrics
153
+ this.fishermanWouldBeIncluded = createUpDownCounterWithDefault(
154
+ this.meter,
155
+ Metrics.FISHERMAN_FEE_ANALYSIS_WOULD_BE_INCLUDED,
156
+ {
157
+ [Attributes.OK]: [true, false],
158
+ [Attributes.BLOCK_FULL]: ['true', 'false'],
159
+ },
160
+ );
161
+
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);
124
203
  }
125
204
 
126
205
  public recordRequiredAttestations(requiredAttestationsCount: number, allowanceMs: number) {
@@ -132,6 +211,10 @@ export class SequencerMetrics {
132
211
  this.timeToCollectAttestations.record(0);
133
212
  }
134
213
 
214
+ public recordCheckpointAttestationDelay(duration: number) {
215
+ this.checkpointAttestationDelay.record(duration);
216
+ }
217
+
135
218
  public recordCollectedAttestations(count: number, durationMs: number) {
136
219
  this.collectedAttestions.record(count);
137
220
  this.timeToCollectAttestations.record(Math.ceil(durationMs));
@@ -157,7 +240,15 @@ export class SequencerMetrics {
157
240
  });
158
241
  }
159
242
 
160
- incOpenSlot(slot: bigint, proposer: string) {
243
+ recordPipelineDepth(depth: number) {
244
+ this.pipelineDepth.record(depth);
245
+ }
246
+
247
+ recordPipelineDiscard(count = 1) {
248
+ this.pipelineDiscards.add(count);
249
+ }
250
+
251
+ incOpenSlot(slot: SlotNumber, proposer: string) {
161
252
  // sequencer went through the loop a second time. Noop
162
253
  if (slot === this.lastSeenSlot) {
163
254
  return;
@@ -188,4 +279,162 @@ export class SequencerMetrics {
188
279
  }
189
280
  }
190
281
  }
282
+
283
+ recordCheckpointSuccess() {
284
+ this.checkpointSuccess.add(1);
285
+ }
286
+
287
+ recordBlockProposalFailed(reason?: string) {
288
+ this.blockProposalFailed.add(1, {
289
+ ...(reason && { [Attributes.ERROR_TYPE]: reason }),
290
+ });
291
+ }
292
+
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 });
301
+ }
302
+
303
+ recordCheckpointProposalFailed(reason?: string) {
304
+ this.checkpointProposalFailed.add(1, {
305
+ ...(reason && { [Attributes.ERROR_TYPE]: reason }),
306
+ });
307
+ }
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
+
317
+ recordSlashingAttempt(actionCount: number) {
318
+ this.slashingAttempts.add(actionCount);
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
+ }
191
440
  }