@aztec/sequencer-client 0.0.0-test.1 → 0.0.1-commit.b655e406

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 (110) hide show
  1. package/dest/client/sequencer-client.d.ts +25 -25
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +65 -51
  4. package/dest/config.d.ts +6 -14
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +50 -54
  7. package/dest/global_variable_builder/global_builder.d.ts +11 -6
  8. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  9. package/dest/global_variable_builder/global_builder.js +39 -34
  10. package/dest/index.d.ts +1 -2
  11. package/dest/index.d.ts.map +1 -1
  12. package/dest/index.js +1 -2
  13. package/dest/publisher/config.d.ts +6 -8
  14. package/dest/publisher/config.d.ts.map +1 -1
  15. package/dest/publisher/config.js +19 -17
  16. package/dest/publisher/index.d.ts +2 -0
  17. package/dest/publisher/index.d.ts.map +1 -1
  18. package/dest/publisher/index.js +3 -0
  19. package/dest/publisher/sequencer-publisher-factory.d.ts +43 -0
  20. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
  21. package/dest/publisher/sequencer-publisher-factory.js +51 -0
  22. package/dest/publisher/sequencer-publisher-metrics.d.ts +2 -1
  23. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  24. package/dest/publisher/sequencer-publisher-metrics.js +37 -2
  25. package/dest/publisher/sequencer-publisher.d.ts +102 -69
  26. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  27. package/dest/publisher/sequencer-publisher.js +606 -212
  28. package/dest/sequencer/block_builder.d.ts +27 -0
  29. package/dest/sequencer/block_builder.d.ts.map +1 -0
  30. package/dest/sequencer/block_builder.js +130 -0
  31. package/dest/sequencer/config.d.ts +5 -0
  32. package/dest/sequencer/config.d.ts.map +1 -1
  33. package/dest/sequencer/errors.d.ts +11 -0
  34. package/dest/sequencer/errors.d.ts.map +1 -0
  35. package/dest/sequencer/errors.js +15 -0
  36. package/dest/sequencer/index.d.ts +1 -1
  37. package/dest/sequencer/index.d.ts.map +1 -1
  38. package/dest/sequencer/index.js +1 -1
  39. package/dest/sequencer/metrics.d.ts +18 -11
  40. package/dest/sequencer/metrics.d.ts.map +1 -1
  41. package/dest/sequencer/metrics.js +84 -50
  42. package/dest/sequencer/sequencer.d.ts +120 -81
  43. package/dest/sequencer/sequencer.d.ts.map +1 -1
  44. package/dest/sequencer/sequencer.js +589 -359
  45. package/dest/sequencer/timetable.d.ts +32 -20
  46. package/dest/sequencer/timetable.d.ts.map +1 -1
  47. package/dest/sequencer/timetable.js +57 -30
  48. package/dest/sequencer/utils.d.ts +11 -35
  49. package/dest/sequencer/utils.d.ts.map +1 -1
  50. package/dest/sequencer/utils.js +9 -47
  51. package/dest/test/index.d.ts +7 -0
  52. package/dest/test/index.d.ts.map +1 -1
  53. package/dest/test/index.js +0 -4
  54. package/dest/tx_validator/nullifier_cache.d.ts +0 -2
  55. package/dest/tx_validator/nullifier_cache.d.ts.map +1 -1
  56. package/dest/tx_validator/tx_validator_factory.d.ts +9 -10
  57. package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -1
  58. package/dest/tx_validator/tx_validator_factory.js +27 -24
  59. package/package.json +42 -43
  60. package/src/client/sequencer-client.ts +94 -84
  61. package/src/config.ts +57 -61
  62. package/src/global_variable_builder/global_builder.ts +44 -23
  63. package/src/index.ts +6 -2
  64. package/src/publisher/config.ts +26 -24
  65. package/src/publisher/index.ts +4 -0
  66. package/src/publisher/sequencer-publisher-factory.ts +90 -0
  67. package/src/publisher/sequencer-publisher-metrics.ts +24 -2
  68. package/src/publisher/sequencer-publisher.ts +729 -235
  69. package/src/sequencer/block_builder.ts +218 -0
  70. package/src/sequencer/config.ts +7 -0
  71. package/src/sequencer/errors.ts +21 -0
  72. package/src/sequencer/index.ts +1 -1
  73. package/src/sequencer/metrics.ts +109 -55
  74. package/src/sequencer/sequencer.ts +766 -415
  75. package/src/sequencer/timetable.ts +98 -33
  76. package/src/sequencer/utils.ts +17 -58
  77. package/src/test/index.ts +11 -4
  78. package/src/tx_validator/tx_validator_factory.ts +44 -32
  79. package/dest/sequencer/allowed.d.ts +0 -3
  80. package/dest/sequencer/allowed.d.ts.map +0 -1
  81. package/dest/sequencer/allowed.js +0 -27
  82. package/dest/slasher/factory.d.ts +0 -7
  83. package/dest/slasher/factory.d.ts.map +0 -1
  84. package/dest/slasher/factory.js +0 -8
  85. package/dest/slasher/index.d.ts +0 -3
  86. package/dest/slasher/index.d.ts.map +0 -1
  87. package/dest/slasher/index.js +0 -2
  88. package/dest/slasher/slasher_client.d.ts +0 -75
  89. package/dest/slasher/slasher_client.d.ts.map +0 -1
  90. package/dest/slasher/slasher_client.js +0 -132
  91. package/dest/tx_validator/archive_cache.d.ts +0 -14
  92. package/dest/tx_validator/archive_cache.d.ts.map +0 -1
  93. package/dest/tx_validator/archive_cache.js +0 -22
  94. package/dest/tx_validator/gas_validator.d.ts +0 -14
  95. package/dest/tx_validator/gas_validator.d.ts.map +0 -1
  96. package/dest/tx_validator/gas_validator.js +0 -78
  97. package/dest/tx_validator/phases_validator.d.ts +0 -12
  98. package/dest/tx_validator/phases_validator.d.ts.map +0 -1
  99. package/dest/tx_validator/phases_validator.js +0 -80
  100. package/dest/tx_validator/test_utils.d.ts +0 -23
  101. package/dest/tx_validator/test_utils.d.ts.map +0 -1
  102. package/dest/tx_validator/test_utils.js +0 -26
  103. package/src/sequencer/allowed.ts +0 -36
  104. package/src/slasher/factory.ts +0 -15
  105. package/src/slasher/index.ts +0 -2
  106. package/src/slasher/slasher_client.ts +0 -193
  107. package/src/tx_validator/archive_cache.ts +0 -28
  108. package/src/tx_validator/gas_validator.ts +0 -101
  109. package/src/tx_validator/phases_validator.ts +0 -98
  110. package/src/tx_validator/test_utils.ts +0 -48
