Skip to content

Commit

Permalink
op-batcher: Improve logging in dynamic eth-da channel config
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianst committed Jul 30, 2024
1 parent 4cf9202 commit 032b3d4
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions op-batcher/batcher/channel_config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,21 @@ func (dec *DynamicEthChannelConfig) ChannelConfig() ChannelConfig {
blobCalldataCost := new(big.Int).Mul(big.NewInt(int64(params.TxGas)), calldataPrice)
blobCost = blobCost.Add(blobCost, blobCalldataCost)

// Now we compare the prices divided by the number of bytes that can be
// submitted for that price.
blobDataBytes := big.NewInt(eth.MaxBlobDataSize * int64(dec.blobConfig.TargetNumFrames))
// The following will compare blobCost(a)/blobDataBytes(x) > calldataCost(b)/calldataBytes(y):
ay := new(big.Int).Mul(blobCost, big.NewInt(int64(calldataBytes)))
bx := new(big.Int).Mul(calldataCost, blobDataBytes)
// ratio only used for logging, more correct multiplicative calculation used for comparison
ayf, bxf := new(big.Float).SetInt(ay), new(big.Float).SetInt(bx)
costRatio := new(big.Float).Quo(ayf, bxf)
lgr := dec.log.New("base_fee", baseFee, "blob_base_fee", blobBaseFee, "tip_cap", tipCap,
"calldata_bytes", calldataBytes, "calldata_cost", calldataCost,
"blob_data_bytes", blobDataBytes, "blob_cost", blobCost)
"blob_data_bytes", blobDataBytes, "blob_cost", blobCost,
"cost_ratio", costRatio)

// Now we compare the prices divided by the number of bytes that can be
// submitted for that price.
// This is comparing blobCost/blobDataBytes > calldataCost/calldataBytes:
if new(big.Int).Mul(blobCost, big.NewInt(int64(calldataBytes))).
Cmp(new(big.Int).Mul(calldataCost, blobDataBytes)) == 1 {
if ay.Cmp(bx) == 1 {
lgr.Info("Using calldata channel config")
dec.lastConfig = &dec.calldataConfig
return dec.calldataConfig
Expand Down

0 comments on commit 032b3d4

Please sign in to comment.