@aztec/sequencer-client 3.0.3 → 3.9.9-nightly.20260312
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/dest/client/sequencer-client.d.ts +32 -15
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +116 -27
- package/dest/config.d.ts +29 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +103 -40
- package/dest/global_variable_builder/global_builder.d.ts +17 -11
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +48 -39
- 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 +33 -19
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +102 -43
- package/dest/publisher/sequencer-publisher-factory.d.ts +13 -5
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +14 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
- 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 +58 -45
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +628 -139
- package/dest/sequencer/checkpoint_proposal_job.d.ts +100 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1234 -0
- package/dest/sequencer/checkpoint_voter.d.ts +35 -0
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_voter.js +109 -0
- package/dest/sequencer/events.d.ts +46 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/index.d.ts +4 -2
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +3 -1
- package/dest/sequencer/metrics.d.ts +37 -5
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +216 -72
- package/dest/sequencer/sequencer.d.ts +122 -131
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +705 -635
- package/dest/sequencer/timetable.d.ts +54 -16
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +147 -62
- package/dest/sequencer/types.d.ts +3 -0
- package/dest/sequencer/types.d.ts.map +1 -0
- package/dest/sequencer/types.js +1 -0
- package/dest/sequencer/utils.d.ts +14 -8
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +7 -4
- package/dest/test/index.d.ts +5 -6
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +95 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +233 -0
- package/dest/test/utils.d.ts +53 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +104 -0
- package/package.json +30 -28
- package/src/client/sequencer-client.ts +154 -45
- package/src/config.ts +119 -45
- package/src/global_variable_builder/global_builder.ts +57 -51
- package/src/index.ts +1 -7
- package/src/publisher/config.ts +115 -46
- package/src/publisher/sequencer-publisher-factory.ts +26 -9
- package/src/publisher/sequencer-publisher-metrics.ts +19 -71
- package/src/publisher/sequencer-publisher.ts +334 -176
- package/src/sequencer/README.md +531 -0
- package/src/sequencer/checkpoint_proposal_job.ts +950 -0
- package/src/sequencer/checkpoint_voter.ts +130 -0
- package/src/sequencer/events.ts +27 -0
- package/src/sequencer/index.ts +3 -1
- package/src/sequencer/metrics.ts +267 -81
- package/src/sequencer/sequencer.ts +444 -834
- package/src/sequencer/timetable.ts +178 -83
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +18 -9
- package/src/test/index.ts +4 -5
- package/src/test/mock_checkpoint_builder.ts +325 -0
- package/src/test/utils.ts +167 -0
- package/dest/sequencer/block_builder.d.ts +0 -28
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -127
- 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 -214
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -133
|
@@ -1,300 +1,290 @@
|
|
|
1
|
-
import { L2Block } from '@aztec/aztec.js/block';
|
|
2
1
|
import { getKzg } from '@aztec/blob-lib';
|
|
3
|
-
import {
|
|
2
|
+
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
4
3
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
5
4
|
import { NoCommitteeError, type RollupContract } from '@aztec/ethereum/contracts';
|
|
6
|
-
import { FormattedViemError } from '@aztec/ethereum/utils';
|
|
7
5
|
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
8
|
-
import { omit, pick } from '@aztec/foundation/collection';
|
|
9
|
-
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
6
|
+
import { merge, omit, pick } from '@aztec/foundation/collection';
|
|
10
7
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
11
8
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
12
|
-
import { Signature } from '@aztec/foundation/eth-signature';
|
|
13
9
|
import { createLogger } from '@aztec/foundation/log';
|
|
14
10
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
11
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
12
|
+
import type { TypedEventEmitter } from '@aztec/foundation/types';
|
|
17
13
|
import type { P2P } from '@aztec/p2p';
|
|
18
14
|
import type { SlasherClientInterface } from '@aztec/slasher';
|
|
15
|
+
import type { BlockData, L2BlockSink, L2BlockSource, ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
16
|
+
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
17
|
+
import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
19
18
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
type L2BlockSource,
|
|
23
|
-
MaliciousCommitteeAttestationsAndSigners,
|
|
24
|
-
type ValidateBlockResult,
|
|
25
|
-
} from '@aztec/stdlib/block';
|
|
26
|
-
import { type L1RollupConstants, getSlotAtTimestamp, getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
27
|
-
import { Gas } from '@aztec/stdlib/gas';
|
|
28
|
-
import {
|
|
29
|
-
type IFullNodeBlockBuilder,
|
|
30
|
-
type PublicProcessorLimits,
|
|
19
|
+
type ResolvedSequencerConfig,
|
|
20
|
+
type SequencerConfig,
|
|
31
21
|
SequencerConfigSchema,
|
|
32
22
|
type WorldStateSynchronizer,
|
|
33
23
|
} from '@aztec/stdlib/interfaces/server';
|
|
34
24
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
35
|
-
import type { BlockProposalOptions } from '@aztec/stdlib/p2p';
|
|
36
|
-
import { orderAttestations } from '@aztec/stdlib/p2p';
|
|
37
|
-
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
38
25
|
import { pickFromSchema } from '@aztec/stdlib/schemas';
|
|
39
|
-
import type { L2BlockBuiltStats } from '@aztec/stdlib/stats';
|
|
40
26
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
41
|
-
import { ContentCommitment, type FailedTx, GlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
42
|
-
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
43
27
|
import { Attributes, type TelemetryClient, type Tracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
44
|
-
import type
|
|
28
|
+
import { FullNodeCheckpointsBuilder, NodeKeystoreAdapter, type ValidatorClient } from '@aztec/validator-client';
|
|
45
29
|
|
|
46
30
|
import EventEmitter from 'node:events';
|
|
47
|
-
import type { TypedDataDefinition } from 'viem';
|
|
48
31
|
|
|
32
|
+
import { DefaultSequencerConfig } from '../config.js';
|
|
49
33
|
import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
50
34
|
import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
|
|
51
|
-
import type {
|
|
52
|
-
import
|
|
35
|
+
import type { InvalidateCheckpointRequest, SequencerPublisher } from '../publisher/sequencer-publisher.js';
|
|
36
|
+
import { CheckpointProposalJob } from './checkpoint_proposal_job.js';
|
|
37
|
+
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
53
38
|
import { SequencerInterruptedError, SequencerTooSlowError } from './errors.js';
|
|
39
|
+
import type { SequencerEvents } from './events.js';
|
|
54
40
|
import { SequencerMetrics } from './metrics.js';
|
|
55
41
|
import { SequencerTimetable } from './timetable.js';
|
|
56
|
-
import {
|
|
42
|
+
import type { SequencerRollupConstants } from './types.js';
|
|
43
|
+
import { SequencerState } from './utils.js';
|
|
57
44
|
|
|
58
45
|
export { SequencerState };
|
|
59
46
|
|
|
60
|
-
type SequencerRollupConstants = Pick<L1RollupConstants, 'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration'>;
|
|
61
|
-
|
|
62
|
-
export type SequencerEvents = {
|
|
63
|
-
['state-changed']: (args: {
|
|
64
|
-
oldState: SequencerState;
|
|
65
|
-
newState: SequencerState;
|
|
66
|
-
secondsIntoSlot?: number;
|
|
67
|
-
slotNumber?: SlotNumber;
|
|
68
|
-
}) => void;
|
|
69
|
-
['proposer-rollup-check-failed']: (args: { reason: string }) => void;
|
|
70
|
-
['tx-count-check-failed']: (args: { minTxs: number; availableTxs: number }) => void;
|
|
71
|
-
['block-build-failed']: (args: { reason: string }) => void;
|
|
72
|
-
['block-publish-failed']: (args: {
|
|
73
|
-
successfulActions?: Action[];
|
|
74
|
-
failedActions?: Action[];
|
|
75
|
-
sentActions?: Action[];
|
|
76
|
-
expiredActions?: Action[];
|
|
77
|
-
}) => void;
|
|
78
|
-
['block-published']: (args: { blockNumber: BlockNumber; slot: number }) => void;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
47
|
/**
|
|
82
48
|
* Sequencer client
|
|
83
|
-
* -
|
|
84
|
-
* -
|
|
85
|
-
* -
|
|
86
|
-
* -
|
|
87
|
-
* -
|
|
88
|
-
* - Publishes L1 tx(s) to the rollup contract via RollupPublisher.
|
|
49
|
+
* - Checks whether it is elected as proposer for the next slot
|
|
50
|
+
* - Builds multiple blocks and broadcasts them
|
|
51
|
+
* - Collects attestations for the checkpoint
|
|
52
|
+
* - Publishes the checkpoint to L1
|
|
53
|
+
* - Votes for proposals and slashes on L1
|
|
89
54
|
*/
|
|
90
55
|
export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<SequencerEvents>) {
|
|
91
56
|
private runningPromise?: RunningPromise;
|
|
92
|
-
private pollingIntervalMs: number = 1000;
|
|
93
|
-
private maxTxsPerBlock = 32;
|
|
94
|
-
private minTxsPerBlock = 1;
|
|
95
|
-
private maxL1TxInclusionTimeIntoSlot = 0;
|
|
96
57
|
private state = SequencerState.STOPPED;
|
|
97
|
-
private maxBlockSizeInBytes: number = 1024 * 1024;
|
|
98
|
-
private maxBlockGas: Gas = new Gas(100e9, 100e9);
|
|
99
58
|
private metrics: SequencerMetrics;
|
|
100
59
|
|
|
101
|
-
|
|
60
|
+
/** The last slot for which we attempted to perform our voting duties with degraded block production */
|
|
61
|
+
private lastSlotForFallbackVote: SlotNumber | undefined;
|
|
102
62
|
|
|
103
|
-
|
|
63
|
+
/** The last slot for which we logged "no committee" warning, to avoid spam */
|
|
64
|
+
private lastSlotForNoCommitteeWarning: SlotNumber | undefined;
|
|
104
65
|
|
|
105
|
-
/** The last slot for which we
|
|
106
|
-
private
|
|
66
|
+
/** The last slot for which we triggered a checkpoint proposal job, to prevent duplicate attempts. */
|
|
67
|
+
private lastSlotForCheckpointProposalJob: SlotNumber | undefined;
|
|
107
68
|
|
|
108
|
-
/**
|
|
109
|
-
private
|
|
69
|
+
/** Last successful checkpoint proposed */
|
|
70
|
+
private lastCheckpointProposed: Checkpoint | undefined;
|
|
71
|
+
|
|
72
|
+
/** The last epoch for which we logged strategy comparison in fisherman mode. */
|
|
73
|
+
private lastEpochForStrategyComparison: EpochNumber | undefined;
|
|
110
74
|
|
|
111
75
|
/** The maximum number of seconds that the sequencer can be into a slot to transition to a particular state. */
|
|
112
76
|
protected timetable!: SequencerTimetable;
|
|
113
|
-
protected enforceTimeTable: boolean = false;
|
|
114
77
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
// As long as those tests only configure a single publisher they will continue to work.
|
|
118
|
-
// This will get re-assigned every time the sequencer goes to build a new block to a publisher that is valid
|
|
119
|
-
// for the block proposer.
|
|
120
|
-
protected publisher: SequencerPublisher | undefined;
|
|
78
|
+
/** Config for the sequencer */
|
|
79
|
+
protected config: ResolvedSequencerConfig = DefaultSequencerConfig;
|
|
121
80
|
|
|
122
81
|
constructor(
|
|
123
82
|
protected publisherFactory: SequencerPublisherFactory,
|
|
124
|
-
protected validatorClient: ValidatorClient
|
|
83
|
+
protected validatorClient: ValidatorClient,
|
|
125
84
|
protected globalsBuilder: GlobalVariableBuilder,
|
|
126
85
|
protected p2pClient: P2P,
|
|
127
86
|
protected worldState: WorldStateSynchronizer,
|
|
128
87
|
protected slasherClient: SlasherClientInterface | undefined,
|
|
129
|
-
protected l2BlockSource: L2BlockSource,
|
|
88
|
+
protected l2BlockSource: L2BlockSource & L2BlockSink,
|
|
130
89
|
protected l1ToL2MessageSource: L1ToL2MessageSource,
|
|
131
|
-
protected
|
|
90
|
+
protected checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
132
91
|
protected l1Constants: SequencerRollupConstants,
|
|
133
92
|
protected dateProvider: DateProvider,
|
|
134
93
|
protected epochCache: EpochCache,
|
|
135
94
|
protected rollupContract: RollupContract,
|
|
136
|
-
|
|
95
|
+
config: SequencerConfig,
|
|
137
96
|
protected telemetry: TelemetryClient = getTelemetryClient(),
|
|
138
97
|
protected log = createLogger('sequencer'),
|
|
139
98
|
) {
|
|
140
99
|
super();
|
|
141
100
|
|
|
142
101
|
// Add [FISHERMAN] prefix to logger if in fisherman mode
|
|
143
|
-
if (
|
|
102
|
+
if (config.fishermanMode) {
|
|
144
103
|
this.log = log.createChild('[FISHERMAN]');
|
|
145
104
|
}
|
|
146
105
|
|
|
147
106
|
this.metrics = new SequencerMetrics(telemetry, this.rollupContract, 'Sequencer');
|
|
148
|
-
|
|
149
|
-
this.updateConfig(this.config);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
get tracer(): Tracer {
|
|
153
|
-
return this.metrics.tracer;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
public getValidatorAddresses() {
|
|
157
|
-
return this.validatorClient?.getValidatorAddresses();
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
public getConfig() {
|
|
161
|
-
return this.config;
|
|
107
|
+
this.updateConfig(config);
|
|
162
108
|
}
|
|
163
109
|
|
|
164
|
-
/**
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
this.log.info(
|
|
170
|
-
`Sequencer config set`,
|
|
171
|
-
omit(pickFromSchema(config, SequencerConfigSchema), 'txPublicSetupAllowList'),
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
if (config.transactionPollingIntervalMS !== undefined) {
|
|
175
|
-
this.pollingIntervalMs = config.transactionPollingIntervalMS;
|
|
176
|
-
}
|
|
177
|
-
if (config.maxTxsPerBlock !== undefined) {
|
|
178
|
-
this.maxTxsPerBlock = config.maxTxsPerBlock;
|
|
179
|
-
}
|
|
180
|
-
if (config.minTxsPerBlock !== undefined) {
|
|
181
|
-
this.minTxsPerBlock = config.minTxsPerBlock;
|
|
182
|
-
}
|
|
183
|
-
if (config.maxDABlockGas !== undefined) {
|
|
184
|
-
this.maxBlockGas = new Gas(config.maxDABlockGas, this.maxBlockGas.l2Gas);
|
|
185
|
-
}
|
|
186
|
-
if (config.maxL2BlockGas !== undefined) {
|
|
187
|
-
this.maxBlockGas = new Gas(this.maxBlockGas.daGas, config.maxL2BlockGas);
|
|
188
|
-
}
|
|
189
|
-
if (config.maxBlockSizeInBytes !== undefined) {
|
|
190
|
-
this.maxBlockSizeInBytes = config.maxBlockSizeInBytes;
|
|
191
|
-
}
|
|
192
|
-
if (config.governanceProposerPayload) {
|
|
193
|
-
this.governanceProposerPayload = config.governanceProposerPayload;
|
|
194
|
-
}
|
|
195
|
-
if (config.maxL1TxInclusionTimeIntoSlot !== undefined) {
|
|
196
|
-
this.maxL1TxInclusionTimeIntoSlot = config.maxL1TxInclusionTimeIntoSlot;
|
|
197
|
-
}
|
|
198
|
-
if (config.enforceTimeTable !== undefined) {
|
|
199
|
-
this.enforceTimeTable = config.enforceTimeTable;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
this.setTimeTable();
|
|
203
|
-
|
|
204
|
-
// TODO: Just read everything from the config object as needed instead of copying everything into local vars.
|
|
205
|
-
|
|
206
|
-
// Update all values on this.config that are populated in the config object.
|
|
207
|
-
Object.assign(this.config, config);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
private setTimeTable() {
|
|
110
|
+
/** Updates sequencer config by the defined values and updates the timetable */
|
|
111
|
+
public updateConfig(config: Partial<SequencerConfig>) {
|
|
112
|
+
const filteredConfig = pickFromSchema(config, SequencerConfigSchema);
|
|
113
|
+
this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowListExtend'));
|
|
114
|
+
this.config = merge(this.config, filteredConfig);
|
|
211
115
|
this.timetable = new SequencerTimetable(
|
|
212
116
|
{
|
|
213
117
|
ethereumSlotDuration: this.l1Constants.ethereumSlotDuration,
|
|
214
118
|
aztecSlotDuration: this.aztecSlotDuration,
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
119
|
+
l1PublishingTime: this.l1PublishingTime,
|
|
120
|
+
p2pPropagationTime: this.config.attestationPropagationTime,
|
|
121
|
+
blockDurationMs: this.config.blockDurationMs,
|
|
122
|
+
enforce: this.config.enforceTimeTable,
|
|
218
123
|
},
|
|
219
124
|
this.metrics,
|
|
220
125
|
this.log,
|
|
221
126
|
);
|
|
222
127
|
}
|
|
223
128
|
|
|
224
|
-
|
|
225
|
-
|
|
129
|
+
/** Initializes the sequencer (precomputes tables). Takes about 3s. */
|
|
130
|
+
public init() {
|
|
226
131
|
getKzg();
|
|
227
|
-
this.publisher = (await this.publisherFactory.create(undefined)).publisher;
|
|
228
132
|
}
|
|
229
133
|
|
|
230
|
-
/**
|
|
231
|
-
* Starts the sequencer and moves to IDLE state.
|
|
232
|
-
*/
|
|
134
|
+
/** Starts the sequencer and moves to IDLE state. */
|
|
233
135
|
public start() {
|
|
234
|
-
this.runningPromise = new RunningPromise(
|
|
136
|
+
this.runningPromise = new RunningPromise(
|
|
137
|
+
this.safeWork.bind(this),
|
|
138
|
+
this.log,
|
|
139
|
+
this.config.sequencerPollingIntervalMS,
|
|
140
|
+
);
|
|
235
141
|
this.setState(SequencerState.IDLE, undefined, { force: true });
|
|
236
142
|
this.runningPromise.start();
|
|
237
143
|
this.log.info('Started sequencer');
|
|
238
144
|
}
|
|
239
145
|
|
|
240
|
-
/**
|
|
241
|
-
* Stops the sequencer from processing txs and moves to STOPPED state.
|
|
242
|
-
*/
|
|
146
|
+
/** Stops the sequencer from building blocks and moves to STOPPED state. */
|
|
243
147
|
public async stop(): Promise<void> {
|
|
244
148
|
this.log.info(`Stopping sequencer`);
|
|
245
149
|
this.setState(SequencerState.STOPPING, undefined, { force: true });
|
|
246
|
-
this.
|
|
150
|
+
this.publisherFactory.interruptAll();
|
|
247
151
|
await this.runningPromise?.stop();
|
|
248
152
|
this.setState(SequencerState.STOPPED, undefined, { force: true });
|
|
249
153
|
this.log.info('Stopped sequencer');
|
|
250
154
|
}
|
|
251
155
|
|
|
252
|
-
/**
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
156
|
+
/** Main sequencer loop with a try/catch */
|
|
157
|
+
protected async safeWork() {
|
|
158
|
+
try {
|
|
159
|
+
await this.work();
|
|
160
|
+
} catch (err) {
|
|
161
|
+
this.emit('checkpoint-error', { error: err as Error });
|
|
162
|
+
if (err instanceof SequencerTooSlowError) {
|
|
163
|
+
// Log as warn only if we had to abort halfway through the block proposal
|
|
164
|
+
const logLvl = [SequencerState.INITIALIZING_CHECKPOINT, SequencerState.PROPOSER_CHECK].includes(
|
|
165
|
+
err.proposedState,
|
|
166
|
+
)
|
|
167
|
+
? ('debug' as const)
|
|
168
|
+
: ('warn' as const);
|
|
169
|
+
this.log[logLvl](err.message, { now: this.dateProvider.nowInSeconds() });
|
|
170
|
+
} else {
|
|
171
|
+
// Re-throw other errors
|
|
172
|
+
throw err;
|
|
173
|
+
}
|
|
174
|
+
} finally {
|
|
175
|
+
this.setState(SequencerState.IDLE, undefined);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Returns the current state of the sequencer. */
|
|
256
180
|
public status() {
|
|
257
181
|
return { state: this.state };
|
|
258
182
|
}
|
|
259
183
|
|
|
260
184
|
/**
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
185
|
+
* Main sequencer loop:
|
|
186
|
+
* - Checks if we are up to date
|
|
187
|
+
* - If we are and we are the sequencer, collect txs and build blocks
|
|
188
|
+
* - Build multiple blocks per slot when configured
|
|
189
|
+
* - Collect attestations for the final block
|
|
190
|
+
* - Submit checkpoint
|
|
267
191
|
*/
|
|
192
|
+
@trackSpan('Sequencer.work')
|
|
268
193
|
protected async work() {
|
|
269
194
|
this.setState(SequencerState.SYNCHRONIZING, undefined);
|
|
270
|
-
const { slot, ts, now } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
195
|
+
const { slot, ts, now, epoch } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
271
196
|
|
|
272
|
-
// Check we
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
`Cannot propose block at next L2 slot ${slot} since that slot was taken by our own block ${this.lastBlockPublished.number}`,
|
|
276
|
-
);
|
|
197
|
+
// Check if we are synced and it's our slot, grab a publisher, check previous block invalidation, etc
|
|
198
|
+
const checkpointProposalJob = await this.prepareCheckpointProposal(epoch, slot, ts, now);
|
|
199
|
+
if (!checkpointProposalJob) {
|
|
277
200
|
return;
|
|
278
201
|
}
|
|
279
202
|
|
|
203
|
+
// Execute the checkpoint proposal job
|
|
204
|
+
const checkpoint = await checkpointProposalJob.execute();
|
|
205
|
+
|
|
206
|
+
// Update last checkpoint proposed (currently unused)
|
|
207
|
+
if (checkpoint) {
|
|
208
|
+
this.lastCheckpointProposed = checkpoint;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Log fee strategy comparison if on fisherman
|
|
212
|
+
if (
|
|
213
|
+
this.config.fishermanMode &&
|
|
214
|
+
(this.lastEpochForStrategyComparison === undefined || epoch > this.lastEpochForStrategyComparison)
|
|
215
|
+
) {
|
|
216
|
+
this.logStrategyComparison(epoch, checkpointProposalJob.getPublisher());
|
|
217
|
+
this.lastEpochForStrategyComparison = epoch;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return checkpoint;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Prepares the checkpoint proposal by performing all necessary checks and setup.
|
|
225
|
+
* This is the initial step in the main loop.
|
|
226
|
+
* @returns CheckpointProposalJob if successful, undefined if we are not yet synced or are not the proposer.
|
|
227
|
+
*/
|
|
228
|
+
@trackSpan('Sequencer.prepareCheckpointProposal')
|
|
229
|
+
private async prepareCheckpointProposal(
|
|
230
|
+
epoch: EpochNumber,
|
|
231
|
+
slot: SlotNumber,
|
|
232
|
+
ts: bigint,
|
|
233
|
+
now: bigint,
|
|
234
|
+
): Promise<CheckpointProposalJob | undefined> {
|
|
235
|
+
// Check we have not already processed this slot (cheapest check)
|
|
236
|
+
// We only check this if enforce timetable is set, since we want to keep processing the same slot if we are not
|
|
237
|
+
// running against actual time (eg when we use sandbox-style automining)
|
|
238
|
+
if (
|
|
239
|
+
this.lastSlotForCheckpointProposalJob &&
|
|
240
|
+
this.lastSlotForCheckpointProposalJob >= slot &&
|
|
241
|
+
this.config.enforceTimeTable
|
|
242
|
+
) {
|
|
243
|
+
this.log.trace(`Slot ${slot} has already been processed`);
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// But if we have already proposed for this slot, the we definitely have to skip it, automining or not
|
|
248
|
+
if (this.lastCheckpointProposed && this.lastCheckpointProposed.header.slotNumber >= slot) {
|
|
249
|
+
this.log.trace(`Slot ${slot} has already been published as checkpoint ${this.lastCheckpointProposed.number}`);
|
|
250
|
+
return undefined;
|
|
251
|
+
}
|
|
252
|
+
|
|
280
253
|
// Check all components are synced to latest as seen by the archiver (queries all subsystems)
|
|
281
254
|
const syncedTo = await this.checkSync({ ts, slot });
|
|
282
255
|
if (!syncedTo) {
|
|
283
256
|
await this.tryVoteWhenSyncFails({ slot, ts });
|
|
284
|
-
return;
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// If escape hatch is open for this epoch, do not start checkpoint proposal work and do not attempt invalidations.
|
|
261
|
+
// Still perform governance/slashing voting (as proposer) once per slot.
|
|
262
|
+
const isEscapeHatchOpen = await this.epochCache.isEscapeHatchOpen(epoch);
|
|
263
|
+
|
|
264
|
+
if (isEscapeHatchOpen) {
|
|
265
|
+
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
266
|
+
const [canPropose, proposer] = await this.checkCanPropose(slot);
|
|
267
|
+
if (canPropose) {
|
|
268
|
+
await this.tryVoteWhenEscapeHatchOpen({ slot, proposer });
|
|
269
|
+
} else {
|
|
270
|
+
this.log.trace(`Escape hatch open but we are not proposer, skipping vote-only actions`, {
|
|
271
|
+
slot,
|
|
272
|
+
epoch,
|
|
273
|
+
proposer,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
return undefined;
|
|
285
277
|
}
|
|
286
278
|
|
|
287
|
-
|
|
288
|
-
const
|
|
279
|
+
// Next checkpoint follows from the last synced one
|
|
280
|
+
const checkpointNumber = CheckpointNumber(syncedTo.checkpointNumber + 1);
|
|
289
281
|
|
|
290
|
-
const
|
|
282
|
+
const logCtx = {
|
|
291
283
|
now,
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
l1SlotDuration: this.l1Constants.ethereumSlotDuration,
|
|
297
|
-
newBlockNumber,
|
|
284
|
+
syncedToL2Slot: syncedTo.syncedL2Slot,
|
|
285
|
+
slot,
|
|
286
|
+
slotTs: ts,
|
|
287
|
+
checkpointNumber,
|
|
298
288
|
isPendingChainValid: pick(syncedTo.pendingChainValidationStatus, 'valid', 'reason', 'invalidIndex'),
|
|
299
289
|
};
|
|
300
290
|
|
|
@@ -302,269 +292,153 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
302
292
|
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
303
293
|
const [canPropose, proposer] = await this.checkCanPropose(slot);
|
|
304
294
|
|
|
305
|
-
// If we are not a proposer check if we should invalidate
|
|
295
|
+
// If we are not a proposer check if we should invalidate an invalid checkpoint, and bail
|
|
306
296
|
if (!canPropose) {
|
|
307
|
-
await this.
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// In fisherman mode, check if we've already validated this slot to prevent duplicate attempts
|
|
312
|
-
if (this.config.fishermanMode) {
|
|
313
|
-
if (this.lastSlotForValidationBlock === slot) {
|
|
314
|
-
this.log.trace(`Already validated block building for slot ${slot} (skipping)`, { slot });
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
this.log.debug(
|
|
318
|
-
`Building validation block for slot ${slot} (actual proposer: ${proposer?.toString() ?? 'none'})`,
|
|
319
|
-
{ slot, proposer: proposer?.toString() },
|
|
320
|
-
);
|
|
321
|
-
// Mark this slot as being validated
|
|
322
|
-
this.lastSlotForValidationBlock = slot;
|
|
297
|
+
await this.considerInvalidatingCheckpoint(syncedTo, slot);
|
|
298
|
+
return undefined;
|
|
323
299
|
}
|
|
324
300
|
|
|
325
301
|
// Check that the slot is not taken by a block already (should never happen, since only us can propose for this slot)
|
|
326
|
-
if (syncedTo.
|
|
302
|
+
if (syncedTo.blockData && syncedTo.blockData.header.getSlot() >= slot) {
|
|
327
303
|
this.log.warn(
|
|
328
304
|
`Cannot propose block at next L2 slot ${slot} since that slot was taken by block ${syncedTo.blockNumber}`,
|
|
329
|
-
{ ...
|
|
305
|
+
{ ...logCtx, block: syncedTo.blockData.header.toInspect() },
|
|
330
306
|
);
|
|
331
|
-
this.metrics.
|
|
332
|
-
return;
|
|
307
|
+
this.metrics.recordCheckpointPrecheckFailed('slot_already_taken');
|
|
308
|
+
return undefined;
|
|
333
309
|
}
|
|
334
310
|
|
|
335
311
|
// We now need to get ourselves a publisher.
|
|
336
312
|
// The returned attestor will be the one we provided if we provided one.
|
|
337
313
|
// Otherwise it will be a valid attestor for the returned publisher.
|
|
338
314
|
// In fisherman mode, pass undefined to use the fisherman's own keystore instead of the actual proposer's
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
);
|
|
315
|
+
const proposerForPublisher = this.config.fishermanMode ? undefined : proposer;
|
|
316
|
+
const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
|
|
342
317
|
this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
|
|
343
|
-
this.publisher = publisher;
|
|
344
318
|
|
|
345
319
|
// In fisherman mode, set the actual proposer's address for simulations
|
|
346
|
-
if (this.config.fishermanMode) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
this.log.debug(`Set proposer address ${proposer} for simulation in fisherman mode`);
|
|
350
|
-
}
|
|
320
|
+
if (this.config.fishermanMode && proposer) {
|
|
321
|
+
publisher.setProposerAddressForSimulation(proposer);
|
|
322
|
+
this.log.debug(`Set proposer address ${proposer} for simulation in fisherman mode`);
|
|
351
323
|
}
|
|
352
324
|
|
|
353
|
-
// Get proposer credentials
|
|
354
|
-
const coinbase = this.validatorClient!.getCoinbaseForAttestor(attestorAddress);
|
|
355
|
-
const feeRecipient = this.validatorClient!.getFeeRecipientForAttestor(attestorAddress);
|
|
356
|
-
|
|
357
325
|
// Prepare invalidation request if the pending chain is invalid (returns undefined if no need)
|
|
358
|
-
const
|
|
326
|
+
const invalidateCheckpoint = await publisher.simulateInvalidateCheckpoint(syncedTo.pendingChainValidationStatus);
|
|
359
327
|
|
|
360
|
-
// Check with the rollup if we can indeed propose at the next L2 slot. This check should not fail
|
|
328
|
+
// Check with the rollup contract if we can indeed propose at the next L2 slot. This check should not fail
|
|
361
329
|
// if all the previous checks are good, but we do it just in case.
|
|
362
330
|
const canProposeCheck = await publisher.canProposeAtNextEthBlock(
|
|
363
|
-
|
|
331
|
+
syncedTo.archive,
|
|
364
332
|
proposer ?? EthAddress.ZERO,
|
|
365
|
-
|
|
333
|
+
invalidateCheckpoint,
|
|
366
334
|
);
|
|
367
335
|
|
|
368
336
|
if (canProposeCheck === undefined) {
|
|
369
337
|
this.log.warn(
|
|
370
|
-
`Cannot propose
|
|
371
|
-
|
|
338
|
+
`Cannot propose checkpoint ${checkpointNumber} at slot ${slot} due to failed rollup contract check`,
|
|
339
|
+
logCtx,
|
|
372
340
|
);
|
|
373
|
-
this.emit('proposer-rollup-check-failed', { reason: 'Rollup contract check failed' });
|
|
374
|
-
this.metrics.
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
341
|
+
this.emit('proposer-rollup-check-failed', { reason: 'Rollup contract check failed', slot });
|
|
342
|
+
this.metrics.recordCheckpointPrecheckFailed('rollup_contract_check_failed');
|
|
343
|
+
return undefined;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (canProposeCheck.slot !== slot) {
|
|
377
347
|
this.log.warn(
|
|
378
348
|
`Cannot propose block due to slot mismatch with rollup contract (this can be caused by a clock out of sync). Expected slot ${slot} but got ${canProposeCheck.slot}.`,
|
|
379
|
-
{ ...
|
|
349
|
+
{ ...logCtx, rollup: canProposeCheck, expectedSlot: slot },
|
|
380
350
|
);
|
|
381
|
-
this.emit('proposer-rollup-check-failed', { reason: 'Slot mismatch' });
|
|
382
|
-
this.metrics.
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
351
|
+
this.emit('proposer-rollup-check-failed', { reason: 'Slot mismatch', slot });
|
|
352
|
+
this.metrics.recordCheckpointPrecheckFailed('slot_mismatch');
|
|
353
|
+
return undefined;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (canProposeCheck.checkpointNumber !== checkpointNumber) {
|
|
385
357
|
this.log.warn(
|
|
386
|
-
`Cannot propose
|
|
387
|
-
{ ...
|
|
358
|
+
`Cannot propose due to block mismatch with rollup contract (this can be caused by a pending archiver sync). Expected checkpoint ${checkpointNumber} but got ${canProposeCheck.checkpointNumber}.`,
|
|
359
|
+
{ ...logCtx, rollup: canProposeCheck, expectedSlot: slot },
|
|
388
360
|
);
|
|
389
|
-
this.emit('proposer-rollup-check-failed', { reason: 'Block mismatch' });
|
|
390
|
-
this.metrics.
|
|
391
|
-
return;
|
|
361
|
+
this.emit('proposer-rollup-check-failed', { reason: 'Block mismatch', slot });
|
|
362
|
+
this.metrics.recordCheckpointPrecheckFailed('block_number_mismatch');
|
|
363
|
+
return undefined;
|
|
392
364
|
}
|
|
393
365
|
|
|
394
|
-
this.
|
|
366
|
+
this.lastSlotForCheckpointProposalJob = slot;
|
|
367
|
+
await this.p2pClient.prepareForSlot(slot);
|
|
368
|
+
this.log.info(`Preparing checkpoint proposal ${checkpointNumber} at slot ${slot}`, { ...logCtx, proposer });
|
|
395
369
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
feeRecipient,
|
|
400
|
-
slot,
|
|
401
|
-
);
|
|
402
|
-
|
|
403
|
-
// Enqueue governance and slashing votes (returns promises that will be awaited later)
|
|
404
|
-
// In fisherman mode, we simulate slashing but don't actually publish to L1
|
|
405
|
-
const votesPromises = this.enqueueGovernanceAndSlashingVotes(
|
|
406
|
-
publisher,
|
|
407
|
-
attestorAddress,
|
|
408
|
-
slot,
|
|
409
|
-
newGlobalVariables.timestamp,
|
|
410
|
-
);
|
|
411
|
-
|
|
412
|
-
// Enqueues block invalidation
|
|
413
|
-
if (invalidateBlock && !this.config.skipInvalidateBlockAsProposer) {
|
|
414
|
-
publisher.enqueueInvalidateBlock(invalidateBlock);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// Actual block building
|
|
418
|
-
this.setState(SequencerState.INITIALIZING_PROPOSAL, slot);
|
|
419
|
-
this.metrics.incOpenSlot(slot, proposer?.toString() ?? 'unknown');
|
|
420
|
-
const block: L2Block | undefined = await this.tryBuildBlockAndEnqueuePublish(
|
|
370
|
+
// Create and return the checkpoint proposal job
|
|
371
|
+
return this.createCheckpointProposalJob(
|
|
372
|
+
epoch,
|
|
421
373
|
slot,
|
|
374
|
+
checkpointNumber,
|
|
375
|
+
syncedTo.blockNumber,
|
|
422
376
|
proposer,
|
|
423
|
-
newBlockNumber,
|
|
424
377
|
publisher,
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
invalidateBlock,
|
|
378
|
+
attestorAddress,
|
|
379
|
+
invalidateCheckpoint,
|
|
428
380
|
);
|
|
429
|
-
|
|
430
|
-
// Wait until the voting promises have resolved, so all requests are enqueued
|
|
431
|
-
await Promise.all(votesPromises);
|
|
432
|
-
|
|
433
|
-
// In fisherman mode, we don't publish to L1
|
|
434
|
-
if (this.config.fishermanMode) {
|
|
435
|
-
// Clear pending requests
|
|
436
|
-
publisher.clearPendingRequests();
|
|
437
|
-
|
|
438
|
-
if (block) {
|
|
439
|
-
this.log.info(`Validation block building SUCCEEDED for slot ${slot}`, {
|
|
440
|
-
blockNumber: newBlockNumber,
|
|
441
|
-
slot: Number(slot),
|
|
442
|
-
archive: block.archive.toString(),
|
|
443
|
-
txCount: block.body.txEffects.length,
|
|
444
|
-
});
|
|
445
|
-
this.lastBlockPublished = block;
|
|
446
|
-
this.metrics.recordBlockProposalSuccess();
|
|
447
|
-
} else {
|
|
448
|
-
// Block building failed in fisherman mode
|
|
449
|
-
this.log.warn(`Validation block building FAILED for slot ${slot}`, {
|
|
450
|
-
blockNumber: newBlockNumber,
|
|
451
|
-
slot: Number(slot),
|
|
452
|
-
});
|
|
453
|
-
this.metrics.recordBlockProposalFailed('block_build_failed');
|
|
454
|
-
}
|
|
455
|
-
} else {
|
|
456
|
-
// Normal mode: send the tx to L1
|
|
457
|
-
const l1Response = await publisher.sendRequests();
|
|
458
|
-
const proposedBlock = l1Response?.successfulActions.find(a => a === 'propose');
|
|
459
|
-
if (proposedBlock) {
|
|
460
|
-
this.lastBlockPublished = block;
|
|
461
|
-
this.emit('block-published', { blockNumber: newBlockNumber, slot: Number(slot) });
|
|
462
|
-
await this.metrics.incFilledSlot(publisher.getSenderAddress().toString(), coinbase);
|
|
463
|
-
} else if (block) {
|
|
464
|
-
this.emit('block-publish-failed', l1Response ?? {});
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
this.setState(SequencerState.IDLE, undefined);
|
|
469
381
|
}
|
|
470
382
|
|
|
471
|
-
|
|
472
|
-
|
|
383
|
+
protected createCheckpointProposalJob(
|
|
384
|
+
epoch: EpochNumber,
|
|
473
385
|
slot: SlotNumber,
|
|
386
|
+
checkpointNumber: CheckpointNumber,
|
|
387
|
+
syncedToBlockNumber: BlockNumber,
|
|
474
388
|
proposer: EthAddress | undefined,
|
|
475
|
-
newBlockNumber: BlockNumber,
|
|
476
389
|
publisher: SequencerPublisher,
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
proposer,
|
|
483
|
-
publisher: publisher.getSenderAddress(),
|
|
484
|
-
globalVariables: newGlobalVariables.toInspect(),
|
|
485
|
-
chainTipArchive,
|
|
486
|
-
blockNumber: newBlockNumber,
|
|
390
|
+
attestorAddress: EthAddress,
|
|
391
|
+
invalidateCheckpoint: InvalidateCheckpointRequest | undefined,
|
|
392
|
+
): CheckpointProposalJob {
|
|
393
|
+
return new CheckpointProposalJob(
|
|
394
|
+
epoch,
|
|
487
395
|
slot,
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
);
|
|
515
|
-
} catch (err: any) {
|
|
516
|
-
this.emit('block-build-failed', { reason: err.message });
|
|
517
|
-
if (err instanceof FormattedViemError) {
|
|
518
|
-
this.log.verbose(`Unable to build/enqueue block ${err.message}`);
|
|
519
|
-
} else {
|
|
520
|
-
this.log.error(`Error building/enqueuing block`, err, { blockNumber: newBlockNumber, slot });
|
|
521
|
-
}
|
|
522
|
-
this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
|
|
523
|
-
}
|
|
524
|
-
} else {
|
|
525
|
-
this.log.verbose(
|
|
526
|
-
`Not enough txs to build block ${newBlockNumber} at slot ${slot} (got ${pendingTxCount} txs, need ${this.minTxsPerBlock})`,
|
|
527
|
-
{ chainTipArchive, blockNumber: newBlockNumber, slot },
|
|
528
|
-
);
|
|
529
|
-
this.emit('tx-count-check-failed', { minTxs: this.minTxsPerBlock, availableTxs: pendingTxCount });
|
|
530
|
-
this.metrics.recordBlockProposalFailed('insufficient_txs');
|
|
531
|
-
}
|
|
532
|
-
return block;
|
|
396
|
+
checkpointNumber,
|
|
397
|
+
syncedToBlockNumber,
|
|
398
|
+
proposer,
|
|
399
|
+
publisher,
|
|
400
|
+
attestorAddress,
|
|
401
|
+
invalidateCheckpoint,
|
|
402
|
+
this.validatorClient,
|
|
403
|
+
this.globalsBuilder,
|
|
404
|
+
this.p2pClient,
|
|
405
|
+
this.worldState,
|
|
406
|
+
this.l1ToL2MessageSource,
|
|
407
|
+
this.l2BlockSource,
|
|
408
|
+
this.checkpointsBuilder,
|
|
409
|
+
this.l2BlockSource,
|
|
410
|
+
this.l1Constants,
|
|
411
|
+
this.config,
|
|
412
|
+
this.timetable,
|
|
413
|
+
this.slasherClient,
|
|
414
|
+
this.epochCache,
|
|
415
|
+
this.dateProvider,
|
|
416
|
+
this.metrics,
|
|
417
|
+
this,
|
|
418
|
+
this.setState.bind(this),
|
|
419
|
+
this.tracer,
|
|
420
|
+
this.log.getBindings(),
|
|
421
|
+
);
|
|
533
422
|
}
|
|
534
423
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
if (err instanceof SequencerTooSlowError) {
|
|
541
|
-
// Log as warn only if we had to abort halfway through the block proposal
|
|
542
|
-
const logLvl = [SequencerState.INITIALIZING_PROPOSAL, SequencerState.PROPOSER_CHECK].includes(err.proposedState)
|
|
543
|
-
? ('debug' as const)
|
|
544
|
-
: ('warn' as const);
|
|
545
|
-
this.log[logLvl](err.message, { now: this.dateProvider.nowInSeconds() });
|
|
546
|
-
} else {
|
|
547
|
-
// Re-throw other errors
|
|
548
|
-
throw err;
|
|
549
|
-
}
|
|
550
|
-
} finally {
|
|
551
|
-
this.setState(SequencerState.IDLE, undefined);
|
|
552
|
-
}
|
|
424
|
+
/**
|
|
425
|
+
* Returns the current sequencer state.
|
|
426
|
+
*/
|
|
427
|
+
public getState(): SequencerState {
|
|
428
|
+
return this.state;
|
|
553
429
|
}
|
|
554
430
|
|
|
555
431
|
/**
|
|
556
|
-
*
|
|
432
|
+
* Internal helper for setting the sequencer state and checks if we have enough time left in the slot to transition to the new state.
|
|
557
433
|
* @param proposedState - The new state to transition to.
|
|
558
434
|
* @param slotNumber - The current slot number.
|
|
559
435
|
* @param force - Whether to force the transition even if the sequencer is stopped.
|
|
560
436
|
*/
|
|
561
|
-
setState(
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
): void;
|
|
567
|
-
setState(proposedState: SequencerState, slotNumber: SlotNumber | undefined, opts: { force?: boolean } = {}): void {
|
|
437
|
+
protected setState(
|
|
438
|
+
proposedState: SequencerState,
|
|
439
|
+
slotNumber: SlotNumber | undefined,
|
|
440
|
+
opts: { force?: boolean } = {},
|
|
441
|
+
): void {
|
|
568
442
|
if (this.state === SequencerState.STOPPING && proposedState !== SequencerState.STOPPED && !opts.force) {
|
|
569
443
|
this.log.warn(`Cannot set sequencer to ${proposedState} as it is stopping.`);
|
|
570
444
|
throw new SequencerInterruptedError();
|
|
@@ -590,362 +464,25 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
590
464
|
oldState: this.state,
|
|
591
465
|
newState: proposedState,
|
|
592
466
|
secondsIntoSlot,
|
|
593
|
-
slotNumber,
|
|
467
|
+
slot: slotNumber,
|
|
594
468
|
});
|
|
595
469
|
this.state = proposedState;
|
|
596
470
|
}
|
|
597
471
|
|
|
598
|
-
private async dropFailedTxsFromP2P(failedTxs: FailedTx[]) {
|
|
599
|
-
if (failedTxs.length === 0) {
|
|
600
|
-
return;
|
|
601
|
-
}
|
|
602
|
-
const failedTxData = failedTxs.map(fail => fail.tx);
|
|
603
|
-
const failedTxHashes = failedTxData.map(tx => tx.getTxHash());
|
|
604
|
-
this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
|
|
605
|
-
await this.p2pClient.deleteTxs(failedTxHashes);
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
protected getBlockBuilderOptions(slot: SlotNumber): PublicProcessorLimits {
|
|
609
|
-
// Deadline for processing depends on whether we're proposing a block
|
|
610
|
-
const secondsIntoSlot = this.getSecondsIntoSlot(slot);
|
|
611
|
-
const processingEndTimeWithinSlot = this.timetable.getBlockProposalExecTimeEnd(secondsIntoSlot);
|
|
612
|
-
|
|
613
|
-
// Deadline is only set if enforceTimeTable is enabled.
|
|
614
|
-
const deadline = this.enforceTimeTable
|
|
615
|
-
? new Date((this.getSlotStartBuildTimestamp(slot) + processingEndTimeWithinSlot) * 1000)
|
|
616
|
-
: undefined;
|
|
617
|
-
return {
|
|
618
|
-
maxTransactions: this.maxTxsPerBlock,
|
|
619
|
-
maxBlockSize: this.maxBlockSizeInBytes,
|
|
620
|
-
maxBlockGas: this.maxBlockGas,
|
|
621
|
-
maxBlobFields: BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB,
|
|
622
|
-
deadline,
|
|
623
|
-
};
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
/**
|
|
627
|
-
* @notice Build and propose a block to the chain
|
|
628
|
-
*
|
|
629
|
-
* @dev MUST throw instead of exiting early to ensure that world-state
|
|
630
|
-
* is being rolled back if the block is dropped.
|
|
631
|
-
*
|
|
632
|
-
* @param pendingTxs - Iterable of pending transactions to construct the block from
|
|
633
|
-
* @param proposalHeader - The partial header constructed for the proposal
|
|
634
|
-
* @param newGlobalVariables - The global variables for the new block
|
|
635
|
-
* @param proposerAddress - The address of the proposer
|
|
636
|
-
*/
|
|
637
|
-
@trackSpan('Sequencer.buildBlockAndEnqueuePublish', (_validTxs, _proposalHeader, newGlobalVariables) => ({
|
|
638
|
-
[Attributes.BLOCK_NUMBER]: newGlobalVariables.blockNumber,
|
|
639
|
-
}))
|
|
640
|
-
private async buildBlockAndEnqueuePublish(
|
|
641
|
-
pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
642
|
-
proposalHeader: CheckpointHeader,
|
|
643
|
-
newGlobalVariables: GlobalVariables,
|
|
644
|
-
proposerAddress: EthAddress | undefined,
|
|
645
|
-
invalidateBlock: InvalidateBlockRequest | undefined,
|
|
646
|
-
publisher: SequencerPublisher,
|
|
647
|
-
): Promise<L2Block> {
|
|
648
|
-
await publisher.validateBlockHeader(proposalHeader, invalidateBlock);
|
|
649
|
-
|
|
650
|
-
const blockNumber = newGlobalVariables.blockNumber;
|
|
651
|
-
const checkpointNumber = CheckpointNumber.fromBlockNumber(blockNumber);
|
|
652
|
-
const slot = proposalHeader.slotNumber;
|
|
653
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
654
|
-
|
|
655
|
-
const workTimer = new Timer();
|
|
656
|
-
this.setState(SequencerState.CREATING_BLOCK, slot);
|
|
657
|
-
|
|
658
|
-
try {
|
|
659
|
-
const blockBuilderOptions = this.getBlockBuilderOptions(slot);
|
|
660
|
-
const buildBlockRes = await this.blockBuilder.buildBlock(
|
|
661
|
-
pendingTxs,
|
|
662
|
-
l1ToL2Messages,
|
|
663
|
-
newGlobalVariables,
|
|
664
|
-
blockBuilderOptions,
|
|
665
|
-
);
|
|
666
|
-
const { publicGas, block, publicProcessorDuration, numTxs, numMsgs, blockBuildingTimer, usedTxs, failedTxs } =
|
|
667
|
-
buildBlockRes;
|
|
668
|
-
const blockBuildDuration = workTimer.ms();
|
|
669
|
-
await this.dropFailedTxsFromP2P(failedTxs);
|
|
670
|
-
|
|
671
|
-
const minTxsPerBlock = this.minTxsPerBlock;
|
|
672
|
-
if (numTxs < minTxsPerBlock) {
|
|
673
|
-
this.log.warn(
|
|
674
|
-
`Block ${blockNumber} has too few txs to be proposed (got ${numTxs} but required ${minTxsPerBlock})`,
|
|
675
|
-
{ slot, blockNumber, numTxs },
|
|
676
|
-
);
|
|
677
|
-
throw new Error(`Block has too few successful txs to be proposed`);
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
// TODO(@PhilWindle) We should probably periodically check for things like another
|
|
681
|
-
// block being published before ours instead of just waiting on our block
|
|
682
|
-
await publisher.validateBlockHeader(block.getCheckpointHeader(), invalidateBlock);
|
|
683
|
-
|
|
684
|
-
const blockStats: L2BlockBuiltStats = {
|
|
685
|
-
eventName: 'l2-block-built',
|
|
686
|
-
creator: proposerAddress?.toString() ?? publisher.getSenderAddress().toString(),
|
|
687
|
-
duration: workTimer.ms(),
|
|
688
|
-
publicProcessDuration: publicProcessorDuration,
|
|
689
|
-
rollupCircuitsDuration: blockBuildingTimer.ms(),
|
|
690
|
-
...block.getStats(),
|
|
691
|
-
};
|
|
692
|
-
|
|
693
|
-
const blockHash = await block.hash();
|
|
694
|
-
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
695
|
-
this.log.info(
|
|
696
|
-
`Built block ${block.number} for slot ${slot} with ${numTxs} txs and ${numMsgs} messages. ${
|
|
697
|
-
publicGas.l2Gas / workTimer.s()
|
|
698
|
-
} mana/s`,
|
|
699
|
-
{
|
|
700
|
-
blockHash,
|
|
701
|
-
globalVariables: block.header.globalVariables.toInspect(),
|
|
702
|
-
txHashes,
|
|
703
|
-
...blockStats,
|
|
704
|
-
},
|
|
705
|
-
);
|
|
706
|
-
|
|
707
|
-
// In fisherman mode, skip attestation collection
|
|
708
|
-
let attestationsAndSigners: CommitteeAttestationsAndSigners;
|
|
709
|
-
if (this.config.fishermanMode) {
|
|
710
|
-
this.log.debug('Skipping attestation collection');
|
|
711
|
-
attestationsAndSigners = CommitteeAttestationsAndSigners.empty();
|
|
712
|
-
} else {
|
|
713
|
-
this.log.debug('Collecting attestations');
|
|
714
|
-
attestationsAndSigners = await this.collectAttestations(block, usedTxs, proposerAddress);
|
|
715
|
-
this.log.verbose(
|
|
716
|
-
`Collected ${attestationsAndSigners.attestations.length} attestations for block ${blockNumber} at slot ${slot}`,
|
|
717
|
-
{ blockHash, blockNumber, slot },
|
|
718
|
-
);
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
// In fisherman mode, skip attestation signing
|
|
722
|
-
const attestationsAndSignersSignature =
|
|
723
|
-
this.config.fishermanMode || !this.validatorClient
|
|
724
|
-
? Signature.empty()
|
|
725
|
-
: await this.validatorClient.signAttestationsAndSigners(
|
|
726
|
-
attestationsAndSigners,
|
|
727
|
-
proposerAddress ?? publisher.getSenderAddress(),
|
|
728
|
-
);
|
|
729
|
-
|
|
730
|
-
await this.enqueuePublishL2Block(
|
|
731
|
-
block,
|
|
732
|
-
attestationsAndSigners,
|
|
733
|
-
attestationsAndSignersSignature,
|
|
734
|
-
invalidateBlock,
|
|
735
|
-
publisher,
|
|
736
|
-
);
|
|
737
|
-
this.metrics.recordBuiltBlock(blockBuildDuration, publicGas.l2Gas);
|
|
738
|
-
return block;
|
|
739
|
-
} catch (err) {
|
|
740
|
-
this.metrics.recordFailedBlock();
|
|
741
|
-
throw err;
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
@trackSpan('Sequencer.collectAttestations', (block, txHashes) => ({
|
|
746
|
-
[Attributes.BLOCK_NUMBER]: block.number,
|
|
747
|
-
[Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
|
|
748
|
-
[Attributes.BLOCK_TXS_COUNT]: txHashes.length,
|
|
749
|
-
}))
|
|
750
|
-
protected async collectAttestations(
|
|
751
|
-
block: L2Block,
|
|
752
|
-
txs: Tx[],
|
|
753
|
-
proposerAddress: EthAddress | undefined,
|
|
754
|
-
): Promise<CommitteeAttestationsAndSigners> {
|
|
755
|
-
const { committee, seed, epoch } = await this.epochCache.getCommittee(block.slot);
|
|
756
|
-
|
|
757
|
-
// We checked above that the committee is defined, so this should never happen.
|
|
758
|
-
if (!committee) {
|
|
759
|
-
throw new Error('No committee when collecting attestations');
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
if (committee.length === 0) {
|
|
763
|
-
this.log.verbose(`Attesting committee is empty`);
|
|
764
|
-
return CommitteeAttestationsAndSigners.empty();
|
|
765
|
-
} else {
|
|
766
|
-
this.log.debug(`Attesting committee length is ${committee.length}`);
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
if (!this.validatorClient) {
|
|
770
|
-
throw new Error('Missing validator client: Cannot collect attestations');
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
const numberOfRequiredAttestations = Math.floor((committee.length * 2) / 3) + 1;
|
|
774
|
-
|
|
775
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
776
|
-
this.setState(SequencerState.COLLECTING_ATTESTATIONS, slotNumber);
|
|
777
|
-
|
|
778
|
-
this.log.debug('Creating block proposal for validators');
|
|
779
|
-
const blockProposalOptions: BlockProposalOptions = {
|
|
780
|
-
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
781
|
-
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal,
|
|
782
|
-
};
|
|
783
|
-
const proposal = await this.validatorClient.createBlockProposal(
|
|
784
|
-
block.header.globalVariables.blockNumber,
|
|
785
|
-
block.getCheckpointHeader(),
|
|
786
|
-
block.archive.root,
|
|
787
|
-
txs,
|
|
788
|
-
proposerAddress,
|
|
789
|
-
blockProposalOptions,
|
|
790
|
-
);
|
|
791
|
-
|
|
792
|
-
if (!proposal) {
|
|
793
|
-
throw new Error(`Failed to create block proposal`);
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
if (this.config.skipCollectingAttestations) {
|
|
797
|
-
this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
|
|
798
|
-
const attestations = await this.validatorClient?.collectOwnAttestations(proposal);
|
|
799
|
-
return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee));
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
this.log.debug('Broadcasting block proposal to validators');
|
|
803
|
-
await this.validatorClient.broadcastBlockProposal(proposal);
|
|
804
|
-
|
|
805
|
-
const attestationTimeAllowed = this.enforceTimeTable
|
|
806
|
-
? this.timetable.getMaxAllowedTime(SequencerState.PUBLISHING_BLOCK)!
|
|
807
|
-
: this.aztecSlotDuration;
|
|
808
|
-
|
|
809
|
-
this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
|
|
810
|
-
|
|
811
|
-
const timer = new Timer();
|
|
812
|
-
let collectedAttestationsCount: number = 0;
|
|
813
|
-
try {
|
|
814
|
-
const attestationDeadline = new Date(this.dateProvider.now() + attestationTimeAllowed * 1000);
|
|
815
|
-
const attestations = await this.validatorClient.collectAttestations(
|
|
816
|
-
proposal,
|
|
817
|
-
numberOfRequiredAttestations,
|
|
818
|
-
attestationDeadline,
|
|
819
|
-
);
|
|
820
|
-
|
|
821
|
-
collectedAttestationsCount = attestations.length;
|
|
822
|
-
|
|
823
|
-
// note: the smart contract requires that the signatures are provided in the order of the committee
|
|
824
|
-
const sorted = orderAttestations(attestations, committee);
|
|
825
|
-
|
|
826
|
-
// manipulate the attestations if we've been configured to do so
|
|
827
|
-
if (this.config.injectFakeAttestation || this.config.shuffleAttestationOrdering) {
|
|
828
|
-
return this.manipulateAttestations(block, epoch, seed, committee, sorted);
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
return new CommitteeAttestationsAndSigners(sorted);
|
|
832
|
-
} catch (err) {
|
|
833
|
-
if (err && err instanceof AttestationTimeoutError) {
|
|
834
|
-
collectedAttestationsCount = err.collectedCount;
|
|
835
|
-
}
|
|
836
|
-
throw err;
|
|
837
|
-
} finally {
|
|
838
|
-
this.metrics.recordCollectedAttestations(collectedAttestationsCount, timer.ms());
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
/** Breaks the attestations before publishing based on attack configs */
|
|
843
|
-
private manipulateAttestations(
|
|
844
|
-
block: L2Block,
|
|
845
|
-
epoch: EpochNumber,
|
|
846
|
-
seed: bigint,
|
|
847
|
-
committee: EthAddress[],
|
|
848
|
-
attestations: CommitteeAttestation[],
|
|
849
|
-
) {
|
|
850
|
-
// Compute the proposer index in the committee, since we dont want to tweak it.
|
|
851
|
-
// Otherwise, the L1 rollup contract will reject the block outright.
|
|
852
|
-
const proposerIndex = Number(
|
|
853
|
-
this.epochCache.computeProposerIndex(block.slot, epoch, seed, BigInt(committee.length)),
|
|
854
|
-
);
|
|
855
|
-
|
|
856
|
-
if (this.config.injectFakeAttestation) {
|
|
857
|
-
// Find non-empty attestations that are not from the proposer
|
|
858
|
-
const nonProposerIndices: number[] = [];
|
|
859
|
-
for (let i = 0; i < attestations.length; i++) {
|
|
860
|
-
if (!attestations[i].signature.isEmpty() && i !== proposerIndex) {
|
|
861
|
-
nonProposerIndices.push(i);
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
if (nonProposerIndices.length > 0) {
|
|
865
|
-
const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
|
|
866
|
-
this.log.warn(`Injecting fake attestation in block ${block.number} at index ${targetIndex}`);
|
|
867
|
-
unfreeze(attestations[targetIndex]).signature = Signature.random();
|
|
868
|
-
}
|
|
869
|
-
return new CommitteeAttestationsAndSigners(attestations);
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
if (this.config.shuffleAttestationOrdering) {
|
|
873
|
-
this.log.warn(`Shuffling attestation ordering in block ${block.number} (proposer index ${proposerIndex})`);
|
|
874
|
-
|
|
875
|
-
const shuffled = [...attestations];
|
|
876
|
-
const [i, j] = [(proposerIndex + 1) % shuffled.length, (proposerIndex + 2) % shuffled.length];
|
|
877
|
-
const valueI = shuffled[i];
|
|
878
|
-
const valueJ = shuffled[j];
|
|
879
|
-
shuffled[i] = valueJ;
|
|
880
|
-
shuffled[j] = valueI;
|
|
881
|
-
|
|
882
|
-
const signers = new CommitteeAttestationsAndSigners(attestations).getSigners();
|
|
883
|
-
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers);
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
return new CommitteeAttestationsAndSigners(attestations);
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
/**
|
|
890
|
-
* Publishes the L2Block to the rollup contract.
|
|
891
|
-
* @param block - The L2Block to be published.
|
|
892
|
-
*/
|
|
893
|
-
@trackSpan('Sequencer.enqueuePublishL2Block', block => ({
|
|
894
|
-
[Attributes.BLOCK_NUMBER]: block.number,
|
|
895
|
-
}))
|
|
896
|
-
protected async enqueuePublishL2Block(
|
|
897
|
-
block: L2Block,
|
|
898
|
-
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
899
|
-
attestationsAndSignersSignature: Signature,
|
|
900
|
-
invalidateBlock: InvalidateBlockRequest | undefined,
|
|
901
|
-
publisher: SequencerPublisher,
|
|
902
|
-
): Promise<void> {
|
|
903
|
-
// Publishes new block to the network and awaits the tx to be mined
|
|
904
|
-
this.setState(SequencerState.PUBLISHING_BLOCK, block.header.globalVariables.slotNumber);
|
|
905
|
-
|
|
906
|
-
// Time out tx at the end of the slot
|
|
907
|
-
const slot = block.header.globalVariables.slotNumber;
|
|
908
|
-
const txTimeoutAt = new Date((this.getSlotStartBuildTimestamp(slot) + this.aztecSlotDuration) * 1000);
|
|
909
|
-
|
|
910
|
-
const enqueued = await publisher.enqueueProposeL2Block(
|
|
911
|
-
block,
|
|
912
|
-
attestationsAndSigners,
|
|
913
|
-
attestationsAndSignersSignature,
|
|
914
|
-
{
|
|
915
|
-
txTimeoutAt,
|
|
916
|
-
forcePendingBlockNumber: invalidateBlock?.forcePendingBlockNumber,
|
|
917
|
-
},
|
|
918
|
-
);
|
|
919
|
-
|
|
920
|
-
if (!enqueued) {
|
|
921
|
-
throw new Error(`Failed to enqueue publish of block ${block.number}`);
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
|
|
925
472
|
/**
|
|
926
473
|
* Returns whether all dependencies have caught up.
|
|
927
474
|
* We don't check against the previous block submitted since it may have been reorg'd out.
|
|
928
475
|
*/
|
|
929
|
-
protected async checkSync(args: { ts: bigint; slot: SlotNumber }): Promise<
|
|
930
|
-
|
|
931
|
-
block?: L2Block;
|
|
932
|
-
blockNumber: BlockNumber;
|
|
933
|
-
archive: Fr;
|
|
934
|
-
l1Timestamp: bigint;
|
|
935
|
-
pendingChainValidationStatus: ValidateBlockResult;
|
|
936
|
-
}
|
|
937
|
-
| undefined
|
|
938
|
-
> {
|
|
939
|
-
// Check that the archiver and dependencies have synced to the previous L1 slot at least
|
|
476
|
+
protected async checkSync(args: { ts: bigint; slot: SlotNumber }): Promise<SequencerSyncCheckResult | undefined> {
|
|
477
|
+
// Check that the archiver has fully synced the L2 slot before the one we want to propose in.
|
|
940
478
|
// TODO(#14766): Archiver reports L1 timestamp based on L1 blocks seen, which means that a missed L1 block will
|
|
941
479
|
// cause the archiver L1 timestamp to fall behind, and cause this sequencer to start processing one L1 slot later.
|
|
942
|
-
const
|
|
943
|
-
const { slot
|
|
944
|
-
if (
|
|
480
|
+
const syncedL2Slot = await this.l2BlockSource.getSyncedL2SlotNumber();
|
|
481
|
+
const { slot } = args;
|
|
482
|
+
if (syncedL2Slot === undefined || syncedL2Slot + 1 < slot) {
|
|
945
483
|
this.log.debug(`Cannot propose block at next L2 slot ${slot} due to pending sync from L1`, {
|
|
946
484
|
slot,
|
|
947
|
-
|
|
948
|
-
l1Timestamp,
|
|
485
|
+
syncedL2Slot,
|
|
949
486
|
});
|
|
950
487
|
return undefined;
|
|
951
488
|
}
|
|
@@ -955,9 +492,9 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
955
492
|
number: syncSummary.latestBlockNumber,
|
|
956
493
|
hash: syncSummary.latestBlockHash,
|
|
957
494
|
})),
|
|
958
|
-
this.l2BlockSource.getL2Tips().then(t => t.
|
|
495
|
+
this.l2BlockSource.getL2Tips().then(t => t.proposed),
|
|
959
496
|
this.p2pClient.getStatus().then(p2p => p2p.syncedToL2Block),
|
|
960
|
-
this.l1ToL2MessageSource.getL2Tips().then(t => t.
|
|
497
|
+
this.l1ToL2MessageSource.getL2Tips().then(t => t.proposed),
|
|
961
498
|
this.l2BlockSource.getPendingChainValidationStatus(),
|
|
962
499
|
] as const);
|
|
963
500
|
|
|
@@ -965,6 +502,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
965
502
|
|
|
966
503
|
// Handle zero as a special case, since the block hash won't match across services if we're changing the prefilled data for the genesis block,
|
|
967
504
|
// as the world state can compute the new genesis block hash, but other components use the hardcoded constant.
|
|
505
|
+
// TODO(palla/mbps): Fix the above. All components should be able to handle dynamic genesis block hashes.
|
|
968
506
|
const result =
|
|
969
507
|
(l2BlockSource.number === 0 && worldState.number === 0 && p2p.number === 0 && l1ToL2MessageSource.number === 0) ||
|
|
970
508
|
(worldState.hash === l2BlockSource.hash &&
|
|
@@ -980,82 +518,32 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
980
518
|
const blockNumber = worldState.number;
|
|
981
519
|
if (blockNumber < INITIAL_L2_BLOCK_NUM) {
|
|
982
520
|
const archive = new Fr((await this.worldState.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
983
|
-
return {
|
|
521
|
+
return {
|
|
522
|
+
checkpointNumber: CheckpointNumber.ZERO,
|
|
523
|
+
blockNumber: BlockNumber.ZERO,
|
|
524
|
+
archive,
|
|
525
|
+
syncedL2Slot,
|
|
526
|
+
pendingChainValidationStatus,
|
|
527
|
+
};
|
|
984
528
|
}
|
|
985
529
|
|
|
986
|
-
const
|
|
987
|
-
if (!
|
|
530
|
+
const blockData = await this.l2BlockSource.getBlockData(blockNumber);
|
|
531
|
+
if (!blockData) {
|
|
988
532
|
// this shouldn't really happen because a moment ago we checked that all components were in sync
|
|
989
|
-
this.log.error(`Failed to get L2 block ${blockNumber} from the archiver with all components in sync`);
|
|
533
|
+
this.log.error(`Failed to get L2 block data ${blockNumber} from the archiver with all components in sync`);
|
|
990
534
|
return undefined;
|
|
991
535
|
}
|
|
992
536
|
|
|
993
537
|
return {
|
|
994
|
-
|
|
995
|
-
blockNumber:
|
|
996
|
-
|
|
997
|
-
|
|
538
|
+
blockData,
|
|
539
|
+
blockNumber: blockData.header.getBlockNumber(),
|
|
540
|
+
checkpointNumber: blockData.checkpointNumber,
|
|
541
|
+
archive: blockData.archive.root,
|
|
542
|
+
syncedL2Slot,
|
|
998
543
|
pendingChainValidationStatus,
|
|
999
544
|
};
|
|
1000
545
|
}
|
|
1001
546
|
|
|
1002
|
-
/**
|
|
1003
|
-
* Enqueues governance and slashing votes with the publisher. Does not block.
|
|
1004
|
-
* @param publisher - The publisher to enqueue votes with
|
|
1005
|
-
* @param attestorAddress - The attestor address to use for signing
|
|
1006
|
-
* @param slot - The slot number
|
|
1007
|
-
* @param timestamp - The timestamp for the votes
|
|
1008
|
-
* @param context - Optional context for logging (e.g., block number)
|
|
1009
|
-
* @returns A tuple of [governanceEnqueued, slashingEnqueued]
|
|
1010
|
-
*/
|
|
1011
|
-
protected enqueueGovernanceAndSlashingVotes(
|
|
1012
|
-
publisher: SequencerPublisher,
|
|
1013
|
-
attestorAddress: EthAddress,
|
|
1014
|
-
slot: SlotNumber,
|
|
1015
|
-
timestamp: bigint,
|
|
1016
|
-
): [Promise<boolean> | undefined, Promise<boolean> | undefined] {
|
|
1017
|
-
try {
|
|
1018
|
-
const signerFn = (msg: TypedDataDefinition) =>
|
|
1019
|
-
this.validatorClient!.signWithAddress(attestorAddress, msg).then(s => s.toString());
|
|
1020
|
-
|
|
1021
|
-
const enqueueGovernancePromise =
|
|
1022
|
-
this.governanceProposerPayload && !this.governanceProposerPayload.isZero()
|
|
1023
|
-
? publisher
|
|
1024
|
-
.enqueueGovernanceCastSignal(this.governanceProposerPayload, slot, timestamp, attestorAddress, signerFn)
|
|
1025
|
-
.catch(err => {
|
|
1026
|
-
this.log.error(`Error enqueuing governance vote`, err, { slot });
|
|
1027
|
-
return false;
|
|
1028
|
-
})
|
|
1029
|
-
: undefined;
|
|
1030
|
-
|
|
1031
|
-
const enqueueSlashingPromise = this.slasherClient
|
|
1032
|
-
? this.slasherClient
|
|
1033
|
-
.getProposerActions(slot)
|
|
1034
|
-
.then(actions => {
|
|
1035
|
-
// Record metrics for fisherman mode
|
|
1036
|
-
if (this.config.fishermanMode && actions.length > 0) {
|
|
1037
|
-
this.log.debug(`Fisherman mode: simulating ${actions.length} slashing action(s) for slot ${slot}`, {
|
|
1038
|
-
slot,
|
|
1039
|
-
actionCount: actions.length,
|
|
1040
|
-
});
|
|
1041
|
-
this.metrics.recordSlashingAttempt(actions.length);
|
|
1042
|
-
}
|
|
1043
|
-
// Enqueue the actions to fully simulate L1 tx building (they won't be sent in fisherman mode)
|
|
1044
|
-
return publisher.enqueueSlashingActions(actions, slot, timestamp, attestorAddress, signerFn);
|
|
1045
|
-
})
|
|
1046
|
-
.catch(err => {
|
|
1047
|
-
this.log.error(`Error enqueuing slashing actions`, err, { slot });
|
|
1048
|
-
return false;
|
|
1049
|
-
})
|
|
1050
|
-
: undefined;
|
|
1051
|
-
|
|
1052
|
-
return [enqueueGovernancePromise, enqueueSlashingPromise];
|
|
1053
|
-
} catch (err) {
|
|
1054
|
-
this.log.error(`Error enqueueing governance and slashing votes`, err);
|
|
1055
|
-
return [undefined, undefined];
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
547
|
/**
|
|
1060
548
|
* Checks if we are the proposer for the next slot.
|
|
1061
549
|
* @returns True if we can propose, and the proposer address (undefined if anyone can propose)
|
|
@@ -1067,7 +555,10 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
1067
555
|
proposer = await this.epochCache.getProposerAttesterAddressInSlot(slot);
|
|
1068
556
|
} catch (e) {
|
|
1069
557
|
if (e instanceof NoCommitteeError) {
|
|
1070
|
-
this.
|
|
558
|
+
if (this.lastSlotForNoCommitteeWarning !== slot) {
|
|
559
|
+
this.lastSlotForNoCommitteeWarning = slot;
|
|
560
|
+
this.log.warn(`Cannot propose at next L2 slot ${slot} since the committee does not exist on L1`);
|
|
561
|
+
}
|
|
1071
562
|
return [false, undefined];
|
|
1072
563
|
}
|
|
1073
564
|
this.log.error(`Error getting proposer for slot ${slot}`, e);
|
|
@@ -1083,7 +574,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
1083
574
|
return [true, proposer];
|
|
1084
575
|
}
|
|
1085
576
|
|
|
1086
|
-
const validatorAddresses = this.validatorClient
|
|
577
|
+
const validatorAddresses = this.validatorClient.getValidatorAddresses();
|
|
1087
578
|
const weAreProposer = validatorAddresses.some(addr => addr.equals(proposer));
|
|
1088
579
|
|
|
1089
580
|
if (!weAreProposer) {
|
|
@@ -1098,30 +589,31 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
1098
589
|
* Tries to vote on slashing actions and governance when the sync check fails but we're past the max time for initializing a proposal.
|
|
1099
590
|
* This allows the sequencer to participate in governance/slashing votes even when it cannot build blocks.
|
|
1100
591
|
*/
|
|
592
|
+
@trackSpan('Seqeuencer.tryVoteWhenSyncFails', ({ slot }) => ({ [Attributes.SLOT_NUMBER]: slot }))
|
|
1101
593
|
protected async tryVoteWhenSyncFails(args: { slot: SlotNumber; ts: bigint }): Promise<void> {
|
|
1102
|
-
const { slot
|
|
594
|
+
const { slot } = args;
|
|
1103
595
|
|
|
1104
596
|
// Prevent duplicate attempts in the same slot
|
|
1105
|
-
if (this.
|
|
1106
|
-
this.log.
|
|
597
|
+
if (this.lastSlotForFallbackVote === slot) {
|
|
598
|
+
this.log.trace(`Already attempted to vote in slot ${slot} (skipping)`);
|
|
1107
599
|
return;
|
|
1108
600
|
}
|
|
1109
601
|
|
|
1110
602
|
// Check if we're past the max time for initializing a proposal
|
|
1111
603
|
const secondsIntoSlot = this.getSecondsIntoSlot(slot);
|
|
1112
|
-
const maxAllowedTime = this.timetable.getMaxAllowedTime(SequencerState.
|
|
604
|
+
const maxAllowedTime = this.timetable.getMaxAllowedTime(SequencerState.INITIALIZING_CHECKPOINT);
|
|
1113
605
|
|
|
1114
606
|
// If we haven't exceeded the time limit for initializing a proposal, don't proceed with voting
|
|
1115
607
|
// We use INITIALIZING_PROPOSAL time limit because if we're past that, we can't build a block anyway
|
|
1116
608
|
if (maxAllowedTime === undefined || secondsIntoSlot <= maxAllowedTime) {
|
|
1117
|
-
this.log.trace(`Not attempting to vote since there is still for block building`, {
|
|
609
|
+
this.log.trace(`Not attempting to vote since there is still time for block building`, {
|
|
1118
610
|
secondsIntoSlot,
|
|
1119
611
|
maxAllowedTime,
|
|
1120
612
|
});
|
|
1121
613
|
return;
|
|
1122
614
|
}
|
|
1123
615
|
|
|
1124
|
-
this.log.
|
|
616
|
+
this.log.trace(`Sync for slot ${slot} failed, checking for voting opportunities`, {
|
|
1125
617
|
secondsIntoSlot,
|
|
1126
618
|
maxAllowedTime,
|
|
1127
619
|
});
|
|
@@ -1129,12 +621,12 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
1129
621
|
// Check if we're a proposer or proposal is open
|
|
1130
622
|
const [canPropose, proposer] = await this.checkCanPropose(slot);
|
|
1131
623
|
if (!canPropose) {
|
|
1132
|
-
this.log.
|
|
624
|
+
this.log.trace(`Cannot vote in slot ${slot} since we are not a proposer`, { slot, proposer });
|
|
1133
625
|
return;
|
|
1134
626
|
}
|
|
1135
627
|
|
|
1136
628
|
// Mark this slot as attempted
|
|
1137
|
-
this.
|
|
629
|
+
this.lastSlotForFallbackVote = slot;
|
|
1138
630
|
|
|
1139
631
|
// Get a publisher for voting
|
|
1140
632
|
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
@@ -1144,11 +636,22 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
1144
636
|
slot,
|
|
1145
637
|
});
|
|
1146
638
|
|
|
1147
|
-
// Enqueue governance and slashing votes
|
|
1148
|
-
const
|
|
1149
|
-
|
|
639
|
+
// Enqueue governance and slashing votes
|
|
640
|
+
const voter = new CheckpointVoter(
|
|
641
|
+
slot,
|
|
642
|
+
publisher,
|
|
643
|
+
attestorAddress,
|
|
644
|
+
this.validatorClient,
|
|
645
|
+
this.slasherClient,
|
|
646
|
+
this.l1Constants,
|
|
647
|
+
this.config,
|
|
648
|
+
this.metrics,
|
|
649
|
+
this.log,
|
|
650
|
+
);
|
|
651
|
+
const votesPromises = voter.enqueueVotes();
|
|
652
|
+
const votes = await Promise.all(votesPromises);
|
|
1150
653
|
|
|
1151
|
-
if (
|
|
654
|
+
if (votes.every(p => !p)) {
|
|
1152
655
|
this.log.debug(`No votes to enqueue for slot ${slot}`);
|
|
1153
656
|
return;
|
|
1154
657
|
}
|
|
@@ -1157,33 +660,81 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
1157
660
|
await publisher.sendRequests();
|
|
1158
661
|
}
|
|
1159
662
|
|
|
663
|
+
/**
|
|
664
|
+
* Tries to vote on slashing actions and governance proposals when escape hatch is open.
|
|
665
|
+
* This allows the sequencer to participate in voting without performing checkpoint proposal work.
|
|
666
|
+
*/
|
|
667
|
+
@trackSpan('Sequencer.tryVoteWhenEscapeHatchOpen', ({ slot }) => ({ [Attributes.SLOT_NUMBER]: slot }))
|
|
668
|
+
protected async tryVoteWhenEscapeHatchOpen(args: {
|
|
669
|
+
slot: SlotNumber;
|
|
670
|
+
proposer: EthAddress | undefined;
|
|
671
|
+
}): Promise<void> {
|
|
672
|
+
const { slot, proposer } = args;
|
|
673
|
+
|
|
674
|
+
// Prevent duplicate attempts in the same slot
|
|
675
|
+
if (this.lastSlotForFallbackVote === slot) {
|
|
676
|
+
this.log.trace(`Already attempted to vote in slot ${slot} (escape hatch open, skipping)`);
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// Mark this slot as attempted
|
|
681
|
+
this.lastSlotForFallbackVote = slot;
|
|
682
|
+
|
|
683
|
+
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
684
|
+
|
|
685
|
+
this.log.debug(`Escape hatch open for slot ${slot}, attempting vote-only actions`, { slot, attestorAddress });
|
|
686
|
+
|
|
687
|
+
const voter = new CheckpointVoter(
|
|
688
|
+
slot,
|
|
689
|
+
publisher,
|
|
690
|
+
attestorAddress,
|
|
691
|
+
this.validatorClient,
|
|
692
|
+
this.slasherClient,
|
|
693
|
+
this.l1Constants,
|
|
694
|
+
this.config,
|
|
695
|
+
this.metrics,
|
|
696
|
+
this.log,
|
|
697
|
+
);
|
|
698
|
+
|
|
699
|
+
const votesPromises = voter.enqueueVotes();
|
|
700
|
+
const votes = await Promise.all(votesPromises);
|
|
701
|
+
|
|
702
|
+
if (votes.every(p => !p)) {
|
|
703
|
+
this.log.debug(`No votes to enqueue for slot ${slot} (escape hatch open)`);
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
this.log.info(`Voting in slot ${slot} (escape hatch open)`, { slot });
|
|
708
|
+
await publisher.sendRequests();
|
|
709
|
+
}
|
|
710
|
+
|
|
1160
711
|
/**
|
|
1161
712
|
* Considers invalidating a block if the pending chain is invalid. Depends on how long the invalid block
|
|
1162
713
|
* has been there without being invalidated and whether the sequencer is in the committee or not. We always
|
|
1163
714
|
* have the proposer try to invalidate, but if they fail, the sequencers in the committee are expected to try,
|
|
1164
715
|
* and if they fail, any sequencer will try as well.
|
|
1165
716
|
*/
|
|
1166
|
-
protected async
|
|
1167
|
-
syncedTo:
|
|
717
|
+
protected async considerInvalidatingCheckpoint(
|
|
718
|
+
syncedTo: SequencerSyncCheckResult,
|
|
1168
719
|
currentSlot: SlotNumber,
|
|
1169
720
|
): Promise<void> {
|
|
1170
|
-
const { pendingChainValidationStatus,
|
|
721
|
+
const { pendingChainValidationStatus, syncedL2Slot } = syncedTo;
|
|
1171
722
|
if (pendingChainValidationStatus.valid) {
|
|
1172
723
|
return;
|
|
1173
724
|
}
|
|
1174
725
|
|
|
1175
|
-
const
|
|
1176
|
-
const
|
|
1177
|
-
const timeSinceChainInvalid = this.dateProvider.nowInSeconds() - Number(
|
|
1178
|
-
const ourValidatorAddresses = this.validatorClient
|
|
726
|
+
const invalidCheckpointNumber = pendingChainValidationStatus.checkpoint.checkpointNumber;
|
|
727
|
+
const invalidCheckpointTimestamp = pendingChainValidationStatus.checkpoint.timestamp;
|
|
728
|
+
const timeSinceChainInvalid = this.dateProvider.nowInSeconds() - Number(invalidCheckpointTimestamp);
|
|
729
|
+
const ourValidatorAddresses = this.validatorClient.getValidatorAddresses();
|
|
1179
730
|
|
|
1180
731
|
const { secondsBeforeInvalidatingBlockAsCommitteeMember, secondsBeforeInvalidatingBlockAsNonCommitteeMember } =
|
|
1181
732
|
this.config;
|
|
1182
733
|
|
|
1183
734
|
const logData = {
|
|
1184
|
-
invalidL1Timestamp:
|
|
1185
|
-
|
|
1186
|
-
|
|
735
|
+
invalidL1Timestamp: invalidCheckpointTimestamp,
|
|
736
|
+
syncedL2Slot,
|
|
737
|
+
invalidCheckpoint: pendingChainValidationStatus.checkpoint,
|
|
1187
738
|
secondsBeforeInvalidatingBlockAsCommitteeMember,
|
|
1188
739
|
secondsBeforeInvalidatingBlockAsNonCommitteeMember,
|
|
1189
740
|
ourValidatorAddresses,
|
|
@@ -1229,29 +780,58 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
1229
780
|
|
|
1230
781
|
const { publisher } = await this.publisherFactory.create(validatorToUse);
|
|
1231
782
|
|
|
1232
|
-
const
|
|
1233
|
-
if (!
|
|
1234
|
-
this.log.warn(`Failed to simulate invalidate
|
|
783
|
+
const invalidateCheckpoint = await publisher.simulateInvalidateCheckpoint(pendingChainValidationStatus);
|
|
784
|
+
if (!invalidateCheckpoint) {
|
|
785
|
+
this.log.warn(`Failed to simulate invalidate checkpoint`, logData);
|
|
1235
786
|
return;
|
|
1236
787
|
}
|
|
1237
788
|
|
|
1238
789
|
this.log.info(
|
|
1239
790
|
invalidateAsCommitteeMember
|
|
1240
|
-
? `Invalidating
|
|
1241
|
-
: `Invalidating
|
|
791
|
+
? `Invalidating checkpoint ${invalidCheckpointNumber} as committee member`
|
|
792
|
+
: `Invalidating checkpoint ${invalidCheckpointNumber} as non-committee member`,
|
|
1242
793
|
logData,
|
|
1243
794
|
);
|
|
1244
795
|
|
|
1245
|
-
publisher.
|
|
796
|
+
publisher.enqueueInvalidateCheckpoint(invalidateCheckpoint);
|
|
1246
797
|
|
|
1247
798
|
if (!this.config.fishermanMode) {
|
|
1248
799
|
await publisher.sendRequests();
|
|
1249
800
|
} else {
|
|
1250
|
-
this.log.info('Invalidating
|
|
801
|
+
this.log.info('Invalidating checkpoint in fisherman mode, clearing pending requests');
|
|
1251
802
|
publisher.clearPendingRequests();
|
|
1252
803
|
}
|
|
1253
804
|
}
|
|
1254
805
|
|
|
806
|
+
private logStrategyComparison(epoch: EpochNumber, publisher: SequencerPublisher): void {
|
|
807
|
+
const feeAnalyzer = publisher.getL1FeeAnalyzer();
|
|
808
|
+
if (!feeAnalyzer) {
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
const comparison = feeAnalyzer.getStrategyComparison();
|
|
813
|
+
if (comparison.length === 0) {
|
|
814
|
+
this.log.debug(`No strategy data available yet for epoch ${epoch}`);
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
this.log.info(`L1 Fee Strategy Performance Report - End of Epoch ${epoch}`, {
|
|
819
|
+
epoch: Number(epoch),
|
|
820
|
+
totalAnalyses: comparison[0]?.totalAnalyses,
|
|
821
|
+
strategies: comparison.map(s => ({
|
|
822
|
+
id: s.strategyId,
|
|
823
|
+
name: s.strategyName,
|
|
824
|
+
inclusionRate: `${(s.inclusionRate * 100).toFixed(1)}%`,
|
|
825
|
+
inclusionCount: `${s.inclusionCount}/${s.totalAnalyses}`,
|
|
826
|
+
avgCostEth: s.avgEstimatedCostEth.toFixed(6),
|
|
827
|
+
totalCostEth: s.totalEstimatedCostEth.toFixed(6),
|
|
828
|
+
avgOverpaymentEth: s.avgOverpaymentEth.toFixed(6),
|
|
829
|
+
totalOverpaymentEth: s.totalOverpaymentEth.toFixed(6),
|
|
830
|
+
avgPriorityFeeDeltaGwei: s.avgPriorityFeeDeltaGwei.toFixed(2),
|
|
831
|
+
})),
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
|
|
1255
835
|
private getSlotStartBuildTimestamp(slotNumber: SlotNumber): number {
|
|
1256
836
|
return getSlotStartBuildTimestamp(slotNumber, this.l1Constants);
|
|
1257
837
|
}
|
|
@@ -1261,15 +841,45 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
1261
841
|
return Number((this.dateProvider.now() / 1000 - slotStartTimestamp).toFixed(3));
|
|
1262
842
|
}
|
|
1263
843
|
|
|
1264
|
-
get aztecSlotDuration() {
|
|
844
|
+
public get aztecSlotDuration() {
|
|
1265
845
|
return this.l1Constants.slotDuration;
|
|
1266
846
|
}
|
|
1267
847
|
|
|
1268
|
-
get maxL2BlockGas(): number | undefined {
|
|
848
|
+
public get maxL2BlockGas(): number | undefined {
|
|
1269
849
|
return this.config.maxL2BlockGas;
|
|
1270
850
|
}
|
|
1271
851
|
|
|
1272
852
|
public getSlasherClient(): SlasherClientInterface | undefined {
|
|
1273
853
|
return this.slasherClient;
|
|
1274
854
|
}
|
|
855
|
+
|
|
856
|
+
public get tracer(): Tracer {
|
|
857
|
+
return this.metrics.tracer;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
public getValidatorAddresses() {
|
|
861
|
+
return this.validatorClient?.getValidatorAddresses();
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
/** Updates the publisher factory's node keystore adapter after a keystore reload. */
|
|
865
|
+
public updatePublisherNodeKeyStore(adapter: NodeKeystoreAdapter): void {
|
|
866
|
+
this.publisherFactory.updateNodeKeyStore(adapter);
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
public getConfig() {
|
|
870
|
+
return this.config;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
private get l1PublishingTime(): number {
|
|
874
|
+
return this.config.l1PublishingTime ?? this.l1Constants.ethereumSlotDuration;
|
|
875
|
+
}
|
|
1275
876
|
}
|
|
877
|
+
|
|
878
|
+
type SequencerSyncCheckResult = {
|
|
879
|
+
blockData?: BlockData;
|
|
880
|
+
checkpointNumber: CheckpointNumber;
|
|
881
|
+
blockNumber: BlockNumber;
|
|
882
|
+
archive: Fr;
|
|
883
|
+
syncedL2Slot: SlotNumber;
|
|
884
|
+
pendingChainValidationStatus: ValidateCheckpointResult;
|
|
885
|
+
};
|