@@ -0,0 +1,218 @@
1
+ import { MerkleTreeId } from '@aztec/aztec.js/trees';
2
+ import { merge, pick } from '@aztec/foundation/collection';
3
+ import type { Fr } from '@aztec/foundation/fields';
4
+ import { createLogger } from '@aztec/foundation/log';
5
+ import { retryUntil } from '@aztec/foundation/retry';
6
+ import { bufferToHex } from '@aztec/foundation/string';
7
+ import { DateProvider, Timer, elapsed } from '@aztec/foundation/timer';
8
+ import { getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
9
+ import { LightweightBlockFactory } from '@aztec/prover-client/block-factory';
10
+ import {
11
+ GuardedMerkleTreeOperations,
12
+ PublicContractsDB,
13
+ PublicProcessor,
14
+ TelemetryPublicTxSimulator,
15
+ } from '@aztec/simulator/server';
16
+ import type { ContractDataSource } from '@aztec/stdlib/contract';
17
+ import { type L1RollupConstants, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
18
+ import { Gas } from '@aztec/stdlib/gas';
19
+ import type {
20
+ BuildBlockResult,
21
+ FullNodeBlockBuilderConfig,
22
+ IFullNodeBlockBuilder,
23
+ MerkleTreeWriteOperations,
24
+ PublicProcessorLimits,
25
+ PublicProcessorValidator,
26
+ WorldStateSynchronizer,
27
+ } from '@aztec/stdlib/interfaces/server';
28
+ import { GlobalVariables, Tx } from '@aztec/stdlib/tx';
29
+ import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
30
+
31
+ import { createValidatorForBlockBuilding } from '../tx_validator/tx_validator_factory.js';
32
+
33
+ const log = createLogger('block-builder');
34
+
35
+ export async function buildBlock(
36
+ pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
37
+ l1ToL2Messages: Fr[],
38
+ newGlobalVariables: GlobalVariables,
39
+ opts: PublicProcessorLimits = {},
40
+ worldStateFork: MerkleTreeWriteOperations,
41
+ processor: PublicProcessor,
42
+ validator: PublicProcessorValidator,
43
+ l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>,
44
+ dateProvider: DateProvider,
45
+ telemetryClient: TelemetryClient = getTelemetryClient(),
46
+ ): Promise<BuildBlockResult> {
47
+ const blockBuildingTimer = new Timer();
48
+ const blockNumber = newGlobalVariables.blockNumber;
49
+ const slot = newGlobalVariables.slotNumber.toBigInt();
50
+ const msgCount = l1ToL2Messages.length;
51
+ const stateReference = await worldStateFork.getStateReference();
52
+ const archiveTree = await worldStateFork.getTreeInfo(MerkleTreeId.ARCHIVE);
53
+
54
+ log.verbose(`Building block ${blockNumber} for slot ${slot}`, {
55
+ slot,
56
+ slotStart: new Date(Number(getTimestampForSlot(slot, l1Constants)) * 1000),
57
+ now: new Date(dateProvider.now()),
58
+ blockNumber,
59
+ msgCount,
60
+ initialStateReference: stateReference.toInspect(),
61
+ initialArchiveRoot: bufferToHex(archiveTree.root),
62
+ opts,
63
+ });
64
+ const blockFactory = new LightweightBlockFactory(worldStateFork, telemetryClient);
65
+ await blockFactory.startNewBlock(newGlobalVariables, l1ToL2Messages);
66
+
67
+ const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(() =>
68
+ processor.process(pendingTxs, opts, validator),
69
+ );
70
+
71
+ // All real transactions have been added, set the block as full and pad if needed
72
+ await blockFactory.addTxs(processedTxs);
73
+ const block = await blockFactory.setBlockCompleted();
74
+
75
+ // How much public gas was processed
76
+ const publicGas = processedTxs.reduce((acc, tx) => acc.add(tx.gasUsed.publicGas), Gas.empty());
77
+
78
+ const res = {
79
+ block,
80
+ publicGas,
81
+ publicProcessorDuration,
82
+ numMsgs: l1ToL2Messages.length,
83
+ numTxs: processedTxs.length,
84
+ failedTxs: failedTxs,
85
+ blockBuildingTimer,
86
+ usedTxs,
87
+ };
88
+ log.trace('Built block', res.block.header);
89
+ return res;
90
+ }
91
+
92
+ const FullNodeBlockBuilderConfigKeys = [
93
+ 'l1GenesisTime',
94
+ 'slotDuration',
95
+ 'l1ChainId',
96
+ 'rollupVersion',
97
+ 'txPublicSetupAllowList',
98
+ 'fakeProcessingDelayPerTxMs',
99
+ ] as const;
100
+
101
+ export class FullNodeBlockBuilder implements IFullNodeBlockBuilder {
102
+ constructor(
103
+ private config: FullNodeBlockBuilderConfig,
104
+ private worldState: WorldStateSynchronizer,
105
+ private contractDataSource: ContractDataSource,
106
+ private dateProvider: DateProvider,
107
+ private telemetryClient: TelemetryClient = getTelemetryClient(),
108
+ ) {}
109
+
110
+ public getConfig(): FullNodeBlockBuilderConfig {
111
+ return pick(this.config, ...FullNodeBlockBuilderConfigKeys);
112
+ }
113
+
114
+ public updateConfig(config: Partial<FullNodeBlockBuilderConfig>) {
115
+ this.config = merge(this.config, pick(config, ...FullNodeBlockBuilderConfigKeys));
116
+ }
117
+
118
+ public async makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations) {
119
+ const txPublicSetupAllowList = this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
120
+ const contractsDB = new PublicContractsDB(this.contractDataSource);
121
+ const guardedFork = new GuardedMerkleTreeOperations(fork);
122
+
123
+ const publicTxSimulator = new TelemetryPublicTxSimulator(
124
+ guardedFork,
125
+ contractsDB,
126
+ globalVariables,
127
+ this.telemetryClient,
128
+ {
129
+ doMerkleOperations: true,
130
+ skipFeeEnforcement: true,
131
+ clientInitiatedSimulation: false,
132
+ },
133
+ );
134
+
135
+ const processor = new PublicProcessor(
136
+ globalVariables,
137
+ guardedFork,
138
+ contractsDB,
139
+ publicTxSimulator,
140
+ this.dateProvider,
141
+ this.telemetryClient,
142
+ undefined,
143
+ this.config,
144
+ );
145
+
146
+ const validator = createValidatorForBlockBuilding(
147
+ fork,
148
+ this.contractDataSource,
149
+ globalVariables,
150
+ txPublicSetupAllowList,
151
+ );
152
+
153
+ return {
154
+ processor,
155
+ validator,
156
+ };
157
+ }
158
+
159
+ private async syncToPreviousBlock(parentBlockNumber: number, timeout: number | undefined) {
160
+ await retryUntil(
161
+ () => this.worldState.syncImmediate(parentBlockNumber, true).then(syncedTo => syncedTo >= parentBlockNumber),
162
+ 'sync to previous block',
163
+ timeout,
164
+ 0.1,
165
+ );
166
+ log.debug(`Synced to previous block ${parentBlockNumber}`);
167
+ }
168
+
169
+ async buildBlock(
170
+ pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
171
+ l1ToL2Messages: Fr[],
172
+ globalVariables: GlobalVariables,
173
+ opts: PublicProcessorLimits,
174
+ suppliedFork?: MerkleTreeWriteOperations,
175
+ ): Promise<BuildBlockResult> {
176
+ const parentBlockNumber = globalVariables.blockNumber - 1;
177
+ const syncTimeout = opts.deadline ? (opts.deadline.getTime() - this.dateProvider.now()) / 1000 : undefined;
178
+ await this.syncToPreviousBlock(parentBlockNumber, syncTimeout);
179
+ const fork = suppliedFork ?? (await this.worldState.fork(parentBlockNumber));
180
+
181
+ try {
182
+ const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, fork);
183
+ const res = await buildBlock(
184
+ pendingTxs,
185
+ l1ToL2Messages,
186
+ globalVariables,
187
+ opts,
188
+ fork,
189
+ processor,
190
+ validator,
191
+ this.config,
192
+ this.dateProvider,
193
+ this.telemetryClient,
194
+ );
195
+ return res;
196
+ } finally {
197
+ // If the fork was supplied, we don't close it.
198
+ // Otherwise, we wait a bit to close the fork we just created,
199
+ // since the processor may still be working on a dangling tx
200
+ // which was interrupted due to the processingDeadline being hit.
201
+ if (!suppliedFork) {
202
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
203
+ setTimeout(async () => {
204
+ try {
205
+ await fork.close();
206
+ } catch (err) {
207
+ // This can happen if the sequencer is stopped before we hit this timeout.
208
+ log.warn(`Error closing forks for block processing`, err);
209
+ }
210
+ }, 5000);
211
+ }
212
+ }
213
+ }
214
+
215
+ getFork(blockNumber: number): Promise<MerkleTreeWriteOperations> {
216
+ return this.worldState.fork(blockNumber);
217
+ }
218
+ }
@@ -1 +1,8 @@
1
+ import type { GovernanceProposerContract, RollupContract } from '@aztec/ethereum';
2
+
1
3
  export { type SequencerConfig } from '@aztec/stdlib/config';
