@aztec/sequencer-client 0.0.1-commit.f504929 → 0.0.1-commit.f5a9928
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 +283 -21
- package/dest/client/sequencer-client.d.ts +23 -5
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +63 -36
- package/dest/config.d.ts +32 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +81 -31
- 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 +13 -26
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +9 -66
- 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/publisher/config.d.ts +19 -3
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +30 -5
- 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 +3 -4
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -1
- 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 +2 -3
- package/dest/publisher/sequencer-publisher.d.ts +91 -69
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +445 -535
- 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 +696 -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 +75 -19
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +831 -256
- 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 +1 -2
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_voter.js +2 -5
- package/dest/sequencer/errors.d.ts +1 -8
- package/dest/sequencer/errors.d.ts.map +1 -1
- package/dest/sequencer/errors.js +0 -9
- package/dest/sequencer/events.d.ts +62 -5
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/metrics.d.ts +14 -11
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +45 -20
- 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 +166 -39
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +616 -198
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- package/dest/test/index.d.ts +3 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +7 -9
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +39 -30
- package/dest/test/utils.d.ts +15 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +25 -7
- package/package.json +28 -28
- package/src/client/sequencer-client.ts +90 -45
- package/src/config.ts +98 -31
- 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 +19 -88
- package/src/global_variable_builder/index.ts +3 -1
- package/src/publisher/config.ts +62 -7
- package/src/publisher/l1_to_l2_messaging.ts +85 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +3 -1
- package/src/publisher/sequencer-bundle-simulator.ts +254 -0
- package/src/publisher/sequencer-publisher-factory.ts +3 -6
- package/src/publisher/sequencer-publisher.ts +510 -584
- package/src/publisher/write_json.ts +78 -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 +800 -0
- package/src/sequencer/automine/index.ts +6 -0
- package/src/sequencer/checkpoint_proposal_job.ts +993 -294
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +1 -12
- package/src/sequencer/errors.ts +0 -15
- package/src/sequencer/events.ts +66 -5
- package/src/sequencer/metrics.ts +63 -25
- package/src/sequencer/requests_tracker.ts +43 -0
- package/src/sequencer/sequencer.ts +720 -220
- package/src/sequencer/types.ts +1 -1
- package/src/test/index.ts +2 -2
- package/src/test/mock_checkpoint_builder.ts +51 -48
- package/src/test/utils.ts +61 -10
- package/dest/sequencer/timetable.d.ts +0 -87
- package/dest/sequencer/timetable.d.ts.map +0 -1
- package/dest/sequencer/timetable.js +0 -223
- package/src/sequencer/README.md +0 -531
- package/src/sequencer/timetable.ts +0 -283
|
@@ -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
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
RollupContract,
|
|
3
|
+
type SimulationOverridesPlan,
|
|
4
|
+
buildSimulationOverridesStateOverride,
|
|
5
|
+
} from '@aztec/ethereum/contracts';
|
|
5
6
|
import type { ViemPublicClient } from '@aztec/ethereum/types';
|
|
6
|
-
import {
|
|
7
|
+
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
7
8
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
8
9
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
9
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
10
10
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
11
11
|
import { type L1RollupConstants, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
12
12
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
@@ -14,21 +14,19 @@ import type {
|
|
|
14
14
|
CheckpointGlobalVariables,
|
|
15
15
|
GlobalVariableBuilder as GlobalVariableBuilderInterface,
|
|
16
16
|
} from '@aztec/stdlib/tx';
|
|
17
|
-
import { GlobalVariables } from '@aztec/stdlib/tx';
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
/** Configuration for the GlobalVariableBuilder (excludes L1 client config). */
|
|
19
|
+
export type GlobalVariableBuilderConfig = {
|
|
20
|
+
rollupAddress: EthAddress;
|
|
21
|
+
ethereumSlotDuration: number;
|
|
22
|
+
rollupVersion: bigint;
|
|
23
|
+
} & Pick<L1RollupConstants, 'slotDuration' | 'l1GenesisTime'>;
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
26
|
* Simple global variables builder.
|
|
23
27
|
*/
|
|
24
28
|
export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
|
|
25
|
-
private log = createLogger('sequencer:global_variable_builder');
|
|
26
|
-
private currentMinFees: Promise<GasFees> = Promise.resolve(new GasFees(0, 0));
|
|
27
|
-
private currentL1BlockNumber: bigint | undefined = undefined;
|
|
28
|
-
|
|
29
29
|
private readonly rollupContract: RollupContract;
|
|
30
|
-
private readonly publicClient: ViemPublicClient;
|
|
31
|
-
private readonly ethereumSlotDuration: number;
|
|
32
30
|
private readonly aztecSlotDuration: number;
|
|
33
31
|
private readonly l1GenesisTime: bigint;
|
|
34
32
|
|
|
@@ -36,83 +34,16 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
|
|
|
36
34
|
private version: Fr;
|
|
37
35
|
|
|
38
36
|
constructor(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
Pick<L1RollupConstants, 'slotDuration' | 'l1GenesisTime'> & { rollupVersion: bigint },
|
|
37
|
+
private readonly publicClient: ViemPublicClient,
|
|
38
|
+
config: GlobalVariableBuilderConfig,
|
|
42
39
|
) {
|
|
43
|
-
const { l1RpcUrls, l1ChainId: chainId, l1Contracts } = config;
|
|
44
|
-
|
|
45
|
-
const chain = createEthereumChain(l1RpcUrls, chainId);
|
|
46
|
-
|
|
47
40
|
this.version = new Fr(config.rollupVersion);
|
|
48
|
-
this.chainId = new Fr(
|
|
41
|
+
this.chainId = new Fr(this.publicClient.chain!.id);
|
|
49
42
|
|
|
50
|
-
this.ethereumSlotDuration = config.ethereumSlotDuration;
|
|
51
43
|
this.aztecSlotDuration = config.slotDuration;
|
|
52
44
|
this.l1GenesisTime = config.l1GenesisTime;
|
|
53
45
|
|
|
54
|
-
this.
|
|
55
|
-
chain: chain.chainInfo,
|
|
56
|
-
transport: fallback(chain.rpcUrls.map(url => http(url, { batch: false }))),
|
|
57
|
-
pollingInterval: config.viemPollingIntervalMS,
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
this.rollupContract = new RollupContract(this.publicClient, l1Contracts.rollupAddress);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Computes the "current" min fees, e.g., the price that you currently should pay to get include in the next block
|
|
65
|
-
* @returns Min fees for the next block
|
|
66
|
-
*/
|
|
67
|
-
private async computeCurrentMinFees(): Promise<GasFees> {
|
|
68
|
-
// Since this might be called in the middle of a slot where a block might have been published,
|
|
69
|
-
// we need to fetch the last block written, and estimate the earliest timestamp for the next block.
|
|
70
|
-
// The timestamp of that last block will act as a lower bound for the next block.
|
|
71
|
-
|
|
72
|
-
const lastCheckpoint = await this.rollupContract.getPendingCheckpoint();
|
|
73
|
-
const earliestTimestamp = await this.rollupContract.getTimestampForSlot(
|
|
74
|
-
SlotNumber.fromBigInt(BigInt(lastCheckpoint.slotNumber) + 1n),
|
|
75
|
-
);
|
|
76
|
-
const nextEthTimestamp = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration));
|
|
77
|
-
const timestamp = earliestTimestamp > nextEthTimestamp ? earliestTimestamp : nextEthTimestamp;
|
|
78
|
-
|
|
79
|
-
return new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public async getCurrentMinFees(): Promise<GasFees> {
|
|
83
|
-
// Get the current block number
|
|
84
|
-
const blockNumber = await this.publicClient.getBlockNumber();
|
|
85
|
-
|
|
86
|
-
// If the L1 block number has changed then chain a new promise to get the current min fees
|
|
87
|
-
if (this.currentL1BlockNumber === undefined || blockNumber > this.currentL1BlockNumber) {
|
|
88
|
-
this.currentL1BlockNumber = blockNumber;
|
|
89
|
-
this.currentMinFees = this.currentMinFees.then(() => this.computeCurrentMinFees());
|
|
90
|
-
}
|
|
91
|
-
return this.currentMinFees;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Simple builder of global variables.
|
|
96
|
-
* @param blockNumber - The block number to build global variables for.
|
|
97
|
-
* @param coinbase - The address to receive block reward.
|
|
98
|
-
* @param feeRecipient - The address to receive fees.
|
|
99
|
-
* @param slotNumber - The slot number to use for the global variables, if undefined it will be calculated.
|
|
100
|
-
* @returns The global variables for the given block number.
|
|
101
|
-
*/
|
|
102
|
-
public async buildGlobalVariables(
|
|
103
|
-
blockNumber: BlockNumber,
|
|
104
|
-
coinbase: EthAddress,
|
|
105
|
-
feeRecipient: AztecAddress,
|
|
106
|
-
maybeSlot?: SlotNumber,
|
|
107
|
-
): Promise<GlobalVariables> {
|
|
108
|
-
const slot: SlotNumber =
|
|
109
|
-
maybeSlot ??
|
|
110
|
-
(await this.rollupContract.getSlotAt(
|
|
111
|
-
BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration)),
|
|
112
|
-
));
|
|
113
|
-
|
|
114
|
-
const checkpointGlobalVariables = await this.buildCheckpointGlobalVariables(coinbase, feeRecipient, slot);
|
|
115
|
-
return GlobalVariables.from({ blockNumber, ...checkpointGlobalVariables });
|
|
46
|
+
this.rollupContract = new RollupContract(this.publicClient, config.rollupAddress);
|
|
116
47
|
}
|
|
117
48
|
|
|
118
49
|
/** Builds global variables that are constant throughout a checkpoint. */
|
|
@@ -120,6 +51,7 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
|
|
|
120
51
|
coinbase: EthAddress,
|
|
121
52
|
feeRecipient: AztecAddress,
|
|
122
53
|
slotNumber: SlotNumber,
|
|
54
|
+
simulationOverridesPlan?: SimulationOverridesPlan,
|
|
123
55
|
): Promise<CheckpointGlobalVariables> {
|
|
124
56
|
const { chainId, version } = this;
|
|
125
57
|
|
|
@@ -128,9 +60,8 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
|
|
|
128
60
|
l1GenesisTime: this.l1GenesisTime,
|
|
129
61
|
});
|
|
130
62
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const gasFees = new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true));
|
|
63
|
+
const stateOverride = await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan);
|
|
64
|
+
const gasFees = new GasFees(0, await this.rollupContract.getManaMinFeeAt(timestamp, true, stateOverride));
|
|
134
65
|
|
|
135
66
|
return { chainId, version, slotNumber, timestamp, coinbase, feeRecipient, gasFees };
|
|
136
67
|
}
|
package/src/publisher/config.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { type BlobClientConfig, blobClientConfigMapping } from '@aztec/blob-client/client/config';
|
|
2
2
|
import { type L1ReaderConfig, l1ReaderConfigMappings } from '@aztec/ethereum/l1-reader';
|
|
3
3
|
import { type L1TxUtilsConfig, l1TxUtilsConfigMappings } from '@aztec/ethereum/l1-tx-utils/config';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
type ConfigMappingsType,
|
|
6
|
+
SecretValue,
|
|
7
|
+
booleanConfigHelper,
|
|
8
|
+
numberConfigHelper,
|
|
9
|
+
} from '@aztec/foundation/config';
|
|
5
10
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
11
|
|
|
12
|
+
import { parseEther } from 'viem';
|
|
13
|
+
|
|
7
14
|
/** Configuration of the transaction publisher. */
|
|
8
15
|
export type TxSenderConfig = L1ReaderConfig & {
|
|
9
16
|
/** The private key to be used by the publisher. */
|
|
@@ -50,13 +57,37 @@ export type PublisherConfig = L1TxUtilsConfig &
|
|
|
50
57
|
publisherForwarderAddress?: EthAddress;
|
|
51
58
|
/** Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path */
|
|
52
59
|
l1TxFailedStore?: string;
|
|
60
|
+
/** Min ETH balance below which a publisher gets funded. Undefined = funding disabled. */
|
|
61
|
+
publisherFundingThreshold?: bigint;
|
|
62
|
+
/** Amount of ETH to send when funding a publisher. Undefined = funding disabled. */
|
|
63
|
+
publisherFundingAmount?: bigint;
|
|
53
64
|
};
|
|
54
65
|
|
|
66
|
+
/** Shared config mappings for publisher funding, used by both sequencer and prover publisher configs. */
|
|
67
|
+
const publisherFundingConfigMappings = {
|
|
68
|
+
publisherFundingThreshold: {
|
|
69
|
+
env: 'PUBLISHER_FUNDING_THRESHOLD' as const,
|
|
70
|
+
description:
|
|
71
|
+
'Min ETH balance below which a publisher gets funded. Specified in ether (e.g. 0.1). Unset = funding disabled.',
|
|
72
|
+
parseEnv: (val: string) => parseEther(val),
|
|
73
|
+
},
|
|
74
|
+
publisherFundingAmount: {
|
|
75
|
+
env: 'PUBLISHER_FUNDING_AMOUNT' as const,
|
|
76
|
+
description:
|
|
77
|
+
'Amount of ETH to send when funding a publisher. Specified in ether (e.g. 0.5). Unset = funding disabled.',
|
|
78
|
+
parseEnv: (val: string) => parseEther(val),
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
55
82
|
export type ProverPublisherConfig = L1TxUtilsConfig &
|
|
56
83
|
BlobClientConfig & {
|
|
57
84
|
fishermanMode?: boolean;
|
|
58
85
|
proverPublisherAllowInvalidStates?: boolean;
|
|
59
86
|
proverPublisherForwarderAddress?: EthAddress;
|
|
87
|
+
/** Min ETH balance below which a publisher gets funded. Undefined = funding disabled. */
|
|
88
|
+
publisherFundingThreshold?: bigint;
|
|
89
|
+
/** Amount of ETH to send when funding a publisher. Undefined = funding disabled. */
|
|
90
|
+
publisherFundingAmount?: bigint;
|
|
60
91
|
};
|
|
61
92
|
|
|
62
93
|
export type SequencerPublisherConfig = L1TxUtilsConfig &
|
|
@@ -64,8 +95,16 @@ export type SequencerPublisherConfig = L1TxUtilsConfig &
|
|
|
64
95
|
fishermanMode?: boolean;
|
|
65
96
|
sequencerPublisherAllowInvalidStates?: boolean;
|
|
66
97
|
sequencerPublisherForwarderAddress?: EthAddress;
|
|
98
|
+
/** How long to wait for the previous L1 block before sending scheduled publisher txs anyway. */
|
|
99
|
+
sequencerPublisherPreviousL1BlockWaitTimeoutMs: number;
|
|
100
|
+
/** Poll interval while waiting for the previous L1 block before scheduled publisher txs. */
|
|
101
|
+
sequencerPublisherPreviousL1BlockWaitPollIntervalMs: number;
|
|
67
102
|
/** Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path */
|
|
68
103
|
l1TxFailedStore?: string;
|
|
104
|
+
/** Min ETH balance below which a publisher gets funded. Undefined = funding disabled. */
|
|
105
|
+
publisherFundingThreshold?: bigint;
|
|
106
|
+
/** Amount of ETH to send when funding a publisher. Undefined = funding disabled. */
|
|
107
|
+
publisherFundingAmount?: bigint;
|
|
69
108
|
};
|
|
70
109
|
|
|
71
110
|
export function getPublisherConfigFromProverConfig(config: ProverPublisherConfig): PublisherConfig {
|
|
@@ -85,12 +124,13 @@ export function getPublisherConfigFromSequencerConfig(config: SequencerPublisher
|
|
|
85
124
|
};
|
|
86
125
|
}
|
|
87
126
|
|
|
88
|
-
export const proverTxSenderConfigMappings: ConfigMappingsType<
|
|
127
|
+
export const proverTxSenderConfigMappings: ConfigMappingsType<ProverTxSenderConfig> = {
|
|
89
128
|
...l1ReaderConfigMappings,
|
|
90
129
|
proverPublisherPrivateKeys: {
|
|
91
130
|
env: `PROVER_PUBLISHER_PRIVATE_KEYS`,
|
|
92
131
|
description: 'The private keys to be used by the prover publisher.',
|
|
93
|
-
parseEnv: (val: string) =>
|
|
132
|
+
parseEnv: (val: string) =>
|
|
133
|
+
val.split(',').map(key => new SecretValue(`0x${key.replace('0x', '')}` as `0x${string}`)),
|
|
94
134
|
defaultValue: [],
|
|
95
135
|
fallback: [`PROVER_PUBLISHER_PRIVATE_KEY`],
|
|
96
136
|
},
|
|
@@ -102,12 +142,13 @@ export const proverTxSenderConfigMappings: ConfigMappingsType<Omit<ProverTxSende
|
|
|
102
142
|
},
|
|
103
143
|
};
|
|
104
144
|
|
|
105
|
-
export const sequencerTxSenderConfigMappings: ConfigMappingsType<
|
|
145
|
+
export const sequencerTxSenderConfigMappings: ConfigMappingsType<SequencerTxSenderConfig> = {
|
|
106
146
|
...l1ReaderConfigMappings,
|
|
107
147
|
sequencerPublisherPrivateKeys: {
|
|
108
148
|
env: `SEQ_PUBLISHER_PRIVATE_KEYS`,
|
|
109
149
|
description: 'The private keys to be used by the sequencer publisher.',
|
|
110
|
-
parseEnv: (val: string) =>
|
|
150
|
+
parseEnv: (val: string) =>
|
|
151
|
+
val.split(',').map(key => new SecretValue(`0x${key.replace('0x', '')}` as `0x${string}`)),
|
|
111
152
|
defaultValue: [],
|
|
112
153
|
fallback: [`SEQ_PUBLISHER_PRIVATE_KEY`],
|
|
113
154
|
},
|
|
@@ -136,12 +177,25 @@ export const sequencerPublisherConfigMappings: ConfigMappingsType<SequencerPubli
|
|
|
136
177
|
sequencerPublisherForwarderAddress: {
|
|
137
178
|
env: `SEQ_PUBLISHER_FORWARDER_ADDRESS`,
|
|
138
179
|
description: 'Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only)',
|
|
139
|
-
parseEnv: (val: string) =>
|
|
180
|
+
parseEnv: (val: string) => EthAddress.fromString(val),
|
|
181
|
+
},
|
|
182
|
+
sequencerPublisherPreviousL1BlockWaitTimeoutMs: {
|
|
183
|
+
env: `SEQ_PUBLISHER_PREVIOUS_L1_BLOCK_WAIT_TIMEOUT_MS`,
|
|
184
|
+
description:
|
|
185
|
+
'How long to wait for the previous L1 block before sending scheduled publisher txs anyway, in milliseconds.',
|
|
186
|
+
...numberConfigHelper(8_000),
|
|
187
|
+
},
|
|
188
|
+
sequencerPublisherPreviousL1BlockWaitPollIntervalMs: {
|
|
189
|
+
env: `SEQ_PUBLISHER_PREVIOUS_L1_BLOCK_WAIT_POLL_INTERVAL_MS`,
|
|
190
|
+
description:
|
|
191
|
+
'Poll interval while waiting for the previous L1 block before scheduled publisher txs, in milliseconds.',
|
|
192
|
+
...numberConfigHelper(500),
|
|
140
193
|
},
|
|
141
194
|
l1TxFailedStore: {
|
|
142
195
|
env: 'L1_TX_FAILED_STORE',
|
|
143
196
|
description: 'Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path',
|
|
144
197
|
},
|
|
198
|
+
...publisherFundingConfigMappings,
|
|
145
199
|
};
|
|
146
200
|
|
|
147
201
|
export const proverPublisherConfigMappings: ConfigMappingsType<ProverPublisherConfig & L1TxUtilsConfig> = {
|
|
@@ -161,6 +215,7 @@ export const proverPublisherConfigMappings: ConfigMappingsType<ProverPublisherCo
|
|
|
161
215
|
proverPublisherForwarderAddress: {
|
|
162
216
|
env: `PROVER_PUBLISHER_FORWARDER_ADDRESS`,
|
|
163
217
|
description: 'Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only)',
|
|
164
|
-
parseEnv: (val: string) =>
|
|
218
|
+
parseEnv: (val: string) => EthAddress.fromString(val),
|
|
165
219
|
},
|
|
220
|
+
...publisherFundingConfigMappings,
|
|
166
221
|
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
2
|
+
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
3
|
+
import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
|
+
import { tryJsonStringify } from '@aztec/foundation/json-rpc';
|
|
6
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
7
|
+
import { InboxAbi } from '@aztec/l1-artifacts';
|
|
8
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
9
|
+
|
|
10
|
+
import { decodeEventLog, getContract } from 'viem';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Sends an L1-to-L2 message via the Inbox contract and returns its hash and global leaf index.
|
|
14
|
+
* Test helper copied from the end-to-end fixtures so this integration test can live in sequencer-client.
|
|
15
|
+
*/
|
|
16
|
+
export async function sendL1ToL2Message(
|
|
17
|
+
message: { recipient: AztecAddress; content: Fr; secretHash: Fr },
|
|
18
|
+
ctx: {
|
|
19
|
+
l1Client: ExtendedViemWalletClient;
|
|
20
|
+
l1ContractAddresses: Pick<L1ContractAddresses, 'inboxAddress' | 'rollupAddress'>;
|
|
21
|
+
},
|
|
22
|
+
) {
|
|
23
|
+
const logger = createLogger('sequencer-client:l1_to_l2_messaging');
|
|
24
|
+
const inbox = getContract({
|
|
25
|
+
address: ctx.l1ContractAddresses.inboxAddress.toString(),
|
|
26
|
+
abi: InboxAbi,
|
|
27
|
+
client: ctx.l1Client,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const { recipient, content, secretHash } = message;
|
|
31
|
+
|
|
32
|
+
const version = await new RollupContract(ctx.l1Client, ctx.l1ContractAddresses.rollupAddress.toString()).getVersion();
|
|
33
|
+
|
|
34
|
+
// We inject the message to Inbox
|
|
35
|
+
const txHash = await inbox.write.sendL2Message(
|
|
36
|
+
[{ actor: recipient.toString(), version: BigInt(version) }, content.toString(), secretHash.toString()],
|
|
37
|
+
{
|
|
38
|
+
gas: 1_000_000n,
|
|
39
|
+
},
|
|
40
|
+
);
|
|
41
|
+
logger.info(`L1 to L2 message sent in tx ${txHash}`);
|
|
42
|
+
|
|
43
|
+
// We check that the message was correctly injected by checking the emitted event
|
|
44
|
+
const txReceipt = await ctx.l1Client.waitForTransactionReceipt({ hash: txHash });
|
|
45
|
+
|
|
46
|
+
if (txReceipt.status !== 'success') {
|
|
47
|
+
throw new Error(`L1 to L2 message failed to be sent in tx ${txHash}. Status: ${txReceipt.status}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
logger.info(`L1 to L2 message receipt retrieved for tx ${txReceipt.transactionHash}`, txReceipt);
|
|
51
|
+
|
|
52
|
+
if (txReceipt.transactionHash !== txHash) {
|
|
53
|
+
throw new Error(`Receipt transaction hash mismatch: ${txReceipt.transactionHash} !== ${txHash}`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Filter for MessageSent events from the Inbox contract by trying to decode each log
|
|
57
|
+
const messageSentLogs = txReceipt.logs
|
|
58
|
+
.filter(log => log.address.toLowerCase() === ctx.l1ContractAddresses.inboxAddress.toString().toLowerCase())
|
|
59
|
+
.map(log => {
|
|
60
|
+
try {
|
|
61
|
+
const decoded = decodeEventLog({
|
|
62
|
+
abi: InboxAbi,
|
|
63
|
+
data: log.data,
|
|
64
|
+
topics: log.topics,
|
|
65
|
+
});
|
|
66
|
+
return { log, decoded };
|
|
67
|
+
} catch {
|
|
68
|
+
return null; // Not a decodable event from this ABI
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
.filter((item): item is { log: any; decoded: any } => item !== null && item.decoded.eventName === 'MessageSent');
|
|
72
|
+
|
|
73
|
+
if (messageSentLogs.length !== 1) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
`Wrong number of MessageSent logs found in ${txHash} transaction (got ${messageSentLogs.length} expected 1)\n${tryJsonStringify(messageSentLogs.map(item => item.log))}`,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// We already have the decoded event
|
|
80
|
+
const topics = messageSentLogs[0].decoded;
|
|
81
|
+
const receivedMsgHash = topics.args.hash;
|
|
82
|
+
const receivedGlobalLeafIndex = topics.args.index;
|
|
83
|
+
|
|
84
|
+
return { msgHash: Fr.fromHexString(receivedMsgHash), globalLeafIndex: new Fr(receivedGlobalLeafIndex), txReceipt };
|
|
85
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import type { Branded } from '@aztec/foundation/branded-types';
|
|
2
|
+
|
|
1
3
|
import type { Hex } from 'viem';
|
|
2
4
|
|
|
3
5
|
/** URI pointing to a stored failed L1 transaction. */
|
|
4
|
-
export type FailedL1TxUri = string
|
|
6
|
+
export type FailedL1TxUri = Branded<string, 'FailedL1TxUri'>;
|
|
5
7
|
|
|
6
8
|
/** A failed L1 transaction captured for debugging and replay. */
|
|
7
9
|
export type FailedL1Tx = {
|