Skip to content

Commit

Permalink
Merge pull request #1701 from OffchainLabs/batch-report-extra-gas
Browse files Browse the repository at this point in the history
Parse new BatchPostingReport field extraGas
  • Loading branch information
PlasmaPower committed Jun 23, 2023
2 parents 7c6240e + 1e6032e commit e6b4b74
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
27 changes: 18 additions & 9 deletions arbos/arbostypes/incomingmessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (msg *L1IncomingMessage) FillInBatchGasCost(batchFetcher FallibleBatchFetch
if batchFetcher == nil || msg.Header.Kind != L1MessageType_BatchPostingReport || msg.BatchGasCost != nil {
return nil
}
_, _, batchHash, batchNum, _, err := ParseBatchPostingReportMessageFields(bytes.NewReader(msg.L2msg))
_, _, batchHash, batchNum, _, _, err := ParseBatchPostingReportMessageFields(bytes.NewReader(msg.L2msg))
if err != nil {
return fmt.Errorf("failed to parse batch posting report: %w", err)
}
Expand Down Expand Up @@ -290,30 +290,39 @@ func (msg *L1IncomingMessage) ParseInitMessage() (*ParsedInitMessage, error) {
return nil, fmt.Errorf("invalid init message data %v", string(msg.L2msg))
}

func ParseBatchPostingReportMessageFields(rd io.Reader) (*big.Int, common.Address, common.Hash, uint64, *big.Int, error) {
func ParseBatchPostingReportMessageFields(rd io.Reader) (*big.Int, common.Address, common.Hash, uint64, *big.Int, uint64, error) {
batchTimestamp, err := util.HashFromReader(rd)
if err != nil {
return nil, common.Address{}, common.Hash{}, 0, nil, err
return nil, common.Address{}, common.Hash{}, 0, nil, 0, err
}
batchPosterAddr, err := util.AddressFromReader(rd)
if err != nil {
return nil, common.Address{}, common.Hash{}, 0, nil, err
return nil, common.Address{}, common.Hash{}, 0, nil, 0, err
}
dataHash, err := util.HashFromReader(rd)
if err != nil {
return nil, common.Address{}, common.Hash{}, 0, nil, err
return nil, common.Address{}, common.Hash{}, 0, nil, 0, err
}
batchNum, err := util.HashFromReader(rd)
if err != nil {
return nil, common.Address{}, common.Hash{}, 0, nil, err
return nil, common.Address{}, common.Hash{}, 0, nil, 0, err
}
l1BaseFee, err := util.HashFromReader(rd)
if err != nil {
return nil, common.Address{}, common.Hash{}, 0, nil, err
return nil, common.Address{}, common.Hash{}, 0, nil, 0, err
}
extraGas, err := util.Uint64FromReader(rd)
if errors.Is(err, io.EOF) {
// This field isn't always present
extraGas = 0
err = nil
}
if err != nil {
return nil, common.Address{}, common.Hash{}, 0, nil, 0, err
}
batchNumBig := batchNum.Big()
if !batchNumBig.IsUint64() {
return nil, common.Address{}, common.Hash{}, 0, nil, fmt.Errorf("batch number %v is not a uint64", batchNumBig)
return nil, common.Address{}, common.Hash{}, 0, nil, 0, fmt.Errorf("batch number %v is not a uint64", batchNumBig)
}
return batchTimestamp.Big(), batchPosterAddr, dataHash, batchNumBig.Uint64(), l1BaseFee.Big(), nil
return batchTimestamp.Big(), batchPosterAddr, dataHash, batchNumBig.Uint64(), l1BaseFee.Big(), extraGas, nil
}
4 changes: 3 additions & 1 deletion arbos/parse_l2.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/offchainlabs/nitro/arbos/arbostypes"
"github.com/offchainlabs/nitro/arbos/util"
"github.com/offchainlabs/nitro/util/arbmath"
)

type InfallibleBatchFetcher func(batchNum uint64, batchHash common.Hash) []byte
Expand Down Expand Up @@ -370,7 +371,7 @@ func parseSubmitRetryableMessage(rd io.Reader, header *arbostypes.L1IncomingMess
}

func parseBatchPostingReportMessage(rd io.Reader, chainId *big.Int, msgBatchGasCost *uint64, batchFetcher InfallibleBatchFetcher) (*types.Transaction, error) {
batchTimestamp, batchPosterAddr, batchHash, batchNum, l1BaseFee, err := arbostypes.ParseBatchPostingReportMessageFields(rd)
batchTimestamp, batchPosterAddr, batchHash, batchNum, l1BaseFee, extraGas, err := arbostypes.ParseBatchPostingReportMessageFields(rd)
if err != nil {
return nil, err
}
Expand All @@ -381,6 +382,7 @@ func parseBatchPostingReportMessage(rd io.Reader, chainId *big.Int, msgBatchGasC
batchData := batchFetcher(batchNum, batchHash)
batchDataGas = arbostypes.ComputeBatchGasCost(batchData)
}
batchDataGas = arbmath.SaturatingUAdd(batchDataGas, extraGas)

data, err := util.PackInternalTxDataBatchPostingReport(
batchTimestamp, batchPosterAddr, batchNum, batchDataGas, l1BaseFee,
Expand Down
2 changes: 1 addition & 1 deletion contracts

0 comments on commit e6b4b74

Please sign in to comment.