@aztec/sequencer-client 0.0.1-commit.993d240 → 0.0.1-commit.9a89641
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 +40 -41
- package/dest/client/sequencer-client.d.ts +16 -3
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +18 -14
- package/dest/config.d.ts +9 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +29 -15
- package/dest/global_variable_builder/fee_predictor.d.ts +1 -1
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -1
- package/dest/global_variable_builder/fee_predictor.js +11 -1
- package/dest/global_variable_builder/fee_provider.d.ts +1 -1
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -1
- package/dest/global_variable_builder/fee_provider.js +27 -5
- package/dest/global_variable_builder/global_builder.d.ts +3 -16
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +2 -25
- 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 +5 -1
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +11 -1
- package/dest/publisher/l1_to_l2_messaging.d.ts +21 -0
- package/dest/publisher/l1_to_l2_messaging.d.ts.map +1 -0
- package/dest/publisher/l1_to_l2_messaging.js +70 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +48 -8
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +68 -1
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +2 -2
- 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 +4 -2
- package/dest/publisher/l1_tx_failed_store/index.d.ts +2 -2
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/index.js +1 -0
- package/dest/publisher/sequencer-publisher.d.ts +39 -10
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +403 -75
- package/dest/publisher/write_json.d.ts +11 -0
- package/dest/publisher/write_json.d.ts.map +1 -0
- package/dest/publisher/write_json.js +57 -0
- package/dest/sequencer/automine/automine_factory.d.ts +5 -3
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -1
- package/dest/sequencer/automine/automine_factory.js +2 -1
- package/dest/sequencer/automine/automine_sequencer.d.ts +43 -5
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -1
- package/dest/sequencer/automine/automine_sequencer.js +209 -19
- package/dest/sequencer/automine/index.d.ts +3 -0
- package/dest/sequencer/automine/index.d.ts.map +1 -0
- package/dest/sequencer/automine/index.js +2 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +28 -15
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +158 -117
- package/dest/sequencer/events.d.ts +16 -4
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/index.d.ts +1 -3
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +0 -2
- package/dest/sequencer/missing_committee.d.ts +72 -0
- package/dest/sequencer/missing_committee.d.ts.map +1 -0
- package/dest/sequencer/missing_committee.js +139 -0
- package/dest/sequencer/requests_tracker.d.ts +22 -0
- package/dest/sequencer/requests_tracker.d.ts.map +1 -0
- package/dest/sequencer/requests_tracker.js +33 -0
- package/dest/sequencer/sequencer.d.ts +113 -28
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +352 -162
- package/dest/test/index.d.ts +3 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/utils.d.ts +15 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +18 -1
- package/package.json +29 -28
- package/src/client/sequencer-client.ts +20 -14
- package/src/config.ts +32 -16
- package/src/global_variable_builder/fee_predictor.ts +11 -1
- package/src/global_variable_builder/fee_provider.ts +27 -5
- package/src/global_variable_builder/global_builder.ts +2 -34
- package/src/index.ts +1 -10
- package/src/publisher/config.ts +22 -1
- package/src/publisher/l1_to_l2_messaging.ts +85 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +114 -7
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +4 -3
- package/src/publisher/l1_tx_failed_store/index.ts +1 -1
- package/src/publisher/sequencer-publisher.ts +430 -86
- package/src/publisher/write_json.ts +78 -0
- package/src/sequencer/README.md +16 -6
- package/src/sequencer/automine/README.md +18 -4
- package/src/sequencer/automine/automine_factory.ts +8 -1
- package/src/sequencer/automine/automine_sequencer.ts +229 -21
- package/src/sequencer/automine/index.ts +6 -0
- package/src/sequencer/checkpoint_proposal_job.ts +177 -132
- package/src/sequencer/events.ts +16 -3
- package/src/sequencer/index.ts +0 -2
- package/src/sequencer/missing_committee.ts +192 -0
- package/src/sequencer/requests_tracker.ts +43 -0
- package/src/sequencer/sequencer.ts +382 -176
- package/src/test/index.ts +2 -2
- package/src/test/utils.ts +33 -0
- package/dest/sequencer/chain_state_overrides.d.ts +0 -61
- package/dest/sequencer/chain_state_overrides.d.ts.map +0 -1
- package/dest/sequencer/chain_state_overrides.js +0 -98
- package/dest/sequencer/timetable.d.ts +0 -101
- package/dest/sequencer/timetable.d.ts.map +0 -1
- package/dest/sequencer/timetable.js +0 -231
- package/src/sequencer/chain_state_overrides.ts +0 -162
- package/src/sequencer/timetable.ts +0 -295
package/src/test/index.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
2
2
|
import type { PublisherManager } from '@aztec/ethereum/publisher-manager';
|
|
3
3
|
import type { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
4
|
+
import type { ProposerTimetable } from '@aztec/stdlib/timetable';
|
|
4
5
|
import type { FullNodeCheckpointsBuilder, ValidatorClient } from '@aztec/validator-client';
|
|
5
6
|
|
|
6
7
|
import { SequencerClient } from '../client/sequencer-client.js';
|
|
7
8
|
import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
|
|
8
9
|
import { Sequencer } from '../sequencer/sequencer.js';
|
|
9
|
-
import type { SequencerTimetable } from '../sequencer/timetable.js';
|
|
10
10
|
|
|
11
11
|
class TestSequencer_ extends Sequencer {
|
|
12
12
|
declare public publicProcessorFactory: PublicProcessorFactory;
|
|
13
|
-
declare public timetable:
|
|
13
|
+
declare public timetable: ProposerTimetable;
|
|
14
14
|
declare public publisherFactory: SequencerPublisherFactory;
|
|
15
15
|
declare public validatorClient: ValidatorClient;
|
|
16
16
|
declare public checkpointsBuilder: FullNodeCheckpointsBuilder;
|
package/src/test/utils.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { Signature } from '@aztec/foundation/eth-signature';
|
|
|
8
8
|
import type { P2P } from '@aztec/p2p';
|
|
9
9
|
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
10
10
|
import { CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
|
|
11
|
+
import { DEFAULT_BLOCK_DURATION_MS } from '@aztec/stdlib/config';
|
|
12
|
+
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
11
13
|
import { BlockProposal, CheckpointAttestation, CheckpointProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
|
|
12
14
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
13
15
|
import {
|
|
@@ -15,6 +17,13 @@ import {
|
|
|
15
17
|
makeAppendOnlyTreeSnapshot,
|
|
16
18
|
mockTxForRollup,
|
|
17
19
|
} from '@aztec/stdlib/testing';
|
|
20
|
+
import {
|
|
21
|
+
DEFAULT_CHECKPOINT_PROPOSAL_INIT_TIME,
|
|
22
|
+
DEFAULT_CHECKPOINT_PROPOSAL_PREPARE_TIME,
|
|
23
|
+
DEFAULT_MIN_BLOCK_DURATION,
|
|
24
|
+
DEFAULT_P2P_PROPAGATION_TIME,
|
|
25
|
+
ProposerTimetable,
|
|
26
|
+
} from '@aztec/stdlib/timetable';
|
|
18
27
|
import { BlockHeader, GlobalVariables, type Tx, makeProcessedTxFromPrivateOnlyTx } from '@aztec/stdlib/tx';
|
|
19
28
|
|
|
20
29
|
import type { MockProxy } from 'jest-mock-extended';
|
|
@@ -22,6 +31,28 @@ import type { MockProxy } from 'jest-mock-extended';
|
|
|
22
31
|
// Re-export mock classes from their dedicated file
|
|
23
32
|
export { MockCheckpointBuilder, MockCheckpointsBuilder } from './mock_checkpoint_builder.js';
|
|
24
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Builds a {@link ProposerTimetable} for tests from a millisecond block duration and optional budgets,
|
|
36
|
+
* filling unset budgets with the shared `DEFAULT_*` values the sequencer config layer applies. Mirrors how
|
|
37
|
+
* the sequencer constructs its timetable so tests exercise the same budget resolution.
|
|
38
|
+
*/
|
|
39
|
+
export function makeProposerTimetable(opts: {
|
|
40
|
+
l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration' | 'ethereumSlotDuration'>;
|
|
41
|
+
blockDurationMs?: number;
|
|
42
|
+
minBlockDuration?: number;
|
|
43
|
+
p2pPropagationTime?: number;
|
|
44
|
+
checkpointProposalPrepareTime?: number;
|
|
45
|
+
}): ProposerTimetable {
|
|
46
|
+
return new ProposerTimetable({
|
|
47
|
+
l1Constants: opts.l1Constants,
|
|
48
|
+
blockDuration: (opts.blockDurationMs ?? DEFAULT_BLOCK_DURATION_MS) / 1000,
|
|
49
|
+
minBlockDuration: opts.minBlockDuration ?? DEFAULT_MIN_BLOCK_DURATION,
|
|
50
|
+
p2pPropagationTime: opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME,
|
|
51
|
+
checkpointProposalPrepareTime: opts.checkpointProposalPrepareTime ?? DEFAULT_CHECKPOINT_PROPOSAL_PREPARE_TIME,
|
|
52
|
+
checkpointProposalInitTime: DEFAULT_CHECKPOINT_PROPOSAL_INIT_TIME,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
25
56
|
/**
|
|
26
57
|
* Creates a mock transaction with a specific seed for deterministic testing
|
|
27
58
|
*/
|
|
@@ -59,6 +90,7 @@ export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Pr
|
|
|
59
90
|
*/
|
|
60
91
|
export function mockPendingTxs(p2p: MockProxy<P2P>, txs: Tx[]): void {
|
|
61
92
|
p2p.getPendingTxCount.mockResolvedValue(txs.length);
|
|
93
|
+
p2p.hasEligiblePendingTxs.mockImplementation(minCount => Promise.resolve(txs.length >= minCount));
|
|
62
94
|
p2p.iteratePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
|
|
63
95
|
p2p.iterateEligiblePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
|
|
64
96
|
}
|
|
@@ -98,6 +130,7 @@ function createCheckpointHeaderFromBlock(block: L2Block): CheckpointHeader {
|
|
|
98
130
|
gv.feeRecipient,
|
|
99
131
|
gv.gasFees,
|
|
100
132
|
block.header.totalManaUsed,
|
|
133
|
+
block.header.totalFees,
|
|
101
134
|
);
|
|
102
135
|
}
|
|
103
136
|
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { RollupContract, type SimulationOverridesPlan } from '@aztec/ethereum/contracts';
|
|
2
|
-
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import type { Logger } from '@aztec/foundation/log';
|
|
4
|
-
import { type ProposedCheckpointData } from '@aztec/stdlib/checkpoint';
|
|
5
|
-
import type { CoordinationSignatureContext } from '@aztec/stdlib/p2p';
|
|
6
|
-
type CheckpointSimulationOverridesPlanInput = {
|
|
7
|
-
/** Target rollup contract. */
|
|
8
|
-
rollup: RollupContract;
|
|
9
|
-
/** Checkpoint number to be proposed. */
|
|
10
|
-
checkpointNumber: CheckpointNumber;
|
|
11
|
-
/** Logger instance. */
|
|
12
|
-
log: Logger;
|
|
13
|
-
/**
|
|
14
|
-
* The proposed parent checkpoint when pipelining. Its `checkpointNumber` must equal
|
|
15
|
-
* `checkpointNumber - 1`; the helper enforces this. Mutually exclusive with
|
|
16
|
-
* `invalidateToPendingCheckpointNumber`.
|
|
17
|
-
*/
|
|
18
|
-
proposedCheckpointData?: ProposedCheckpointData;
|
|
19
|
-
/**
|
|
20
|
-
* The pending checkpoint number we'll end up at after invalidation lands. Mutually exclusive
|
|
21
|
-
* with `proposedCheckpointData`.
|
|
22
|
-
*/
|
|
23
|
-
invalidateToPendingCheckpointNumber?: CheckpointNumber;
|
|
24
|
-
/**
|
|
25
|
-
* The real on-chain pending checkpoint number (typically `syncedTo.checkpointedCheckpointNumber`).
|
|
26
|
-
* Used as the snapshot we pin both `pending` and `proven` to avoid prunes in simulation.
|
|
27
|
-
*/
|
|
28
|
-
checkpointedCheckpointNumber: CheckpointNumber;
|
|
29
|
-
/**
|
|
30
|
-
* Chain-level consensus signature context. Used to recompute the parent's `payloadDigest` for the
|
|
31
|
-
* pipelined simulation override so it matches what `propose` will write into `tempCheckpointLogs[parent]`
|
|
32
|
-
* once the parent lands.
|
|
33
|
-
*/
|
|
34
|
-
signatureContext: CoordinationSignatureContext;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Builds the SimulationOverridesPlan describing the simulated L1 rollup state for a checkpoint's
|
|
38
|
-
* enqueue-time simulations: `canProposeAt` (in Sequencer.doWork) and the propose-related sims
|
|
39
|
-
* (validateBlockHeader, simulateProposeTx). The plan reflects "as if our pipelined parent
|
|
40
|
-
* checkpoint has landed and any required invalidation has executed" — the gap that needs to be
|
|
41
|
-
* bridged at enqueue time.
|
|
42
|
-
*
|
|
43
|
-
* Pipelining (`proposedCheckpointData`) and invalidation (`invalidateToPendingCheckpointNumber`)
|
|
44
|
-
* are mutually exclusive; passing both throws.
|
|
45
|
-
*/
|
|
46
|
-
export declare function buildCheckpointSimulationOverridesPlan(input: CheckpointSimulationOverridesPlanInput): Promise<SimulationOverridesPlan | undefined>;
|
|
47
|
-
type PipelinedParentFeeHeaderInput = {
|
|
48
|
-
checkpointNumber: CheckpointNumber;
|
|
49
|
-
proposedCheckpointData: ProposedCheckpointData;
|
|
50
|
-
rollup: RollupContract;
|
|
51
|
-
log: Logger;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Derives the pending parent fee header used during pipelined proposal simulation. Returns
|
|
55
|
-
* `undefined` only when no grandparent exists (i.e. the proposed parent is the genesis
|
|
56
|
-
* checkpoint); all other failure modes (missing grandparent state, missing fee header, RPC
|
|
57
|
-
* errors) throw so callers don't silently desync the fee-header override.
|
|
58
|
-
*/
|
|
59
|
-
export declare function computePipelinedParentFeeHeader(input: PipelinedParentFeeHeaderInput): Promise<import("@aztec/ethereum/contracts").FeeHeader | undefined>;
|
|
60
|
-
export {};
|
|
61
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hhaW5fc3RhdGVfb3ZlcnJpZGVzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc2VxdWVuY2VyL2NoYWluX3N0YXRlX292ZXJyaWRlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsY0FBYyxFQUE4QixLQUFLLHVCQUF1QixFQUFFLE1BQU0sMkJBQTJCLENBQUM7QUFDckgsT0FBTyxFQUFFLGdCQUFnQixFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDbkUsT0FBTyxLQUFLLEVBQUUsTUFBTSxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFDcEQsT0FBTyxFQUFFLEtBQUssc0JBQXNCLEVBQWtDLE1BQU0sMEJBQTBCLENBQUM7QUFDdkcsT0FBTyxLQUFLLEVBQUUsNEJBQTRCLEVBQUUsTUFBTSxtQkFBbUIsQ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CAAC;AACrH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,KAAK,sBAAsB,EAAkC,MAAM,0BAA0B,CAAC;AACvG,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;AAEtE,KAAK,sCAAsC,GAAG;IAC5C,8BAA8B;IAC9B,MAAM,EAAE,cAAc,CAAC;IACvB,wCAAwC;IACxC,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,uBAAuB;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;IAChD;;;OAGG;IACH,mCAAmC,CAAC,EAAE,gBAAgB,CAAC;IACvD;;;OAGG;IACH,4BAA4B,EAAE,gBAAgB,CAAC;IAC/C;;;;OAIG;IACH,gBAAgB,EAAE,4BAA4B,CAAC;CAChD,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,sCAAsC,CAC1D,KAAK,EAAE,sCAAsC,GAC5C,OAAO,CAAC,uBAAuB,GAAG,SAAS,CAAC,CAsD9C;AAqBD,KAAK,6BAA6B,GAAG;IACnC,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,sBAAsB,EAAE,sBAAsB,CAAC;IAC/C,MAAM,EAAE,cAAc,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,+BAA+B,CAAC,KAAK,EAAE,6BAA6B,sEAwBzF"}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { RollupContract, SimulationOverridesBuilder } from '@aztec/ethereum/contracts';
|
|
2
|
-
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import { computeCheckpointPayloadDigest } from '@aztec/stdlib/checkpoint';
|
|
4
|
-
/**
|
|
5
|
-
* Builds the SimulationOverridesPlan describing the simulated L1 rollup state for a checkpoint's
|
|
6
|
-
* enqueue-time simulations: `canProposeAt` (in Sequencer.doWork) and the propose-related sims
|
|
7
|
-
* (validateBlockHeader, simulateProposeTx). The plan reflects "as if our pipelined parent
|
|
8
|
-
* checkpoint has landed and any required invalidation has executed" — the gap that needs to be
|
|
9
|
-
* bridged at enqueue time.
|
|
10
|
-
*
|
|
11
|
-
* Pipelining (`proposedCheckpointData`) and invalidation (`invalidateToPendingCheckpointNumber`)
|
|
12
|
-
* are mutually exclusive; passing both throws.
|
|
13
|
-
*/ export async function buildCheckpointSimulationOverridesPlan(input) {
|
|
14
|
-
if (input.proposedCheckpointData && input.invalidateToPendingCheckpointNumber !== undefined) {
|
|
15
|
-
throw new Error('Error in buildCheckpointSimulationOverridesPlan: proposedCheckpointData and invalidateToPendingCheckpointNumber are mutually exclusive');
|
|
16
|
-
}
|
|
17
|
-
const builder = new SimulationOverridesBuilder();
|
|
18
|
-
const pendingCheckpointNumber = derivePendingCheckpointNumber(input);
|
|
19
|
-
// Override the latest checkpoint number when invalidating or pipelining, so our checkpoint
|
|
20
|
-
// follows from it. We also override the proven chain tip so we dont need to worry about
|
|
21
|
-
// prunes kicking in that would break out simulation if there's a prune pending. We always
|
|
22
|
-
// assume that a proof will land in time. If we don't have a pending checkpoint number to force,
|
|
23
|
-
// we still set both tips to the current checkpoint number to avoid the prune trigger.
|
|
24
|
-
const overridenChainTip = pendingCheckpointNumber ?? input.checkpointedCheckpointNumber;
|
|
25
|
-
builder.withChainTips({
|
|
26
|
-
pending: overridenChainTip,
|
|
27
|
-
proven: overridenChainTip
|
|
28
|
-
});
|
|
29
|
-
if (input.proposedCheckpointData) {
|
|
30
|
-
const { header, archive, checkpointOutHash, feeAssetPriceModifier } = input.proposedCheckpointData;
|
|
31
|
-
builder.withPendingArchive(archive.root);
|
|
32
|
-
// Override every locally-derivable `tempCheckpointLogs[parent]` field that L1 will eventually
|
|
33
|
-
// write. `slotNumber` is load-bearing for `STFLib.canPruneAtTime`: without it the cell reads
|
|
34
|
-
// slotNumber 0, the contract treats the pending tip as belonging to an expired epoch, and
|
|
35
|
-
// `getEffectivePendingCheckpointNumber` silently collapses pending back to proven — producing
|
|
36
|
-
// a spurious `Rollup__InvalidArchive` against the on-chain genesis archive. The other fields
|
|
37
|
-
// (headerHash, outHash, payloadDigest) are not strictly load-bearing for `canProposeAt` /
|
|
38
|
-
// `validateBlockHeader`, but mirroring the full cell keeps the simulation byte-faithful with
|
|
39
|
-
// what the actual `propose()` send will observe, which is a defense against future reads
|
|
40
|
-
// taking dependencies on them.
|
|
41
|
-
builder.withPendingTempCheckpointLogFields({
|
|
42
|
-
headerHash: header.hash(),
|
|
43
|
-
outHash: checkpointOutHash,
|
|
44
|
-
slotNumber: header.slotNumber,
|
|
45
|
-
payloadDigest: computeCheckpointPayloadDigest({
|
|
46
|
-
header,
|
|
47
|
-
archiveRoot: archive.root,
|
|
48
|
-
feeAssetPriceModifier,
|
|
49
|
-
signatureContext: input.signatureContext
|
|
50
|
-
})
|
|
51
|
-
});
|
|
52
|
-
const feeHeader = await computePipelinedParentFeeHeader({
|
|
53
|
-
checkpointNumber: input.checkpointNumber,
|
|
54
|
-
proposedCheckpointData: input.proposedCheckpointData,
|
|
55
|
-
rollup: input.rollup,
|
|
56
|
-
log: input.log
|
|
57
|
-
});
|
|
58
|
-
if (feeHeader) {
|
|
59
|
-
builder.withPendingFeeHeader(feeHeader);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return builder.build();
|
|
63
|
-
}
|
|
64
|
-
function derivePendingCheckpointNumber(input) {
|
|
65
|
-
if (input.invalidateToPendingCheckpointNumber !== undefined) {
|
|
66
|
-
return input.invalidateToPendingCheckpointNumber;
|
|
67
|
-
}
|
|
68
|
-
if (!input.proposedCheckpointData) {
|
|
69
|
-
return undefined;
|
|
70
|
-
}
|
|
71
|
-
if (input.checkpointNumber < 1) {
|
|
72
|
-
throw new Error(`Cannot build simulation override for checkpoint ${input.checkpointNumber}: no parent exists`);
|
|
73
|
-
}
|
|
74
|
-
const expectedParent = CheckpointNumber(input.checkpointNumber - 1);
|
|
75
|
-
if (input.proposedCheckpointData.checkpointNumber !== expectedParent) {
|
|
76
|
-
throw new Error(`Cannot build simulation override for checkpoint ${input.checkpointNumber}: proposedCheckpointData.checkpointNumber (${input.proposedCheckpointData.checkpointNumber}) does not match expected parent ${expectedParent}`);
|
|
77
|
-
}
|
|
78
|
-
return expectedParent;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Derives the pending parent fee header used during pipelined proposal simulation. Returns
|
|
82
|
-
* `undefined` only when no grandparent exists (i.e. the proposed parent is the genesis
|
|
83
|
-
* checkpoint); all other failure modes (missing grandparent state, missing fee header, RPC
|
|
84
|
-
* errors) throw so callers don't silently desync the fee-header override.
|
|
85
|
-
*/ export async function computePipelinedParentFeeHeader(input) {
|
|
86
|
-
if (input.checkpointNumber < 2) {
|
|
87
|
-
return undefined;
|
|
88
|
-
}
|
|
89
|
-
const grandparentCheckpointNumber = CheckpointNumber(input.checkpointNumber - 2);
|
|
90
|
-
const [grandparentCheckpoint, manaTarget] = await Promise.all([
|
|
91
|
-
input.rollup.getCheckpoint(grandparentCheckpointNumber),
|
|
92
|
-
input.rollup.getManaTarget()
|
|
93
|
-
]);
|
|
94
|
-
if (!grandparentCheckpoint?.feeHeader) {
|
|
95
|
-
throw new Error(`Grandparent checkpoint or feeHeader missing for checkpoint ${grandparentCheckpointNumber.toString()}`);
|
|
96
|
-
}
|
|
97
|
-
return RollupContract.computeChildFeeHeader(grandparentCheckpoint.feeHeader, input.proposedCheckpointData.totalManaUsed, input.proposedCheckpointData.feeAssetPriceModifier, manaTarget);
|
|
98
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
-
import type { SequencerMetrics } from './metrics.js';
|
|
3
|
-
import { SequencerState } from './utils.js';
|
|
4
|
-
export declare class SequencerTimetable {
|
|
5
|
-
private readonly metrics?;
|
|
6
|
-
private readonly log?;
|
|
7
|
-
private readonly checkpointTiming;
|
|
8
|
-
/**
|
|
9
|
-
* How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
|
|
10
|
-
* assuming an execution time equal to `minExecutionTime`, subtracted from the slot duration. This means that, if the proposer
|
|
11
|
-
* starts building at this time, and all times hold, it will have at least `minExecutionTime` to execute txs for the block.
|
|
12
|
-
*/
|
|
13
|
-
readonly initializeDeadline: number;
|
|
14
|
-
/**
|
|
15
|
-
* Fixed time offset (in seconds) when the first sub-slot starts, used as baseline for all block deadlines.
|
|
16
|
-
* This is an estimate of how long initialization (sync + proposer check) typically takes.
|
|
17
|
-
* If actual initialization takes longer/shorter, blocks just get less/more time accordingly.
|
|
18
|
-
*/
|
|
19
|
-
readonly initializationOffset: number;
|
|
20
|
-
/**
|
|
21
|
-
* Total time needed to finalize and publish a checkpoint, including:
|
|
22
|
-
* - Assembling the checkpoint
|
|
23
|
-
* - Round-trip p2p propagation for the checkpoint proposal and its corresponding attestations
|
|
24
|
-
* - Publishing to L1
|
|
25
|
-
*/
|
|
26
|
-
readonly checkpointFinalizationTime: number;
|
|
27
|
-
/**
|
|
28
|
-
* How long it takes to get a published block into L1. L1 builders typically accept txs up to 4 seconds into their slot,
|
|
29
|
-
* but we'll timeout sooner to give it more time to propagate (remember we also have blobs!). Still, when working in anvil,
|
|
30
|
-
* we can just post in the very last second of the L1 slot and still expect the tx to be accepted.
|
|
31
|
-
*/
|
|
32
|
-
readonly l1PublishingTime: number;
|
|
33
|
-
/**
|
|
34
|
-
* What's the minimum time we want to leave available for execution and reexecution (used to derive init deadline)
|
|
35
|
-
* Defaults to half of the block duration if set, otherwise a constant.
|
|
36
|
-
*/
|
|
37
|
-
readonly minExecutionTime: number;
|
|
38
|
-
/** How long it takes to get ready to start building */
|
|
39
|
-
readonly checkpointInitializationTime: number;
|
|
40
|
-
/** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */
|
|
41
|
-
readonly p2pPropagationTime: number;
|
|
42
|
-
/** How much time we spend assembling a checkpoint after building the last block */
|
|
43
|
-
readonly checkpointAssembleTime: number;
|
|
44
|
-
/** Ethereum slot duration in seconds */
|
|
45
|
-
readonly ethereumSlotDuration: number;
|
|
46
|
-
/** Aztec slot duration in seconds (must be multiple of ethereum slot duration) */
|
|
47
|
-
readonly aztecSlotDuration: number;
|
|
48
|
-
/** Whether assertTimeLeft will throw if not enough time. */
|
|
49
|
-
readonly enforce: boolean;
|
|
50
|
-
/** Duration per block when building multiple blocks per slot (undefined = single block per slot) */
|
|
51
|
-
readonly blockDuration: number | undefined;
|
|
52
|
-
/** Maximum number of blocks that can be built in this slot configuration */
|
|
53
|
-
readonly maxNumberOfBlocks: number;
|
|
54
|
-
/** Whether pipelining is enabled (checkpoint finalization deferred to next slot). */
|
|
55
|
-
readonly pipelining: boolean;
|
|
56
|
-
/**
|
|
57
|
-
* How far into the target slot attestation collection can extend when pipelining.
|
|
58
|
-
* Covers validator re-execution (one block duration) plus one-way attestation return.
|
|
59
|
-
*/
|
|
60
|
-
readonly pipeliningAttestationGracePeriod: number;
|
|
61
|
-
constructor(opts: {
|
|
62
|
-
ethereumSlotDuration: number;
|
|
63
|
-
aztecSlotDuration: number;
|
|
64
|
-
l1PublishingTime: number;
|
|
65
|
-
p2pPropagationTime?: number;
|
|
66
|
-
blockDurationMs?: number;
|
|
67
|
-
enforce: boolean;
|
|
68
|
-
pipelining?: boolean;
|
|
69
|
-
}, metrics?: SequencerMetrics | undefined, log?: Logger | undefined);
|
|
70
|
-
getCheckpointAssemblyDeadline(): number;
|
|
71
|
-
getCheckpointAttestationDeadline(): number;
|
|
72
|
-
getCheckpointAttestationStartDeadline(): number;
|
|
73
|
-
getCheckpointPublishingDeadline(): number;
|
|
74
|
-
getMaxAllowedTime(state: Extract<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>): undefined;
|
|
75
|
-
getMaxAllowedTime(state: Exclude<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>): number;
|
|
76
|
-
getMaxAllowedTime(state: SequencerState): number | undefined;
|
|
77
|
-
assertTimeLeft(newState: SequencerState, secondsIntoSlot: number): void;
|
|
78
|
-
/**
|
|
79
|
-
* Determines if we can start building the next block and returns its deadline.
|
|
80
|
-
*
|
|
81
|
-
* The timetable divides the slot into fixed sub-slots. This method finds the next
|
|
82
|
-
* available sub-slot that has enough time remaining to build a block.
|
|
83
|
-
*
|
|
84
|
-
* @param secondsIntoSlot - Current time (seconds into the slot)
|
|
85
|
-
* @returns Object with canStart flag, deadline, and whether this is the last block
|
|
86
|
-
*/
|
|
87
|
-
canStartNextBlock(secondsIntoSlot: number): {
|
|
88
|
-
canStart: true;
|
|
89
|
-
deadline: undefined;
|
|
90
|
-
isLastBlock: true;
|
|
91
|
-
} | {
|
|
92
|
-
canStart: false;
|
|
93
|
-
deadline: undefined;
|
|
94
|
-
isLastBlock: false;
|
|
95
|
-
} | {
|
|
96
|
-
canStart: boolean;
|
|
97
|
-
deadline: number;
|
|
98
|
-
isLastBlock: boolean;
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGltZXRhYmxlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc2VxdWVuY2VyL3RpbWV0YWJsZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQVdwRCxPQUFPLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLGNBQWMsQ0FBQztBQUNyRCxPQUFPLEVBQUUsY0FBYyxFQUFFLE1BQU0sWUFBWSxDQUFDO0FBRTVDLHFCQUFhLGtCQUFrQjtJQWlGM0IsT0FBTyxDQUFDLFFBQVEsQ0FBQyx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c,CAAC,OAAO,GAAG,cAAc,CAAC,IAAI,GAAG,cAAc,CAAC,aAAa,CAAC,GAC1G,MAAM,CAAC;IACH,iBAAiB,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,GAAG,SAAS,CAAC;IA4B7D,cAAc,CAAC,QAAQ,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,QAiBtE;IAED;;;;;;;;OAQG;IACI,iBAAiB,CACtB,eAAe,EAAE,MAAM,GAErB;QAAE,QAAQ,EAAE,IAAI,CAAC;QAAC,QAAQ,EAAE,SAAS,CAAC;QAAC,WAAW,EAAE,IAAI,CAAA;KAAE,GAC1D;QAAE,QAAQ,EAAE,KAAK,CAAC;QAAC,QAAQ,EAAE,SAAS,CAAC;QAAC,WAAW,EAAE,KAAK,CAAA;KAAE,GAC5D;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,OAAO,CAAA;KAAE,CAwDhE;CACF"}
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import { CHECKPOINT_ASSEMBLE_TIME, CHECKPOINT_INITIALIZATION_TIME, DEFAULT_P2P_PROPAGATION_TIME, MIN_EXECUTION_TIME, createCheckpointTimingModel } from '@aztec/stdlib/timetable';
|
|
2
|
-
import { SequencerTooSlowError } from './errors.js';
|
|
3
|
-
import { SequencerState } from './utils.js';
|
|
4
|
-
export class SequencerTimetable {
|
|
5
|
-
metrics;
|
|
6
|
-
log;
|
|
7
|
-
checkpointTiming;
|
|
8
|
-
/**
|
|
9
|
-
* How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
|
|
10
|
-
* assuming an execution time equal to `minExecutionTime`, subtracted from the slot duration. This means that, if the proposer
|
|
11
|
-
* starts building at this time, and all times hold, it will have at least `minExecutionTime` to execute txs for the block.
|
|
12
|
-
*/ initializeDeadline;
|
|
13
|
-
/**
|
|
14
|
-
* Fixed time offset (in seconds) when the first sub-slot starts, used as baseline for all block deadlines.
|
|
15
|
-
* This is an estimate of how long initialization (sync + proposer check) typically takes.
|
|
16
|
-
* If actual initialization takes longer/shorter, blocks just get less/more time accordingly.
|
|
17
|
-
*/ initializationOffset;
|
|
18
|
-
/**
|
|
19
|
-
* Total time needed to finalize and publish a checkpoint, including:
|
|
20
|
-
* - Assembling the checkpoint
|
|
21
|
-
* - Round-trip p2p propagation for the checkpoint proposal and its corresponding attestations
|
|
22
|
-
* - Publishing to L1
|
|
23
|
-
*/ checkpointFinalizationTime;
|
|
24
|
-
/**
|
|
25
|
-
* How long it takes to get a published block into L1. L1 builders typically accept txs up to 4 seconds into their slot,
|
|
26
|
-
* but we'll timeout sooner to give it more time to propagate (remember we also have blobs!). Still, when working in anvil,
|
|
27
|
-
* we can just post in the very last second of the L1 slot and still expect the tx to be accepted.
|
|
28
|
-
*/ l1PublishingTime;
|
|
29
|
-
/**
|
|
30
|
-
* What's the minimum time we want to leave available for execution and reexecution (used to derive init deadline)
|
|
31
|
-
* Defaults to half of the block duration if set, otherwise a constant.
|
|
32
|
-
*/ minExecutionTime;
|
|
33
|
-
/** How long it takes to get ready to start building */ checkpointInitializationTime;
|
|
34
|
-
/** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */ p2pPropagationTime;
|
|
35
|
-
/** How much time we spend assembling a checkpoint after building the last block */ checkpointAssembleTime;
|
|
36
|
-
/** Ethereum slot duration in seconds */ ethereumSlotDuration;
|
|
37
|
-
/** Aztec slot duration in seconds (must be multiple of ethereum slot duration) */ aztecSlotDuration;
|
|
38
|
-
/** Whether assertTimeLeft will throw if not enough time. */ enforce;
|
|
39
|
-
/** Duration per block when building multiple blocks per slot (undefined = single block per slot) */ blockDuration;
|
|
40
|
-
/** Maximum number of blocks that can be built in this slot configuration */ maxNumberOfBlocks;
|
|
41
|
-
/** Whether pipelining is enabled (checkpoint finalization deferred to next slot). */ pipelining;
|
|
42
|
-
/**
|
|
43
|
-
* How far into the target slot attestation collection can extend when pipelining.
|
|
44
|
-
* Covers validator re-execution (one block duration) plus one-way attestation return.
|
|
45
|
-
*/ pipeliningAttestationGracePeriod;
|
|
46
|
-
constructor(opts, metrics, log){
|
|
47
|
-
this.metrics = metrics;
|
|
48
|
-
this.log = log;
|
|
49
|
-
this.minExecutionTime = MIN_EXECUTION_TIME;
|
|
50
|
-
this.checkpointInitializationTime = CHECKPOINT_INITIALIZATION_TIME;
|
|
51
|
-
this.checkpointAssembleTime = CHECKPOINT_ASSEMBLE_TIME;
|
|
52
|
-
this.ethereumSlotDuration = opts.ethereumSlotDuration;
|
|
53
|
-
this.aztecSlotDuration = opts.aztecSlotDuration;
|
|
54
|
-
this.l1PublishingTime = opts.l1PublishingTime;
|
|
55
|
-
this.blockDuration = opts.blockDurationMs ? opts.blockDurationMs / 1000 : undefined;
|
|
56
|
-
this.enforce = opts.enforce;
|
|
57
|
-
this.pipelining = opts.pipelining ?? false;
|
|
58
|
-
this.checkpointTiming = createCheckpointTimingModel({
|
|
59
|
-
aztecSlotDuration: this.aztecSlotDuration,
|
|
60
|
-
ethereumSlotDuration: this.ethereumSlotDuration,
|
|
61
|
-
blockDuration: this.blockDuration,
|
|
62
|
-
l1PublishingTime: this.l1PublishingTime,
|
|
63
|
-
p2pPropagationTime: opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME,
|
|
64
|
-
pipelining: this.pipelining
|
|
65
|
-
});
|
|
66
|
-
this.p2pPropagationTime = this.checkpointTiming.p2pPropagationTime;
|
|
67
|
-
this.checkpointAssembleTime = this.checkpointTiming.checkpointAssembleTime;
|
|
68
|
-
this.checkpointInitializationTime = this.checkpointTiming.checkpointInitializationTime;
|
|
69
|
-
this.minExecutionTime = this.checkpointTiming.minExecutionTime;
|
|
70
|
-
// Calculate initialization offset - estimate of time needed for sync + proposer check
|
|
71
|
-
// This is the baseline for all sub-slot deadlines
|
|
72
|
-
this.initializationOffset = this.checkpointTiming.checkpointInitializationTime;
|
|
73
|
-
this.checkpointFinalizationTime = this.checkpointTiming.checkpointFinalizationTime;
|
|
74
|
-
this.pipeliningAttestationGracePeriod = this.checkpointTiming.pipeliningAttestationGracePeriod;
|
|
75
|
-
this.maxNumberOfBlocks = this.checkpointTiming.calculateMaxBlocksPerSlot();
|
|
76
|
-
this.initializeDeadline = this.checkpointTiming.initializeDeadline;
|
|
77
|
-
this.log?.info(`Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`, {
|
|
78
|
-
ethereumSlotDuration: this.ethereumSlotDuration,
|
|
79
|
-
aztecSlotDuration: this.aztecSlotDuration,
|
|
80
|
-
l1PublishingTime: this.l1PublishingTime,
|
|
81
|
-
minExecutionTime: this.minExecutionTime,
|
|
82
|
-
blockPrepareTime: this.checkpointInitializationTime,
|
|
83
|
-
p2pPropagationTime: this.p2pPropagationTime,
|
|
84
|
-
blockAssembleTime: this.checkpointAssembleTime,
|
|
85
|
-
initializeDeadline: this.initializeDeadline,
|
|
86
|
-
enforce: this.enforce,
|
|
87
|
-
pipelining: this.pipelining,
|
|
88
|
-
pipeliningAttestationGracePeriod: this.pipeliningAttestationGracePeriod,
|
|
89
|
-
minWorkToDo: this.checkpointTiming.minimumBuildSlotWork,
|
|
90
|
-
blockDuration: this.blockDuration,
|
|
91
|
-
maxNumberOfBlocks: this.maxNumberOfBlocks
|
|
92
|
-
});
|
|
93
|
-
if (this.initializeDeadline <= 0) {
|
|
94
|
-
throw new Error(`Block proposal initialize deadline cannot be negative (got ${this.initializeDeadline} from total time needed ${this.checkpointTiming.minimumBuildSlotWork} and a slot duration of ${this.aztecSlotDuration}).`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
getCheckpointAssemblyDeadline() {
|
|
98
|
-
return this.checkpointTiming.checkpointAssemblyDeadline;
|
|
99
|
-
}
|
|
100
|
-
getCheckpointAttestationDeadline() {
|
|
101
|
-
return this.checkpointTiming.checkpointAttestationDeadline;
|
|
102
|
-
}
|
|
103
|
-
getCheckpointAttestationStartDeadline() {
|
|
104
|
-
return this.checkpointTiming.checkpointAttestationStartDeadline;
|
|
105
|
-
}
|
|
106
|
-
getCheckpointPublishingDeadline() {
|
|
107
|
-
return this.checkpointTiming.checkpointPublishingDeadline;
|
|
108
|
-
}
|
|
109
|
-
getMaxAllowedTime(state) {
|
|
110
|
-
switch(state){
|
|
111
|
-
case SequencerState.STOPPED:
|
|
112
|
-
case SequencerState.STOPPING:
|
|
113
|
-
case SequencerState.IDLE:
|
|
114
|
-
case SequencerState.SYNCHRONIZING:
|
|
115
|
-
return; // We don't really care about times for this states
|
|
116
|
-
case SequencerState.PROPOSER_CHECK:
|
|
117
|
-
case SequencerState.INITIALIZING_CHECKPOINT:
|
|
118
|
-
return this.initializeDeadline;
|
|
119
|
-
case SequencerState.WAITING_FOR_TXS:
|
|
120
|
-
case SequencerState.CREATING_BLOCK:
|
|
121
|
-
case SequencerState.WAITING_UNTIL_NEXT_BLOCK:
|
|
122
|
-
return this.initializeDeadline + this.checkpointInitializationTime;
|
|
123
|
-
case SequencerState.ASSEMBLING_CHECKPOINT:
|
|
124
|
-
return this.getCheckpointAssemblyDeadline();
|
|
125
|
-
case SequencerState.COLLECTING_ATTESTATIONS:
|
|
126
|
-
return this.getCheckpointAttestationStartDeadline();
|
|
127
|
-
case SequencerState.PUBLISHING_CHECKPOINT:
|
|
128
|
-
return this.getCheckpointPublishingDeadline();
|
|
129
|
-
default:
|
|
130
|
-
{
|
|
131
|
-
const _exhaustiveCheck = state;
|
|
132
|
-
throw new Error(`Unexpected state: ${state}`);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
assertTimeLeft(newState, secondsIntoSlot) {
|
|
137
|
-
if (!this.enforce) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
const maxAllowedTime = this.getMaxAllowedTime(newState);
|
|
141
|
-
if (maxAllowedTime === undefined) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
const bufferSeconds = maxAllowedTime - secondsIntoSlot;
|
|
145
|
-
if (bufferSeconds < 0) {
|
|
146
|
-
throw new SequencerTooSlowError(newState, maxAllowedTime, secondsIntoSlot);
|
|
147
|
-
}
|
|
148
|
-
this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
|
|
149
|
-
this.log?.trace(`Enough time to transition to ${newState}`, {
|
|
150
|
-
maxAllowedTime,
|
|
151
|
-
secondsIntoSlot
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Determines if we can start building the next block and returns its deadline.
|
|
156
|
-
*
|
|
157
|
-
* The timetable divides the slot into fixed sub-slots. This method finds the next
|
|
158
|
-
* available sub-slot that has enough time remaining to build a block.
|
|
159
|
-
*
|
|
160
|
-
* @param secondsIntoSlot - Current time (seconds into the slot)
|
|
161
|
-
* @returns Object with canStart flag, deadline, and whether this is the last block
|
|
162
|
-
*/ canStartNextBlock(secondsIntoSlot) {
|
|
163
|
-
// When timetable enforcement is disabled, always allow starting,
|
|
164
|
-
// and build a single block with no deadline. This is here just to
|
|
165
|
-
// satisfy a subset of e2e tests and the sandbox that assume that the
|
|
166
|
-
// sequencer is permanently mining every tx sent.
|
|
167
|
-
if (!this.enforce) {
|
|
168
|
-
return {
|
|
169
|
-
canStart: true,
|
|
170
|
-
deadline: undefined,
|
|
171
|
-
isLastBlock: true
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
// If no block duration is set, then we're in single-block mode, which
|
|
175
|
-
// is handled for backwards compatibility towards another subset of e2e tests.
|
|
176
|
-
if (this.blockDuration === undefined) {
|
|
177
|
-
// In single block mode, execution and re-execution happen sequentially, so we need to
|
|
178
|
-
// split the available time between them. After building, we need time for attestations and L1.
|
|
179
|
-
const maxAllowed = this.aztecSlotDuration - this.checkpointFinalizationTime;
|
|
180
|
-
const available = (maxAllowed - secondsIntoSlot) / 2; // Split remaining time: half for execution, half for re-execution
|
|
181
|
-
const canStart = available >= this.minExecutionTime;
|
|
182
|
-
const deadline = secondsIntoSlot + available;
|
|
183
|
-
this.log?.verbose(`${canStart ? 'Can' : 'Cannot'} start single-block checkpoint at ${secondsIntoSlot}s into slot`, {
|
|
184
|
-
secondsIntoSlot,
|
|
185
|
-
maxAllowed,
|
|
186
|
-
available,
|
|
187
|
-
deadline
|
|
188
|
-
});
|
|
189
|
-
return {
|
|
190
|
-
canStart,
|
|
191
|
-
deadline,
|
|
192
|
-
isLastBlock: true
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
// Otherwise, we're in multi-block-per-slot mode, the default when running in production
|
|
196
|
-
// Find the next available sub-slot that has enough time remaining
|
|
197
|
-
for(let subSlot = 1; subSlot <= this.maxNumberOfBlocks; subSlot++){
|
|
198
|
-
// Calculate end for this sub-slot
|
|
199
|
-
const deadline = this.initializationOffset + subSlot * this.blockDuration;
|
|
200
|
-
// Check if we have enough time to build a block with this deadline
|
|
201
|
-
const timeUntilDeadline = deadline - secondsIntoSlot;
|
|
202
|
-
if (timeUntilDeadline >= this.minExecutionTime) {
|
|
203
|
-
// Found an available sub-slot! Is this the last one?
|
|
204
|
-
const isLastBlock = subSlot === this.maxNumberOfBlocks;
|
|
205
|
-
this.log?.verbose(`Can start ${isLastBlock ? 'last block' : 'block'} in sub-slot ${subSlot} with deadline ${deadline}s`, {
|
|
206
|
-
secondsIntoSlot,
|
|
207
|
-
deadline,
|
|
208
|
-
timeUntilDeadline,
|
|
209
|
-
subSlot,
|
|
210
|
-
maxBlocks: this.maxNumberOfBlocks
|
|
211
|
-
});
|
|
212
|
-
return {
|
|
213
|
-
canStart: true,
|
|
214
|
-
deadline,
|
|
215
|
-
isLastBlock
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
// No sub-slots available with enough time
|
|
220
|
-
this.log?.verbose(`No time left to start any more blocks`, {
|
|
221
|
-
secondsIntoSlot,
|
|
222
|
-
maxBlocks: this.maxNumberOfBlocks,
|
|
223
|
-
initializationOffset: this.initializationOffset
|
|
224
|
-
});
|
|
225
|
-
return {
|
|
226
|
-
canStart: false,
|
|
227
|
-
deadline: undefined,
|
|
228
|
-
isLastBlock: false
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
}
|