diff --git a/l1-contracts/test/fees/FeeRollup.t.sol b/l1-contracts/test/fees/FeeRollup.t.sol index adbc27994a5..7f131fb9da5 100644 --- a/l1-contracts/test/fees/FeeRollup.t.sol +++ b/l1-contracts/test/fees/FeeRollup.t.sol @@ -299,8 +299,6 @@ contract FeeRollupTest is FeeModelTestPoints, DecoderBase { Slot nextSlot = Slot.wrap(1); Epoch nextEpoch = Epoch.wrap(1); - // We need the fee at the time just before the first slot - // Loop through all of the L1 metadata for (uint256 i = 0; i < l1Metadata.length; i++) { // Predict what the fee will be before we jump in time! diff --git a/yarn-project/sequencer-client/src/global_variable_builder/global_builder.ts b/yarn-project/sequencer-client/src/global_variable_builder/global_builder.ts index 5cb86742980..ecd911cc97f 100644 --- a/yarn-project/sequencer-client/src/global_variable_builder/global_builder.ts +++ b/yarn-project/sequencer-client/src/global_variable_builder/global_builder.ts @@ -51,7 +51,15 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface { * @returns Base fees for the expected next block */ public async getCurrentBaseFees(): Promise { - const timestamp = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration)); + // Since this might be called in the middle of a slot where a block might have been published, + // we need to fetch the last block written, and estimate the earliest timestamp for the next block. + // The timestamp of that last block will act as a lower bound for the next block. + + const lastBlock = await this.rollupContract.read.getBlock([await this.rollupContract.read.getPendingBlockNumber()]); + const earliestTimestamp = await this.rollupContract.read.getTimestampForSlot([lastBlock.slotNumber + 1n]); + const nextEthTimestamp = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(this.ethereumSlotDuration)); + const timestamp = earliestTimestamp > nextEthTimestamp ? earliestTimestamp : nextEthTimestamp; + return new GasFees(Fr.ZERO, new Fr(await this.rollupContract.read.getManaBaseFeeAt([timestamp, true]))); } @@ -82,6 +90,7 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface { const slotFr = new Fr(slotNumber); const timestampFr = new Fr(timestamp); + // We can skip much of the logic in getCurrentBaseFees since it we already check that we are not within a slot elsewhere. const gasFees = new GasFees(Fr.ZERO, new Fr(await this.rollupContract.read.getManaBaseFeeAt([timestamp, true]))); const globalVariables = new GlobalVariables(