@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.
- package/README.md +307 -0
- package/dest/client/index.d.ts +2 -0
- package/dest/client/index.d.ts.map +1 -0
- package/dest/client/index.js +1 -0
- package/dest/client/sequencer-client.d.ts +94 -0
- package/dest/client/sequencer-client.d.ts.map +1 -0
- package/dest/client/sequencer-client.js +177 -0
- package/dest/config.d.ts +56 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/config.js +251 -0
- package/dest/global_variable_builder/fee_predictor.d.ts +49 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +127 -0
- package/dest/global_variable_builder/fee_provider.d.ts +28 -0
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_provider.js +87 -0
- package/dest/global_variable_builder/global_builder.d.ts +28 -0
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -0
- package/dest/global_variable_builder/global_builder.js +40 -0
- package/dest/global_variable_builder/index.d.ts +4 -0
- package/dest/global_variable_builder/index.d.ts.map +1 -0
- package/dest/global_variable_builder/index.js +3 -0
- package/dest/index.d.ts +7 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +8 -0
- package/dest/publisher/config.d.ts +68 -0
- package/dest/publisher/config.d.ts.map +1 -0
- package/dest/publisher/config.js +137 -0
- package/dest/publisher/index.d.ts +5 -0
- package/dest/publisher/index.d.ts.map +1 -0
- package/dest/publisher/index.js +4 -0
- package/dest/publisher/l1_to_l2_messaging.d.ts +21 -0
- package/dest/publisher/l1_to_l2_messaging.d.ts.map +1 -0
- package/dest/publisher/l1_to_l2_messaging.js +70 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +101 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +68 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +36 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +3 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
- package/dest/publisher/sequencer-bundle-simulator.js +198 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +50 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
- package/dest/publisher/sequencer-publisher-factory.js +75 -0
- package/dest/publisher/sequencer-publisher-metrics.d.ts +26 -0
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -0
- package/dest/publisher/sequencer-publisher-metrics.js +101 -0
- package/dest/publisher/sequencer-publisher.d.ts +254 -0
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -0
- package/dest/publisher/sequencer-publisher.js +1784 -0
- package/dest/publisher/write_json.d.ts +11 -0
- package/dest/publisher/write_json.d.ts.map +1 -0
- package/dest/publisher/write_json.js +57 -0
- package/dest/sequencer/automine/automine_factory.d.ts +56 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +85 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +189 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +732 -0
- package/dest/sequencer/automine/index.d.ts +3 -0
- package/dest/sequencer/automine/index.d.ts.map +1 -0
- package/dest/sequencer/automine/index.js +2 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +169 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1961 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
- package/dest/sequencer/checkpoint_voter.d.ts +34 -0
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_voter.js +106 -0
- package/dest/sequencer/config.d.ts +8 -0
- package/dest/sequencer/config.d.ts.map +1 -0
- package/dest/sequencer/config.js +1 -0
- package/dest/sequencer/errors.d.ts +11 -0
- package/dest/sequencer/errors.d.ts.map +1 -0
- package/dest/sequencer/errors.js +15 -0
- package/dest/sequencer/events.d.ts +103 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/inbox_bucket_selector.d.ts +88 -0
- package/dest/sequencer/inbox_bucket_selector.d.ts.map +1 -0
- package/dest/sequencer/inbox_bucket_selector.js +80 -0
- package/dest/sequencer/index.d.ts +6 -0
- package/dest/sequencer/index.d.ts.map +1 -0
- package/dest/sequencer/index.js +5 -0
- package/dest/sequencer/metrics.d.ts +75 -0
- package/dest/sequencer/metrics.d.ts.map +1 -0
- package/dest/sequencer/metrics.js +343 -0
- package/dest/sequencer/missing_committee.d.ts +72 -0
- package/dest/sequencer/missing_committee.d.ts.map +1 -0
- package/dest/sequencer/missing_committee.js +139 -0
- package/dest/sequencer/requests_tracker.d.ts +22 -0
- package/dest/sequencer/requests_tracker.d.ts.map +1 -0
- package/dest/sequencer/requests_tracker.js +33 -0
- package/dest/sequencer/sequencer.d.ts +326 -0
- package/dest/sequencer/sequencer.d.ts.map +1 -0
- package/dest/sequencer/sequencer.js +1495 -0
- package/dest/sequencer/types.d.ts +3 -0
- package/dest/sequencer/types.d.ts.map +1 -0
- package/dest/sequencer/types.js +1 -0
- package/dest/sequencer/utils.d.ts +30 -0
- package/dest/sequencer/utils.d.ts.map +1 -0
- package/dest/sequencer/utils.js +18 -0
- package/dest/test/index.d.ts +23 -0
- package/dest/test/index.d.ts.map +1 -0
- package/dest/test/index.js +6 -0
- package/dest/test/mock_checkpoint_builder.d.ts +95 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +230 -0
- package/dest/test/utils.d.ts +67 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +121 -0
- package/package.json +118 -0
- package/src/client/index.ts +1 -0
- package/src/client/sequencer-client.ts +281 -0
- package/src/config.ts +309 -0
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +176 -0
- package/src/global_variable_builder/fee_provider.ts +104 -0
- package/src/global_variable_builder/global_builder.ts +68 -0
- package/src/global_variable_builder/index.ts +3 -0
- package/src/index.ts +15 -0
- package/src/publisher/config.ts +220 -0
- package/src/publisher/index.ts +8 -0
- package/src/publisher/l1_to_l2_messaging.ts +85 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +166 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +47 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-bundle-simulator.ts +253 -0
- package/src/publisher/sequencer-publisher-factory.ts +121 -0
- package/src/publisher/sequencer-publisher-metrics.ts +145 -0
- package/src/publisher/sequencer-publisher.ts +1719 -0
- package/src/publisher/write_json.ts +77 -0
- package/src/sequencer/README.md +243 -0
- package/src/sequencer/automine/README.md +60 -0
- package/src/sequencer/automine/automine_factory.ts +156 -0
- package/src/sequencer/automine/automine_sequencer.ts +841 -0
- package/src/sequencer/automine/index.ts +6 -0
- package/src/sequencer/checkpoint_proposal_job.ts +1889 -0
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +118 -0
- package/src/sequencer/config.ts +9 -0
- package/src/sequencer/errors.ts +21 -0
- package/src/sequencer/events.ts +93 -0
- package/src/sequencer/inbox_bucket_selector.ts +160 -0
- package/src/sequencer/index.ts +5 -0
- package/src/sequencer/metrics.ts +463 -0
- package/src/sequencer/missing_committee.ts +192 -0
- package/src/sequencer/requests_tracker.ts +43 -0
- package/src/sequencer/sequencer.ts +1401 -0
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +42 -0
- package/src/test/index.ts +26 -0
- package/src/test/mock_checkpoint_builder.ts +324 -0
- package/src/test/utils.ts +215 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import type { EpochCache } from '@aztec-labs/epoch-cache';
|
|
2
|
+
import { Multicall3, type RollupContract, buildSimulationOverridesStateOverride } from '@aztec-labs/ethereum/contracts';
|
|
3
|
+
import { type L1TxUtils, MAX_L1_TX_LIMIT } from '@aztec-labs/ethereum/l1-tx-utils';
|
|
4
|
+
import { formatViemError } from '@aztec-labs/ethereum/utils';
|
|
5
|
+
import type { SlotNumber } from '@aztec-labs/foundation/branded-types';
|
|
6
|
+
import { type Logger, createLogger } from '@aztec-labs/foundation/log';
|
|
7
|
+
import { getLastL1SlotTimestampForL2Slot } from '@aztec-labs/stdlib/epoch-helpers';
|
|
8
|
+
import type { Hex, StateOverride } from 'viem';
|
|
9
|
+
|
|
10
|
+
import type { RequestWithExpiry } from './sequencer-publisher.js';
|
|
11
|
+
|
|
12
|
+
/** A request that was dropped by bundle simulation, with the decoded revert reason. */
|
|
13
|
+
export type DroppedRequest = {
|
|
14
|
+
request: RequestWithExpiry;
|
|
15
|
+
revertReason: string | undefined;
|
|
16
|
+
returnData: Hex | undefined;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Result of {@link SequencerBundleSimulator.simulate}.
|
|
21
|
+
*
|
|
22
|
+
* - `success`: simulation succeeded. `requests` is the filtered survivor list, `gasLimit` is
|
|
23
|
+
* the bumped gas limit derived from `gasUsed` (plus blob evaluation gas). `droppedRequests`
|
|
24
|
+
* lists the entries that were observed to revert in simulation.
|
|
25
|
+
* - `fallback`: the node does not support eth_simulateV1 (or the simulate call threw). The
|
|
26
|
+
* caller should send `requests` as-is with a safe gas limit (e.g. {@link MAX_L1_TX_LIMIT}).
|
|
27
|
+
* `droppedRequests` carries any entries that the first pass already proved reverted, so the
|
|
28
|
+
* caller does not re-include them when the second pass falls back.
|
|
29
|
+
* - `aborted`: the bundle cannot be sent. `droppedRequests` contains only entries that were
|
|
30
|
+
* actually observed to revert (so they can be reported as simulation failures); it is empty
|
|
31
|
+
* when the abort was caused by an empty input bundle.
|
|
32
|
+
*/
|
|
33
|
+
export type BundleSimulateResult =
|
|
34
|
+
| { kind: 'success'; requests: RequestWithExpiry[]; gasLimit: bigint; droppedRequests: DroppedRequest[] }
|
|
35
|
+
| { kind: 'fallback'; requests: RequestWithExpiry[]; droppedRequests: DroppedRequest[] }
|
|
36
|
+
| { kind: 'aborted'; reason: AbortReason; droppedRequests: DroppedRequest[] };
|
|
37
|
+
|
|
38
|
+
export type AbortReason = 'empty-bundle' | 'all-reverted' | 'second-pass-reverts';
|
|
39
|
+
|
|
40
|
+
type SimulatePassResult =
|
|
41
|
+
| { kind: 'decoded'; survivors: RequestWithExpiry[]; droppedRequests: DroppedRequest[]; gasUsed: bigint }
|
|
42
|
+
| { kind: 'fallback' };
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Bundle-level simulator for the aggregate3 payload that `SequencerPublisher` is about to send.
|
|
46
|
+
*
|
|
47
|
+
* Runs `eth_simulateV1` against `Multicall3.aggregate3`, drops entries that revert, and returns
|
|
48
|
+
* a gasLimit for the survivors. When `eth_simulateV1` is unavailable, signals fallback to the
|
|
49
|
+
* caller so it can send the bundle as-is with a conservative gas limit.
|
|
50
|
+
*/
|
|
51
|
+
export class SequencerBundleSimulator {
|
|
52
|
+
private readonly log: Logger;
|
|
53
|
+
|
|
54
|
+
constructor(
|
|
55
|
+
private readonly deps: {
|
|
56
|
+
getL1TxUtils: () => L1TxUtils;
|
|
57
|
+
rollupContract: RollupContract;
|
|
58
|
+
epochCache: EpochCache;
|
|
59
|
+
log?: Logger;
|
|
60
|
+
},
|
|
61
|
+
) {
|
|
62
|
+
this.log = deps.log ?? createLogger('sequencer:publisher:bundle-simulator');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Simulates the given bundle near the end of the target slot and filters out entries
|
|
67
|
+
* that revert.
|
|
68
|
+
*
|
|
69
|
+
* - If all entries pass on the first pass, returns `success` with the gasLimit.
|
|
70
|
+
* - If some entries revert, re-simulates the survivors. If the second pass is clean, returns
|
|
71
|
+
* `success` with the survivors and dropped entries. If the second pass surfaces any revert,
|
|
72
|
+
* returns `aborted` — we refuse to send a bundle whose composition still has internal
|
|
73
|
+
* reverts after one round of filtering.
|
|
74
|
+
* - If eth_simulateV1 is unavailable, returns `fallback`. The caller is expected to send the
|
|
75
|
+
* bundle as-is with a safe gas limit.
|
|
76
|
+
*
|
|
77
|
+
* The simulation `block.timestamp` is the last L1 slot timestamp inside the target L2 slot.
|
|
78
|
+
* This still maps to the target L2 slot for propose's `validateHeader` and EIP-712 signature
|
|
79
|
+
* checks, while avoiding eth_simulateV1 rejecting a child block whose timestamp is not strictly
|
|
80
|
+
* greater than the current L1 head.
|
|
81
|
+
*
|
|
82
|
+
* Known limitation: on networks where L1 is mining behind cadence (missed L1 slots, anvil with
|
|
83
|
+
* overridden timestamps), the actual `block.timestamp` at send time can land in the prior L2
|
|
84
|
+
* slot. In that case `propose` would revert silently inside the multicall. The simulator does
|
|
85
|
+
* not detect this case because it simulates inside the target slot — the prior implementation
|
|
86
|
+
* used `min(predictedNextL1Ts, targetTimestamp)` to surface this failure mode at simulate time.
|
|
87
|
+
*/
|
|
88
|
+
public async simulate(validRequests: RequestWithExpiry[], targetSlot: SlotNumber): Promise<BundleSimulateResult> {
|
|
89
|
+
if (validRequests.length === 0) {
|
|
90
|
+
return { kind: 'aborted', reason: 'empty-bundle', droppedRequests: [] };
|
|
91
|
+
}
|
|
92
|
+
// Pin the publisher we'll use across the whole simulate call so that the publisher's rotation
|
|
93
|
+
// can't change l1TxUtils mid-flight.
|
|
94
|
+
const l1TxUtils = this.deps.getL1TxUtils();
|
|
95
|
+
|
|
96
|
+
const proposeRequest = validRequests.find(r => r.action === 'propose');
|
|
97
|
+
const simulateTimestamp = getLastL1SlotTimestampForL2Slot(targetSlot, this.deps.epochCache.getL1Constants());
|
|
98
|
+
const firstPassOverrides = await this.buildStateOverrides(!!proposeRequest);
|
|
99
|
+
|
|
100
|
+
const firstPass = await this.simulateAndDecode(l1TxUtils, validRequests, simulateTimestamp, firstPassOverrides);
|
|
101
|
+
|
|
102
|
+
if (firstPass.kind === 'fallback') {
|
|
103
|
+
this.log.warn('Bundle simulate fallback (eth_simulateV1 unavailable); caller will send bundle as-is', {
|
|
104
|
+
actions: validRequests.map(r => r.action),
|
|
105
|
+
});
|
|
106
|
+
return { kind: 'fallback', requests: validRequests, droppedRequests: [] };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (firstPass.survivors.length === 0) {
|
|
110
|
+
this.log.warn('All bundle entries dropped in simulation; aborting send', {
|
|
111
|
+
actions: validRequests.map(r => r.action),
|
|
112
|
+
});
|
|
113
|
+
return { kind: 'aborted', reason: 'all-reverted', droppedRequests: firstPass.droppedRequests };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (firstPass.droppedRequests.length === 0) {
|
|
117
|
+
return this.buildSuccessResult(l1TxUtils, firstPass.survivors, [], firstPass.gasUsed, proposeRequest);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
this.log.warn('Some bundle entries reverted; re-simulating reduced bundle', {
|
|
121
|
+
droppedActions: firstPass.droppedRequests.map(d => d.request.action),
|
|
122
|
+
remainingActions: firstPass.survivors.map(r => r.action),
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Rebuild overrides for the reduced bundle: if propose was dropped, we no longer need the blob-check override
|
|
126
|
+
const proposeSurvived = proposeRequest !== undefined && firstPass.survivors.includes(proposeRequest);
|
|
127
|
+
const secondPassOverrides = proposeSurvived ? firstPassOverrides : await this.buildStateOverrides(false);
|
|
128
|
+
const secondPass = await this.simulateAndDecode(
|
|
129
|
+
l1TxUtils,
|
|
130
|
+
firstPass.survivors,
|
|
131
|
+
simulateTimestamp,
|
|
132
|
+
secondPassOverrides,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
if (secondPass.kind === 'fallback') {
|
|
136
|
+
this.log.warn(
|
|
137
|
+
'Bundle simulate errored on second pass (eth_simulateV1 unavailable); sending first-pass survivors as-is',
|
|
138
|
+
{
|
|
139
|
+
actions: firstPass.survivors.map(r => r.action),
|
|
140
|
+
droppedActions: firstPass.droppedRequests.map(d => d.request.action),
|
|
141
|
+
},
|
|
142
|
+
);
|
|
143
|
+
return { kind: 'fallback', requests: firstPass.survivors, droppedRequests: firstPass.droppedRequests };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// We refuse to chase reverts through repeated trimming: anything other than a clean second pass aborts the whole send
|
|
147
|
+
if (secondPass.droppedRequests.length > 0) {
|
|
148
|
+
this.log.error('Re-simulate surfaced reverts; aborting send', {
|
|
149
|
+
secondPassDroppedActions: secondPass.droppedRequests.map(d => d.request.action),
|
|
150
|
+
});
|
|
151
|
+
return {
|
|
152
|
+
kind: 'aborted',
|
|
153
|
+
reason: 'second-pass-reverts',
|
|
154
|
+
droppedRequests: [...firstPass.droppedRequests, ...secondPass.droppedRequests],
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return this.buildSuccessResult(
|
|
159
|
+
l1TxUtils,
|
|
160
|
+
secondPass.survivors,
|
|
161
|
+
firstPass.droppedRequests,
|
|
162
|
+
secondPass.gasUsed,
|
|
163
|
+
proposeRequest,
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private buildSuccessResult(
|
|
168
|
+
l1TxUtils: L1TxUtils,
|
|
169
|
+
survivors: RequestWithExpiry[],
|
|
170
|
+
droppedRequests: DroppedRequest[],
|
|
171
|
+
bundleGasUsed: bigint,
|
|
172
|
+
proposeRequest: RequestWithExpiry | undefined,
|
|
173
|
+
): BundleSimulateResult {
|
|
174
|
+
const proposeSurvived = proposeRequest !== undefined && survivors.includes(proposeRequest);
|
|
175
|
+
const blobEvaluationGas = proposeSurvived ? (proposeRequest?.blobEvaluationGas ?? 0n) : 0n;
|
|
176
|
+
const gasLimit = this.computeGasLimit(l1TxUtils, bundleGasUsed, blobEvaluationGas);
|
|
177
|
+
this.log.debug('Bundle simulate complete', {
|
|
178
|
+
survivingRequests: survivors.length,
|
|
179
|
+
bundleGasUsed,
|
|
180
|
+
gasLimit,
|
|
181
|
+
actions: survivors.map(r => r.action),
|
|
182
|
+
});
|
|
183
|
+
return { kind: 'success', requests: survivors, gasLimit, droppedRequests };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* `gasLimit = bumpGasLimit(ceil(gasUsed * 64 / 63))`, plus blob evaluation gas if a propose
|
|
188
|
+
* survived, capped at the L1 block gas limit.
|
|
189
|
+
*/
|
|
190
|
+
private computeGasLimit(l1TxUtils: L1TxUtils, bundleGasUsed: bigint, blobEvaluationGas: bigint): bigint {
|
|
191
|
+
const gasUsedWithEip150 = (bundleGasUsed * 64n + 62n) / 63n;
|
|
192
|
+
const gasLimit = l1TxUtils.bumpGasLimit(gasUsedWithEip150) + blobEvaluationGas;
|
|
193
|
+
return gasLimit > MAX_L1_TX_LIMIT ? MAX_L1_TX_LIMIT : gasLimit;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* eth_simulateV1 cannot carry blob sidecar data, so disable the rollup's on-chain blob check
|
|
198
|
+
* when a propose is in the bundle.
|
|
199
|
+
*/
|
|
200
|
+
private buildStateOverrides(hasProposeAction: boolean): Promise<StateOverride> {
|
|
201
|
+
return buildSimulationOverridesStateOverride(
|
|
202
|
+
this.deps.rollupContract,
|
|
203
|
+
hasProposeAction ? { disableBlobCheck: true } : undefined,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
private async simulateAndDecode(
|
|
208
|
+
l1TxUtils: L1TxUtils,
|
|
209
|
+
requests: RequestWithExpiry[],
|
|
210
|
+
simulateTimestamp: bigint,
|
|
211
|
+
stateOverrides: StateOverride,
|
|
212
|
+
): Promise<SimulatePassResult> {
|
|
213
|
+
let simResult: Awaited<ReturnType<typeof Multicall3.simulateAggregate3>>;
|
|
214
|
+
try {
|
|
215
|
+
simResult = await Multicall3.simulateAggregate3(
|
|
216
|
+
requests.map(r => ({ to: r.request.to! as Hex, data: r.request.data! as Hex, abi: r.request.abi })),
|
|
217
|
+
l1TxUtils,
|
|
218
|
+
{
|
|
219
|
+
blockOverrides: { time: simulateTimestamp, gasLimit: MAX_L1_TX_LIMIT * 2n },
|
|
220
|
+
stateOverrides,
|
|
221
|
+
gas: MAX_L1_TX_LIMIT,
|
|
222
|
+
fallbackGasEstimate: MAX_L1_TX_LIMIT,
|
|
223
|
+
},
|
|
224
|
+
);
|
|
225
|
+
} catch (err) {
|
|
226
|
+
this.log.warn('Bundle simulate threw; treating as fallback', {
|
|
227
|
+
err: formatViemError(err),
|
|
228
|
+
actions: requests.map(r => r.action),
|
|
229
|
+
});
|
|
230
|
+
return { kind: 'fallback' };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (simResult.kind === 'fallback') {
|
|
234
|
+
return { kind: 'fallback' };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const survivors: RequestWithExpiry[] = [];
|
|
238
|
+
const droppedRequests: DroppedRequest[] = [];
|
|
239
|
+
for (let i = 0; i < requests.length; i++) {
|
|
240
|
+
const entry = simResult.entries[i];
|
|
241
|
+
if (entry.success) {
|
|
242
|
+
survivors.push(requests[i]);
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
droppedRequests.push({
|
|
246
|
+
request: requests[i],
|
|
247
|
+
revertReason: entry.revertReason,
|
|
248
|
+
returnData: entry.returnData,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
return { kind: 'decoded', survivors, droppedRequests, gasUsed: simResult.gasUsed };
|
|
252
|
+
}
|
|
253
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
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 { PublisherFilter, PublisherManager } from '@aztec-labs/ethereum/publisher-manager';
|
|
6
|
+
import { SlotNumber } from '@aztec-labs/foundation/branded-types';
|
|
7
|
+
import { EthAddress } from '@aztec-labs/foundation/eth-address';
|
|
8
|
+
import { type Logger, createLogger } from '@aztec-labs/foundation/log';
|
|
9
|
+
import type { DateProvider } from '@aztec-labs/foundation/timer';
|
|
10
|
+
import type { TelemetryClient } from '@aztec-labs/telemetry-client';
|
|
11
|
+
import { NodeKeystoreAdapter } from '@aztec-labs/validator-client';
|
|
12
|
+
|
|
13
|
+
import type { SequencerClientConfig } from '../config.js';
|
|
14
|
+
import { SequencerPublisherMetrics } from './sequencer-publisher-metrics.js';
|
|
15
|
+
import { type Action, SequencerPublisher } from './sequencer-publisher.js';
|
|
16
|
+
|
|
17
|
+
export type AttestorPublisherPair = {
|
|
18
|
+
attestorAddress: EthAddress;
|
|
19
|
+
publisher: SequencerPublisher;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export class SequencerPublisherFactory {
|
|
23
|
+
private publisherMetrics: SequencerPublisherMetrics;
|
|
24
|
+
|
|
25
|
+
/** Stores the last slot in which every action was carried out by a publisher */
|
|
26
|
+
private lastActions: Partial<Record<Action, SlotNumber>> = {};
|
|
27
|
+
|
|
28
|
+
private nodeKeyStore: NodeKeystoreAdapter;
|
|
29
|
+
|
|
30
|
+
private logger: Logger;
|
|
31
|
+
|
|
32
|
+
constructor(
|
|
33
|
+
private sequencerConfig: SequencerClientConfig,
|
|
34
|
+
private deps: {
|
|
35
|
+
telemetry: TelemetryClient;
|
|
36
|
+
publisherManager: PublisherManager<L1TxUtils>;
|
|
37
|
+
blobClient: BlobClientInterface;
|
|
38
|
+
dateProvider: DateProvider;
|
|
39
|
+
epochCache: EpochCache;
|
|
40
|
+
rollupContract: RollupContract;
|
|
41
|
+
governanceProposerContract: GovernanceProposerContract;
|
|
42
|
+
nodeKeyStore: NodeKeystoreAdapter;
|
|
43
|
+
logger?: Logger;
|
|
44
|
+
},
|
|
45
|
+
) {
|
|
46
|
+
this.publisherMetrics = new SequencerPublisherMetrics(deps.telemetry, 'SequencerPublisher');
|
|
47
|
+
this.logger = deps.logger ?? createLogger('sequencer');
|
|
48
|
+
this.nodeKeyStore = this.deps.nodeKeyStore;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Updates the node keystore adapter used for publisher lookups.
|
|
53
|
+
* Called when the keystore is reloaded at runtime to reflect new validator-publisher mappings.
|
|
54
|
+
*/
|
|
55
|
+
public updateNodeKeyStore(adapter: NodeKeystoreAdapter): void {
|
|
56
|
+
this.nodeKeyStore = adapter;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Creates a new SequencerPublisher instance.
|
|
61
|
+
* @param _validatorAddress - The address of the validator that will be using the publisher.
|
|
62
|
+
* @returns A new SequencerPublisher instance.
|
|
63
|
+
*/
|
|
64
|
+
public async create(validatorAddress?: EthAddress): Promise<AttestorPublisherPair> {
|
|
65
|
+
// If we have been given an attestor address we must only allow publishers permitted for that attestor
|
|
66
|
+
|
|
67
|
+
const allowedPublishers = !validatorAddress ? [] : this.nodeKeyStore.getPublisherAddresses(validatorAddress);
|
|
68
|
+
const filter: PublisherFilter<L1TxUtils> = !validatorAddress
|
|
69
|
+
? () => true
|
|
70
|
+
: (utils: L1TxUtils) => {
|
|
71
|
+
const publisherAddress = utils.getSenderAddress();
|
|
72
|
+
return allowedPublishers.some(allowedPublisher => allowedPublisher.equals(publisherAddress));
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const l1Publisher = await this.deps.publisherManager.getAvailablePublisher(filter);
|
|
76
|
+
const attestorAddress =
|
|
77
|
+
validatorAddress ?? this.nodeKeyStore.getAttestorForPublisher(l1Publisher.getSenderAddress());
|
|
78
|
+
|
|
79
|
+
const rollup = this.deps.rollupContract;
|
|
80
|
+
const slashingProposerContract = await rollup.getSlashingProposer();
|
|
81
|
+
|
|
82
|
+
const getNextPublisher = async (excludeAddresses: EthAddress[]): Promise<L1TxUtils | undefined> => {
|
|
83
|
+
const exclusionFilter: PublisherFilter<L1TxUtils> = (utils: L1TxUtils) => {
|
|
84
|
+
if (excludeAddresses.some(addr => addr.equals(utils.getSenderAddress()))) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
return filter(utils);
|
|
88
|
+
};
|
|
89
|
+
try {
|
|
90
|
+
return await this.deps.publisherManager.getAvailablePublisher(exclusionFilter);
|
|
91
|
+
} catch {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const publisher = new SequencerPublisher(this.sequencerConfig, {
|
|
97
|
+
l1TxUtils: l1Publisher,
|
|
98
|
+
getNextPublisher,
|
|
99
|
+
telemetry: this.deps.telemetry,
|
|
100
|
+
blobClient: this.deps.blobClient,
|
|
101
|
+
rollupContract: this.deps.rollupContract,
|
|
102
|
+
epochCache: this.deps.epochCache,
|
|
103
|
+
governanceProposerContract: this.deps.governanceProposerContract,
|
|
104
|
+
slashingProposerContract,
|
|
105
|
+
dateProvider: this.deps.dateProvider,
|
|
106
|
+
metrics: this.publisherMetrics,
|
|
107
|
+
lastActions: this.lastActions,
|
|
108
|
+
log: this.logger.createChild('publisher'),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
attestorAddress,
|
|
113
|
+
publisher,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Stops all publishers managed by this factory. Used during sequencer shutdown. */
|
|
118
|
+
public async stopAll(): Promise<void> {
|
|
119
|
+
await this.deps.publisherManager.stop();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { createLogger } from '@aztec-labs/foundation/log';
|
|
2
|
+
import type { L1PublishCheckpointStats, L1PublishStats } from '@aztec-labs/stdlib/stats';
|
|
3
|
+
import {
|
|
4
|
+
Attributes,
|
|
5
|
+
type Gauge,
|
|
6
|
+
type Histogram,
|
|
7
|
+
Metrics,
|
|
8
|
+
type TelemetryClient,
|
|
9
|
+
type UpDownCounter,
|
|
10
|
+
createUpDownCounterWithDefault,
|
|
11
|
+
} from '@aztec-labs/telemetry-client';
|
|
12
|
+
import { formatEther } from 'viem/utils';
|
|
13
|
+
|
|
14
|
+
export type L1TxType = 'process';
|
|
15
|
+
|
|
16
|
+
export class SequencerPublisherMetrics {
|
|
17
|
+
private gasPrice: Histogram;
|
|
18
|
+
|
|
19
|
+
private txCount: UpDownCounter;
|
|
20
|
+
private txDuration: Histogram;
|
|
21
|
+
private txGas: Histogram;
|
|
22
|
+
private txCalldataSize: Histogram;
|
|
23
|
+
private txCalldataGas: Histogram;
|
|
24
|
+
private txBlobDataGasUsed: Histogram;
|
|
25
|
+
private txBlobDataGasCost: Histogram;
|
|
26
|
+
private txTotalFee: Histogram;
|
|
27
|
+
|
|
28
|
+
private readonly blobCountHistogram: Histogram;
|
|
29
|
+
private readonly blobInclusionBlocksHistogram: Histogram;
|
|
30
|
+
private readonly blobTxSuccessCounter: UpDownCounter;
|
|
31
|
+
private readonly blobTxFailureCounter: UpDownCounter;
|
|
32
|
+
|
|
33
|
+
private senderBalance: Gauge;
|
|
34
|
+
|
|
35
|
+
constructor(
|
|
36
|
+
client: TelemetryClient,
|
|
37
|
+
name = 'SequencerPublisher',
|
|
38
|
+
private logger = createLogger('sequencer:publisher:metrics'),
|
|
39
|
+
) {
|
|
40
|
+
const meter = client.getMeter(name);
|
|
41
|
+
|
|
42
|
+
this.gasPrice = meter.createHistogram(Metrics.L1_PUBLISHER_GAS_PRICE);
|
|
43
|
+
|
|
44
|
+
this.txCount = createUpDownCounterWithDefault(meter, Metrics.L1_PUBLISHER_TX_COUNT, {
|
|
45
|
+
[Attributes.L1_TX_TYPE]: ['process'],
|
|
46
|
+
[Attributes.OK]: [true, false],
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
this.txDuration = meter.createHistogram(Metrics.L1_PUBLISHER_TX_DURATION);
|
|
50
|
+
|
|
51
|
+
this.txGas = meter.createHistogram(Metrics.L1_PUBLISHER_TX_GAS);
|
|
52
|
+
|
|
53
|
+
this.txCalldataSize = meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_SIZE);
|
|
54
|
+
|
|
55
|
+
this.txCalldataGas = meter.createHistogram(Metrics.L1_PUBLISHER_TX_CALLDATA_GAS);
|
|
56
|
+
|
|
57
|
+
this.txBlobDataGasUsed = meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_USED);
|
|
58
|
+
|
|
59
|
+
this.txBlobDataGasCost = meter.createHistogram(Metrics.L1_PUBLISHER_TX_BLOBDATA_GAS_COST);
|
|
60
|
+
|
|
61
|
+
this.blobCountHistogram = meter.createHistogram(Metrics.L1_PUBLISHER_BLOB_COUNT);
|
|
62
|
+
|
|
63
|
+
this.blobInclusionBlocksHistogram = meter.createHistogram(Metrics.L1_PUBLISHER_BLOB_INCLUSION_BLOCKS);
|
|
64
|
+
|
|
65
|
+
this.blobTxSuccessCounter = createUpDownCounterWithDefault(meter, Metrics.L1_PUBLISHER_BLOB_TX_SUCCESS);
|
|
66
|
+
|
|
67
|
+
this.blobTxFailureCounter = createUpDownCounterWithDefault(meter, Metrics.L1_PUBLISHER_BLOB_TX_FAILURE);
|
|
68
|
+
|
|
69
|
+
this.txTotalFee = meter.createHistogram(Metrics.L1_PUBLISHER_TX_TOTAL_FEE);
|
|
70
|
+
|
|
71
|
+
this.senderBalance = meter.createGauge(Metrics.L1_PUBLISHER_BALANCE);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
recordFailedTx(txType: L1TxType) {
|
|
75
|
+
this.txCount.add(1, {
|
|
76
|
+
[Attributes.L1_TX_TYPE]: txType,
|
|
77
|
+
[Attributes.OK]: false,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
if (txType === 'process') {
|
|
81
|
+
this.blobTxFailureCounter.add(1);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
recordProcessBlockTx(durationMs: number, stats: L1PublishCheckpointStats) {
|
|
86
|
+
this.recordTx('process', durationMs, stats);
|
|
87
|
+
|
|
88
|
+
if (stats.blobCount && stats.blobCount > 0) {
|
|
89
|
+
this.blobCountHistogram.record(stats.blobCount);
|
|
90
|
+
|
|
91
|
+
if (stats.inclusionBlocks !== undefined) {
|
|
92
|
+
this.blobInclusionBlocksHistogram.record(stats.inclusionBlocks);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
this.blobTxSuccessCounter.add(1);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
recordSenderBalance(wei: bigint, senderAddress: string) {
|
|
100
|
+
const eth = parseFloat(formatEther(wei, 'wei'));
|
|
101
|
+
this.senderBalance.record(eth, {
|
|
102
|
+
[Attributes.SENDER_ADDRESS]: senderAddress,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private recordTx(txType: L1TxType, durationMs: number, stats: L1PublishStats) {
|
|
107
|
+
const attributes = {
|
|
108
|
+
[Attributes.L1_TX_TYPE]: txType,
|
|
109
|
+
[Attributes.L1_SENDER]: stats.sender,
|
|
110
|
+
} as const;
|
|
111
|
+
|
|
112
|
+
this.txCount.add(1, {
|
|
113
|
+
...attributes,
|
|
114
|
+
[Attributes.OK]: true,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
this.txDuration.record(Math.ceil(durationMs), attributes);
|
|
118
|
+
this.txGas.record(
|
|
119
|
+
// safe to downcast - total block limit is 30M gas which fits in a JS number
|
|
120
|
+
Number(stats.gasUsed),
|
|
121
|
+
attributes,
|
|
122
|
+
);
|
|
123
|
+
this.txCalldataGas.record(stats.calldataGas, attributes);
|
|
124
|
+
this.txCalldataSize.record(stats.calldataSize, attributes);
|
|
125
|
+
|
|
126
|
+
this.txBlobDataGasCost.record(Number(stats.blobDataGas), attributes);
|
|
127
|
+
this.txBlobDataGasUsed.record(Number(stats.blobGasUsed), attributes);
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
this.gasPrice.record(parseInt(formatEther(stats.gasPrice, 'gwei'), 10));
|
|
131
|
+
} catch {
|
|
132
|
+
// ignore
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const executionFee = stats.gasUsed * stats.gasPrice;
|
|
136
|
+
const blobFee = stats.blobGasUsed * stats.blobDataGas;
|
|
137
|
+
const totalFee = executionFee + blobFee;
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
this.txTotalFee.record(parseFloat(formatEther(totalFee)));
|
|
141
|
+
} catch {
|
|
142
|
+
// ignore
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|