@aztec-labs/sequencer-client 6.0.0-nightly.20260829

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 (165) hide show
  1. package/README.md +307 -0
  2. package/dest/client/index.d.ts +2 -0
  3. package/dest/client/index.d.ts.map +1 -0
  4. package/dest/client/index.js +1 -0
  5. package/dest/client/sequencer-client.d.ts +94 -0
  6. package/dest/client/sequencer-client.d.ts.map +1 -0
  7. package/dest/client/sequencer-client.js +177 -0
  8. package/dest/config.d.ts +56 -0
  9. package/dest/config.d.ts.map +1 -0
  10. package/dest/config.js +251 -0
  11. package/dest/global_variable_builder/fee_predictor.d.ts +49 -0
  12. package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
  13. package/dest/global_variable_builder/fee_predictor.js +127 -0
  14. package/dest/global_variable_builder/fee_provider.d.ts +28 -0
  15. package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
  16. package/dest/global_variable_builder/fee_provider.js +87 -0
  17. package/dest/global_variable_builder/global_builder.d.ts +28 -0
  18. package/dest/global_variable_builder/global_builder.d.ts.map +1 -0
  19. package/dest/global_variable_builder/global_builder.js +40 -0
  20. package/dest/global_variable_builder/index.d.ts +4 -0
  21. package/dest/global_variable_builder/index.d.ts.map +1 -0
  22. package/dest/global_variable_builder/index.js +3 -0
  23. package/dest/index.d.ts +7 -0
  24. package/dest/index.d.ts.map +1 -0
  25. package/dest/index.js +8 -0
  26. package/dest/publisher/config.d.ts +68 -0
  27. package/dest/publisher/config.d.ts.map +1 -0
  28. package/dest/publisher/config.js +137 -0
  29. package/dest/publisher/index.d.ts +5 -0
  30. package/dest/publisher/index.d.ts.map +1 -0
  31. package/dest/publisher/index.js +4 -0
  32. package/dest/publisher/l1_to_l2_messaging.d.ts +21 -0
  33. package/dest/publisher/l1_to_l2_messaging.d.ts.map +1 -0
  34. package/dest/publisher/l1_to_l2_messaging.js +70 -0
  35. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  36. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  37. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  38. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +101 -0
  39. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  40. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +68 -0
  41. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  42. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  43. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +36 -0
  44. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  45. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  46. package/dest/publisher/l1_tx_failed_store/index.js +3 -0
  47. package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
  48. package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
  49. package/dest/publisher/sequencer-bundle-simulator.js +198 -0
  50. package/dest/publisher/sequencer-publisher-factory.d.ts +50 -0
  51. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
  52. package/dest/publisher/sequencer-publisher-factory.js +75 -0
  53. package/dest/publisher/sequencer-publisher-metrics.d.ts +26 -0
  54. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -0
  55. package/dest/publisher/sequencer-publisher-metrics.js +101 -0
  56. package/dest/publisher/sequencer-publisher.d.ts +254 -0
  57. package/dest/publisher/sequencer-publisher.d.ts.map +1 -0
  58. package/dest/publisher/sequencer-publisher.js +1784 -0
  59. package/dest/publisher/write_json.d.ts +11 -0
  60. package/dest/publisher/write_json.d.ts.map +1 -0
  61. package/dest/publisher/write_json.js +57 -0
  62. package/dest/sequencer/automine/automine_factory.d.ts +56 -0
  63. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
  64. package/dest/sequencer/automine/automine_factory.js +85 -0
  65. package/dest/sequencer/automine/automine_sequencer.d.ts +189 -0
  66. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
  67. package/dest/sequencer/automine/automine_sequencer.js +732 -0
  68. package/dest/sequencer/automine/index.d.ts +3 -0
  69. package/dest/sequencer/automine/index.d.ts.map +1 -0
  70. package/dest/sequencer/automine/index.js +2 -0
  71. package/dest/sequencer/checkpoint_proposal_job.d.ts +169 -0
  72. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  73. package/dest/sequencer/checkpoint_proposal_job.js +1961 -0
  74. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  75. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  76. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  77. package/dest/sequencer/checkpoint_voter.d.ts +34 -0
  78. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  79. package/dest/sequencer/checkpoint_voter.js +106 -0
  80. package/dest/sequencer/config.d.ts +8 -0
  81. package/dest/sequencer/config.d.ts.map +1 -0
  82. package/dest/sequencer/config.js +1 -0
  83. package/dest/sequencer/errors.d.ts +11 -0
  84. package/dest/sequencer/errors.d.ts.map +1 -0
  85. package/dest/sequencer/errors.js +15 -0
  86. package/dest/sequencer/events.d.ts +103 -0
  87. package/dest/sequencer/events.d.ts.map +1 -0
  88. package/dest/sequencer/events.js +1 -0
  89. package/dest/sequencer/inbox_bucket_selector.d.ts +88 -0
  90. package/dest/sequencer/inbox_bucket_selector.d.ts.map +1 -0
  91. package/dest/sequencer/inbox_bucket_selector.js +80 -0
  92. package/dest/sequencer/index.d.ts +6 -0
  93. package/dest/sequencer/index.d.ts.map +1 -0
  94. package/dest/sequencer/index.js +5 -0
  95. package/dest/sequencer/metrics.d.ts +75 -0
  96. package/dest/sequencer/metrics.d.ts.map +1 -0
  97. package/dest/sequencer/metrics.js +343 -0
  98. package/dest/sequencer/missing_committee.d.ts +72 -0
  99. package/dest/sequencer/missing_committee.d.ts.map +1 -0
  100. package/dest/sequencer/missing_committee.js +139 -0
  101. package/dest/sequencer/requests_tracker.d.ts +22 -0
  102. package/dest/sequencer/requests_tracker.d.ts.map +1 -0
  103. package/dest/sequencer/requests_tracker.js +33 -0
  104. package/dest/sequencer/sequencer.d.ts +326 -0
  105. package/dest/sequencer/sequencer.d.ts.map +1 -0
  106. package/dest/sequencer/sequencer.js +1495 -0
  107. package/dest/sequencer/types.d.ts +3 -0
  108. package/dest/sequencer/types.d.ts.map +1 -0
  109. package/dest/sequencer/types.js +1 -0
  110. package/dest/sequencer/utils.d.ts +30 -0
  111. package/dest/sequencer/utils.d.ts.map +1 -0
  112. package/dest/sequencer/utils.js +18 -0
  113. package/dest/test/index.d.ts +23 -0
  114. package/dest/test/index.d.ts.map +1 -0
  115. package/dest/test/index.js +6 -0
  116. package/dest/test/mock_checkpoint_builder.d.ts +95 -0
  117. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  118. package/dest/test/mock_checkpoint_builder.js +230 -0
  119. package/dest/test/utils.d.ts +67 -0
  120. package/dest/test/utils.d.ts.map +1 -0
  121. package/dest/test/utils.js +121 -0
  122. package/package.json +118 -0
  123. package/src/client/index.ts +1 -0
  124. package/src/client/sequencer-client.ts +281 -0
  125. package/src/config.ts +309 -0
  126. package/src/global_variable_builder/README.md +44 -0
  127. package/src/global_variable_builder/fee_predictor.ts +176 -0
  128. package/src/global_variable_builder/fee_provider.ts +104 -0
  129. package/src/global_variable_builder/global_builder.ts +68 -0
  130. package/src/global_variable_builder/index.ts +3 -0
  131. package/src/index.ts +15 -0
  132. package/src/publisher/config.ts +220 -0
  133. package/src/publisher/index.ts +8 -0
  134. package/src/publisher/l1_to_l2_messaging.ts +85 -0
  135. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  136. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +166 -0
  137. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +47 -0
  138. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  139. package/src/publisher/sequencer-bundle-simulator.ts +253 -0
  140. package/src/publisher/sequencer-publisher-factory.ts +121 -0
  141. package/src/publisher/sequencer-publisher-metrics.ts +145 -0
  142. package/src/publisher/sequencer-publisher.ts +1719 -0
  143. package/src/publisher/write_json.ts +77 -0
  144. package/src/sequencer/README.md +243 -0
  145. package/src/sequencer/automine/README.md +60 -0
  146. package/src/sequencer/automine/automine_factory.ts +156 -0
  147. package/src/sequencer/automine/automine_sequencer.ts +841 -0
  148. package/src/sequencer/automine/index.ts +6 -0
  149. package/src/sequencer/checkpoint_proposal_job.ts +1889 -0
  150. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  151. package/src/sequencer/checkpoint_voter.ts +118 -0
  152. package/src/sequencer/config.ts +9 -0
  153. package/src/sequencer/errors.ts +21 -0
  154. package/src/sequencer/events.ts +93 -0
  155. package/src/sequencer/inbox_bucket_selector.ts +160 -0
  156. package/src/sequencer/index.ts +5 -0
  157. package/src/sequencer/metrics.ts +463 -0
  158. package/src/sequencer/missing_committee.ts +192 -0
  159. package/src/sequencer/requests_tracker.ts +43 -0
  160. package/src/sequencer/sequencer.ts +1401 -0
  161. package/src/sequencer/types.ts +6 -0
  162. package/src/sequencer/utils.ts +42 -0
  163. package/src/test/index.ts +26 -0
  164. package/src/test/mock_checkpoint_builder.ts +324 -0
  165. package/src/test/utils.ts +215 -0
