@aztec/sequencer-client 0.0.0-test.0 → 0.0.1-commit.03f7ef2

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 (141) hide show
  1. package/dest/client/index.d.ts +1 -1
  2. package/dest/client/sequencer-client.d.ts +30 -29
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +82 -60
  5. package/dest/config.d.ts +15 -16
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +113 -70
  8. package/dest/global_variable_builder/global_builder.d.ts +25 -14
  9. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  10. package/dest/global_variable_builder/global_builder.js +60 -42
  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 +15 -12
  16. package/dest/publisher/config.d.ts.map +1 -1
  17. package/dest/publisher/config.js +32 -19
  18. package/dest/publisher/index.d.ts +3 -1
  19. package/dest/publisher/index.d.ts.map +1 -1
  20. package/dest/publisher/index.js +3 -0
  21. package/dest/publisher/sequencer-publisher-factory.d.ts +44 -0
  22. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
  23. package/dest/publisher/sequencer-publisher-factory.js +51 -0
  24. package/dest/publisher/sequencer-publisher-metrics.d.ts +5 -4
  25. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  26. package/dest/publisher/sequencer-publisher-metrics.js +37 -2
  27. package/dest/publisher/sequencer-publisher.d.ts +132 -86
  28. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  29. package/dest/publisher/sequencer-publisher.js +755 -248
  30. package/dest/sequencer/block_builder.d.ts +26 -0
  31. package/dest/sequencer/block_builder.d.ts.map +1 -0
  32. package/dest/sequencer/block_builder.js +129 -0
  33. package/dest/sequencer/checkpoint_builder.d.ts +63 -0
  34. package/dest/sequencer/checkpoint_builder.d.ts.map +1 -0
  35. package/dest/sequencer/checkpoint_builder.js +131 -0
  36. package/dest/sequencer/checkpoint_proposal_job.d.ts +74 -0
  37. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  38. package/dest/sequencer/checkpoint_proposal_job.js +640 -0
  39. package/dest/sequencer/checkpoint_voter.d.ts +34 -0
  40. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  41. package/dest/sequencer/checkpoint_voter.js +85 -0
  42. package/dest/sequencer/config.d.ts +7 -1
  43. package/dest/sequencer/config.d.ts.map +1 -1
  44. package/dest/sequencer/errors.d.ts +11 -0
  45. package/dest/sequencer/errors.d.ts.map +1 -0
  46. package/dest/sequencer/errors.js +15 -0
  47. package/dest/sequencer/events.d.ts +46 -0
  48. package/dest/sequencer/events.d.ts.map +1 -0
  49. package/dest/sequencer/events.js +1 -0
  50. package/dest/sequencer/index.d.ts +6 -2
  51. package/dest/sequencer/index.d.ts.map +1 -1
  52. package/dest/sequencer/index.js +5 -1
  53. package/dest/sequencer/metrics.d.ts +48 -12
  54. package/dest/sequencer/metrics.d.ts.map +1 -1
  55. package/dest/sequencer/metrics.js +274 -48
  56. package/dest/sequencer/sequencer.d.ts +132 -135
  57. package/dest/sequencer/sequencer.d.ts.map +1 -1
  58. package/dest/sequencer/sequencer.js +519 -521
  59. package/dest/sequencer/timetable.d.ts +76 -24
  60. package/dest/sequencer/timetable.d.ts.map +1 -1
  61. package/dest/sequencer/timetable.js +177 -61
  62. package/dest/sequencer/types.d.ts +3 -0
  63. package/dest/sequencer/types.d.ts.map +1 -0
  64. package/dest/sequencer/types.js +1 -0
  65. package/dest/sequencer/utils.d.ts +20 -38
  66. package/dest/sequencer/utils.d.ts.map +1 -1
  67. package/dest/sequencer/utils.js +12 -47
  68. package/dest/test/index.d.ts +10 -1
  69. package/dest/test/index.d.ts.map +1 -1
  70. package/dest/test/index.js +0 -4
  71. package/dest/test/mock_checkpoint_builder.d.ts +83 -0
  72. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  73. package/dest/test/mock_checkpoint_builder.js +179 -0
  74. package/dest/test/utils.d.ts +49 -0
  75. package/dest/test/utils.d.ts.map +1 -0
  76. package/dest/test/utils.js +94 -0
  77. package/dest/tx_validator/nullifier_cache.d.ts +1 -3
  78. package/dest/tx_validator/nullifier_cache.d.ts.map +1 -1
  79. package/dest/tx_validator/tx_validator_factory.d.ts +11 -11
  80. package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -1
  81. package/dest/tx_validator/tx_validator_factory.js +28 -25
  82. package/package.json +45 -45
  83. package/src/client/sequencer-client.ts +105 -105
  84. package/src/config.ts +126 -81
  85. package/src/global_variable_builder/global_builder.ts +82 -53
  86. package/src/index.ts +8 -2
  87. package/src/publisher/config.ts +45 -32
  88. package/src/publisher/index.ts +4 -0
  89. package/src/publisher/sequencer-publisher-factory.ts +92 -0
  90. package/src/publisher/sequencer-publisher-metrics.ts +26 -4
  91. package/src/publisher/sequencer-publisher.ts +955 -293
  92. package/src/sequencer/README.md +531 -0
  93. package/src/sequencer/block_builder.ts +217 -0
  94. package/src/sequencer/checkpoint_builder.ts +217 -0
  95. package/src/sequencer/checkpoint_proposal_job.ts +703 -0
  96. package/src/sequencer/checkpoint_voter.ts +105 -0
  97. package/src/sequencer/config.ts +8 -0
  98. package/src/sequencer/errors.ts +21 -0
  99. package/src/sequencer/events.ts +27 -0
  100. package/src/sequencer/index.ts +5 -1
  101. package/src/sequencer/metrics.ts +355 -50
  102. package/src/sequencer/sequencer.ts +631 -594
  103. package/src/sequencer/timetable.ts +221 -62
  104. package/src/sequencer/types.ts +6 -0
  105. package/src/sequencer/utils.ts +28 -60
  106. package/src/test/index.ts +13 -4
  107. package/src/test/mock_checkpoint_builder.ts +247 -0
  108. package/src/test/utils.ts +137 -0
  109. package/src/tx_validator/tx_validator_factory.ts +46 -33
  110. package/dest/sequencer/allowed.d.ts +0 -3
  111. package/dest/sequencer/allowed.d.ts.map +0 -1
  112. package/dest/sequencer/allowed.js +0 -27
  113. package/dest/slasher/factory.d.ts +0 -7
  114. package/dest/slasher/factory.d.ts.map +0 -1
  115. package/dest/slasher/factory.js +0 -8
  116. package/dest/slasher/index.d.ts +0 -3
  117. package/dest/slasher/index.d.ts.map +0 -1
  118. package/dest/slasher/index.js +0 -2
  119. package/dest/slasher/slasher_client.d.ts +0 -75
  120. package/dest/slasher/slasher_client.d.ts.map +0 -1
  121. package/dest/slasher/slasher_client.js +0 -132
  122. package/dest/tx_validator/archive_cache.d.ts +0 -14
  123. package/dest/tx_validator/archive_cache.d.ts.map +0 -1
  124. package/dest/tx_validator/archive_cache.js +0 -22
  125. package/dest/tx_validator/gas_validator.d.ts +0 -14
  126. package/dest/tx_validator/gas_validator.d.ts.map +0 -1
  127. package/dest/tx_validator/gas_validator.js +0 -78
  128. package/dest/tx_validator/phases_validator.d.ts +0 -12
  129. package/dest/tx_validator/phases_validator.d.ts.map +0 -1
  130. package/dest/tx_validator/phases_validator.js +0 -80
  131. package/dest/tx_validator/test_utils.d.ts +0 -23
  132. package/dest/tx_validator/test_utils.d.ts.map +0 -1
  133. package/dest/tx_validator/test_utils.js +0 -26
  134. package/src/sequencer/allowed.ts +0 -36
  135. package/src/slasher/factory.ts +0 -15
  136. package/src/slasher/index.ts +0 -2
  137. package/src/slasher/slasher_client.ts +0 -193
  138. package/src/tx_validator/archive_cache.ts +0 -28
  139. package/src/tx_validator/gas_validator.ts +0 -101
  140. package/src/tx_validator/phases_validator.ts +0 -98
  141. package/src/tx_validator/test_utils.ts +0 -48
