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