@@ -0,0 +1,15 @@
1
+ import { type Logger } from '@aztec-labs/foundation/log';
2
+ import type { FileStore } from '@aztec-labs/stdlib/file-store';
3
+ import { type FailedL1Tx, type FailedL1TxUri, type L1TxFailedStore } from './failed_tx_store.js';
4
+ /**
5
+ * L1TxFailedStore implementation using the FileStore abstraction.
6
+ * Supports any backend that FileStore supports (GCS, S3, R2, local filesystem).
7
+ */
8
+ export declare class FileStoreL1TxFailedStore implements L1TxFailedStore {
9
+ private readonly fileStore;
10
+ private readonly log;
11
+ constructor(fileStore: FileStore, logger?: Logger);
12
+ saveFailedTx(tx: FailedL1Tx): Promise<FailedL1TxUri>;
13
+ getFailedTx(uri: FailedL1TxUri): Promise<FailedL1Tx>;
14
+ }
15
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmlsZV9zdG9yZV9mYWlsZWRfdHhfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9wdWJsaXNoZXIvbDFfdHhfZmFpbGVkX3N0b3JlL2ZpbGVfc3RvcmVfZmFpbGVkX3R4X3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxLQUFLLE1BQU0sRUFBZ0IsTUFBTSw0QkFBNEIsQ0FBQztBQUN2RSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUUvRCxPQUFPLEVBQUUsS0FBSyxVQUFVLEVBQW9CLEtBQUssYUFBYSxFQUFFLEtBQUssZUFBZSxFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFFbkg7OztHQUdHO0FBQ0gscUJBQWEsd0JBQXlCLFlBQVcsZUFBZTtJQUk1RCxPQUFPLENBQUMsUUFBUSxDQUFDLFNBQVM7SUFINUIsT0FBTyxDQUFDLFFBQVEsQ0FBQyxHQUFHLENBQVM7SUFFN0IsWUFDbUIsU0FBUyxFQUFFLFNBQVMsRUFDckMsTUFBTSxDQUFDLEVBQUUsTUFBTSxFQUdoQjtJQUVZLFlBQVksQ0FBQyxFQUFFLEVBQUUsVUFBVSxHQUFHLE9BQU8sQ0FBQyxhQUFhLENBQUMsQ0FvQmhFO0lBRVksV0FBVyxDQUFDLEdBQUcsRUFBRSxhQUFhLEdBQUcsT0FBTyxDQUFDLFVBQVUsQ0FBQyxDQUdoRTtDQUNGIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file_store_failed_tx_store.d.ts","sourceRoot":"","sources":["../../../src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,4BAA4B,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE/D,OAAO,EAAE,KAAK,UAAU,EAAoB,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEnH;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,eAAe;IAI5D,OAAO,CAAC,QAAQ,CAAC,SAAS;IAH5B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAE7B,YACmB,SAAS,EAAE,SAAS,EACrC,MAAM,CAAC,EAAE,MAAM,EAGhB;IAEY,YAAY,CAAC,EAAE,EAAE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,CAoBhE;IAEY,WAAW,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,CAGhE;CACF"}
@@ -0,0 +1,36 @@
1
+ import { jsonParseWithSchema, jsonStringify } from '@aztec-labs/foundation/json-rpc';
2
+ import { createLogger } from '@aztec-labs/foundation/log';
3
+ import { FailedL1TxSchema } from './failed_tx_store.js';
4
+ /**
5
+ * L1TxFailedStore implementation using the FileStore abstraction.
6
+ * Supports any backend that FileStore supports (GCS, S3, R2, local filesystem).
7
+ */ export class FileStoreL1TxFailedStore {
8
+ fileStore;
9
+ log;
10
+ constructor(fileStore, logger){
11
+ this.fileStore = fileStore;
12
+ this.log = logger ?? createLogger('sequencer:l1-tx-failed-store');
13
+ }
14
+ async saveFailedTx(tx) {
15
+ const prefix = tx.receipt ? 'tx' : 'data';
16
+ const path = `${tx.failureType}/${prefix}-${tx.id}.json`;
17
+ const json = jsonStringify(tx, true);
18
+ const uri = await this.fileStore.save(path, Buffer.from(json), {
19
+ metadata: {
20
+ 'content-type': 'application/json',
21
+ actions: tx.context.actions.join(','),
22
+ 'failure-type': tx.failureType
23
+ }
24
+ });
25
+ this.log.info(`Saved failed L1 tx to ${uri}`, {
26
+ id: tx.id,
27
+ failureType: tx.failureType,
28
+ actions: tx.context.actions.join(',')
29
+ });
30
+ return uri;
31
+ }
32
+ async getFailedTx(uri) {
33
+ const data = await this.fileStore.read(uri);
34
+ return jsonParseWithSchema(data.toString(), FailedL1TxSchema);
35
+ }
36
+ }
@@ -0,0 +1,4 @@
1
+ export { type FailedL1Tx, FailedL1TxSchema, type FailedL1TxUri, type L1TxFailedStore } from './failed_tx_store.js';
2
+ export { createL1TxFailedStore } from './factory.js';
3
+ export { FileStoreL1TxFailedStore } from './file_store_failed_tx_store.js';
4
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9wdWJsaXNoZXIvbDFfdHhfZmFpbGVkX3N0b3JlL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxLQUFLLFVBQVUsRUFBRSxnQkFBZ0IsRUFBRSxLQUFLLGFBQWEsRUFBRSxLQUFLLGVBQWUsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQ25ILE9BQU8sRUFBRSxxQkFBcUIsRUFBRSxNQUFNLGNBQWMsQ0FBQztBQUNyRCxPQUFPLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQyJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/publisher/l1_tx_failed_store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,gBAAgB,EAAE,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACnH,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { FailedL1TxSchema } from './failed_tx_store.js';
2
+ export { createL1TxFailedStore } from './factory.js';
3
+ export { FileStoreL1TxFailedStore } from './file_store_failed_tx_store.js';
@@ -0,0 +1,96 @@
1
+ import type { EpochCache } from '@aztec-labs/epoch-cache';
2
+ import { type RollupContract } from '@aztec-labs/ethereum/contracts';
3
+ import { type L1TxUtils } from '@aztec-labs/ethereum/l1-tx-utils';
4
+ import type { SlotNumber } from '@aztec-labs/foundation/branded-types';
5
+ import { type Logger } from '@aztec-labs/foundation/log';
6
+ import type { Hex } from 'viem';
7
+ import type { RequestWithExpiry } from './sequencer-publisher.js';
8
+ /** A request that was dropped by bundle simulation, with the decoded revert reason. */
9
+ export type DroppedRequest = {
10
+ request: RequestWithExpiry;
11
+ revertReason: string | undefined;
12
+ returnData: Hex | undefined;
13
+ };
14
+ /**
15
+ * Result of {@link SequencerBundleSimulator.simulate}.
16
+ *
17
+ * - `success`: simulation succeeded. `requests` is the filtered survivor list, `gasLimit` is
18
+ * the bumped gas limit derived from `gasUsed` (plus blob evaluation gas). `droppedRequests`
19
+ * lists the entries that were observed to revert in simulation.
20
+ * - `fallback`: the node does not support eth_simulateV1 (or the simulate call threw). The
21
+ * caller should send `requests` as-is with a safe gas limit (e.g. {@link MAX_L1_TX_LIMIT}).
22
+ * `droppedRequests` carries any entries that the first pass already proved reverted, so the
23
+ * caller does not re-include them when the second pass falls back.
24
+ * - `aborted`: the bundle cannot be sent. `droppedRequests` contains only entries that were
25
+ * actually observed to revert (so they can be reported as simulation failures); it is empty
26
+ * when the abort was caused by an empty input bundle.
27
+ */
28
+ export type BundleSimulateResult = {
29
+ kind: 'success';
30
+ requests: RequestWithExpiry[];
31
+ gasLimit: bigint;
32
+ droppedRequests: DroppedRequest[];
33
+ } | {
34
+ kind: 'fallback';
35
+ requests: RequestWithExpiry[];
36
+ droppedRequests: DroppedRequest[];
37
+ } | {
38
+ kind: 'aborted';
39
+ reason: AbortReason;
40
+ droppedRequests: DroppedRequest[];
41
+ };
42
+ export type AbortReason = 'empty-bundle' | 'all-reverted' | 'second-pass-reverts';
43
+ /**
44
+ * Bundle-level simulator for the aggregate3 payload that `SequencerPublisher` is about to send.
45
+ *
46
+ * Runs `eth_simulateV1` against `Multicall3.aggregate3`, drops entries that revert, and returns
47
+ * a gasLimit for the survivors. When `eth_simulateV1` is unavailable, signals fallback to the
48
+ * caller so it can send the bundle as-is with a conservative gas limit.
49
+ */
50
+ export declare class SequencerBundleSimulator {
51
+ private readonly deps;
52
+ private readonly log;
53
+ constructor(deps: {
54
+ getL1TxUtils: () => L1TxUtils;
55
+ rollupContract: RollupContract;
56
+ epochCache: EpochCache;
57
+ log?: Logger;
58
+ });
59
+ /**
60
+ * Simulates the given bundle near the end of the target slot and filters out entries
61
+ * that revert.
62
+ *
63
+ * - If all entries pass on the first pass, returns `success` with the gasLimit.
64
+ * - If some entries revert, re-simulates the survivors. If the second pass is clean, returns
65
+ * `success` with the survivors and dropped entries. If the second pass surfaces any revert,
66
+ * returns `aborted` — we refuse to send a bundle whose composition still has internal
67
+ * reverts after one round of filtering.
68
+ * - If eth_simulateV1 is unavailable, returns `fallback`. The caller is expected to send the
69
+ * bundle as-is with a safe gas limit.
70
+ *
71
+ * The simulation `block.timestamp` is the last L1 slot timestamp inside the target L2 slot.
72
+ * This still maps to the target L2 slot for propose's `validateHeader` and EIP-712 signature
73
+ * checks, while avoiding eth_simulateV1 rejecting a child block whose timestamp is not strictly
74
+ * greater than the current L1 head.
75
+ *
76
+ * Known limitation: on networks where L1 is mining behind cadence (missed L1 slots, anvil with
77
+ * overridden timestamps), the actual `block.timestamp` at send time can land in the prior L2
78
+ * slot. In that case `propose` would revert silently inside the multicall. The simulator does
79
+ * not detect this case because it simulates inside the target slot — the prior implementation
80
+ * used `min(predictedNextL1Ts, targetTimestamp)` to surface this failure mode at simulate time.
81
+ */
82
+ simulate(validRequests: RequestWithExpiry[], targetSlot: SlotNumber): Promise<BundleSimulateResult>;
83
+ private buildSuccessResult;
84
+ /**
85
+ * `gasLimit = bumpGasLimit(ceil(gasUsed * 64 / 63))`, plus blob evaluation gas if a propose
86
+ * survived, capped at the L1 block gas limit.
87
+ */
88
+ private computeGasLimit;
89
+ /**
90
+ * eth_simulateV1 cannot carry blob sidecar data, so disable the rollup's on-chain blob check
91
+ * when a propose is in the bundle.
92
+ */
93
+ private buildStateOverrides;
94
+ private simulateAndDecode;
95
+ }
96
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VxdWVuY2VyLWJ1bmRsZS1zaW11bGF0b3IuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wdWJsaXNoZXIvc2VxdWVuY2VyLWJ1bmRsZS1zaW11bGF0b3IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFDMUQsT0FBTyxFQUFjLEtBQUssY0FBYyxFQUF5QyxNQUFNLGdDQUFnQyxDQUFDO0FBQ3hILE9BQU8sRUFBRSxLQUFLLFNBQVMsRUFBbUIsTUFBTSxrQ0FBa0MsQ0FBQztBQUVuRixPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSxzQ0FBc0MsQ0FBQztBQUN2RSxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQWdCLE1BQU0sNEJBQTRCLENBQUM7QUFFdkUsT0FBTyxLQUFLLEVBQUUsR0FBRyxFQUFpQixNQUFNLE1BQU0sQ0FBQztBQUUvQyxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBRWxFLHVGQUF1RjtBQUN2RixNQUFNLE1BQU0sY0FBYyxHQUFHO0lBQzNCLE9BQU8sRUFBRSxpQkFBaUIsQ0FBQztJQUMzQixZQUFZLEVBQUUsTUFBTSxHQUF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,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAAC,eAAe,EAAE,cAAc,EAAE,CAAA;CAAE,GACtF;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,WAAW,CAAC;IAAC,eAAe,EAAE,cAAc,EAAE,CAAA;CAAE,CAAC;AAEhF,MAAM,MAAM,WAAW,GAAG,cAAc,GAAG,cAAc,GAAG,qBAAqB,CAAC;AAMlF;;;;;;GAMG;AACH,qBAAa,wBAAwB;IAIjC,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHvB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAE7B,YACmB,IAAI,EAAE;QACrB,YAAY,EAAE,MAAM,SAAS,CAAC;QAC9B,cAAc,EAAE,cAAc,CAAC;QAC/B,UAAU,EAAE,UAAU,CAAC;QACvB,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,EAGF;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACU,QAAQ,CAAC,aAAa,EAAE,iBAAiB,EAAE,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA6E/G;IAED,OAAO,CAAC,kBAAkB;IAmB1B;;;OAGG;IACH,OAAO,CAAC,eAAe;IAMvB;;;OAGG;IACH,OAAO,CAAC,mBAAmB;YAOb,iBAAiB;CA8ChC"}
@@ -0,0 +1,198 @@
1
+ import { Multicall3, buildSimulationOverridesStateOverride } from '@aztec-labs/ethereum/contracts';
2
+ import { MAX_L1_TX_LIMIT } from '@aztec-labs/ethereum/l1-tx-utils';
3
+ import { formatViemError } from '@aztec-labs/ethereum/utils';
4
+ import { createLogger } from '@aztec-labs/foundation/log';
5
+ import { getLastL1SlotTimestampForL2Slot } from '@aztec-labs/stdlib/epoch-helpers';
6
+ /**
7
+ * Bundle-level simulator for the aggregate3 payload that `SequencerPublisher` is about to send.
8
+ *
9
+ * Runs `eth_simulateV1` against `Multicall3.aggregate3`, drops entries that revert, and returns
10
+ * a gasLimit for the survivors. When `eth_simulateV1` is unavailable, signals fallback to the
11
+ * caller so it can send the bundle as-is with a conservative gas limit.
12
+ */ export class SequencerBundleSimulator {
13
+ deps;
14
+ log;
15
+ constructor(deps){
16
+ this.deps = deps;
17
+ this.log = deps.log ?? createLogger('sequencer:publisher:bundle-simulator');
18
+ }
19
+ /**
20
+ * Simulates the given bundle near the end of the target slot and filters out entries
21
+ * that revert.
22
+ *
23
+ * - If all entries pass on the first pass, returns `success` with the gasLimit.
24
+ * - If some entries revert, re-simulates the survivors. If the second pass is clean, returns
25
+ * `success` with the survivors and dropped entries. If the second pass surfaces any revert,
26
+ * returns `aborted` — we refuse to send a bundle whose composition still has internal
27
+ * reverts after one round of filtering.
28
+ * - If eth_simulateV1 is unavailable, returns `fallback`. The caller is expected to send the
29
+ * bundle as-is with a safe gas limit.
30
+ *
31
+ * The simulation `block.timestamp` is the last L1 slot timestamp inside the target L2 slot.
32
+ * This still maps to the target L2 slot for propose's `validateHeader` and EIP-712 signature
33
+ * checks, while avoiding eth_simulateV1 rejecting a child block whose timestamp is not strictly
34
+ * greater than the current L1 head.
35
+ *
36
+ * Known limitation: on networks where L1 is mining behind cadence (missed L1 slots, anvil with
37
+ * overridden timestamps), the actual `block.timestamp` at send time can land in the prior L2
38
+ * slot. In that case `propose` would revert silently inside the multicall. The simulator does
39
+ * not detect this case because it simulates inside the target slot — the prior implementation
40
+ * used `min(predictedNextL1Ts, targetTimestamp)` to surface this failure mode at simulate time.
41
+ */ async simulate(validRequests, targetSlot) {
42
+ if (validRequests.length === 0) {
43
+ return {
44
+ kind: 'aborted',
45
+ reason: 'empty-bundle',
46
+ droppedRequests: []
47
+ };
48
+ }
49
+ // Pin the publisher we'll use across the whole simulate call so that the publisher's rotation
50
+ // can't change l1TxUtils mid-flight.
51
+ const l1TxUtils = this.deps.getL1TxUtils();
52
+ const proposeRequest = validRequests.find((r)=>r.action === 'propose');
53
+ const simulateTimestamp = getLastL1SlotTimestampForL2Slot(targetSlot, this.deps.epochCache.getL1Constants());
54
+ const firstPassOverrides = await this.buildStateOverrides(!!proposeRequest);
55
+ const firstPass = await this.simulateAndDecode(l1TxUtils, validRequests, simulateTimestamp, firstPassOverrides);
56
+ if (firstPass.kind === 'fallback') {
57
+ this.log.warn('Bundle simulate fallback (eth_simulateV1 unavailable); caller will send bundle as-is', {
58
+ actions: validRequests.map((r)=>r.action)
59
+ });
60
+ return {
61
+ kind: 'fallback',
62
+ requests: validRequests,
63
+ droppedRequests: []
64
+ };
65
+ }
66
+ if (firstPass.survivors.length === 0) {
67
+ this.log.warn('All bundle entries dropped in simulation; aborting send', {
68
+ actions: validRequests.map((r)=>r.action)
69
+ });
70
+ return {
71
+ kind: 'aborted',
72
+ reason: 'all-reverted',
73
+ droppedRequests: firstPass.droppedRequests
74
+ };
75
+ }
76
+ if (firstPass.droppedRequests.length === 0) {
77
+ return this.buildSuccessResult(l1TxUtils, firstPass.survivors, [], firstPass.gasUsed, proposeRequest);
78
+ }
79
+ this.log.warn('Some bundle entries reverted; re-simulating reduced bundle', {
80
+ droppedActions: firstPass.droppedRequests.map((d)=>d.request.action),
81
+ remainingActions: firstPass.survivors.map((r)=>r.action)
82
+ });
83
+ // Rebuild overrides for the reduced bundle: if propose was dropped, we no longer need the blob-check override
84
+ const proposeSurvived = proposeRequest !== undefined && firstPass.survivors.includes(proposeRequest);
85
+ const secondPassOverrides = proposeSurvived ? firstPassOverrides : await this.buildStateOverrides(false);
86
+ const secondPass = await this.simulateAndDecode(l1TxUtils, firstPass.survivors, simulateTimestamp, secondPassOverrides);
87
+ if (secondPass.kind === 'fallback') {
88
+ this.log.warn('Bundle simulate errored on second pass (eth_simulateV1 unavailable); sending first-pass survivors as-is', {
89
+ actions: firstPass.survivors.map((r)=>r.action),
90
+ droppedActions: firstPass.droppedRequests.map((d)=>d.request.action)
91
+ });
92
+ return {
93
+ kind: 'fallback',
94
+ requests: firstPass.survivors,
95
+ droppedRequests: firstPass.droppedRequests
96
+ };
97
+ }
98
+ // We refuse to chase reverts through repeated trimming: anything other than a clean second pass aborts the whole send
99
+ if (secondPass.droppedRequests.length > 0) {
100
+ this.log.error('Re-simulate surfaced reverts; aborting send', {
101
+ secondPassDroppedActions: secondPass.droppedRequests.map((d)=>d.request.action)
102
+ });
103
+ return {
104
+ kind: 'aborted',
105
+ reason: 'second-pass-reverts',
106
+ droppedRequests: [
107
+ ...firstPass.droppedRequests,
108
+ ...secondPass.droppedRequests
109
+ ]
110
+ };
111
+ }
112
+ return this.buildSuccessResult(l1TxUtils, secondPass.survivors, firstPass.droppedRequests, secondPass.gasUsed, proposeRequest);
113
+ }
114
+ buildSuccessResult(l1TxUtils, survivors, droppedRequests, bundleGasUsed, proposeRequest) {
115
+ const proposeSurvived = proposeRequest !== undefined && survivors.includes(proposeRequest);
116
+ const blobEvaluationGas = proposeSurvived ? proposeRequest?.blobEvaluationGas ?? 0n : 0n;
117
+ const gasLimit = this.computeGasLimit(l1TxUtils, bundleGasUsed, blobEvaluationGas);
118
+ this.log.debug('Bundle simulate complete', {
119
+ survivingRequests: survivors.length,
120
+ bundleGasUsed,
121
+ gasLimit,
122
+ actions: survivors.map((r)=>r.action)
123
+ });
124
+ return {
125
+ kind: 'success',
126
+ requests: survivors,
127
+ gasLimit,
128
+ droppedRequests
129
+ };
130
+ }
131
+ /**
132
+ * `gasLimit = bumpGasLimit(ceil(gasUsed * 64 / 63))`, plus blob evaluation gas if a propose
133
+ * survived, capped at the L1 block gas limit.
134
+ */ computeGasLimit(l1TxUtils, bundleGasUsed, blobEvaluationGas) {
135
+ const gasUsedWithEip150 = (bundleGasUsed * 64n + 62n) / 63n;
136
+ const gasLimit = l1TxUtils.bumpGasLimit(gasUsedWithEip150) + blobEvaluationGas;
137
+ return gasLimit > MAX_L1_TX_LIMIT ? MAX_L1_TX_LIMIT : gasLimit;
138
+ }
139
+ /**
140
+ * eth_simulateV1 cannot carry blob sidecar data, so disable the rollup's on-chain blob check
141
+ * when a propose is in the bundle.
142
+ */ buildStateOverrides(hasProposeAction) {
143
+ return buildSimulationOverridesStateOverride(this.deps.rollupContract, hasProposeAction ? {
144
+ disableBlobCheck: true
145
+ } : undefined);
146
+ }
147
+ async simulateAndDecode(l1TxUtils, requests, simulateTimestamp, stateOverrides) {
148
+ let simResult;
149
+ try {
150
+ simResult = await Multicall3.simulateAggregate3(requests.map((r)=>({
151
+ to: r.request.to,
152
+ data: r.request.data,
153
+ abi: r.request.abi
154
+ })), l1TxUtils, {
155
+ blockOverrides: {
156
+ time: simulateTimestamp,
157
+ gasLimit: MAX_L1_TX_LIMIT * 2n
158
+ },
159
+ stateOverrides,
160
+ gas: MAX_L1_TX_LIMIT,
161
+ fallbackGasEstimate: MAX_L1_TX_LIMIT
162
+ });
163
+ } catch (err) {
164
+ this.log.warn('Bundle simulate threw; treating as fallback', {
165
+ err: formatViemError(err),
166
+ actions: requests.map((r)=>r.action)
167
+ });
168
+ return {
169
+ kind: 'fallback'
170
+ };
171
+ }
172
+ if (simResult.kind === 'fallback') {
173
+ return {
174
+ kind: 'fallback'
175
+ };
176
+ }
177
+ const survivors = [];
178
+ const droppedRequests = [];
179
+ for(let i = 0; i < requests.length; i++){
180
+ const entry = simResult.entries[i];
181
+ if (entry.success) {
182
+ survivors.push(requests[i]);
183
+ continue;
184
+ }
185
+ droppedRequests.push({
186
+ request: requests[i],
187
+ revertReason: entry.revertReason,
188
+ returnData: entry.returnData
189
+ });
190
+ }
191
+ return {
192
+ kind: 'decoded',
193
+ survivors,
194
+ droppedRequests,
195
+ gasUsed: simResult.gasUsed
196
+ };
197
+ }
198
+ }
@@ -0,0 +1,50 @@
1
+ import type { BlobClientInterface } from '@aztec-labs/blob-client/client';
2
+ import type { EpochCache } from '@aztec-labs/epoch-cache';
3
+ import type { GovernanceProposerContract, RollupContract } from '@aztec-labs/ethereum/contracts';
4
+ import type { L1TxUtils } from '@aztec-labs/ethereum/l1-tx-utils';
5
+ import type { PublisherManager } from '@aztec-labs/ethereum/publisher-manager';
6
+ import { EthAddress } from '@aztec-labs/foundation/eth-address';
7
+ import { type Logger } from '@aztec-labs/foundation/log';
8
+ import type { DateProvider } from '@aztec-labs/foundation/timer';
9
+ import type { TelemetryClient } from '@aztec-labs/telemetry-client';
10
+ import { NodeKeystoreAdapter } from '@aztec-labs/validator-client';
11
+ import type { SequencerClientConfig } from '../config.js';
12
+ import { SequencerPublisher } from './sequencer-publisher.js';
13
+ export type AttestorPublisherPair = {
14
+ attestorAddress: EthAddress;
15
+ publisher: SequencerPublisher;
16
+ };
17
+ export declare class SequencerPublisherFactory {
18
+ private sequencerConfig;
19
+ private deps;
20
+ private publisherMetrics;
21
+ /** Stores the last slot in which every action was carried out by a publisher */
22
+ private lastActions;
23
+ private nodeKeyStore;
24
+ private logger;
25
+ constructor(sequencerConfig: SequencerClientConfig, deps: {
26
+ telemetry: TelemetryClient;
27
+ publisherManager: PublisherManager<L1TxUtils>;
28
+ blobClient: BlobClientInterface;
29
+ dateProvider: DateProvider;
30
+ epochCache: EpochCache;
31
+ rollupContract: RollupContract;
32
+ governanceProposerContract: GovernanceProposerContract;
33
+ nodeKeyStore: NodeKeystoreAdapter;
34
+ logger?: Logger;
35
+ });
36
+ /**
37
+ * Updates the node keystore adapter used for publisher lookups.
38
+ * Called when the keystore is reloaded at runtime to reflect new validator-publisher mappings.
39
+ */
40
+ updateNodeKeyStore(adapter: NodeKeystoreAdapter): void;
41
+ /**
42
+ * Creates a new SequencerPublisher instance.
43
+ * @param _validatorAddress - The address of the validator that will be using the publisher.
44
+ * @returns A new SequencerPublisher instance.
45
+ */
46
+ create(validatorAddress?: EthAddress): Promise<AttestorPublisherPair>;
47
+ /** Stops all publishers managed by this factory. Used during sequencer shutdown. */
48
+ stopAll(): Promise<void>;
49
+ }
50
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VxdWVuY2VyLXB1Ymxpc2hlci1mYWN0b3J5LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uL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SUFDdkIsT0FBTyxDQUFDLElBQUk7SUFYZCxPQUFPLENBQUMsZ0JBQWdCLENBQTRCO0lBRXBELGdGQUFnRjtJQUNoRixPQUFPLENBQUMsV0FBVyxDQUEyQztJQUU5RCxPQUFPLENBQUMsWUFBWSxDQUFzQjtJQUUxQyxPQUFPLENBQUMsTUFBTSxDQUFTO0lBRXZCLFlBQ1UsZUFBZSxFQUFFLHFCQUFxQixFQUN0QyxJQUFJLEVBQUU7UUFDWixTQUFTLEVBQUUsZUFBZSxDQUFDO1FBQzNCLGdCQUFnQixFQUFFLGdCQUFnQixDQUFDLFNBQVMsQ0FBQyxDQUFDO1FBQzlDLFVBQVUsRUFBRSxtQkFBbUIsQ0FBQztRQUNoQyxZQUFZLEVBQUUsWUFBWSxDQUFDO1FBQzNCLFVBQVUsRUFBRSxVQUFVLENBQUM7UUFDdkIsY0FBYyxFQUFFLGNBQWMsQ0FBQztRQUMvQiwwQkFBMEIsRUFBRSwwQkFBMEIsQ0FBQztRQUN2RCxZQUFZLEVBQUUsbUJBQW1CLENBQUM7UUFDbEMsTUFBTSxDQUFDLEVBQUUsTUFBTSxDQUFDO0tBQ2pCLEVBS0Y7SUFFRDs7O09BR0c7SUFDSSxrQkFBa0IsQ0FBQyxPQUFPLEVBQUUsbUJBQW1CLEdBQUcsSUFBSSxDQUU1RDtJQUVEOzs7O09BSUc7SUFDVSxNQUFNLENBQUMsZ0JBQWdCLENBQUMsRUFBRSxVQUFVLEdBQUcsT0FBTyxDQUFDLHFCQUFxQixDQUFDLENBbURqRjtJQUVELG9GQUFvRjtJQUN2RSxPQUFPLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQUVwQztDQUNGIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sequencer-publisher-factory.d.ts","sourceRoot":"","sources":["../../src/publisher/sequencer-publisher-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAA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BAA0B,CAAC;QACvD,YAAY,EAAE,mBAAmB,CAAC;QAClC,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,EAKF;IAED;;;OAGG;IACI,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI,CAE5D;IAED;;;;OAIG;IACU,MAAM,CAAC,gBAAgB,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAmDjF;IAED,oFAAoF;IACvE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAEpC;CACF"}
@@ -0,0 +1,75 @@
1
+ import { createLogger } from '@aztec-labs/foundation/log';
2
+ import { SequencerPublisherMetrics } from './sequencer-publisher-metrics.js';
3
+ import { SequencerPublisher } from './sequencer-publisher.js';
4
+ export class SequencerPublisherFactory {
5
+ sequencerConfig;
6
+ deps;
7
+ publisherMetrics;
8
+ /** Stores the last slot in which every action was carried out by a publisher */ lastActions;
9
+ nodeKeyStore;
10
+ logger;
11
+ constructor(sequencerConfig, deps){
12
+ this.sequencerConfig = sequencerConfig;
13
+ this.deps = deps;
14
+ this.lastActions = {};
15
+ this.publisherMetrics = new SequencerPublisherMetrics(deps.telemetry, 'SequencerPublisher');
16
+ this.logger = deps.logger ?? createLogger('sequencer');
17
+ this.nodeKeyStore = this.deps.nodeKeyStore;
18
+ }
19
+ /**
20
+ * Updates the node keystore adapter used for publisher lookups.
21
+ * Called when the keystore is reloaded at runtime to reflect new validator-publisher mappings.
22
+ */ updateNodeKeyStore(adapter) {
23
+ this.nodeKeyStore = adapter;
24
+ }
25
+ /**
26
+ * Creates a new SequencerPublisher instance.
27
+ * @param _validatorAddress - The address of the validator that will be using the publisher.
28
+ * @returns A new SequencerPublisher instance.
29
+ */ async create(validatorAddress) {
30
+ // If we have been given an attestor address we must only allow publishers permitted for that attestor
31
+ const allowedPublishers = !validatorAddress ? [] : this.nodeKeyStore.getPublisherAddresses(validatorAddress);
32
+ const filter = !validatorAddress ? ()=>true : (utils)=>{
33
+ const publisherAddress = utils.getSenderAddress();
34
+ return allowedPublishers.some((allowedPublisher)=>allowedPublisher.equals(publisherAddress));
35
+ };
36
+ const l1Publisher = await this.deps.publisherManager.getAvailablePublisher(filter);
37
+ const attestorAddress = validatorAddress ?? this.nodeKeyStore.getAttestorForPublisher(l1Publisher.getSenderAddress());
38
+ const rollup = this.deps.rollupContract;
39
+ const slashingProposerContract = await rollup.getSlashingProposer();
40
+ const getNextPublisher = async (excludeAddresses)=>{
41
+ const exclusionFilter = (utils)=>{
42
+ if (excludeAddresses.some((addr)=>addr.equals(utils.getSenderAddress()))) {
43
+ return false;
44
+ }
45
+ return filter(utils);
46
+ };
47
+ try {
48
+ return await this.deps.publisherManager.getAvailablePublisher(exclusionFilter);
49
+ } catch {
50
+ return undefined;
51
+ }
52
+ };
53
+ const publisher = new SequencerPublisher(this.sequencerConfig, {
54
+ l1TxUtils: l1Publisher,
55
+ getNextPublisher,
56
+ telemetry: this.deps.telemetry,
57
+ blobClient: this.deps.blobClient,
58
+ rollupContract: this.deps.rollupContract,
59
+ epochCache: this.deps.epochCache,
60
+ governanceProposerContract: this.deps.governanceProposerContract,
61
+ slashingProposerContract,
62
+ dateProvider: this.deps.dateProvider,
63
+ metrics: this.publisherMetrics,
64
+ lastActions: this.lastActions,
65
+ log: this.logger.createChild('publisher')
66
+ });
67
+ return {
68
+ attestorAddress,
69
+ publisher
70
+ };
71
+ }
72
+ /** Stops all publishers managed by this factory. Used during sequencer shutdown. */ async stopAll() {
73
+ await this.deps.publisherManager.stop();
74
+ }
75
+ }
@@ -0,0 +1,26 @@
1
+ import type { L1PublishCheckpointStats } from '@aztec-labs/stdlib/stats';
2
+ import { type TelemetryClient } from '@aztec-labs/telemetry-client';
3
+ export type L1TxType = 'process';
4
+ export declare class SequencerPublisherMetrics {
5
+ private logger;
6
+ private gasPrice;
7
+ private txCount;
8
+ private txDuration;
9
+ private txGas;
10
+ private txCalldataSize;
11
+ private txCalldataGas;
12
+ private txBlobDataGasUsed;
13
+ private txBlobDataGasCost;
14
+ private txTotalFee;
15
+ private readonly blobCountHistogram;
16
+ private readonly blobInclusionBlocksHistogram;
17
+ private readonly blobTxSuccessCounter;
18
+ private readonly blobTxFailureCounter;
19
+ private senderBalance;
20
+ constructor(client: TelemetryClient, name?: string, logger?: import("@aztec-labs/foundation/log").Logger);
21
+ recordFailedTx(txType: L1TxType): void;
22
+ recordProcessBlockTx(durationMs: number, stats: L1PublishCheckpointStats): void;
23
+ recordSenderBalance(wei: bigint, senderAddress: string): void;
24
+ private recordTx;
25
+ }
26
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VxdWVuY2VyLXB1Ymxpc2hlci1tZXRyaWNzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcHVibGlzaGVyL3NlcXVlbmNlci1wdWJsaXNoZXItbWV0cmljcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEtBQUssRUFBRSx3QkFBd0IsRUFBa0IsTUFBTSwwQkFBMEIsQ0FBQztBQUN6RixPQUFPLEVBS0wsS0FBSyxlQUFlLEVBR3JCLE1BQU0sOEJBQThCLENBQUM7QUFHdEMsTUFBTSxNQUFNLFFBQVEsR0FBRyxTQUFTLENBQUM7QUFFakMscUJBQWEseUJBQXlCO0lBc0JsQyxPQUFPLENBQUMsTUFBTTtJQXJCaEIsT0FBTyxDQUFDLFFBQVEsQ0FBWTtJQUU1QixPQUFPLENBQUMsT0FBTyxDQUFnQjtJQUMvQixPQUFPLENBQUMsVUFBVSxDQUFZO0lBQzlCLE9BQU8sQ0FBQyxLQUFLLENBQVk7SUFDekIsT0FBTyxDQUFDLGNBQWMsQ0FBWTtJQUNsQyxPQUFPLENBQUMsYUFBYSxDQUFZO0lBQ2pDLE9BQU8sQ0FBQyxpQkFBaUIsQ0FBWTtJQUNyQyxPQUFPLENBQUMsaUJBQWlCLENBQVk7SUFDckMsT0FBT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jC,OAAO,CAAC,iBAAiB,CAAY;IACrC,OAAO,CAAC,iBAAiB,CAAY;IACrC,OAAO,CAAC,UAAU,CAAY;IAE9B,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAY;IAC/C,OAAO,CAAC,QAAQ,CAAC,4BAA4B,CAAY;IACzD,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAgB;IACrD,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAgB;IAErD,OAAO,CAAC,aAAa,CAAQ;IAE7B,YACE,MAAM,EAAE,eAAe,EACvB,IAAI,SAAuB,EACnB,MAAM,8CAA8C,EAkC7D;IAED,cAAc,CAAC,MAAM,EAAE,QAAQ,QAS9B;IAED,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,wBAAwB,QAYvE;IAED,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,QAKrD;IAED,OAAO,CAAC,QAAQ;CAuCjB"}
@@ -0,0 +1,101 @@
1
+ import { createLogger } from '@aztec-labs/foundation/log';
2
+ import { Attributes, Metrics, createUpDownCounterWithDefault } from '@aztec-labs/telemetry-client';
3
+ import { formatEther } from 'viem/utils';
4
+ export class SequencerPublisherMetrics {
5
+ logger;
6
+ gasPrice;
7
+ txCount;
8
+ txDuration;
9
+ txGas;
10
+ txCalldataSize;
11
+ txCalldataGas;
12
+ txBlobDataGasUsed;
13
+ txBlobDataGasCost;
14
+ txTotalFee;
15
+ blobCountHistogram;
16
+ blobInclusionBlocksHistogram;
17
+ blobTxSuccessCounter;
18
+ blobTxFailureCounter;
19
+ senderBalance;
20
+ constructor(client, name = 'SequencerPublisher', logger = createLogger('sequencer:publisher:metrics')){
21
+ this.logger = logger;
22
+ const meter = client.getMeter(name);
23
+ this.gasPrice = meter.createHistogram(Metrics.L1_PUBLISHER_GAS_PRICE);
24
+ this.txCount = createUpDownCounterWithDefault(meter, Metrics.L1_PUBLISHER_TX_COUNT, {
25
+ [Attributes.L1_TX_TYPE]: [
26
+ 'process'
27
+ ],
28
+ [Attributes.OK]: [
29
+ true,
30
+ false
31
+ ]
32
+ });
33
+ this.txDuration = meter.createHistogram(Metrics.L1_PUBLISHER_TX_DURATION);
34
+ this.txGas = meter.createHistogram(Metrics.L1_PUBLISHER_TX_GAS);
35
+ this.txCalldataSize = meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_SIZE);
36
+ this.txCalldataGas = meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_GAS);
37
+ this.txBlobDataGasUsed = meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_USED);
38
+ this.txBlobDataGasCost = meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_COST);
39
+ this.blobCountHistogram = meter.createHistogram(Metrics.L1_PUBLISHER_BLOB_COUNT);
40
+ this.blobInclusionBlocksHistogram = meter.createHistogram(Metrics.L1_PUBLISHER_BLOB_INCLUSION_BLOCKS);
41
+ this.blobTxSuccessCounter = createUpDownCounterWithDefault(meter, Metrics.L1_PUBLISHER_BLOB_TX_SUCCESS);
42
+ this.blobTxFailureCounter = createUpDownCounterWithDefault(meter, Metrics.L1_PUBLISHER_BLOB_TX_FAILURE);
43
+ this.txTotalFee = meter.createHistogram(Metrics.L1_PUBLISHER_TX_TOTAL_FEE);
44
+ this.senderBalance = meter.createGauge(Metrics.L1_PUBLISHER_BALANCE);
45
+ }
46
+ recordFailedTx(txType) {
47
+ this.txCount.add(1, {
48
+ [Attributes.L1_TX_TYPE]: txType,
49
+ [Attributes.OK]: false
50
+ });
51
+ if (txType === 'process') {
52
+ this.blobTxFailureCounter.add(1);
53
+ }
54
+ }
55
+ recordProcessBlockTx(durationMs, stats) {
56
+ this.recordTx('process', durationMs, stats);
57
+ if (stats.blobCount && stats.blobCount > 0) {
58
+ this.blobCountHistogram.record(stats.blobCount);
59
+ if (stats.inclusionBlocks !== undefined) {
60
+ this.blobInclusionBlocksHistogram.record(stats.inclusionBlocks);
61
+ }
62
+ this.blobTxSuccessCounter.add(1);
63
+ }
64
+ }
65
+ recordSenderBalance(wei, senderAddress) {
66
+ const eth = parseFloat(formatEther(wei, 'wei'));
67
+ this.senderBalance.record(eth, {
68
+ [Attributes.SENDER_ADDRESS]: senderAddress
69
+ });
70
+ }
71
+ recordTx(txType, durationMs, stats) {
72
+ const attributes = {
73
+ [Attributes.L1_TX_TYPE]: txType,
74
+ [Attributes.L1_SENDER]: stats.sender
75
+ };
76
+ this.txCount.add(1, {
77
+ ...attributes,
78
+ [Attributes.OK]: true
79
+ });
80
+ this.txDuration.record(Math.ceil(durationMs), attributes);
81
+ this.txGas.record(// safe to downcast - total block limit is 30M gas which fits in a JS number
82
+ Number(stats.gasUsed), attributes);
83
+ this.txCalldataGas.record(stats.calldataGas, attributes);
84
+ this.txCalldataSize.record(stats.calldataSize, attributes);
85
+ this.txBlobDataGasCost.record(Number(stats.blobDataGas), attributes);
86
+ this.txBlobDataGasUsed.record(Number(stats.blobGasUsed), attributes);
87
+ try {
88
+ this.gasPrice.record(parseInt(formatEther(stats.gasPrice, 'gwei'), 10));
89
+ } catch {
90
+ // ignore
91
+ }
92
+ const executionFee = stats.gasUsed * stats.gasPrice;
93
+ const blobFee = stats.blobGasUsed * stats.blobDataGas;
94
+ const totalFee = executionFee + blobFee;
95
+ try {
96
+ this.txTotalFee.record(parseFloat(formatEther(totalFee)));
97
+ } catch {
98
+ // ignore
99
+ }
100
+ }
101
+ }