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