@aztec/sequencer-client 0.0.0-test.0 → 0.0.1-commit.03f7ef2
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/index.d.ts +1 -1
- package/dest/client/sequencer-client.d.ts +30 -29
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +82 -60
- package/dest/config.d.ts +15 -16
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +113 -70
- package/dest/global_variable_builder/global_builder.d.ts +25 -14
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +60 -42
- package/dest/global_variable_builder/index.d.ts +1 -1
- 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 +15 -12
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +32 -19
- package/dest/publisher/index.d.ts +3 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/index.js +3 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +44 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
- package/dest/publisher/sequencer-publisher-factory.js +51 -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 +37 -2
- package/dest/publisher/sequencer-publisher.d.ts +132 -86
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +755 -248
- package/dest/sequencer/block_builder.d.ts +26 -0
- package/dest/sequencer/block_builder.d.ts.map +1 -0
- package/dest/sequencer/block_builder.js +129 -0
- package/dest/sequencer/checkpoint_builder.d.ts +63 -0
- package/dest/sequencer/checkpoint_builder.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_builder.js +131 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +74 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +640 -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 +85 -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 +46 -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 +48 -12
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +274 -48
- package/dest/sequencer/sequencer.d.ts +132 -135
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +519 -521
- package/dest/sequencer/timetable.d.ts +76 -24
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +177 -61
- 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 +10 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +0 -4
- package/dest/test/mock_checkpoint_builder.d.ts +83 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +179 -0
- package/dest/test/utils.d.ts +49 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +94 -0
- package/dest/tx_validator/nullifier_cache.d.ts +1 -3
- package/dest/tx_validator/nullifier_cache.d.ts.map +1 -1
- package/dest/tx_validator/tx_validator_factory.d.ts +11 -11
- package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -1
- package/dest/tx_validator/tx_validator_factory.js +28 -25
- package/package.json +45 -45
- package/src/client/sequencer-client.ts +105 -105
- package/src/config.ts +126 -81
- package/src/global_variable_builder/global_builder.ts +82 -53
- package/src/index.ts +8 -2
- package/src/publisher/config.ts +45 -32
- package/src/publisher/index.ts +4 -0
- package/src/publisher/sequencer-publisher-factory.ts +92 -0
- package/src/publisher/sequencer-publisher-metrics.ts +26 -4
- package/src/publisher/sequencer-publisher.ts +955 -293
- package/src/sequencer/README.md +531 -0
- package/src/sequencer/block_builder.ts +217 -0
- package/src/sequencer/checkpoint_builder.ts +217 -0
- package/src/sequencer/checkpoint_proposal_job.ts +703 -0
- package/src/sequencer/checkpoint_voter.ts +105 -0
- package/src/sequencer/config.ts +8 -0
- package/src/sequencer/errors.ts +21 -0
- package/src/sequencer/events.ts +27 -0
- package/src/sequencer/index.ts +5 -1
- package/src/sequencer/metrics.ts +355 -50
- package/src/sequencer/sequencer.ts +631 -594
- package/src/sequencer/timetable.ts +221 -62
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +28 -60
- package/src/test/index.ts +13 -4
- package/src/test/mock_checkpoint_builder.ts +247 -0
- package/src/test/utils.ts +137 -0
- package/src/tx_validator/tx_validator_factory.ts +46 -33
- 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/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/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/phases_validator.ts +0 -98
- package/src/tx_validator/test_utils.ts +0 -48
|
@@ -1,759 +1,796 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getKzg } from '@aztec/blob-lib';
|
|
2
2
|
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
3
|
-
import {
|
|
3
|
+
import type { EpochCache } from '@aztec/epoch-cache';
|
|
4
|
+
import { NoCommitteeError, type RollupContract } from '@aztec/ethereum/contracts';
|
|
5
|
+
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
6
|
+
import { merge, omit, pick } from '@aztec/foundation/collection';
|
|
7
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
8
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
|
-
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
6
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
7
9
|
import { createLogger } from '@aztec/foundation/log';
|
|
8
10
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
9
|
-
import {
|
|
11
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
12
|
+
import type { TypedEventEmitter } from '@aztec/foundation/types';
|
|
10
13
|
import type { P2P } from '@aztec/p2p';
|
|
11
|
-
import type {
|
|
12
|
-
import type {
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
15
|
-
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
16
|
-
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
17
|
-
import { Gas } from '@aztec/stdlib/gas';
|
|
14
|
+
import type { SlasherClientInterface } from '@aztec/slasher';
|
|
15
|
+
import type { L2BlockNew, L2BlockSource, ValidateBlockResult } from '@aztec/stdlib/block';
|
|
16
|
+
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
17
|
+
import { getSlotAtTimestamp, getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
18
18
|
import {
|
|
19
|
-
type
|
|
19
|
+
type ResolvedSequencerConfig,
|
|
20
|
+
type SequencerConfig,
|
|
20
21
|
SequencerConfigSchema,
|
|
21
22
|
type WorldStateSynchronizer,
|
|
22
|
-
type WorldStateSynchronizerStatus,
|
|
23
23
|
} from '@aztec/stdlib/interfaces/server';
|
|
24
24
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
25
25
|
import { pickFromSchema } from '@aztec/stdlib/schemas';
|
|
26
|
-
import
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
BlockHeader,
|
|
30
|
-
ContentCommitment,
|
|
31
|
-
type GlobalVariables,
|
|
32
|
-
StateReference,
|
|
33
|
-
Tx,
|
|
34
|
-
type TxHash,
|
|
35
|
-
} from '@aztec/stdlib/tx';
|
|
36
|
-
import { Attributes, type TelemetryClient, type Tracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
26
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
27
|
+
import { type TelemetryClient, type Tracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
37
28
|
import type { ValidatorClient } from '@aztec/validator-client';
|
|
38
29
|
|
|
30
|
+
import EventEmitter from 'node:events';
|
|
31
|
+
|
|
32
|
+
import { DefaultSequencerConfig } from '../config.js';
|
|
39
33
|
import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
40
|
-
import
|
|
41
|
-
import type {
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
import
|
|
34
|
+
import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
|
|
35
|
+
import type { InvalidateBlockRequest, SequencerPublisher } from '../publisher/sequencer-publisher.js';
|
|
36
|
+
import { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
37
|
+
import { CheckpointProposalJob } from './checkpoint_proposal_job.js';
|
|
38
|
+
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
39
|
+
import { SequencerInterruptedError, SequencerTooSlowError } from './errors.js';
|
|
40
|
+
import type { SequencerEvents } from './events.js';
|
|
45
41
|
import { SequencerMetrics } from './metrics.js';
|
|
46
|
-
import { SequencerTimetable
|
|
47
|
-
import {
|
|
42
|
+
import { SequencerTimetable } from './timetable.js';
|
|
43
|
+
import type { SequencerRollupConstants } from './types.js';
|
|
44
|
+
import { SequencerState } from './utils.js';
|
|
48
45
|
|
|
49
46
|
export { SequencerState };
|
|
50
47
|
|
|
51
|
-
type SequencerRollupConstants = Pick<L1RollupConstants, 'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration'>;
|
|
52
|
-
|
|
53
48
|
/**
|
|
54
49
|
* Sequencer client
|
|
55
|
-
* -
|
|
56
|
-
* -
|
|
57
|
-
* -
|
|
58
|
-
* -
|
|
59
|
-
* -
|
|
60
|
-
* - Publishes L1 tx(s) to the rollup contract via RollupPublisher.
|
|
50
|
+
* - Checks whether it is elected as proposer for the next slot
|
|
51
|
+
* - Builds multiple blocks and broadcasts them
|
|
52
|
+
* - Collects attestations for the checkpoint
|
|
53
|
+
* - Publishes the checkpoint to L1
|
|
54
|
+
* - Votes for proposals and slashes on L1
|
|
61
55
|
*/
|
|
62
|
-
export class Sequencer {
|
|
56
|
+
export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<SequencerEvents>) {
|
|
63
57
|
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
58
|
private state = SequencerState.STOPPED;
|
|
72
|
-
private allowedInSetup: AllowedElement[] = [];
|
|
73
|
-
private maxBlockSizeInBytes: number = 1024 * 1024;
|
|
74
|
-
private maxBlockGas: Gas = new Gas(100e9, 100e9);
|
|
75
59
|
private metrics: SequencerMetrics;
|
|
76
|
-
|
|
60
|
+
|
|
61
|
+
/** The last slot for which we attempted to vote when sync failed, to prevent duplicate attempts. */
|
|
62
|
+
private lastSlotForVoteWhenSyncFailed: SlotNumber | undefined;
|
|
63
|
+
|
|
64
|
+
/** The last slot for which we triggered a checkpoint proposal job, to prevent duplicate attempts. */
|
|
65
|
+
private lastSlotForCheckpointProposalJob: SlotNumber | undefined;
|
|
66
|
+
|
|
67
|
+
/** Last successful checkpoint proposed */
|
|
68
|
+
private lastCheckpointProposed: Checkpoint | undefined;
|
|
69
|
+
|
|
70
|
+
/** The last epoch for which we logged strategy comparison in fisherman mode. */
|
|
71
|
+
private lastEpochForStrategyComparison: EpochNumber | undefined;
|
|
77
72
|
|
|
78
73
|
/** The maximum number of seconds that the sequencer can be into a slot to transition to a particular state. */
|
|
79
74
|
protected timetable!: SequencerTimetable;
|
|
80
75
|
|
|
81
|
-
|
|
76
|
+
// This shouldn't be here as this gets re-created each time we build/propose a block.
|
|
77
|
+
// But we have a number of tests that abuse/rely on this class having a permanent publisher.
|
|
78
|
+
// As long as those tests only configure a single publisher they will continue to work.
|
|
79
|
+
// This will get re-assigned every time the sequencer goes to build a new block to a publisher that is valid
|
|
80
|
+
// for the block proposer.
|
|
81
|
+
// TODO(palla/mbps): Remove this field and fix tests
|
|
82
|
+
protected publisher: SequencerPublisher | undefined;
|
|
83
|
+
|
|
84
|
+
/** Config for the sequencer */
|
|
85
|
+
protected config: ResolvedSequencerConfig = DefaultSequencerConfig;
|
|
82
86
|
|
|
83
87
|
constructor(
|
|
84
|
-
protected
|
|
85
|
-
protected validatorClient: ValidatorClient
|
|
88
|
+
protected publisherFactory: SequencerPublisherFactory,
|
|
89
|
+
protected validatorClient: ValidatorClient,
|
|
86
90
|
protected globalsBuilder: GlobalVariableBuilder,
|
|
87
91
|
protected p2pClient: P2P,
|
|
88
92
|
protected worldState: WorldStateSynchronizer,
|
|
89
|
-
protected slasherClient:
|
|
90
|
-
protected blockBuilderFactory: BlockBuilderFactory,
|
|
93
|
+
protected slasherClient: SlasherClientInterface | undefined,
|
|
91
94
|
protected l2BlockSource: L2BlockSource,
|
|
92
95
|
protected l1ToL2MessageSource: L1ToL2MessageSource,
|
|
93
|
-
protected
|
|
94
|
-
protected contractDataSource: ContractDataSource,
|
|
96
|
+
protected checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
95
97
|
protected l1Constants: SequencerRollupConstants,
|
|
96
98
|
protected dateProvider: DateProvider,
|
|
97
|
-
protected
|
|
98
|
-
|
|
99
|
+
protected epochCache: EpochCache,
|
|
100
|
+
protected rollupContract: RollupContract,
|
|
101
|
+
config: SequencerConfig,
|
|
102
|
+
protected telemetry: TelemetryClient = getTelemetryClient(),
|
|
99
103
|
protected log = createLogger('sequencer'),
|
|
100
104
|
) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// Register the block builder with the validator client for re-execution
|
|
104
|
-
this.validatorClient?.registerBlockBuilder(this.buildBlock.bind(this));
|
|
105
|
-
|
|
106
|
-
// Register the slasher on the publisher to fetch slashing payloads
|
|
107
|
-
this.publisher.registerSlashPayloadGetter(this.slasherClient.getSlashPayload.bind(this.slasherClient));
|
|
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'));
|
|
105
|
+
super();
|
|
120
106
|
|
|
121
|
-
if
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (config.maxTxsPerBlock !== undefined) {
|
|
125
|
-
this.maxTxsPerBlock = config.maxTxsPerBlock;
|
|
126
|
-
}
|
|
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;
|
|
107
|
+
// Add [FISHERMAN] prefix to logger if in fisherman mode
|
|
108
|
+
if (config.fishermanMode) {
|
|
109
|
+
this.log = log.createChild('[FISHERMAN]');
|
|
141
110
|
}
|
|
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
111
|
|
|
162
|
-
|
|
163
|
-
this.config
|
|
112
|
+
this.metrics = new SequencerMetrics(telemetry, this.rollupContract, 'Sequencer');
|
|
113
|
+
this.updateConfig(config);
|
|
164
114
|
}
|
|
165
115
|
|
|
166
|
-
|
|
116
|
+
/** Updates sequencer config by the defined values and updates the timetable */
|
|
117
|
+
public updateConfig(config: Partial<SequencerConfig>) {
|
|
118
|
+
const filteredConfig = pickFromSchema(config, SequencerConfigSchema);
|
|
119
|
+
this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowList'));
|
|
120
|
+
this.config = merge(this.config, filteredConfig);
|
|
167
121
|
this.timetable = new SequencerTimetable(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
122
|
+
{
|
|
123
|
+
ethereumSlotDuration: this.l1Constants.ethereumSlotDuration,
|
|
124
|
+
aztecSlotDuration: this.aztecSlotDuration,
|
|
125
|
+
l1PublishingTime: this.l1PublishingTime,
|
|
126
|
+
p2pPropagationTime: this.config.attestationPropagationTime,
|
|
127
|
+
blockDurationMs: this.config.blockDurationMs,
|
|
128
|
+
enforce: this.config.enforceTimeTable,
|
|
129
|
+
},
|
|
172
130
|
this.metrics,
|
|
173
131
|
this.log,
|
|
174
132
|
);
|
|
175
|
-
this.log.verbose(`Sequencer timetable updated`, { enforceTimeTable: this.enforceTimeTable });
|
|
176
133
|
}
|
|
177
134
|
|
|
178
|
-
/**
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
135
|
+
/** Initializes the sequencer (precomputes tables and creates a publisher). Takes about 3s. */
|
|
136
|
+
public async init() {
|
|
137
|
+
getKzg();
|
|
138
|
+
this.publisher = (await this.publisherFactory.create(undefined)).publisher;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Starts the sequencer and moves to IDLE state. */
|
|
142
|
+
public start() {
|
|
143
|
+
this.runningPromise = new RunningPromise(
|
|
144
|
+
this.safeWork.bind(this),
|
|
145
|
+
this.log,
|
|
146
|
+
this.config.sequencerPollingIntervalMS,
|
|
147
|
+
);
|
|
148
|
+
this.setState(SequencerState.IDLE, undefined, { force: true });
|
|
185
149
|
this.runningPromise.start();
|
|
186
|
-
this.log.info(
|
|
150
|
+
this.log.info('Started sequencer');
|
|
187
151
|
}
|
|
188
152
|
|
|
189
|
-
/**
|
|
190
|
-
* Stops the sequencer from processing txs and moves to STOPPED state.
|
|
191
|
-
*/
|
|
153
|
+
/** Stops the sequencer from building blocks and moves to STOPPED state. */
|
|
192
154
|
public async stop(): Promise<void> {
|
|
193
|
-
this.log.
|
|
194
|
-
|
|
155
|
+
this.log.info(`Stopping sequencer`);
|
|
156
|
+
this.setState(SequencerState.STOPPING, undefined, { force: true });
|
|
157
|
+
this.publisher?.interrupt();
|
|
195
158
|
await this.runningPromise?.stop();
|
|
196
|
-
this.
|
|
197
|
-
this.publisher.interrupt();
|
|
198
|
-
this.setState(SequencerState.STOPPED, 0n, true /** force */);
|
|
159
|
+
this.setState(SequencerState.STOPPED, undefined, { force: true });
|
|
199
160
|
this.log.info('Stopped sequencer');
|
|
200
161
|
}
|
|
201
162
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
163
|
+
@trackSpan('Sequencer.work')
|
|
164
|
+
/** Main sequencer loop with a try/catch */
|
|
165
|
+
protected async safeWork() {
|
|
166
|
+
try {
|
|
167
|
+
await this.work();
|
|
168
|
+
} catch (err) {
|
|
169
|
+
this.emit('checkpoint-error', { error: err as Error });
|
|
170
|
+
if (err instanceof SequencerTooSlowError) {
|
|
171
|
+
// TODO(palla/mbps): Add missing states
|
|
172
|
+
// Log as warn only if we had to abort halfway through the block proposal
|
|
173
|
+
const logLvl = [SequencerState.INITIALIZING_CHECKPOINT, SequencerState.PROPOSER_CHECK].includes(
|
|
174
|
+
err.proposedState,
|
|
175
|
+
)
|
|
176
|
+
? ('debug' as const)
|
|
177
|
+
: ('warn' as const);
|
|
178
|
+
this.log[logLvl](err.message, { now: this.dateProvider.nowInSeconds() });
|
|
179
|
+
} else {
|
|
180
|
+
// Re-throw other errors
|
|
181
|
+
throw err;
|
|
182
|
+
}
|
|
183
|
+
} finally {
|
|
184
|
+
this.setState(SequencerState.IDLE, undefined);
|
|
185
|
+
}
|
|
210
186
|
}
|
|
211
187
|
|
|
212
|
-
/**
|
|
213
|
-
* Returns the current state of the sequencer.
|
|
214
|
-
* @returns An object with a state entry with one of SequencerState.
|
|
215
|
-
*/
|
|
188
|
+
/** Returns the current state of the sequencer. */
|
|
216
189
|
public status() {
|
|
217
190
|
return { state: this.state };
|
|
218
191
|
}
|
|
219
192
|
|
|
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
193
|
/**
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
194
|
+
* Main sequencer loop:
|
|
195
|
+
* - Checks if we are up to date
|
|
196
|
+
* - If we are and we are the sequencer, collect txs and build blocks
|
|
197
|
+
* - Build multiple blocks per slot when configured
|
|
198
|
+
* - Collect attestations for the final block
|
|
199
|
+
* - Submit checkpoint
|
|
232
200
|
*/
|
|
233
|
-
protected async
|
|
234
|
-
this.setState(SequencerState.SYNCHRONIZING,
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
//
|
|
238
|
-
|
|
201
|
+
protected async work() {
|
|
202
|
+
this.setState(SequencerState.SYNCHRONIZING, undefined);
|
|
203
|
+
const { slot, ts, now, epoch } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
204
|
+
|
|
205
|
+
// Check if we are synced and it's our slot, grab a publisher, check previous block invalidation, etc
|
|
206
|
+
const checkpointProposalJob = await this.prepareCheckpointProposal(slot, ts, now);
|
|
207
|
+
if (!checkpointProposalJob) {
|
|
239
208
|
return;
|
|
240
209
|
}
|
|
241
210
|
|
|
242
|
-
|
|
211
|
+
// Execute the checkpoint proposal job
|
|
212
|
+
const checkpoint = await checkpointProposalJob.execute();
|
|
243
213
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
214
|
+
// Update last checkpoint proposed (currently unused)
|
|
215
|
+
if (checkpoint) {
|
|
216
|
+
this.lastCheckpointProposed = checkpoint;
|
|
217
|
+
}
|
|
248
218
|
|
|
249
|
-
|
|
250
|
-
if (
|
|
251
|
-
this.
|
|
252
|
-
|
|
219
|
+
// Log fee strategy comparison if on fisherman
|
|
220
|
+
if (
|
|
221
|
+
this.config.fishermanMode &&
|
|
222
|
+
(this.lastEpochForStrategyComparison === undefined || epoch > this.lastEpochForStrategyComparison)
|
|
223
|
+
) {
|
|
224
|
+
this.logStrategyComparison(epoch, checkpointProposalJob.getPublisher());
|
|
225
|
+
this.lastEpochForStrategyComparison = epoch;
|
|
253
226
|
}
|
|
254
227
|
|
|
255
|
-
|
|
228
|
+
return checkpoint;
|
|
229
|
+
}
|
|
256
230
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
231
|
+
/**
|
|
232
|
+
* Prepares the checkpoint proposal by performing all necessary checks and setup.
|
|
233
|
+
* This is the initial step in the main loop.
|
|
234
|
+
* @returns CheckpointProposalJob if successful, undefined if we are not yet synced or are not the proposer.
|
|
235
|
+
*/
|
|
236
|
+
private async prepareCheckpointProposal(
|
|
237
|
+
slot: SlotNumber,
|
|
238
|
+
ts: bigint,
|
|
239
|
+
now: bigint,
|
|
240
|
+
): Promise<CheckpointProposalJob | undefined> {
|
|
241
|
+
// Check we have not already processed this slot (cheapest check)
|
|
242
|
+
// We only check this if enforce timetable is set, since we want to keep processing the same slot if we are not
|
|
243
|
+
// running against actual time (eg when we use sandbox-style automining)
|
|
244
|
+
if (
|
|
245
|
+
this.lastSlotForCheckpointProposalJob &&
|
|
246
|
+
this.lastSlotForCheckpointProposalJob >= slot &&
|
|
247
|
+
this.config.enforceTimeTable
|
|
248
|
+
) {
|
|
249
|
+
this.log.trace(`Slot ${slot} has already been processed`);
|
|
250
|
+
return undefined;
|
|
251
|
+
}
|
|
263
252
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const enqueueSlashingVotePromise = this.publisher.enqueueCastVote(
|
|
270
|
-
slot,
|
|
271
|
-
newGlobalVariables.timestamp.toBigInt(),
|
|
272
|
-
VoteType.SLASHING,
|
|
273
|
-
);
|
|
253
|
+
// But if we have already proposed for this slot, the we definitely have to skip it, automining or not
|
|
254
|
+
if (this.lastCheckpointProposed && this.lastCheckpointProposed.header.slotNumber >= slot) {
|
|
255
|
+
this.log.trace(`Slot ${slot} has already been published as checkpoint ${this.lastCheckpointProposed.number}`);
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
274
258
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
259
|
+
// Check all components are synced to latest as seen by the archiver (queries all subsystems)
|
|
260
|
+
const syncedTo = await this.checkSync({ ts, slot });
|
|
261
|
+
if (!syncedTo) {
|
|
262
|
+
await this.tryVoteWhenSyncFails({ slot, ts });
|
|
263
|
+
return undefined;
|
|
264
|
+
}
|
|
281
265
|
|
|
282
|
-
//
|
|
283
|
-
const
|
|
284
|
-
new AppendOnlyTreeSnapshot(chainTipArchive, 1),
|
|
285
|
-
ContentCommitment.empty(),
|
|
286
|
-
StateReference.empty(),
|
|
287
|
-
newGlobalVariables,
|
|
288
|
-
Fr.ZERO,
|
|
289
|
-
Fr.ZERO,
|
|
290
|
-
);
|
|
266
|
+
// TODO(palla/mbps): Compute proper checkpoint number
|
|
267
|
+
const checkpointNumber = CheckpointNumber.fromBlockNumber(BlockNumber(syncedTo.blockNumber + 1));
|
|
291
268
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
269
|
+
const logCtx = {
|
|
270
|
+
now,
|
|
271
|
+
syncedToL1Ts: syncedTo.l1Timestamp,
|
|
272
|
+
syncedToL2Slot: getSlotAtTimestamp(syncedTo.l1Timestamp, this.l1Constants),
|
|
273
|
+
slot,
|
|
274
|
+
slotTs: ts,
|
|
275
|
+
checkpointNumber,
|
|
276
|
+
isPendingChainValid: pick(syncedTo.pendingChainValidationStatus, 'valid', 'reason', 'invalidIndex'),
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
// Check that we are a proposer for the next slot
|
|
280
|
+
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
281
|
+
const [canPropose, proposer] = await this.checkCanPropose(slot);
|
|
282
|
+
|
|
283
|
+
// If we are not a proposer check if we should invalidate a invalid block, and bail
|
|
284
|
+
if (!canPropose) {
|
|
285
|
+
await this.considerInvalidatingBlock(syncedTo, slot);
|
|
286
|
+
return undefined;
|
|
287
|
+
}
|
|
298
288
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
this.log.debug(
|
|
305
|
-
`Not enough txs to build block ${newBlockNumber} at slot ${slot}: got ${pendingTxCount} txs, need ${this.minTxsPerBlock}`,
|
|
289
|
+
// Check that the slot is not taken by a block already (should never happen, since only us can propose for this slot)
|
|
290
|
+
if (syncedTo.block && syncedTo.block.header.getSlot() >= slot) {
|
|
291
|
+
this.log.warn(
|
|
292
|
+
`Cannot propose block at next L2 slot ${slot} since that slot was taken by block ${syncedTo.blockNumber}`,
|
|
293
|
+
{ ...logCtx, block: syncedTo.block.header.toInspect() },
|
|
306
294
|
);
|
|
295
|
+
this.metrics.recordBlockProposalPrecheckFailed('slot_already_taken');
|
|
296
|
+
return undefined;
|
|
307
297
|
}
|
|
308
298
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
299
|
+
// We now need to get ourselves a publisher.
|
|
300
|
+
// The returned attestor will be the one we provided if we provided one.
|
|
301
|
+
// Otherwise it will be a valid attestor for the returned publisher.
|
|
302
|
+
// In fisherman mode, pass undefined to use the fisherman's own keystore instead of the actual proposer's
|
|
303
|
+
const proposerForPublisher = this.config.fishermanMode ? undefined : proposer;
|
|
304
|
+
const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
|
|
305
|
+
this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
|
|
306
|
+
this.publisher = publisher;
|
|
307
|
+
|
|
308
|
+
// In fisherman mode, set the actual proposer's address for simulations
|
|
309
|
+
if (this.config.fishermanMode && proposer) {
|
|
310
|
+
publisher.setProposerAddressForSimulation(proposer);
|
|
311
|
+
this.log.debug(`Set proposer address ${proposer} for simulation in fisherman mode`);
|
|
320
312
|
}
|
|
321
313
|
|
|
322
|
-
|
|
323
|
-
|
|
314
|
+
// Prepare invalidation request if the pending chain is invalid (returns undefined if no need)
|
|
315
|
+
// TODO(palla/mbps): We need to invalidate checkpoints, not blocks
|
|
316
|
+
const invalidateBlock = await publisher.simulateInvalidateBlock(syncedTo.pendingChainValidationStatus);
|
|
324
317
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
} else {
|
|
333
|
-
// Re-throw other errors
|
|
334
|
-
throw err;
|
|
335
|
-
}
|
|
336
|
-
} finally {
|
|
337
|
-
this.setState(SequencerState.IDLE, 0n);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
318
|
+
// Check with the rollup contract if we can indeed propose at the next L2 slot. This check should not fail
|
|
319
|
+
// if all the previous checks are good, but we do it just in case.
|
|
320
|
+
const canProposeCheck = await publisher.canProposeAtNextEthBlock(
|
|
321
|
+
syncedTo.archive,
|
|
322
|
+
proposer ?? EthAddress.ZERO,
|
|
323
|
+
invalidateBlock,
|
|
324
|
+
);
|
|
340
325
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
326
|
+
if (canProposeCheck === undefined) {
|
|
327
|
+
this.log.warn(
|
|
328
|
+
`Cannot propose checkpoint ${checkpointNumber} at slot ${slot} due to failed rollup contract check`,
|
|
329
|
+
logCtx,
|
|
330
|
+
);
|
|
331
|
+
this.emit('proposer-rollup-check-failed', { reason: 'Rollup contract check failed', slot });
|
|
332
|
+
this.metrics.recordBlockProposalPrecheckFailed('rollup_contract_check_failed');
|
|
333
|
+
return undefined;
|
|
334
|
+
}
|
|
344
335
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
336
|
+
if (canProposeCheck.slot !== slot) {
|
|
337
|
+
this.log.warn(
|
|
338
|
+
`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}.`,
|
|
339
|
+
{ ...logCtx, rollup: canProposeCheck, expectedSlot: slot },
|
|
340
|
+
);
|
|
341
|
+
this.emit('proposer-rollup-check-failed', { reason: 'Slot mismatch', slot });
|
|
342
|
+
this.metrics.recordBlockProposalPrecheckFailed('slot_mismatch');
|
|
343
|
+
return undefined;
|
|
344
|
+
}
|
|
353
345
|
|
|
354
|
-
if (
|
|
346
|
+
if (canProposeCheck.checkpointNumber !== checkpointNumber) {
|
|
347
|
+
this.log.warn(
|
|
348
|
+
`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}.`,
|
|
349
|
+
{ ...logCtx, rollup: canProposeCheck, expectedSlot: slot },
|
|
350
|
+
);
|
|
351
|
+
this.emit('proposer-rollup-check-failed', { reason: 'Block mismatch', slot });
|
|
352
|
+
this.metrics.recordBlockProposalPrecheckFailed('block_number_mismatch');
|
|
355
353
|
return undefined;
|
|
356
354
|
}
|
|
357
355
|
|
|
358
|
-
|
|
356
|
+
this.lastSlotForCheckpointProposalJob = slot;
|
|
357
|
+
this.log.info(`Preparing checkpoint proposal ${checkpointNumber} at slot ${slot}`, { ...logCtx, proposer });
|
|
359
358
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
359
|
+
// Create and return the checkpoint proposal job
|
|
360
|
+
return this.createCheckpointProposalJob(
|
|
361
|
+
slot,
|
|
362
|
+
checkpointNumber,
|
|
363
|
+
syncedTo.blockNumber,
|
|
364
|
+
proposer,
|
|
365
|
+
publisher,
|
|
366
|
+
attestorAddress,
|
|
367
|
+
invalidateBlock,
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
protected createCheckpointProposalJob(
|
|
372
|
+
slot: SlotNumber,
|
|
373
|
+
checkpointNumber: CheckpointNumber,
|
|
374
|
+
syncedToBlockNumber: BlockNumber,
|
|
375
|
+
proposer: EthAddress | undefined,
|
|
376
|
+
publisher: SequencerPublisher,
|
|
377
|
+
attestorAddress: EthAddress,
|
|
378
|
+
invalidateBlock: InvalidateBlockRequest | undefined,
|
|
379
|
+
): CheckpointProposalJob {
|
|
380
|
+
return new CheckpointProposalJob(
|
|
381
|
+
slot,
|
|
382
|
+
checkpointNumber,
|
|
383
|
+
syncedToBlockNumber,
|
|
384
|
+
proposer,
|
|
385
|
+
publisher,
|
|
386
|
+
attestorAddress,
|
|
387
|
+
invalidateBlock,
|
|
388
|
+
this.validatorClient,
|
|
389
|
+
this.globalsBuilder,
|
|
390
|
+
this.p2pClient,
|
|
391
|
+
this.worldState,
|
|
392
|
+
this.l1ToL2MessageSource,
|
|
393
|
+
this.checkpointsBuilder,
|
|
394
|
+
this.l1Constants,
|
|
395
|
+
this.config,
|
|
396
|
+
this.timetable,
|
|
397
|
+
this.slasherClient,
|
|
398
|
+
this.epochCache,
|
|
399
|
+
this.dateProvider,
|
|
400
|
+
this.metrics,
|
|
401
|
+
this,
|
|
402
|
+
this.setState.bind(this),
|
|
403
|
+
this.log,
|
|
404
|
+
);
|
|
366
405
|
}
|
|
367
406
|
|
|
368
407
|
/**
|
|
369
|
-
*
|
|
408
|
+
* 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
409
|
* @param proposedState - The new state to transition to.
|
|
371
|
-
* @param
|
|
410
|
+
* @param slotNumber - The current slot number.
|
|
372
411
|
* @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.
|
|
376
412
|
*/
|
|
377
|
-
setState(
|
|
378
|
-
|
|
413
|
+
protected setState(
|
|
414
|
+
proposedState: SequencerState,
|
|
415
|
+
slotNumber: SlotNumber | undefined,
|
|
416
|
+
opts: { force?: boolean } = {},
|
|
417
|
+
): void {
|
|
418
|
+
if (this.state === SequencerState.STOPPING && proposedState !== SequencerState.STOPPED && !opts.force) {
|
|
419
|
+
this.log.warn(`Cannot set sequencer to ${proposedState} as it is stopping.`);
|
|
420
|
+
throw new SequencerInterruptedError();
|
|
421
|
+
}
|
|
422
|
+
if (this.state === SequencerState.STOPPED && !opts.force) {
|
|
379
423
|
this.log.warn(`Cannot set sequencer from ${this.state} to ${proposedState} as it is stopped.`);
|
|
380
424
|
return;
|
|
381
425
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
426
|
+
let secondsIntoSlot = undefined;
|
|
427
|
+
if (slotNumber !== undefined) {
|
|
428
|
+
secondsIntoSlot = this.getSecondsIntoSlot(slotNumber);
|
|
429
|
+
this.timetable.assertTimeLeft(proposedState, secondsIntoSlot);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const boringStates = [SequencerState.IDLE, SequencerState.SYNCHRONIZING];
|
|
433
|
+
const logLevel =
|
|
434
|
+
boringStates.includes(proposedState) && boringStates.includes(this.state)
|
|
435
|
+
? ('trace' as const)
|
|
436
|
+
: ('debug' as const);
|
|
437
|
+
this.log[logLevel](`Transitioning from ${this.state} to ${proposedState}`, { slotNumber, secondsIntoSlot });
|
|
438
|
+
|
|
439
|
+
this.emit('state-changed', {
|
|
440
|
+
oldState: this.state,
|
|
441
|
+
newState: proposedState,
|
|
442
|
+
secondsIntoSlot,
|
|
443
|
+
slot: slotNumber,
|
|
444
|
+
});
|
|
385
445
|
this.state = proposedState;
|
|
386
446
|
}
|
|
387
447
|
|
|
388
448
|
/**
|
|
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
|
|
449
|
+
* Returns whether all dependencies have caught up.
|
|
450
|
+
* We don't check against the previous block submitted since it may have been reorg'd out.
|
|
397
451
|
*/
|
|
398
|
-
protected async
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(BigInt(blockNumber));
|
|
407
|
-
const msgCount = l1ToL2Messages.length;
|
|
408
|
-
|
|
409
|
-
this.log.verbose(`Building block ${blockNumber} for slot ${slot}`, {
|
|
410
|
-
slot,
|
|
411
|
-
blockNumber,
|
|
412
|
-
msgCount,
|
|
413
|
-
validator: opts.validateOnly,
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
// Sync to the previous block at least
|
|
417
|
-
await this.worldState.syncImmediate(blockNumber - 1);
|
|
418
|
-
this.log.debug(`Synced to previous block ${blockNumber - 1}`);
|
|
419
|
-
|
|
420
|
-
// NB: separating the dbs because both should update the state
|
|
421
|
-
const publicProcessorFork = await this.worldState.fork();
|
|
422
|
-
const orchestratorFork = await this.worldState.fork();
|
|
423
|
-
|
|
424
|
-
const previousBlockHeader =
|
|
425
|
-
(await this.l2BlockSource.getBlock(blockNumber - 1))?.header ?? orchestratorFork.getInitialHeader();
|
|
426
|
-
|
|
427
|
-
try {
|
|
428
|
-
const processor = this.publicProcessorFactory.create(publicProcessorFork, newGlobalVariables, true);
|
|
429
|
-
const blockBuildingTimer = new Timer();
|
|
430
|
-
const blockBuilder = this.blockBuilderFactory.create(orchestratorFork);
|
|
431
|
-
await blockBuilder.startNewBlock(newGlobalVariables, l1ToL2Messages, previousBlockHeader);
|
|
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`, {
|
|
452
|
+
protected async checkSync(args: { ts: bigint; slot: SlotNumber }): Promise<SequencerSyncCheckResult | undefined> {
|
|
453
|
+
// Check that the archiver and dependencies have synced to the previous L1 slot at least
|
|
454
|
+
// TODO(#14766): Archiver reports L1 timestamp based on L1 blocks seen, which means that a missed L1 block will
|
|
455
|
+
// cause the archiver L1 timestamp to fall behind, and cause this sequencer to start processing one L1 slot later.
|
|
456
|
+
const l1Timestamp = await this.l2BlockSource.getL1Timestamp();
|
|
457
|
+
const { slot, ts } = args;
|
|
458
|
+
if (l1Timestamp === undefined || l1Timestamp + BigInt(this.l1Constants.ethereumSlotDuration) < ts) {
|
|
459
|
+
this.log.debug(`Cannot propose block at next L2 slot ${slot} due to pending sync from L1`, {
|
|
445
460
|
slot,
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
deadline,
|
|
461
|
+
ts,
|
|
462
|
+
l1Timestamp,
|
|
449
463
|
});
|
|
464
|
+
return undefined;
|
|
465
|
+
}
|
|
450
466
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
)
|
|
467
|
+
const syncedBlocks = await Promise.all([
|
|
468
|
+
this.worldState.status().then(({ syncSummary }) => ({
|
|
469
|
+
number: syncSummary.latestBlockNumber,
|
|
470
|
+
hash: syncSummary.latestBlockHash,
|
|
471
|
+
})),
|
|
472
|
+
this.l2BlockSource.getL2Tips().then(t => t.latest),
|
|
473
|
+
this.p2pClient.getStatus().then(p2p => p2p.syncedToL2Block),
|
|
474
|
+
this.l1ToL2MessageSource.getL2Tips().then(t => t.latest),
|
|
475
|
+
this.l2BlockSource.getPendingChainValidationStatus(),
|
|
476
|
+
] as const);
|
|
457
477
|
|
|
458
|
-
|
|
459
|
-
// of the sequencer to update world state and iterate over txs. We should refactor this along with unifying the
|
|
460
|
-
// publicProcessorFork and orchestratorFork, to avoid doing tree insertions twice when building the block.
|
|
461
|
-
const proposerLimits = {
|
|
462
|
-
maxTransactions: this.maxTxsPerBlock,
|
|
463
|
-
maxBlockSize: this.maxBlockSizeInBytes,
|
|
464
|
-
maxBlockGas: this.maxBlockGas,
|
|
465
|
-
};
|
|
466
|
-
const limits = opts.validateOnly ? { deadline } : { deadline, ...proposerLimits };
|
|
467
|
-
const [publicProcessorDuration, [processedTxs, failedTxs]] = await elapsed(() =>
|
|
468
|
-
processor.process(pendingTxs, limits, validators),
|
|
469
|
-
);
|
|
478
|
+
const [worldState, l2BlockSource, p2p, l1ToL2MessageSource, pendingChainValidationStatus] = syncedBlocks;
|
|
470
479
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
480
|
+
// 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,
|
|
481
|
+
// as the world state can compute the new genesis block hash, but other components use the hardcoded constant.
|
|
482
|
+
const result =
|
|
483
|
+
(l2BlockSource.number === 0 && worldState.number === 0 && p2p.number === 0 && l1ToL2MessageSource.number === 0) ||
|
|
484
|
+
(worldState.hash === l2BlockSource.hash &&
|
|
485
|
+
p2p.hash === l2BlockSource.hash &&
|
|
486
|
+
l1ToL2MessageSource.hash === l2BlockSource.hash);
|
|
477
487
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
processedTxs.length < this.minTxsPerBlock
|
|
483
|
-
) {
|
|
484
|
-
this.log.warn(
|
|
485
|
-
`Block ${blockNumber} has too few txs to be proposed (got ${processedTxs.length} but required ${this.minTxsPerBlock})`,
|
|
486
|
-
{ slot, blockNumber, processedTxCount: processedTxs.length },
|
|
487
|
-
);
|
|
488
|
-
throw new Error(`Block has too few successful txs to be proposed`);
|
|
489
|
-
}
|
|
488
|
+
if (!result) {
|
|
489
|
+
this.log.debug(`Sequencer sync check failed`, { worldState, l2BlockSource, p2p, l1ToL2MessageSource });
|
|
490
|
+
return undefined;
|
|
491
|
+
}
|
|
490
492
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
const
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
//
|
|
501
|
-
|
|
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);
|
|
493
|
+
// Special case for genesis state
|
|
494
|
+
const blockNumber = worldState.number;
|
|
495
|
+
if (blockNumber < INITIAL_L2_BLOCK_NUM) {
|
|
496
|
+
const archive = new Fr((await this.worldState.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
497
|
+
return { blockNumber: BlockNumber(INITIAL_L2_BLOCK_NUM - 1), archive, l1Timestamp, pendingChainValidationStatus };
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const block = await this.l2BlockSource.getL2BlockNew(blockNumber);
|
|
501
|
+
if (!block) {
|
|
502
|
+
// this shouldn't really happen because a moment ago we checked that all components were in sync
|
|
503
|
+
this.log.error(`Failed to get L2 block ${blockNumber} from the archiver with all components in sync`);
|
|
504
|
+
return undefined;
|
|
526
505
|
}
|
|
506
|
+
|
|
507
|
+
return {
|
|
508
|
+
block,
|
|
509
|
+
blockNumber: block.number,
|
|
510
|
+
archive: block.archive.root,
|
|
511
|
+
l1Timestamp,
|
|
512
|
+
pendingChainValidationStatus,
|
|
513
|
+
};
|
|
527
514
|
}
|
|
528
515
|
|
|
529
516
|
/**
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
* @dev MUST throw instead of exiting early to ensure that world-state
|
|
533
|
-
* is being rolled back if the block is dropped.
|
|
534
|
-
*
|
|
535
|
-
* @param pendingTxs - Iterable of pending transactions to construct the block from
|
|
536
|
-
* @param proposalHeader - The partial header constructed for the proposal
|
|
517
|
+
* Checks if we are the proposer for the next slot.
|
|
518
|
+
* @returns True if we can propose, and the proposer address (undefined if anyone can propose)
|
|
537
519
|
*/
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
}))
|
|
541
|
-
private async buildBlockAndEnqueuePublish(
|
|
542
|
-
pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
543
|
-
proposalHeader: BlockHeader,
|
|
544
|
-
): Promise<void> {
|
|
545
|
-
await this.publisher.validateBlockForSubmission(proposalHeader);
|
|
546
|
-
|
|
547
|
-
const newGlobalVariables = proposalHeader.globalVariables;
|
|
548
|
-
const blockNumber = newGlobalVariables.blockNumber.toNumber();
|
|
549
|
-
const slot = newGlobalVariables.slotNumber.toBigInt();
|
|
550
|
-
|
|
551
|
-
// this.metrics.recordNewBlock(blockNumber, validTxs.length);
|
|
552
|
-
const workTimer = new Timer();
|
|
553
|
-
this.setState(SequencerState.CREATING_BLOCK, slot);
|
|
520
|
+
protected async checkCanPropose(slot: SlotNumber): Promise<[boolean, EthAddress | undefined]> {
|
|
521
|
+
let proposer: EthAddress | undefined;
|
|
554
522
|
|
|
555
523
|
try {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
// block being published before ours instead of just waiting on our block
|
|
562
|
-
await this.publisher.validateBlockForSubmission(block.header);
|
|
563
|
-
|
|
564
|
-
const blockStats: L2BlockBuiltStats = {
|
|
565
|
-
eventName: 'l2-block-built',
|
|
566
|
-
creator: this.publisher.getSenderAddress().toString(),
|
|
567
|
-
duration: workTimer.ms(),
|
|
568
|
-
publicProcessDuration: publicProcessorDuration,
|
|
569
|
-
rollupCircuitsDuration: blockBuildingTimer.ms(),
|
|
570
|
-
...block.getStats(),
|
|
571
|
-
};
|
|
572
|
-
|
|
573
|
-
const blockHash = await block.hash();
|
|
574
|
-
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
575
|
-
this.log.info(
|
|
576
|
-
`Built block ${block.number} for slot ${slot} with ${numTxs} txs and ${numMsgs} messages. ${
|
|
577
|
-
publicGas.l2Gas / workTimer.s()
|
|
578
|
-
} mana/s`,
|
|
579
|
-
{
|
|
580
|
-
blockHash,
|
|
581
|
-
globalVariables: block.header.globalVariables.toInspect(),
|
|
582
|
-
txHashes,
|
|
583
|
-
...blockStats,
|
|
584
|
-
},
|
|
585
|
-
);
|
|
586
|
-
|
|
587
|
-
this.log.debug('Collecting attestations');
|
|
588
|
-
const stopCollectingAttestationsTimer = this.metrics.startCollectingAttestationsTimer();
|
|
589
|
-
const attestations = await this.collectAttestations(block, txHashes);
|
|
590
|
-
if (attestations !== undefined) {
|
|
591
|
-
this.log.verbose(`Collected ${attestations.length} attestations`, { blockHash, blockNumber });
|
|
524
|
+
proposer = await this.epochCache.getProposerAttesterAddressInSlot(slot);
|
|
525
|
+
} catch (e) {
|
|
526
|
+
if (e instanceof NoCommitteeError) {
|
|
527
|
+
this.log.warn(`Cannot propose at next L2 slot ${slot} since the committee does not exist on L1`);
|
|
528
|
+
return [false, undefined];
|
|
592
529
|
}
|
|
593
|
-
|
|
530
|
+
this.log.error(`Error getting proposer for slot ${slot}`, e);
|
|
531
|
+
return [false, undefined];
|
|
532
|
+
}
|
|
594
533
|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
534
|
+
// If proposer is undefined, then the committee is empty and anyone may propose
|
|
535
|
+
if (proposer === undefined) {
|
|
536
|
+
return [true, undefined];
|
|
537
|
+
}
|
|
538
|
+
// In fisherman mode, just return the current proposer
|
|
539
|
+
if (this.config.fishermanMode) {
|
|
540
|
+
return [true, proposer];
|
|
599
541
|
}
|
|
542
|
+
|
|
543
|
+
const validatorAddresses = this.validatorClient.getValidatorAddresses();
|
|
544
|
+
const weAreProposer = validatorAddresses.some(addr => addr.equals(proposer));
|
|
545
|
+
|
|
546
|
+
if (!weAreProposer) {
|
|
547
|
+
this.log.debug(`Cannot propose at slot ${slot} since we are not a proposer`, { validatorAddresses, proposer });
|
|
548
|
+
return [false, proposer];
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
return [true, proposer];
|
|
600
552
|
}
|
|
601
553
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
})
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
return undefined;
|
|
614
|
-
} else {
|
|
615
|
-
this.log.debug(`Attesting committee length is ${committee.length}`);
|
|
554
|
+
/**
|
|
555
|
+
* Tries to vote on slashing actions and governance when the sync check fails but we're past the max time for initializing a proposal.
|
|
556
|
+
* This allows the sequencer to participate in governance/slashing votes even when it cannot build blocks.
|
|
557
|
+
*/
|
|
558
|
+
protected async tryVoteWhenSyncFails(args: { slot: SlotNumber; ts: bigint }): Promise<void> {
|
|
559
|
+
const { slot } = args;
|
|
560
|
+
|
|
561
|
+
// Prevent duplicate attempts in the same slot
|
|
562
|
+
if (this.lastSlotForVoteWhenSyncFailed === slot) {
|
|
563
|
+
this.log.trace(`Already attempted to vote in slot ${slot} (skipping)`);
|
|
564
|
+
return;
|
|
616
565
|
}
|
|
617
566
|
|
|
618
|
-
if
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
567
|
+
// Check if we're past the max time for initializing a proposal
|
|
568
|
+
const secondsIntoSlot = this.getSecondsIntoSlot(slot);
|
|
569
|
+
const maxAllowedTime = this.timetable.getMaxAllowedTime(SequencerState.INITIALIZING_CHECKPOINT);
|
|
570
|
+
|
|
571
|
+
// If we haven't exceeded the time limit for initializing a proposal, don't proceed with voting
|
|
572
|
+
// We use INITIALIZING_PROPOSAL time limit because if we're past that, we can't build a block anyway
|
|
573
|
+
if (maxAllowedTime === undefined || secondsIntoSlot <= maxAllowedTime) {
|
|
574
|
+
this.log.trace(`Not attempting to vote since there is still time for block building`, {
|
|
575
|
+
secondsIntoSlot,
|
|
576
|
+
maxAllowedTime,
|
|
577
|
+
});
|
|
578
|
+
return;
|
|
622
579
|
}
|
|
623
580
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
581
|
+
this.log.trace(`Sync for slot ${slot} failed, checking for voting opportunities`, {
|
|
582
|
+
secondsIntoSlot,
|
|
583
|
+
maxAllowedTime,
|
|
584
|
+
});
|
|
627
585
|
|
|
628
|
-
|
|
629
|
-
const
|
|
630
|
-
if (!
|
|
631
|
-
|
|
632
|
-
|
|
586
|
+
// Check if we're a proposer or proposal is open
|
|
587
|
+
const [canPropose, proposer] = await this.checkCanPropose(slot);
|
|
588
|
+
if (!canPropose) {
|
|
589
|
+
this.log.trace(`Cannot vote in slot ${slot} since we are not a proposer`, { slot, proposer });
|
|
590
|
+
return;
|
|
633
591
|
}
|
|
634
592
|
|
|
635
|
-
this
|
|
636
|
-
this.
|
|
593
|
+
// Mark this slot as attempted
|
|
594
|
+
this.lastSlotForVoteWhenSyncFailed = slot;
|
|
595
|
+
|
|
596
|
+
// Get a publisher for voting
|
|
597
|
+
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
637
598
|
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
599
|
+
this.log.debug(`Attempting to vote despite sync failure at slot ${slot}`, {
|
|
600
|
+
attestorAddress,
|
|
601
|
+
slot,
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
// Enqueue governance and slashing votes
|
|
605
|
+
const voter = new CheckpointVoter(
|
|
606
|
+
slot,
|
|
607
|
+
publisher,
|
|
608
|
+
attestorAddress,
|
|
609
|
+
this.validatorClient,
|
|
610
|
+
this.slasherClient,
|
|
611
|
+
this.l1Constants,
|
|
612
|
+
this.config,
|
|
613
|
+
this.metrics,
|
|
614
|
+
this.log,
|
|
646
615
|
);
|
|
616
|
+
const votesPromises = voter.enqueueVotes();
|
|
617
|
+
const votes = await Promise.all(votesPromises);
|
|
647
618
|
|
|
648
|
-
|
|
649
|
-
|
|
619
|
+
if (votes.every(p => !p)) {
|
|
620
|
+
this.log.debug(`No votes to enqueue for slot ${slot}`);
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
this.log.info(`Voting in slot ${slot} despite sync failure`, { slot });
|
|
625
|
+
await publisher.sendRequests();
|
|
650
626
|
}
|
|
651
627
|
|
|
652
628
|
/**
|
|
653
|
-
*
|
|
654
|
-
*
|
|
629
|
+
* Considers invalidating a block if the pending chain is invalid. Depends on how long the invalid block
|
|
630
|
+
* has been there without being invalidated and whether the sequencer is in the committee or not. We always
|
|
631
|
+
* have the proposer try to invalidate, but if they fail, the sequencers in the committee are expected to try,
|
|
632
|
+
* and if they fail, any sequencer will try as well.
|
|
655
633
|
*/
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
protected async enqueuePublishL2Block(
|
|
660
|
-
block: L2Block,
|
|
661
|
-
attestations?: Signature[],
|
|
662
|
-
txHashes?: TxHash[],
|
|
634
|
+
protected async considerInvalidatingBlock(
|
|
635
|
+
syncedTo: SequencerSyncCheckResult,
|
|
636
|
+
currentSlot: SlotNumber,
|
|
663
637
|
): Promise<void> {
|
|
664
|
-
|
|
665
|
-
|
|
638
|
+
const { pendingChainValidationStatus, l1Timestamp } = syncedTo;
|
|
639
|
+
if (pendingChainValidationStatus.valid) {
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
666
642
|
|
|
667
|
-
|
|
668
|
-
const
|
|
669
|
-
const
|
|
643
|
+
const invalidBlockNumber = pendingChainValidationStatus.block.blockNumber;
|
|
644
|
+
const invalidBlockTimestamp = pendingChainValidationStatus.block.timestamp;
|
|
645
|
+
const timeSinceChainInvalid = this.dateProvider.nowInSeconds() - Number(invalidBlockTimestamp);
|
|
646
|
+
const ourValidatorAddresses = this.validatorClient.getValidatorAddresses();
|
|
647
|
+
|
|
648
|
+
const { secondsBeforeInvalidatingBlockAsCommitteeMember, secondsBeforeInvalidatingBlockAsNonCommitteeMember } =
|
|
649
|
+
this.config;
|
|
650
|
+
|
|
651
|
+
const logData = {
|
|
652
|
+
invalidL1Timestamp: invalidBlockTimestamp,
|
|
653
|
+
l1Timestamp,
|
|
654
|
+
invalidBlock: pendingChainValidationStatus.block,
|
|
655
|
+
secondsBeforeInvalidatingBlockAsCommitteeMember,
|
|
656
|
+
secondsBeforeInvalidatingBlockAsNonCommitteeMember,
|
|
657
|
+
ourValidatorAddresses,
|
|
658
|
+
currentSlot,
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
const inCurrentCommittee = () =>
|
|
662
|
+
this.epochCache
|
|
663
|
+
.getCommittee(currentSlot)
|
|
664
|
+
.then(c => c?.committee?.some(member => ourValidatorAddresses.some(addr => addr.equals(member))));
|
|
665
|
+
|
|
666
|
+
const invalidateAsCommitteeMember =
|
|
667
|
+
secondsBeforeInvalidatingBlockAsCommitteeMember !== undefined &&
|
|
668
|
+
secondsBeforeInvalidatingBlockAsCommitteeMember > 0 &&
|
|
669
|
+
timeSinceChainInvalid > secondsBeforeInvalidatingBlockAsCommitteeMember &&
|
|
670
|
+
(await inCurrentCommittee());
|
|
671
|
+
|
|
672
|
+
const invalidateAsNonCommitteeMember =
|
|
673
|
+
secondsBeforeInvalidatingBlockAsNonCommitteeMember !== undefined &&
|
|
674
|
+
secondsBeforeInvalidatingBlockAsNonCommitteeMember > 0 &&
|
|
675
|
+
timeSinceChainInvalid > secondsBeforeInvalidatingBlockAsNonCommitteeMember;
|
|
676
|
+
|
|
677
|
+
if (!invalidateAsCommitteeMember && !invalidateAsNonCommitteeMember) {
|
|
678
|
+
this.log.debug(`Not invalidating pending chain`, logData);
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
670
681
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
682
|
+
let validatorToUse: EthAddress;
|
|
683
|
+
if (invalidateAsCommitteeMember) {
|
|
684
|
+
// When invalidating as a committee member, use first validator that's actually in the committee
|
|
685
|
+
const { committee } = await this.epochCache.getCommittee(currentSlot);
|
|
686
|
+
if (committee) {
|
|
687
|
+
const committeeSet = new Set(committee.map(addr => addr.toString()));
|
|
688
|
+
validatorToUse =
|
|
689
|
+
ourValidatorAddresses.find(addr => committeeSet.has(addr.toString())) ?? ourValidatorAddresses[0];
|
|
690
|
+
} else {
|
|
691
|
+
validatorToUse = ourValidatorAddresses[0];
|
|
692
|
+
}
|
|
693
|
+
} else {
|
|
694
|
+
// When invalidating as a non-committee member, use the first validator
|
|
695
|
+
validatorToUse = ourValidatorAddresses[0];
|
|
696
|
+
}
|
|
674
697
|
|
|
675
|
-
|
|
676
|
-
|
|
698
|
+
const { publisher } = await this.publisherFactory.create(validatorToUse);
|
|
699
|
+
|
|
700
|
+
const invalidateBlock = await publisher.simulateInvalidateBlock(pendingChainValidationStatus);
|
|
701
|
+
if (!invalidateBlock) {
|
|
702
|
+
this.log.warn(`Failed to simulate invalidate block`, logData);
|
|
703
|
+
return;
|
|
677
704
|
}
|
|
678
|
-
}
|
|
679
705
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
const syncedBlocks = await Promise.all([
|
|
687
|
-
this.worldState.status().then((s: WorldStateSynchronizerStatus) => {
|
|
688
|
-
return {
|
|
689
|
-
number: s.syncSummary.latestBlockNumber,
|
|
690
|
-
hash: s.syncSummary.latestBlockHash,
|
|
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);
|
|
706
|
+
this.log.info(
|
|
707
|
+
invalidateAsCommitteeMember
|
|
708
|
+
? `Invalidating block ${invalidBlockNumber} as committee member`
|
|
709
|
+
: `Invalidating block ${invalidBlockNumber} as non-committee member`,
|
|
710
|
+
logData,
|
|
711
|
+
);
|
|
697
712
|
|
|
698
|
-
|
|
713
|
+
publisher.enqueueInvalidateBlock(invalidateBlock);
|
|
699
714
|
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
(
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
// and once we stop pretending that the l1tol2message source is not
|
|
708
|
-
// just the archiver under a different name
|
|
709
|
-
(!l2BlockSource.hash || p2p.hash === l2BlockSource.hash) &&
|
|
710
|
-
l1ToL2MessageSource === l2BlockSource.number;
|
|
711
|
-
|
|
712
|
-
this.log.debug(`Sequencer sync check ${result ? 'succeeded' : 'failed'}`, {
|
|
713
|
-
worldStateNumber: worldState.number,
|
|
714
|
-
worldStateHash: worldState.hash,
|
|
715
|
-
l2BlockSourceNumber: l2BlockSource.number,
|
|
716
|
-
l2BlockSourceHash: l2BlockSource.hash,
|
|
717
|
-
p2pNumber: p2p.number,
|
|
718
|
-
p2pHash: p2p.hash,
|
|
719
|
-
l1ToL2MessageSourceNumber: l1ToL2MessageSource,
|
|
720
|
-
});
|
|
715
|
+
if (!this.config.fishermanMode) {
|
|
716
|
+
await publisher.sendRequests();
|
|
717
|
+
} else {
|
|
718
|
+
this.log.info('Invalidating block in fisherman mode, clearing pending requests');
|
|
719
|
+
publisher.clearPendingRequests();
|
|
720
|
+
}
|
|
721
|
+
}
|
|
721
722
|
|
|
722
|
-
|
|
723
|
-
|
|
723
|
+
private logStrategyComparison(epoch: EpochNumber, publisher: SequencerPublisher): void {
|
|
724
|
+
const feeAnalyzer = publisher.getL1FeeAnalyzer();
|
|
725
|
+
if (!feeAnalyzer) {
|
|
726
|
+
return;
|
|
724
727
|
}
|
|
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
728
|
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
return
|
|
729
|
+
const comparison = feeAnalyzer.getStrategyComparison();
|
|
730
|
+
if (comparison.length === 0) {
|
|
731
|
+
this.log.debug(`No strategy data available yet for epoch ${epoch}`);
|
|
732
|
+
return;
|
|
736
733
|
}
|
|
734
|
+
|
|
735
|
+
this.log.info(`L1 Fee Strategy Performance Report - End of Epoch ${epoch}`, {
|
|
736
|
+
epoch: Number(epoch),
|
|
737
|
+
totalAnalyses: comparison[0]?.totalAnalyses,
|
|
738
|
+
strategies: comparison.map(s => ({
|
|
739
|
+
id: s.strategyId,
|
|
740
|
+
name: s.strategyName,
|
|
741
|
+
inclusionRate: `${(s.inclusionRate * 100).toFixed(1)}%`,
|
|
742
|
+
inclusionCount: `${s.inclusionCount}/${s.totalAnalyses}`,
|
|
743
|
+
avgCostEth: s.avgEstimatedCostEth.toFixed(6),
|
|
744
|
+
totalCostEth: s.totalEstimatedCostEth.toFixed(6),
|
|
745
|
+
avgOverpaymentEth: s.avgOverpaymentEth.toFixed(6),
|
|
746
|
+
totalOverpaymentEth: s.totalOverpaymentEth.toFixed(6),
|
|
747
|
+
avgPriorityFeeDeltaGwei: s.avgPriorityFeeDeltaGwei.toFixed(2),
|
|
748
|
+
})),
|
|
749
|
+
});
|
|
737
750
|
}
|
|
738
751
|
|
|
739
|
-
private
|
|
740
|
-
return
|
|
752
|
+
private getSlotStartBuildTimestamp(slotNumber: SlotNumber): number {
|
|
753
|
+
return getSlotStartBuildTimestamp(slotNumber, this.l1Constants);
|
|
741
754
|
}
|
|
742
755
|
|
|
743
|
-
private getSecondsIntoSlot(slotNumber:
|
|
744
|
-
const slotStartTimestamp = this.
|
|
756
|
+
private getSecondsIntoSlot(slotNumber: SlotNumber): number {
|
|
757
|
+
const slotStartTimestamp = this.getSlotStartBuildTimestamp(slotNumber);
|
|
745
758
|
return Number((this.dateProvider.now() / 1000 - slotStartTimestamp).toFixed(3));
|
|
746
759
|
}
|
|
747
760
|
|
|
748
|
-
get aztecSlotDuration() {
|
|
761
|
+
public get aztecSlotDuration() {
|
|
749
762
|
return this.l1Constants.slotDuration;
|
|
750
763
|
}
|
|
751
764
|
|
|
752
|
-
get
|
|
753
|
-
return this.
|
|
765
|
+
public get maxL2BlockGas(): number | undefined {
|
|
766
|
+
return this.config.maxL2BlockGas;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
public getSlasherClient(): SlasherClientInterface | undefined {
|
|
770
|
+
return this.slasherClient;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
public get tracer(): Tracer {
|
|
774
|
+
return this.metrics.tracer;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
public getValidatorAddresses() {
|
|
778
|
+
return this.validatorClient?.getValidatorAddresses();
|
|
754
779
|
}
|
|
755
780
|
|
|
756
|
-
|
|
757
|
-
return this.
|
|
781
|
+
public getConfig() {
|
|
782
|
+
return this.config;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
private get l1PublishingTime(): number {
|
|
786
|
+
return this.config.l1PublishingTime ?? this.l1Constants.ethereumSlotDuration;
|
|
758
787
|
}
|
|
759
788
|
}
|
|
789
|
+
|
|
790
|
+
type SequencerSyncCheckResult = {
|
|
791
|
+
block?: L2BlockNew;
|
|
792
|
+
blockNumber: BlockNumber;
|
|
793
|
+
archive: Fr;
|
|
794
|
+
l1Timestamp: bigint;
|
|
795
|
+
pendingChainValidationStatus: ValidateBlockResult;
|
|
796
|
+
};
|