@aztec/sequencer-client 0.0.1-commit.3fd054f6 → 0.0.1-commit.431c48d
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 +283 -21
- package/dest/client/sequencer-client.d.ts +20 -5
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +26 -22
- package/dest/config.d.ts +13 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +67 -26
- package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +138 -0
- package/dest/global_variable_builder/fee_provider.d.ts +21 -0
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_provider.js +80 -0
- package/dest/global_variable_builder/global_builder.d.ts +6 -25
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +7 -65
- package/dest/global_variable_builder/index.d.ts +3 -1
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- package/dest/global_variable_builder/index.js +2 -0
- package/dest/publisher/config.d.ts +7 -3
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +13 -3
- 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/failed_tx_store.d.ts +3 -4
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -1
- 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 +1 -3
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +0 -1
- package/dest/publisher/sequencer-publisher.d.ts +88 -71
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +434 -548
- 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 +696 -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 +71 -21
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +738 -214
- 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 +1 -2
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_voter.js +2 -5
- package/dest/sequencer/errors.d.ts +1 -8
- package/dest/sequencer/errors.d.ts.map +1 -1
- package/dest/sequencer/errors.js +0 -9
- package/dest/sequencer/events.d.ts +61 -5
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/metrics.d.ts +10 -11
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +34 -20
- 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 +157 -33
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +566 -158
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- package/dest/test/index.d.ts +3 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/utils.d.ts +15 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +25 -7
- package/package.json +28 -27
- package/src/client/sequencer-client.ts +37 -27
- package/src/config.ts +79 -26
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +182 -0
- package/src/global_variable_builder/fee_provider.ts +97 -0
- package/src/global_variable_builder/global_builder.ts +12 -80
- package/src/global_variable_builder/index.ts +2 -0
- package/src/publisher/config.ts +30 -7
- package/src/publisher/l1_to_l2_messaging.ts +85 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +3 -1
- package/src/publisher/sequencer-bundle-simulator.ts +254 -0
- package/src/publisher/sequencer-publisher-factory.ts +0 -3
- package/src/publisher/sequencer-publisher.ts +494 -596
- package/src/publisher/write_json.ts +78 -0
- package/src/sequencer/automine/README.md +60 -0
- package/src/sequencer/automine/automine_factory.ts +152 -0
- package/src/sequencer/automine/automine_sequencer.ts +800 -0
- package/src/sequencer/automine/index.ts +6 -0
- package/src/sequencer/checkpoint_proposal_job.ts +854 -243
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +1 -12
- package/src/sequencer/errors.ts +0 -15
- package/src/sequencer/events.ts +66 -5
- package/src/sequencer/metrics.ts +49 -25
- package/src/sequencer/requests_tracker.ts +43 -0
- package/src/sequencer/sequencer.ts +646 -175
- package/src/sequencer/types.ts +1 -1
- package/src/test/index.ts +2 -2
- package/src/test/utils.ts +61 -10
- package/dest/sequencer/timetable.d.ts +0 -88
- package/dest/sequencer/timetable.d.ts.map +0 -1
- package/dest/sequencer/timetable.js +0 -222
- package/src/sequencer/README.md +0 -531
- package/src/sequencer/timetable.ts +0 -283
|
@@ -3,16 +3,16 @@ import { Blob, getBlobsPerL1Block, getPrefixedEthBlobCommitments } from '@aztec/
|
|
|
3
3
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
4
4
|
import type { L1ContractsConfig } from '@aztec/ethereum/config';
|
|
5
5
|
import {
|
|
6
|
-
type EmpireSlashingProposerContract,
|
|
7
6
|
FeeAssetPriceOracle,
|
|
8
7
|
type GovernanceProposerContract,
|
|
9
|
-
type IEmpireBase,
|
|
10
8
|
MULTI_CALL_3_ADDRESS,
|
|
11
9
|
Multicall3,
|
|
12
|
-
|
|
13
|
-
type
|
|
14
|
-
type
|
|
15
|
-
type
|
|
10
|
+
MulticallForwarderRevertedError,
|
|
11
|
+
type PayloadProposalStatus,
|
|
12
|
+
type RollupContract,
|
|
13
|
+
type SimulationOverridesPlan,
|
|
14
|
+
type SlashingProposerContract,
|
|
15
|
+
buildSimulationOverridesStateOverride,
|
|
16
16
|
} from '@aztec/ethereum/contracts';
|
|
17
17
|
import { type L1FeeAnalysisResult, L1FeeAnalyzer } from '@aztec/ethereum/l1-fee-analysis';
|
|
18
18
|
import {
|
|
@@ -24,45 +24,82 @@ import {
|
|
|
24
24
|
type TransactionStats,
|
|
25
25
|
WEI_CONST,
|
|
26
26
|
} from '@aztec/ethereum/l1-tx-utils';
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
import {
|
|
28
|
+
FormattedViemError,
|
|
29
|
+
formatViemError,
|
|
30
|
+
mergeAbis,
|
|
31
|
+
tryDecodeRevertReason,
|
|
32
|
+
tryExtractEvent,
|
|
33
|
+
} from '@aztec/ethereum/utils';
|
|
30
34
|
import { CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
31
35
|
import { trimmedBytesLength } from '@aztec/foundation/buffer';
|
|
32
36
|
import { pick } from '@aztec/foundation/collection';
|
|
33
37
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
34
38
|
import { TimeoutError } from '@aztec/foundation/error';
|
|
35
39
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
36
|
-
import { Signature
|
|
40
|
+
import { Signature } from '@aztec/foundation/eth-signature';
|
|
37
41
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
38
|
-
import {
|
|
42
|
+
import { InterruptibleSleep } from '@aztec/foundation/sleep';
|
|
39
43
|
import { bufferToHex } from '@aztec/foundation/string';
|
|
40
|
-
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
41
|
-
import { EmpireBaseAbi, ErrorsAbi, RollupAbi } from '@aztec/l1-artifacts';
|
|
44
|
+
import { type DateProvider, Timer } from '@aztec/foundation/timer';
|
|
45
|
+
import { EmpireBaseAbi, ErrorsAbi, RollupAbi, SlashingProposerAbi } from '@aztec/l1-artifacts';
|
|
42
46
|
import { type ProposerSlashAction, encodeSlashConsensusVotes } from '@aztec/slasher';
|
|
43
47
|
import { CommitteeAttestationsAndSigners, type ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
44
48
|
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
45
|
-
import {
|
|
46
|
-
import {
|
|
49
|
+
import type { SequencerConfig } from '@aztec/stdlib/config';
|
|
50
|
+
import {
|
|
51
|
+
getLastL1SlotTimestampForL2Slot,
|
|
52
|
+
getNextL1SlotTimestamp,
|
|
53
|
+
getTimestampForSlot,
|
|
54
|
+
} from '@aztec/stdlib/epoch-helpers';
|
|
47
55
|
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
48
56
|
import type { L1PublishCheckpointStats } from '@aztec/stdlib/stats';
|
|
49
57
|
import { type TelemetryClient, type Tracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
50
58
|
|
|
51
59
|
import {
|
|
60
|
+
type Abi,
|
|
52
61
|
type Hex,
|
|
53
|
-
type StateOverride,
|
|
54
62
|
type TransactionReceipt,
|
|
55
63
|
type TypedDataDefinition,
|
|
56
64
|
encodeFunctionData,
|
|
57
65
|
keccak256,
|
|
58
|
-
multicall3Abi,
|
|
59
66
|
toHex,
|
|
60
67
|
} from 'viem';
|
|
61
68
|
|
|
62
69
|
import type { SequencerPublisherConfig } from './config.js';
|
|
63
70
|
import { type FailedL1Tx, type L1TxFailedStore, createL1TxFailedStore } from './l1_tx_failed_store/index.js';
|
|
71
|
+
import { type DroppedRequest, SequencerBundleSimulator } from './sequencer-bundle-simulator.js';
|
|
64
72
|
import { SequencerPublisherMetrics } from './sequencer-publisher-metrics.js';
|
|
65
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Returns true if the receipt indicates a successful send AND the expected event was emitted
|
|
76
|
+
* by the target contract. Both pieces are required: an aggregate3 entry that reverted will
|
|
77
|
+
* have receipt.status === 'success' but no event log.
|
|
78
|
+
*/
|
|
79
|
+
function extractEventSuccess(
|
|
80
|
+
receipt: TransactionReceipt | undefined,
|
|
81
|
+
opts: { address: string; abi: Abi; eventName: string },
|
|
82
|
+
): boolean {
|
|
83
|
+
if (!receipt || receipt.status !== 'success') {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
return !!tryExtractEvent(receipt.logs, opts.address.toString() as Hex, opts.abi, opts.eventName);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Result of a sendRequests call, returned by both sendRequests() and sendRequestsAt(). */
|
|
90
|
+
export type SendRequestsResult = {
|
|
91
|
+
/** The L1 transaction receipt from the bundled multicall. */
|
|
92
|
+
result: { receipt: TransactionReceipt };
|
|
93
|
+
/** Actions that expired (past their deadline) before the request was sent. */
|
|
94
|
+
expiredActions: Action[];
|
|
95
|
+
/** Actions that were included in the sent L1 transaction. */
|
|
96
|
+
sentActions: Action[];
|
|
97
|
+
/** Actions whose L1 simulation succeeded (subset of sentActions). */
|
|
98
|
+
successfulActions: Action[];
|
|
99
|
+
/** Actions whose L1 simulation failed (subset of sentActions). */
|
|
100
|
+
failedActions: Action[];
|
|
101
|
+
};
|
|
102
|
+
|
|
66
103
|
/** Arguments to the process method of the rollup contract */
|
|
67
104
|
type L1ProcessArgs = {
|
|
68
105
|
/** The L2 block header. */
|
|
@@ -82,18 +119,16 @@ type L1ProcessArgs = {
|
|
|
82
119
|
export const Actions = [
|
|
83
120
|
'invalidate-by-invalid-attestation',
|
|
84
121
|
'invalidate-by-insufficient-attestations',
|
|
122
|
+
'prune',
|
|
85
123
|
'propose',
|
|
86
124
|
'governance-signal',
|
|
87
|
-
'empire-slashing-signal',
|
|
88
|
-
'create-empire-payload',
|
|
89
|
-
'execute-empire-payload',
|
|
90
125
|
'vote-offenses',
|
|
91
126
|
'execute-slash',
|
|
92
127
|
] as const;
|
|
93
128
|
|
|
94
129
|
export type Action = (typeof Actions)[number];
|
|
95
130
|
|
|
96
|
-
type GovernanceSignalAction = Extract<Action, 'governance-signal'
|
|
131
|
+
type GovernanceSignalAction = Extract<Action, 'governance-signal'>;
|
|
97
132
|
|
|
98
133
|
// Sorting for actions such that invalidations go before proposals, and proposals go before votes
|
|
99
134
|
export const compareActions = (a: Action, b: Action) => Actions.indexOf(a) - Actions.indexOf(b);
|
|
@@ -104,14 +139,22 @@ export type InvalidateCheckpointRequest = {
|
|
|
104
139
|
gasUsed: bigint;
|
|
105
140
|
checkpointNumber: CheckpointNumber;
|
|
106
141
|
forcePendingCheckpointNumber: CheckpointNumber;
|
|
142
|
+
/** Archive at the rollback target checkpoint (checkpoint N-1). */
|
|
143
|
+
lastArchive: Fr;
|
|
107
144
|
};
|
|
108
145
|
|
|
109
|
-
|
|
146
|
+
type EnqueueProposeCheckpointOpts = {
|
|
147
|
+
txTimeoutAt?: Date;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export interface RequestWithExpiry {
|
|
110
151
|
action: Action;
|
|
111
152
|
request: L1TxRequest;
|
|
112
153
|
lastValidL2Slot: SlotNumber;
|
|
113
154
|
gasConfig?: Pick<L1TxConfig, 'txTimeoutAt' | 'gasLimit'>;
|
|
114
155
|
blobConfig?: L1BlobInputs;
|
|
156
|
+
/** Gas consumed by validateBlobs; stashed for the bundle simulate at send time. */
|
|
157
|
+
blobEvaluationGas?: bigint;
|
|
115
158
|
checkSuccess: (
|
|
116
159
|
request: L1TxRequest,
|
|
117
160
|
result?: { receipt: TransactionReceipt; stats?: TransactionStats; errorMsg?: string },
|
|
@@ -121,26 +164,29 @@ interface RequestWithExpiry {
|
|
|
121
164
|
export class SequencerPublisher {
|
|
122
165
|
private interrupted = false;
|
|
123
166
|
private metrics: SequencerPublisherMetrics;
|
|
167
|
+
private bundleSimulator: SequencerBundleSimulator;
|
|
124
168
|
public epochCache: EpochCache;
|
|
125
169
|
private failedTxStore?: Promise<L1TxFailedStore | undefined>;
|
|
126
170
|
|
|
127
|
-
|
|
128
|
-
|
|
171
|
+
/**
|
|
172
|
+
* ABI used to decode raw revert payloads from dropped bundle entries when the original
|
|
173
|
+
* request did not carry an abi (e.g. the propose request). Merges every contract the
|
|
174
|
+
* publisher can route to so any of their custom errors decode against it.
|
|
175
|
+
*/
|
|
176
|
+
private readonly revertDecoderAbi: Abi = mergeAbis([RollupAbi, SlashingProposerAbi, EmpireBaseAbi, ErrorsAbi]);
|
|
129
177
|
|
|
130
178
|
protected lastActions: Partial<Record<Action, SlotNumber>> = {};
|
|
131
179
|
|
|
132
|
-
private isPayloadEmptyCache: Map<string, boolean> = new Map<string, boolean>();
|
|
133
|
-
private payloadProposedCache: Set<string> = new Set<string>();
|
|
134
|
-
|
|
135
180
|
protected log: Logger;
|
|
136
181
|
protected ethereumSlotDuration: bigint;
|
|
137
182
|
protected aztecSlotDuration: bigint;
|
|
138
|
-
private
|
|
183
|
+
private readonly previousL1BlockWaitTimeoutMs: number;
|
|
184
|
+
private readonly previousL1BlockWaitPollIntervalMs: number;
|
|
139
185
|
|
|
140
|
-
|
|
186
|
+
/** Date provider for wall-clock time. */
|
|
187
|
+
private readonly dateProvider: DateProvider;
|
|
141
188
|
|
|
142
|
-
|
|
143
|
-
private proposerAddressForSimulation?: EthAddress;
|
|
189
|
+
private blobClient: BlobClientInterface;
|
|
144
190
|
|
|
145
191
|
/** Optional callback to obtain a replacement publisher when the current one fails to send. */
|
|
146
192
|
private getNextPublisher?: (excludeAddresses: EthAddress[]) => Promise<L1TxUtils | undefined>;
|
|
@@ -151,33 +197,35 @@ export class SequencerPublisher {
|
|
|
151
197
|
/** Fee asset price oracle for computing price modifiers from Uniswap V4 */
|
|
152
198
|
private feeAssetPriceOracle: FeeAssetPriceOracle;
|
|
153
199
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
// Gas report for VotingWithSigTest shows a max gas of 100k, but we've seen it cost 700k+ in testnet
|
|
158
|
-
public static VOTE_GAS_GUESS: bigint = 800_000n;
|
|
200
|
+
/** Interruptible sleep used by sendRequestsAt to wait until a target timestamp. */
|
|
201
|
+
private readonly interruptibleSleep = new InterruptibleSleep();
|
|
159
202
|
|
|
160
203
|
public l1TxUtils: L1TxUtils;
|
|
161
204
|
public rollupContract: RollupContract;
|
|
162
205
|
public govProposerContract: GovernanceProposerContract;
|
|
163
|
-
public slashingProposerContract:
|
|
164
|
-
public slashFactoryContract: SlashFactoryContract;
|
|
206
|
+
public slashingProposerContract: SlashingProposerContract | undefined;
|
|
165
207
|
|
|
166
208
|
public readonly tracer: Tracer;
|
|
167
209
|
|
|
168
210
|
protected requests: RequestWithExpiry[] = [];
|
|
169
211
|
|
|
170
212
|
constructor(
|
|
171
|
-
private config: Pick<
|
|
213
|
+
private config: Pick<
|
|
214
|
+
SequencerPublisherConfig,
|
|
215
|
+
| 'fishermanMode'
|
|
216
|
+
| 'l1TxFailedStore'
|
|
217
|
+
| 'sequencerPublisherPreviousL1BlockWaitTimeoutMs'
|
|
218
|
+
| 'sequencerPublisherPreviousL1BlockWaitPollIntervalMs'
|
|
219
|
+
> &
|
|
220
|
+
Pick<SequencerConfig, 'governanceProposerForcePayloadVote'> &
|
|
172
221
|
Pick<L1ContractsConfig, 'ethereumSlotDuration' | 'aztecSlotDuration'> & { l1ChainId: number },
|
|
173
222
|
deps: {
|
|
174
223
|
telemetry?: TelemetryClient;
|
|
175
224
|
blobClient: BlobClientInterface;
|
|
176
225
|
l1TxUtils: L1TxUtils;
|
|
177
226
|
rollupContract: RollupContract;
|
|
178
|
-
slashingProposerContract:
|
|
227
|
+
slashingProposerContract: SlashingProposerContract | undefined;
|
|
179
228
|
governanceProposerContract: GovernanceProposerContract;
|
|
180
|
-
slashFactoryContract: SlashFactoryContract;
|
|
181
229
|
epochCache: EpochCache;
|
|
182
230
|
dateProvider: DateProvider;
|
|
183
231
|
metrics: SequencerPublisherMetrics;
|
|
@@ -189,11 +237,14 @@ export class SequencerPublisher {
|
|
|
189
237
|
this.log = deps.log ?? createLogger('sequencer:publisher');
|
|
190
238
|
this.ethereumSlotDuration = BigInt(config.ethereumSlotDuration);
|
|
191
239
|
this.aztecSlotDuration = BigInt(config.aztecSlotDuration);
|
|
240
|
+
this.previousL1BlockWaitTimeoutMs = config.sequencerPublisherPreviousL1BlockWaitTimeoutMs;
|
|
241
|
+
this.previousL1BlockWaitPollIntervalMs = config.sequencerPublisherPreviousL1BlockWaitPollIntervalMs;
|
|
192
242
|
this.dateProvider = deps.dateProvider;
|
|
193
243
|
this.epochCache = deps.epochCache;
|
|
194
244
|
this.lastActions = deps.lastActions;
|
|
195
245
|
|
|
196
246
|
this.blobClient = deps.blobClient;
|
|
247
|
+
this.dateProvider = deps.dateProvider;
|
|
197
248
|
|
|
198
249
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
199
250
|
this.metrics = deps.metrics ?? new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
|
|
@@ -211,14 +262,12 @@ export class SequencerPublisher {
|
|
|
211
262
|
const newSlashingProposer = await this.rollupContract.getSlashingProposer();
|
|
212
263
|
this.slashingProposerContract = newSlashingProposer;
|
|
213
264
|
});
|
|
214
|
-
this.slashFactoryContract = deps.slashFactoryContract;
|
|
215
|
-
|
|
216
265
|
// Initialize L1 fee analyzer for fisherman mode
|
|
217
266
|
if (config.fishermanMode) {
|
|
218
267
|
this.l1FeeAnalyzer = new L1FeeAnalyzer(
|
|
219
268
|
this.l1TxUtils.client,
|
|
220
269
|
deps.dateProvider,
|
|
221
|
-
|
|
270
|
+
this.log.createChild('fee-analyzer'),
|
|
222
271
|
);
|
|
223
272
|
}
|
|
224
273
|
|
|
@@ -226,11 +275,18 @@ export class SequencerPublisher {
|
|
|
226
275
|
this.feeAssetPriceOracle = new FeeAssetPriceOracle(
|
|
227
276
|
this.l1TxUtils.client,
|
|
228
277
|
this.rollupContract,
|
|
229
|
-
|
|
278
|
+
this.log.createChild('price-oracle'),
|
|
230
279
|
);
|
|
231
280
|
|
|
232
281
|
// Initialize failed L1 tx store (optional, for test networks)
|
|
233
282
|
this.failedTxStore = createL1TxFailedStore(config.l1TxFailedStore, this.log);
|
|
283
|
+
|
|
284
|
+
this.bundleSimulator = new SequencerBundleSimulator({
|
|
285
|
+
getL1TxUtils: () => this.l1TxUtils,
|
|
286
|
+
rollupContract: this.rollupContract,
|
|
287
|
+
epochCache: this.epochCache,
|
|
288
|
+
log: this.log.createChild('bundle-simulator'),
|
|
289
|
+
});
|
|
234
290
|
}
|
|
235
291
|
|
|
236
292
|
/**
|
|
@@ -261,10 +317,14 @@ export class SequencerPublisher {
|
|
|
261
317
|
|
|
262
318
|
/**
|
|
263
319
|
* Gets the fee asset price modifier from the oracle.
|
|
264
|
-
*
|
|
320
|
+
*
|
|
321
|
+
* @param predictedParentEthPerFeeAssetE12 - Optional predicted parent eth-per-fee-asset (E12).
|
|
322
|
+
* Pipelined proposers should pass the value from the predicted parent fee header so the
|
|
323
|
+
* modifier matches the parent L1 will use when applying it.
|
|
324
|
+
* @returns The fee asset price modifier in basis points, or 0n if the oracle query fails.
|
|
265
325
|
*/
|
|
266
|
-
public getFeeAssetPriceModifier(): Promise<bigint> {
|
|
267
|
-
return this.feeAssetPriceOracle.computePriceModifier();
|
|
326
|
+
public getFeeAssetPriceModifier(predictedParentEthPerFeeAssetE12?: bigint): Promise<bigint> {
|
|
327
|
+
return this.feeAssetPriceOracle.computePriceModifier(predictedParentEthPerFeeAssetE12);
|
|
268
328
|
}
|
|
269
329
|
|
|
270
330
|
public getSenderAddress() {
|
|
@@ -278,14 +338,6 @@ export class SequencerPublisher {
|
|
|
278
338
|
return this.l1FeeAnalyzer;
|
|
279
339
|
}
|
|
280
340
|
|
|
281
|
-
/**
|
|
282
|
-
* Sets the proposer address to use for simulations in fisherman mode.
|
|
283
|
-
* @param proposerAddress - The actual proposer's address to use for balance lookups in simulations
|
|
284
|
-
*/
|
|
285
|
-
public setProposerAddressForSimulation(proposerAddress: EthAddress | undefined) {
|
|
286
|
-
this.proposerAddressForSimulation = proposerAddress;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
341
|
public addRequest(request: RequestWithExpiry) {
|
|
290
342
|
this.requests.push(request);
|
|
291
343
|
}
|
|
@@ -363,22 +415,26 @@ export class SequencerPublisher {
|
|
|
363
415
|
|
|
364
416
|
/**
|
|
365
417
|
* Sends all requests that are still valid.
|
|
418
|
+
* @param targetSlot - The target L2 slot for this send. When provided (the production path, via
|
|
419
|
+
* sendRequestsAt), it is threaded into bundleSimulate so the block.timestamp override matches
|
|
420
|
+
* the slot the propose is built for. When omitted, falls back to getCurrentL2Slot() for the
|
|
421
|
+
* AutomineSequencer, which publishes synchronously within the current slot.
|
|
366
422
|
* @returns one of:
|
|
367
423
|
* - A receipt and stats if the tx succeeded
|
|
368
424
|
* - a receipt and errorMsg if it failed on L1
|
|
369
425
|
* - undefined if no valid requests are found OR the tx failed to send.
|
|
370
426
|
*/
|
|
371
427
|
@trackSpan('SequencerPublisher.sendRequests')
|
|
372
|
-
public async sendRequests() {
|
|
428
|
+
public async sendRequests(targetSlot?: SlotNumber): Promise<SendRequestsResult | undefined> {
|
|
373
429
|
const requestsToProcess = [...this.requests];
|
|
374
430
|
this.requests = [];
|
|
431
|
+
|
|
375
432
|
if (this.interrupted || requestsToProcess.length === 0) {
|
|
376
433
|
return undefined;
|
|
377
434
|
}
|
|
378
|
-
const currentL2Slot = this.getCurrentL2Slot();
|
|
435
|
+
const currentL2Slot = targetSlot ?? this.getCurrentL2Slot();
|
|
379
436
|
this.log.debug(`Sending requests on L2 slot ${currentL2Slot}`);
|
|
380
437
|
const validRequests = requestsToProcess.filter(request => request.lastValidL2Slot >= currentL2Slot);
|
|
381
|
-
const validActions = validRequests.map(x => x.action);
|
|
382
438
|
const expiredActions = requestsToProcess
|
|
383
439
|
.filter(request => request.lastValidL2Slot < currentL2Slot)
|
|
384
440
|
.map(x => x.action);
|
|
@@ -401,70 +457,60 @@ export class SequencerPublisher {
|
|
|
401
457
|
return undefined;
|
|
402
458
|
}
|
|
403
459
|
|
|
404
|
-
//
|
|
405
|
-
// find requests with gas and blob configs
|
|
406
|
-
// See https://github.com/AztecProtocol/aztec-packages/issues/11513
|
|
460
|
+
// Collect earliest txTimeoutAt across all requests.
|
|
407
461
|
const gasConfigs = validRequests.filter(request => request.gasConfig).map(request => request.gasConfig);
|
|
408
|
-
const blobConfigs = validRequests.filter(request => request.blobConfig).map(request => request.blobConfig);
|
|
409
|
-
|
|
410
|
-
if (blobConfigs.length > 1) {
|
|
411
|
-
throw new Error('Multiple blob configs found');
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
const blobConfig = blobConfigs[0];
|
|
415
|
-
|
|
416
|
-
// Merge gasConfigs. Yields the sum of gasLimits, and the earliest txTimeoutAt, or undefined if no gasConfig sets them.
|
|
417
|
-
const gasLimits = gasConfigs.map(g => g?.gasLimit).filter((g): g is bigint => g !== undefined);
|
|
418
|
-
let gasLimit = gasLimits.length > 0 ? sumBigint(gasLimits) : undefined; // sum
|
|
419
|
-
// Cap at L1 block gas limit so the node accepts the tx ("gas limit too high" otherwise).
|
|
420
|
-
const maxGas = MAX_L1_TX_LIMIT;
|
|
421
|
-
if (gasLimit !== undefined && gasLimit > maxGas) {
|
|
422
|
-
this.log.debug('Capping bundled tx gas limit to L1 max', {
|
|
423
|
-
requested: gasLimit,
|
|
424
|
-
capped: maxGas,
|
|
425
|
-
});
|
|
426
|
-
gasLimit = maxGas;
|
|
427
|
-
}
|
|
428
462
|
const txTimeoutAts = gasConfigs.map(g => g?.txTimeoutAt).filter((g): g is Date => g !== undefined);
|
|
429
|
-
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map(g => g.getTime()))) : undefined;
|
|
430
|
-
const txConfig: RequestWithExpiry['gasConfig'] = { gasLimit, txTimeoutAt };
|
|
463
|
+
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map(g => g.getTime()))) : undefined;
|
|
431
464
|
|
|
432
465
|
// Sort the requests so that proposals always go first
|
|
433
466
|
// This ensures the committee gets precomputed correctly
|
|
434
467
|
validRequests.sort((a, b) => compareActions(a.action, b.action));
|
|
435
468
|
|
|
436
469
|
try {
|
|
437
|
-
//
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
})),
|
|
448
|
-
],
|
|
449
|
-
});
|
|
450
|
-
const blobDataHex = blobConfig?.blobs?.map(b => toHex(b)) as Hex[] | undefined;
|
|
470
|
+
// Bundle-level eth_simulateV1: filters out entries that revert and derives the gasLimit.
|
|
471
|
+
const bundleResult = await this.bundleSimulator.simulate(validRequests, currentL2Slot);
|
|
472
|
+
|
|
473
|
+
if (bundleResult.kind === 'aborted') {
|
|
474
|
+
this.logDroppedInSim(bundleResult.droppedRequests);
|
|
475
|
+
void this.backupDroppedInSim(bundleResult.droppedRequests).catch(err =>
|
|
476
|
+
this.log.error(`Failed to backup requests dropped in simulation`, err),
|
|
477
|
+
);
|
|
478
|
+
return undefined;
|
|
479
|
+
}
|
|
451
480
|
|
|
452
|
-
const
|
|
481
|
+
const { requests, droppedRequests, gasLimit } =
|
|
482
|
+
bundleResult.kind === 'fallback'
|
|
483
|
+
? {
|
|
484
|
+
requests: bundleResult.requests,
|
|
485
|
+
droppedRequests: bundleResult.droppedRequests,
|
|
486
|
+
gasLimit: MAX_L1_TX_LIMIT,
|
|
487
|
+
}
|
|
488
|
+
: bundleResult;
|
|
489
|
+
|
|
490
|
+
this.logDroppedInSim(droppedRequests);
|
|
491
|
+
|
|
492
|
+
// Compute blobConfig from survivors (not original validRequests) so that if the propose
|
|
493
|
+
// entry was dropped by bundleSimulate we don't attach a blob-typed config to a non-blob tx.
|
|
494
|
+
const [blobConfig] = requests.filter(r => r.blobConfig).map(r => r.blobConfig);
|
|
495
|
+
const txConfig: RequestWithExpiry['gasConfig'] = { gasLimit, txTimeoutAt };
|
|
453
496
|
|
|
454
497
|
this.log.debug('Forwarding transactions', {
|
|
455
|
-
|
|
498
|
+
requests: requests.map(request => request.action),
|
|
456
499
|
txConfig,
|
|
457
500
|
});
|
|
458
|
-
const result = await this.forwardWithPublisherRotation(
|
|
501
|
+
const result = await this.forwardWithPublisherRotation(requests, txConfig, blobConfig);
|
|
459
502
|
if (result === undefined) {
|
|
460
503
|
return undefined;
|
|
461
504
|
}
|
|
462
|
-
const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(
|
|
463
|
-
|
|
505
|
+
const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(requests, result);
|
|
506
|
+
const allFailedActions = [...failedActions, ...droppedRequests.map(d => d.request.action)];
|
|
507
|
+
return {
|
|
464
508
|
result,
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
509
|
+
expiredActions,
|
|
510
|
+
sentActions: requests.map(x => x.action),
|
|
511
|
+
successfulActions,
|
|
512
|
+
failedActions: allFailedActions,
|
|
513
|
+
};
|
|
468
514
|
} catch (err) {
|
|
469
515
|
const viemError = formatViemError(err);
|
|
470
516
|
this.log.error(`Failed to publish bundled transactions`, viemError);
|
|
@@ -481,6 +527,40 @@ export class SequencerPublisher {
|
|
|
481
527
|
}
|
|
482
528
|
}
|
|
483
529
|
|
|
530
|
+
/** Logs entries dropped by bundle simulation as warnings on the publisher's logger. */
|
|
531
|
+
private logDroppedInSim(dropped: DroppedRequest[]): void {
|
|
532
|
+
for (const drop of dropped) {
|
|
533
|
+
const revertReasonDecoded = drop.revertReason ?? tryDecodeRevertReason(drop.returnData, this.revertDecoderAbi);
|
|
534
|
+
this.log.warn('Bundle entry dropped: action reverted in sim', {
|
|
535
|
+
action: drop.request.action,
|
|
536
|
+
revertReason: revertReasonDecoded ?? drop.returnData,
|
|
537
|
+
revertReasonDecoded,
|
|
538
|
+
returnData: drop.returnData,
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/** Backs up entries dropped by bundle simulation, one record per dropped action. */
|
|
544
|
+
private async backupDroppedInSim(dropped: DroppedRequest[]): Promise<void> {
|
|
545
|
+
if (dropped.length === 0) {
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
549
|
+
for (const { request: req } of dropped) {
|
|
550
|
+
this.backupFailedTx({
|
|
551
|
+
id: keccak256(req.request.data!),
|
|
552
|
+
failureType: 'simulation',
|
|
553
|
+
request: { to: req.request.to! as Hex, data: req.request.data! },
|
|
554
|
+
l1BlockNumber: l1BlockNumber.toString(),
|
|
555
|
+
error: { message: 'Bundle entry dropped: action reverted in sim' },
|
|
556
|
+
context: {
|
|
557
|
+
actions: [req.action],
|
|
558
|
+
sender: this.getSenderAddress().toString(),
|
|
559
|
+
},
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
484
564
|
/**
|
|
485
565
|
* Forwards transactions via Multicall3, rotating to the next available publisher if a send
|
|
486
566
|
* failure occurs (i.e. the tx never reached the chain).
|
|
@@ -491,19 +571,30 @@ export class SequencerPublisher {
|
|
|
491
571
|
txConfig: RequestWithExpiry['gasConfig'],
|
|
492
572
|
blobConfig: L1BlobInputs | undefined,
|
|
493
573
|
) {
|
|
574
|
+
if (!txConfig?.gasLimit) {
|
|
575
|
+
throw new Error('gasLimit is required for bundled transactions');
|
|
576
|
+
}
|
|
577
|
+
const txConfigWithGasLimit = txConfig as L1TxConfig & { gasLimit: bigint };
|
|
578
|
+
|
|
494
579
|
const triedAddresses: EthAddress[] = [];
|
|
495
580
|
let currentPublisher = this.l1TxUtils;
|
|
496
581
|
|
|
497
582
|
while (true) {
|
|
583
|
+
if (txConfig.txTimeoutAt && new Date() > txConfig.txTimeoutAt) {
|
|
584
|
+
this.log.warn(`Tx timeout (${txConfig.txTimeoutAt.toISOString()}) elapsed; stopping publisher rotation`, {
|
|
585
|
+
triedAddresses: triedAddresses.map(a => a.toString()),
|
|
586
|
+
});
|
|
587
|
+
return undefined;
|
|
588
|
+
}
|
|
498
589
|
triedAddresses.push(currentPublisher.getSenderAddress());
|
|
590
|
+
|
|
499
591
|
try {
|
|
500
592
|
const result = await Multicall3.forward(
|
|
501
593
|
validRequests.map(r => r.request),
|
|
502
594
|
currentPublisher,
|
|
503
|
-
|
|
595
|
+
txConfigWithGasLimit,
|
|
504
596
|
blobConfig,
|
|
505
|
-
|
|
506
|
-
this.log,
|
|
597
|
+
{ gasLimitRequired: true },
|
|
507
598
|
);
|
|
508
599
|
this.l1TxUtils = currentPublisher;
|
|
509
600
|
return result;
|
|
@@ -511,6 +602,12 @@ export class SequencerPublisher {
|
|
|
511
602
|
if (err instanceof TimeoutError) {
|
|
512
603
|
throw err;
|
|
513
604
|
}
|
|
605
|
+
if (err instanceof MulticallForwarderRevertedError) {
|
|
606
|
+
this.log.error('Forwarder transaction reverted on-chain; not rotating publisher', err, {
|
|
607
|
+
transactionHash: err.receipt.transactionHash,
|
|
608
|
+
});
|
|
609
|
+
return undefined;
|
|
610
|
+
}
|
|
514
611
|
const viemError = formatViemError(err);
|
|
515
612
|
if (!this.getNextPublisher) {
|
|
516
613
|
this.log.error('Failed to publish bundled transactions', viemError);
|
|
@@ -522,7 +619,11 @@ export class SequencerPublisher {
|
|
|
522
619
|
);
|
|
523
620
|
const nextPublisher = await this.getNextPublisher([...triedAddresses]);
|
|
524
621
|
if (!nextPublisher) {
|
|
525
|
-
this.log.error(
|
|
622
|
+
this.log.error(
|
|
623
|
+
`All available publishers exhausted (tried ${triedAddresses.length}), failed to publish bundled transactions`,
|
|
624
|
+
viemError,
|
|
625
|
+
{ triedAddresses: triedAddresses.map(a => a.toString()) },
|
|
626
|
+
);
|
|
526
627
|
return undefined;
|
|
527
628
|
}
|
|
528
629
|
currentPublisher = nextPublisher;
|
|
@@ -530,74 +631,98 @@ export class SequencerPublisher {
|
|
|
530
631
|
}
|
|
531
632
|
}
|
|
532
633
|
|
|
634
|
+
/*
|
|
635
|
+
* Schedules sending all enqueued requests at (or after) the start of the given L2 slot.
|
|
636
|
+
*/
|
|
637
|
+
public async sendRequestsAt(targetSlot: SlotNumber): Promise<SendRequestsResult | undefined> {
|
|
638
|
+
await this.waitForTargetSlot(targetSlot);
|
|
639
|
+
if (this.interrupted) {
|
|
640
|
+
return undefined;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
return this.sendRequests(targetSlot);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Sleeps until one L1 slot before the L2 slot boundary, and then waits for that L1 block
|
|
648
|
+
* to be mined, so we don't risk being included in it. If that block never gets mined after
|
|
649
|
+
* a timeout, we assume it got skipped on L1, so we send the tx anyway.
|
|
650
|
+
*/
|
|
651
|
+
private async waitForTargetSlot(targetSlot: SlotNumber): Promise<void> {
|
|
652
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
653
|
+
const nowInSeconds = this.dateProvider.nowInSeconds();
|
|
654
|
+
const startOfTargetSlotTs = getTimestampForSlot(targetSlot, l1Constants);
|
|
655
|
+
const previousL1BlockTs = startOfTargetSlotTs - this.ethereumSlotDuration;
|
|
656
|
+
const waitDeadlineTs = previousL1BlockTs + BigInt(this.previousL1BlockWaitTimeoutMs / 1000);
|
|
657
|
+
const logCtx = { targetSlot, startOfTargetSlotTs, nowInSeconds, previousL1BlockTs, waitDeadlineTs };
|
|
658
|
+
|
|
659
|
+
// Check if we are already past time
|
|
660
|
+
if (nowInSeconds >= startOfTargetSlotTs) {
|
|
661
|
+
this.log.verbose(`Target slot ${targetSlot} already started, sending requests immediately`, logCtx);
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// Otherwise we wait
|
|
666
|
+
this.log.debug(`Waiting for slot ${targetSlot} before sending requests`, logCtx);
|
|
667
|
+
|
|
668
|
+
// Wait until previous L1 block timestamp first
|
|
669
|
+
const sleepMs = (Number(previousL1BlockTs) - nowInSeconds) * 1000;
|
|
670
|
+
if (sleepMs > 0 && !this.interrupted) {
|
|
671
|
+
this.log.trace(`Sleeping ${sleepMs}ms before waiting for previous L1 block`, logCtx);
|
|
672
|
+
await this.interruptibleSleep.sleep(sleepMs);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// Then loop until we see the previous L1 block, so we know that we cannot be included in it.
|
|
676
|
+
// We time out after a while, once we are sure that that block is skipped in L1.
|
|
677
|
+
while (!this.interrupted) {
|
|
678
|
+
try {
|
|
679
|
+
const nowInSeconds = this.dateProvider.nowInSeconds();
|
|
680
|
+
logCtx.nowInSeconds = nowInSeconds;
|
|
681
|
+
|
|
682
|
+
if (nowInSeconds >= waitDeadlineTs) {
|
|
683
|
+
this.log.warn(`Timed out waiting for previous L1 block before sending requests, proceeding`, logCtx);
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
const latestBlockTs = await this.l1TxUtils.getBlock().then(b => b.timestamp);
|
|
688
|
+
if (latestBlockTs >= previousL1BlockTs) {
|
|
689
|
+
this.log.debug(`Previous L1 block mined, proceeding to send requests`, { ...logCtx, latestBlockTs });
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
this.log.trace(`Previous L1 block not mined yet, continuing to wait`, { ...logCtx, latestBlockTs });
|
|
693
|
+
} catch (err) {
|
|
694
|
+
this.log.error(`Error while waiting for previous L1 block before sending requests; retrying`, err, logCtx);
|
|
695
|
+
} finally {
|
|
696
|
+
await this.interruptibleSleep.sleep(this.previousL1BlockWaitPollIntervalMs);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
533
701
|
private callbackBundledTransactions(
|
|
534
702
|
requests: RequestWithExpiry[],
|
|
535
|
-
result: { receipt: TransactionReceipt;
|
|
536
|
-
txContext: { multicallData: Hex; blobData?: Hex[]; l1BlockNumber: bigint },
|
|
703
|
+
result: { receipt: TransactionReceipt; multicallData: Hex },
|
|
537
704
|
) {
|
|
538
705
|
const actionsListStr = requests.map(r => r.action).join(', ');
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
|
|
557
|
-
result,
|
|
558
|
-
requests: requests.map(r => ({
|
|
559
|
-
...r,
|
|
560
|
-
// Avoid logging large blob data
|
|
561
|
-
blobConfig: r.blobConfig
|
|
562
|
-
? { ...r.blobConfig, blobs: r.blobConfig.blobs.map(b => ({ size: trimmedBytesLength(b) })) }
|
|
563
|
-
: undefined,
|
|
564
|
-
})),
|
|
565
|
-
});
|
|
566
|
-
const successfulActions: Action[] = [];
|
|
567
|
-
const failedActions: Action[] = [];
|
|
568
|
-
for (const request of requests) {
|
|
569
|
-
if (request.checkSuccess(request.request, result)) {
|
|
570
|
-
successfulActions.push(request.action);
|
|
571
|
-
} else {
|
|
572
|
-
failedActions.push(request.action);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
// Single backup for the whole reverted tx
|
|
576
|
-
if (failedActions.length > 0 && result?.receipt?.status === 'reverted') {
|
|
577
|
-
this.backupFailedTx({
|
|
578
|
-
id: result.receipt.transactionHash,
|
|
579
|
-
failureType: 'revert',
|
|
580
|
-
request: { to: MULTI_CALL_3_ADDRESS, data: txContext.multicallData },
|
|
581
|
-
blobData: txContext.blobData,
|
|
582
|
-
l1BlockNumber: result.receipt.blockNumber.toString(),
|
|
583
|
-
receipt: {
|
|
584
|
-
transactionHash: result.receipt.transactionHash,
|
|
585
|
-
blockNumber: result.receipt.blockNumber.toString(),
|
|
586
|
-
gasUsed: (result.receipt.gasUsed ?? 0n).toString(),
|
|
587
|
-
status: 'reverted',
|
|
588
|
-
},
|
|
589
|
-
error: { message: result.errorMsg ?? 'Transaction reverted' },
|
|
590
|
-
context: {
|
|
591
|
-
actions: failedActions,
|
|
592
|
-
requests: requests
|
|
593
|
-
.filter(r => failedActions.includes(r.action))
|
|
594
|
-
.map(r => ({ action: r.action, to: r.request.to! as Hex, data: r.request.data! })),
|
|
595
|
-
sender: this.getSenderAddress().toString(),
|
|
596
|
-
},
|
|
597
|
-
});
|
|
706
|
+
this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
|
|
707
|
+
result,
|
|
708
|
+
requests: requests.map(r => ({
|
|
709
|
+
...r,
|
|
710
|
+
// Avoid logging large blob data
|
|
711
|
+
blobConfig: r.blobConfig
|
|
712
|
+
? { ...r.blobConfig, blobs: r.blobConfig.blobs.map(b => ({ size: trimmedBytesLength(b) })) }
|
|
713
|
+
: undefined,
|
|
714
|
+
})),
|
|
715
|
+
});
|
|
716
|
+
const successfulActions: Action[] = [];
|
|
717
|
+
const failedActions: Action[] = [];
|
|
718
|
+
for (const request of requests) {
|
|
719
|
+
if (request.checkSuccess(request.request, result)) {
|
|
720
|
+
successfulActions.push(request.action);
|
|
721
|
+
} else {
|
|
722
|
+
failedActions.push(request.action);
|
|
598
723
|
}
|
|
599
|
-
return { successfulActions, failedActions };
|
|
600
724
|
}
|
|
725
|
+
return { successfulActions, failedActions };
|
|
601
726
|
}
|
|
602
727
|
|
|
603
728
|
/**
|
|
@@ -605,25 +730,27 @@ export class SequencerPublisher {
|
|
|
605
730
|
* @param tipArchive - The archive to check
|
|
606
731
|
* @returns The slot and block number if it is possible to propose, undefined otherwise
|
|
607
732
|
*/
|
|
608
|
-
public canProposeAt(
|
|
609
|
-
tipArchive: Fr,
|
|
610
|
-
msgSender: EthAddress,
|
|
611
|
-
opts: { forcePendingCheckpointNumber?: CheckpointNumber; pipelined?: boolean } = {},
|
|
612
|
-
) {
|
|
733
|
+
public async canProposeAt(tipArchive: Fr, msgSender: EthAddress, simulationOverridesPlan?: SimulationOverridesPlan) {
|
|
613
734
|
// TODO: #14291 - should loop through multiple keys to check if any of them can propose
|
|
614
|
-
|
|
735
|
+
// These errors are expected when we cannot actually propose right now — usually because our
|
|
736
|
+
// local view of the chain is ahead of L1 (proposed parent hasn't landed yet, or someone
|
|
737
|
+
// else has just landed the slot, or the archive override doesn't match). We log a warn and
|
|
738
|
+
// skip the proposal; we do NOT treat these as bugs.
|
|
739
|
+
const expectedErrors = ['SlotAlreadyInChain', 'InvalidProposer', 'InvalidArchive'];
|
|
615
740
|
|
|
616
|
-
const
|
|
617
|
-
const slotOffset = pipelined ? this.aztecSlotDuration : 0n;
|
|
741
|
+
const slotOffset = this.aztecSlotDuration;
|
|
618
742
|
const nextL1SlotTs = this.getNextL1SlotTimestamp() + slotOffset;
|
|
619
743
|
|
|
620
744
|
return this.rollupContract
|
|
621
|
-
.canProposeAt(
|
|
622
|
-
|
|
623
|
-
|
|
745
|
+
.canProposeAt(
|
|
746
|
+
tipArchive.toBuffer(),
|
|
747
|
+
msgSender.toString(),
|
|
748
|
+
nextL1SlotTs,
|
|
749
|
+
await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan),
|
|
750
|
+
)
|
|
624
751
|
.catch(err => {
|
|
625
|
-
if (err instanceof FormattedViemError &&
|
|
626
|
-
this.log.warn(`Failed canProposeAtTime check with ${
|
|
752
|
+
if (err instanceof FormattedViemError && expectedErrors.find(e => err.message.includes(e))) {
|
|
753
|
+
this.log.warn(`Failed canProposeAtTime check with ${expectedErrors.find(e => err.message.includes(e))}`, {
|
|
627
754
|
error: err.message,
|
|
628
755
|
});
|
|
629
756
|
} else {
|
|
@@ -634,21 +761,21 @@ export class SequencerPublisher {
|
|
|
634
761
|
}
|
|
635
762
|
|
|
636
763
|
/**
|
|
637
|
-
* @notice Will simulate `
|
|
638
|
-
* @dev This is a convenience function that can be used by the sequencer to validate a "partial" header
|
|
639
|
-
* It will throw if the
|
|
640
|
-
* @param header - The
|
|
764
|
+
* @notice Will simulate the rollup's `validateHeaderWithAttestations` to make sure the checkpoint header is valid
|
|
765
|
+
* @dev This is a convenience function that can be used by the sequencer to validate a "partial" header,
|
|
766
|
+
* skipping the DA and signature checks. It will throw if the checkpoint header is invalid.
|
|
767
|
+
* @param header - The checkpoint header to validate
|
|
641
768
|
*/
|
|
642
|
-
@trackSpan('SequencerPublisher.
|
|
643
|
-
public async
|
|
769
|
+
@trackSpan('SequencerPublisher.validateCheckpointHeader')
|
|
770
|
+
public async validateCheckpointHeader(
|
|
644
771
|
header: CheckpointHeader,
|
|
645
|
-
|
|
772
|
+
simulationOverridesPlan?: SimulationOverridesPlan,
|
|
646
773
|
): Promise<void> {
|
|
647
774
|
const flags = { ignoreDA: true, ignoreSignatures: true };
|
|
648
775
|
|
|
649
776
|
const args = [
|
|
650
777
|
header.toViem(),
|
|
651
|
-
CommitteeAttestationsAndSigners.
|
|
778
|
+
CommitteeAttestationsAndSigners.packAttestations([]),
|
|
652
779
|
[], // no signers
|
|
653
780
|
Signature.empty().toViemSignature(),
|
|
654
781
|
`0x${'0'.repeat(64)}`, // 32 empty bytes
|
|
@@ -656,21 +783,13 @@ export class SequencerPublisher {
|
|
|
656
783
|
flags,
|
|
657
784
|
] as const;
|
|
658
785
|
|
|
659
|
-
const
|
|
660
|
-
const
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
let balance = 0n;
|
|
664
|
-
if (this.config.fishermanMode) {
|
|
665
|
-
// In fisherman mode, we can't know where the proposer is publishing from
|
|
666
|
-
// so we just add sufficient balance to the multicall3 address
|
|
667
|
-
balance = 10n * WEI_CONST * WEI_CONST; // 10 ETH
|
|
668
|
-
} else {
|
|
669
|
-
balance = await this.l1TxUtils.getSenderBalance();
|
|
670
|
-
}
|
|
786
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
787
|
+
const ts = getLastL1SlotTimestampForL2Slot(header.slotNumber, l1Constants);
|
|
788
|
+
const stateOverrides = await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan);
|
|
789
|
+
// Balance override for compatibility with providers that apply an upfront funds check to simulated calls.
|
|
671
790
|
stateOverrides.push({
|
|
672
791
|
address: MULTI_CALL_3_ADDRESS,
|
|
673
|
-
balance,
|
|
792
|
+
balance: 10n * WEI_CONST * WEI_CONST, // 10 ETH
|
|
674
793
|
});
|
|
675
794
|
|
|
676
795
|
await this.l1TxUtils.simulate(
|
|
@@ -679,7 +798,7 @@ export class SequencerPublisher {
|
|
|
679
798
|
data: encodeFunctionData({ abi: RollupAbi, functionName: 'validateHeaderWithAttestations', args }),
|
|
680
799
|
from: MULTI_CALL_3_ADDRESS,
|
|
681
800
|
},
|
|
682
|
-
{ time: ts
|
|
801
|
+
{ time: ts },
|
|
683
802
|
stateOverrides,
|
|
684
803
|
);
|
|
685
804
|
this.log.debug(`Simulated validateHeader`);
|
|
@@ -732,6 +851,7 @@ export class SequencerPublisher {
|
|
|
732
851
|
gasUsed,
|
|
733
852
|
checkpointNumber,
|
|
734
853
|
forcePendingCheckpointNumber: CheckpointNumber(checkpointNumber - 1),
|
|
854
|
+
lastArchive: validationResult.checkpoint.lastArchive,
|
|
735
855
|
reason,
|
|
736
856
|
};
|
|
737
857
|
} catch (err) {
|
|
@@ -744,8 +864,8 @@ export class SequencerPublisher {
|
|
|
744
864
|
`Simulation for invalidate checkpoint ${checkpointNumber} failed due to checkpoint not being in pending chain`,
|
|
745
865
|
{ ...logData, request, error: viemError.message },
|
|
746
866
|
);
|
|
747
|
-
const
|
|
748
|
-
if (
|
|
867
|
+
const latestProposedCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
868
|
+
if (latestProposedCheckpointNumber < checkpointNumber) {
|
|
749
869
|
this.log.verbose(`Checkpoint ${checkpointNumber} has already been invalidated`, { ...logData });
|
|
750
870
|
return undefined;
|
|
751
871
|
} else {
|
|
@@ -790,9 +910,11 @@ export class SequencerPublisher {
|
|
|
790
910
|
const logData = { ...checkpoint, reason };
|
|
791
911
|
this.log.debug(`Building invalidate checkpoint ${checkpoint.checkpointNumber} request`, logData);
|
|
792
912
|
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
)
|
|
913
|
+
// Use the exact packed tuple posted to L1 verbatim. A repack via `packAttestations` is not a
|
|
914
|
+
// byte-faithful inverse of `fromPacked` (a canonicalized yParity byte or an all-zero signature slot
|
|
915
|
+
// round-trips differently), so it would diverge from the stored `attestationsHash` and revert the
|
|
916
|
+
// invalidation.
|
|
917
|
+
const attestationsAndSigners = validationResult.verbatimAttestations;
|
|
796
918
|
|
|
797
919
|
if (reason === 'invalid-attestation') {
|
|
798
920
|
return this.rollupContract.buildInvalidateBadAttestationRequest(
|
|
@@ -813,45 +935,11 @@ export class SequencerPublisher {
|
|
|
813
935
|
}
|
|
814
936
|
}
|
|
815
937
|
|
|
816
|
-
/** Simulates `propose` to make sure that the checkpoint is valid for submission */
|
|
817
|
-
@trackSpan('SequencerPublisher.validateCheckpointForSubmission')
|
|
818
|
-
public async validateCheckpointForSubmission(
|
|
819
|
-
checkpoint: Checkpoint,
|
|
820
|
-
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
821
|
-
attestationsAndSignersSignature: Signature,
|
|
822
|
-
options: { forcePendingCheckpointNumber?: CheckpointNumber },
|
|
823
|
-
): Promise<bigint> {
|
|
824
|
-
// Anchor the simulation timestamp to the checkpoint's own slot start time
|
|
825
|
-
// rather than the current L1 block timestamp, which may overshoot into the next slot if the build ran late.
|
|
826
|
-
const ts = checkpoint.header.timestamp;
|
|
827
|
-
const blobFields = checkpoint.toBlobFields();
|
|
828
|
-
const blobs = await getBlobsPerL1Block(blobFields);
|
|
829
|
-
const blobInput = getPrefixedEthBlobCommitments(blobs);
|
|
830
|
-
|
|
831
|
-
const args = [
|
|
832
|
-
{
|
|
833
|
-
header: checkpoint.header.toViem(),
|
|
834
|
-
archive: toHex(checkpoint.archive.root.toBuffer()),
|
|
835
|
-
oracleInput: {
|
|
836
|
-
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier,
|
|
837
|
-
},
|
|
838
|
-
},
|
|
839
|
-
attestationsAndSigners.getPackedAttestations(),
|
|
840
|
-
attestationsAndSigners.getSigners().map(signer => signer.toString()),
|
|
841
|
-
attestationsAndSignersSignature.toViemSignature(),
|
|
842
|
-
blobInput,
|
|
843
|
-
] as const;
|
|
844
|
-
|
|
845
|
-
await this.simulateProposeTx(args, ts, options);
|
|
846
|
-
return ts;
|
|
847
|
-
}
|
|
848
|
-
|
|
849
938
|
private async enqueueCastSignalHelper(
|
|
850
939
|
slotNumber: SlotNumber,
|
|
851
|
-
timestamp: bigint,
|
|
852
940
|
signalType: GovernanceSignalAction,
|
|
853
941
|
payload: EthAddress,
|
|
854
|
-
base:
|
|
942
|
+
base: GovernanceProposerContract,
|
|
855
943
|
signerAddress: EthAddress,
|
|
856
944
|
signer: (msg: TypedDataDefinition) => Promise<`0x${string}`>,
|
|
857
945
|
): Promise<boolean> {
|
|
@@ -866,6 +954,19 @@ export class SequencerPublisher {
|
|
|
866
954
|
this.log.warn(`Cannot enqueue vote cast signal ${signalType} for address zero at slot ${slotNumber}`);
|
|
867
955
|
return false;
|
|
868
956
|
}
|
|
957
|
+
|
|
958
|
+
const canonicalRollup = await base.getRollupAddress();
|
|
959
|
+
if (!canonicalRollup.equals(EthAddress.fromString(this.rollupContract.address))) {
|
|
960
|
+
this.log.warn(`Rollup ${this.rollupContract.address} is not canonical, skipping governance signal`, {
|
|
961
|
+
slotNumber,
|
|
962
|
+
signalType,
|
|
963
|
+
canonicalRollup,
|
|
964
|
+
targetRollup: this.rollupContract.address,
|
|
965
|
+
payload: payload.toString(),
|
|
966
|
+
});
|
|
967
|
+
return false;
|
|
968
|
+
}
|
|
969
|
+
|
|
869
970
|
const round = await base.computeRound(slotNumber);
|
|
870
971
|
const roundInfo = await base.getRoundInfo(this.rollupContract.address, round);
|
|
871
972
|
|
|
@@ -877,34 +978,43 @@ export class SequencerPublisher {
|
|
|
877
978
|
return false;
|
|
878
979
|
}
|
|
879
980
|
|
|
880
|
-
if (await
|
|
981
|
+
if (await base.isPayloadEmpty(payload)) {
|
|
881
982
|
this.log.warn(`Skipping vote cast for payload with empty code`);
|
|
882
983
|
return false;
|
|
883
984
|
}
|
|
884
985
|
|
|
885
|
-
//
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
}
|
|
986
|
+
// Classify the payload against the Governance proposal history so we stop signalling once its
|
|
987
|
+
// proposal is live or was already executed, while still re-signalling one whose proposal was
|
|
988
|
+
// merely rejected/dropped/expired.
|
|
989
|
+
let status: PayloadProposalStatus = 'none';
|
|
990
|
+
try {
|
|
991
|
+
status = await base.getPayloadProposalStatus(payload.toString());
|
|
992
|
+
} catch (err) {
|
|
993
|
+
// We deliberately swallow the error and proceed to signal. Failing closed (skipping the
|
|
994
|
+
// signal) on transient RPC errors would let a flaky L1 endpoint silence governance
|
|
995
|
+
// participation entirely; failing open at worst produces a duplicate signal that the
|
|
996
|
+
// contract will simply count alongside others in the round.
|
|
997
|
+
this.log.error(`Failed to check governance proposal status for payload ${payload} (signalling anyway)`, err, {
|
|
998
|
+
slotNumber,
|
|
999
|
+
signalType,
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
if (status === 'live') {
|
|
1004
|
+
this.log.info(`Payload ${payload} has a live governance proposal, stopping signals`, {
|
|
1005
|
+
slotNumber,
|
|
1006
|
+
signalType,
|
|
1007
|
+
payload: payload.toString(),
|
|
1008
|
+
});
|
|
1009
|
+
return false;
|
|
904
1010
|
}
|
|
905
1011
|
|
|
906
|
-
if (this.
|
|
907
|
-
this.log.info(
|
|
1012
|
+
if (status === 'executed' && !this.config.governanceProposerForcePayloadVote) {
|
|
1013
|
+
this.log.info(
|
|
1014
|
+
`Payload ${payload} was executed by governance within lookback, stopping signals ` +
|
|
1015
|
+
`(set GOVERNANCE_PROPOSER_FORCE_PAYLOAD_VOTE to re-signal)`,
|
|
1016
|
+
{ slotNumber, signalType, payload: payload.toString() },
|
|
1017
|
+
);
|
|
908
1018
|
return false;
|
|
909
1019
|
}
|
|
910
1020
|
|
|
@@ -926,41 +1036,19 @@ export class SequencerPublisher {
|
|
|
926
1036
|
lastValidL2Slot: slotNumber,
|
|
927
1037
|
});
|
|
928
1038
|
|
|
929
|
-
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
930
|
-
|
|
931
|
-
try {
|
|
932
|
-
await this.l1TxUtils.simulate(request, { time: timestamp }, [], mergeAbis([request.abi ?? [], ErrorsAbi]));
|
|
933
|
-
this.log.debug(`Simulation for ${action} at slot ${slotNumber} succeeded`, { request });
|
|
934
|
-
} catch (err) {
|
|
935
|
-
const viemError = formatViemError(err);
|
|
936
|
-
this.log.error(`Failed simulation for ${action} at slot ${slotNumber} (enqueuing the action anyway)`, viemError);
|
|
937
|
-
this.backupFailedTx({
|
|
938
|
-
id: keccak256(request.data!),
|
|
939
|
-
failureType: 'simulation',
|
|
940
|
-
request: { to: request.to!, data: request.data!, value: request.value?.toString() },
|
|
941
|
-
l1BlockNumber: l1BlockNumber.toString(),
|
|
942
|
-
error: { message: viemError.message, name: viemError.name },
|
|
943
|
-
context: {
|
|
944
|
-
actions: [action],
|
|
945
|
-
slot: slotNumber,
|
|
946
|
-
sender: this.getSenderAddress().toString(),
|
|
947
|
-
},
|
|
948
|
-
});
|
|
949
|
-
// Yes, we enqueue the request anyway, in case there was a bug with the simulation itself
|
|
950
|
-
}
|
|
951
|
-
|
|
952
1039
|
// TODO(palla/slash): All votes (governance and slashing) should txTimeoutAt at the end of the slot.
|
|
953
1040
|
this.addRequest({
|
|
954
|
-
gasConfig: { gasLimit: SequencerPublisher.VOTE_GAS_GUESS },
|
|
955
1041
|
action,
|
|
956
1042
|
request,
|
|
957
1043
|
lastValidL2Slot: slotNumber,
|
|
958
1044
|
checkSuccess: (_request, result) => {
|
|
959
1045
|
const success =
|
|
960
1046
|
result &&
|
|
961
|
-
result.receipt
|
|
962
|
-
|
|
963
|
-
|
|
1047
|
+
extractEventSuccess(result.receipt, {
|
|
1048
|
+
address: base.address.toString(),
|
|
1049
|
+
abi: EmpireBaseAbi,
|
|
1050
|
+
eventName: 'SignalCast',
|
|
1051
|
+
});
|
|
964
1052
|
|
|
965
1053
|
const logData = { ...result, slotNumber, round, payload: payload.toString() };
|
|
966
1054
|
if (!success) {
|
|
@@ -982,33 +1070,19 @@ export class SequencerPublisher {
|
|
|
982
1070
|
return true;
|
|
983
1071
|
}
|
|
984
1072
|
|
|
985
|
-
private async isPayloadEmpty(payload: EthAddress): Promise<boolean> {
|
|
986
|
-
const key = payload.toString();
|
|
987
|
-
const cached = this.isPayloadEmptyCache.get(key);
|
|
988
|
-
if (cached) {
|
|
989
|
-
return cached;
|
|
990
|
-
}
|
|
991
|
-
const isEmpty = !(await this.l1TxUtils.getCode(payload));
|
|
992
|
-
this.isPayloadEmptyCache.set(key, isEmpty);
|
|
993
|
-
return isEmpty;
|
|
994
|
-
}
|
|
995
|
-
|
|
996
1073
|
/**
|
|
997
1074
|
* Enqueues a governance castSignal transaction to cast a signal for a given slot number.
|
|
998
1075
|
* @param slotNumber - The slot number to cast a signal for.
|
|
999
|
-
* @param timestamp - The timestamp of the slot to cast a signal for.
|
|
1000
1076
|
* @returns True if the signal was successfully enqueued, false otherwise.
|
|
1001
1077
|
*/
|
|
1002
1078
|
public enqueueGovernanceCastSignal(
|
|
1003
1079
|
governancePayload: EthAddress,
|
|
1004
1080
|
slotNumber: SlotNumber,
|
|
1005
|
-
timestamp: bigint,
|
|
1006
1081
|
signerAddress: EthAddress,
|
|
1007
1082
|
signer: (msg: TypedDataDefinition) => Promise<`0x${string}`>,
|
|
1008
1083
|
): Promise<boolean> {
|
|
1009
1084
|
return this.enqueueCastSignalHelper(
|
|
1010
1085
|
slotNumber,
|
|
1011
|
-
timestamp,
|
|
1012
1086
|
'governance-signal',
|
|
1013
1087
|
governancePayload,
|
|
1014
1088
|
this.govProposerContract,
|
|
@@ -1017,11 +1091,51 @@ export class SequencerPublisher {
|
|
|
1017
1091
|
);
|
|
1018
1092
|
}
|
|
1019
1093
|
|
|
1094
|
+
/**
|
|
1095
|
+
* Enqueues a `prune()` transaction if the rollup is prunable at the given slot's L1 timestamp.
|
|
1096
|
+
* `prune()` is permissionless and idempotent — if the chain is no longer prunable by send time the
|
|
1097
|
+
* bundle simulation usually drops the entry; on a node without `eth_simulateV1` the bundle is sent
|
|
1098
|
+
* as-is and the prune reverts `Rollup__NothingToPrune` inside `aggregate3(allowFailure: true)`
|
|
1099
|
+
* (a failed action, never a whole-tx revert). Used by the failed-sync fallback so a stuck pending
|
|
1100
|
+
* chain (e.g. bad data blocking sync) can be wound back to recover.
|
|
1101
|
+
* @returns true if a prune request was enqueued, false otherwise.
|
|
1102
|
+
*/
|
|
1103
|
+
public async enqueuePruneIfPrunable(slotNumber: SlotNumber): Promise<boolean> {
|
|
1104
|
+
if (this.lastActions['prune'] === slotNumber) {
|
|
1105
|
+
this.log.debug(`Skipping duplicate prune for slot ${slotNumber}`, { slotNumber });
|
|
1106
|
+
return false;
|
|
1107
|
+
}
|
|
1108
|
+
// Use the SAME timestamp the bundle simulator overrides block.timestamp with at send time
|
|
1109
|
+
// (sequencer-bundle-simulator.ts) so this upfront check and the send-time sim agree. Slot-start
|
|
1110
|
+
// and last-L1-slot both fall within the same L2 slot (and epoch, which is what `canPruneAtTime`
|
|
1111
|
+
// derives), so they agree today; matching the simulator keeps it robust if the contract ever uses
|
|
1112
|
+
// the timestamp more granularly.
|
|
1113
|
+
const ts = getLastL1SlotTimestampForL2Slot(slotNumber, this.epochCache.getL1Constants());
|
|
1114
|
+
const canPrune = await this.rollupContract.canPruneAtTime(ts).catch(err => {
|
|
1115
|
+
this.log.error(`Failed to check canPruneAtTime for slot ${slotNumber}`, err, { slotNumber });
|
|
1116
|
+
return false;
|
|
1117
|
+
});
|
|
1118
|
+
if (!canPrune) {
|
|
1119
|
+
this.log.debug(`Rollup not prunable at slot ${slotNumber}`, { slotNumber });
|
|
1120
|
+
return false;
|
|
1121
|
+
}
|
|
1122
|
+
const request: L1TxRequest = {
|
|
1123
|
+
to: this.rollupContract.address,
|
|
1124
|
+
data: encodeFunctionData({ abi: RollupAbi, functionName: 'prune', args: [] }),
|
|
1125
|
+
};
|
|
1126
|
+
this.log.info(`Enqueuing rollup prune for slot ${slotNumber}`, { slotNumber });
|
|
1127
|
+
return this.enqueueRequest(
|
|
1128
|
+
'prune',
|
|
1129
|
+
request,
|
|
1130
|
+
{ address: this.rollupContract.address, abi: RollupAbi, eventName: 'PrunedPending' },
|
|
1131
|
+
slotNumber,
|
|
1132
|
+
);
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1020
1135
|
/** Enqueues all slashing actions as returned by the slasher client. */
|
|
1021
1136
|
public async enqueueSlashingActions(
|
|
1022
1137
|
actions: ProposerSlashAction[],
|
|
1023
1138
|
slotNumber: SlotNumber,
|
|
1024
|
-
timestamp: bigint,
|
|
1025
1139
|
signerAddress: EthAddress,
|
|
1026
1140
|
signer: (msg: TypedDataDefinition) => Promise<`0x${string}`>,
|
|
1027
1141
|
): Promise<boolean> {
|
|
@@ -1032,58 +1146,6 @@ export class SequencerPublisher {
|
|
|
1032
1146
|
|
|
1033
1147
|
for (const action of actions) {
|
|
1034
1148
|
switch (action.type) {
|
|
1035
|
-
case 'vote-empire-payload': {
|
|
1036
|
-
if (this.slashingProposerContract?.type !== 'empire') {
|
|
1037
|
-
this.log.error('Cannot vote for empire payload on non-empire slashing contract');
|
|
1038
|
-
break;
|
|
1039
|
-
}
|
|
1040
|
-
this.log.debug(`Enqueuing slashing vote for payload ${action.payload} at slot ${slotNumber}`, {
|
|
1041
|
-
signerAddress,
|
|
1042
|
-
});
|
|
1043
|
-
await this.enqueueCastSignalHelper(
|
|
1044
|
-
slotNumber,
|
|
1045
|
-
timestamp,
|
|
1046
|
-
'empire-slashing-signal',
|
|
1047
|
-
action.payload,
|
|
1048
|
-
this.slashingProposerContract,
|
|
1049
|
-
signerAddress,
|
|
1050
|
-
signer,
|
|
1051
|
-
);
|
|
1052
|
-
break;
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
case 'create-empire-payload': {
|
|
1056
|
-
this.log.debug(`Enqueuing slashing create payload at slot ${slotNumber}`, { slotNumber, signerAddress });
|
|
1057
|
-
const request = this.slashFactoryContract.buildCreatePayloadRequest(action.data);
|
|
1058
|
-
await this.simulateAndEnqueueRequest(
|
|
1059
|
-
'create-empire-payload',
|
|
1060
|
-
request,
|
|
1061
|
-
(receipt: TransactionReceipt) =>
|
|
1062
|
-
!!this.slashFactoryContract.tryExtractSlashPayloadCreatedEvent(receipt.logs),
|
|
1063
|
-
slotNumber,
|
|
1064
|
-
timestamp,
|
|
1065
|
-
);
|
|
1066
|
-
break;
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
case 'execute-empire-payload': {
|
|
1070
|
-
this.log.debug(`Enqueuing slashing execute payload at slot ${slotNumber}`, { slotNumber, signerAddress });
|
|
1071
|
-
if (this.slashingProposerContract?.type !== 'empire') {
|
|
1072
|
-
this.log.error('Cannot execute slashing payload on non-empire slashing contract');
|
|
1073
|
-
return false;
|
|
1074
|
-
}
|
|
1075
|
-
const empireSlashingProposer = this.slashingProposerContract as EmpireSlashingProposerContract;
|
|
1076
|
-
const request = empireSlashingProposer.buildExecuteRoundRequest(action.round);
|
|
1077
|
-
await this.simulateAndEnqueueRequest(
|
|
1078
|
-
'execute-empire-payload',
|
|
1079
|
-
request,
|
|
1080
|
-
(receipt: TransactionReceipt) => !!empireSlashingProposer.tryExtractPayloadSubmittedEvent(receipt.logs),
|
|
1081
|
-
slotNumber,
|
|
1082
|
-
timestamp,
|
|
1083
|
-
);
|
|
1084
|
-
break;
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
1149
|
case 'vote-offenses': {
|
|
1088
1150
|
this.log.debug(`Enqueuing slashing vote for ${action.votes.length} votes at slot ${slotNumber}`, {
|
|
1089
1151
|
slotNumber,
|
|
@@ -1091,19 +1153,21 @@ export class SequencerPublisher {
|
|
|
1091
1153
|
votesCount: action.votes.length,
|
|
1092
1154
|
signerAddress,
|
|
1093
1155
|
});
|
|
1094
|
-
if (this.slashingProposerContract
|
|
1095
|
-
this.log.error('
|
|
1156
|
+
if (!this.slashingProposerContract) {
|
|
1157
|
+
this.log.error('No slashing proposer contract available');
|
|
1096
1158
|
return false;
|
|
1097
1159
|
}
|
|
1098
|
-
const tallySlashingProposer = this.slashingProposerContract as TallySlashingProposerContract;
|
|
1099
1160
|
const votes = bufferToHex(encodeSlashConsensusVotes(action.votes));
|
|
1100
|
-
const request = await
|
|
1101
|
-
|
|
1161
|
+
const request = await this.slashingProposerContract.buildVoteRequestFromSigner(votes, slotNumber, signer);
|
|
1162
|
+
this.enqueueRequest(
|
|
1102
1163
|
'vote-offenses',
|
|
1103
1164
|
request,
|
|
1104
|
-
|
|
1165
|
+
{
|
|
1166
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1167
|
+
abi: SlashingProposerAbi,
|
|
1168
|
+
eventName: 'VoteCast',
|
|
1169
|
+
},
|
|
1105
1170
|
slotNumber,
|
|
1106
|
-
timestamp,
|
|
1107
1171
|
);
|
|
1108
1172
|
break;
|
|
1109
1173
|
}
|
|
@@ -1114,18 +1178,23 @@ export class SequencerPublisher {
|
|
|
1114
1178
|
round: action.round,
|
|
1115
1179
|
signerAddress,
|
|
1116
1180
|
});
|
|
1117
|
-
if (this.slashingProposerContract
|
|
1118
|
-
this.log.error('
|
|
1181
|
+
if (!this.slashingProposerContract) {
|
|
1182
|
+
this.log.error('No slashing proposer contract available');
|
|
1119
1183
|
return false;
|
|
1120
1184
|
}
|
|
1121
|
-
const
|
|
1122
|
-
|
|
1123
|
-
|
|
1185
|
+
const executeRequest = this.slashingProposerContract.buildExecuteRoundRequest(
|
|
1186
|
+
action.round,
|
|
1187
|
+
action.committees,
|
|
1188
|
+
);
|
|
1189
|
+
this.enqueueRequest(
|
|
1124
1190
|
'execute-slash',
|
|
1125
|
-
|
|
1126
|
-
|
|
1191
|
+
executeRequest,
|
|
1192
|
+
{
|
|
1193
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1194
|
+
abi: SlashingProposerAbi,
|
|
1195
|
+
eventName: 'RoundExecuted',
|
|
1196
|
+
},
|
|
1127
1197
|
slotNumber,
|
|
1128
|
-
timestamp,
|
|
1129
1198
|
);
|
|
1130
1199
|
break;
|
|
1131
1200
|
}
|
|
@@ -1140,12 +1209,12 @@ export class SequencerPublisher {
|
|
|
1140
1209
|
return true;
|
|
1141
1210
|
}
|
|
1142
1211
|
|
|
1143
|
-
/**
|
|
1212
|
+
/** Enqueues a proposal for a checkpoint on L1 */
|
|
1144
1213
|
public async enqueueProposeCheckpoint(
|
|
1145
1214
|
checkpoint: Checkpoint,
|
|
1146
1215
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
1147
1216
|
attestationsAndSignersSignature: Signature,
|
|
1148
|
-
opts:
|
|
1217
|
+
opts: EnqueueProposeCheckpointOpts = {},
|
|
1149
1218
|
): Promise<void> {
|
|
1150
1219
|
const checkpointHeader = checkpoint.header;
|
|
1151
1220
|
|
|
@@ -1161,31 +1230,11 @@ export class SequencerPublisher {
|
|
|
1161
1230
|
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier,
|
|
1162
1231
|
};
|
|
1163
1232
|
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
// By simulation issue, I mean the fact that the block.timestamp is equal to the last block, not the next, which
|
|
1170
|
-
// make time consistency checks break.
|
|
1171
|
-
// TODO(palla): Check whether we're validating twice, once here and once within addProposeTx, since we call simulateProposeTx in both places.
|
|
1172
|
-
ts = await this.validateCheckpointForSubmission(
|
|
1173
|
-
checkpoint,
|
|
1174
|
-
attestationsAndSigners,
|
|
1175
|
-
attestationsAndSignersSignature,
|
|
1176
|
-
opts,
|
|
1177
|
-
);
|
|
1178
|
-
} catch (err: any) {
|
|
1179
|
-
this.log.error(`Checkpoint validation failed. ${err instanceof Error ? err.message : 'No error message'}`, err, {
|
|
1180
|
-
...checkpoint.getStats(),
|
|
1181
|
-
slotNumber: checkpoint.header.slotNumber,
|
|
1182
|
-
forcePendingCheckpointNumber: opts.forcePendingCheckpointNumber,
|
|
1183
|
-
});
|
|
1184
|
-
throw err;
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
|
-
this.log.verbose(`Enqueuing checkpoint propose transaction`, { ...checkpoint.toCheckpointInfo(), ...opts });
|
|
1188
|
-
await this.addProposeTx(checkpoint, proposeTxArgs, opts, ts);
|
|
1233
|
+
this.log.verbose(`Enqueuing checkpoint propose transaction`, {
|
|
1234
|
+
...checkpoint.toCheckpointInfo(),
|
|
1235
|
+
txTimeoutAt: opts.txTimeoutAt,
|
|
1236
|
+
});
|
|
1237
|
+
await this.addProposeTx(checkpoint, proposeTxArgs, { txTimeoutAt: opts.txTimeoutAt });
|
|
1189
1238
|
}
|
|
1190
1239
|
|
|
1191
1240
|
public enqueueInvalidateCheckpoint(
|
|
@@ -1196,23 +1245,22 @@ export class SequencerPublisher {
|
|
|
1196
1245
|
return;
|
|
1197
1246
|
}
|
|
1198
1247
|
|
|
1199
|
-
// We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
1200
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil((Number(request.gasUsed) * 64) / 63)));
|
|
1201
|
-
|
|
1202
1248
|
const { gasUsed, checkpointNumber } = request;
|
|
1203
|
-
const logData = { gasUsed, checkpointNumber,
|
|
1249
|
+
const logData = { gasUsed, checkpointNumber, opts };
|
|
1204
1250
|
this.log.verbose(`Enqueuing invalidate checkpoint request`, logData);
|
|
1205
1251
|
this.addRequest({
|
|
1206
1252
|
action: `invalidate-by-${request.reason}`,
|
|
1207
1253
|
request: request.request,
|
|
1208
|
-
gasConfig: {
|
|
1254
|
+
gasConfig: opts.txTimeoutAt ? { txTimeoutAt: opts.txTimeoutAt } : undefined,
|
|
1209
1255
|
lastValidL2Slot: SlotNumber(this.getCurrentL2Slot() + 2),
|
|
1210
1256
|
checkSuccess: (_req, result) => {
|
|
1211
1257
|
const success =
|
|
1212
1258
|
result &&
|
|
1213
|
-
result.receipt
|
|
1214
|
-
|
|
1215
|
-
|
|
1259
|
+
extractEventSuccess(result.receipt, {
|
|
1260
|
+
address: this.rollupContract.address,
|
|
1261
|
+
abi: RollupAbi,
|
|
1262
|
+
eventName: 'CheckpointInvalidated',
|
|
1263
|
+
});
|
|
1216
1264
|
if (!success) {
|
|
1217
1265
|
this.log.warn(`Invalidate checkpoint ${request.checkpointNumber} failed`, { ...result, ...logData });
|
|
1218
1266
|
} else {
|
|
@@ -1223,72 +1271,36 @@ export class SequencerPublisher {
|
|
|
1223
1271
|
});
|
|
1224
1272
|
}
|
|
1225
1273
|
|
|
1226
|
-
|
|
1274
|
+
/**
|
|
1275
|
+
* Dedup-checked enqueue helper for actions that are simulated at bundle-send time rather
|
|
1276
|
+
* than at enqueue time. Validates the (action, slot) dedup key, sets `lastActions`, and
|
|
1277
|
+
* enqueues without a gasLimit so the bundle simulate sets the only gasLimit that matters.
|
|
1278
|
+
*/
|
|
1279
|
+
private enqueueRequest(
|
|
1227
1280
|
action: Action,
|
|
1228
1281
|
request: L1TxRequest,
|
|
1229
|
-
|
|
1282
|
+
eventOpts: { address: string; abi: Abi; eventName: string },
|
|
1230
1283
|
slotNumber: SlotNumber,
|
|
1231
|
-
|
|
1232
|
-
) {
|
|
1233
|
-
const logData = { slotNumber, timestamp, gasLimit: undefined as bigint | undefined };
|
|
1284
|
+
): boolean {
|
|
1234
1285
|
if (this.lastActions[action] && this.lastActions[action] === slotNumber) {
|
|
1235
1286
|
this.log.debug(`Skipping duplicate action ${action} for slot ${slotNumber}`);
|
|
1236
1287
|
return false;
|
|
1237
1288
|
}
|
|
1238
|
-
|
|
1239
1289
|
const cachedLastActionSlot = this.lastActions[action];
|
|
1240
1290
|
this.lastActions[action] = slotNumber;
|
|
1241
1291
|
|
|
1242
|
-
this.log.debug(`
|
|
1243
|
-
|
|
1244
|
-
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
1245
|
-
|
|
1246
|
-
let gasUsed: bigint;
|
|
1247
|
-
const simulateAbi = mergeAbis([request.abi ?? [], ErrorsAbi]);
|
|
1248
|
-
try {
|
|
1249
|
-
({ gasUsed } = await this.l1TxUtils.simulate(request, { time: timestamp }, [], simulateAbi)); // TODO(palla/slash): Check the timestamp logic
|
|
1250
|
-
this.log.verbose(`Simulation for ${action} succeeded`, { ...logData, request, gasUsed });
|
|
1251
|
-
} catch (err) {
|
|
1252
|
-
const viemError = formatViemError(err, simulateAbi);
|
|
1253
|
-
this.log.error(`Simulation for ${action} at ${slotNumber} failed`, viemError, logData);
|
|
1254
|
-
|
|
1255
|
-
this.backupFailedTx({
|
|
1256
|
-
id: keccak256(request.data!),
|
|
1257
|
-
failureType: 'simulation',
|
|
1258
|
-
request: { to: request.to!, data: request.data!, value: request.value?.toString() },
|
|
1259
|
-
l1BlockNumber: l1BlockNumber.toString(),
|
|
1260
|
-
error: { message: viemError.message, name: viemError.name },
|
|
1261
|
-
context: {
|
|
1262
|
-
actions: [action],
|
|
1263
|
-
slot: slotNumber,
|
|
1264
|
-
sender: this.getSenderAddress().toString(),
|
|
1265
|
-
},
|
|
1266
|
-
});
|
|
1267
|
-
|
|
1268
|
-
return false;
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
// We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
1272
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil((Number(gasUsed) * 64) / 63)));
|
|
1273
|
-
logData.gasLimit = gasLimit;
|
|
1274
|
-
|
|
1275
|
-
// Store the ABI used for simulation on the request so Multicall3.forward can decode errors
|
|
1276
|
-
// when the tx is sent and a revert is diagnosed via simulation.
|
|
1277
|
-
const requestWithAbi = { ...request, abi: simulateAbi };
|
|
1278
|
-
|
|
1279
|
-
this.log.debug(`Enqueuing ${action}`, logData);
|
|
1292
|
+
this.log.debug(`Enqueuing ${action}`, { slotNumber });
|
|
1280
1293
|
this.addRequest({
|
|
1281
1294
|
action,
|
|
1282
|
-
request
|
|
1283
|
-
gasConfig: { gasLimit },
|
|
1295
|
+
request,
|
|
1284
1296
|
lastValidL2Slot: slotNumber,
|
|
1285
|
-
checkSuccess: (
|
|
1286
|
-
const success = result && result.receipt
|
|
1297
|
+
checkSuccess: (_request, result) => {
|
|
1298
|
+
const success = result && extractEventSuccess(result.receipt, eventOpts);
|
|
1287
1299
|
if (!success) {
|
|
1288
|
-
this.log.warn(`Action ${action} at ${slotNumber} failed`, { ...result,
|
|
1300
|
+
this.log.warn(`Action ${action} at ${slotNumber} failed`, { ...result, slotNumber });
|
|
1289
1301
|
this.lastActions[action] = cachedLastActionSlot;
|
|
1290
1302
|
} else {
|
|
1291
|
-
this.log.info(`Action ${action} at ${slotNumber} succeeded`, { ...result,
|
|
1303
|
+
this.log.info(`Action ${action} at ${slotNumber} succeeded`, { ...result, slotNumber });
|
|
1292
1304
|
}
|
|
1293
1305
|
return !!success;
|
|
1294
1306
|
},
|
|
@@ -1304,6 +1316,7 @@ export class SequencerPublisher {
|
|
|
1304
1316
|
*/
|
|
1305
1317
|
public interrupt() {
|
|
1306
1318
|
this.interrupted = true;
|
|
1319
|
+
this.interruptibleSleep.interrupt();
|
|
1307
1320
|
this.l1TxUtils.interrupt();
|
|
1308
1321
|
}
|
|
1309
1322
|
|
|
@@ -1313,11 +1326,7 @@ export class SequencerPublisher {
|
|
|
1313
1326
|
this.l1TxUtils.restart();
|
|
1314
1327
|
}
|
|
1315
1328
|
|
|
1316
|
-
private async prepareProposeTx(
|
|
1317
|
-
encodedData: L1ProcessArgs,
|
|
1318
|
-
timestamp: bigint,
|
|
1319
|
-
options: { forcePendingCheckpointNumber?: CheckpointNumber },
|
|
1320
|
-
) {
|
|
1329
|
+
private async prepareProposeTx(encodedData: L1ProcessArgs) {
|
|
1321
1330
|
const kzg = Blob.getViemKzgInstance();
|
|
1322
1331
|
const blobInput = getPrefixedEthBlobCommitments(encodedData.blobs);
|
|
1323
1332
|
this.log.debug('Validating blob input', { blobInput });
|
|
@@ -1330,7 +1339,11 @@ export class SequencerPublisher {
|
|
|
1330
1339
|
blobEvaluationGas = BigInt(encodedData.blobs.length) * 21_000n;
|
|
1331
1340
|
this.log.debug(`Using fixed blob evaluation gas estimate in fisherman mode: ${blobEvaluationGas}`);
|
|
1332
1341
|
} else {
|
|
1333
|
-
//
|
|
1342
|
+
// We call validateBlobs via estimateGas with real blob+kzg sidecars as a consistency check
|
|
1343
|
+
// that our locally-built blob commitments match the blob data. The bundle simulate at send
|
|
1344
|
+
// time uses eth_simulateV1, which cannot carry blob inputs, so the rollup's on-chain blob
|
|
1345
|
+
// check is forced off there — making this the only pre-flight detector of a commitment/data
|
|
1346
|
+
// mismatch. The returned gas estimate is stashed on the request for the bundle path to read.
|
|
1334
1347
|
blobEvaluationGas = await this.l1TxUtils
|
|
1335
1348
|
.estimateGas(
|
|
1336
1349
|
this.getSenderAddress().toString(),
|
|
@@ -1388,138 +1401,21 @@ export class SequencerPublisher {
|
|
|
1388
1401
|
blobInput,
|
|
1389
1402
|
] as const;
|
|
1390
1403
|
|
|
1391
|
-
const
|
|
1392
|
-
|
|
1393
|
-
return { args, blobEvaluationGas, rollupData, simulationResult };
|
|
1394
|
-
}
|
|
1395
|
-
|
|
1396
|
-
/**
|
|
1397
|
-
* Simulates the propose tx with eth_simulateV1
|
|
1398
|
-
* @param args - The propose tx args
|
|
1399
|
-
* @param timestamp - The timestamp to simulate proposal at
|
|
1400
|
-
* @returns The simulation result
|
|
1401
|
-
*/
|
|
1402
|
-
private async simulateProposeTx(
|
|
1403
|
-
args: readonly [
|
|
1404
|
-
{
|
|
1405
|
-
readonly header: ViemHeader;
|
|
1406
|
-
readonly archive: `0x${string}`;
|
|
1407
|
-
readonly oracleInput: {
|
|
1408
|
-
readonly feeAssetPriceModifier: bigint;
|
|
1409
|
-
};
|
|
1410
|
-
},
|
|
1411
|
-
ViemCommitteeAttestations,
|
|
1412
|
-
`0x${string}`[], // Signers
|
|
1413
|
-
ViemSignature,
|
|
1414
|
-
`0x${string}`,
|
|
1415
|
-
],
|
|
1416
|
-
timestamp: bigint,
|
|
1417
|
-
options: { forcePendingCheckpointNumber?: CheckpointNumber },
|
|
1418
|
-
) {
|
|
1419
|
-
const rollupData = encodeFunctionData({
|
|
1420
|
-
abi: RollupAbi,
|
|
1421
|
-
functionName: 'propose',
|
|
1422
|
-
args,
|
|
1423
|
-
});
|
|
1424
|
-
|
|
1425
|
-
// override the pending checkpoint number if requested
|
|
1426
|
-
const forcePendingCheckpointNumberStateDiff = (
|
|
1427
|
-
options.forcePendingCheckpointNumber !== undefined
|
|
1428
|
-
? await this.rollupContract.makePendingCheckpointNumberOverride(options.forcePendingCheckpointNumber)
|
|
1429
|
-
: []
|
|
1430
|
-
).flatMap(override => override.stateDiff ?? []);
|
|
1431
|
-
|
|
1432
|
-
const stateOverrides: StateOverride = [
|
|
1433
|
-
{
|
|
1434
|
-
address: this.rollupContract.address,
|
|
1435
|
-
// @note we override checkBlob to false since blobs are not part simulate()
|
|
1436
|
-
stateDiff: [
|
|
1437
|
-
{ slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true), value: toPaddedHex(0n, true) },
|
|
1438
|
-
...forcePendingCheckpointNumberStateDiff,
|
|
1439
|
-
],
|
|
1440
|
-
},
|
|
1441
|
-
];
|
|
1442
|
-
// In fisherman mode, simulate as the proposer but with sufficient balance
|
|
1443
|
-
if (this.proposerAddressForSimulation) {
|
|
1444
|
-
stateOverrides.push({
|
|
1445
|
-
address: this.proposerAddressForSimulation.toString(),
|
|
1446
|
-
balance: 10n * WEI_CONST * WEI_CONST, // 10 ETH
|
|
1447
|
-
});
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
1451
|
-
|
|
1452
|
-
const simulationResult = await this.l1TxUtils
|
|
1453
|
-
.simulate(
|
|
1454
|
-
{
|
|
1455
|
-
to: this.rollupContract.address,
|
|
1456
|
-
data: rollupData,
|
|
1457
|
-
gas: MAX_L1_TX_LIMIT,
|
|
1458
|
-
...(this.proposerAddressForSimulation && { from: this.proposerAddressForSimulation.toString() }),
|
|
1459
|
-
},
|
|
1460
|
-
{
|
|
1461
|
-
// @note we add 1n to the timestamp because geth implementation doesn't like simulation timestamp to be equal to the current block timestamp
|
|
1462
|
-
time: timestamp + 1n,
|
|
1463
|
-
// @note reth should have a 30m gas limit per block but throws errors that this tx is beyond limit so we increase here
|
|
1464
|
-
gasLimit: MAX_L1_TX_LIMIT * 2n,
|
|
1465
|
-
},
|
|
1466
|
-
stateOverrides,
|
|
1467
|
-
RollupAbi,
|
|
1468
|
-
{
|
|
1469
|
-
// @note fallback gas estimate to use if the node doesn't support simulation API
|
|
1470
|
-
fallbackGasEstimate: MAX_L1_TX_LIMIT,
|
|
1471
|
-
},
|
|
1472
|
-
)
|
|
1473
|
-
.catch(err => {
|
|
1474
|
-
// In fisherman mode, we expect ValidatorSelection__MissingProposerSignature since fisherman doesn't have proposer signature
|
|
1475
|
-
const viemError = formatViemError(err);
|
|
1476
|
-
if (this.config.fishermanMode && viemError.message?.includes('ValidatorSelection__MissingProposerSignature')) {
|
|
1477
|
-
this.log.debug(`Ignoring expected ValidatorSelection__MissingProposerSignature error in fisherman mode`);
|
|
1478
|
-
// Return a minimal simulation result with the fallback gas estimate
|
|
1479
|
-
return {
|
|
1480
|
-
gasUsed: MAX_L1_TX_LIMIT,
|
|
1481
|
-
logs: [],
|
|
1482
|
-
};
|
|
1483
|
-
}
|
|
1484
|
-
this.log.error(`Failed to simulate propose tx`, viemError);
|
|
1485
|
-
this.backupFailedTx({
|
|
1486
|
-
id: keccak256(rollupData),
|
|
1487
|
-
failureType: 'simulation',
|
|
1488
|
-
request: { to: this.rollupContract.address, data: rollupData },
|
|
1489
|
-
l1BlockNumber: l1BlockNumber.toString(),
|
|
1490
|
-
error: { message: viemError.message, name: viemError.name },
|
|
1491
|
-
context: {
|
|
1492
|
-
actions: ['propose'],
|
|
1493
|
-
slot: Number(args[0].header.slotNumber),
|
|
1494
|
-
sender: this.getSenderAddress().toString(),
|
|
1495
|
-
},
|
|
1496
|
-
});
|
|
1497
|
-
throw err;
|
|
1498
|
-
});
|
|
1404
|
+
const rollupData = encodeFunctionData({ abi: RollupAbi, functionName: 'propose', args });
|
|
1499
1405
|
|
|
1500
|
-
return {
|
|
1406
|
+
return { args, blobEvaluationGas, rollupData };
|
|
1501
1407
|
}
|
|
1502
1408
|
|
|
1503
1409
|
private async addProposeTx(
|
|
1504
1410
|
checkpoint: Checkpoint,
|
|
1505
1411
|
encodedData: L1ProcessArgs,
|
|
1506
|
-
opts:
|
|
1507
|
-
timestamp: bigint,
|
|
1412
|
+
opts: EnqueueProposeCheckpointOpts = {},
|
|
1508
1413
|
): Promise<void> {
|
|
1509
1414
|
const slot = checkpoint.header.slotNumber;
|
|
1510
1415
|
const timer = new Timer();
|
|
1511
1416
|
const kzg = Blob.getViemKzgInstance();
|
|
1512
|
-
const { rollupData,
|
|
1513
|
-
encodedData,
|
|
1514
|
-
timestamp,
|
|
1515
|
-
opts,
|
|
1516
|
-
);
|
|
1417
|
+
const { rollupData, blobEvaluationGas } = await this.prepareProposeTx(encodedData);
|
|
1517
1418
|
const startBlock = await this.l1TxUtils.getBlockNumber();
|
|
1518
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(
|
|
1519
|
-
BigInt(Math.ceil((Number(simulationResult.gasUsed) * 64) / 63)) +
|
|
1520
|
-
blobEvaluationGas +
|
|
1521
|
-
SequencerPublisher.MULTICALL_OVERHEAD_GAS_GUESS, // We issue the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
1522
|
-
);
|
|
1523
1419
|
|
|
1524
1420
|
// Send the blobs to the blob client preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
|
|
1525
1421
|
// tx fails but it does get mined. We make sure that the blobs are sent to the blob client regardless of the tx outcome.
|
|
@@ -1536,7 +1432,8 @@ export class SequencerPublisher {
|
|
|
1536
1432
|
data: rollupData,
|
|
1537
1433
|
},
|
|
1538
1434
|
lastValidL2Slot: checkpoint.header.slotNumber,
|
|
1539
|
-
gasConfig: {
|
|
1435
|
+
gasConfig: { txTimeoutAt: opts.txTimeoutAt, gasLimit: undefined },
|
|
1436
|
+
blobEvaluationGas,
|
|
1540
1437
|
blobConfig: {
|
|
1541
1438
|
blobs: encodedData.blobs.map(b => b.data),
|
|
1542
1439
|
kzg,
|
|
@@ -1546,10 +1443,11 @@ export class SequencerPublisher {
|
|
|
1546
1443
|
return false;
|
|
1547
1444
|
}
|
|
1548
1445
|
const { receipt, stats, errorMsg } = result;
|
|
1549
|
-
const success =
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1446
|
+
const success = extractEventSuccess(receipt, {
|
|
1447
|
+
address: this.rollupContract.address,
|
|
1448
|
+
abi: RollupAbi,
|
|
1449
|
+
eventName: 'CheckpointProposed',
|
|
1450
|
+
});
|
|
1553
1451
|
|
|
1554
1452
|
if (success) {
|
|
1555
1453
|
const endBlock = receipt.blockNumber;
|
|
@@ -1590,7 +1488,7 @@ export class SequencerPublisher {
|
|
|
1590
1488
|
});
|
|
1591
1489
|
}
|
|
1592
1490
|
|
|
1593
|
-
/** Returns the timestamp
|
|
1491
|
+
/** Returns the timestamp of the next L1 slot boundary after now. */
|
|
1594
1492
|
private getNextL1SlotTimestamp(): bigint {
|
|
1595
1493
|
const l1Constants = this.epochCache.getL1Constants();
|
|
1596
1494
|
return getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), l1Constants);
|