@@ -0,0 +1,105 @@
1
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
2
+ import type { EthAddress } from '@aztec/foundation/eth-address';
3
+ import type { Logger } from '@aztec/foundation/log';
4
+ import type { SlasherClientInterface } from '@aztec/slasher';
5
+ import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
6
+ import type { ResolvedSequencerConfig } from '@aztec/stdlib/interfaces/server';
7
+ import type { ValidatorClient } from '@aztec/validator-client';
8
+
9
+ import type { TypedDataDefinition } from 'viem';
10
+
11
+ import type { SequencerPublisher } from '../publisher/sequencer-publisher.js';
12
+ import type { SequencerMetrics } from './metrics.js';
13
+ import type { SequencerRollupConstants } from './types.js';
14
+
15
+ /**
16
+ * Handles governance and slashing voting for a given slot.
17
+ */
18
+ export class CheckpointVoter {
19
+ private slotTimestamp: bigint;
20
+ private signer: (msg: TypedDataDefinition) => Promise<`0x${string}`>;
21
+
22
+ constructor(
23
+ private readonly slot: SlotNumber,
24
+ private readonly publisher: SequencerPublisher,
25
+ private readonly attestorAddress: EthAddress,
26
+ private readonly validatorClient: ValidatorClient,
27
+ private readonly slasherClient: SlasherClientInterface | undefined,
28
+ private readonly l1Constants: SequencerRollupConstants,
29
+ private readonly config: ResolvedSequencerConfig,
30
+ private readonly metrics: SequencerMetrics,
31
+ private readonly log: Logger,
32
+ ) {
33
+ this.slotTimestamp = getTimestampForSlot(this.slot, this.l1Constants);
34
+ this.signer = (msg: TypedDataDefinition) =>
35
+ this.validatorClient.signWithAddress(this.attestorAddress, msg).then(s => s.toString());
36
+ }
37
+
38
+ /**
39
+ * Enqueues governance and slashing votes with the publisher.
40
+ * Returns a tuple of promises that resolve to whether each vote was successfully enqueued.
41
+ */
42
+ enqueueVotes(): [Promise<boolean | undefined>, Promise<boolean | undefined>] {
43
+ try {
44
+ const enqueueGovernancePromise = this.enqueueGovernanceVote();
45
+ const enqueueSlashingPromise = this.enqueueSlashingVote();
46
+
47
+ return [enqueueGovernancePromise, enqueueSlashingPromise];
48
+ } catch (err) {
49
+ this.log.error(`Error enqueueing governance and slashing votes`, err);
50
+ return [Promise.resolve(false), Promise.resolve(false)];
51
+ }
52
+ }
53
+
54
+ private async enqueueGovernanceVote(): Promise<boolean | undefined> {
55
+ const governanceProposerPayload = this.config.governanceProposerPayload;
56
+ if (!governanceProposerPayload || governanceProposerPayload.isZero()) {
57
+ return undefined;
58
+ }
59
+
60
+ this.log.info(`Enqueuing vote for ${governanceProposerPayload} governance for slot ${this.slot}`, {
61
+ slot: this.slot,
62
+ governanceProposerPayload: governanceProposerPayload.toString(),
63
+ });
64
+
65
+ try {
66
+ return await this.publisher.enqueueGovernanceCastSignal(
67
+ governanceProposerPayload,
68
+ this.slot,
69
+ this.slotTimestamp,
70
+ this.attestorAddress,
71
+ this.signer,
72
+ );
73
+ } catch (err) {
74
+ this.log.error(`Error enqueuing governance vote`, err, { slot: this.slot });
75
+ return false;
76
+ }
77
+ }
78
+
79
+ private async enqueueSlashingVote(): Promise<boolean | undefined> {
80
+ try {
81
+ const actions = await this.slasherClient?.getProposerActions(this.slot);
82
+ if (!actions || actions.length === 0) {
83
+ return undefined;
84
+ }
85
+
86
+ this.log.info(`Enqueuing vote for ${actions.length} slashing actions for slot ${this.slot}`, {
87
+ slot: this.slot,
88
+ actionCount: actions.length,
89
+ });
90
+
91
+ this.metrics.recordSlashingAttempt(actions.length);
92
+
93
+ return await this.publisher.enqueueSlashingActions(
94
+ actions,
95
+ this.slot,
96
+ this.slotTimestamp,
97
+ this.attestorAddress,
98
+ this.signer,
99
+ );
100
+ } catch (err) {
101
+ this.log.error(`Error enqueuing slashing vote`, err, { slot: this.slot });
102
+ return false;
103
+ }
104
+ }
105
+ }
@@ -1 +1,9 @@
1
+ import type { GovernanceProposerContract } from '@aztec/ethereum/contracts';
2
+ import type { RollupContract } from '@aztec/ethereum/contracts/rollup';
3
+
1
4
  export { type SequencerConfig } from '@aztec/stdlib/config';
