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