4
+
5
+ export type SequencerContracts = {
6
+ rollupContract: RollupContract;
7
+ governanceProposerContract: GovernanceProposerContract;
8
+ };
@@ -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
+ }
@@ -1,3 +1,3 @@
1
+ export * from './block_builder.js';
1
2
  export * from './config.js';
2
3
  export * from './sequencer.js';
3
- export * from './allowed.js';
@@ -1,7 +1,10 @@
1
+ import { EthAddress } from '@aztec/aztec.js/addresses';
2
+ import type { RollupContract } from '@aztec/ethereum';
1
3
  import {
2
4
  Attributes,
3
5
  type Gauge,
4
6
  type Histogram,
7
+ type Meter,
5
8
  Metrics,
6
9
  type TelemetryClient,
7
10
  type Tracer,
@@ -9,100 +12,129 @@ import {
9
12
  ValueType,
10
13
  } from '@aztec/telemetry-client';
11
14
 
12
- import { type SequencerState, type SequencerStateCallback, sequencerStateToNumber } from './utils.js';
15
+ import { type Hex, formatUnits } from 'viem';
16
+
17
+ import type { SequencerState } from './utils.js';
13
18
 
14
19
  export class SequencerMetrics {
15
20
  public readonly tracer: Tracer;
21
+ private meter: Meter;
16
22
 
17
23
  private blockCounter: UpDownCounter;
18
24
  private blockBuildDuration: Histogram;
19
25
  private blockBuildManaPerSecond: Gauge;
20
26
  private stateTransitionBufferDuration: Histogram;
21
- private currentBlockNumber: Gauge;
22
- private currentBlockSize: Gauge;
23
- private blockBuilderInsertions: Histogram;
24
27
 
28
+ // these are gauges because for individual sequencers building a block is not something that happens often enough to warrant a histogram
25
29
  private timeToCollectAttestations: Gauge;
30
+ private allowanceToCollectAttestations: Gauge;
31
+ private requiredAttestions: Gauge;
32
+ private collectedAttestions: Gauge;
33
+
34
+ private rewards: Gauge;
35
+
36
+ private slots: UpDownCounter;
37
+ private filledSlots: UpDownCounter;
38
+
39
+ private lastSeenSlot?: bigint;
26
40
 
27
- constructor(client: TelemetryClient, getState: SequencerStateCallback, name = 'Sequencer') {
28
- const meter = client.getMeter(name);
41
+ constructor(
42
+ client: TelemetryClient,
43
+ private rollup: RollupContract,
44
+ name = 'Sequencer',
45
+ ) {
46
+ this.meter = client.getMeter(name);
29
47
  this.tracer = client.getTracer(name);
30
48
 
31
- this.blockCounter = meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_COUNT);
49
+ this.blockCounter = this.meter.createUpDownCounter(Metrics.SEQUENCER_BLOCK_COUNT);
32
50
 
33
- this.blockBuildDuration = meter.createHistogram(Metrics.SEQUENCER_BLOCK_BUILD_DURATION, {
51
+ this.blockBuildDuration = this.meter.createHistogram(Metrics.SEQUENCER_BLOCK_BUILD_DURATION, {
34
52
  unit: 'ms',
35
53
  description: 'Duration to build a block',
36
54
  valueType: ValueType.INT,
37
55
  });
38
56
 
39
- this.blockBuildManaPerSecond = meter.createGauge(Metrics.SEQUENCER_BLOCK_BUILD_MANA_PER_SECOND, {
57
+ this.blockBuildManaPerSecond = this.meter.createGauge(Metrics.SEQUENCER_BLOCK_BUILD_MANA_PER_SECOND, {
40
58
  unit: 'mana/s',
41
59
  description: 'Mana per second when building a block',
42
60
  valueType: ValueType.INT,
43
61
  });
44
62
 
45
- this.stateTransitionBufferDuration = meter.createHistogram(Metrics.SEQUENCER_STATE_TRANSITION_BUFFER_DURATION, {
46
- unit: 'ms',
47
- description:
48
- 'The time difference between when the sequencer needed to transition to a new state and when it actually did.',
49
- valueType: ValueType.INT,
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
+ );
72
+
73
+ // Init gauges and counters
74
+ this.blockCounter.add(0, {
75
+ [Attributes.STATUS]: 'failed',
50
76
  });
51
-
52
- const currentState = meter.createObservableGauge(Metrics.SEQUENCER_CURRENT_STATE, {
53
- description: 'Current state of the sequencer',
77
+ this.blockCounter.add(0, {
78
+ [Attributes.STATUS]: 'built',
54
79
  });
55
80
 
56
- currentState.addCallback(observer => {
57
- observer.observe(sequencerStateToNumber(getState()));
81
+ this.rewards = this.meter.createGauge(Metrics.SEQUENCER_CURRENT_BLOCK_REWARDS, {
82
+ valueType: ValueType.DOUBLE,
83
+ description: 'The rewards earned',
58
84
  });
59
85
 
60
- this.currentBlockNumber = meter.createGauge(Metrics.SEQUENCER_CURRENT_BLOCK_NUMBER, {
61
- description: 'Current block number',
86
+ this.slots = this.meter.createUpDownCounter(Metrics.SEQUENCER_SLOT_COUNT, {
62
87
  valueType: ValueType.INT,
88
+ description: 'The number of slots this sequencer was selected for',
63
89
  });
64
90
 
65
- this.currentBlockSize = meter.createGauge(Metrics.SEQUENCER_CURRENT_BLOCK_SIZE, {
66
- description: 'Current block size',
91
+ /**
92
+ * NOTE: we do not track missed slots as a separate metric. That would be difficult to determine
93
+ * Instead, use a computed metric, `slots - filledSlots` to get the number of slots a sequencer has missed.
94
+ */
95
+ this.filledSlots = this.meter.createUpDownCounter(Metrics.SEQUENCER_FILLED_SLOT_COUNT, {
67
96
  valueType: ValueType.INT,
97
+ description: 'The number of slots this sequencer has filled',
68
98
  });
69
99
 
70
- this.timeToCollectAttestations = meter.createGauge(Metrics.SEQUENCER_TIME_TO_COLLECT_ATTESTATIONS, {
100
+ this.timeToCollectAttestations = this.meter.createGauge(Metrics.SEQUENCER_COLLECT_ATTESTATIONS_DURATION, {
71
101
  description: 'The time spent collecting attestations from committee members',
102
+ unit: 'ms',
72
103
  valueType: ValueType.INT,
73
104
  });
74
105
 
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',
106
+ this.allowanceToCollectAttestations = this.meter.createGauge(
107
+ Metrics.SEQUENCER_COLLECT_ATTESTATIONS_TIME_ALLOWANCE,
108
+ {
109
+ description: 'Maximum amount of time to collect attestations',
110
+ unit: 'ms',
111
+ valueType: ValueType.INT,
112
+ },
113
+ );
114
+
115
+ this.requiredAttestions = this.meter.createGauge(Metrics.SEQUENCER_REQUIRED_ATTESTATIONS_COUNT, {
78
116
  valueType: ValueType.INT,
117
+ description: 'The minimum number of attestations required to publish a block',
79
118
  });
80
119
 
81
- this.setCurrentBlock(0, 0);
82
- }
83
-
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);
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
+ });
91
124
  }
92
125
 
93
- recordTimeToCollectAttestations(time: number) {
94
- this.timeToCollectAttestations.record(time);
95
- }
126
+ public recordRequiredAttestations(requiredAttestationsCount: number, allowanceMs: number) {
127
+ this.requiredAttestions.record(requiredAttestationsCount);
128
+ this.allowanceToCollectAttestations.record(Math.ceil(allowanceMs));
96
129
 
97
- recordBlockBuilderTreeInsertions(timeUs: number) {
98
- this.blockBuilderInsertions.record(Math.ceil(timeUs));
130
+ // reset
131
+ this.collectedAttestions.record(0);
132
+ this.timeToCollectAttestations.record(0);
99
133
  }
100
134
 
101
- recordCancelledBlock() {
102
- this.blockCounter.add(1, {
103
- [Attributes.STATUS]: 'cancelled',
104
- });
105
- this.setCurrentBlock(0, 0);
135
+ public recordCollectedAttestations(count: number, durationMs: number) {
136
+ this.collectedAttestions.record(count);
137
+ this.timeToCollectAttestations.record(Math.ceil(durationMs));
106
138
  }
107
139
 
108
140
  recordBuiltBlock(buildDurationMs: number, totalMana: number) {
@@ -117,11 +149,6 @@ export class SequencerMetrics {
117
149
  this.blockCounter.add(1, {
118
150
  [Attributes.STATUS]: 'failed',
119
151
  });
120
- this.setCurrentBlock(0, 0);
121
- }
122
-
123
- recordNewBlock(blockNumber: number, txCount: number) {
124
- this.setCurrentBlock(blockNumber, txCount);
125
152
  }
126
153
 
127
154
  recordStateTransitionBufferMs(durationMs: number, state: SequencerState) {
@@ -130,8 +157,35 @@ export class SequencerMetrics {
130
157
  });
131
158
  }
132
159
 
133
- private setCurrentBlock(blockNumber: number, txCount: number) {
134
- this.currentBlockNumber.record(blockNumber);
135
- this.currentBlockSize.record(txCount);
160
+ incOpenSlot(slot: bigint, proposer: string) {
161
+ // sequencer went through the loop a second time. Noop
162
+ if (slot === this.lastSeenSlot) {
163
+ return;
164
+ }
165
+
166
+ this.slots.add(1, {
167
+ [Attributes.BLOCK_PROPOSER]: proposer,
168
+ });
169
+
170
+ this.lastSeenSlot = slot;
171
+ }
172
+
173
+ async incFilledSlot(proposer: string, coinbase: Hex | EthAddress | undefined): Promise<void> {
174
+ this.filledSlots.add(1, {
175
+ [Attributes.BLOCK_PROPOSER]: proposer,
176
+ });
177
+ this.lastSeenSlot = undefined;
178
+
179
+ if (coinbase) {
180
+ try {
181
+ const rewards = await this.rollup.getSequencerRewards(coinbase);
182
+ const fmt = parseFloat(formatUnits(rewards, 18));
183
+ this.rewards.record(fmt, {
184
+ [Attributes.COINBASE]: coinbase.toString(),
185
+ });
186
+ } catch {
187
+ // no-op
188
+ }
189
+ }
136
190
  }
137
191
  }