Skip to content

Commit

Permalink
Added both block basefee and blob basefee to batch spending report
Browse files Browse the repository at this point in the history
  • Loading branch information
yahgwai committed Jan 18, 2024
1 parent 5d0dca2 commit 1e07937
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
20 changes: 12 additions & 8 deletions src/bridge/SequencerInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
afterDelayedMessagesRead
);

// we use addSequencerL2BatchImpl for submitting the message
// normally this would also submit a batch spending report but that is skipped if we pass
// an empty call data size, then we submit a separate batch spending report later
(
uint256 seqMessageIndex,
bytes32 beforeAcc,
Expand Down Expand Up @@ -453,11 +456,7 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox

// submit a batch spending report to refund the entity that produced the blob batch data
uint256 blobBasefee = blobBasefeeReader.getBlobBaseFee();

// TODO: This report the gas spending using the blob basefee, however the actual spending actually involve
// 2 parts: 1. data cost priced in blob basefee, 2. tx cost priced in block basefee
// We might need to change the batch spending report format so both costs are reported.
submitBatchSpendingReport(dataHash, seqMessageIndex, blobBasefee);
submitBatchSpendingReport(dataHash, seqMessageIndex, block.basefee, blobBasefee);
}

function addSequencerL2Batch(
Expand Down Expand Up @@ -625,7 +624,8 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
function submitBatchSpendingReport(
bytes32 dataHash,
uint256 seqMessageIndex,
uint256 gasPrice
uint256 gasPrice,
uint256 blobBaseFeePrice
) internal {
bytes memory spendingReportMsg;
address batchPoster = msg.sender;
Expand All @@ -646,12 +646,16 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
uint64(extraGas)
);
} else {
// when a blob base fee is supplied we include it into the batch spending report
spendingReportMsg = abi.encodePacked(
block.timestamp,
batchPoster,
dataHash,
seqMessageIndex,
gasPrice
gasPrice,
// we add an empty extraGas since the parsing code expects a value here
uint64(0),
blobBaseFeePrice
);
}

Expand Down Expand Up @@ -691,7 +695,7 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
totalDelayedMessagesRead = afterDelayedMessagesRead;

if (calldataLengthPosted > 0) {
submitBatchSpendingReport(dataHash, seqMessageIndex, block.basefee);
submitBatchSpendingReport(dataHash, seqMessageIndex, block.basefee, 0);
}
}

Expand Down
25 changes: 22 additions & 3 deletions test/contract/sequencerInbox.spec.4844.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,11 @@ describe('SequencerInbox', async () => {
const batchSendTx = await Toolkit4844.getTx(txHash)
const blobHashes = (batchSendTx as any)['blobVersionedHashes'] as string[]
const batchSendReceipt = await Toolkit4844.getTxReceipt(txHash)
const { timestamp: blockTimestamp, number: blockNumber } =
await wallet.provider.getBlock(batchSendReceipt.blockNumber)
const {
timestamp: blockTimestamp,
number: blockNumber,
baseFeePerGas,
} = await wallet.provider.getBlock(batchSendReceipt.blockNumber)

const timeBounds = await getTimeBounds(
blockNumber,
Expand Down Expand Up @@ -516,8 +519,12 @@ describe('SequencerInbox', async () => {
'0x' + inboxMsgDeliveredEvent.data.substring(106, 170)
const spendingSeqMessageIndex =
'0x' + inboxMsgDeliveredEvent.data.substring(170, 234)
const spendingBlobBasefee =
const spendingBlockBaseFee =
'0x' + inboxMsgDeliveredEvent.data.substring(234, 298)
const spendingExtraGas =
'0x' + inboxMsgDeliveredEvent.data.substring(298, 314)
const spendingBlobBasefee =
'0x' + inboxMsgDeliveredEvent.data.substring(314, 378)

expect(
BigNumber.from(spendingTimestamp).eq(blockTimestamp),
Expand All @@ -531,6 +538,18 @@ describe('SequencerInbox', async () => {
BigNumber.from(spendingSeqMessageIndex).eq(sequenceNumber),
'spending seq message index'
).to.eq(true)

if (baseFeePerGas == null) {
throw new Error('Missing base fee')
}
expect(
BigNumber.from(spendingBlockBaseFee).eq(baseFeePerGas),
`spending basefee: ${BigNumber.from(spendingBlockBaseFee).toString()}`
).to.eq(true)
expect(
BigNumber.from(spendingExtraGas).eq(0),
`spending extra gas: ${BigNumber.from(spendingExtraGas).toString()}`
).to.eq(true)
// we expect a very low - 1 - basefee since we havent sent many blobs
expect(
BigNumber.from(spendingBlobBasefee).eq(1),
Expand Down
4 changes: 3 additions & 1 deletion test/foundry/SequencerInbox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ contract SequencerInboxTest is Test {
msg.sender,
dataHash,
sequenceNumber,
block.basefee
block.basefee,
uint64(0),
uint256(0)
);
bytes32 beforeAcc = bytes32(0);
bytes32 delayedAcc = bridge.delayedInboxAccs(delayedMessagesRead - 1);
Expand Down

0 comments on commit 1e07937

Please sign in to comment.