@aztec/sequencer-client 0.0.1-commit.2448fdb → 0.0.1-commit.2606882
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 +4 -3
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +11 -11
- package/dest/config.d.ts +4 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +35 -14
- package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +128 -0
- package/dest/global_variable_builder/fee_provider.d.ts +21 -0
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_provider.js +58 -0
- package/dest/global_variable_builder/global_builder.d.ts +4 -10
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +5 -40
- package/dest/global_variable_builder/index.d.ts +3 -1
- 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 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/publisher/config.d.ts +19 -3
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +25 -5
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +2 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
- package/dest/publisher/sequencer-bundle-simulator.js +198 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +3 -5
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +16 -3
- package/dest/publisher/sequencer-publisher.d.ts +77 -66
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +410 -398
- package/dest/sequencer/automine/automine_factory.d.ts +54 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +84 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +151 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +509 -0
- package/dest/sequencer/chain_state_overrides.d.ts +61 -0
- package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
- package/dest/sequencer/chain_state_overrides.js +98 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +58 -10
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +736 -191
- 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/events.d.ts +48 -2
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/index.d.ts +3 -1
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +2 -0
- package/dest/sequencer/metrics.d.ts +13 -10
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +45 -20
- package/dest/sequencer/sequencer.d.ts +59 -12
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +344 -105
- package/dest/sequencer/timetable.d.ts +11 -1
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +41 -36
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +0 -2
- package/dest/test/utils.d.ts +1 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +7 -6
- package/package.json +27 -28
- package/src/client/sequencer-client.ts +19 -20
- package/src/config.ts +40 -11
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +172 -0
- package/src/global_variable_builder/fee_provider.ts +75 -0
- package/src/global_variable_builder/global_builder.ts +10 -46
- package/src/global_variable_builder/index.ts +2 -0
- package/src/index.ts +10 -1
- package/src/publisher/config.ts +49 -6
- package/src/publisher/index.ts +3 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-bundle-simulator.ts +254 -0
- package/src/publisher/sequencer-publisher-factory.ts +18 -6
- package/src/publisher/sequencer-publisher.ts +485 -474
- package/src/sequencer/README.md +162 -450
- package/src/sequencer/automine/README.md +46 -0
- package/src/sequencer/automine/automine_factory.ts +145 -0
- package/src/sequencer/automine/automine_sequencer.ts +595 -0
- package/src/sequencer/chain_state_overrides.ts +162 -0
- package/src/sequencer/checkpoint_proposal_job.ts +857 -201
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/events.ts +51 -2
- package/src/sequencer/index.ts +2 -0
- package/src/sequencer/metrics.ts +57 -24
- package/src/sequencer/sequencer.ts +421 -118
- package/src/sequencer/timetable.ts +49 -44
- package/src/sequencer/types.ts +1 -1
- package/src/test/mock_checkpoint_builder.ts +0 -2
- package/src/test/utils.ts +28 -10
package/dest/config.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { l1ContractsConfigMappings } from '@aztec/ethereum/config';
|
|
2
2
|
import { l1ReaderConfigMappings } from '@aztec/ethereum/l1-reader';
|
|
3
|
-
import { booleanConfigHelper, getConfigFromMappings, numberConfigHelper, pickConfigMappings } from '@aztec/foundation/config';
|
|
3
|
+
import { booleanConfigHelper, getConfigFromMappings, numberConfigHelper, optionalNumberConfigHelper, pickConfigMappings } from '@aztec/foundation/config';
|
|
4
4
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
5
|
import { keyStoreConfigMappings } from '@aztec/node-keystore/config';
|
|
6
6
|
import { p2pConfigMappings } from '@aztec/p2p/config';
|
|
7
7
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
|
-
import { chainConfigMappings, sharedSequencerConfigMappings } from '@aztec/stdlib/config';
|
|
8
|
+
import { DEFAULT_MAX_BLOCKS_PER_CHECKPOINT, chainConfigMappings, sharedSequencerConfigMappings } from '@aztec/stdlib/config';
|
|
9
9
|
import { DEFAULT_P2P_PROPAGATION_TIME } from '@aztec/stdlib/timetable';
|
|
10
10
|
import { validatorClientConfigMappings } from '@aztec/validator-client/config';
|
|
11
11
|
import { sequencerPublisherConfigMappings, sequencerTxSenderConfigMappings } from './publisher/config.js';
|
|
@@ -26,14 +26,17 @@ export * from './publisher/config.js';
|
|
|
26
26
|
secondsBeforeInvalidatingBlockAsNonCommitteeMember: 432,
|
|
27
27
|
skipCollectingAttestations: false,
|
|
28
28
|
skipInvalidateBlockAsProposer: false,
|
|
29
|
+
skipWaitForValidParentCheckpointOnL1: false,
|
|
29
30
|
broadcastInvalidBlockProposal: false,
|
|
31
|
+
broadcastInvalidCheckpointProposalOnly: false,
|
|
30
32
|
injectFakeAttestation: false,
|
|
31
33
|
injectHighSValueAttestation: false,
|
|
32
34
|
injectUnrecoverableSignatureAttestation: false,
|
|
33
35
|
fishermanMode: false,
|
|
34
36
|
shuffleAttestationOrdering: false,
|
|
35
37
|
skipPushProposedBlocksToArchiver: false,
|
|
36
|
-
skipPublishingCheckpointsPercent: 0
|
|
38
|
+
skipPublishingCheckpointsPercent: 0,
|
|
39
|
+
maxBlocksPerCheckpoint: DEFAULT_MAX_BLOCKS_PER_CHECKPOINT
|
|
37
40
|
};
|
|
38
41
|
export const sequencerConfigMappings = {
|
|
39
42
|
sequencerPollingIntervalMS: {
|
|
@@ -44,7 +47,7 @@ export const sequencerConfigMappings = {
|
|
|
44
47
|
maxTxsPerCheckpoint: {
|
|
45
48
|
env: 'SEQ_MAX_TX_PER_CHECKPOINT',
|
|
46
49
|
description: 'The maximum number of txs across all blocks in a checkpoint.',
|
|
47
|
-
|
|
50
|
+
...optionalNumberConfigHelper()
|
|
48
51
|
},
|
|
49
52
|
minTxsPerBlock: {
|
|
50
53
|
env: 'SEQ_MIN_TX_PER_BLOCK',
|
|
@@ -62,12 +65,12 @@ export const sequencerConfigMappings = {
|
|
|
62
65
|
maxL2BlockGas: {
|
|
63
66
|
env: 'SEQ_MAX_L2_BLOCK_GAS',
|
|
64
67
|
description: 'The maximum L2 block gas.',
|
|
65
|
-
|
|
68
|
+
...optionalNumberConfigHelper()
|
|
66
69
|
},
|
|
67
70
|
maxDABlockGas: {
|
|
68
71
|
env: 'SEQ_MAX_DA_BLOCK_GAS',
|
|
69
72
|
description: 'The maximum DA block gas.',
|
|
70
|
-
|
|
73
|
+
...optionalNumberConfigHelper()
|
|
71
74
|
},
|
|
72
75
|
perBlockAllocationMultiplier: {
|
|
73
76
|
env: 'SEQ_PER_BLOCK_ALLOCATION_MULTIPLIER',
|
|
@@ -81,7 +84,7 @@ export const sequencerConfigMappings = {
|
|
|
81
84
|
},
|
|
82
85
|
coinbase: {
|
|
83
86
|
env: 'COINBASE',
|
|
84
|
-
parseEnv: (val)=>
|
|
87
|
+
parseEnv: (val)=>EthAddress.fromString(val),
|
|
85
88
|
description: 'Recipient of block reward.'
|
|
86
89
|
},
|
|
87
90
|
feeRecipient: {
|
|
@@ -110,12 +113,7 @@ export const sequencerConfigMappings = {
|
|
|
110
113
|
l1PublishingTime: {
|
|
111
114
|
env: 'SEQ_L1_PUBLISHING_TIME_ALLOWANCE_IN_SLOT',
|
|
112
115
|
description: 'How much time (in seconds) we allow in the slot for publishing the L1 tx (defaults to 1 L1 slot).',
|
|
113
|
-
|
|
114
|
-
},
|
|
115
|
-
attestationPropagationTime: {
|
|
116
|
-
env: 'SEQ_ATTESTATION_PROPAGATION_TIME',
|
|
117
|
-
description: 'How many seconds it takes for proposals and attestations to travel across the p2p layer (one-way)',
|
|
118
|
-
...numberConfigHelper(DefaultSequencerConfig.attestationPropagationTime)
|
|
116
|
+
...optionalNumberConfigHelper()
|
|
119
117
|
},
|
|
120
118
|
fakeProcessingDelayPerTxMs: {
|
|
121
119
|
description: 'Used for testing to introduce a fake delay after processing each tx'
|
|
@@ -141,10 +139,22 @@ export const sequencerConfigMappings = {
|
|
|
141
139
|
description: 'Do not invalidate the previous block if invalid when we are the proposer (for testing only)',
|
|
142
140
|
...booleanConfigHelper(DefaultSequencerConfig.skipInvalidateBlockAsProposer)
|
|
143
141
|
},
|
|
142
|
+
skipWaitForValidParentCheckpointOnL1: {
|
|
143
|
+
description: 'Bypass the parent checkpoint validity check before submitting a pipelined checkpoint, ' + 'allowing the proposer to publish even when the parent landed on L1 with invalid attestations (for testing only)',
|
|
144
|
+
...booleanConfigHelper(DefaultSequencerConfig.skipWaitForValidParentCheckpointOnL1)
|
|
145
|
+
},
|
|
144
146
|
broadcastInvalidBlockProposal: {
|
|
145
147
|
description: 'Broadcast invalid block proposals with corrupted state (for testing only)',
|
|
146
148
|
...booleanConfigHelper(DefaultSequencerConfig.broadcastInvalidBlockProposal)
|
|
147
149
|
},
|
|
150
|
+
invalidBlockProposalIndexWithinCheckpoint: {
|
|
151
|
+
description: 'Broadcast an invalid block proposal only at this indexWithinCheckpoint (for testing only)',
|
|
152
|
+
...optionalNumberConfigHelper()
|
|
153
|
+
},
|
|
154
|
+
broadcastInvalidCheckpointProposalOnly: {
|
|
155
|
+
description: 'Broadcast invalid checkpoint proposals while keeping the underlying block proposals valid (for testing only). When unset, the checkpoint follows broadcastInvalidBlockProposal.',
|
|
156
|
+
...booleanConfigHelper(DefaultSequencerConfig.broadcastInvalidCheckpointProposalOnly)
|
|
157
|
+
},
|
|
148
158
|
injectFakeAttestation: {
|
|
149
159
|
description: 'Inject a fake attestation (for testing only)',
|
|
150
160
|
...booleanConfigHelper(DefaultSequencerConfig.injectFakeAttestation)
|
|
@@ -184,18 +194,29 @@ export const sequencerConfigMappings = {
|
|
|
184
194
|
description: 'Percent probability (0 - 100) of sequencer skipping checkpoint publishing (testing only)',
|
|
185
195
|
...numberConfigHelper(DefaultSequencerConfig.skipPublishingCheckpointsPercent)
|
|
186
196
|
},
|
|
197
|
+
skipBroadcastProposals: {
|
|
198
|
+
description: 'Skip broadcasting checkpoint and block proposals via gossipsub when proposer (for testing only)',
|
|
199
|
+
...booleanConfigHelper(false)
|
|
200
|
+
},
|
|
201
|
+
skipBroadcastCheckpointProposal: {
|
|
202
|
+
description: 'Skip broadcasting only the CheckpointProposal via gossipsub when proposer; the held last block is broadcast ' + 'standalone instead so peers still receive it as a proposed-but-uncheckpointed tip (for testing only)',
|
|
203
|
+
...booleanConfigHelper(false)
|
|
204
|
+
},
|
|
205
|
+
pauseProposingForSlots: {
|
|
206
|
+
description: 'List of slots for which the sequencer will not produce a proposal (for testing only). Attestation paths are unaffected.'
|
|
207
|
+
},
|
|
187
208
|
...pickConfigMappings(p2pConfigMappings, [
|
|
188
209
|
'txPublicSetupAllowListExtend'
|
|
189
210
|
])
|
|
190
211
|
};
|
|
191
212
|
export const sequencerClientConfigMappings = {
|
|
213
|
+
...chainConfigMappings,
|
|
192
214
|
...validatorClientConfigMappings,
|
|
193
215
|
...sequencerConfigMappings,
|
|
194
216
|
...keyStoreConfigMappings,
|
|
195
217
|
...l1ReaderConfigMappings,
|
|
196
218
|
...sequencerTxSenderConfigMappings,
|
|
197
219
|
...sequencerPublisherConfigMappings,
|
|
198
|
-
...chainConfigMappings,
|
|
199
220
|
...pickConfigMappings(l1ContractsConfigMappings, [
|
|
200
221
|
'ethereumSlotDuration',
|
|
201
222
|
'aztecSlotDuration',
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type RollupContract } from '@aztec/ethereum/contracts';
|
|
2
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
3
|
+
import { GasFees, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
4
|
+
/**
|
|
5
|
+
* Predicts min fees for LAG upcoming slots based on the L1 oracle state.
|
|
6
|
+
* A new oracle update can activate at startSlot + LAG, so only the first LAG entries
|
|
7
|
+
* are guaranteed stable. Caches L1 queries per L1 block and recomputes predictions
|
|
8
|
+
* for each mana usage estimate.
|
|
9
|
+
*/
|
|
10
|
+
export declare class FeePredictor {
|
|
11
|
+
private readonly rollupContract;
|
|
12
|
+
private readonly publicClient;
|
|
13
|
+
private readonly dateProvider;
|
|
14
|
+
private cachedState;
|
|
15
|
+
private cachedL1BlockNumber;
|
|
16
|
+
private readonly slotDuration;
|
|
17
|
+
private readonly l1GenesisTime;
|
|
18
|
+
private readonly ethereumSlotDuration;
|
|
19
|
+
constructor(rollupContract: RollupContract, publicClient: {
|
|
20
|
+
getBlockNumber: (opts?: {
|
|
21
|
+
cacheTime?: number;
|
|
22
|
+
}) => Promise<bigint>;
|
|
23
|
+
}, dateProvider: DateProvider, config: {
|
|
24
|
+
slotDuration: number;
|
|
25
|
+
l1GenesisTime: bigint;
|
|
26
|
+
ethereumSlotDuration: number;
|
|
27
|
+
});
|
|
28
|
+
/** Returns predicted min fees for each slot in the prediction window. */
|
|
29
|
+
getPredictedMinFees(manaUsage: ManaUsageEstimate): Promise<GasFees[]>;
|
|
30
|
+
private getState;
|
|
31
|
+
private fetchState;
|
|
32
|
+
/** Computes per-slot fee predictions given cached state and a mana usage assumption. */
|
|
33
|
+
private computePredictions;
|
|
34
|
+
private getAssumedManaUsed;
|
|
35
|
+
private computeGasFees;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmVlX3ByZWRpY3Rvci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2dsb2JhbF92YXJpYWJsZV9idWlsZGVyL2ZlZV9wcmVkaWN0b3IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFvRCxLQUFLLGNBQWMsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBR2xILE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBRTVELE9BQU8sRUFFTCxPQUFPLEVBRVAsaUJBQWlCLEVBR2xCLE1BQU0sbUJBQW1CLENBQUM7QUFlM0I7Ozs7O0dBS0c7QUFDSCxxQkFBYSxZQUFZO0lBU3JCLE9BQU8sQ0FBQyxRQUFRLENBQUMsY0FBYztJQUMvQixPQUFPLENBQUMsUUFBUSxDQUFDLFlBQVk7SUFDN0IsT0FBTyxDQUFDLFFBQVEsQ0FBQyxZQUFZO0lBVi9CLE9BQU8sQ0FBQyxXQUFXLENBQXNDO0lBQ3pELE9BQU8sQ0FBQyxtQkFBbUIsQ0FBcUI7SUFFaEQsT0FBTyxDQUFDLFFBQVEsQ0FBQyxZQUFZLENBQVM7SUFDdEMsT0FBTyxDQUFDLFFBQVEsQ0FBQy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Y;IAC7B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAV/B,OAAO,CAAC,WAAW,CAAsC;IACzD,OAAO,CAAC,mBAAmB,CAAqB;IAEhD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAS;IAE9C,YACmB,cAAc,EAAE,cAAc,EAC9B,YAAY,EAAE;QAAE,cAAc,EAAE,CAAC,IAAI,CAAC,EAAE;YAAE,SAAS,CAAC,EAAE,MAAM,CAAA;SAAE,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;KAAE,EACpF,YAAY,EAAE,YAAY,EAC3C,MAAM,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,oBAAoB,EAAE,MAAM,CAAA;KAAE,EAKtF;IAED,yEAAyE;IACnE,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAG1E;YAGa,QAAQ;YASR,UAAU;IAiDxB,wFAAwF;IACxF,OAAO,CAAC,kBAAkB;IAuB1B,OAAO,CAAC,kBAAkB;IAW1B,OAAO,CAAC,cAAc;CAmBvB"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { MAX_FEE_ASSET_PRICE_MODIFIER_BPS } from '@aztec/ethereum/contracts';
|
|
2
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { times } from '@aztec/foundation/collection';
|
|
4
|
+
import { getSlotAtNextL1Block, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
5
|
+
import { FEE_ORACLE_LAG, GasFees, MIN_ETH_PER_FEE_ASSET, ManaUsageEstimate, computeExcessMana, computeManaMinFee } from '@aztec/stdlib/gas';
|
|
6
|
+
/**
|
|
7
|
+
* Predicts min fees for LAG upcoming slots based on the L1 oracle state.
|
|
8
|
+
* A new oracle update can activate at startSlot + LAG, so only the first LAG entries
|
|
9
|
+
* are guaranteed stable. Caches L1 queries per L1 block and recomputes predictions
|
|
10
|
+
* for each mana usage estimate.
|
|
11
|
+
*/ export class FeePredictor {
|
|
12
|
+
rollupContract;
|
|
13
|
+
publicClient;
|
|
14
|
+
dateProvider;
|
|
15
|
+
cachedState;
|
|
16
|
+
cachedL1BlockNumber;
|
|
17
|
+
slotDuration;
|
|
18
|
+
l1GenesisTime;
|
|
19
|
+
ethereumSlotDuration;
|
|
20
|
+
constructor(rollupContract, publicClient, dateProvider, config){
|
|
21
|
+
this.rollupContract = rollupContract;
|
|
22
|
+
this.publicClient = publicClient;
|
|
23
|
+
this.dateProvider = dateProvider;
|
|
24
|
+
this.slotDuration = config.slotDuration;
|
|
25
|
+
this.l1GenesisTime = config.l1GenesisTime;
|
|
26
|
+
this.ethereumSlotDuration = config.ethereumSlotDuration;
|
|
27
|
+
}
|
|
28
|
+
/** Returns predicted min fees for each slot in the prediction window. */ async getPredictedMinFees(manaUsage) {
|
|
29
|
+
const state = await this.getState();
|
|
30
|
+
return this.computePredictions(state, manaUsage);
|
|
31
|
+
}
|
|
32
|
+
/** Fetches and caches rollup state. Refreshes when L1 block number advances. */ async getState() {
|
|
33
|
+
const blockNumber = await this.publicClient.getBlockNumber({
|
|
34
|
+
cacheTime: 0
|
|
35
|
+
});
|
|
36
|
+
if (this.cachedL1BlockNumber === undefined || blockNumber > this.cachedL1BlockNumber) {
|
|
37
|
+
this.cachedL1BlockNumber = blockNumber;
|
|
38
|
+
this.cachedState = this.fetchState(blockNumber);
|
|
39
|
+
}
|
|
40
|
+
return this.cachedState;
|
|
41
|
+
}
|
|
42
|
+
async fetchState(blockNumber) {
|
|
43
|
+
// Pin all non-constant queries to this L1 block number for a consistent snapshot.
|
|
44
|
+
const opts = {
|
|
45
|
+
blockNumber
|
|
46
|
+
};
|
|
47
|
+
// Cached constants don't need pinning
|
|
48
|
+
const [manaTarget, manaLimit, provingCostPerManaEth, epochDuration] = await Promise.all([
|
|
49
|
+
this.rollupContract.getManaTarget(),
|
|
50
|
+
this.rollupContract.getManaLimit(),
|
|
51
|
+
this.rollupContract.getProvingCostPerMana(),
|
|
52
|
+
this.rollupContract.getEpochDuration()
|
|
53
|
+
]);
|
|
54
|
+
// First, compute the earliest possible nextSlot independently of the checkpoint, so we can
|
|
55
|
+
// evaluate pruneability at the prediction start timestamp instead of the current L1 block time.
|
|
56
|
+
// This avoids an epoch-boundary edge case where the effective parent differs between now and nextSlot.
|
|
57
|
+
const slotConfig = {
|
|
58
|
+
slotDuration: this.slotDuration,
|
|
59
|
+
l1GenesisTime: this.l1GenesisTime
|
|
60
|
+
};
|
|
61
|
+
const currentSlot = await this.rollupContract.getSlotNumber(opts);
|
|
62
|
+
const slotAtNextL1Block = getSlotAtNextL1Block(BigInt(this.dateProvider.nowInSeconds()), {
|
|
63
|
+
l1GenesisTime: this.l1GenesisTime,
|
|
64
|
+
slotDuration: this.slotDuration,
|
|
65
|
+
ethereumSlotDuration: this.ethereumSlotDuration
|
|
66
|
+
});
|
|
67
|
+
const preliminaryNextSlot = SlotNumber(Math.max(currentSlot, slotAtNextL1Block));
|
|
68
|
+
const nextSlotTimestamp = getTimestampForSlot(preliminaryNextSlot, slotConfig);
|
|
69
|
+
// Resolve the effective checkpoint at the prediction start timestamp
|
|
70
|
+
const lastCheckpoint = await this.rollupContract.getEffectivePendingCheckpoint(nextSlotTimestamp, opts);
|
|
71
|
+
const lastSlot = lastCheckpoint.slotNumber;
|
|
72
|
+
// Refine nextSlot: also account for the slot after the last checkpoint
|
|
73
|
+
const nextSlot = SlotNumber(Math.max(SlotNumber.add(lastSlot, 1), preliminaryNextSlot));
|
|
74
|
+
const feeHeader = lastCheckpoint.feeHeader;
|
|
75
|
+
const slotCount = FEE_ORACLE_LAG;
|
|
76
|
+
const timestamps = times(slotCount, (i)=>getTimestampForSlot(SlotNumber.add(nextSlot, i), slotConfig));
|
|
77
|
+
const l1FeesBySlot = await Promise.all(timestamps.map((ts)=>this.rollupContract.getL1FeesAt(ts, opts)));
|
|
78
|
+
return {
|
|
79
|
+
lastSlot,
|
|
80
|
+
excessMana: computeExcessMana(feeHeader.excessMana, feeHeader.manaUsed, manaTarget),
|
|
81
|
+
ethPerFeeAsset: feeHeader.ethPerFeeAsset,
|
|
82
|
+
manaTarget,
|
|
83
|
+
manaLimit,
|
|
84
|
+
provingCostPerManaEth,
|
|
85
|
+
epochDuration: BigInt(epochDuration),
|
|
86
|
+
l1FeesBySlot
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** Computes per-slot fee predictions given cached state and a mana usage assumption. */ computePredictions(state, manaUsage) {
|
|
90
|
+
const assumedManaUsed = this.getAssumedManaUsed(state, manaUsage);
|
|
91
|
+
const result = [];
|
|
92
|
+
let { excessMana } = state;
|
|
93
|
+
let { ethPerFeeAsset } = state;
|
|
94
|
+
// Slot 0: current state (next available slot after last checkpoint)
|
|
95
|
+
result.push(this.computeGasFees(state, excessMana, ethPerFeeAsset, state.l1FeesBySlot[0]));
|
|
96
|
+
// Slots 1..LAG-1: advance excessMana with the assumed mana usage per checkpoint,
|
|
97
|
+
// and decay ethPerFeeAsset by MAX_FEE_ASSET_PRICE_MODIFIER_BPS per slot for conservative estimates.
|
|
98
|
+
// Lower ethPerFeeAsset means higher fees in fee asset terms.
|
|
99
|
+
for(let i = 1; i < state.l1FeesBySlot.length; i++){
|
|
100
|
+
excessMana = computeExcessMana(excessMana, assumedManaUsed, state.manaTarget);
|
|
101
|
+
const decayed = ethPerFeeAsset * (10000n - MAX_FEE_ASSET_PRICE_MODIFIER_BPS) / 10000n;
|
|
102
|
+
ethPerFeeAsset = decayed < MIN_ETH_PER_FEE_ASSET ? MIN_ETH_PER_FEE_ASSET : decayed;
|
|
103
|
+
result.push(this.computeGasFees(state, excessMana, ethPerFeeAsset, state.l1FeesBySlot[i]));
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
getAssumedManaUsed(state, manaUsage) {
|
|
108
|
+
switch(manaUsage){
|
|
109
|
+
case ManaUsageEstimate.None:
|
|
110
|
+
return 0n;
|
|
111
|
+
case ManaUsageEstimate.Target:
|
|
112
|
+
return state.manaTarget;
|
|
113
|
+
case ManaUsageEstimate.Limit:
|
|
114
|
+
return state.manaLimit;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
computeGasFees(state, excessMana, ethPerFeeAsset, l1Fees) {
|
|
118
|
+
return new GasFees(0, computeManaMinFee({
|
|
119
|
+
l1BaseFee: l1Fees.baseFee,
|
|
120
|
+
l1BlobFee: l1Fees.blobFee,
|
|
121
|
+
manaTarget: state.manaTarget,
|
|
122
|
+
epochDuration: state.epochDuration,
|
|
123
|
+
provingCostPerManaEth: state.provingCostPerManaEth,
|
|
124
|
+
excessMana,
|
|
125
|
+
ethPerFeeAsset
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ViemPublicClient } from '@aztec/ethereum/types';
|
|
2
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
3
|
+
import { GasFees, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
4
|
+
import type { FeeProvider } from '@aztec/stdlib/tx';
|
|
5
|
+
import type { GlobalVariableBuilderConfig } from './global_builder.js';
|
|
6
|
+
/** Provides current and predicted fee information based on on-chain state. */
|
|
7
|
+
export declare class FeeProviderImpl implements FeeProvider {
|
|
8
|
+
private readonly dateProvider;
|
|
9
|
+
private readonly publicClient;
|
|
10
|
+
private currentMinFees;
|
|
11
|
+
private currentL1BlockNumber;
|
|
12
|
+
private readonly rollupContract;
|
|
13
|
+
private readonly feePredictor;
|
|
14
|
+
private readonly ethereumSlotDuration;
|
|
15
|
+
private readonly l1GenesisTime;
|
|
16
|
+
constructor(dateProvider: DateProvider, publicClient: ViemPublicClient, config: GlobalVariableBuilderConfig);
|
|
17
|
+
private computeCurrentMinFees;
|
|
18
|
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B,EAWpC;YAMa,qBAAqB;IAkBtB,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC,CAUjD;IAEM,mBAAmB,CAAC,SAAS,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAE5E;CACF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
2
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { getNextL1SlotTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
4
|
+
import { GasFees, ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
5
|
+
import { FeePredictor } from './fee_predictor.js';
|
|
6
|
+
/** Provides current and predicted fee information based on on-chain state. */ export class FeeProviderImpl {
|
|
7
|
+
dateProvider;
|
|
8
|
+
publicClient;
|
|
9
|
+
currentMinFees;
|
|
10
|
+
currentL1BlockNumber;
|
|
11
|
+
rollupContract;
|
|
12
|
+
feePredictor;
|
|
13
|
+
ethereumSlotDuration;
|
|
14
|
+
l1GenesisTime;
|
|
15
|
+
constructor(dateProvider, publicClient, config){
|
|
16
|
+
this.dateProvider = dateProvider;
|
|
17
|
+
this.publicClient = publicClient;
|
|
18
|
+
this.currentMinFees = Promise.resolve(new GasFees(0, 0));
|
|
19
|
+
this.currentL1BlockNumber = undefined;
|
|
20
|
+
this.ethereumSlotDuration = config.ethereumSlotDuration;
|
|
21
|
+
this.l1GenesisTime = config.l1GenesisTime;
|
|
22
|
+
this.rollupContract = new RollupContract(this.publicClient, config.rollupAddress);
|
|
23
|
+
this.feePredictor = new FeePredictor(this.rollupContract, this.publicClient, this.dateProvider, {
|
|
24
|
+
slotDuration: config.slotDuration,
|
|
25
|
+
l1GenesisTime: config.l1GenesisTime,
|
|
26
|
+
ethereumSlotDuration: config.ethereumSlotDuration
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Computes the "current" min fees, e.g., the price that you currently should pay to get include in the next block
|
|
31
|
+
* @returns Min fees for the next block
|
|
32
|
+
*/ async computeCurrentMinFees() {
|
|
33
|
+
// Since this might be called in the middle of a slot where a block might have been published,
|
|
34
|
+
// we need to fetch the last block written, and estimate the earliest timestamp for the next block.
|
|
35
|
+
// The timestamp of that last block will act as a lower bound for the next block.
|
|
36
|
+
const lastCheckpoint = await this.rollupContract.getPendingCheckpoint();
|
|
37
|
+
const earliestTimestamp = await this.rollupContract.getTimestampForSlot(SlotNumber.fromBigInt(BigInt(lastCheckpoint.slotNumber) + 1n));
|
|
38
|
+
const nextEthTimestamp = getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), {
|
|
39
|
+
l1GenesisTime: this.l1GenesisTime,
|
|
40
|
+
ethereumSlotDuration: this.ethereumSlotDuration
|
|
41
|
+
});
|
|
42
|
+
const timestamp = earliestTimestamp > nextEthTimestamp ? earliestTimestamp : nextEthTimestamp;
|
|
43
|
+
return new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
|
|
44
|
+
}
|
|
45
|
+
async getCurrentMinFees() {
|
|
46
|
+
// Get the current block number
|
|
47
|
+
const blockNumber = await this.publicClient.getBlockNumber();
|
|
48
|
+
// If the L1 block number has changed then chain a new promise to get the current min fees
|
|
49
|
+
if (this.currentL1BlockNumber === undefined || blockNumber > this.currentL1BlockNumber) {
|
|
50
|
+
this.currentL1BlockNumber = blockNumber;
|
|
51
|
+
this.currentMinFees = this.currentMinFees.then(()=>this.computeCurrentMinFees());
|
|
52
|
+
}
|
|
53
|
+
return this.currentMinFees;
|
|
54
|
+
}
|
|
55
|
+
getPredictedMinFees(manaUsage) {
|
|
56
|
+
return this.feePredictor.getPredictedMinFees(manaUsage ?? ManaUsageEstimate.Target);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type SimulationOverridesPlan } from '@aztec/ethereum/contracts';
|
|
2
2
|
import type { ViemPublicClient } from '@aztec/ethereum/types';
|
|
3
3
|
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
4
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
5
|
import type { DateProvider } from '@aztec/foundation/timer';
|
|
6
6
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
7
|
import { type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
8
|
-
import { GasFees } from '@aztec/stdlib/gas';
|
|
9
8
|
import type { CheckpointGlobalVariables, GlobalVariableBuilder as GlobalVariableBuilderInterface } from '@aztec/stdlib/tx';
|
|
10
9
|
import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
11
10
|
/** Configuration for the GlobalVariableBuilder (excludes L1 client config). */
|
|
12
11
|
export type GlobalVariableBuilderConfig = {
|
|
13
|
-
|
|
12
|
+
rollupAddress: EthAddress;
|
|
14
13
|
ethereumSlotDuration: number;
|
|
15
14
|
rollupVersion: bigint;
|
|
16
15
|
} & Pick<L1RollupConstants, 'slotDuration' | 'l1GenesisTime'>;
|
|
@@ -20,9 +19,6 @@ export type GlobalVariableBuilderConfig = {
|
|
|
20
19
|
export declare class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
|
|
21
20
|
private readonly dateProvider;
|
|
22
21
|
private readonly publicClient;
|
|
23
|
-
private log;
|
|
24
|
-
private currentMinFees;
|
|
25
|
-
private currentL1BlockNumber;
|
|
26
22
|
private readonly rollupContract;
|
|
27
23
|
private readonly ethereumSlotDuration;
|
|
28
24
|
private readonly aztecSlotDuration;
|
|
@@ -30,8 +26,6 @@ export declare class GlobalVariableBuilder implements GlobalVariableBuilderInter
|
|
|
30
26
|
private chainId;
|
|
31
27
|
private version;
|
|
32
28
|
constructor(dateProvider: DateProvider, publicClient: ViemPublicClient, config: GlobalVariableBuilderConfig);
|
|
33
|
-
private computeCurrentMinFees;
|
|
34
|
-
getCurrentMinFees(): Promise<GasFees>;
|
|
35
29
|
/**
|
|
36
30
|
* Simple builder of global variables.
|
|
37
31
|
* @param blockNumber - The block number to build global variables for.
|
|
@@ -42,6 +36,6 @@ export declare class GlobalVariableBuilder implements GlobalVariableBuilderInter
|
|
|
42
36
|
*/
|
|
43
37
|
buildGlobalVariables(blockNumber: BlockNumber, coinbase: EthAddress, feeRecipient: AztecAddress, maybeSlot?: SlotNumber): Promise<GlobalVariables>;
|
|
44
38
|
/** Builds global variables that are constant throughout a checkpoint. */
|
|
45
|
-
buildCheckpointGlobalVariables(coinbase: EthAddress, feeRecipient: AztecAddress, slotNumber: SlotNumber): Promise<CheckpointGlobalVariables>;
|
|
39
|
+
buildCheckpointGlobalVariables(coinbase: EthAddress, feeRecipient: AztecAddress, slotNumber: SlotNumber, simulationOverridesPlan?: SimulationOverridesPlan): Promise<CheckpointGlobalVariables>;
|
|
46
40
|
}
|
|
47
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
41
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2xvYmFsX2J1aWxkZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9nbG9iYWxfdmFyaWFibGVfYnVpbGRlci9nbG9iYWxfYnVpbGRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBRUwsS0FBSyx1QkFBdUIsRUFFN0IsTUFBTSwyQkFBMkIsQ0FBQztBQUNuQyxPQUFPLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBQzlELE9BQU8sRUFBRSxXQUFXLEVBQUUsVUFBVSxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFFMUUsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDaEUsT0FBTyxLQUFLLEVBQUUsWUFBWSxFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFDNUQsT0FBTyxLQUFLLEVBQUUsWUF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LG9CQUFvQixDQUMvQixXQUFXLEVBQUUsV0FBVyxFQUN4QixRQUFRLEVBQUUsVUFBVSxFQUNwQixZQUFZLEVBQUUsWUFBWSxFQUMxQixTQUFTLENBQUMsRUFBRSxVQUFVLEdBQ3JCLE9BQU8sQ0FBQyxlQUFlLENBQUMsQ0FZMUI7SUFFRCx5RUFBeUU7SUFDNUQsOEJBQThCLENBQ3pDLFFBQVEsRUFBRSxVQUFVLEVBQ3BCLFlBQVksRUFBRSxZQUFZLEVBQzFCLFVBQVUsRUFBRSxVQUFVLEVBQ3RCLHVCQUF1QixDQUFDLEVBQUUsdUJBQXVCLEdBQ2hELE9BQU8sQ0FBQyx5QkFBeUIsQ0FBQyxDQVlwQztDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global_builder.d.ts","sourceRoot":"","sources":["../../src/global_variable_builder/global_builder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"global_builder.d.ts","sourceRoot":"","sources":["../../src/global_variable_builder/global_builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,uBAAuB,EAE7B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,KAAK,iBAAiB,EAA+C,MAAM,6BAA6B,CAAC;AAElH,OAAO,KAAK,EACV,yBAAyB,EACzB,qBAAqB,IAAI,8BAA8B,EACxD,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,+EAA+E;AAC/E,MAAM,MAAM,2BAA2B,GAAG;IACxC,aAAa,EAAE,UAAU,CAAC;IAC1B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,aAAa,EAAE,MAAM,CAAC;CACvB,GAAG,IAAI,CAAC,iBAAiB,EAAE,cAAc,GAAG,eAAe,CAAC,CAAC;AAE9D;;GAEG;AACH,qBAAa,qBAAsB,YAAW,8BAA8B;IAUxE,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAV/B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiB;IAChD,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAS;IAC9C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IAEvC,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,OAAO,CAAK;IAEpB,YACmB,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,gBAAgB,EAC/C,MAAM,EAAE,2BAA2B,EAUpC;IAED;;;;;;;OAOG;IACU,oBAAoB,CAC/B,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,UAAU,EACpB,YAAY,EAAE,YAAY,EAC1B,SAAS,CAAC,EAAE,UAAU,GACrB,OAAO,CAAC,eAAe,CAAC,CAY1B;IAED,yEAAyE;IAC5D,8BAA8B,CACzC,QAAQ,EAAE,UAAU,EACpB,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,UAAU,EACtB,uBAAuB,CAAC,EAAE,uBAAuB,GAChD,OAAO,CAAC,yBAAyB,CAAC,CAYpC;CACF"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
2
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
|
+
import { RollupContract, buildSimulationOverridesStateOverride } from '@aztec/ethereum/contracts';
|
|
3
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
5
3
|
import { getNextL1SlotTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
6
4
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
7
5
|
import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
@@ -10,9 +8,6 @@ import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
|
10
8
|
*/ export class GlobalVariableBuilder {
|
|
11
9
|
dateProvider;
|
|
12
10
|
publicClient;
|
|
13
|
-
log;
|
|
14
|
-
currentMinFees;
|
|
15
|
-
currentL1BlockNumber;
|
|
16
11
|
rollupContract;
|
|
17
12
|
ethereumSlotDuration;
|
|
18
13
|
aztecSlotDuration;
|
|
@@ -22,41 +17,12 @@ import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
|
22
17
|
constructor(dateProvider, publicClient, config){
|
|
23
18
|
this.dateProvider = dateProvider;
|
|
24
19
|
this.publicClient = publicClient;
|
|
25
|
-
this.log = createLogger('sequencer:global_variable_builder');
|
|
26
|
-
this.currentMinFees = Promise.resolve(new GasFees(0, 0));
|
|
27
|
-
this.currentL1BlockNumber = undefined;
|
|
28
20
|
this.version = new Fr(config.rollupVersion);
|
|
29
21
|
this.chainId = new Fr(this.publicClient.chain.id);
|
|
30
22
|
this.ethereumSlotDuration = config.ethereumSlotDuration;
|
|
31
23
|
this.aztecSlotDuration = config.slotDuration;
|
|
32
24
|
this.l1GenesisTime = config.l1GenesisTime;
|
|
33
|
-
this.rollupContract = new RollupContract(this.publicClient, config.
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Computes the "current" min fees, e.g., the price that you currently should pay to get include in the next block
|
|
37
|
-
* @returns Min fees for the next block
|
|
38
|
-
*/ async computeCurrentMinFees() {
|
|
39
|
-
// Since this might be called in the middle of a slot where a block might have been published,
|
|
40
|
-
// we need to fetch the last block written, and estimate the earliest timestamp for the next block.
|
|
41
|
-
// The timestamp of that last block will act as a lower bound for the next block.
|
|
42
|
-
const lastCheckpoint = await this.rollupContract.getPendingCheckpoint();
|
|
43
|
-
const earliestTimestamp = await this.rollupContract.getTimestampForSlot(SlotNumber.fromBigInt(BigInt(lastCheckpoint.slotNumber) + 1n));
|
|
44
|
-
const nextEthTimestamp = getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), {
|
|
45
|
-
l1GenesisTime: this.l1GenesisTime,
|
|
46
|
-
ethereumSlotDuration: this.ethereumSlotDuration
|
|
47
|
-
});
|
|
48
|
-
const timestamp = earliestTimestamp > nextEthTimestamp ? earliestTimestamp : nextEthTimestamp;
|
|
49
|
-
return new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
|
|
50
|
-
}
|
|
51
|
-
async getCurrentMinFees() {
|
|
52
|
-
// Get the current block number
|
|
53
|
-
const blockNumber = await this.publicClient.getBlockNumber();
|
|
54
|
-
// If the L1 block number has changed then chain a new promise to get the current min fees
|
|
55
|
-
if (this.currentL1BlockNumber === undefined || blockNumber > this.currentL1BlockNumber) {
|
|
56
|
-
this.currentL1BlockNumber = blockNumber;
|
|
57
|
-
this.currentMinFees = this.currentMinFees.then(()=>this.computeCurrentMinFees());
|
|
58
|
-
}
|
|
59
|
-
return this.currentMinFees;
|
|
25
|
+
this.rollupContract = new RollupContract(this.publicClient, config.rollupAddress);
|
|
60
26
|
}
|
|
61
27
|
/**
|
|
62
28
|
* Simple builder of global variables.
|
|
@@ -76,15 +42,14 @@ import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
|
76
42
|
...checkpointGlobalVariables
|
|
77
43
|
});
|
|
78
44
|
}
|
|
79
|
-
/** Builds global variables that are constant throughout a checkpoint. */ async buildCheckpointGlobalVariables(coinbase, feeRecipient, slotNumber) {
|
|
45
|
+
/** Builds global variables that are constant throughout a checkpoint. */ async buildCheckpointGlobalVariables(coinbase, feeRecipient, slotNumber, simulationOverridesPlan) {
|
|
80
46
|
const { chainId, version } = this;
|
|
81
47
|
const timestamp = getTimestampForSlot(slotNumber, {
|
|
82
48
|
slotDuration: this.aztecSlotDuration,
|
|
83
49
|
l1GenesisTime: this.l1GenesisTime
|
|
84
50
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const gasFees = new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
|
|
51
|
+
const stateOverride = await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan);
|
|
52
|
+
const gasFees = new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true, stateOverride));
|
|
88
53
|
return {
|
|
89
54
|
chainId,
|
|
90
55
|
version,
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
export { FeeProviderImpl } from './fee_provider.js';
|
|
1
2
|
export { GlobalVariableBuilder, type GlobalVariableBuilderConfig } from './global_builder.js';
|
|
2
|
-
|
|
3
|
+
export { FeePredictor } from './fee_predictor.js';
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9nbG9iYWxfdmFyaWFibGVfYnVpbGRlci9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsZUFBZSxFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFDcEQsT0FBTyxFQUFFLHFCQUFxQixFQUFFLEtBQUssMkJBQTJCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUM5RixPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sb0JBQW9CLENBQUMifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/global_variable_builder/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,KAAK,2BAA2B,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/global_variable_builder/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,KAAK,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dest/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './client/index.js';
|
|
2
2
|
export * from './config.js';
|
|
3
3
|
export * from './publisher/index.js';
|
|
4
|
-
export { Sequencer, SequencerState, type SequencerEvents } from './sequencer/index.js';
|
|
4
|
+
export { AutomineSequencer, type AutomineSequencerConstants, type AutomineSequencerDeps, createAutomineSequencer, type CreateAutomineSequencerArgs, Sequencer, SequencerState, type SequencerEvents, } from './sequencer/index.js';
|
|
5
5
|
export * from './global_variable_builder/index.js';
|
|
6
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
6
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLG1CQUFtQixDQUFDO0FBQ2xDLGNBQWMsYUFBYSxDQUFDO0FBQzVCLGNBQWMsc0JBQXNCLENBQUM7QUFDckMsT0FBTyxFQUNMLGlCQUFpQixFQUNqQixLQUFLLDBCQUEwQixFQUMvQixLQUFLLHFCQUFxQixFQUMxQix1QkFBdUIsRUFDdkIsS0FBSywyQkFBMkIsRUFDaEMsU0FBUyxFQUNULGNBQWMsRUFDZCxLQUFLLGVBQWUsR0FDckIsTUFBTSxzQkFBc0IsQ0FBQztBQUk5QixjQUFjLG9DQUFvQyxDQUFDIn0=
|
package/dest/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,OAAO,EACL,iBAAiB,EACjB,KAAK,0BAA0B,EAC/B,KAAK,qBAAqB,EAC1B,uBAAuB,EACvB,KAAK,2BAA2B,EAChC,SAAS,EACT,cAAc,EACd,KAAK,eAAe,GACrB,MAAM,sBAAsB,CAAC;AAI9B,cAAc,oCAAoC,CAAC"}
|
package/dest/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './client/index.js';
|
|
2
2
|
export * from './config.js';
|
|
3
3
|
export * from './publisher/index.js';
|
|
4
|
-
export { Sequencer, SequencerState } from './sequencer/index.js';
|
|
4
|
+
export { AutomineSequencer, createAutomineSequencer, Sequencer, SequencerState } from './sequencer/index.js';
|
|
5
5
|
// Used by the node to simulate public parts of transactions. Should these be moved to a shared library?
|
|
6
6
|
// ISSUE(#9832)
|
|
7
7
|
export * from './global_variable_builder/index.js';
|