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

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