@aztec-labs/sequencer-client 6.0.0-rc.3 → 6.0.0
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 +1 -1
- package/dest/client/sequencer-client.d.ts +1 -1
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +7 -2
- package/dest/config.d.ts +2 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +5 -0
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/publisher/config.d.ts +7 -4
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +12 -10
- package/dest/publisher/gas_constants.d.ts +39 -0
- package/dest/publisher/gas_constants.d.ts.map +1 -0
- package/dest/publisher/gas_constants.js +42 -0
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/index.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +1 -1
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +1 -0
- package/dest/publisher/publisher-manager-metrics.d.ts +19 -0
- package/dest/publisher/publisher-manager-metrics.d.ts.map +1 -0
- package/dest/publisher/publisher-manager-metrics.js +67 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +8 -4
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +16 -6
- package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +0 -8
- package/dest/publisher/sequencer-publisher.d.ts +17 -4
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +168 -17
- package/dest/publisher/write_json.d.ts +1 -1
- package/dest/publisher/write_json.d.ts.map +1 -1
- package/dest/publisher/write_json.js +3 -1
- package/dest/sequencer/attestation_manipulation.d.ts +24 -0
- package/dest/sequencer/attestation_manipulation.d.ts.map +1 -0
- package/dest/sequencer/attestation_manipulation.js +72 -0
- package/dest/sequencer/automine/automine_factory.d.ts +1 -1
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -1
- package/dest/sequencer/automine/automine_factory.js +5 -1
- package/dest/sequencer/checkpoint_inbox_consumption.d.ts +135 -0
- package/dest/sequencer/checkpoint_inbox_consumption.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_inbox_consumption.js +275 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +27 -23
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +323 -527
- package/dest/sequencer/inbox_message_selection.d.ts +17 -16
- package/dest/sequencer/inbox_message_selection.d.ts.map +1 -1
- package/dest/sequencer/inbox_message_selection.js +20 -7
- package/dest/sequencer/metrics.d.ts +4 -4
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +6 -9
- package/dest/sequencer/sequencer.d.ts +9 -4
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +129 -38
- package/package.json +23 -23
- package/src/client/sequencer-client.ts +6 -1
- package/src/config.ts +7 -0
- package/src/index.ts +0 -3
- package/src/publisher/config.ts +20 -11
- package/src/publisher/gas_constants.ts +51 -0
- package/src/publisher/index.ts +1 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +1 -0
- package/src/publisher/publisher-manager-metrics.ts +76 -0
- package/src/publisher/sequencer-publisher-factory.ts +18 -7
- package/src/publisher/sequencer-publisher-metrics.ts +0 -12
- package/src/publisher/sequencer-publisher.ts +201 -24
- package/src/publisher/write_json.ts +3 -1
- package/src/sequencer/attestation_manipulation.ts +123 -0
- package/src/sequencer/automine/automine_factory.ts +4 -0
- package/src/sequencer/checkpoint_inbox_consumption.ts +340 -0
- package/src/sequencer/checkpoint_proposal_job.ts +434 -632
- package/src/sequencer/inbox_message_selection.ts +45 -24
- package/src/sequencer/metrics.ts +7 -9
- package/src/sequencer/sequencer.ts +116 -27
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure selection rules for streaming Inbox consumption: how far a block may consume, and when it has to ask L1.
|
|
3
|
+
*
|
|
4
|
+
* Every message count here other than the caps is one coordinate: the cumulative number of Inbox messages since the
|
|
5
|
+
* first one. It is an exclusive end, so it is also the index of the next message and the L1-to-L2 tree leaf count of a
|
|
6
|
+
* block header that consumed through it; {@link InboxMessagePosition} pairs it with the rolling hash. Callers spell
|
|
7
|
+
* the same unit `…Count`, `…Total` or `…TotalMsgCount`. An endpoint total is a count at which a live L1 bucket ends,
|
|
8
|
+
* the only place a checkpoint's final block may stop. A bucket sequence (`bucketSeq`, the `propose` hint) is an L1
|
|
9
|
+
* bucket ordinal, not a count. The archiver's message synchronizer uses "cursor" for the L1 block it scans from; here
|
|
10
|
+
* the cursor is a message position.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
1
14
|
import { MAX_L1_TO_L2_MSGS_PER_BLOCK, MAX_L1_TO_L2_MSGS_PER_CHECKPOINT } from '@aztec-labs/constants';
|
|
2
15
|
import type { InboxContract } from '@aztec-labs/ethereum/contracts';
|
|
3
16
|
import { minBigint } from '@aztec-labs/foundation/bigint';
|
|
@@ -32,6 +45,16 @@ export type StreamingMessageSource = Pick<
|
|
|
32
45
|
'getSyncedMessagePosition' | 'getMessagePosition' | 'getL1ToL2MessageRange'
|
|
33
46
|
>;
|
|
34
47
|
|
|
48
|
+
/** The observed positions a block's message selection is computed from. */
|
|
49
|
+
export type InboxSelectionPositions = {
|
|
50
|
+
/** How far the checkpoint being built has consumed: where the next block's range starts. */
|
|
51
|
+
cursorCount: bigint;
|
|
52
|
+
/** How far this node's archiver has synced the Inbox. No newly selected message lies past it. */
|
|
53
|
+
localSyncedCount: bigint;
|
|
54
|
+
/** The cursor when the checkpoint began (the parent checkpoint's final count); origin of the per-checkpoint cap. */
|
|
55
|
+
checkpointStartCount: bigint;
|
|
56
|
+
};
|
|
57
|
+
|
|
35
58
|
/** The cumulative message count a checkpoint may consume through at most. */
|
|
36
59
|
export function getCheckpointCapEnd(
|
|
37
60
|
checkpointStartCount: bigint,
|
|
@@ -51,7 +74,7 @@ export function getCheckpointCapEnd(
|
|
|
51
74
|
* step to 956 could leave 800 behind. With a cap of 1024 and buckets of 256 the threshold is the checkpoint start
|
|
52
75
|
* plus 768.
|
|
53
76
|
*/
|
|
54
|
-
export function
|
|
77
|
+
export function getEndpointLookupThreshold(
|
|
55
78
|
checkpointStartCount: bigint,
|
|
56
79
|
caps: Pick<InboxConsumptionCaps, 'perCheckpointCap' | 'maxMessagesPerBucket'>,
|
|
57
80
|
): bigint {
|
|
@@ -69,12 +92,11 @@ export function getOrdinaryCeiling(
|
|
|
69
92
|
* sequence. Never below the cursor, so a block consuming nothing keeps its position. This is the *prospective* end:
|
|
70
93
|
* whether the block may take it without consulting L1 is {@link mustQueryEndpoint}.
|
|
71
94
|
*/
|
|
72
|
-
export function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}): bigint {
|
|
95
|
+
export function selectGreedyEnd(
|
|
96
|
+
input: InboxSelectionPositions & {
|
|
97
|
+
caps: Pick<InboxConsumptionCaps, 'perBlockCap' | 'perCheckpointCap'>;
|
|
98
|
+
},
|
|
99
|
+
): bigint {
|
|
78
100
|
const { cursorCount, localSyncedCount, checkpointStartCount, caps } = input;
|
|
79
101
|
const end = minBigint(
|
|
80
102
|
localSyncedCount,
|
|
@@ -86,25 +108,25 @@ export function selectOrdinaryMessageEnd(input: {
|
|
|
86
108
|
|
|
87
109
|
/**
|
|
88
110
|
* The furthest a block may advance on the local log alone without risking the checkpoint's last legal endpoint: the
|
|
89
|
-
* greedy end held down to the threshold.
|
|
90
|
-
*
|
|
111
|
+
* greedy end held down to the threshold. Never below the cursor, so a cursor already past the threshold stays where it
|
|
112
|
+
* is. A non-final block whose endpoint lookup fails or resolves short of this still takes it, since ending at or
|
|
113
|
+
* below the threshold always leaves one bucket of checkpoint capacity in reserve.
|
|
91
114
|
*
|
|
92
115
|
* Reused outside block building to guess what the next block will consume, this is an estimate and not a bound in
|
|
93
116
|
* either direction. A checkpoint's final block has to land on a live L1 bucket boundary, which can be below this:
|
|
94
117
|
* from a cursor of 0, with 400 messages observed and live buckets ending at 200 and 400, this returns 256 while the
|
|
95
118
|
* final block ends at 200.
|
|
96
119
|
*/
|
|
97
|
-
export function selectSafeLocalEnd(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}): bigint {
|
|
120
|
+
export function selectSafeLocalEnd(
|
|
121
|
+
input: InboxSelectionPositions & {
|
|
122
|
+
caps: Pick<InboxConsumptionCaps, 'perBlockCap' | 'perCheckpointCap' | 'maxMessagesPerBucket'>;
|
|
123
|
+
},
|
|
124
|
+
): bigint {
|
|
103
125
|
const { cursorCount, localSyncedCount, checkpointStartCount, caps } = input;
|
|
104
126
|
const end = minBigint(
|
|
105
127
|
localSyncedCount,
|
|
106
128
|
cursorCount + BigInt(caps.perBlockCap),
|
|
107
|
-
|
|
129
|
+
getEndpointLookupThreshold(checkpointStartCount, caps),
|
|
108
130
|
);
|
|
109
131
|
return end < cursorCount ? cursorCount : end;
|
|
110
132
|
}
|
|
@@ -122,7 +144,7 @@ export function mustQueryEndpoint(input: {
|
|
|
122
144
|
caps: Pick<InboxConsumptionCaps, 'perCheckpointCap' | 'maxMessagesPerBucket'>;
|
|
123
145
|
}): boolean {
|
|
124
146
|
const { prospectiveEnd, checkpointStartCount, isFinalBlock, caps } = input;
|
|
125
|
-
return isFinalBlock || prospectiveEnd >
|
|
147
|
+
return isFinalBlock || prospectiveEnd > getEndpointLookupThreshold(checkpointStartCount, caps);
|
|
126
148
|
}
|
|
127
149
|
|
|
128
150
|
/**
|
|
@@ -131,13 +153,12 @@ export function mustQueryEndpoint(input: {
|
|
|
131
153
|
* the result, so that a mandatory bucket beyond its own reach is not stranded by a nearer endpoint; the final block,
|
|
132
154
|
* which has to land on the endpoint, is additionally bounded by what it alone can carry.
|
|
133
155
|
*/
|
|
134
|
-
export function getEndpointUpperBound(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}): bigint {
|
|
156
|
+
export function getEndpointUpperBound(
|
|
157
|
+
input: InboxSelectionPositions & {
|
|
158
|
+
isFinalBlock: boolean;
|
|
159
|
+
caps: Pick<InboxConsumptionCaps, 'perBlockCap' | 'perCheckpointCap'>;
|
|
160
|
+
},
|
|
161
|
+
): bigint {
|
|
141
162
|
const { cursorCount, localSyncedCount, checkpointStartCount, isFinalBlock, caps } = input;
|
|
142
163
|
const bound = minBigint(localSyncedCount, getCheckpointCapEnd(checkpointStartCount, caps));
|
|
143
164
|
return isFinalBlock ? minBigint(bound, cursorCount + BigInt(caps.perBlockCap)) : bound;
|
package/src/sequencer/metrics.ts
CHANGED
|
@@ -131,6 +131,7 @@ export class SequencerMetrics {
|
|
|
131
131
|
'rollup_contract_check_failed',
|
|
132
132
|
'slot_mismatch',
|
|
133
133
|
'block_number_mismatch',
|
|
134
|
+
'insufficient_publisher_balance',
|
|
134
135
|
],
|
|
135
136
|
},
|
|
136
137
|
);
|
|
@@ -274,23 +275,19 @@ export class SequencerMetrics {
|
|
|
274
275
|
});
|
|
275
276
|
}
|
|
276
277
|
|
|
277
|
-
incOpenSlot(slot: SlotNumber
|
|
278
|
+
incOpenSlot(slot: SlotNumber) {
|
|
278
279
|
// sequencer went through the loop a second time. Noop
|
|
279
280
|
if (slot === this.lastSeenSlot) {
|
|
280
281
|
return;
|
|
281
282
|
}
|
|
282
283
|
|
|
283
|
-
this.slots.add(1
|
|
284
|
-
[Attributes.BLOCK_PROPOSER]: proposer,
|
|
285
|
-
});
|
|
284
|
+
this.slots.add(1);
|
|
286
285
|
|
|
287
286
|
this.lastSeenSlot = slot;
|
|
288
287
|
}
|
|
289
288
|
|
|
290
|
-
async incFilledSlot(
|
|
291
|
-
this.filledSlots.add(1
|
|
292
|
-
[Attributes.BLOCK_PROPOSER]: proposer,
|
|
293
|
-
});
|
|
289
|
+
async incFilledSlot(coinbase: Hex | EthAddress | undefined): Promise<void> {
|
|
290
|
+
this.filledSlots.add(1);
|
|
294
291
|
this.lastSeenSlot = undefined;
|
|
295
292
|
|
|
296
293
|
if (coinbase) {
|
|
@@ -326,7 +323,8 @@ export class SequencerMetrics {
|
|
|
326
323
|
| 'rollup_contract_check_failed'
|
|
327
324
|
| 'slot_mismatch'
|
|
328
325
|
| 'block_number_mismatch'
|
|
329
|
-
| 'no_peers'
|
|
326
|
+
| 'no_peers'
|
|
327
|
+
| 'insufficient_publisher_balance',
|
|
330
328
|
) {
|
|
331
329
|
this.checkpointPrecheckFailed.add(1, { [Attributes.ERROR_TYPE]: checkType });
|
|
332
330
|
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { getKzg } from '@aztec-labs/blob-lib';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
type EpochCache,
|
|
4
|
+
PROPOSER_PIPELINING_SLOT_OFFSET,
|
|
5
|
+
type ProposerLookup,
|
|
6
|
+
requireStableCommittee,
|
|
7
|
+
} from '@aztec-labs/epoch-cache';
|
|
8
|
+
import type { InboxContract, RollupContract } from '@aztec-labs/ethereum/contracts';
|
|
9
|
+
import { NoAffordablePublisherError } from '@aztec-labs/ethereum/publisher-manager';
|
|
4
10
|
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec-labs/foundation/branded-types';
|
|
5
11
|
import { merge, omit, pick } from '@aztec-labs/foundation/collection';
|
|
6
12
|
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
@@ -53,7 +59,8 @@ import EventEmitter from 'node:events';
|
|
|
53
59
|
|
|
54
60
|
import { DefaultSequencerConfig } from '../config.js';
|
|
55
61
|
import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
56
|
-
import
|
|
62
|
+
import { INVALIDATE_REQUIREMENT, getProposeRequirement } from '../publisher/gas_constants.js';
|
|
63
|
+
import type { AttestorPublisherPair, SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
|
|
57
64
|
import type { InvalidateCheckpointRequest, SequencerPublisher } from '../publisher/sequencer-publisher.js';
|
|
58
65
|
import { CheckpointProposalJob } from './checkpoint_proposal_job.js';
|
|
59
66
|
import { CheckpointProposalJobMetrics } from './checkpoint_proposal_job_metrics.js';
|
|
@@ -107,6 +114,9 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
107
114
|
/** The last epoch for which we logged a "no committee" diagnostic, to avoid per-slot log spam. */
|
|
108
115
|
private lastEpochForNoCommitteeLog: EpochNumber | undefined;
|
|
109
116
|
|
|
117
|
+
/** The last target slot for which we logged that its committee is not stable on L1 yet, to avoid per-tick log spam. */
|
|
118
|
+
private lastSlotForCommitteeNotStableLog: SlotNumber | undefined;
|
|
119
|
+
|
|
110
120
|
/** The last slot for which we triggered a checkpoint proposal job, to prevent duplicate attempts. */
|
|
111
121
|
protected lastSlotForCheckpointProposalJob: SlotNumber | undefined;
|
|
112
122
|
|
|
@@ -494,6 +504,19 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
494
504
|
return { slot, targetSlot, epoch, targetEpoch: getEpochAtSlot(targetSlot, this.l1Constants), ts, nowSeconds };
|
|
495
505
|
}
|
|
496
506
|
|
|
507
|
+
/**
|
|
508
|
+
* Whether the epoch's committee is already stored on L1, so a proposal in it does not also run setupEpoch. Reads the
|
|
509
|
+
* latest mined L1 state; returns false if the read fails, so the proposal is costed for the more expensive case.
|
|
510
|
+
*/
|
|
511
|
+
private async isEpochSetUpOnL1(epoch: EpochNumber): Promise<boolean> {
|
|
512
|
+
try {
|
|
513
|
+
return await this.rollupContract.isEpochSetUp(epoch);
|
|
514
|
+
} catch (err) {
|
|
515
|
+
this.log.warn(`Failed to read whether epoch ${epoch} is set up on L1, assuming it is not`, { epoch, err });
|
|
516
|
+
return false;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
497
520
|
/**
|
|
498
521
|
* Prepares the checkpoint proposal by performing all necessary checks and setup.
|
|
499
522
|
* This is the initial step in the main loop.
|
|
@@ -535,12 +558,17 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
535
558
|
// expensive multi-subsystem checkSync (and the rest of the build path) behind it. Computed once
|
|
536
559
|
// here and reused for the escape-hatch voting path below. No setState/timing gate on this path:
|
|
537
560
|
// the build-start deadline gate runs only on the proposer build path, before checkSync.
|
|
538
|
-
const
|
|
561
|
+
const proposerCheck = await this.checkCanPropose(targetSlot);
|
|
562
|
+
if (proposerCheck === undefined) {
|
|
563
|
+
return undefined;
|
|
564
|
+
}
|
|
565
|
+
const [canPropose, proposer] = proposerCheck;
|
|
539
566
|
|
|
540
567
|
// If escape hatch is open for the target epoch, do not start checkpoint proposal work and do not attempt invalidations.
|
|
541
568
|
// Still perform governance/slashing voting (as proposer) once per slot.
|
|
542
569
|
// When pipelining, we check the target epoch (slot+1's epoch) since that's the epoch we're building for.
|
|
543
|
-
|
|
570
|
+
// checkCanPropose has already skipped the slot if its committee is not stable.
|
|
571
|
+
const { isEscapeHatchOpen } = requireStableCommittee(await this.epochCache.lookupEscapeHatch(targetEpoch));
|
|
544
572
|
|
|
545
573
|
if (isEscapeHatchOpen) {
|
|
546
574
|
if (canPropose) {
|
|
@@ -662,7 +690,34 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
662
690
|
// Otherwise it will be a valid attestor for the returned publisher.
|
|
663
691
|
// In fisherman mode, pass undefined to use the fisherman's own keystore instead of the actual proposer's
|
|
664
692
|
const proposerForPublisher = this.config.fishermanMode ? undefined : proposer;
|
|
665
|
-
|
|
693
|
+
// Only a publisher that can afford the proposal (plus the invalidation bundled with it, see below) is eligible, so
|
|
694
|
+
// we skip the slot here rather than build and gossip a checkpoint that can never land. Fisherman nodes never send.
|
|
695
|
+
const needsInvalidation = !syncedTo.hasProposedCheckpoint && !syncedTo.pendingChainValidationStatus.valid;
|
|
696
|
+
const requirement = this.config.fishermanMode
|
|
697
|
+
? undefined
|
|
698
|
+
: getProposeRequirement({
|
|
699
|
+
withInvalidate: needsInvalidation,
|
|
700
|
+
withSetupEpoch: !(await this.isEpochSetUpOnL1(targetEpoch)),
|
|
701
|
+
});
|
|
702
|
+
let created: AttestorPublisherPair;
|
|
703
|
+
try {
|
|
704
|
+
created = await this.publisherFactory.create(proposerForPublisher, { requirement });
|
|
705
|
+
} catch (err) {
|
|
706
|
+
if (!(err instanceof NoAffordablePublisherError)) {
|
|
707
|
+
throw err;
|
|
708
|
+
}
|
|
709
|
+
this.log.error(
|
|
710
|
+
`Skipping checkpoint proposal for slot ${targetSlot}: no publisher can afford it, ${err.describeFunding()}`,
|
|
711
|
+
err,
|
|
712
|
+
{ ...logCtx, proposer, ...err.toLogContext() },
|
|
713
|
+
);
|
|
714
|
+
this.metrics.recordCheckpointPrecheckFailed('insufficient_publisher_balance');
|
|
715
|
+
// Mark the slot as attempted so we do not re-check on every tick. Votes are cheaper and optional, so still try.
|
|
716
|
+
await this.tryVoteAndPruneWhenCannotBuild({ slot, targetSlot });
|
|
717
|
+
this.lastSlotForCheckpointProposalJob = targetSlot;
|
|
718
|
+
return undefined;
|
|
719
|
+
}
|
|
720
|
+
const { attestorAddress, publisher } = created;
|
|
666
721
|
using cleanup = new DisposableStack();
|
|
667
722
|
cleanup.use(publisher);
|
|
668
723
|
this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
|
|
@@ -1047,15 +1102,30 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
1047
1102
|
|
|
1048
1103
|
/**
|
|
1049
1104
|
* Checks if we are the proposer for the next slot.
|
|
1050
|
-
* @returns True if we can propose, and the proposer address (undefined if anyone can propose)
|
|
1105
|
+
* @returns True if we can propose, and the proposer address (undefined if anyone can propose). Undefined if the
|
|
1106
|
+
* target slot's committee is not stable on L1 yet, in which case the slot must be skipped altogether.
|
|
1051
1107
|
*/
|
|
1052
|
-
protected async checkCanPropose(targetSlot: SlotNumber): Promise<[boolean, EthAddress | undefined]> {
|
|
1053
|
-
let
|
|
1054
|
-
|
|
1108
|
+
protected async checkCanPropose(targetSlot: SlotNumber): Promise<[boolean, EthAddress | undefined] | undefined> {
|
|
1109
|
+
let lookup: ProposerLookup;
|
|
1055
1110
|
try {
|
|
1056
|
-
|
|
1111
|
+
lookup = await this.epochCache.lookupProposer(targetSlot);
|
|
1057
1112
|
} catch (e) {
|
|
1058
|
-
|
|
1113
|
+
this.log.error(`Error getting proposer for target slot ${targetSlot}`, e);
|
|
1114
|
+
return [false, undefined];
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
switch (lookup.state) {
|
|
1118
|
+
case 'unstable':
|
|
1119
|
+
if (this.lastSlotForCommitteeNotStableLog !== targetSlot) {
|
|
1120
|
+
this.lastSlotForCommitteeNotStableLog = targetSlot;
|
|
1121
|
+
this.log.verbose(`Skipping target slot ${targetSlot}: its committee is not stable on L1 yet`, {
|
|
1122
|
+
targetSlot,
|
|
1123
|
+
epoch: lookup.epoch,
|
|
1124
|
+
l1BlockNumber: lookup.l1BlockNumber,
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
return undefined;
|
|
1128
|
+
case 'none': {
|
|
1059
1129
|
const targetEpoch = getEpochAtSlot(targetSlot, this.l1Constants);
|
|
1060
1130
|
if (this.lastEpochForNoCommitteeLog !== targetEpoch) {
|
|
1061
1131
|
this.lastEpochForNoCommitteeLog = targetEpoch;
|
|
@@ -1070,14 +1140,13 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
1070
1140
|
}
|
|
1071
1141
|
return [false, undefined];
|
|
1072
1142
|
}
|
|
1073
|
-
|
|
1074
|
-
|
|
1143
|
+
case 'open':
|
|
1144
|
+
return [true, undefined];
|
|
1145
|
+
case 'members':
|
|
1146
|
+
break;
|
|
1075
1147
|
}
|
|
1076
1148
|
|
|
1077
|
-
|
|
1078
|
-
if (proposer === undefined) {
|
|
1079
|
-
return [true, undefined];
|
|
1080
|
-
}
|
|
1149
|
+
const { proposer } = lookup;
|
|
1081
1150
|
// In fisherman mode, just return the current proposer
|
|
1082
1151
|
if (this.config.fishermanMode) {
|
|
1083
1152
|
return [true, proposer];
|
|
@@ -1129,11 +1198,12 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
1129
1198
|
});
|
|
1130
1199
|
|
|
1131
1200
|
// Check if we're a proposer or proposal is open
|
|
1132
|
-
const
|
|
1133
|
-
if (!
|
|
1134
|
-
this.log.trace(`Cannot vote in slot ${slot} since we are not a proposer`, { slot, proposer });
|
|
1201
|
+
const proposerCheck = await this.checkCanPropose(targetSlot);
|
|
1202
|
+
if (!proposerCheck?.[0]) {
|
|
1203
|
+
this.log.trace(`Cannot vote in slot ${slot} since we are not a proposer`, { slot, proposer: proposerCheck?.[1] });
|
|
1135
1204
|
return;
|
|
1136
1205
|
}
|
|
1206
|
+
const [, proposer] = proposerCheck;
|
|
1137
1207
|
|
|
1138
1208
|
// Mark this slot as attempted
|
|
1139
1209
|
this.lastSlotForFallbackAction = slot;
|
|
@@ -1325,10 +1395,14 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
1325
1395
|
currentSlot,
|
|
1326
1396
|
};
|
|
1327
1397
|
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1398
|
+
// Only a committee with members can include us. A committee that is not stable on L1 yet cannot tell whether we
|
|
1399
|
+
// are in it, so treat that as not being in it.
|
|
1400
|
+
const getCurrentCommittee = async () => {
|
|
1401
|
+
const lookup = await this.epochCache.getCommittee(currentSlot);
|
|
1402
|
+
return lookup.state === 'members' ? lookup.committee : undefined;
|
|
1403
|
+
};
|
|
1404
|
+
const inCurrentCommittee = async () =>
|
|
1405
|
+
(await getCurrentCommittee())?.some(member => ourValidatorAddresses.some(addr => addr.equals(member)));
|
|
1332
1406
|
|
|
1333
1407
|
const invalidateAsCommitteeMember =
|
|
1334
1408
|
secondsBeforeInvalidatingBlockAsCommitteeMember !== undefined &&
|
|
@@ -1349,7 +1423,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
1349
1423
|
let validatorToUse: EthAddress;
|
|
1350
1424
|
if (invalidateAsCommitteeMember) {
|
|
1351
1425
|
// When invalidating as a committee member, use first validator that's actually in the committee
|
|
1352
|
-
const
|
|
1426
|
+
const committee = await getCurrentCommittee();
|
|
1353
1427
|
if (committee) {
|
|
1354
1428
|
const committeeSet = new Set(committee.map(addr => addr.toString()));
|
|
1355
1429
|
validatorToUse =
|
|
@@ -1362,7 +1436,22 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
1362
1436
|
validatorToUse = ourValidatorAddresses[0];
|
|
1363
1437
|
}
|
|
1364
1438
|
|
|
1365
|
-
|
|
1439
|
+
let createdPublisher: SequencerPublisher;
|
|
1440
|
+
try {
|
|
1441
|
+
({ publisher: createdPublisher } = await this.publisherFactory.create(validatorToUse, {
|
|
1442
|
+
requirement: this.config.fishermanMode ? undefined : INVALIDATE_REQUIREMENT,
|
|
1443
|
+
}));
|
|
1444
|
+
} catch (err) {
|
|
1445
|
+
if (!(err instanceof NoAffordablePublisherError)) {
|
|
1446
|
+
throw err;
|
|
1447
|
+
}
|
|
1448
|
+
this.log.error(`Not invalidating checkpoint ${invalidCheckpointNumber} since no publisher can afford it`, err, {
|
|
1449
|
+
...logData,
|
|
1450
|
+
...err.toLogContext(),
|
|
1451
|
+
});
|
|
1452
|
+
this.lastInvalidationAttempt = { slot: currentSlot, checkpointNumber: invalidCheckpointNumber };
|
|
1453
|
+
return;
|
|
1454
|
+
}
|
|
1366
1455
|
using publisher = createdPublisher;
|
|
1367
1456
|
|
|
1368
1457
|
const invalidateCheckpoint = await publisher.simulateInvalidateCheckpoint(pendingChainValidationStatus);
|