Skip to content

Commit

Permalink
export a function to estimate the l1 batch size of a transaction (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-bayardo authored Oct 28, 2024
1 parent c6b531b commit 5c98784
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions core/types/rollup_cost.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,7 @@ func NewL1CostFuncFjord(l1BaseFee, l1BlobBaseFee, baseFeeScalar, blobFeeScalar *
calldataCostPerByte := new(big.Int).Mul(scaledL1BaseFee, sixteen)
blobCostPerByte := new(big.Int).Mul(blobFeeScalar, l1BlobBaseFee)
l1FeeScaled := new(big.Int).Add(calldataCostPerByte, blobCostPerByte)

fastLzSize := new(big.Int).SetUint64(costData.FastLzSize)
estimatedSize := new(big.Int).Add(L1CostIntercept, new(big.Int).Mul(L1CostFastlzCoef, fastLzSize))

if estimatedSize.Cmp(MinTransactionSizeScaled) < 0 {
estimatedSize.Set(MinTransactionSizeScaled)
}

estimatedSize := EstimatedL1Size(costData)
l1CostScaled := new(big.Int).Mul(estimatedSize, l1FeeScaled)
l1Cost := new(big.Int).Div(l1CostScaled, fjordDivisor)

Expand All @@ -382,6 +375,18 @@ func NewL1CostFuncFjord(l1BaseFee, l1BlobBaseFee, baseFeeScalar, blobFeeScalar *
}
}

// EstimatedL1Size estimates the number of bytes the transaction will occupy in its L1 batch, using
// the Fjord linear regression model.
func EstimatedL1Size(costData RollupCostData) *big.Int {
fastLzSize := new(big.Int).SetUint64(costData.FastLzSize)
estimatedSize := new(big.Int).Add(L1CostIntercept, new(big.Int).Mul(L1CostFastlzCoef, fastLzSize))

if estimatedSize.Cmp(MinTransactionSizeScaled) < 0 {
estimatedSize.Set(MinTransactionSizeScaled)
}
return estimatedSize
}

func extractEcotoneFeeParams(l1FeeParams []byte) (l1BaseFeeScalar, l1BlobBaseFeeScalar *big.Int) {
offset := scalarSectionStart
l1BaseFeeScalar = new(big.Int).SetBytes(l1FeeParams[offset : offset+4])
Expand Down

0 comments on commit 5c98784

Please sign in to comment.