5
+
6
+ export type SequencerContracts = {
7
+ rollupContract: RollupContract;
8
+ governanceProposerContract: GovernanceProposerContract;
9
+ };
@@ -0,0 +1,21 @@
1
+ import type { SequencerState } from './utils.js';
2
+
3
+ export class SequencerTooSlowError extends Error {
4
+ constructor(
5
+ public readonly proposedState: SequencerState,
6
+ public readonly maxAllowedTime: number,
7
+ public readonly currentTime: number,
8
+ ) {
9
+ super(
10
+ `Too far into slot for ${proposedState} (time into slot ${currentTime}s greater than ${maxAllowedTime}s allowance)`,
11
+ );
12
+ this.name = 'SequencerTooSlowError';
13
+ }
14
+ }
15
+
16
+ export class SequencerInterruptedError extends Error {
17
+ constructor() {
18
+ super(`Sequencer was interrupted`);
19
+ this.name = 'SequencerInterruptedError';
20
+ }
21
+ }
@@ -0,0 +1,27 @@
1
+ import type { BlockNumber, CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
+
3
+ import type { Action } from '../publisher/sequencer-publisher.js';
4
+ import type { SequencerState } from './utils.js';
5
+
6
+ export type SequencerEvents = {
7
+ ['state-changed']: (args: {
8
+ oldState: SequencerState;
9
+ newState: SequencerState;
10
+ secondsIntoSlot?: number;
11
+ slot?: SlotNumber;
12
+ }) => void;
13
+ ['proposer-rollup-check-failed']: (args: { reason: string; slot: SlotNumber }) => void;
14
+ ['block-tx-count-check-failed']: (args: { minTxs: number; availableTxs: number; slot: SlotNumber }) => void;
15
+ ['block-build-failed']: (args: { reason: string; slot: SlotNumber }) => void;
16
+ ['block-proposed']: (args: { blockNumber: BlockNumber; slot: SlotNumber }) => void;
17
+ ['checkpoint-empty']: (args: { slot: SlotNumber }) => void;
18
+ ['checkpoint-publish-failed']: (args: {
19
+ slot: SlotNumber;
20
+ successfulActions?: Action[];
21
+ failedActions?: Action[];
22
+ sentActions?: Action[];
23
+ expiredActions?: Action[];
24
+ }) => void;
25
+ ['checkpoint-published']: (args: { checkpoint: CheckpointNumber; slot: SlotNumber }) => void;
26
+ ['checkpoint-error']: (args: { error: Error }) => void;
27
+ };
@@ -1,3 +1,7 @@
1
+ export * from './block_builder.js';
2
+ export * from './checkpoint_builder.js';
3
+ export * from './checkpoint_proposal_job.js';
4
+ export * from './checkpoint_voter.js';
1
5
  export * from './config.js';
6
+ export * from './events.js';
2
7
  export * from './sequencer.js';
3
- export * from './allowed.js';
@@ -1,7 +1,12 @@
1
+ import { EthAddress } from '@aztec/aztec.js/addresses';
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';
1
5
  import {
2
6
  Attributes,
3
7
  type Gauge,
4
8
  type Histogram,
9
+ type Meter,
5
10
  Metrics,
6
11
  type TelemetryClient,
7
12
  type Tracer,
@@ -9,100 +14,263 @@ import {
9
14
  ValueType,
10
15
  } from '@aztec/telemetry-client';
11
16
 
12
- import { type SequencerState, type SequencerStateCallback, sequencerStateToNumber } from './utils.js';
17
+ import { type Hex, formatUnits } from 'viem';
13
18
 
19
+ import type { SequencerState } from './utils.js';
20
+
21
+ // TODO(palla/mbps): Review all metrics and add any missing ones per checkpoint
14
22
  export class SequencerMetrics {
15
23
  public readonly tracer: Tracer;
24
+ private meter: Meter;
16
25
 
17
26
  private blockCounter: UpDownCounter;
18
27
  private blockBuildDuration: Histogram;
19
28
  private blockBuildManaPerSecond: Gauge;
20
29
  private stateTransitionBufferDuration: Histogram;
21
- private currentBlockNumber: Gauge;
22
- private currentBlockSize: Gauge;
23
- private blockBuilderInsertions: Histogram;
24
30
 
31
+ // these are gauges because for individual sequencers building a block is not something that happens often enough to warrant a histogram
25
32
  private timeToCollectAttestations: Gauge;
33
+ private allowanceToCollectAttestations: Gauge;
34
+ private requiredAttestions: Gauge;
35
+ private collectedAttestions: Gauge;
36
+
37
+ private rewards: Gauge;
38
+
39
+ private slots: UpDownCounter;
40
+ private filledSlots: UpDownCounter;
41
+
42
+ private blockProposalFailed: UpDownCounter;
43
+ private blockProposalSuccess: UpDownCounter;
44
+ private blockProposalPrecheckFailed: UpDownCounter;
45
+ private checkpointSuccess: UpDownCounter;
46
+ private slashingAttempts: UpDownCounter;
47
+ private blockAttestationDelay: Histogram;
48
+
49
+ // Fisherman fee analysis metrics
50
+ private fishermanWouldBeIncluded: UpDownCounter;
51
+ private fishermanTimeBeforeBlock: Histogram;
52
+ private fishermanPendingBlobTxCount: Histogram;
53
+ private fishermanIncludedBlobTxCount: Histogram;
54
+ private fishermanCalculatedPriorityFee: Histogram;
55
+ private fishermanPriorityFeeDelta: Histogram;
56
+ private fishermanEstimatedCost: Histogram;
57
+ private fishermanEstimatedOverpayment: Histogram;
58
+ private fishermanMinedBlobTxPriorityFee: Histogram;
59
+ private fishermanMinedBlobTxTotalCost: Histogram;
60
+
61
+ private lastSeenSlot?: SlotNumber;
26
62
 
27
- constructor(client: TelemetryClient, getState: SequencerStateCallback, name = 'Sequencer') {
28
- const meter = client.getMeter(name);
63
+ constructor(
64
+ client: TelemetryClient,
65
+ private rollup: RollupContract,
66
+ name = 'Sequencer',
67
+ ) {
68
+ this.meter = client.getMeter(name);
29
69
  this.tracer = client.getTracer(name);
30
70
 
31
- this.blockCounter = meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_COUNT);
71
+ this.blockCounter = this.meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_COUNT);
32
72
 
33
- this.blockBuildDuration = meter.createHistogram(Metrics.SEQUENCER_BLOCK_BUILD_DURATION, {
73
+ this.blockBuildDuration = this.meter.createHistogram(Metrics.SEQUENCER_BLOCK_BUILD_DURATION, {
34
74
  unit: 'ms',
35
75
  description: 'Duration to build a block',
36
76
  valueType: ValueType.INT,
37
77
  });
38
78
 
39
- this.blockBuildManaPerSecond = meter.createGauge(Metrics.SEQUENCER_BLOCK_BUILD_MANA_PER_SECOND, {
79
+ this.blockBuildManaPerSecond = this.meter.createGauge(Metrics.SEQUENCER_BLOCK_BUILD_MANA_PER_SECOND, {
40
80
  unit: 'mana/s',
41
81
  description: 'Mana per second when building a block',
42
82
  valueType: ValueType.INT,
43
83
  });
44
84
 
45
- this.stateTransitionBufferDuration = meter.createHistogram(Metrics.SEQUENCER_STATE_TRANSITION_BUFFER_DURATION, {
85
+ this.stateTransitionBufferDuration = this.meter.createHistogram(
86
+ Metrics.SEQUENCER_STATE_TRANSITION_BUFFER_DURATION,
87
+ {
88
+ unit: 'ms',
89
+ description:
90
+ 'The time difference between when the sequencer needed to transition to a new state and when it actually did.',
91
+ valueType: ValueType.INT,
92
+ },
93
+ );
94
+
95
+ this.blockAttestationDelay = this.meter.createHistogram(Metrics.SEQUENCER_BLOCK_ATTESTATION_DELAY, {
46
96
  unit: 'ms',
47
- description:
48
- 'The time difference between when the sequencer needed to transition to a new state and when it actually did.',
97
+ description: 'The time difference between block proposal and minimal attestation count reached,',
49
98
  valueType: ValueType.INT,
50
99
  });
51
100
 
52
- const currentState = meter.createObservableGauge(Metrics.SEQUENCER_CURRENT_STATE, {
53
- description: 'Current state of the sequencer',
101
+ // Init gauges and counters
102
+ this.blockCounter.add(0, {
103
+ [Attributes.STATUS]: 'failed',
104
+ });
105
+ this.blockCounter.add(0, {
106
+ [Attributes.STATUS]: 'built',
54
107
  });
55
108
 
56
- currentState.addCallback(observer => {
57
- observer.observe(sequencerStateToNumber(getState()));
109
+ this.rewards = this.meter.createGauge(Metrics.SEQUENCER_CURRENT_BLOCK_REWARDS, {
110
+ valueType: ValueType.DOUBLE,
111
+ description: 'The rewards earned',
58
112
  });
59
113
 
60
- this.currentBlockNumber = meter.createGauge(Metrics.SEQUENCER_CURRENT_BLOCK_NUMBER, {
61
- description: 'Current block number',
114
+ this.slots = this.meter.createUpDownCounter(Metrics.SEQUENCER_SLOT_COUNT, {
62
115
  valueType: ValueType.INT,
116
+ description: 'The number of slots this sequencer was selected for',
63
117
  });
64
118
 
65
- this.currentBlockSize = meter.createGauge(Metrics.SEQUENCER_CURRENT_BLOCK_SIZE, {
66
- description: 'Current block size',
119
+ /**
120
+ * NOTE: we do not track missed slots as a separate metric. That would be difficult to determine
121
+ * Instead, use a computed metric, `slots - filledSlots` to get the number of slots a sequencer has missed.
122
+ */
123
+ this.filledSlots = this.meter.createUpDownCounter(Metrics.SEQUENCER_FILLED_SLOT_COUNT, {
67
124
  valueType: ValueType.INT,
125
+ description: 'The number of slots this sequencer has filled',
68
126
  });
69
127
 
70
- this.timeToCollectAttestations = meter.createGauge(Metrics.SEQUENCER_TIME_TO_COLLECT_ATTESTATIONS, {
128
+ this.timeToCollectAttestations = this.meter.createGauge(Metrics.SEQUENCER_COLLECT_ATTESTATIONS_DURATION, {
71
129
  description: 'The time spent collecting attestations from committee members',
130
+ unit: 'ms',
72
131
  valueType: ValueType.INT,
73
132
  });
74
133
 
75
- this.blockBuilderInsertions = meter.createHistogram(Metrics.SEQUENCER_BLOCK_BUILD_INSERTION_TIME, {
76
- description: 'Timer for tree insertions performed by the block builder',
77
- unit: 'us',
134
+ this.allowanceToCollectAttestations = this.meter.createGauge(
135
+ Metrics.SEQUENCER_COLLECT_ATTESTATIONS_TIME_ALLOWANCE,
136
+ {
137
+ description: 'Maximum amount of time to collect attestations',
138
+ unit: 'ms',
139
+ valueType: ValueType.INT,
140
+ },
141
+ );
142
+
143
+ this.requiredAttestions = this.meter.createGauge(Metrics.SEQUENCER_REQUIRED_ATTESTATIONS_COUNT, {
78
144
  valueType: ValueType.INT,
145
+ description: 'The minimum number of attestations required to publish a block',
79
146
  });
80
147
 
81
- this.setCurrentBlock(0, 0);
82
- }
148
+ this.collectedAttestions = this.meter.createGauge(Metrics.SEQUENCER_COLLECTED_ATTESTATIONS_COUNT, {
149
+ valueType: ValueType.INT,
150
+ description: 'The minimum number of attestations required to publish a block',
151
+ });
152
+
153
+ this.blockProposalFailed = this.meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_PROPOSAL_FAILED_COUNT, {
154
+ valueType: ValueType.INT,
155
+ description: 'The number of times block proposal failed (including validation builds)',
156
+ });
157
+
158
+ this.blockProposalSuccess = this.meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_PROPOSAL_SUCCESS_COUNT, {
159
+ valueType: ValueType.INT,
160
+ description: 'The number of times block proposal succeeded (including validation builds)',
161
+ });
162
+
163
+ this.checkpointSuccess = this.meter.createUpDownCounter(Metrics.SEQUENCER_CHECKPOINT_SUCCESS_COUNT, {
164
+ valueType: ValueType.INT,
165
+ description: 'The number of times checkpoint publishing succeeded',
166
+ });
167
+
168
+ this.blockProposalPrecheckFailed = this.meter.createUpDownCounter(
169
+ Metrics.SEQUENCER_BLOCK_PROPOSAL_PRECHECK_FAILED_COUNT,
170
+ {
171
+ valueType: ValueType.INT,
172
+ description: 'The number of times block proposal pre-build checks failed',
173
+ },
174
+ );
175
+
176
+ this.slashingAttempts = this.meter.createUpDownCounter(Metrics.SEQUENCER_SLASHING_ATTEMPTS_COUNT, {
177
+ valueType: ValueType.INT,
178
+ description: 'The number of slashing action attempts',
179
+ });
180
+
181
+ // Fisherman fee analysis metrics
182
+ this.fishermanWouldBeIncluded = this.meter.createUpDownCounter(Metrics.FISHERMAN_FEE_ANALYSIS_WOULD_BE_INCLUDED, {
183
+ valueType: ValueType.INT,
184
+ description: 'Whether the transaction would have been included in the block',
185
+ });
186
+
187
+ this.fishermanTimeBeforeBlock = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_TIME_BEFORE_BLOCK, {
188
+ unit: 'ms',
189
+ description: 'Time in ms between fee analysis and block being mined',
190
+ valueType: ValueType.INT,
191
+ });
192
+
193
+ this.fishermanPendingBlobTxCount = this.meter.createHistogram(
194
+ Metrics.FISHERMAN_FEE_ANALYSIS_PENDING_BLOB_TX_COUNT,
195
+ {
196
+ description: 'Number of blob transactions seen in the pending block',
197
+ valueType: ValueType.INT,
198
+ },
199
+ );
200
+
201
+ this.fishermanIncludedBlobTxCount = this.meter.createHistogram(
202
+ Metrics.FISHERMAN_FEE_ANALYSIS_INCLUDED_BLOB_TX_COUNT,
203
+ {
204
+ description: 'Number of blob transactions that got included in the mined block',
205
+ valueType: ValueType.INT,
206
+ },
207
+ );
208
+
209
+ this.fishermanCalculatedPriorityFee = this.meter.createHistogram(
210
+ Metrics.FISHERMAN_FEE_ANALYSIS_CALCULATED_PRIORITY_FEE,
211
+ {
212
+ unit: 'gwei',
213
+ description: 'Priority fee calculated by each strategy',
214
+ valueType: ValueType.DOUBLE,
215
+ },
216
+ );
217
+
218
+ this.fishermanPriorityFeeDelta = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_PRIORITY_FEE_DELTA, {
219
+ unit: 'gwei',
220
+ description: 'Difference between our priority fee and minimum included priority fee',
221
+ valueType: ValueType.DOUBLE,
222
+ });
223
+
224
+ this.fishermanEstimatedCost = this.meter.createHistogram(Metrics.FISHERMAN_FEE_ANALYSIS_ESTIMATED_COST, {
225
+ unit: 'eth',
226
+ description: 'Estimated total cost in ETH for the transaction with this strategy',
227
+ valueType: ValueType.DOUBLE,
228
+ });
229
+
230
+ this.fishermanEstimatedOverpayment = this.meter.createHistogram(
231
+ Metrics.FISHERMAN_FEE_ANALYSIS_ESTIMATED_OVERPAYMENT,
232
+ {
233
+ unit: 'eth',
234
+ description: 'Estimated overpayment in ETH vs minimum required for inclusion',
235
+ valueType: ValueType.DOUBLE,
236
+ },
237
+ );
83
238
 
84
- startCollectingAttestationsTimer(): () => void {
85
- const startTime = Date.now();
86
- const stop = () => {
87
- const duration = Date.now() - startTime;
88
- this.recordTimeToCollectAttestations(duration);
89
- };
90
- return stop.bind(this);
239
+ this.fishermanMinedBlobTxPriorityFee = this.meter.createHistogram(
240
+ Metrics.FISHERMAN_FEE_ANALYSIS_MINED_BLOB_TX_PRIORITY_FEE,
241
+ {
242
+ unit: 'gwei',
243
+ description: 'Priority fee per gas for blob transactions in mined blocks',
244
+ valueType: ValueType.DOUBLE,
245
+ },
246
+ );
247
+
248
+ this.fishermanMinedBlobTxTotalCost = this.meter.createHistogram(
249
+ Metrics.FISHERMAN_FEE_ANALYSIS_MINED_BLOB_TX_TOTAL_COST,
250
+ {
251
+ unit: 'eth',
252
+ description: 'Total cost in ETH for blob transactions in mined blocks',
253
+ valueType: ValueType.DOUBLE,
254
+ },
255
+ );
91
256
  }
92
257
 
93
- recordTimeToCollectAttestations(time: number) {
94
- this.timeToCollectAttestations.record(time);
258
+ public recordRequiredAttestations(requiredAttestationsCount: number, allowanceMs: number) {
259
+ this.requiredAttestions.record(requiredAttestationsCount);
260
+ this.allowanceToCollectAttestations.record(Math.ceil(allowanceMs));
261
+
262
+ // reset
263
+ this.collectedAttestions.record(0);
264
+ this.timeToCollectAttestations.record(0);
95
265
  }
96
266
 
97
- recordBlockBuilderTreeInsertions(timeUs: number) {
98
- this.blockBuilderInsertions.record(Math.ceil(timeUs));
267
+ public recordBlockAttestationDelay(duration: number) {
268
+ this.blockAttestationDelay.record(duration);
99
269
  }
100
270
 
101
- recordCancelledBlock() {
102
- this.blockCounter.add(1, {
103
- [Attributes.STATUS]: 'cancelled',
104
- });
105
- this.setCurrentBlock(0, 0);
271
+ public recordCollectedAttestations(count: number, durationMs: number) {
272
+ this.collectedAttestions.record(count);
273
+ this.timeToCollectAttestations.record(Math.ceil(durationMs));
106
274
  }
107
275
 
108
276
  recordBuiltBlock(buildDurationMs: number, totalMana: number) {
@@ -117,11 +285,6 @@ export class SequencerMetrics {
117
285
  this.blockCounter.add(1, {
118
286
  [Attributes.STATUS]: 'failed',
119
287
  });
120
- this.setCurrentBlock(0, 0);
121
- }
122
-
123
- recordNewBlock(blockNumber: number, txCount: number) {
124
- this.setCurrentBlock(blockNumber, txCount);
125
288
  }
126
289
 
127
290
  recordStateTransitionBufferMs(durationMs: number, state: SequencerState) {
@@ -130,8 +293,150 @@ export class SequencerMetrics {
130
293
  });
131
294
  }
132
295
 
133
- private setCurrentBlock(blockNumber: number, txCount: number) {
134
- this.currentBlockNumber.record(blockNumber);
135
- this.currentBlockSize.record(txCount);
296
+ incOpenSlot(slot: SlotNumber, proposer: string) {
297
+ // sequencer went through the loop a second time. Noop
298
+ if (slot === this.lastSeenSlot) {
299
+ return;
300
+ }
301
+
302
+ this.slots.add(1, {
303
+ [Attributes.BLOCK_PROPOSER]: proposer,
304
+ });
305
+
306
+ this.lastSeenSlot = slot;
307
+ }
308
+
309
+ async incFilledSlot(proposer: string, coinbase: Hex | EthAddress | undefined): Promise<void> {
310
+ this.filledSlots.add(1, {
311
+ [Attributes.BLOCK_PROPOSER]: proposer,
312
+ });
313
+ this.lastSeenSlot = undefined;
314
+
315
+ if (coinbase) {
316
+ try {
317
+ const rewards = await this.rollup.getSequencerRewards(coinbase);
318
+ const fmt = parseFloat(formatUnits(rewards, 18));
319
+ this.rewards.record(fmt, {
320
+ [Attributes.COINBASE]: coinbase.toString(),
321
+ });
322
+ } catch {
323
+ // no-op
324
+ }
325
+ }
326
+ }
327
+
328
+ recordCheckpointSuccess() {
329
+ this.checkpointSuccess.add(1);
330
+ }
331
+
332
+ recordBlockProposalFailed(reason?: string) {
333
+ this.blockProposalFailed.add(1, {
334
+ ...(reason && { [Attributes.ERROR_TYPE]: reason }),
335
+ });
336
+ }
337
+
338
+ recordBlockProposalSuccess() {
339
+ this.blockProposalSuccess.add(1);
340
+ }
341
+
342
+ recordBlockProposalPrecheckFailed(checkType: string) {
343
+ this.blockProposalPrecheckFailed.add(1, {
344
+ [Attributes.ERROR_TYPE]: checkType,
345
+ });
346
+ }
347
+
348
+ recordSlashingAttempt(actionCount: number) {
349
+ this.slashingAttempts.add(actionCount);
350
+ }
351
+
352
+ /**
353
+ * Records metrics for a completed fisherman fee analysis
354
+ * @param analysis - The completed fee analysis result
355
+ */
356
+ recordFishermanFeeAnalysis(analysis: L1FeeAnalysisResult) {
357
+ // In fisherman mode, we should always have strategy results
358
+ if (!analysis.computedPrices.strategyResults || analysis.computedPrices.strategyResults.length === 0) {
359
+ // This should never happen in fisherman mode - log an error
360
+ // We don't record metrics without strategy IDs as that defeats the purpose
361
+ throw new Error(
362
+ `No strategy results found in fisherman fee analysis ${analysis.id}. This indicates a bug in the fee analysis.`,
363
+ );
364
+ }
365
+
366
+ // Record metrics for each strategy separately
367
+ for (const strategyResult of analysis.computedPrices.strategyResults) {
368
+ const strategyAttributes = {
369
+ [Attributes.FISHERMAN_FEE_STRATEGY_ID]: strategyResult.strategyId,
370
+ };
371
+
372
+ // Record pending block snapshot data (once per strategy for comparison)
373
+ this.fishermanPendingBlobTxCount.record(analysis.pendingSnapshot.pendingBlobTxCount, strategyAttributes);
374
+
375
+ // Record mined block data if available
376
+ if (analysis.minedBlock) {
377
+ this.fishermanIncludedBlobTxCount.record(analysis.minedBlock.includedBlobTxCount, strategyAttributes);
378
+
379
+ // Record actual fees from blob transactions in the mined block
380
+ for (const blobTx of analysis.minedBlock.includedBlobTxs) {
381
+ // Record priority fee per gas in Gwei
382
+ const priorityFeeGwei = Number(blobTx.maxPriorityFeePerGas) / 1e9;
383
+ this.fishermanMinedBlobTxPriorityFee.record(priorityFeeGwei, strategyAttributes);
384
+
385
+ // Calculate total cost in ETH
386
+ // Cost = (gas * (baseFee + priorityFee)) + (blobCount * blobGasPerBlob * blobBaseFee)
387
+ const baseFee = analysis.minedBlock.baseFeePerGas;
388
+ const effectiveGasPrice = baseFee + blobTx.maxPriorityFeePerGas;
389
+
390
+ // Calculate execution cost using actual gas limit from the transaction
391
+ const executionCost = blobTx.gas * effectiveGasPrice;
392
+
393
+ // Calculate blob cost using maxFeePerBlobGas * blobCount * GAS_PER_BLOB
394
+ const blobCost = blobTx.maxFeePerBlobGas * BigInt(blobTx.blobCount) * 131072n; // 128KB per blob
395
+
396
+ const totalCostWei = executionCost + blobCost;
397
+ const totalCostEth = Number(totalCostWei) / 1e18;
398
+
399
+ this.fishermanMinedBlobTxTotalCost.record(totalCostEth, strategyAttributes);
400
+ }
401
+ }
402
+
403
+ // Record the calculated priority fee for this strategy
404
+ const calculatedPriorityFeeGwei = Number(strategyResult.calculatedPriorityFee) / 1e9;
405
+ this.fishermanCalculatedPriorityFee.record(calculatedPriorityFeeGwei, strategyAttributes);
406
+
407
+ // Record analysis results if available
408
+ if (analysis.analysis) {
409
+ this.fishermanTimeBeforeBlock.record(Math.ceil(analysis.analysis.timeBeforeBlockMs), strategyAttributes);
410
+
411
+ // Record strategy-specific inclusion result
412
+ if (strategyResult.wouldBeIncluded !== undefined) {
413
+ if (strategyResult.wouldBeIncluded) {
414
+ this.fishermanWouldBeIncluded.add(1, { ...strategyAttributes, [Attributes.OK]: true });
415
+ } else {
416
+ this.fishermanWouldBeIncluded.add(1, {
417
+ ...strategyAttributes,
418
+ [Attributes.OK]: false,
419
+ ...(strategyResult.exclusionReason && { [Attributes.ERROR_TYPE]: strategyResult.exclusionReason }),
420
+ });
421
+ }
422
+ }
423
+
424
+ // Record strategy-specific priority fee delta
425
+ if (strategyResult.priorityFeeDelta !== undefined) {
426
+ const priorityFeeDeltaGwei = Number(strategyResult.priorityFeeDelta) / 1e9;
427
+ this.fishermanPriorityFeeDelta.record(priorityFeeDeltaGwei, strategyAttributes);
428
+ }
429
+
430
+ // Record estimated cost if available
431
+ if (strategyResult.estimatedCostEth !== undefined) {
432
+ this.fishermanEstimatedCost.record(strategyResult.estimatedCostEth, strategyAttributes);
433
+ }
434
+
435
+ // Record estimated overpayment if available
436
+ if (strategyResult.estimatedOverpaymentEth !== undefined) {
437
+ this.fishermanEstimatedOverpayment.record(strategyResult.estimatedOverpaymentEth, strategyAttributes);
438
+ }
439
+ }
440
+ }
136
441
  }
137
442
  }