@aztec/sequencer-client 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +281 -21
- package/dest/client/sequencer-client.d.ts +41 -18
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +88 -43
- package/dest/config.d.ts +41 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +146 -55
- package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +138 -0
- package/dest/global_variable_builder/fee_provider.d.ts +21 -0
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_provider.js +80 -0
- package/dest/global_variable_builder/global_builder.d.ts +20 -26
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +28 -75
- package/dest/global_variable_builder/index.d.ts +4 -2
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- package/dest/global_variable_builder/index.js +2 -0
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/publisher/config.d.ts +57 -20
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +134 -39
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -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/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +98 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +68 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +36 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +3 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
- package/dest/publisher/sequencer-bundle-simulator.js +198 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +15 -8
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +28 -4
- package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +23 -86
- package/dest/publisher/sequencer-publisher.d.ts +152 -90
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +1257 -421
- 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 +56 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +85 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +189 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +690 -0
- 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 +158 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1801 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
- package/dest/sequencer/checkpoint_voter.d.ts +34 -0
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_voter.js +106 -0
- package/dest/sequencer/config.d.ts +3 -2
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/events.d.ts +103 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/index.d.ts +4 -2
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +3 -1
- package/dest/sequencer/metrics.d.ts +42 -7
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +241 -72
- 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 +251 -138
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +1190 -704
- package/dest/sequencer/types.d.ts +3 -0
- package/dest/sequencer/types.d.ts.map +1 -0
- package/dest/sequencer/types.js +1 -0
- package/dest/sequencer/utils.d.ts +14 -8
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +7 -4
- package/dest/test/index.d.ts +8 -9
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +95 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +231 -0
- package/dest/test/utils.d.ts +67 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +122 -0
- package/package.json +32 -29
- package/src/client/sequencer-client.ts +118 -66
- package/src/config.ts +173 -64
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +182 -0
- package/src/global_variable_builder/fee_provider.ts +97 -0
- package/src/global_variable_builder/global_builder.ts +45 -110
- package/src/global_variable_builder/index.ts +3 -1
- package/src/index.ts +1 -7
- package/src/publisher/config.ts +182 -46
- package/src/publisher/index.ts +3 -0
- package/src/publisher/l1_to_l2_messaging.ts +85 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +164 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +47 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-bundle-simulator.ts +254 -0
- package/src/publisher/sequencer-publisher-factory.ts +43 -13
- package/src/publisher/sequencer-publisher-metrics.ts +19 -71
- package/src/publisher/sequencer-publisher.ts +1042 -542
- package/src/publisher/write_json.ts +78 -0
- package/src/sequencer/README.md +243 -0
- package/src/sequencer/automine/README.md +60 -0
- package/src/sequencer/automine/automine_factory.ts +152 -0
- package/src/sequencer/automine/automine_sequencer.ts +796 -0
- package/src/sequencer/automine/index.ts +6 -0
- package/src/sequencer/checkpoint_proposal_job.ts +1652 -0
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +119 -0
- package/src/sequencer/config.ts +2 -1
- package/src/sequencer/events.ts +88 -0
- package/src/sequencer/index.ts +3 -1
- package/src/sequencer/metrics.ts +302 -83
- package/src/sequencer/requests_tracker.ts +43 -0
- package/src/sequencer/sequencer.ts +1011 -898
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +18 -9
- package/src/test/index.ts +7 -8
- package/src/test/mock_checkpoint_builder.ts +323 -0
- package/src/test/utils.ts +218 -0
- package/dest/sequencer/block_builder.d.ts +0 -28
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -134
- package/dest/sequencer/timetable.d.ts +0 -50
- package/dest/sequencer/timetable.d.ts.map +0 -1
- package/dest/sequencer/timetable.js +0 -137
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -53
- package/src/sequencer/block_builder.ts +0 -222
- package/src/sequencer/timetable.ts +0 -188
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -133
package/src/config.ts
CHANGED
|
@@ -1,87 +1,151 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
type L1ReaderConfig,
|
|
4
|
-
l1ContractsConfigMappings,
|
|
5
|
-
l1ReaderConfigMappings,
|
|
6
|
-
} from '@aztec/ethereum';
|
|
1
|
+
import { type L1ContractsConfig, l1ContractsConfigMappings } from '@aztec/ethereum/config';
|
|
2
|
+
import { type L1ReaderConfig, l1ReaderConfigMappings } from '@aztec/ethereum/l1-reader';
|
|
7
3
|
import {
|
|
8
4
|
type ConfigMappingsType,
|
|
9
5
|
booleanConfigHelper,
|
|
6
|
+
floatConfigHelper,
|
|
10
7
|
getConfigFromMappings,
|
|
11
8
|
numberConfigHelper,
|
|
9
|
+
optionalNumberConfigHelper,
|
|
12
10
|
pickConfigMappings,
|
|
13
11
|
} from '@aztec/foundation/config';
|
|
14
12
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
15
|
-
import { type KeyStoreConfig, keyStoreConfigMappings } from '@aztec/node-keystore';
|
|
16
|
-
import { type P2PConfig, p2pConfigMappings } from '@aztec/p2p';
|
|
13
|
+
import { type KeyStoreConfig, keyStoreConfigMappings } from '@aztec/node-keystore/config';
|
|
14
|
+
import { type P2PConfig, p2pConfigMappings } from '@aztec/p2p/config';
|
|
17
15
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
18
|
-
import {
|
|
19
|
-
|
|
16
|
+
import {
|
|
17
|
+
type ChainConfig,
|
|
18
|
+
DEFAULT_BLOCK_DURATION_MS,
|
|
19
|
+
DEFAULT_MAX_BLOCKS_PER_CHECKPOINT,
|
|
20
|
+
type SequencerConfig,
|
|
21
|
+
chainConfigMappings,
|
|
22
|
+
sharedSequencerConfigMappings,
|
|
23
|
+
} from '@aztec/stdlib/config';
|
|
24
|
+
import { MIN_PER_BLOCK_ALLOCATION_MULTIPLIER, MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER } from '@aztec/stdlib/gas';
|
|
25
|
+
import type { ResolvedSequencerConfig } from '@aztec/stdlib/interfaces/server';
|
|
26
|
+
import { DEFAULT_P2P_PROPAGATION_TIME } from '@aztec/stdlib/timetable';
|
|
27
|
+
import { type ValidatorClientConfig, validatorClientConfigMappings } from '@aztec/validator-client/config';
|
|
20
28
|
|
|
21
29
|
import {
|
|
22
|
-
type
|
|
23
|
-
type
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
type SequencerPublisherConfig,
|
|
31
|
+
type SequencerTxSenderConfig,
|
|
32
|
+
sequencerPublisherConfigMappings,
|
|
33
|
+
sequencerTxSenderConfigMappings,
|
|
26
34
|
} from './publisher/config.js';
|
|
27
35
|
|
|
28
36
|
export * from './publisher/config.js';
|
|
29
37
|
export type { SequencerConfig };
|
|
30
38
|
|
|
31
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Default values for SequencerConfig.
|
|
41
|
+
* Centralized location for all sequencer configuration defaults.
|
|
42
|
+
*/
|
|
43
|
+
export const DefaultSequencerConfig = {
|
|
44
|
+
sequencerPollingIntervalMS: 500,
|
|
45
|
+
minTxsPerBlock: 1,
|
|
46
|
+
buildCheckpointIfEmpty: false,
|
|
47
|
+
publishTxsWithProposals: false,
|
|
48
|
+
perBlockAllocationMultiplier: MIN_PER_BLOCK_ALLOCATION_MULTIPLIER,
|
|
49
|
+
perBlockDAAllocationMultiplier: MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER,
|
|
50
|
+
redistributeCheckpointBudget: true,
|
|
51
|
+
blockDurationMs: DEFAULT_BLOCK_DURATION_MS,
|
|
52
|
+
l1PublishingTime: 12,
|
|
53
|
+
checkpointProposalSyncGraceSeconds: 2 * (DEFAULT_BLOCK_DURATION_MS / 1000),
|
|
54
|
+
attestationPropagationTime: DEFAULT_P2P_PROPAGATION_TIME,
|
|
55
|
+
secondsBeforeInvalidatingBlockAsCommitteeMember: 144, // 12 L1 blocks
|
|
56
|
+
secondsBeforeInvalidatingBlockAsNonCommitteeMember: 432, // 36 L1 blocks
|
|
57
|
+
skipCollectingAttestations: false,
|
|
58
|
+
skipInvalidateBlockAsProposer: false,
|
|
59
|
+
skipWaitForValidParentCheckpointOnL1: false,
|
|
60
|
+
broadcastInvalidBlockProposal: false,
|
|
61
|
+
broadcastInvalidCheckpointProposalOnly: false,
|
|
62
|
+
injectFakeAttestation: false,
|
|
63
|
+
injectHighSValueAttestation: false,
|
|
64
|
+
injectUnrecoverableSignatureAttestation: false,
|
|
65
|
+
injectYParityAttestation: false,
|
|
66
|
+
fishermanMode: false,
|
|
67
|
+
shuffleAttestationOrdering: false,
|
|
68
|
+
skipPushProposedBlocksToArchiver: false,
|
|
69
|
+
skipPublishingCheckpointsPercent: 0,
|
|
70
|
+
maxBlocksPerCheckpoint: DEFAULT_MAX_BLOCKS_PER_CHECKPOINT,
|
|
71
|
+
} satisfies ResolvedSequencerConfig;
|
|
32
72
|
|
|
33
73
|
/**
|
|
34
74
|
* Configuration settings for the SequencerClient.
|
|
35
75
|
*/
|
|
36
|
-
export type SequencerClientConfig =
|
|
76
|
+
export type SequencerClientConfig = SequencerPublisherConfig &
|
|
37
77
|
KeyStoreConfig &
|
|
38
78
|
ValidatorClientConfig &
|
|
39
|
-
|
|
79
|
+
SequencerTxSenderConfig &
|
|
40
80
|
SequencerConfig &
|
|
41
81
|
L1ReaderConfig &
|
|
42
82
|
ChainConfig &
|
|
43
|
-
Pick<P2PConfig, '
|
|
83
|
+
Pick<P2PConfig, 'txPublicSetupAllowListExtend'> &
|
|
44
84
|
Pick<L1ContractsConfig, 'ethereumSlotDuration' | 'aztecSlotDuration' | 'aztecEpochDuration'>;
|
|
45
85
|
|
|
46
86
|
export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
|
|
47
|
-
|
|
48
|
-
env: '
|
|
49
|
-
description: 'The number of ms to wait between polling for
|
|
50
|
-
...numberConfigHelper(
|
|
87
|
+
sequencerPollingIntervalMS: {
|
|
88
|
+
env: 'SEQ_POLLING_INTERVAL_MS',
|
|
89
|
+
description: 'The number of ms to wait between polling for checking to build on the next slot.',
|
|
90
|
+
...numberConfigHelper(DefaultSequencerConfig.sequencerPollingIntervalMS),
|
|
51
91
|
},
|
|
52
|
-
|
|
53
|
-
env: '
|
|
54
|
-
description: 'The maximum number of txs
|
|
55
|
-
...
|
|
92
|
+
maxTxsPerCheckpoint: {
|
|
93
|
+
env: 'SEQ_MAX_TX_PER_CHECKPOINT',
|
|
94
|
+
description: 'The maximum number of txs across all blocks in a checkpoint.',
|
|
95
|
+
...optionalNumberConfigHelper(),
|
|
56
96
|
},
|
|
57
97
|
minTxsPerBlock: {
|
|
58
98
|
env: 'SEQ_MIN_TX_PER_BLOCK',
|
|
59
99
|
description: 'The minimum number of txs to include in a block.',
|
|
60
|
-
...numberConfigHelper(
|
|
100
|
+
...numberConfigHelper(DefaultSequencerConfig.minTxsPerBlock),
|
|
101
|
+
},
|
|
102
|
+
minValidTxsPerBlock: {
|
|
103
|
+
description:
|
|
104
|
+
'The minimum number of valid txs (after execution) to include in a block. If not set, falls back to minTxsPerBlock.',
|
|
61
105
|
},
|
|
62
106
|
publishTxsWithProposals: {
|
|
63
107
|
env: 'SEQ_PUBLISH_TXS_WITH_PROPOSALS',
|
|
64
108
|
description: 'Whether to publish txs with proposals.',
|
|
65
|
-
...booleanConfigHelper(
|
|
109
|
+
...booleanConfigHelper(DefaultSequencerConfig.publishTxsWithProposals),
|
|
66
110
|
},
|
|
67
111
|
maxL2BlockGas: {
|
|
68
112
|
env: 'SEQ_MAX_L2_BLOCK_GAS',
|
|
69
113
|
description: 'The maximum L2 block gas.',
|
|
70
|
-
...
|
|
114
|
+
...optionalNumberConfigHelper(),
|
|
71
115
|
},
|
|
72
116
|
maxDABlockGas: {
|
|
73
117
|
env: 'SEQ_MAX_DA_BLOCK_GAS',
|
|
74
118
|
description: 'The maximum DA block gas.',
|
|
75
|
-
...
|
|
119
|
+
...optionalNumberConfigHelper(),
|
|
120
|
+
},
|
|
121
|
+
perBlockAllocationMultiplier: {
|
|
122
|
+
env: 'SEQ_PER_BLOCK_ALLOCATION_MULTIPLIER',
|
|
123
|
+
description:
|
|
124
|
+
'Per-block gas budget multiplier for both L2 and DA gas. Budget per block is (checkpointLimit / maxBlocks) * multiplier.' +
|
|
125
|
+
' Values greater than one allow early blocks to use more than their even share, relying on checkpoint-level capping for later blocks.',
|
|
126
|
+
...floatConfigHelper(DefaultSequencerConfig.perBlockAllocationMultiplier),
|
|
127
|
+
},
|
|
128
|
+
perBlockDAAllocationMultiplier: {
|
|
129
|
+
env: 'SEQ_PER_BLOCK_DA_ALLOCATION_MULTIPLIER',
|
|
130
|
+
description:
|
|
131
|
+
'Per-block budget multiplier applied to DA gas and blob fields in place of perBlockAllocationMultiplier.' +
|
|
132
|
+
' Defaults higher than the general multiplier so the largest contract class deploy fits a single block.',
|
|
133
|
+
...floatConfigHelper(DefaultSequencerConfig.perBlockDAAllocationMultiplier),
|
|
134
|
+
},
|
|
135
|
+
redistributeCheckpointBudget: {
|
|
136
|
+
env: 'SEQ_REDISTRIBUTE_CHECKPOINT_BUDGET',
|
|
137
|
+
description:
|
|
138
|
+
'Redistribute remaining checkpoint budget evenly across remaining blocks instead of allowing a single block to consume the entire remaining budget.',
|
|
139
|
+
...booleanConfigHelper(DefaultSequencerConfig.redistributeCheckpointBudget),
|
|
76
140
|
},
|
|
77
141
|
coinbase: {
|
|
78
142
|
env: 'COINBASE',
|
|
79
|
-
parseEnv: (val: string) =>
|
|
143
|
+
parseEnv: (val: string) => EthAddress.fromString(val),
|
|
80
144
|
description: 'Recipient of block reward.',
|
|
81
145
|
},
|
|
82
146
|
feeRecipient: {
|
|
83
147
|
env: 'FEE_RECIPIENT',
|
|
84
|
-
parseEnv: (val: string) => AztecAddress.
|
|
148
|
+
parseEnv: (val: string) => AztecAddress.fromStringUnsafe(val),
|
|
85
149
|
description: 'Address to receive fees.',
|
|
86
150
|
},
|
|
87
151
|
acvmWorkingDirectory: {
|
|
@@ -92,88 +156,133 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
|
|
|
92
156
|
env: 'ACVM_BINARY_PATH',
|
|
93
157
|
description: 'The path to the ACVM binary',
|
|
94
158
|
},
|
|
95
|
-
maxBlockSizeInBytes: {
|
|
96
|
-
env: 'SEQ_MAX_BLOCK_SIZE_IN_BYTES',
|
|
97
|
-
description: 'Max block size',
|
|
98
|
-
...numberConfigHelper(1024 * 1024),
|
|
99
|
-
},
|
|
100
|
-
enforceTimeTable: {
|
|
101
|
-
env: 'SEQ_ENFORCE_TIME_TABLE',
|
|
102
|
-
description: 'Whether to enforce the time table when building blocks',
|
|
103
|
-
...booleanConfigHelper(),
|
|
104
|
-
defaultValue: true,
|
|
105
|
-
},
|
|
106
159
|
governanceProposerPayload: {
|
|
107
160
|
env: 'GOVERNANCE_PROPOSER_PAYLOAD_ADDRESS',
|
|
108
161
|
description: 'The address of the payload for the governanceProposer',
|
|
109
162
|
parseEnv: (val: string) => EthAddress.fromString(val),
|
|
110
|
-
defaultValue: EthAddress.ZERO,
|
|
111
|
-
},
|
|
112
|
-
maxL1TxInclusionTimeIntoSlot: {
|
|
113
|
-
env: 'SEQ_MAX_L1_TX_INCLUSION_TIME_INTO_SLOT',
|
|
114
|
-
description: 'How many seconds into an L1 slot we can still send a tx and get it mined.',
|
|
115
|
-
parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
|
|
116
163
|
},
|
|
117
|
-
|
|
118
|
-
env: '
|
|
119
|
-
description: 'How
|
|
120
|
-
...numberConfigHelper(
|
|
164
|
+
l1PublishingTime: {
|
|
165
|
+
env: 'SEQ_L1_PUBLISHING_TIME_ALLOWANCE_IN_SLOT',
|
|
166
|
+
description: 'How much time in seconds to allow in the slot for publishing the L1 transaction.',
|
|
167
|
+
...numberConfigHelper(DefaultSequencerConfig.l1PublishingTime),
|
|
121
168
|
},
|
|
122
169
|
fakeProcessingDelayPerTxMs: {
|
|
123
170
|
description: 'Used for testing to introduce a fake delay after processing each tx',
|
|
124
171
|
},
|
|
172
|
+
fakeThrowAfterProcessingTxCount: {
|
|
173
|
+
description: 'Used for testing to throw an error after processing N txs',
|
|
174
|
+
},
|
|
125
175
|
secondsBeforeInvalidatingBlockAsCommitteeMember: {
|
|
126
176
|
env: 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_COMMITTEE_MEMBER',
|
|
127
177
|
description:
|
|
128
178
|
'How many seconds to wait before trying to invalidate a block from the pending chain as a committee member (zero to never invalidate).' +
|
|
129
179
|
' The next proposer is expected to invalidate, so the committee acts as a fallback.',
|
|
130
|
-
...numberConfigHelper(
|
|
180
|
+
...numberConfigHelper(DefaultSequencerConfig.secondsBeforeInvalidatingBlockAsCommitteeMember),
|
|
131
181
|
},
|
|
132
182
|
secondsBeforeInvalidatingBlockAsNonCommitteeMember: {
|
|
133
183
|
env: 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_NON_COMMITTEE_MEMBER',
|
|
134
184
|
description:
|
|
135
185
|
'How many seconds to wait before trying to invalidate a block from the pending chain as a non-committee member (zero to never invalidate).' +
|
|
136
186
|
' The next proposer is expected to invalidate, then the committee, so other sequencers act as a fallback.',
|
|
137
|
-
...numberConfigHelper(
|
|
187
|
+
...numberConfigHelper(DefaultSequencerConfig.secondsBeforeInvalidatingBlockAsNonCommitteeMember),
|
|
138
188
|
},
|
|
139
189
|
skipCollectingAttestations: {
|
|
140
190
|
description:
|
|
141
191
|
'Whether to skip collecting attestations from validators and only use self-attestations (for testing only)',
|
|
142
|
-
...booleanConfigHelper(
|
|
192
|
+
...booleanConfigHelper(DefaultSequencerConfig.skipCollectingAttestations),
|
|
143
193
|
},
|
|
144
194
|
skipInvalidateBlockAsProposer: {
|
|
145
195
|
description: 'Do not invalidate the previous block if invalid when we are the proposer (for testing only)',
|
|
146
|
-
...booleanConfigHelper(
|
|
196
|
+
...booleanConfigHelper(DefaultSequencerConfig.skipInvalidateBlockAsProposer),
|
|
197
|
+
},
|
|
198
|
+
skipWaitForValidParentCheckpointOnL1: {
|
|
199
|
+
description:
|
|
200
|
+
'Bypass the parent checkpoint validity check before submitting a pipelined checkpoint, ' +
|
|
201
|
+
'allowing the proposer to publish even when the parent landed on L1 with invalid attestations (for testing only)',
|
|
202
|
+
...booleanConfigHelper(DefaultSequencerConfig.skipWaitForValidParentCheckpointOnL1),
|
|
147
203
|
},
|
|
148
204
|
broadcastInvalidBlockProposal: {
|
|
149
205
|
description: 'Broadcast invalid block proposals with corrupted state (for testing only)',
|
|
150
|
-
...booleanConfigHelper(
|
|
206
|
+
...booleanConfigHelper(DefaultSequencerConfig.broadcastInvalidBlockProposal),
|
|
207
|
+
},
|
|
208
|
+
invalidBlockProposalIndexWithinCheckpoint: {
|
|
209
|
+
description: 'Broadcast an invalid block proposal only at this indexWithinCheckpoint (for testing only)',
|
|
210
|
+
...optionalNumberConfigHelper(),
|
|
211
|
+
},
|
|
212
|
+
broadcastInvalidCheckpointProposalOnly: {
|
|
213
|
+
description:
|
|
214
|
+
'Broadcast invalid checkpoint proposals while keeping the underlying block proposals valid (for testing only). When unset, the checkpoint follows broadcastInvalidBlockProposal.',
|
|
215
|
+
...booleanConfigHelper(DefaultSequencerConfig.broadcastInvalidCheckpointProposalOnly),
|
|
151
216
|
},
|
|
152
217
|
injectFakeAttestation: {
|
|
153
218
|
description: 'Inject a fake attestation (for testing only)',
|
|
154
|
-
...booleanConfigHelper(
|
|
219
|
+
...booleanConfigHelper(DefaultSequencerConfig.injectFakeAttestation),
|
|
220
|
+
},
|
|
221
|
+
injectHighSValueAttestation: {
|
|
222
|
+
description: 'Inject a malleable attestation with a high-s value (for testing only)',
|
|
223
|
+
...booleanConfigHelper(DefaultSequencerConfig.injectHighSValueAttestation),
|
|
224
|
+
},
|
|
225
|
+
injectUnrecoverableSignatureAttestation: {
|
|
226
|
+
description: 'Inject an attestation with an unrecoverable signature (for testing only)',
|
|
227
|
+
...booleanConfigHelper(DefaultSequencerConfig.injectUnrecoverableSignatureAttestation),
|
|
228
|
+
},
|
|
229
|
+
injectYParityAttestation: {
|
|
230
|
+
description: 'Inject a non-proposer attestation slot in yParity form in the packed L1 tuple (for testing only)',
|
|
231
|
+
...booleanConfigHelper(DefaultSequencerConfig.injectYParityAttestation),
|
|
155
232
|
},
|
|
156
233
|
fishermanMode: {
|
|
157
234
|
env: 'FISHERMAN_MODE',
|
|
158
235
|
description:
|
|
159
236
|
'Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1',
|
|
160
|
-
...booleanConfigHelper(
|
|
237
|
+
...booleanConfigHelper(DefaultSequencerConfig.fishermanMode),
|
|
161
238
|
},
|
|
162
239
|
shuffleAttestationOrdering: {
|
|
163
240
|
description: 'Shuffle attestation ordering to create invalid ordering (for testing only)',
|
|
241
|
+
...booleanConfigHelper(DefaultSequencerConfig.shuffleAttestationOrdering),
|
|
242
|
+
},
|
|
243
|
+
...sharedSequencerConfigMappings,
|
|
244
|
+
buildCheckpointIfEmpty: {
|
|
245
|
+
env: 'SEQ_BUILD_CHECKPOINT_IF_EMPTY',
|
|
246
|
+
description: 'Have sequencer build and publish an empty checkpoint if there are no txs',
|
|
247
|
+
...booleanConfigHelper(DefaultSequencerConfig.buildCheckpointIfEmpty),
|
|
248
|
+
},
|
|
249
|
+
skipPushProposedBlocksToArchiver: {
|
|
250
|
+
description: 'Skip pushing proposed blocks to archiver (test only)',
|
|
251
|
+
...booleanConfigHelper(DefaultSequencerConfig.skipPushProposedBlocksToArchiver),
|
|
252
|
+
},
|
|
253
|
+
minBlocksForCheckpoint: {
|
|
254
|
+
description: 'Minimum number of blocks required for a checkpoint proposal (test only)',
|
|
255
|
+
},
|
|
256
|
+
skipPublishingCheckpointsPercent: {
|
|
257
|
+
env: 'SEQ_SKIP_CHECKPOINT_PUBLISH_PERCENT',
|
|
258
|
+
description: 'Percent probability (0 - 100) of sequencer skipping checkpoint publishing (testing only)',
|
|
259
|
+
...numberConfigHelper(DefaultSequencerConfig.skipPublishingCheckpointsPercent),
|
|
260
|
+
},
|
|
261
|
+
skipBroadcastProposals: {
|
|
262
|
+
description: 'Skip broadcasting checkpoint and block proposals via gossipsub when proposer (for testing only)',
|
|
263
|
+
...booleanConfigHelper(false),
|
|
264
|
+
},
|
|
265
|
+
skipBroadcastCheckpointProposal: {
|
|
266
|
+
description:
|
|
267
|
+
'Skip broadcasting only the CheckpointProposal via gossipsub when proposer; the held last block is broadcast ' +
|
|
268
|
+
'standalone instead so peers still receive it as a proposed-but-uncheckpointed tip (for testing only)',
|
|
164
269
|
...booleanConfigHelper(false),
|
|
165
270
|
},
|
|
166
|
-
|
|
271
|
+
pauseProposingForSlots: {
|
|
272
|
+
description:
|
|
273
|
+
'List of slots for which the sequencer will not produce a proposal (for testing only). Attestation paths are unaffected.',
|
|
274
|
+
},
|
|
275
|
+
...pickConfigMappings(p2pConfigMappings, ['txPublicSetupAllowListExtend']),
|
|
167
276
|
};
|
|
168
277
|
|
|
169
278
|
export const sequencerClientConfigMappings: ConfigMappingsType<SequencerClientConfig> = {
|
|
279
|
+
...chainConfigMappings,
|
|
170
280
|
...validatorClientConfigMappings,
|
|
171
281
|
...sequencerConfigMappings,
|
|
172
282
|
...keyStoreConfigMappings,
|
|
173
283
|
...l1ReaderConfigMappings,
|
|
174
|
-
...
|
|
175
|
-
...
|
|
176
|
-
...chainConfigMappings,
|
|
284
|
+
...sequencerTxSenderConfigMappings,
|
|
285
|
+
...sequencerPublisherConfigMappings,
|
|
177
286
|
...pickConfigMappings(l1ContractsConfigMappings, ['ethereumSlotDuration', 'aztecSlotDuration', 'aztecEpochDuration']),
|
|
178
287
|
};
|
|
179
288
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Fee Prediction
|
|
2
|
+
|
|
3
|
+
The `FeePredictor` predicts min fees for upcoming L2 slots based on the current L1
|
|
4
|
+
oracle state and an assumed mana usage pattern.
|
|
5
|
+
|
|
6
|
+
## Prediction Window
|
|
7
|
+
|
|
8
|
+
The prediction covers `LAG = 2` entries (the next available slot plus 1 more).
|
|
9
|
+
A new oracle update can activate at `startSlot + LAG`, so only the first LAG entries
|
|
10
|
+
are guaranteed stable. Beyond that, L1 fees could change unpredictably.
|
|
11
|
+
|
|
12
|
+
Each entry uses:
|
|
13
|
+
|
|
14
|
+
- The **actual L1 fees** the oracle would return for that slot's timestamp (pre or post,
|
|
15
|
+
depending on whether the slot is before or after `slotOfChange`).
|
|
16
|
+
- A **configurable congestion assumption** (`ManaUsageEstimate`): none (0 mana), target
|
|
17
|
+
(steady state), or limit (worst case, 2x target).
|
|
18
|
+
|
|
19
|
+
The client picks `max(predicted[0..LAG-1])` as their `maxFeesPerGas`.
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
predicted[0] → fee at next slot (current oracle + current congestion)
|
|
23
|
+
predicted[1] → fee at next slot + 1 (congestion may change based on usage estimate)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Why LAG and not LIFETIME?
|
|
27
|
+
|
|
28
|
+
The L1 gas oracle has two timing constants:
|
|
29
|
+
|
|
30
|
+
- **LAG = 2 slots**: when new fees are queued, they activate LAG slots later
|
|
31
|
+
- **LIFETIME = 5 slots**: after an oracle update, the next update is rejected until
|
|
32
|
+
`slotOfChange + (LIFETIME - LAG)` slots have passed
|
|
33
|
+
|
|
34
|
+
If the oracle cooldown has already elapsed (i.e., no recent update), a new update can
|
|
35
|
+
be enqueued at any moment. Its new values would activate LAG slots later. This means
|
|
36
|
+
predictions beyond LAG slots could be invalidated by an oracle update that happens
|
|
37
|
+
right after we query.
|
|
38
|
+
|
|
39
|
+
With a LIFETIME-sized window, we'd give a false sense of coverage: the prediction
|
|
40
|
+
would look like it covers 6 slots, but slots beyond LAG could be wrong if an update
|
|
41
|
+
is enqueued after the prediction is computed.
|
|
42
|
+
|
|
43
|
+
By limiting to LAG entries, we guarantee that all predicted L1 fees are the ones that
|
|
44
|
+
will actually be used — no oracle update can change them within this window.
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { type L1FeeData, MAX_FEE_ASSET_PRICE_MODIFIER_BPS, type RollupContract } from '@aztec/ethereum/contracts';
|
|
2
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { times } from '@aztec/foundation/collection';
|
|
4
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
5
|
+
import { getSlotAtNextL1Block, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
6
|
+
import {
|
|
7
|
+
FEE_ORACLE_LAG,
|
|
8
|
+
GasFees,
|
|
9
|
+
MIN_ETH_PER_FEE_ASSET,
|
|
10
|
+
ManaUsageEstimate,
|
|
11
|
+
computeExcessMana,
|
|
12
|
+
computeManaMinFee,
|
|
13
|
+
} from '@aztec/stdlib/gas';
|
|
14
|
+
|
|
15
|
+
/** Cached rollup state for fee prediction. Refreshed once per L1 block. */
|
|
16
|
+
type FeeOracleState = {
|
|
17
|
+
lastSlot: SlotNumber;
|
|
18
|
+
excessMana: bigint;
|
|
19
|
+
ethPerFeeAsset: bigint;
|
|
20
|
+
manaTarget: bigint;
|
|
21
|
+
manaLimit: bigint;
|
|
22
|
+
provingCostPerManaEth: bigint;
|
|
23
|
+
epochDuration: bigint;
|
|
24
|
+
/** Pre-resolved L1 fees for each slot in the prediction window. */
|
|
25
|
+
l1FeesBySlot: L1FeeData[];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Predicts min fees for LAG upcoming slots based on the L1 oracle state.
|
|
30
|
+
* A new oracle update can activate at startSlot + LAG, so only the first LAG entries
|
|
31
|
+
* are guaranteed stable. Caches L1 queries per L1 block and recomputes predictions
|
|
32
|
+
* for each mana usage estimate.
|
|
33
|
+
*/
|
|
34
|
+
export class FeePredictor {
|
|
35
|
+
private cachedState: Promise<FeeOracleState> | undefined;
|
|
36
|
+
private cachedL1BlockNumber: bigint | undefined;
|
|
37
|
+
|
|
38
|
+
private readonly slotDuration: number;
|
|
39
|
+
private readonly l1GenesisTime: bigint;
|
|
40
|
+
private readonly ethereumSlotDuration: number;
|
|
41
|
+
|
|
42
|
+
constructor(
|
|
43
|
+
private readonly rollupContract: RollupContract,
|
|
44
|
+
private readonly publicClient: { getBlockNumber: (opts?: { cacheTime?: number }) => Promise<bigint> },
|
|
45
|
+
private readonly dateProvider: DateProvider,
|
|
46
|
+
config: { slotDuration: number; l1GenesisTime: bigint; ethereumSlotDuration: number },
|
|
47
|
+
) {
|
|
48
|
+
this.slotDuration = config.slotDuration;
|
|
49
|
+
this.l1GenesisTime = config.l1GenesisTime;
|
|
50
|
+
this.ethereumSlotDuration = config.ethereumSlotDuration;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Returns predicted min fees for each slot in the prediction window. */
|
|
54
|
+
async getPredictedMinFees(manaUsage: ManaUsageEstimate): Promise<GasFees[]> {
|
|
55
|
+
const state = await this.getState();
|
|
56
|
+
return this.computePredictions(state, manaUsage);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Fetches and caches rollup state. Refreshes when L1 block number advances. */
|
|
60
|
+
private async getState(): Promise<FeeOracleState> {
|
|
61
|
+
const blockNumber = await this.publicClient.getBlockNumber({ cacheTime: 0 });
|
|
62
|
+
if (this.cachedL1BlockNumber === undefined || blockNumber > this.cachedL1BlockNumber) {
|
|
63
|
+
this.cachedL1BlockNumber = blockNumber;
|
|
64
|
+
// Reset the cached block number on failure so a transient L1 RPC error does not leave a
|
|
65
|
+
// rejected promise cached for this block, which would replay the same rejection on every
|
|
66
|
+
// subsequent call until the next L1 block arrives. Only clear it if it still points at the
|
|
67
|
+
// block this attempt was for, so a stale rejection from an older block cannot wipe a marker
|
|
68
|
+
// a newer call already advanced (which would also defeat the monotonic block-number guard).
|
|
69
|
+
this.cachedState = this.fetchState(blockNumber).catch(err => {
|
|
70
|
+
if (this.cachedL1BlockNumber === blockNumber) {
|
|
71
|
+
this.cachedL1BlockNumber = undefined;
|
|
72
|
+
}
|
|
73
|
+
throw err;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return this.cachedState!;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private async fetchState(blockNumber: bigint): Promise<FeeOracleState> {
|
|
80
|
+
// Pin all non-constant queries to this L1 block number for a consistent snapshot.
|
|
81
|
+
const opts = { blockNumber };
|
|
82
|
+
|
|
83
|
+
// Cached constants don't need pinning
|
|
84
|
+
const [manaTarget, manaLimit, provingCostPerManaEth, epochDuration] = await Promise.all([
|
|
85
|
+
this.rollupContract.getManaTarget(),
|
|
86
|
+
this.rollupContract.getManaLimit(),
|
|
87
|
+
this.rollupContract.getProvingCostPerMana(),
|
|
88
|
+
this.rollupContract.getEpochDuration(),
|
|
89
|
+
]);
|
|
90
|
+
|
|
91
|
+
// First, compute the earliest possible nextSlot independently of the checkpoint, so we can
|
|
92
|
+
// evaluate pruneability at the prediction start timestamp instead of the current L1 block time.
|
|
93
|
+
// This avoids an epoch-boundary edge case where the effective parent differs between now and nextSlot.
|
|
94
|
+
const slotConfig = { slotDuration: this.slotDuration, l1GenesisTime: this.l1GenesisTime };
|
|
95
|
+
const currentSlot = await this.rollupContract.getSlotNumber(opts);
|
|
96
|
+
|
|
97
|
+
const slotAtNextL1Block = getSlotAtNextL1Block(BigInt(this.dateProvider.nowInSeconds()), {
|
|
98
|
+
l1GenesisTime: this.l1GenesisTime,
|
|
99
|
+
slotDuration: this.slotDuration,
|
|
100
|
+
ethereumSlotDuration: this.ethereumSlotDuration,
|
|
101
|
+
});
|
|
102
|
+
const preliminaryNextSlot = SlotNumber(Math.max(currentSlot, slotAtNextL1Block));
|
|
103
|
+
const nextSlotTimestamp = getTimestampForSlot(preliminaryNextSlot, slotConfig);
|
|
104
|
+
|
|
105
|
+
// Resolve the effective checkpoint at the prediction start timestamp
|
|
106
|
+
const lastCheckpoint = await this.rollupContract.getEffectivePendingCheckpoint(nextSlotTimestamp, opts);
|
|
107
|
+
const lastSlot = lastCheckpoint.slotNumber;
|
|
108
|
+
// Refine nextSlot: also account for the slot after the last checkpoint
|
|
109
|
+
const nextSlot = SlotNumber(Math.max(SlotNumber.add(lastSlot, 1), preliminaryNextSlot));
|
|
110
|
+
const feeHeader = lastCheckpoint.feeHeader;
|
|
111
|
+
|
|
112
|
+
const slotCount = FEE_ORACLE_LAG;
|
|
113
|
+
const timestamps = times(slotCount, i => getTimestampForSlot(SlotNumber.add(nextSlot, i), slotConfig));
|
|
114
|
+
const l1FeesBySlot = await Promise.all(timestamps.map(ts => this.rollupContract.getL1FeesAt(ts, opts)));
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
lastSlot,
|
|
118
|
+
excessMana: computeExcessMana(feeHeader.excessMana, feeHeader.manaUsed, manaTarget),
|
|
119
|
+
ethPerFeeAsset: feeHeader.ethPerFeeAsset,
|
|
120
|
+
manaTarget,
|
|
121
|
+
manaLimit,
|
|
122
|
+
provingCostPerManaEth,
|
|
123
|
+
epochDuration: BigInt(epochDuration),
|
|
124
|
+
l1FeesBySlot,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Computes per-slot fee predictions given cached state and a mana usage assumption. */
|
|
129
|
+
private computePredictions(state: FeeOracleState, manaUsage: ManaUsageEstimate): GasFees[] {
|
|
130
|
+
const assumedManaUsed = this.getAssumedManaUsed(state, manaUsage);
|
|
131
|
+
|
|
132
|
+
const result: GasFees[] = [];
|
|
133
|
+
let { excessMana } = state;
|
|
134
|
+
let { ethPerFeeAsset } = state;
|
|
135
|
+
|
|
136
|
+
// Slot 0: current state (next available slot after last checkpoint)
|
|
137
|
+
result.push(this.computeGasFees(state, excessMana, ethPerFeeAsset, state.l1FeesBySlot[0]));
|
|
138
|
+
|
|
139
|
+
// Slots 1..LAG-1: advance excessMana with the assumed mana usage per checkpoint,
|
|
140
|
+
// and decay ethPerFeeAsset by MAX_FEE_ASSET_PRICE_MODIFIER_BPS per slot for conservative estimates.
|
|
141
|
+
// Lower ethPerFeeAsset means higher fees in fee asset terms.
|
|
142
|
+
for (let i = 1; i < state.l1FeesBySlot.length; i++) {
|
|
143
|
+
excessMana = computeExcessMana(excessMana, assumedManaUsed, state.manaTarget);
|
|
144
|
+
const decayed = (ethPerFeeAsset * (10000n - MAX_FEE_ASSET_PRICE_MODIFIER_BPS)) / 10000n;
|
|
145
|
+
ethPerFeeAsset = decayed < MIN_ETH_PER_FEE_ASSET ? MIN_ETH_PER_FEE_ASSET : decayed;
|
|
146
|
+
result.push(this.computeGasFees(state, excessMana, ethPerFeeAsset, state.l1FeesBySlot[i]));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private getAssumedManaUsed(state: FeeOracleState, manaUsage: ManaUsageEstimate): bigint {
|
|
153
|
+
switch (manaUsage) {
|
|
154
|
+
case ManaUsageEstimate.None:
|
|
155
|
+
return 0n;
|
|
156
|
+
case ManaUsageEstimate.Target:
|
|
157
|
+
return state.manaTarget;
|
|
158
|
+
case ManaUsageEstimate.Limit:
|
|
159
|
+
return state.manaLimit;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private computeGasFees(
|
|
164
|
+
state: FeeOracleState,
|
|
165
|
+
excessMana: bigint,
|
|
166
|
+
ethPerFeeAsset: bigint,
|
|
167
|
+
l1Fees: L1FeeData,
|
|
168
|
+
): GasFees {
|
|
169
|
+
return new GasFees(
|
|
170
|
+
0,
|
|
171
|
+
computeManaMinFee({
|
|
172
|
+
l1BaseFee: l1Fees.baseFee,
|
|
173
|
+
l1BlobFee: l1Fees.blobFee,
|
|
174
|
+
manaTarget: state.manaTarget,
|
|
175
|
+
epochDuration: state.epochDuration,
|
|
176
|
+
provingCostPerManaEth: state.provingCostPerManaEth,
|
|
177
|
+
excessMana,
|
|
178
|
+
ethPerFeeAsset,
|
|
179
|
+
}),
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
2
|
+
import type { ViemPublicClient } from '@aztec/ethereum/types';
|
|
3
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
5
|
+
import { getNextL1SlotTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
6
|
+
import { GasFees, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
7
|
+
import type { FeeProvider } from '@aztec/stdlib/tx';
|
|
8
|
+
|
|
9
|
+
import { FeePredictor } from './fee_predictor.js';
|
|
10
|
+
import type { GlobalVariableBuilderConfig } from './global_builder.js';
|
|
11
|
+
|
|
12
|
+
/** Provides current and predicted fee information based on on-chain state. */
|
|
13
|
+
export class FeeProviderImpl implements FeeProvider {
|
|
14
|
+
private currentMinFees: Promise<GasFees> = Promise.resolve(new GasFees(0, 0));
|
|
15
|
+
private currentL1BlockNumber: bigint | undefined = undefined;
|
|
16
|
+
|
|
17
|
+
private readonly rollupContract: RollupContract;
|
|
18
|
+
private readonly feePredictor: FeePredictor;
|
|
19
|
+
private readonly ethereumSlotDuration: number;
|
|
20
|
+
private readonly l1GenesisTime: bigint;
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
private readonly dateProvider: DateProvider,
|
|
24
|
+
private readonly publicClient: ViemPublicClient,
|
|
25
|
+
config: GlobalVariableBuilderConfig,
|
|
26
|
+
) {
|
|
27
|
+
this.ethereumSlotDuration = config.ethereumSlotDuration;
|
|
28
|
+
this.l1GenesisTime = config.l1GenesisTime;
|
|
29
|
+
|
|
30
|
+
this.rollupContract = new RollupContract(this.publicClient, config.rollupAddress);
|
|
31
|
+
this.feePredictor = new FeePredictor(this.rollupContract, this.publicClient, this.dateProvider, {
|
|
32
|
+
slotDuration: config.slotDuration,
|
|
33
|
+
l1GenesisTime: config.l1GenesisTime,
|
|
34
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Computes the "current" min fees, e.g., the price that you currently should pay to get include in the next block
|
|
40
|
+
* @returns Min fees for the next block
|
|
41
|
+
*/
|
|
42
|
+
private async computeCurrentMinFees(): Promise<GasFees> {
|
|
43
|
+
// Since this might be called in the middle of a slot where a block might have been published,
|
|
44
|
+
// we need to fetch the last block written, and estimate the earliest timestamp for the next block.
|
|
45
|
+
// The timestamp of that last block will act as a lower bound for the next block.
|
|
46
|
+
|
|
47
|
+
const lastCheckpoint = await this.rollupContract.getPendingCheckpoint();
|
|
48
|
+
const earliestTimestamp = await this.rollupContract.getTimestampForSlot(
|
|
49
|
+
SlotNumber.fromBigInt(BigInt(lastCheckpoint.slotNumber) + 1n),
|
|
50
|
+
);
|
|
51
|
+
const nextEthTimestamp = getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), {
|
|
52
|
+
l1GenesisTime: this.l1GenesisTime,
|
|
53
|
+
ethereumSlotDuration: this.ethereumSlotDuration,
|
|
54
|
+
});
|
|
55
|
+
const timestamp = earliestTimestamp > nextEthTimestamp ? earliestTimestamp : nextEthTimestamp;
|
|
56
|
+
|
|
57
|
+
return new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public async getCurrentMinFees(): Promise<GasFees> {
|
|
61
|
+
// Get the current block number
|
|
62
|
+
const blockNumber = await this.publicClient.getBlockNumber({ cacheTime: 0 });
|
|
63
|
+
|
|
64
|
+
// If the L1 block number has changed then chain a new promise to get the current min fees.
|
|
65
|
+
// We chain off the previous promise's settlement (via a swallowing catch) rather than its
|
|
66
|
+
// fulfillment, so a prior rejection does not short-circuit the new computation. If the new
|
|
67
|
+
// computation fails (e.g. a transient L1 RPC error), reset the cached block number so the
|
|
68
|
+
// next call recomputes instead of permanently replaying the rejected promise — otherwise a
|
|
69
|
+
// single transient failure would wedge fee estimation until the next L1 block arrives. Only
|
|
70
|
+
// clear it if it still points at the block this attempt was for, so a stale rejection from an
|
|
71
|
+
// older block cannot wipe a marker a newer call already advanced (which would also defeat the
|
|
72
|
+
// monotonic block-number guard).
|
|
73
|
+
if (this.currentL1BlockNumber === undefined || blockNumber > this.currentL1BlockNumber) {
|
|
74
|
+
this.currentL1BlockNumber = blockNumber;
|
|
75
|
+
this.currentMinFees = this.currentMinFees
|
|
76
|
+
.catch(() => undefined)
|
|
77
|
+
.then(() =>
|
|
78
|
+
this.computeCurrentMinFees().catch(err => {
|
|
79
|
+
if (this.currentL1BlockNumber === blockNumber) {
|
|
80
|
+
this.currentL1BlockNumber = undefined;
|
|
81
|
+
}
|
|
82
|
+
throw err;
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
return this.currentMinFees;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public async getPredictedMinFees(manaUsage?: ManaUsageEstimate): Promise<GasFees[]> {
|
|
90
|
+
const [currentMinFees, predictedMinFees] = await Promise.all([
|
|
91
|
+
this.getCurrentMinFees(),
|
|
92
|
+
this.feePredictor.getPredictedMinFees(manaUsage ?? ManaUsageEstimate.Target),
|
|
93
|
+
]);
|
|
94
|
+
|
|
95
|
+
return [currentMinFees, ...predictedMinFees];
|
|
96
|
+
}
|
|
97
|
+
}
|