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