@aztec/sequencer-client 0.0.1-commit.001888fc → 0.0.1-commit.017a351
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 -87
- package/dest/config.d.ts +4 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +35 -17
- 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 -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/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 +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 +314 -532
- 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 +509 -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 +60 -10
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +732 -180
- 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 +48 -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 +62 -14
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +349 -107
- package/dest/sequencer/timetable.d.ts +11 -1
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +41 -36
- 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 +4 -8
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- 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 -27
- package/src/client/sequencer-client.ts +55 -116
- package/src/config.ts +40 -14
- 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 -63
- 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 +3 -6
- package/src/publisher/sequencer-publisher.ts +373 -577
- package/src/sequencer/README.md +162 -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 +595 -0
- package/src/sequencer/chain_state_overrides.ts +162 -0
- package/src/sequencer/checkpoint_proposal_job.ts +872 -207
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +1 -12
- package/src/sequencer/events.ts +51 -2
- package/src/sequencer/index.ts +2 -0
- package/src/sequencer/metrics.ts +57 -24
- package/src/sequencer/sequencer.ts +429 -121
- package/src/sequencer/timetable.ts +49 -44
- package/src/sequencer/types.ts +1 -1
- package/src/test/mock_checkpoint_builder.ts +3 -3
- 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,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
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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);
|
|
458
|
+
|
|
459
|
+
if (bundleResult.kind === 'aborted') {
|
|
460
|
+
this.logDroppedInSim(bundleResult.droppedRequests);
|
|
461
|
+
void this.backupDroppedInSim(bundleResult.droppedRequests);
|
|
462
|
+
return undefined;
|
|
463
|
+
}
|
|
446
464
|
|
|
447
|
-
const
|
|
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,88 @@ 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
|
+
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
|
+
|
|
528
647
|
private callbackBundledTransactions(
|
|
529
648
|
requests: RequestWithExpiry[],
|
|
530
|
-
result: { receipt: TransactionReceipt;
|
|
531
|
-
txContext: { multicallData: Hex; blobData?: Hex[]; l1BlockNumber: bigint },
|
|
649
|
+
result: { receipt: TransactionReceipt; multicallData: Hex },
|
|
532
650
|
) {
|
|
533
651
|
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
|
-
});
|
|
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);
|
|
593
669
|
}
|
|
594
|
-
return { successfulActions, failedActions };
|
|
595
670
|
}
|
|
671
|
+
return { successfulActions, failedActions };
|
|
596
672
|
}
|
|
597
673
|
|
|
598
674
|
/**
|
|
599
|
-
* @notice Will call `
|
|
675
|
+
* @notice Will call `canProposeAt` to make sure that it is possible to propose
|
|
600
676
|
* @param tipArchive - The archive to check
|
|
601
677
|
* @returns The slot and block number if it is possible to propose, undefined otherwise
|
|
602
678
|
*/
|
|
603
|
-
public
|
|
604
|
-
tipArchive: Fr,
|
|
605
|
-
msgSender: EthAddress,
|
|
606
|
-
opts: { forcePendingCheckpointNumber?: CheckpointNumber } = {},
|
|
607
|
-
) {
|
|
679
|
+
public async canProposeAt(tipArchive: Fr, msgSender: EthAddress, simulationOverridesPlan?: SimulationOverridesPlan) {
|
|
608
680
|
// TODO: #14291 - should loop through multiple keys to check if any of them can propose
|
|
609
|
-
|
|
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 slotOffset = this.aztecSlotDuration;
|
|
688
|
+
const nextL1SlotTs = this.getNextL1SlotTimestamp() + slotOffset;
|
|
610
689
|
|
|
611
690
|
return this.rollupContract
|
|
612
|
-
.
|
|
613
|
-
|
|
614
|
-
|
|
691
|
+
.canProposeAt(
|
|
692
|
+
tipArchive.toBuffer(),
|
|
693
|
+
msgSender.toString(),
|
|
694
|
+
nextL1SlotTs,
|
|
695
|
+
await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan),
|
|
696
|
+
)
|
|
615
697
|
.catch(err => {
|
|
616
|
-
if (err instanceof FormattedViemError &&
|
|
617
|
-
this.log.warn(`Failed canProposeAtTime check with ${
|
|
698
|
+
if (err instanceof FormattedViemError && expectedErrors.find(e => err.message.includes(e))) {
|
|
699
|
+
this.log.warn(`Failed canProposeAtTime check with ${expectedErrors.find(e => err.message.includes(e))}`, {
|
|
618
700
|
error: err.message,
|
|
619
701
|
});
|
|
620
702
|
} else {
|
|
@@ -623,6 +705,7 @@ export class SequencerPublisher {
|
|
|
623
705
|
return undefined;
|
|
624
706
|
});
|
|
625
707
|
}
|
|
708
|
+
|
|
626
709
|
/**
|
|
627
710
|
* @notice Will simulate `validateHeader` to make sure that the block header is valid
|
|
628
711
|
* @dev This is a convenience function that can be used by the sequencer to validate a "partial" header.
|
|
@@ -632,13 +715,13 @@ export class SequencerPublisher {
|
|
|
632
715
|
@trackSpan('SequencerPublisher.validateBlockHeader')
|
|
633
716
|
public async validateBlockHeader(
|
|
634
717
|
header: CheckpointHeader,
|
|
635
|
-
|
|
718
|
+
simulationOverridesPlan?: SimulationOverridesPlan,
|
|
636
719
|
): Promise<void> {
|
|
637
720
|
const flags = { ignoreDA: true, ignoreSignatures: true };
|
|
638
721
|
|
|
639
722
|
const args = [
|
|
640
723
|
header.toViem(),
|
|
641
|
-
CommitteeAttestationsAndSigners.
|
|
724
|
+
CommitteeAttestationsAndSigners.packAttestations([]),
|
|
642
725
|
[], // no signers
|
|
643
726
|
Signature.empty().toViemSignature(),
|
|
644
727
|
`0x${'0'.repeat(64)}`, // 32 empty bytes
|
|
@@ -646,10 +729,9 @@ export class SequencerPublisher {
|
|
|
646
729
|
flags,
|
|
647
730
|
] as const;
|
|
648
731
|
|
|
649
|
-
const
|
|
650
|
-
const
|
|
651
|
-
|
|
652
|
-
);
|
|
732
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
733
|
+
const ts = getLastL1SlotTimestampForL2Slot(header.slotNumber, l1Constants);
|
|
734
|
+
const stateOverrides = await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan);
|
|
653
735
|
let balance = 0n;
|
|
654
736
|
if (this.config.fishermanMode) {
|
|
655
737
|
// In fisherman mode, we can't know where the proposer is publishing from
|
|
@@ -669,7 +751,7 @@ export class SequencerPublisher {
|
|
|
669
751
|
data: encodeFunctionData({ abi: RollupAbi, functionName: 'validateHeaderWithAttestations', args }),
|
|
670
752
|
from: MULTI_CALL_3_ADDRESS,
|
|
671
753
|
},
|
|
672
|
-
{ time: ts
|
|
754
|
+
{ time: ts },
|
|
673
755
|
stateOverrides,
|
|
674
756
|
);
|
|
675
757
|
this.log.debug(`Simulated validateHeader`);
|
|
@@ -722,6 +804,7 @@ export class SequencerPublisher {
|
|
|
722
804
|
gasUsed,
|
|
723
805
|
checkpointNumber,
|
|
724
806
|
forcePendingCheckpointNumber: CheckpointNumber(checkpointNumber - 1),
|
|
807
|
+
lastArchive: validationResult.checkpoint.lastArchive,
|
|
725
808
|
reason,
|
|
726
809
|
};
|
|
727
810
|
} catch (err) {
|
|
@@ -734,8 +817,8 @@ export class SequencerPublisher {
|
|
|
734
817
|
`Simulation for invalidate checkpoint ${checkpointNumber} failed due to checkpoint not being in pending chain`,
|
|
735
818
|
{ ...logData, request, error: viemError.message },
|
|
736
819
|
);
|
|
737
|
-
const
|
|
738
|
-
if (
|
|
820
|
+
const latestProposedCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
821
|
+
if (latestProposedCheckpointNumber < checkpointNumber) {
|
|
739
822
|
this.log.verbose(`Checkpoint ${checkpointNumber} has already been invalidated`, { ...logData });
|
|
740
823
|
return undefined;
|
|
741
824
|
} else {
|
|
@@ -780,9 +863,7 @@ export class SequencerPublisher {
|
|
|
780
863
|
const logData = { ...checkpoint, reason };
|
|
781
864
|
this.log.debug(`Building invalidate checkpoint ${checkpoint.checkpointNumber} request`, logData);
|
|
782
865
|
|
|
783
|
-
const attestationsAndSigners =
|
|
784
|
-
validationResult.attestations,
|
|
785
|
-
).getPackedAttestations();
|
|
866
|
+
const attestationsAndSigners = CommitteeAttestationsAndSigners.packAttestations(validationResult.attestations);
|
|
786
867
|
|
|
787
868
|
if (reason === 'invalid-attestation') {
|
|
788
869
|
return this.rollupContract.buildInvalidateBadAttestationRequest(
|
|
@@ -803,43 +884,11 @@ export class SequencerPublisher {
|
|
|
803
884
|
}
|
|
804
885
|
}
|
|
805
886
|
|
|
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
887
|
private async enqueueCastSignalHelper(
|
|
838
888
|
slotNumber: SlotNumber,
|
|
839
|
-
timestamp: bigint,
|
|
840
889
|
signalType: GovernanceSignalAction,
|
|
841
890
|
payload: EthAddress,
|
|
842
|
-
base:
|
|
891
|
+
base: GovernanceProposerContract,
|
|
843
892
|
signerAddress: EthAddress,
|
|
844
893
|
signer: (msg: TypedDataDefinition) => Promise<`0x${string}`>,
|
|
845
894
|
): Promise<boolean> {
|
|
@@ -865,34 +914,28 @@ export class SequencerPublisher {
|
|
|
865
914
|
return false;
|
|
866
915
|
}
|
|
867
916
|
|
|
868
|
-
if (await
|
|
917
|
+
if (await base.isPayloadEmpty(payload)) {
|
|
869
918
|
this.log.warn(`Skipping vote cast for payload with empty code`);
|
|
870
919
|
return false;
|
|
871
920
|
}
|
|
872
921
|
|
|
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
|
-
}
|
|
922
|
+
// Skip signaling if there is already a live (non-terminal) Governance proposal for this
|
|
923
|
+
// payload. This is intentionally not cached: a previously-live proposal may transition to
|
|
924
|
+
// a terminal state (Dropped/Rejected/Expired/Executed), at which point we may want to re-signal
|
|
925
|
+
// the same payload in a future round.
|
|
926
|
+
let proposed = false;
|
|
927
|
+
try {
|
|
928
|
+
proposed = await base.hasActiveProposalWithPayload(payload.toString());
|
|
929
|
+
} catch (err) {
|
|
930
|
+
// We deliberately swallow the error and proceed to signal. Failing closed (skipping the
|
|
931
|
+
// signal) on transient RPC errors would let a flaky L1 endpoint silence governance
|
|
932
|
+
// participation entirely; failing open at worst produces a duplicate signal that the
|
|
933
|
+
// contract will simply count alongside others in the round.
|
|
934
|
+
this.log.error(`Failed to check if payload ${payload} was already proposed (signalling anyway)`, err);
|
|
892
935
|
}
|
|
893
936
|
|
|
894
|
-
if (
|
|
895
|
-
this.log.info(`Payload ${payload}
|
|
937
|
+
if (proposed) {
|
|
938
|
+
this.log.info(`Payload ${payload} has a live governance proposal, stopping signals`);
|
|
896
939
|
return false;
|
|
897
940
|
}
|
|
898
941
|
|
|
@@ -914,41 +957,19 @@ export class SequencerPublisher {
|
|
|
914
957
|
lastValidL2Slot: slotNumber,
|
|
915
958
|
});
|
|
916
959
|
|
|
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
960
|
// TODO(palla/slash): All votes (governance and slashing) should txTimeoutAt at the end of the slot.
|
|
941
961
|
this.addRequest({
|
|
942
|
-
gasConfig: { gasLimit: SequencerPublisher.VOTE_GAS_GUESS },
|
|
943
962
|
action,
|
|
944
963
|
request,
|
|
945
964
|
lastValidL2Slot: slotNumber,
|
|
946
965
|
checkSuccess: (_request, result) => {
|
|
947
966
|
const success =
|
|
948
967
|
result &&
|
|
949
|
-
result.receipt
|
|
950
|
-
|
|
951
|
-
|
|
968
|
+
extractEventSuccess(result.receipt, {
|
|
969
|
+
address: base.address.toString(),
|
|
970
|
+
abi: EmpireBaseAbi,
|
|
971
|
+
eventName: 'SignalCast',
|
|
972
|
+
});
|
|
952
973
|
|
|
953
974
|
const logData = { ...result, slotNumber, round, payload: payload.toString() };
|
|
954
975
|
if (!success) {
|
|
@@ -970,33 +991,19 @@ export class SequencerPublisher {
|
|
|
970
991
|
return true;
|
|
971
992
|
}
|
|
972
993
|
|
|
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
994
|
/**
|
|
985
995
|
* Enqueues a governance castSignal transaction to cast a signal for a given slot number.
|
|
986
996
|
* @param slotNumber - The slot number to cast a signal for.
|
|
987
|
-
* @param timestamp - The timestamp of the slot to cast a signal for.
|
|
988
997
|
* @returns True if the signal was successfully enqueued, false otherwise.
|
|
989
998
|
*/
|
|
990
999
|
public enqueueGovernanceCastSignal(
|
|
991
1000
|
governancePayload: EthAddress,
|
|
992
1001
|
slotNumber: SlotNumber,
|
|
993
|
-
timestamp: bigint,
|
|
994
1002
|
signerAddress: EthAddress,
|
|
995
1003
|
signer: (msg: TypedDataDefinition) => Promise<`0x${string}`>,
|
|
996
1004
|
): Promise<boolean> {
|
|
997
1005
|
return this.enqueueCastSignalHelper(
|
|
998
1006
|
slotNumber,
|
|
999
|
-
timestamp,
|
|
1000
1007
|
'governance-signal',
|
|
1001
1008
|
governancePayload,
|
|
1002
1009
|
this.govProposerContract,
|
|
@@ -1009,7 +1016,6 @@ export class SequencerPublisher {
|
|
|
1009
1016
|
public async enqueueSlashingActions(
|
|
1010
1017
|
actions: ProposerSlashAction[],
|
|
1011
1018
|
slotNumber: SlotNumber,
|
|
1012
|
-
timestamp: bigint,
|
|
1013
1019
|
signerAddress: EthAddress,
|
|
1014
1020
|
signer: (msg: TypedDataDefinition) => Promise<`0x${string}`>,
|
|
1015
1021
|
): Promise<boolean> {
|
|
@@ -1020,58 +1026,6 @@ export class SequencerPublisher {
|
|
|
1020
1026
|
|
|
1021
1027
|
for (const action of actions) {
|
|
1022
1028
|
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
1029
|
case 'vote-offenses': {
|
|
1076
1030
|
this.log.debug(`Enqueuing slashing vote for ${action.votes.length} votes at slot ${slotNumber}`, {
|
|
1077
1031
|
slotNumber,
|
|
@@ -1079,19 +1033,21 @@ export class SequencerPublisher {
|
|
|
1079
1033
|
votesCount: action.votes.length,
|
|
1080
1034
|
signerAddress,
|
|
1081
1035
|
});
|
|
1082
|
-
if (this.slashingProposerContract
|
|
1083
|
-
this.log.error('
|
|
1036
|
+
if (!this.slashingProposerContract) {
|
|
1037
|
+
this.log.error('No slashing proposer contract available');
|
|
1084
1038
|
return false;
|
|
1085
1039
|
}
|
|
1086
|
-
const tallySlashingProposer = this.slashingProposerContract as TallySlashingProposerContract;
|
|
1087
1040
|
const votes = bufferToHex(encodeSlashConsensusVotes(action.votes));
|
|
1088
|
-
const request = await
|
|
1089
|
-
|
|
1041
|
+
const request = await this.slashingProposerContract.buildVoteRequestFromSigner(votes, slotNumber, signer);
|
|
1042
|
+
this.enqueueRequest(
|
|
1090
1043
|
'vote-offenses',
|
|
1091
1044
|
request,
|
|
1092
|
-
|
|
1045
|
+
{
|
|
1046
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1047
|
+
abi: SlashingProposerAbi,
|
|
1048
|
+
eventName: 'VoteCast',
|
|
1049
|
+
},
|
|
1093
1050
|
slotNumber,
|
|
1094
|
-
timestamp,
|
|
1095
1051
|
);
|
|
1096
1052
|
break;
|
|
1097
1053
|
}
|
|
@@ -1102,18 +1058,23 @@ export class SequencerPublisher {
|
|
|
1102
1058
|
round: action.round,
|
|
1103
1059
|
signerAddress,
|
|
1104
1060
|
});
|
|
1105
|
-
if (this.slashingProposerContract
|
|
1106
|
-
this.log.error('
|
|
1061
|
+
if (!this.slashingProposerContract) {
|
|
1062
|
+
this.log.error('No slashing proposer contract available');
|
|
1107
1063
|
return false;
|
|
1108
1064
|
}
|
|
1109
|
-
const
|
|
1110
|
-
|
|
1111
|
-
|
|
1065
|
+
const executeRequest = this.slashingProposerContract.buildExecuteRoundRequest(
|
|
1066
|
+
action.round,
|
|
1067
|
+
action.committees,
|
|
1068
|
+
);
|
|
1069
|
+
this.enqueueRequest(
|
|
1112
1070
|
'execute-slash',
|
|
1113
|
-
|
|
1114
|
-
|
|
1071
|
+
executeRequest,
|
|
1072
|
+
{
|
|
1073
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1074
|
+
abi: SlashingProposerAbi,
|
|
1075
|
+
eventName: 'RoundExecuted',
|
|
1076
|
+
},
|
|
1115
1077
|
slotNumber,
|
|
1116
|
-
timestamp,
|
|
1117
1078
|
);
|
|
1118
1079
|
break;
|
|
1119
1080
|
}
|
|
@@ -1128,12 +1089,12 @@ export class SequencerPublisher {
|
|
|
1128
1089
|
return true;
|
|
1129
1090
|
}
|
|
1130
1091
|
|
|
1131
|
-
/**
|
|
1092
|
+
/** Enqueues a proposal for a checkpoint on L1 */
|
|
1132
1093
|
public async enqueueProposeCheckpoint(
|
|
1133
1094
|
checkpoint: Checkpoint,
|
|
1134
1095
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
1135
1096
|
attestationsAndSignersSignature: Signature,
|
|
1136
|
-
opts:
|
|
1097
|
+
opts: EnqueueProposeCheckpointOpts = {},
|
|
1137
1098
|
): Promise<void> {
|
|
1138
1099
|
const checkpointHeader = checkpoint.header;
|
|
1139
1100
|
|
|
@@ -1149,31 +1110,11 @@ export class SequencerPublisher {
|
|
|
1149
1110
|
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier,
|
|
1150
1111
|
};
|
|
1151
1112
|
|
|
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);
|
|
1113
|
+
this.log.verbose(`Enqueuing checkpoint propose transaction`, {
|
|
1114
|
+
...checkpoint.toCheckpointInfo(),
|
|
1115
|
+
txTimeoutAt: opts.txTimeoutAt,
|
|
1116
|
+
});
|
|
1117
|
+
await this.addProposeTx(checkpoint, proposeTxArgs, { txTimeoutAt: opts.txTimeoutAt });
|
|
1177
1118
|
}
|
|
1178
1119
|
|
|
1179
1120
|
public enqueueInvalidateCheckpoint(
|
|
@@ -1184,23 +1125,22 @@ export class SequencerPublisher {
|
|
|
1184
1125
|
return;
|
|
1185
1126
|
}
|
|
1186
1127
|
|
|
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
1128
|
const { gasUsed, checkpointNumber } = request;
|
|
1191
|
-
const logData = { gasUsed, checkpointNumber,
|
|
1129
|
+
const logData = { gasUsed, checkpointNumber, opts };
|
|
1192
1130
|
this.log.verbose(`Enqueuing invalidate checkpoint request`, logData);
|
|
1193
1131
|
this.addRequest({
|
|
1194
1132
|
action: `invalidate-by-${request.reason}`,
|
|
1195
1133
|
request: request.request,
|
|
1196
|
-
gasConfig: {
|
|
1134
|
+
gasConfig: opts.txTimeoutAt ? { txTimeoutAt: opts.txTimeoutAt } : undefined,
|
|
1197
1135
|
lastValidL2Slot: SlotNumber(this.getCurrentL2Slot() + 2),
|
|
1198
1136
|
checkSuccess: (_req, result) => {
|
|
1199
1137
|
const success =
|
|
1200
1138
|
result &&
|
|
1201
|
-
result.receipt
|
|
1202
|
-
|
|
1203
|
-
|
|
1139
|
+
extractEventSuccess(result.receipt, {
|
|
1140
|
+
address: this.rollupContract.address,
|
|
1141
|
+
abi: RollupAbi,
|
|
1142
|
+
eventName: 'CheckpointInvalidated',
|
|
1143
|
+
});
|
|
1204
1144
|
if (!success) {
|
|
1205
1145
|
this.log.warn(`Invalidate checkpoint ${request.checkpointNumber} failed`, { ...result, ...logData });
|
|
1206
1146
|
} else {
|
|
@@ -1211,72 +1151,36 @@ export class SequencerPublisher {
|
|
|
1211
1151
|
});
|
|
1212
1152
|
}
|
|
1213
1153
|
|
|
1214
|
-
|
|
1154
|
+
/**
|
|
1155
|
+
* Dedup-checked enqueue helper for actions that are simulated at bundle-send time rather
|
|
1156
|
+
* than at enqueue time. Validates the (action, slot) dedup key, sets `lastActions`, and
|
|
1157
|
+
* enqueues without a gasLimit so the bundle simulate sets the only gasLimit that matters.
|
|
1158
|
+
*/
|
|
1159
|
+
private enqueueRequest(
|
|
1215
1160
|
action: Action,
|
|
1216
1161
|
request: L1TxRequest,
|
|
1217
|
-
|
|
1162
|
+
eventOpts: { address: string; abi: Abi; eventName: string },
|
|
1218
1163
|
slotNumber: SlotNumber,
|
|
1219
|
-
|
|
1220
|
-
) {
|
|
1221
|
-
const logData = { slotNumber, timestamp, gasLimit: undefined as bigint | undefined };
|
|
1164
|
+
): boolean {
|
|
1222
1165
|
if (this.lastActions[action] && this.lastActions[action] === slotNumber) {
|
|
1223
1166
|
this.log.debug(`Skipping duplicate action ${action} for slot ${slotNumber}`);
|
|
1224
1167
|
return false;
|
|
1225
1168
|
}
|
|
1226
|
-
|
|
1227
1169
|
const cachedLastActionSlot = this.lastActions[action];
|
|
1228
1170
|
this.lastActions[action] = slotNumber;
|
|
1229
1171
|
|
|
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);
|
|
1172
|
+
this.log.debug(`Enqueuing ${action}`, { slotNumber });
|
|
1268
1173
|
this.addRequest({
|
|
1269
1174
|
action,
|
|
1270
|
-
request
|
|
1271
|
-
gasConfig: { gasLimit },
|
|
1175
|
+
request,
|
|
1272
1176
|
lastValidL2Slot: slotNumber,
|
|
1273
|
-
checkSuccess: (
|
|
1274
|
-
const success = result && result.receipt
|
|
1177
|
+
checkSuccess: (_request, result) => {
|
|
1178
|
+
const success = result && extractEventSuccess(result.receipt, eventOpts);
|
|
1275
1179
|
if (!success) {
|
|
1276
|
-
this.log.warn(`Action ${action} at ${slotNumber} failed`, { ...result,
|
|
1180
|
+
this.log.warn(`Action ${action} at ${slotNumber} failed`, { ...result, slotNumber });
|
|
1277
1181
|
this.lastActions[action] = cachedLastActionSlot;
|
|
1278
1182
|
} else {
|
|
1279
|
-
this.log.info(`Action ${action} at ${slotNumber} succeeded`, { ...result,
|
|
1183
|
+
this.log.info(`Action ${action} at ${slotNumber} succeeded`, { ...result, slotNumber });
|
|
1280
1184
|
}
|
|
1281
1185
|
return !!success;
|
|
1282
1186
|
},
|
|
@@ -1292,6 +1196,7 @@ export class SequencerPublisher {
|
|
|
1292
1196
|
*/
|
|
1293
1197
|
public interrupt() {
|
|
1294
1198
|
this.interrupted = true;
|
|
1199
|
+
this.interruptibleSleep.interrupt();
|
|
1295
1200
|
this.l1TxUtils.interrupt();
|
|
1296
1201
|
}
|
|
1297
1202
|
|
|
@@ -1301,11 +1206,7 @@ export class SequencerPublisher {
|
|
|
1301
1206
|
this.l1TxUtils.restart();
|
|
1302
1207
|
}
|
|
1303
1208
|
|
|
1304
|
-
private async prepareProposeTx(
|
|
1305
|
-
encodedData: L1ProcessArgs,
|
|
1306
|
-
timestamp: bigint,
|
|
1307
|
-
options: { forcePendingCheckpointNumber?: CheckpointNumber },
|
|
1308
|
-
) {
|
|
1209
|
+
private async prepareProposeTx(encodedData: L1ProcessArgs) {
|
|
1309
1210
|
const kzg = Blob.getViemKzgInstance();
|
|
1310
1211
|
const blobInput = getPrefixedEthBlobCommitments(encodedData.blobs);
|
|
1311
1212
|
this.log.debug('Validating blob input', { blobInput });
|
|
@@ -1318,7 +1219,11 @@ export class SequencerPublisher {
|
|
|
1318
1219
|
blobEvaluationGas = BigInt(encodedData.blobs.length) * 21_000n;
|
|
1319
1220
|
this.log.debug(`Using fixed blob evaluation gas estimate in fisherman mode: ${blobEvaluationGas}`);
|
|
1320
1221
|
} else {
|
|
1321
|
-
//
|
|
1222
|
+
// We call validateBlobs via estimateGas with real blob+kzg sidecars as a consistency check
|
|
1223
|
+
// that our locally-built blob commitments match the blob data. The bundle simulate at send
|
|
1224
|
+
// time uses eth_simulateV1, which cannot carry blob inputs, so the rollup's on-chain blob
|
|
1225
|
+
// check is forced off there — making this the only pre-flight detector of a commitment/data
|
|
1226
|
+
// mismatch. The returned gas estimate is stashed on the request for the bundle path to read.
|
|
1322
1227
|
blobEvaluationGas = await this.l1TxUtils
|
|
1323
1228
|
.estimateGas(
|
|
1324
1229
|
this.getSenderAddress().toString(),
|
|
@@ -1376,138 +1281,21 @@ export class SequencerPublisher {
|
|
|
1376
1281
|
blobInput,
|
|
1377
1282
|
] as const;
|
|
1378
1283
|
|
|
1379
|
-
const
|
|
1284
|
+
const rollupData = encodeFunctionData({ abi: RollupAbi, functionName: 'propose', args });
|
|
1380
1285
|
|
|
1381
|
-
return { args, blobEvaluationGas, rollupData
|
|
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();
|
|
1439
|
-
|
|
1440
|
-
const simulationResult = await this.l1TxUtils
|
|
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 };
|
|
1286
|
+
return { args, blobEvaluationGas, rollupData };
|
|
1489
1287
|
}
|
|
1490
1288
|
|
|
1491
1289
|
private async addProposeTx(
|
|
1492
1290
|
checkpoint: Checkpoint,
|
|
1493
1291
|
encodedData: L1ProcessArgs,
|
|
1494
|
-
opts:
|
|
1495
|
-
timestamp: bigint,
|
|
1292
|
+
opts: EnqueueProposeCheckpointOpts = {},
|
|
1496
1293
|
): Promise<void> {
|
|
1497
1294
|
const slot = checkpoint.header.slotNumber;
|
|
1498
1295
|
const timer = new Timer();
|
|
1499
1296
|
const kzg = Blob.getViemKzgInstance();
|
|
1500
|
-
const { rollupData,
|
|
1501
|
-
encodedData,
|
|
1502
|
-
timestamp,
|
|
1503
|
-
opts,
|
|
1504
|
-
);
|
|
1297
|
+
const { rollupData, blobEvaluationGas } = await this.prepareProposeTx(encodedData);
|
|
1505
1298
|
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
1299
|
|
|
1512
1300
|
// Send the blobs to the blob client preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
|
|
1513
1301
|
// 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 +1312,8 @@ export class SequencerPublisher {
|
|
|
1524
1312
|
data: rollupData,
|
|
1525
1313
|
},
|
|
1526
1314
|
lastValidL2Slot: checkpoint.header.slotNumber,
|
|
1527
|
-
gasConfig: {
|
|
1315
|
+
gasConfig: { txTimeoutAt: opts.txTimeoutAt, gasLimit: undefined },
|
|
1316
|
+
blobEvaluationGas,
|
|
1528
1317
|
blobConfig: {
|
|
1529
1318
|
blobs: encodedData.blobs.map(b => b.data),
|
|
1530
1319
|
kzg,
|
|
@@ -1534,10 +1323,11 @@ export class SequencerPublisher {
|
|
|
1534
1323
|
return false;
|
|
1535
1324
|
}
|
|
1536
1325
|
const { receipt, stats, errorMsg } = result;
|
|
1537
|
-
const success =
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1326
|
+
const success = extractEventSuccess(receipt, {
|
|
1327
|
+
address: this.rollupContract.address,
|
|
1328
|
+
abi: RollupAbi,
|
|
1329
|
+
eventName: 'CheckpointProposed',
|
|
1330
|
+
});
|
|
1541
1331
|
|
|
1542
1332
|
if (success) {
|
|
1543
1333
|
const endBlock = receipt.blockNumber;
|
|
@@ -1577,4 +1367,10 @@ export class SequencerPublisher {
|
|
|
1577
1367
|
},
|
|
1578
1368
|
});
|
|
1579
1369
|
}
|
|
1370
|
+
|
|
1371
|
+
/** Returns the timestamp of the next L1 slot boundary after now. */
|
|
1372
|
+
private getNextL1SlotTimestamp(): bigint {
|
|
1373
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
1374
|
+
return getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), l1Constants);
|
|
1375
|
+
}
|
|
1580
1376
|
}
|