@aztec/sequencer-client 0.0.0-test.1 → 0.0.1-commit.017a351
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +281 -21
- package/dest/client/index.d.ts +1 -1
- package/dest/client/sequencer-client.d.ts +43 -33
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +117 -62
- package/dest/config.d.ts +38 -17
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +172 -85
- 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 +26 -17
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +45 -61
- 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 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -3
- package/dest/publisher/config.d.ts +60 -27
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +124 -32
- package/dest/publisher/index.d.ts +4 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/index.js +3 -0
- 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 +50 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
- package/dest/publisher/sequencer-publisher-factory.js +75 -0
- package/dest/publisher/sequencer-publisher-metrics.d.ts +5 -4
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +34 -62
- package/dest/publisher/sequencer-publisher.d.ts +170 -97
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +1255 -276
- package/dest/sequencer/automine/automine_factory.d.ts +54 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +84 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +151 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +509 -0
- package/dest/sequencer/chain_state_overrides.d.ts +61 -0
- package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
- package/dest/sequencer/chain_state_overrides.js +98 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +150 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1792 -0
- 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 +34 -0
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_voter.js +106 -0
- package/dest/sequencer/config.d.ts +7 -1
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/errors.d.ts +11 -0
- package/dest/sequencer/errors.d.ts.map +1 -0
- package/dest/sequencer/errors.js +15 -0
- package/dest/sequencer/events.d.ts +92 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/index.d.ts +6 -2
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +5 -1
- package/dest/sequencer/metrics.d.ts +64 -13
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +309 -68
- package/dest/sequencer/sequencer.d.ts +205 -135
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +1208 -523
- package/dest/sequencer/timetable.d.ts +85 -25
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +177 -60
- 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 +20 -38
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +12 -47
- package/dest/test/index.d.ts +9 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +0 -4
- 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 +231 -0
- package/dest/test/utils.d.ts +53 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +105 -0
- package/package.json +46 -45
- package/src/client/sequencer-client.ts +158 -103
- package/src/config.ts +201 -99
- 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 +68 -76
- package/src/global_variable_builder/index.ts +3 -1
- package/src/index.ts +10 -3
- package/src/publisher/config.ts +184 -59
- package/src/publisher/index.ts +7 -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 +121 -0
- package/src/publisher/sequencer-publisher-metrics.ts +33 -63
- package/src/publisher/sequencer-publisher.ts +1101 -350
- package/src/sequencer/README.md +243 -0
- package/src/sequencer/automine/README.md +46 -0
- package/src/sequencer/automine/automine_factory.ts +145 -0
- package/src/sequencer/automine/automine_sequencer.ts +595 -0
- package/src/sequencer/chain_state_overrides.ts +162 -0
- package/src/sequencer/checkpoint_proposal_job.ts +1632 -0
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +119 -0
- package/src/sequencer/config.ts +8 -0
- package/src/sequencer/errors.ts +21 -0
- package/src/sequencer/events.ts +76 -0
- package/src/sequencer/index.ts +5 -1
- package/src/sequencer/metrics.ts +397 -75
- package/src/sequencer/sequencer.ts +1013 -579
- package/src/sequencer/timetable.ts +225 -60
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +28 -60
- package/src/test/index.ts +11 -5
- package/src/test/mock_checkpoint_builder.ts +323 -0
- package/src/test/utils.ts +185 -0
- package/dest/sequencer/allowed.d.ts +0 -3
- package/dest/sequencer/allowed.d.ts.map +0 -1
- package/dest/sequencer/allowed.js +0 -27
- package/dest/slasher/factory.d.ts +0 -7
- package/dest/slasher/factory.d.ts.map +0 -1
- package/dest/slasher/factory.js +0 -8
- package/dest/slasher/index.d.ts +0 -3
- package/dest/slasher/index.d.ts.map +0 -1
- package/dest/slasher/index.js +0 -2
- package/dest/slasher/slasher_client.d.ts +0 -75
- package/dest/slasher/slasher_client.d.ts.map +0 -1
- package/dest/slasher/slasher_client.js +0 -132
- package/dest/tx_validator/archive_cache.d.ts +0 -14
- package/dest/tx_validator/archive_cache.d.ts.map +0 -1
- package/dest/tx_validator/archive_cache.js +0 -22
- package/dest/tx_validator/gas_validator.d.ts +0 -14
- package/dest/tx_validator/gas_validator.d.ts.map +0 -1
- package/dest/tx_validator/gas_validator.js +0 -78
- package/dest/tx_validator/nullifier_cache.d.ts +0 -16
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/phases_validator.d.ts +0 -12
- package/dest/tx_validator/phases_validator.d.ts.map +0 -1
- package/dest/tx_validator/phases_validator.js +0 -80
- package/dest/tx_validator/test_utils.d.ts +0 -23
- package/dest/tx_validator/test_utils.d.ts.map +0 -1
- package/dest/tx_validator/test_utils.js +0 -26
- 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 -50
- package/src/sequencer/allowed.ts +0 -36
- package/src/slasher/factory.ts +0 -15
- package/src/slasher/index.ts +0 -2
- package/src/slasher/slasher_client.ts +0 -193
- package/src/tx_validator/archive_cache.ts +0 -28
- package/src/tx_validator/gas_validator.ts +0 -101
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/phases_validator.ts +0 -98
- package/src/tx_validator/test_utils.ts +0 -48
- package/src/tx_validator/tx_validator_factory.ts +0 -120
|
@@ -1,759 +1,1193 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { getKzg } from '@aztec/blob-lib';
|
|
2
|
+
import { type EpochCache, PROPOSER_PIPELINING_SLOT_OFFSET } from '@aztec/epoch-cache';
|
|
3
|
+
import { NoCommitteeError, type RollupContract } from '@aztec/ethereum/contracts';
|
|
4
|
+
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
5
|
+
import { merge, omit, pick } from '@aztec/foundation/collection';
|
|
6
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
7
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
|
-
import type
|
|
6
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
7
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
8
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
8
9
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
9
|
-
import {
|
|
10
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
11
|
+
import type { TypedEventEmitter } from '@aztec/foundation/types';
|
|
10
12
|
import type { P2P } from '@aztec/p2p';
|
|
11
|
-
import type {
|
|
12
|
-
import type {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
import type { SlasherClientInterface } from '@aztec/slasher';
|
|
14
|
+
import type {
|
|
15
|
+
BlockData,
|
|
16
|
+
L2BlockSink,
|
|
17
|
+
L2BlockSource,
|
|
18
|
+
ProposedCheckpointSink,
|
|
19
|
+
ValidateCheckpointResult,
|
|
20
|
+
} from '@aztec/stdlib/block';
|
|
21
|
+
import type { Checkpoint, ProposedCheckpointData } from '@aztec/stdlib/checkpoint';
|
|
22
|
+
import type { ChainConfig } from '@aztec/stdlib/config';
|
|
23
|
+
import { getEpochAtSlot, getSlotStartBuildTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
18
24
|
import {
|
|
19
|
-
type
|
|
25
|
+
type ResolvedSequencerConfig,
|
|
26
|
+
type SequencerConfig,
|
|
20
27
|
SequencerConfigSchema,
|
|
21
28
|
type WorldStateSynchronizer,
|
|
22
|
-
type WorldStateSynchronizerStatus,
|
|
23
29
|
} from '@aztec/stdlib/interfaces/server';
|
|
24
30
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
31
|
+
import type { CoordinationSignatureContext } from '@aztec/stdlib/p2p';
|
|
25
32
|
import { pickFromSchema } from '@aztec/stdlib/schemas';
|
|
26
|
-
import
|
|
27
|
-
import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
|
|
28
|
-
import {
|
|
29
|
-
BlockHeader,
|
|
30
|
-
ContentCommitment,
|
|
31
|
-
type GlobalVariables,
|
|
32
|
-
StateReference,
|
|
33
|
-
Tx,
|
|
34
|
-
type TxHash,
|
|
35
|
-
} from '@aztec/stdlib/tx';
|
|
33
|
+
import { MIN_EXECUTION_TIME } from '@aztec/stdlib/timetable';
|
|
36
34
|
import { Attributes, type TelemetryClient, type Tracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
37
|
-
import type
|
|
35
|
+
import { FullNodeCheckpointsBuilder, NodeKeystoreAdapter, type ValidatorClient } from '@aztec/validator-client';
|
|
36
|
+
|
|
37
|
+
import EventEmitter from 'node:events';
|
|
38
38
|
|
|
39
|
+
import { DefaultSequencerConfig } from '../config.js';
|
|
39
40
|
import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
40
|
-
import
|
|
41
|
-
import type {
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
import
|
|
41
|
+
import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
|
|
42
|
+
import type { InvalidateCheckpointRequest, SequencerPublisher } from '../publisher/sequencer-publisher.js';
|
|
43
|
+
import { buildCheckpointSimulationOverridesPlan } from './chain_state_overrides.js';
|
|
44
|
+
import { CheckpointProposalJob } from './checkpoint_proposal_job.js';
|
|
45
|
+
import { CheckpointProposalJobMetrics } from './checkpoint_proposal_job_metrics.js';
|
|
46
|
+
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
47
|
+
import { SequencerInterruptedError, SequencerTooSlowError } from './errors.js';
|
|
48
|
+
import type { SequencerEvents } from './events.js';
|
|
45
49
|
import { SequencerMetrics } from './metrics.js';
|
|
46
|
-
import { SequencerTimetable
|
|
47
|
-
import {
|
|
50
|
+
import { SequencerTimetable } from './timetable.js';
|
|
51
|
+
import type { SequencerRollupConstants } from './types.js';
|
|
52
|
+
import { SequencerState } from './utils.js';
|
|
48
53
|
|
|
49
54
|
export { SequencerState };
|
|
50
55
|
|
|
51
|
-
|
|
56
|
+
/** Slot snapshot used to prepare a checkpoint proposal. */
|
|
57
|
+
type SequencerSlotContext = {
|
|
58
|
+
slot: SlotNumber;
|
|
59
|
+
targetSlot: SlotNumber;
|
|
60
|
+
epoch: EpochNumber;
|
|
61
|
+
targetEpoch: EpochNumber;
|
|
62
|
+
ts: bigint;
|
|
63
|
+
nowSeconds: bigint;
|
|
64
|
+
};
|
|
52
65
|
|
|
53
66
|
/**
|
|
54
67
|
* Sequencer client
|
|
55
|
-
* -
|
|
56
|
-
* -
|
|
57
|
-
* -
|
|
58
|
-
* -
|
|
59
|
-
* -
|
|
60
|
-
* - Publishes L1 tx(s) to the rollup contract via RollupPublisher.
|
|
68
|
+
* - Checks whether it is elected as proposer for the next slot
|
|
69
|
+
* - Builds multiple blocks and broadcasts them
|
|
70
|
+
* - Collects attestations for the checkpoint
|
|
71
|
+
* - Publishes the checkpoint to L1
|
|
72
|
+
* - Votes for proposals and slashes on L1
|
|
61
73
|
*/
|
|
62
|
-
export class Sequencer {
|
|
74
|
+
export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<SequencerEvents>) {
|
|
63
75
|
private runningPromise?: RunningPromise;
|
|
64
|
-
private pollingIntervalMs: number = 1000;
|
|
65
|
-
private maxTxsPerBlock = 32;
|
|
66
|
-
private minTxsPerBlock = 1;
|
|
67
|
-
private maxL1TxInclusionTimeIntoSlot = 0;
|
|
68
|
-
// TODO: zero values should not be allowed for the following 2 values in PROD
|
|
69
|
-
private _coinbase = EthAddress.ZERO;
|
|
70
|
-
private _feeRecipient = AztecAddress.ZERO;
|
|
71
76
|
private state = SequencerState.STOPPED;
|
|
72
|
-
private
|
|
73
|
-
private
|
|
74
|
-
private maxBlockGas: Gas = new Gas(100e9, 100e9);
|
|
77
|
+
private stateSlotNumber: SlotNumber | undefined;
|
|
78
|
+
private stateEnteredAtMs = performance.now();
|
|
75
79
|
private metrics: SequencerMetrics;
|
|
76
|
-
private
|
|
80
|
+
private checkpointProposalJobMetrics: CheckpointProposalJobMetrics;
|
|
81
|
+
private readonly stateLog: Logger;
|
|
82
|
+
|
|
83
|
+
/** The last slot for which we attempted to perform our voting duties with degraded block production */
|
|
84
|
+
private lastSlotForFallbackVote: SlotNumber | undefined;
|
|
85
|
+
|
|
86
|
+
/** The last slot for which we logged "no committee" warning, to avoid spam */
|
|
87
|
+
private lastSlotForNoCommitteeWarning: SlotNumber | undefined;
|
|
88
|
+
|
|
89
|
+
/** The last slot for which we triggered a checkpoint proposal job, to prevent duplicate attempts. */
|
|
90
|
+
private lastSlotForCheckpointProposalJob: SlotNumber | undefined;
|
|
91
|
+
|
|
92
|
+
/** Last successful checkpoint proposed */
|
|
93
|
+
private lastCheckpointProposed: Checkpoint | undefined;
|
|
94
|
+
|
|
95
|
+
/** The last epoch for which we logged strategy comparison in fisherman mode. */
|
|
96
|
+
private lastEpochForStrategyComparison: EpochNumber | undefined;
|
|
97
|
+
|
|
98
|
+
/** The last checkpoint proposal job, tracked so we can await its pending L1 submission during shutdown. */
|
|
99
|
+
protected lastCheckpointProposalJob: CheckpointProposalJob | undefined;
|
|
77
100
|
|
|
78
101
|
/** The maximum number of seconds that the sequencer can be into a slot to transition to a particular state. */
|
|
79
102
|
protected timetable!: SequencerTimetable;
|
|
80
103
|
|
|
81
|
-
|
|
104
|
+
/** Config for the sequencer */
|
|
105
|
+
protected config: ResolvedSequencerConfig = DefaultSequencerConfig;
|
|
106
|
+
private readonly signatureContext: CoordinationSignatureContext;
|
|
82
107
|
|
|
83
108
|
constructor(
|
|
84
|
-
protected
|
|
85
|
-
protected validatorClient: ValidatorClient
|
|
109
|
+
protected publisherFactory: SequencerPublisherFactory,
|
|
110
|
+
protected validatorClient: ValidatorClient,
|
|
86
111
|
protected globalsBuilder: GlobalVariableBuilder,
|
|
87
112
|
protected p2pClient: P2P,
|
|
88
113
|
protected worldState: WorldStateSynchronizer,
|
|
89
|
-
protected slasherClient:
|
|
90
|
-
protected
|
|
91
|
-
protected l2BlockSource: L2BlockSource,
|
|
114
|
+
protected slasherClient: SlasherClientInterface | undefined,
|
|
115
|
+
protected l2BlockSource: L2BlockSource & L2BlockSink & ProposedCheckpointSink,
|
|
92
116
|
protected l1ToL2MessageSource: L1ToL2MessageSource,
|
|
93
|
-
protected
|
|
94
|
-
protected contractDataSource: ContractDataSource,
|
|
117
|
+
protected checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
95
118
|
protected l1Constants: SequencerRollupConstants,
|
|
96
119
|
protected dateProvider: DateProvider,
|
|
97
|
-
protected
|
|
98
|
-
|
|
120
|
+
protected epochCache: EpochCache,
|
|
121
|
+
protected rollupContract: RollupContract,
|
|
122
|
+
config: SequencerConfig & Pick<ChainConfig, 'l1ChainId' | 'rollupAddress'>,
|
|
123
|
+
protected telemetry: TelemetryClient = getTelemetryClient(),
|
|
99
124
|
protected log = createLogger('sequencer'),
|
|
100
125
|
) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// Register the block builder with the validator client for re-execution
|
|
104
|
-
this.validatorClient?.registerBlockBuilder(this.buildBlock.bind(this));
|
|
126
|
+
super();
|
|
127
|
+
this.stateLog = log.createChild('state');
|
|
105
128
|
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
get tracer(): Tracer {
|
|
111
|
-
return this.metrics.tracer;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Updates sequencer config.
|
|
116
|
-
* @param config - New parameters.
|
|
117
|
-
*/
|
|
118
|
-
public async updateConfig(config: SequencerConfig) {
|
|
119
|
-
this.log.info(`Sequencer config set`, omit(pickFromSchema(config, SequencerConfigSchema), 'allowedInSetup'));
|
|
120
|
-
|
|
121
|
-
if (config.transactionPollingIntervalMS !== undefined) {
|
|
122
|
-
this.pollingIntervalMs = config.transactionPollingIntervalMS;
|
|
123
|
-
}
|
|
124
|
-
if (config.maxTxsPerBlock !== undefined) {
|
|
125
|
-
this.maxTxsPerBlock = config.maxTxsPerBlock;
|
|
129
|
+
// Add [FISHERMAN] prefix to logger if in fisherman mode
|
|
130
|
+
if (config.fishermanMode) {
|
|
131
|
+
this.log = log.createChild('[FISHERMAN]');
|
|
126
132
|
}
|
|
127
|
-
if (config.minTxsPerBlock !== undefined) {
|
|
128
|
-
this.minTxsPerBlock = config.minTxsPerBlock;
|
|
129
|
-
}
|
|
130
|
-
if (config.maxDABlockGas !== undefined) {
|
|
131
|
-
this.maxBlockGas = new Gas(config.maxDABlockGas, this.maxBlockGas.l2Gas);
|
|
132
|
-
}
|
|
133
|
-
if (config.maxL2BlockGas !== undefined) {
|
|
134
|
-
this.maxBlockGas = new Gas(this.maxBlockGas.daGas, config.maxL2BlockGas);
|
|
135
|
-
}
|
|
136
|
-
if (config.coinbase) {
|
|
137
|
-
this._coinbase = config.coinbase;
|
|
138
|
-
}
|
|
139
|
-
if (config.feeRecipient) {
|
|
140
|
-
this._feeRecipient = config.feeRecipient;
|
|
141
|
-
}
|
|
142
|
-
if (config.allowedInSetup) {
|
|
143
|
-
this.allowedInSetup = config.allowedInSetup;
|
|
144
|
-
} else {
|
|
145
|
-
this.allowedInSetup = await getDefaultAllowedSetupFunctions();
|
|
146
|
-
}
|
|
147
|
-
if (config.maxBlockSizeInBytes !== undefined) {
|
|
148
|
-
this.maxBlockSizeInBytes = config.maxBlockSizeInBytes;
|
|
149
|
-
}
|
|
150
|
-
if (config.governanceProposerPayload) {
|
|
151
|
-
this.publisher.setGovernancePayload(config.governanceProposerPayload);
|
|
152
|
-
}
|
|
153
|
-
if (config.maxL1TxInclusionTimeIntoSlot !== undefined) {
|
|
154
|
-
this.maxL1TxInclusionTimeIntoSlot = config.maxL1TxInclusionTimeIntoSlot;
|
|
155
|
-
}
|
|
156
|
-
if (config.enforceTimeTable !== undefined) {
|
|
157
|
-
this.enforceTimeTable = config.enforceTimeTable;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
this.setTimeTable();
|
|
161
133
|
|
|
162
|
-
|
|
163
|
-
|
|
134
|
+
this.signatureContext = {
|
|
135
|
+
chainId: config.l1ChainId,
|
|
136
|
+
rollupAddress: config.rollupAddress,
|
|
137
|
+
};
|
|
138
|
+
this.metrics = new SequencerMetrics(telemetry, this.rollupContract, 'Sequencer');
|
|
139
|
+
this.checkpointProposalJobMetrics = new CheckpointProposalJobMetrics(telemetry);
|
|
140
|
+
this.updateConfig(config);
|
|
164
141
|
}
|
|
165
142
|
|
|
166
|
-
|
|
143
|
+
/** Updates sequencer config by the defined values and updates the timetable */
|
|
144
|
+
public updateConfig(config: Partial<SequencerConfig>) {
|
|
145
|
+
const filteredConfig = pickFromSchema(config, SequencerConfigSchema);
|
|
146
|
+
this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowListExtend'));
|
|
147
|
+
this.config = merge(this.config, filteredConfig);
|
|
148
|
+
const p2pPropagationTime = this.config.attestationPropagationTime;
|
|
167
149
|
this.timetable = new SequencerTimetable(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
150
|
+
{
|
|
151
|
+
ethereumSlotDuration: this.l1Constants.ethereumSlotDuration,
|
|
152
|
+
aztecSlotDuration: this.aztecSlotDuration,
|
|
153
|
+
l1PublishingTime: this.l1PublishingTime,
|
|
154
|
+
p2pPropagationTime,
|
|
155
|
+
blockDurationMs: this.config.blockDurationMs,
|
|
156
|
+
enforce: this.config.enforceTimeTable,
|
|
157
|
+
},
|
|
172
158
|
this.metrics,
|
|
173
159
|
this.log,
|
|
174
160
|
);
|
|
175
|
-
this.log.verbose(`Sequencer timetable updated`, { enforceTimeTable: this.enforceTimeTable });
|
|
176
161
|
}
|
|
177
162
|
|
|
178
|
-
/**
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
163
|
+
/** Initializes the sequencer (precomputes tables). Takes about 3s. */
|
|
164
|
+
public init() {
|
|
165
|
+
getKzg();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Starts the sequencer and moves to IDLE state. */
|
|
169
|
+
public start() {
|
|
170
|
+
this.runningPromise = new RunningPromise(
|
|
171
|
+
this.safeWork.bind(this),
|
|
172
|
+
this.log,
|
|
173
|
+
this.config.sequencerPollingIntervalMS,
|
|
174
|
+
);
|
|
175
|
+
this.setState(SequencerState.IDLE, undefined, { force: true });
|
|
185
176
|
this.runningPromise.start();
|
|
186
|
-
this.log.info(
|
|
177
|
+
this.log.info('Started sequencer');
|
|
187
178
|
}
|
|
188
179
|
|
|
189
|
-
/**
|
|
190
|
-
|
|
191
|
-
|
|
180
|
+
/** Triggers an immediate run of the sequencer, bypassing the polling interval. */
|
|
181
|
+
public trigger() {
|
|
182
|
+
return this.runningPromise?.trigger();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Stops the sequencer from building blocks and moves to STOPPED state. */
|
|
192
186
|
public async stop(): Promise<void> {
|
|
193
|
-
this.log.
|
|
194
|
-
|
|
187
|
+
this.log.info(`Stopping sequencer`);
|
|
188
|
+
this.setState(SequencerState.STOPPING, undefined, { force: true });
|
|
189
|
+
this.lastCheckpointProposalJob?.interrupt();
|
|
190
|
+
await this.publisherFactory.stopAll();
|
|
195
191
|
await this.runningPromise?.stop();
|
|
196
|
-
this.
|
|
197
|
-
this.
|
|
198
|
-
this.setState(SequencerState.STOPPED, 0n, true /** force */);
|
|
192
|
+
await this.lastCheckpointProposalJob?.awaitPendingSubmission();
|
|
193
|
+
this.setState(SequencerState.STOPPED, undefined, { force: true });
|
|
199
194
|
this.log.info('Stopped sequencer');
|
|
200
195
|
}
|
|
201
196
|
|
|
202
|
-
/**
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
197
|
+
/** Main sequencer loop with a try/catch */
|
|
198
|
+
protected async safeWork() {
|
|
199
|
+
try {
|
|
200
|
+
await this.work();
|
|
201
|
+
} catch (err) {
|
|
202
|
+
if (
|
|
203
|
+
err instanceof SequencerTooSlowError &&
|
|
204
|
+
[SequencerState.INITIALIZING_CHECKPOINT, SequencerState.PROPOSER_CHECK].includes(err.proposedState)
|
|
205
|
+
) {
|
|
206
|
+
// No need to alert if we just didn't get to start in time
|
|
207
|
+
this.log.debug(err.message, { now: this.dateProvider.nowInSeconds() });
|
|
208
|
+
} else {
|
|
209
|
+
// Re-throw other errors
|
|
210
|
+
this.emit('checkpoint-error', { error: err as Error });
|
|
211
|
+
throw err;
|
|
212
|
+
}
|
|
213
|
+
} finally {
|
|
214
|
+
this.setState(SequencerState.IDLE, undefined);
|
|
215
|
+
}
|
|
210
216
|
}
|
|
211
217
|
|
|
212
|
-
/**
|
|
213
|
-
* Returns the current state of the sequencer.
|
|
214
|
-
* @returns An object with a state entry with one of SequencerState.
|
|
215
|
-
*/
|
|
218
|
+
/** Returns the current state of the sequencer. */
|
|
216
219
|
public status() {
|
|
217
220
|
return { state: this.state };
|
|
218
221
|
}
|
|
219
222
|
|
|
220
|
-
/** Forces the sequencer to bypass all time and tx count checks for the next block and build anyway. */
|
|
221
|
-
public flush() {
|
|
222
|
-
this.isFlushing = true;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
223
|
/**
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
224
|
+
* Main sequencer loop:
|
|
225
|
+
* - Checks if we are up to date
|
|
226
|
+
* - If we are and we are the sequencer, collect txs and build blocks
|
|
227
|
+
* - Build multiple blocks per slot when configured
|
|
228
|
+
* - Collect attestations for the final block
|
|
229
|
+
* - Submit checkpoint
|
|
232
230
|
*/
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
if
|
|
231
|
+
@trackSpan('Sequencer.work')
|
|
232
|
+
protected async work() {
|
|
233
|
+
this.setState(SequencerState.SYNCHRONIZING, undefined);
|
|
234
|
+
const { slot, targetSlot, epoch, targetEpoch, ts, nowSeconds } = this.getSlotContextInNextL1Slot();
|
|
235
|
+
|
|
236
|
+
// Check if we are synced and it's our slot, grab a publisher, check previous block invalidation, etc
|
|
237
|
+
const checkpointProposalJob = await this.prepareCheckpointProposal(
|
|
238
|
+
slot,
|
|
239
|
+
targetSlot,
|
|
240
|
+
epoch,
|
|
241
|
+
targetEpoch,
|
|
242
|
+
ts,
|
|
243
|
+
nowSeconds,
|
|
244
|
+
);
|
|
245
|
+
if (!checkpointProposalJob) {
|
|
239
246
|
return;
|
|
240
247
|
}
|
|
241
248
|
|
|
242
|
-
|
|
249
|
+
// Track the job so we can await its pending L1 submission during shutdown
|
|
250
|
+
this.lastCheckpointProposalJob = checkpointProposalJob;
|
|
243
251
|
|
|
244
|
-
|
|
252
|
+
// Execute the checkpoint proposal job
|
|
253
|
+
const checkpoint = await checkpointProposalJob.execute();
|
|
245
254
|
|
|
246
|
-
//
|
|
247
|
-
|
|
255
|
+
// Update last checkpoint proposed (currently unused)
|
|
256
|
+
if (checkpoint) {
|
|
257
|
+
this.lastCheckpointProposed = checkpoint;
|
|
258
|
+
}
|
|
248
259
|
|
|
249
|
-
|
|
250
|
-
if (
|
|
251
|
-
this.
|
|
252
|
-
|
|
260
|
+
// Log fee strategy comparison if on fisherman (uses target epoch since we mirror the proposer's perspective)
|
|
261
|
+
if (
|
|
262
|
+
this.config.fishermanMode &&
|
|
263
|
+
(this.lastEpochForStrategyComparison === undefined || targetEpoch > this.lastEpochForStrategyComparison)
|
|
264
|
+
) {
|
|
265
|
+
this.logStrategyComparison(targetEpoch, checkpointProposalJob.getPublisher());
|
|
266
|
+
this.lastEpochForStrategyComparison = targetEpoch;
|
|
253
267
|
}
|
|
254
268
|
|
|
255
|
-
|
|
269
|
+
return checkpoint;
|
|
270
|
+
}
|
|
256
271
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
272
|
+
/** Returns slot and target slot from a single clock snapshot. */
|
|
273
|
+
protected getSlotContextInNextL1Slot(): SequencerSlotContext {
|
|
274
|
+
const { slot, ts, nowSeconds, epoch } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
275
|
+
const targetSlot = SlotNumber(slot + PROPOSER_PIPELINING_SLOT_OFFSET);
|
|
276
|
+
return { slot, targetSlot, epoch, targetEpoch: getEpochAtSlot(targetSlot, this.l1Constants), ts, nowSeconds };
|
|
277
|
+
}
|
|
263
278
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
279
|
+
/**
|
|
280
|
+
* Prepares the checkpoint proposal by performing all necessary checks and setup.
|
|
281
|
+
* This is the initial step in the main loop.
|
|
282
|
+
* @returns CheckpointProposalJob if successful, undefined if we are not yet synced or are not the proposer.
|
|
283
|
+
*/
|
|
284
|
+
@trackSpan('Sequencer.prepareCheckpointProposal')
|
|
285
|
+
protected async prepareCheckpointProposal(
|
|
286
|
+
slot: SlotNumber,
|
|
287
|
+
targetSlot: SlotNumber,
|
|
288
|
+
epoch: EpochNumber,
|
|
289
|
+
targetEpoch: EpochNumber,
|
|
290
|
+
ts: bigint,
|
|
291
|
+
nowSeconds: bigint,
|
|
292
|
+
): Promise<CheckpointProposalJob | undefined> {
|
|
293
|
+
// Check we have not already processed this target slot (cheapest check)
|
|
294
|
+
// We only check this if enforce timetable is set, since we want to keep processing the same slot if we are not
|
|
295
|
+
// running against actual time (eg when we use sandbox-style automining)
|
|
296
|
+
if (
|
|
297
|
+
this.lastSlotForCheckpointProposalJob &&
|
|
298
|
+
this.lastSlotForCheckpointProposalJob >= targetSlot &&
|
|
299
|
+
this.config.enforceTimeTable
|
|
300
|
+
) {
|
|
301
|
+
this.log.trace(`Target slot ${targetSlot} has already been processed`);
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// But if we have already proposed for this slot, then we definitely have to skip it, automining or not
|
|
306
|
+
if (this.lastCheckpointProposed && this.lastCheckpointProposed.header.slotNumber >= targetSlot) {
|
|
307
|
+
this.log.trace(
|
|
308
|
+
`Slot ${targetSlot} has already been published as checkpoint ${this.lastCheckpointProposed.number}`,
|
|
309
|
+
);
|
|
310
|
+
return undefined;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Test-only: skip proposing for explicitly paused slots. Attestation paths run in the validator
|
|
314
|
+
// client and are not gated by this hook, so paused proposers still attest to others' proposals.
|
|
315
|
+
if (this.config.pauseProposingForSlots?.some(s => s === targetSlot)) {
|
|
316
|
+
this.log.warn(`Skipping proposal for paused slot ${targetSlot} (test-only pauseProposingForSlots hook)`, {
|
|
317
|
+
targetSlot,
|
|
318
|
+
});
|
|
319
|
+
return undefined;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// Check all components are synced to latest as seen by the archiver (queries all subsystems)
|
|
323
|
+
const syncedTo = await this.checkSync({ ts, slot });
|
|
324
|
+
if (!syncedTo) {
|
|
325
|
+
await this.tryVoteWhenSyncFails({ slot, targetSlot, ts });
|
|
326
|
+
return undefined;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// If escape hatch is open for the target epoch, do not start checkpoint proposal work and do not attempt invalidations.
|
|
330
|
+
// Still perform governance/slashing voting (as proposer) once per slot.
|
|
331
|
+
// When pipelining, we check the target epoch (slot+1's epoch) since that's the epoch we're building for.
|
|
332
|
+
const isEscapeHatchOpen = await this.epochCache.isEscapeHatchOpen(targetEpoch);
|
|
333
|
+
|
|
334
|
+
if (isEscapeHatchOpen) {
|
|
335
|
+
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
336
|
+
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
337
|
+
if (canPropose) {
|
|
338
|
+
await this.tryVoteWhenEscapeHatchOpen({ slot, targetSlot, proposer });
|
|
339
|
+
} else {
|
|
340
|
+
this.log.trace(`Escape hatch open but we are not proposer, skipping vote-only actions`, {
|
|
341
|
+
slot,
|
|
342
|
+
epoch,
|
|
343
|
+
proposer,
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
return undefined;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// Next checkpoint follows from the last synced one
|
|
350
|
+
const checkpointNumber = CheckpointNumber(syncedTo.checkpointNumber + 1);
|
|
274
351
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
blockNumber: newBlockNumber,
|
|
352
|
+
const logCtx = {
|
|
353
|
+
nowSeconds,
|
|
354
|
+
syncedToL2Slot: syncedTo.syncedL2Slot,
|
|
279
355
|
slot,
|
|
280
|
-
|
|
356
|
+
targetSlot,
|
|
357
|
+
slotTs: ts,
|
|
358
|
+
checkpointNumber,
|
|
359
|
+
isPendingChainValid: pick(syncedTo.pendingChainValidationStatus, 'valid', 'reason', 'invalidIndex'),
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
// Check that we are a proposer for the target slot.
|
|
363
|
+
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
364
|
+
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
365
|
+
|
|
366
|
+
// If we are not a proposer check if we should invalidate an invalid checkpoint, and bail
|
|
367
|
+
if (!canPropose) {
|
|
368
|
+
await this.considerInvalidatingCheckpoint(syncedTo, slot);
|
|
369
|
+
return undefined;
|
|
370
|
+
}
|
|
281
371
|
|
|
282
|
-
//
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
372
|
+
// Guard: don't exceed 1-deep pipeline. Without a proposed checkpoint, we can only build
|
|
373
|
+
// confirmed + 1. With a proposed checkpoint, we can build confirmed + 2.
|
|
374
|
+
const confirmedCkpt = syncedTo.checkpointedCheckpointNumber;
|
|
375
|
+
if (checkpointNumber > confirmedCkpt + 2) {
|
|
376
|
+
this.log.verbose(
|
|
377
|
+
`Skipping slot ${targetSlot}: checkpoint ${checkpointNumber} exceeds max pipeline depth (confirmed=${confirmedCkpt})`,
|
|
378
|
+
);
|
|
379
|
+
return undefined;
|
|
380
|
+
}
|
|
291
381
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
382
|
+
// Check that the target slot is not taken by a block already (should never happen, since only us can propose for this slot)
|
|
383
|
+
if (syncedTo.blockData && syncedTo.blockData.header.getSlot() >= targetSlot) {
|
|
384
|
+
this.log.warn(
|
|
385
|
+
`Cannot propose block at target slot ${targetSlot} since that slot was taken by block ${syncedTo.blockNumber}`,
|
|
386
|
+
{ ...logCtx, block: syncedTo.blockData.header.toInspect() },
|
|
387
|
+
);
|
|
388
|
+
this.metrics.recordCheckpointPrecheckFailed('slot_already_taken');
|
|
389
|
+
return undefined;
|
|
390
|
+
}
|
|
298
391
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
392
|
+
// We now need to get ourselves a publisher.
|
|
393
|
+
// The returned attestor will be the one we provided if we provided one.
|
|
394
|
+
// Otherwise it will be a valid attestor for the returned publisher.
|
|
395
|
+
// In fisherman mode, pass undefined to use the fisherman's own keystore instead of the actual proposer's
|
|
396
|
+
const proposerForPublisher = this.config.fishermanMode ? undefined : proposer;
|
|
397
|
+
const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
|
|
398
|
+
this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
|
|
399
|
+
|
|
400
|
+
// Prepare invalidation request if the pending chain is invalid (returns undefined if no need).
|
|
401
|
+
// Only simulate invalidation when there's no proposed parent, since we assume the proposed parent
|
|
402
|
+
// will invalidate the currently invalid checkpoint on L1.
|
|
403
|
+
const invalidateCheckpoint =
|
|
404
|
+
syncedTo.hasProposedCheckpoint || syncedTo.pendingChainValidationStatus.valid
|
|
405
|
+
? undefined
|
|
406
|
+
: await publisher.simulateInvalidateCheckpoint(syncedTo.pendingChainValidationStatus);
|
|
407
|
+
|
|
408
|
+
// Determine the correct archive and L1 state overrides for the canProposeAt check.
|
|
409
|
+
// The L1 contract reads archives[proposedCheckpointNumber] and compares it with the provided archive.
|
|
410
|
+
// When invalidating or pipelining, the local archive may differ from L1's, so we adjust accordingly.
|
|
411
|
+
let archiveForCheck = syncedTo.archive;
|
|
412
|
+
|
|
413
|
+
if (syncedTo.hasProposedCheckpoint) {
|
|
414
|
+
this.metrics.recordPipelineDepth(syncedTo.checkpointNumber - syncedTo.checkpointedCheckpointNumber);
|
|
415
|
+
this.log.verbose(
|
|
416
|
+
`Building on top of proposed checkpoint (pending=${syncedTo.proposedCheckpointData?.checkpointNumber}) for target slot ${targetSlot}`,
|
|
417
|
+
{ targetSlot, parentCheckpointNumber: CheckpointNumber(checkpointNumber - 1) },
|
|
306
418
|
);
|
|
419
|
+
// Match what L1 will see at archives[pending] once the proposed parent lands: the parent's
|
|
420
|
+
// own archive root from the gossiped proposal. `syncedTo.archive` is the world-state-local
|
|
421
|
+
// view and can transiently diverge from the proposed parent (e.g. before the proposed
|
|
422
|
+
// parent's blocks have been applied locally); diverging here would cause the canProposeAt
|
|
423
|
+
// override to set archives[pending] to one value while we present another for comparison.
|
|
424
|
+
archiveForCheck = syncedTo.proposedCheckpointData!.archive.root;
|
|
425
|
+
} else if (invalidateCheckpoint) {
|
|
426
|
+
// After invalidation, L1 will roll back to checkpoint N-1. The archive at N-1 already
|
|
427
|
+
// exists on L1, so we just pass the matching archive (the lastArchive of the invalid checkpoint).
|
|
428
|
+
archiveForCheck = invalidateCheckpoint.lastArchive;
|
|
429
|
+
this.metrics.recordPipelineDepth(0);
|
|
430
|
+
} else {
|
|
431
|
+
this.metrics.recordPipelineDepth(0);
|
|
307
432
|
}
|
|
308
433
|
|
|
309
|
-
|
|
310
|
-
|
|
434
|
+
// Build the simulation plan: pending/proven override from pipelining or invalidation (or the
|
|
435
|
+
// current snapshot when neither applies, to short-circuit any pending prune in simulation),
|
|
436
|
+
// plus the parent checkpoint cell and fee header when pipelining.
|
|
437
|
+
const simulationOverridesPlan = await buildCheckpointSimulationOverridesPlan({
|
|
438
|
+
checkpointNumber,
|
|
439
|
+
proposedCheckpointData: syncedTo.hasProposedCheckpoint ? syncedTo.proposedCheckpointData : undefined,
|
|
440
|
+
invalidateToPendingCheckpointNumber: invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
441
|
+
checkpointedCheckpointNumber: syncedTo.checkpointedCheckpointNumber,
|
|
442
|
+
rollup: this.rollupContract,
|
|
443
|
+
signatureContext: this.signatureContext,
|
|
444
|
+
log: this.log,
|
|
311
445
|
});
|
|
312
|
-
|
|
313
|
-
|
|
446
|
+
|
|
447
|
+
// The plan always pins both pending/proven (to short-circuit `canPruneAtTime` in simulation),
|
|
448
|
+
// so `provenOverride` always reflects the assumed proven checkpoint we are pinning the
|
|
449
|
+
// simulation to. We additionally warn when the pin is load-bearing — i.e. when a prune would
|
|
450
|
+
// actually fire at the target slot without it — so observers can spot "we are building
|
|
451
|
+
// optimistically across a pruning boundary" in the logs.
|
|
452
|
+
const provenOverride = simulationOverridesPlan?.chainTipsOverride?.proven;
|
|
453
|
+
if (provenOverride !== undefined && (await this.l2BlockSource.isPruneDueAtSlot(targetSlot))) {
|
|
454
|
+
this.log.warn(
|
|
455
|
+
`Assuming proof for epoch ending at checkpoint ${provenOverride} lands by target slot ${targetSlot}`,
|
|
456
|
+
{ checkpointNumber, slot, targetSlot, provenOverride },
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
this.emit('preparing-checkpoint', {
|
|
461
|
+
targetSlot,
|
|
462
|
+
checkpointNumber,
|
|
463
|
+
hadProposedParent: syncedTo.hasProposedCheckpoint,
|
|
464
|
+
provenOverride,
|
|
465
|
+
simulatedPending: simulationOverridesPlan?.chainTipsOverride?.pending,
|
|
314
466
|
});
|
|
315
467
|
|
|
316
|
-
await
|
|
468
|
+
const canProposeCheck = await publisher.canProposeAt(
|
|
469
|
+
archiveForCheck,
|
|
470
|
+
proposer ?? EthAddress.ZERO,
|
|
471
|
+
simulationOverridesPlan,
|
|
472
|
+
);
|
|
317
473
|
|
|
318
|
-
|
|
319
|
-
|
|
474
|
+
const proposeContext = {
|
|
475
|
+
hasProposedCheckpoint: syncedTo.hasProposedCheckpoint,
|
|
476
|
+
proposedCheckpointNumber: syncedTo.proposedCheckpointData?.checkpointNumber,
|
|
477
|
+
checkpointedCheckpointNumber: syncedTo.checkpointedCheckpointNumber,
|
|
478
|
+
isInvalidating: !!invalidateCheckpoint,
|
|
479
|
+
invalidatingCheckpointNumber: invalidateCheckpoint?.checkpointNumber,
|
|
480
|
+
archiveForCheck: archiveForCheck.toString(),
|
|
481
|
+
overridePendingCheckpointNumber: simulationOverridesPlan?.chainTipsOverride?.pending,
|
|
482
|
+
overrideArchive: simulationOverridesPlan?.pendingCheckpointState?.archive,
|
|
483
|
+
overrideFeeHeader: simulationOverridesPlan?.pendingCheckpointState?.feeHeader,
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
if (canProposeCheck === undefined) {
|
|
487
|
+
this.log.warn(
|
|
488
|
+
`Cannot propose checkpoint ${checkpointNumber} at slot ${slot} due to failed rollup contract check`,
|
|
489
|
+
{ ...logCtx, ...proposeContext },
|
|
490
|
+
);
|
|
491
|
+
this.emit('proposer-rollup-check-failed', { reason: 'Rollup contract check failed', slot });
|
|
492
|
+
this.metrics.recordCheckpointPrecheckFailed('rollup_contract_check_failed');
|
|
493
|
+
return undefined;
|
|
320
494
|
}
|
|
321
495
|
|
|
322
|
-
|
|
323
|
-
|
|
496
|
+
if (canProposeCheck.slot !== targetSlot) {
|
|
497
|
+
this.log.warn(
|
|
498
|
+
`Cannot propose block due to slot mismatch with rollup contract (this can be caused by a clock out of sync). Expected slot ${targetSlot} but got ${canProposeCheck.slot}.`,
|
|
499
|
+
{ ...logCtx, ...proposeContext, rollup: canProposeCheck, expectedSlot: targetSlot },
|
|
500
|
+
);
|
|
501
|
+
this.emit('proposer-rollup-check-failed', { reason: 'Slot mismatch', slot });
|
|
502
|
+
this.metrics.recordCheckpointPrecheckFailed('slot_mismatch');
|
|
503
|
+
return undefined;
|
|
504
|
+
}
|
|
324
505
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
// Re-throw other errors
|
|
334
|
-
throw err;
|
|
335
|
-
}
|
|
336
|
-
} finally {
|
|
337
|
-
this.setState(SequencerState.IDLE, 0n);
|
|
506
|
+
if (canProposeCheck.checkpointNumber !== checkpointNumber) {
|
|
507
|
+
this.log.warn(
|
|
508
|
+
`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}.`,
|
|
509
|
+
{ ...logCtx, ...proposeContext, rollup: canProposeCheck, expectedSlot: slot },
|
|
510
|
+
);
|
|
511
|
+
this.emit('proposer-rollup-check-failed', { reason: 'Block mismatch', slot });
|
|
512
|
+
this.metrics.recordCheckpointPrecheckFailed('block_number_mismatch');
|
|
513
|
+
return undefined;
|
|
338
514
|
}
|
|
515
|
+
|
|
516
|
+
this.lastSlotForCheckpointProposalJob = targetSlot;
|
|
517
|
+
|
|
518
|
+
await this.p2pClient.prepareForSlot(targetSlot);
|
|
519
|
+
this.log.info(
|
|
520
|
+
`Preparing checkpoint proposal ${checkpointNumber} for target slot ${targetSlot} during wall-clock slot ${slot}`,
|
|
521
|
+
{
|
|
522
|
+
...logCtx,
|
|
523
|
+
...proposeContext,
|
|
524
|
+
proposer,
|
|
525
|
+
},
|
|
526
|
+
);
|
|
527
|
+
|
|
528
|
+
// Create and return the checkpoint proposal job
|
|
529
|
+
return this.createCheckpointProposalJob(
|
|
530
|
+
slot,
|
|
531
|
+
targetSlot,
|
|
532
|
+
targetEpoch,
|
|
533
|
+
checkpointNumber,
|
|
534
|
+
syncedTo.blockNumber,
|
|
535
|
+
syncedTo.checkpointedCheckpointNumber,
|
|
536
|
+
proposer,
|
|
537
|
+
publisher,
|
|
538
|
+
attestorAddress,
|
|
539
|
+
invalidateCheckpoint,
|
|
540
|
+
syncedTo.proposedCheckpointData,
|
|
541
|
+
);
|
|
339
542
|
}
|
|
340
543
|
|
|
341
|
-
|
|
342
|
-
|
|
544
|
+
protected createCheckpointProposalJob(
|
|
545
|
+
slot: SlotNumber,
|
|
546
|
+
targetSlot: SlotNumber,
|
|
547
|
+
targetEpoch: EpochNumber,
|
|
548
|
+
checkpointNumber: CheckpointNumber,
|
|
549
|
+
syncedToBlockNumber: BlockNumber,
|
|
550
|
+
checkpointedCheckpointNumber: CheckpointNumber,
|
|
551
|
+
proposer: EthAddress | undefined,
|
|
552
|
+
publisher: SequencerPublisher,
|
|
553
|
+
attestorAddress: EthAddress,
|
|
554
|
+
invalidateCheckpoint: InvalidateCheckpointRequest | undefined,
|
|
555
|
+
proposedCheckpointData?: ProposedCheckpointData,
|
|
556
|
+
): CheckpointProposalJob {
|
|
557
|
+
return new CheckpointProposalJob(
|
|
558
|
+
slot,
|
|
559
|
+
targetSlot,
|
|
560
|
+
targetEpoch,
|
|
561
|
+
checkpointNumber,
|
|
562
|
+
syncedToBlockNumber,
|
|
563
|
+
checkpointedCheckpointNumber,
|
|
564
|
+
proposer,
|
|
565
|
+
publisher,
|
|
566
|
+
attestorAddress,
|
|
567
|
+
invalidateCheckpoint,
|
|
568
|
+
this.validatorClient,
|
|
569
|
+
this.globalsBuilder,
|
|
570
|
+
this.p2pClient,
|
|
571
|
+
this.worldState,
|
|
572
|
+
this.l1ToL2MessageSource,
|
|
573
|
+
this.l2BlockSource,
|
|
574
|
+
this.checkpointsBuilder,
|
|
575
|
+
this.l2BlockSource,
|
|
576
|
+
this.l1Constants,
|
|
577
|
+
this.signatureContext,
|
|
578
|
+
this.config,
|
|
579
|
+
this.timetable,
|
|
580
|
+
this.slasherClient,
|
|
581
|
+
this.epochCache,
|
|
582
|
+
this.dateProvider,
|
|
583
|
+
this.metrics,
|
|
584
|
+
this.checkpointProposalJobMetrics.createRecorder(),
|
|
585
|
+
this,
|
|
586
|
+
(state, slot, timeReferenceSlot) => this.setState(state, slot, { timeReferenceSlot }),
|
|
587
|
+
this.tracer,
|
|
588
|
+
this.log.getBindings(),
|
|
589
|
+
proposedCheckpointData,
|
|
590
|
+
);
|
|
343
591
|
}
|
|
344
592
|
|
|
345
593
|
/**
|
|
346
|
-
*
|
|
347
|
-
* @param tipArchive - The archive of the previous block.
|
|
348
|
-
* @param proposalBlockNumber - The block number of the proposal.
|
|
349
|
-
* @returns The slot number if we can propose at the next block, otherwise undefined.
|
|
594
|
+
* Returns the current sequencer state.
|
|
350
595
|
*/
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
if (!result) {
|
|
355
|
-
return undefined;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
const [slot, blockNumber] = result;
|
|
359
|
-
|
|
360
|
-
if (proposalBlockNumber !== blockNumber) {
|
|
361
|
-
const msg = `Sequencer block number mismatch. Expected ${proposalBlockNumber} but got ${blockNumber}.`;
|
|
362
|
-
this.log.warn(msg);
|
|
363
|
-
throw new Error(msg);
|
|
364
|
-
}
|
|
365
|
-
return slot;
|
|
596
|
+
public getState(): SequencerState {
|
|
597
|
+
return this.state;
|
|
366
598
|
}
|
|
367
599
|
|
|
368
600
|
/**
|
|
369
|
-
*
|
|
601
|
+
* Internal helper for setting the sequencer state and checks if we have enough time left in the slot to transition to the new state.
|
|
370
602
|
* @param proposedState - The new state to transition to.
|
|
371
|
-
* @param
|
|
603
|
+
* @param slotNumber - The logical slot associated with the new state.
|
|
372
604
|
* @param force - Whether to force the transition even if the sequencer is stopped.
|
|
373
|
-
*
|
|
374
|
-
* @dev If the `currentSlotNumber` doesn't matter (e.g. transitioning to IDLE), pass in `0n`;
|
|
375
|
-
* it is only used to check if we have enough time left in the slot to transition to the new state.
|
|
605
|
+
* @param timeReferenceSlot - The slot to use for deadline checks when it differs from the logical slot.
|
|
376
606
|
*/
|
|
377
|
-
setState(
|
|
378
|
-
|
|
607
|
+
protected setState(
|
|
608
|
+
proposedState: SequencerState,
|
|
609
|
+
slotNumber: SlotNumber | undefined,
|
|
610
|
+
opts: { force?: boolean; timeReferenceSlot?: SlotNumber } = {},
|
|
611
|
+
): void {
|
|
612
|
+
if (this.state === SequencerState.STOPPING && proposedState !== SequencerState.STOPPED && !opts.force) {
|
|
613
|
+
this.log.warn(`Cannot set sequencer to ${proposedState} as it is stopping.`);
|
|
614
|
+
throw new SequencerInterruptedError();
|
|
615
|
+
}
|
|
616
|
+
if (this.state === SequencerState.STOPPED && !opts.force) {
|
|
379
617
|
this.log.warn(`Cannot set sequencer from ${this.state} to ${proposedState} as it is stopped.`);
|
|
380
618
|
return;
|
|
381
619
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
620
|
+
let secondsIntoSlot = undefined;
|
|
621
|
+
const timeReferenceSlot = opts.timeReferenceSlot ?? slotNumber;
|
|
622
|
+
if (timeReferenceSlot !== undefined) {
|
|
623
|
+
secondsIntoSlot = this.getSecondsIntoSlot(timeReferenceSlot);
|
|
624
|
+
this.timetable.assertTimeLeft(proposedState, secondsIntoSlot);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
const oldState = this.state;
|
|
628
|
+
const oldStateSlotNumber = this.stateSlotNumber;
|
|
629
|
+
const stateChanged = proposedState !== oldState;
|
|
630
|
+
const transitionAtMs = performance.now();
|
|
631
|
+
const stateDurationMs = transitionAtMs - this.stateEnteredAtMs;
|
|
632
|
+
|
|
633
|
+
const boringStates = [SequencerState.IDLE, SequencerState.SYNCHRONIZING];
|
|
634
|
+
const logLevel =
|
|
635
|
+
boringStates.includes(proposedState) && boringStates.includes(oldState) ? ('trace' as const) : ('debug' as const);
|
|
636
|
+
this.stateLog[logLevel](`Transitioning from ${oldState} to ${proposedState}`, {
|
|
637
|
+
oldState,
|
|
638
|
+
newState: proposedState,
|
|
639
|
+
slotNumber,
|
|
640
|
+
timeReferenceSlot,
|
|
641
|
+
stateSlotNumber: oldStateSlotNumber,
|
|
642
|
+
secondsIntoSlot,
|
|
643
|
+
...(stateChanged && { stateDurationMs: Math.ceil(stateDurationMs) }),
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
this.emit('state-changed', {
|
|
647
|
+
oldState,
|
|
648
|
+
newState: proposedState,
|
|
649
|
+
secondsIntoSlot,
|
|
650
|
+
slot: slotNumber,
|
|
651
|
+
timeReferenceSlot,
|
|
652
|
+
});
|
|
653
|
+
if (stateChanged) {
|
|
654
|
+
this.metrics.recordStateDuration(stateDurationMs, oldState);
|
|
655
|
+
this.stateEnteredAtMs = transitionAtMs;
|
|
656
|
+
this.stateSlotNumber = slotNumber;
|
|
657
|
+
}
|
|
385
658
|
this.state = proposedState;
|
|
386
659
|
}
|
|
387
660
|
|
|
388
661
|
/**
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
* Shared between the sequencer and the validator for re-execution
|
|
392
|
-
*
|
|
393
|
-
* @param pendingTxs - The pending transactions to construct the block from
|
|
394
|
-
* @param newGlobalVariables - The global variables for the new block
|
|
395
|
-
* @param historicalHeader - The historical header of the parent
|
|
396
|
-
* @param opts - Whether to just validate the block as a validator, as opposed to building it as a proposal
|
|
662
|
+
* Returns whether all dependencies have caught up.
|
|
663
|
+
* We don't check against the previous block submitted since it may have been reorg'd out.
|
|
397
664
|
*/
|
|
398
|
-
protected async
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
blockNumber,
|
|
412
|
-
msgCount,
|
|
413
|
-
validator: opts.validateOnly,
|
|
414
|
-
});
|
|
665
|
+
protected async checkSync(args: { ts: bigint; slot: SlotNumber }): Promise<SequencerSyncCheckResult | undefined> {
|
|
666
|
+
// Check that the archiver has fully synced the L2 slot before the one we want to propose in.
|
|
667
|
+
// The archiver reports sync progress via L1 block timestamps and synced checkpoint slots.
|
|
668
|
+
// See getSyncedL2SlotNumber for how missed L1 blocks are handled.
|
|
669
|
+
const syncedL2Slot = await this.l2BlockSource.getSyncedL2SlotNumber();
|
|
670
|
+
const { slot } = args;
|
|
671
|
+
if (syncedL2Slot === undefined || syncedL2Slot + 1 < slot) {
|
|
672
|
+
this.log.debug(`Cannot propose block at next L2 slot ${slot} due to pending sync from L1`, {
|
|
673
|
+
slot,
|
|
674
|
+
syncedL2Slot,
|
|
675
|
+
});
|
|
676
|
+
return undefined;
|
|
677
|
+
}
|
|
415
678
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
679
|
+
const syncedBlocks = await Promise.all([
|
|
680
|
+
this.worldState.status().then(({ syncSummary }) => ({
|
|
681
|
+
number: syncSummary.latestBlockNumber,
|
|
682
|
+
hash: syncSummary.latestBlockHash,
|
|
683
|
+
})),
|
|
684
|
+
this.l2BlockSource
|
|
685
|
+
.getL2Tips()
|
|
686
|
+
.then(t => ({ proposed: t.proposed, checkpointed: t.checkpointed, proposedCheckpoint: t.proposedCheckpoint })),
|
|
687
|
+
this.p2pClient.getStatus().then(p2p => p2p.syncedToL2Block),
|
|
688
|
+
this.l1ToL2MessageSource.getL2Tips().then(t => ({ proposed: t.proposed, checkpointed: t.checkpointed })),
|
|
689
|
+
this.l2BlockSource.getPendingChainValidationStatus(),
|
|
690
|
+
this.l2BlockSource.getProposedCheckpointData(),
|
|
691
|
+
] as const);
|
|
419
692
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
const orchestratorFork = await this.worldState.fork();
|
|
693
|
+
const [worldState, l2Tips, p2p, l1ToL2MessageSourceTips, pendingChainValidationStatus, proposedCheckpointData] =
|
|
694
|
+
syncedBlocks;
|
|
423
695
|
|
|
424
|
-
const
|
|
425
|
-
|
|
696
|
+
const result =
|
|
697
|
+
worldState.hash === l2Tips.proposed.hash &&
|
|
698
|
+
p2p.hash === l2Tips.proposed.hash &&
|
|
699
|
+
l1ToL2MessageSourceTips.proposed.hash === l2Tips.proposed.hash &&
|
|
700
|
+
l1ToL2MessageSourceTips.checkpointed.block.hash === l2Tips.checkpointed.block.hash &&
|
|
701
|
+
l1ToL2MessageSourceTips.checkpointed.checkpoint.hash === l2Tips.checkpointed.checkpoint.hash;
|
|
426
702
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
// Deadline for processing depends on whether we're proposing a block
|
|
434
|
-
const secondsIntoSlot = this.getSecondsIntoSlot(slot);
|
|
435
|
-
const processingEndTimeWithinSlot = opts.validateOnly
|
|
436
|
-
? this.timetable.getValidatorReexecTimeEnd(secondsIntoSlot)
|
|
437
|
-
: this.timetable.getBlockProposalExecTimeEnd(secondsIntoSlot);
|
|
438
|
-
|
|
439
|
-
// Deadline is only set if enforceTimeTable is enabled.
|
|
440
|
-
const deadline = this.enforceTimeTable
|
|
441
|
-
? new Date((this.getSlotStartTimestamp(slot) + processingEndTimeWithinSlot) * 1000)
|
|
442
|
-
: undefined;
|
|
443
|
-
|
|
444
|
-
this.log.verbose(`Processing pending txs`, {
|
|
445
|
-
slot,
|
|
446
|
-
slotStart: new Date(this.getSlotStartTimestamp(slot) * 1000),
|
|
447
|
-
now: new Date(this.dateProvider.now()),
|
|
448
|
-
deadline,
|
|
703
|
+
if (!result) {
|
|
704
|
+
this.log.debug(`Sequencer sync check failed`, {
|
|
705
|
+
worldState,
|
|
706
|
+
l2BlockSource: l2Tips.proposed,
|
|
707
|
+
p2p,
|
|
708
|
+
l1ToL2MessageSourceTips,
|
|
449
709
|
});
|
|
710
|
+
return undefined;
|
|
711
|
+
}
|
|
450
712
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
713
|
+
const blockNumber = worldState.number;
|
|
714
|
+
const blockData = await this.l2BlockSource.getBlockData({ number: blockNumber });
|
|
715
|
+
if (!blockData) {
|
|
716
|
+
this.log.warn(`Sequencer sync check failed: failed to get L2 block data ${blockNumber} from the archiver`, {
|
|
717
|
+
blockNumber,
|
|
718
|
+
l2Tips,
|
|
719
|
+
syncedL2Slot,
|
|
720
|
+
...args,
|
|
721
|
+
});
|
|
722
|
+
return undefined;
|
|
723
|
+
}
|
|
457
724
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
725
|
+
// Refuse to build a checkpoint on top of a proposed block whose enclosing checkpoint was never
|
|
726
|
+
// proposed. Under pipelining we may have received and reexecuted such a block locally — advancing
|
|
727
|
+
// our world-state tip past the checkpointed tip — while the proposing node never published the
|
|
728
|
+
// matching proposed checkpoint (e.g. it crashed before assembling it). Building on this orphan block
|
|
729
|
+
// would fork the chain off a tip no other node can follow. The archiver prunes these orphan blocks
|
|
730
|
+
// once their build slot ends; this guard is the correctness barrier during the grace window before.
|
|
731
|
+
if (
|
|
732
|
+
blockData.checkpointNumber > l2Tips.checkpointed.checkpoint.number &&
|
|
733
|
+
(l2Tips.proposedCheckpoint.checkpoint.number !== blockData.checkpointNumber ||
|
|
734
|
+
proposedCheckpointData?.checkpointNumber !== blockData.checkpointNumber)
|
|
735
|
+
) {
|
|
736
|
+
const logCtx = {
|
|
737
|
+
blockCheckpointNumber: blockData.checkpointNumber,
|
|
738
|
+
checkpointedCheckpointNumber: l2Tips.checkpointed.checkpoint.number,
|
|
739
|
+
proposedCheckpointTipNumber: l2Tips.proposedCheckpoint.checkpoint.number,
|
|
740
|
+
proposedCheckpointDataNumber: proposedCheckpointData?.checkpointNumber,
|
|
741
|
+
blockNumber: blockData.header.getBlockNumber(),
|
|
742
|
+
blockSlot: blockData.header.getSlot(),
|
|
743
|
+
syncedL2Slot,
|
|
744
|
+
...args,
|
|
465
745
|
};
|
|
466
|
-
const limits = opts.validateOnly ? { deadline } : { deadline, ...proposerLimits };
|
|
467
|
-
const [publicProcessorDuration, [processedTxs, failedTxs]] = await elapsed(() =>
|
|
468
|
-
processor.process(pendingTxs, limits, validators),
|
|
469
|
-
);
|
|
470
746
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
747
|
+
// Under pipelining the block proposal for a checkpoint leads its checkpoint proposal by up to one
|
|
748
|
+
// slot, so a world-state tip sitting in an as-yet-unproposed checkpoint is the expected steady state
|
|
749
|
+
// until that checkpoint is due. Only treat it as abnormal — and warn — once the checkpoint is overdue
|
|
750
|
+
// by the same deadline the archiver uses to prune the orphan block (see pruneOrphanProposedBlocks).
|
|
751
|
+
// Before then this is normal pipelining and we wait it out quietly.
|
|
752
|
+
if (this.isProposedCheckpointOverdue(blockData.header.getSlot())) {
|
|
753
|
+
this.log.warn(`Sequencer sync check failed: proposed block has no matching proposed checkpoint`, logCtx);
|
|
754
|
+
} else {
|
|
755
|
+
this.log.debug(`Waiting for proposed checkpoint to catch up with reexecuted block`, logCtx);
|
|
476
756
|
}
|
|
757
|
+
return undefined;
|
|
758
|
+
}
|
|
477
759
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
760
|
+
const hasProposedCheckpoint = l2Tips.proposedCheckpoint.checkpoint.number > l2Tips.checkpointed.checkpoint.number;
|
|
761
|
+
|
|
762
|
+
// The l2Tips and proposedCheckpointData reads above come from independent archiver snapshots
|
|
763
|
+
// (a JS-side tips cache vs. a direct store read on `#proposedCheckpoints`). A concurrent archiver
|
|
764
|
+
// write that mutates both can be observed split, leaving us with `hasProposedCheckpoint=true` but
|
|
765
|
+
// no proposedCheckpointData (or one whose number doesn't match the tip). Refuse to proceed in that
|
|
766
|
+
// window — the next checkSync tick will see a coherent snapshot.
|
|
767
|
+
if (
|
|
768
|
+
hasProposedCheckpoint &&
|
|
769
|
+
(!proposedCheckpointData ||
|
|
770
|
+
proposedCheckpointData.checkpointNumber !== l2Tips.proposedCheckpoint.checkpoint.number)
|
|
771
|
+
) {
|
|
772
|
+
this.log.warn(`Sequencer sync check failed: inconsistent proposed-checkpoint state`, {
|
|
773
|
+
proposedCheckpointTipNumber: l2Tips.proposedCheckpoint.checkpoint.number,
|
|
774
|
+
checkpointedTipNumber: l2Tips.checkpointed.checkpoint.number,
|
|
775
|
+
proposedCheckpointDataNumber: proposedCheckpointData?.checkpointNumber,
|
|
776
|
+
syncedL2Slot,
|
|
777
|
+
...args,
|
|
778
|
+
});
|
|
779
|
+
return undefined;
|
|
780
|
+
}
|
|
490
781
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
const publicGas = processedTxs.reduce((acc, tx) => acc.add(tx.gasUsed.publicGas), Gas.empty());
|
|
502
|
-
|
|
503
|
-
return {
|
|
504
|
-
block,
|
|
505
|
-
publicGas,
|
|
506
|
-
publicProcessorDuration,
|
|
507
|
-
numMsgs: l1ToL2Messages.length,
|
|
508
|
-
numTxs: processedTxs.length,
|
|
509
|
-
numFailedTxs: failedTxs.length,
|
|
510
|
-
blockBuildingTimer,
|
|
511
|
-
};
|
|
512
|
-
} finally {
|
|
513
|
-
// We create a fresh processor each time to reset any cached state (eg storage writes)
|
|
514
|
-
// We wait a bit to close the forks since the processor may still be working on a dangling tx
|
|
515
|
-
// which was interrupted due to the processingDeadline being hit.
|
|
516
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
517
|
-
setTimeout(async () => {
|
|
518
|
-
try {
|
|
519
|
-
await publicProcessorFork.close();
|
|
520
|
-
await orchestratorFork.close();
|
|
521
|
-
} catch (err) {
|
|
522
|
-
// This can happen if the sequencer is stopped before we hit this timeout.
|
|
523
|
-
this.log.warn(`Error closing forks for block processing`, err);
|
|
524
|
-
}
|
|
525
|
-
}, 5000);
|
|
782
|
+
// Check that the proposed checkpoint is indeed the parent of the checkpoint we'll be building
|
|
783
|
+
// The checkpoint number to build is derived as blockData.checkpointNumber + 1
|
|
784
|
+
if (proposedCheckpointData && proposedCheckpointData.checkpointNumber !== blockData.checkpointNumber) {
|
|
785
|
+
this.log.warn(`Sequencer sync check failed: proposed checkpoint number mismatch`, {
|
|
786
|
+
proposedCheckpointNumber: proposedCheckpointData.checkpointNumber,
|
|
787
|
+
blockCheckpointNumber: blockData.checkpointNumber,
|
|
788
|
+
syncedL2Slot,
|
|
789
|
+
...args,
|
|
790
|
+
});
|
|
791
|
+
return undefined;
|
|
526
792
|
}
|
|
793
|
+
|
|
794
|
+
return {
|
|
795
|
+
blockData,
|
|
796
|
+
blockNumber: blockData.header.getBlockNumber(),
|
|
797
|
+
checkpointNumber: blockData.checkpointNumber,
|
|
798
|
+
checkpointedCheckpointNumber: l2Tips.checkpointed.checkpoint.number,
|
|
799
|
+
archive: blockData.archive.root,
|
|
800
|
+
hasProposedCheckpoint,
|
|
801
|
+
proposedCheckpointData,
|
|
802
|
+
syncedL2Slot,
|
|
803
|
+
pendingChainValidationStatus,
|
|
804
|
+
};
|
|
527
805
|
}
|
|
528
806
|
|
|
529
807
|
/**
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
* @param pendingTxs - Iterable of pending transactions to construct the block from
|
|
536
|
-
* @param proposalHeader - The partial header constructed for the proposal
|
|
808
|
+
* Whether the enclosing checkpoint of a reexecuted block is overdue: past the deadline by which a
|
|
809
|
+
* well-behaved proposer should have published it. Mirrors the archiver's orphan-prune deadline (the
|
|
810
|
+
* start of the slot after the block's build slot, plus a grace period) so the sequencer only warns
|
|
811
|
+
* about a missing proposed checkpoint once the archiver itself would prune the orphan block. The grace
|
|
812
|
+
* is derived from the block build duration the same way the archiver defaults it at node wiring.
|
|
537
813
|
*/
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
await this.publisher.validateBlockForSubmission(proposalHeader);
|
|
546
|
-
|
|
547
|
-
const newGlobalVariables = proposalHeader.globalVariables;
|
|
548
|
-
const blockNumber = newGlobalVariables.blockNumber.toNumber();
|
|
549
|
-
const slot = newGlobalVariables.slotNumber.toBigInt();
|
|
814
|
+
private isProposedCheckpointOverdue(blockSlot: SlotNumber): boolean {
|
|
815
|
+
const expectedBySlot = SlotNumber(Number(blockSlot) - PROPOSER_PIPELINING_SLOT_OFFSET + 1);
|
|
816
|
+
const graceSeconds =
|
|
817
|
+
this.config.blockDurationMs !== undefined ? Math.ceil(this.config.blockDurationMs / 1000) : MIN_EXECUTION_TIME;
|
|
818
|
+
const expectedByTime = getTimestampForSlot(expectedBySlot, this.l1Constants) + BigInt(graceSeconds);
|
|
819
|
+
return BigInt(this.dateProvider.nowInSeconds()) >= expectedByTime;
|
|
820
|
+
}
|
|
550
821
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
822
|
+
/**
|
|
823
|
+
* Checks if we are the proposer for the next slot.
|
|
824
|
+
* @returns True if we can propose, and the proposer address (undefined if anyone can propose)
|
|
825
|
+
*/
|
|
826
|
+
protected async checkCanPropose(targetSlot: SlotNumber): Promise<[boolean, EthAddress | undefined]> {
|
|
827
|
+
let proposer: EthAddress | undefined;
|
|
554
828
|
|
|
555
829
|
try {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
publicProcessDuration: publicProcessorDuration,
|
|
569
|
-
rollupCircuitsDuration: blockBuildingTimer.ms(),
|
|
570
|
-
...block.getStats(),
|
|
571
|
-
};
|
|
830
|
+
proposer = await this.epochCache.getProposerAttesterAddressInSlot(targetSlot);
|
|
831
|
+
} catch (e) {
|
|
832
|
+
if (e instanceof NoCommitteeError) {
|
|
833
|
+
if (this.lastSlotForNoCommitteeWarning !== targetSlot) {
|
|
834
|
+
this.lastSlotForNoCommitteeWarning = targetSlot;
|
|
835
|
+
this.log.warn(`Cannot propose at target slot ${targetSlot} since the committee does not exist on L1`);
|
|
836
|
+
}
|
|
837
|
+
return [false, undefined];
|
|
838
|
+
}
|
|
839
|
+
this.log.error(`Error getting proposer for target slot ${targetSlot}`, e);
|
|
840
|
+
return [false, undefined];
|
|
841
|
+
}
|
|
572
842
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
globalVariables: block.header.globalVariables.toInspect(),
|
|
582
|
-
txHashes,
|
|
583
|
-
...blockStats,
|
|
584
|
-
},
|
|
585
|
-
);
|
|
843
|
+
// If proposer is undefined, then the committee is empty and anyone may propose
|
|
844
|
+
if (proposer === undefined) {
|
|
845
|
+
return [true, undefined];
|
|
846
|
+
}
|
|
847
|
+
// In fisherman mode, just return the current proposer
|
|
848
|
+
if (this.config.fishermanMode) {
|
|
849
|
+
return [true, proposer];
|
|
850
|
+
}
|
|
586
851
|
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
const attestations = await this.collectAttestations(block, txHashes);
|
|
590
|
-
if (attestations !== undefined) {
|
|
591
|
-
this.log.verbose(`Collected ${attestations.length} attestations`, { blockHash, blockNumber });
|
|
592
|
-
}
|
|
593
|
-
stopCollectingAttestationsTimer();
|
|
852
|
+
const validatorAddresses = this.validatorClient.getValidatorAddresses();
|
|
853
|
+
const weAreProposer = validatorAddresses.some(addr => addr.equals(proposer));
|
|
594
854
|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
855
|
+
if (!weAreProposer) {
|
|
856
|
+
this.log.debug(`Cannot propose at target slot ${targetSlot} since we are not a proposer`, {
|
|
857
|
+
targetSlot,
|
|
858
|
+
validatorAddresses,
|
|
859
|
+
proposer,
|
|
860
|
+
});
|
|
861
|
+
return [false, proposer];
|
|
599
862
|
}
|
|
863
|
+
|
|
864
|
+
this.log.info(`We are the proposer for pipeline slot ${targetSlot}`, {
|
|
865
|
+
targetSlot,
|
|
866
|
+
proposer,
|
|
867
|
+
});
|
|
868
|
+
return [true, proposer];
|
|
600
869
|
}
|
|
601
870
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
}))
|
|
607
|
-
protected async
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
if (
|
|
612
|
-
this.log.
|
|
613
|
-
return
|
|
614
|
-
} else {
|
|
615
|
-
this.log.debug(`Attesting committee length is ${committee.length}`);
|
|
871
|
+
/**
|
|
872
|
+
* Tries to vote on slashing actions and governance when the sync check fails but we're past the max time for initializing a proposal.
|
|
873
|
+
* This allows the sequencer to participate in governance/slashing votes even when it cannot build blocks.
|
|
874
|
+
*/
|
|
875
|
+
@trackSpan('Seqeuencer.tryVoteWhenSyncFails', ({ slot }) => ({ [Attributes.SLOT_NUMBER]: slot }))
|
|
876
|
+
protected async tryVoteWhenSyncFails(args: { slot: SlotNumber; targetSlot: SlotNumber; ts: bigint }): Promise<void> {
|
|
877
|
+
const { slot, targetSlot } = args;
|
|
878
|
+
|
|
879
|
+
// Prevent duplicate attempts in the same slot
|
|
880
|
+
if (this.lastSlotForFallbackVote === slot) {
|
|
881
|
+
this.log.trace(`Already attempted to vote in slot ${slot} (skipping)`);
|
|
882
|
+
return;
|
|
616
883
|
}
|
|
617
884
|
|
|
618
|
-
if
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
885
|
+
// Check if we're past the max time for initializing a proposal
|
|
886
|
+
const secondsIntoSlot = this.getSecondsIntoSlot(slot);
|
|
887
|
+
const maxAllowedTime = this.timetable.getMaxAllowedTime(SequencerState.INITIALIZING_CHECKPOINT);
|
|
888
|
+
|
|
889
|
+
// If we haven't exceeded the time limit for initializing a proposal, don't proceed with voting
|
|
890
|
+
// We use INITIALIZING_PROPOSAL time limit because if we're past that, we can't build a block anyway
|
|
891
|
+
if (maxAllowedTime === undefined || secondsIntoSlot <= maxAllowedTime) {
|
|
892
|
+
this.log.trace(`Not attempting to vote since there is still time for block building`, {
|
|
893
|
+
secondsIntoSlot,
|
|
894
|
+
maxAllowedTime,
|
|
895
|
+
});
|
|
896
|
+
return;
|
|
622
897
|
}
|
|
623
898
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
899
|
+
this.log.trace(`Sync for slot ${slot} failed, checking for voting opportunities`, {
|
|
900
|
+
secondsIntoSlot,
|
|
901
|
+
maxAllowedTime,
|
|
902
|
+
});
|
|
627
903
|
|
|
628
|
-
|
|
629
|
-
const
|
|
630
|
-
if (!
|
|
631
|
-
|
|
632
|
-
|
|
904
|
+
// Check if we're a proposer or proposal is open
|
|
905
|
+
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
906
|
+
if (!canPropose) {
|
|
907
|
+
this.log.trace(`Cannot vote in slot ${slot} since we are not a proposer`, { slot, proposer });
|
|
908
|
+
return;
|
|
633
909
|
}
|
|
634
910
|
|
|
635
|
-
this
|
|
636
|
-
this.
|
|
911
|
+
// Mark this slot as attempted
|
|
912
|
+
this.lastSlotForFallbackVote = slot;
|
|
637
913
|
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
914
|
+
// Get a publisher for voting
|
|
915
|
+
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
916
|
+
|
|
917
|
+
this.log.debug(`Attempting to vote despite sync failure at slot ${slot}`, {
|
|
918
|
+
attestorAddress,
|
|
919
|
+
slot,
|
|
920
|
+
});
|
|
921
|
+
|
|
922
|
+
// Enqueue governance and slashing votes (voter uses the target slot for L1 submission)
|
|
923
|
+
const voter = new CheckpointVoter(
|
|
924
|
+
targetSlot,
|
|
925
|
+
publisher,
|
|
926
|
+
attestorAddress,
|
|
927
|
+
this.validatorClient,
|
|
928
|
+
this.slasherClient,
|
|
929
|
+
this.l1Constants,
|
|
930
|
+
this.config,
|
|
931
|
+
this.metrics,
|
|
932
|
+
this.log,
|
|
646
933
|
);
|
|
934
|
+
const votesPromises = voter.enqueueVotes();
|
|
935
|
+
const votes = await Promise.all(votesPromises);
|
|
647
936
|
|
|
648
|
-
|
|
649
|
-
|
|
937
|
+
if (votes.every(p => !p)) {
|
|
938
|
+
this.log.debug(`No votes to enqueue for slot ${slot}`);
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
this.log.info(`Voting in slot ${slot} despite sync failure`, { slot });
|
|
943
|
+
// Votes are EIP-712-signed for `targetSlot` (the pipelined slot in which the multicall is
|
|
944
|
+
// expected to mine). Delay submission to the start of `targetSlot` so the tx mines in the
|
|
945
|
+
// slot the votes were signed for. We fire-and-forget so we don't block the sequencer's
|
|
946
|
+
// work loop while waiting for the target slot to start.
|
|
947
|
+
void publisher.sendRequestsAt(targetSlot).catch(err => {
|
|
948
|
+
this.log.error(`Failed to publish votes despite sync failure for slot ${slot}`, err, { slot });
|
|
949
|
+
});
|
|
650
950
|
}
|
|
651
951
|
|
|
652
952
|
/**
|
|
653
|
-
*
|
|
654
|
-
*
|
|
953
|
+
* Tries to vote on slashing actions and governance proposals when escape hatch is open.
|
|
954
|
+
* This allows the sequencer to participate in voting without performing checkpoint proposal work.
|
|
655
955
|
*/
|
|
656
|
-
@trackSpan('Sequencer.
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
//
|
|
665
|
-
this.
|
|
956
|
+
@trackSpan('Sequencer.tryVoteWhenEscapeHatchOpen', ({ slot }) => ({ [Attributes.SLOT_NUMBER]: slot }))
|
|
957
|
+
protected async tryVoteWhenEscapeHatchOpen(args: {
|
|
958
|
+
slot: SlotNumber;
|
|
959
|
+
targetSlot: SlotNumber;
|
|
960
|
+
proposer: EthAddress | undefined;
|
|
961
|
+
}): Promise<void> {
|
|
962
|
+
const { slot, targetSlot, proposer } = args;
|
|
963
|
+
|
|
964
|
+
// Prevent duplicate attempts in the same slot
|
|
965
|
+
if (this.lastSlotForFallbackVote === slot) {
|
|
966
|
+
this.log.trace(`Already attempted to vote in slot ${slot} (escape hatch open, skipping)`);
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
666
969
|
|
|
667
|
-
//
|
|
668
|
-
|
|
669
|
-
const txTimeoutAt = new Date((this.getSlotStartTimestamp(slot) + this.aztecSlotDuration) * 1000);
|
|
970
|
+
// Mark this slot as attempted
|
|
971
|
+
this.lastSlotForFallbackVote = slot;
|
|
670
972
|
|
|
671
|
-
const
|
|
672
|
-
|
|
973
|
+
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
974
|
+
|
|
975
|
+
this.log.debug(`Escape hatch open for slot ${slot}, attempting vote-only actions`, {
|
|
976
|
+
slot,
|
|
977
|
+
targetSlot,
|
|
978
|
+
attestorAddress,
|
|
673
979
|
});
|
|
674
980
|
|
|
675
|
-
|
|
676
|
-
|
|
981
|
+
// Under proposer pipelining, the multicall is expected to mine in `targetSlot` (slot + 1).
|
|
982
|
+
// Governance and slashing votes are EIP-712-signed against the slot they will mine in, and the
|
|
983
|
+
// L1 contract checks `msg.sender == getCurrentProposer()` using the mining slot. So we must
|
|
984
|
+
// sign for `targetSlot` and delay submission to the start of `targetSlot`.
|
|
985
|
+
const voter = new CheckpointVoter(
|
|
986
|
+
targetSlot,
|
|
987
|
+
publisher,
|
|
988
|
+
attestorAddress,
|
|
989
|
+
this.validatorClient,
|
|
990
|
+
this.slasherClient,
|
|
991
|
+
this.l1Constants,
|
|
992
|
+
this.config,
|
|
993
|
+
this.metrics,
|
|
994
|
+
this.log,
|
|
995
|
+
);
|
|
996
|
+
|
|
997
|
+
const votesPromises = voter.enqueueVotes();
|
|
998
|
+
const votes = await Promise.all(votesPromises);
|
|
999
|
+
|
|
1000
|
+
if (votes.every(p => !p)) {
|
|
1001
|
+
this.log.debug(`No votes to enqueue for slot ${slot} (escape hatch open)`);
|
|
1002
|
+
return;
|
|
677
1003
|
}
|
|
1004
|
+
|
|
1005
|
+
this.log.info(`Voting in slot ${slot} (escape hatch open)`, { slot, targetSlot });
|
|
1006
|
+
// Votes are EIP-712-signed for `targetSlot`. Delay submission to the start of `targetSlot` so
|
|
1007
|
+
// the multicall mines in the slot the votes were signed for; otherwise the L1 contract reads
|
|
1008
|
+
// `signaler = getCurrentProposer()` against the wrong slot and signature verification fails
|
|
1009
|
+
// silently inside Multicall3. Fire-and-forget so we don't block the sequencer's work loop while
|
|
1010
|
+
// waiting for the target slot to start, mirroring tryVoteWhenSyncFails.
|
|
1011
|
+
void publisher.sendRequestsAt(targetSlot).catch(err => {
|
|
1012
|
+
this.log.error(`Failed to publish escape-hatch votes for slot ${slot}`, err, { slot, targetSlot });
|
|
1013
|
+
});
|
|
678
1014
|
}
|
|
679
1015
|
|
|
680
1016
|
/**
|
|
681
|
-
*
|
|
682
|
-
*
|
|
683
|
-
*
|
|
1017
|
+
* Considers invalidating a block if the pending chain is invalid. Depends on how long the invalid block
|
|
1018
|
+
* has been there without being invalidated and whether the sequencer is in the committee or not. We always
|
|
1019
|
+
* have the proposer try to invalidate, but if they fail, the sequencers in the committee are expected to try,
|
|
1020
|
+
* and if they fail, any sequencer will try as well.
|
|
684
1021
|
*/
|
|
685
|
-
protected async
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
this.l2BlockSource.getL2Tips().then(t => t.latest),
|
|
694
|
-
this.p2pClient.getStatus().then(p2p => p2p.syncedToL2Block),
|
|
695
|
-
this.l1ToL2MessageSource.getBlockNumber(),
|
|
696
|
-
] as const);
|
|
1022
|
+
protected async considerInvalidatingCheckpoint(
|
|
1023
|
+
syncedTo: SequencerSyncCheckResult,
|
|
1024
|
+
currentSlot: SlotNumber,
|
|
1025
|
+
): Promise<void> {
|
|
1026
|
+
const { pendingChainValidationStatus, syncedL2Slot } = syncedTo;
|
|
1027
|
+
if (pendingChainValidationStatus.valid) {
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
697
1030
|
|
|
698
|
-
const
|
|
1031
|
+
const invalidCheckpointNumber = pendingChainValidationStatus.checkpoint.checkpointNumber;
|
|
1032
|
+
const invalidCheckpointTimestamp = pendingChainValidationStatus.checkpoint.timestamp;
|
|
1033
|
+
const timeSinceChainInvalid = this.dateProvider.nowInSeconds() - Number(invalidCheckpointTimestamp);
|
|
1034
|
+
const ourValidatorAddresses = this.validatorClient.getValidatorAddresses();
|
|
1035
|
+
|
|
1036
|
+
const { secondsBeforeInvalidatingBlockAsCommitteeMember, secondsBeforeInvalidatingBlockAsNonCommitteeMember } =
|
|
1037
|
+
this.config;
|
|
1038
|
+
|
|
1039
|
+
const logData = {
|
|
1040
|
+
invalidL1Timestamp: invalidCheckpointTimestamp,
|
|
1041
|
+
syncedL2Slot,
|
|
1042
|
+
invalidCheckpoint: pendingChainValidationStatus.checkpoint,
|
|
1043
|
+
secondsBeforeInvalidatingBlockAsCommitteeMember,
|
|
1044
|
+
secondsBeforeInvalidatingBlockAsNonCommitteeMember,
|
|
1045
|
+
ourValidatorAddresses,
|
|
1046
|
+
currentSlot,
|
|
1047
|
+
};
|
|
1048
|
+
|
|
1049
|
+
const inCurrentCommittee = () =>
|
|
1050
|
+
this.epochCache
|
|
1051
|
+
.getCommittee(currentSlot)
|
|
1052
|
+
.then(c => c?.committee?.some(member => ourValidatorAddresses.some(addr => addr.equals(member))));
|
|
1053
|
+
|
|
1054
|
+
const invalidateAsCommitteeMember =
|
|
1055
|
+
secondsBeforeInvalidatingBlockAsCommitteeMember !== undefined &&
|
|
1056
|
+
secondsBeforeInvalidatingBlockAsCommitteeMember > 0 &&
|
|
1057
|
+
timeSinceChainInvalid > secondsBeforeInvalidatingBlockAsCommitteeMember &&
|
|
1058
|
+
(await inCurrentCommittee());
|
|
1059
|
+
|
|
1060
|
+
const invalidateAsNonCommitteeMember =
|
|
1061
|
+
secondsBeforeInvalidatingBlockAsNonCommitteeMember !== undefined &&
|
|
1062
|
+
secondsBeforeInvalidatingBlockAsNonCommitteeMember > 0 &&
|
|
1063
|
+
timeSinceChainInvalid > secondsBeforeInvalidatingBlockAsNonCommitteeMember;
|
|
1064
|
+
|
|
1065
|
+
if (!invalidateAsCommitteeMember && !invalidateAsNonCommitteeMember) {
|
|
1066
|
+
this.log.debug(`Not invalidating pending chain`, logData);
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
699
1069
|
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
//
|
|
703
|
-
|
|
704
|
-
(
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
l2BlockSourceNumber: l2BlockSource.number,
|
|
716
|
-
l2BlockSourceHash: l2BlockSource.hash,
|
|
717
|
-
p2pNumber: p2p.number,
|
|
718
|
-
p2pHash: p2p.hash,
|
|
719
|
-
l1ToL2MessageSourceNumber: l1ToL2MessageSource,
|
|
720
|
-
});
|
|
1070
|
+
let validatorToUse: EthAddress;
|
|
1071
|
+
if (invalidateAsCommitteeMember) {
|
|
1072
|
+
// When invalidating as a committee member, use first validator that's actually in the committee
|
|
1073
|
+
const { committee } = await this.epochCache.getCommittee(currentSlot);
|
|
1074
|
+
if (committee) {
|
|
1075
|
+
const committeeSet = new Set(committee.map(addr => addr.toString()));
|
|
1076
|
+
validatorToUse =
|
|
1077
|
+
ourValidatorAddresses.find(addr => committeeSet.has(addr.toString())) ?? ourValidatorAddresses[0];
|
|
1078
|
+
} else {
|
|
1079
|
+
validatorToUse = ourValidatorAddresses[0];
|
|
1080
|
+
}
|
|
1081
|
+
} else {
|
|
1082
|
+
// When invalidating as a non-committee member, use the first validator
|
|
1083
|
+
validatorToUse = ourValidatorAddresses[0];
|
|
1084
|
+
}
|
|
721
1085
|
|
|
722
|
-
|
|
723
|
-
|
|
1086
|
+
const { publisher } = await this.publisherFactory.create(validatorToUse);
|
|
1087
|
+
|
|
1088
|
+
const invalidateCheckpoint = await publisher.simulateInvalidateCheckpoint(pendingChainValidationStatus);
|
|
1089
|
+
if (!invalidateCheckpoint) {
|
|
1090
|
+
this.log.warn(`Failed to simulate invalidate checkpoint`, logData);
|
|
1091
|
+
return;
|
|
724
1092
|
}
|
|
725
|
-
if (worldState.number >= INITIAL_L2_BLOCK_NUM) {
|
|
726
|
-
const block = await this.l2BlockSource.getBlock(worldState.number);
|
|
727
|
-
if (!block) {
|
|
728
|
-
// this shouldn't really happen because a moment ago we checked that all components were in synch
|
|
729
|
-
return undefined;
|
|
730
|
-
}
|
|
731
1093
|
|
|
732
|
-
|
|
1094
|
+
this.log.info(
|
|
1095
|
+
invalidateAsCommitteeMember
|
|
1096
|
+
? `Invalidating checkpoint ${invalidCheckpointNumber} as committee member`
|
|
1097
|
+
: `Invalidating checkpoint ${invalidCheckpointNumber} as non-committee member`,
|
|
1098
|
+
logData,
|
|
1099
|
+
);
|
|
1100
|
+
|
|
1101
|
+
publisher.enqueueInvalidateCheckpoint(invalidateCheckpoint);
|
|
1102
|
+
|
|
1103
|
+
if (!this.config.fishermanMode) {
|
|
1104
|
+
await publisher.sendRequests();
|
|
733
1105
|
} else {
|
|
734
|
-
|
|
735
|
-
|
|
1106
|
+
this.log.info('Invalidating checkpoint in fisherman mode, clearing pending requests');
|
|
1107
|
+
publisher.clearPendingRequests();
|
|
736
1108
|
}
|
|
737
1109
|
}
|
|
738
1110
|
|
|
739
|
-
private
|
|
740
|
-
|
|
1111
|
+
private logStrategyComparison(epoch: EpochNumber, publisher: SequencerPublisher): void {
|
|
1112
|
+
const feeAnalyzer = publisher.getL1FeeAnalyzer();
|
|
1113
|
+
if (!feeAnalyzer) {
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
const comparison = feeAnalyzer.getStrategyComparison();
|
|
1118
|
+
if (comparison.length === 0) {
|
|
1119
|
+
this.log.debug(`No strategy data available yet for epoch ${epoch}`);
|
|
1120
|
+
return;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
this.log.info(`L1 Fee Strategy Performance Report - End of Epoch ${epoch}`, {
|
|
1124
|
+
epoch: Number(epoch),
|
|
1125
|
+
totalAnalyses: comparison[0]?.totalAnalyses,
|
|
1126
|
+
strategies: comparison.map(s => ({
|
|
1127
|
+
id: s.strategyId,
|
|
1128
|
+
name: s.strategyName,
|
|
1129
|
+
inclusionRate: `${(s.inclusionRate * 100).toFixed(1)}%`,
|
|
1130
|
+
inclusionCount: `${s.inclusionCount}/${s.totalAnalyses}`,
|
|
1131
|
+
avgCostEth: s.avgEstimatedCostEth.toFixed(6),
|
|
1132
|
+
totalCostEth: s.totalEstimatedCostEth.toFixed(6),
|
|
1133
|
+
avgOverpaymentEth: s.avgOverpaymentEth.toFixed(6),
|
|
1134
|
+
totalOverpaymentEth: s.totalOverpaymentEth.toFixed(6),
|
|
1135
|
+
avgPriorityFeeDeltaGwei: s.avgPriorityFeeDeltaGwei.toFixed(2),
|
|
1136
|
+
})),
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
private getSlotStartBuildTimestamp(slotNumber: SlotNumber): number {
|
|
1141
|
+
return getSlotStartBuildTimestamp(slotNumber, this.l1Constants);
|
|
741
1142
|
}
|
|
742
1143
|
|
|
743
|
-
private getSecondsIntoSlot(slotNumber:
|
|
744
|
-
const slotStartTimestamp = this.
|
|
1144
|
+
private getSecondsIntoSlot(slotNumber: SlotNumber): number {
|
|
1145
|
+
const slotStartTimestamp = this.getSlotStartBuildTimestamp(slotNumber);
|
|
745
1146
|
return Number((this.dateProvider.now() / 1000 - slotStartTimestamp).toFixed(3));
|
|
746
1147
|
}
|
|
747
1148
|
|
|
748
|
-
get aztecSlotDuration() {
|
|
1149
|
+
public get aztecSlotDuration() {
|
|
749
1150
|
return this.l1Constants.slotDuration;
|
|
750
1151
|
}
|
|
751
1152
|
|
|
752
|
-
get
|
|
753
|
-
return this.
|
|
1153
|
+
public get maxL2BlockGas(): number | undefined {
|
|
1154
|
+
return this.config.maxL2BlockGas;
|
|
754
1155
|
}
|
|
755
1156
|
|
|
756
|
-
|
|
757
|
-
return this.
|
|
1157
|
+
public getSlasherClient(): SlasherClientInterface | undefined {
|
|
1158
|
+
return this.slasherClient;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
public get tracer(): Tracer {
|
|
1162
|
+
return this.metrics.tracer;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
public getValidatorAddresses() {
|
|
1166
|
+
return this.validatorClient?.getValidatorAddresses();
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
/** Updates the publisher factory's node keystore adapter after a keystore reload. */
|
|
1170
|
+
public updatePublisherNodeKeyStore(adapter: NodeKeystoreAdapter): void {
|
|
1171
|
+
this.publisherFactory.updateNodeKeyStore(adapter);
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
public getConfig() {
|
|
1175
|
+
return this.config;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
private get l1PublishingTime(): number {
|
|
1179
|
+
return this.config.l1PublishingTime ?? this.l1Constants.ethereumSlotDuration;
|
|
758
1180
|
}
|
|
759
1181
|
}
|
|
1182
|
+
|
|
1183
|
+
type SequencerSyncCheckResult = {
|
|
1184
|
+
blockData?: BlockData;
|
|
1185
|
+
checkpointNumber: CheckpointNumber;
|
|
1186
|
+
checkpointedCheckpointNumber: CheckpointNumber;
|
|
1187
|
+
blockNumber: BlockNumber;
|
|
1188
|
+
archive: Fr;
|
|
1189
|
+
hasProposedCheckpoint: boolean;
|
|
1190
|
+
proposedCheckpointData?: ProposedCheckpointData;
|
|
1191
|
+
syncedL2Slot: SlotNumber;
|
|
1192
|
+
pendingChainValidationStatus: ValidateCheckpointResult;
|
|
1193
|
+
};
|