Skip to content

Commit

Permalink
Merge pull request #2199 from OffchainLabs/rbf-max-multiple
Browse files Browse the repository at this point in the history
Fix MaxFeeBidMultipleBips to respect rbf minimums [NIT-2371]
  • Loading branch information
Tristan-Wilson committed Mar 25, 2024
2 parents 14a2b0b + 7911fae commit 5b1871c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
21 changes: 15 additions & 6 deletions arbnode/dataposter/data_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,13 +583,8 @@ func (p *DataPoster) feeAndTipCaps(ctx context.Context, nonce uint64, gasLimit u
blobGasUsed := params.BlobTxBlobGasPerBlob * numBlobs
currentBlobCost := arbmath.BigMulByUint(currentBlobFee, blobGasUsed)
currentNonBlobCost := arbmath.BigMulByUint(currentNonBlobFee, gasLimit)
currentTotalCost := arbmath.BigAdd(currentBlobCost, currentNonBlobCost)
if config.MaxFeeBidMultipleBips > 0 {
targetMaxCost = arbmath.BigMin(targetMaxCost, arbmath.BigMulByBips(currentTotalCost, config.MaxFeeBidMultipleBips))
}

newBlobFeeCap := arbmath.BigMul(targetMaxCost, currentBlobFee)
newBlobFeeCap.Div(newBlobFeeCap, currentTotalCost)
newBlobFeeCap.Div(newBlobFeeCap, arbmath.BigAdd(currentBlobCost, currentNonBlobCost))
if lastTx != nil && lastTx.BlobGasFeeCap() != nil {
newBlobFeeCap = arbmath.BigMax(newBlobFeeCap, arbmath.BigMulByBips(lastTx.BlobGasFeeCap(), minRbfIncrease))
}
Expand All @@ -606,6 +601,20 @@ func (p *DataPoster) feeAndTipCaps(ctx context.Context, nonce uint64, gasLimit u
newBlobFeeCap = arbmath.BigDivByUint(newBlobCost, blobGasUsed)
}

if config.MaxFeeBidMultipleBips > 0 {
// Limit the fee caps to be no greater than max(MaxFeeBidMultipleBips, minRbf)
maxNonBlobFee := arbmath.BigMulByBips(currentNonBlobFee, config.MaxFeeBidMultipleBips)
if lastTx != nil {
maxNonBlobFee = arbmath.BigMax(maxNonBlobFee, arbmath.BigMulByBips(lastTx.GasFeeCap(), minRbfIncrease))
}
maxBlobFee := arbmath.BigMulByBips(currentBlobFee, config.MaxFeeBidMultipleBips)
if lastTx != nil && lastTx.BlobGasFeeCap() != nil {
maxBlobFee = arbmath.BigMax(maxBlobFee, arbmath.BigMulByBips(lastTx.BlobGasFeeCap(), minRbfIncrease))
}
newBaseFeeCap = arbmath.BigMin(newBaseFeeCap, maxNonBlobFee)
newBlobFeeCap = arbmath.BigMin(newBlobFeeCap, maxBlobFee)
}

if arbmath.BigGreaterThan(newTipCap, newBaseFeeCap) {
log.Info(
"reducing new tip cap to new basefee cap",
Expand Down
5 changes: 3 additions & 2 deletions broadcaster/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"net"
"runtime/debug"

"github.com/gobwas/ws"

Expand Down Expand Up @@ -60,7 +61,7 @@ func (b *Broadcaster) NewBroadcastFeedMessage(message arbostypes.MessageWithMeta
func (b *Broadcaster) BroadcastSingle(msg arbostypes.MessageWithMetadata, seq arbutil.MessageIndex) (err error) {
defer func() {
if r := recover(); r != nil {
log.Error("recovered error in BroadcastSingle", "recover", r)
log.Error("recovered error in BroadcastSingle", "recover", r, "backtrace", string(debug.Stack()))
err = errors.New("panic in BroadcastSingle")
}
}()
Expand All @@ -84,7 +85,7 @@ func (b *Broadcaster) BroadcastSingleFeedMessage(bfm *m.BroadcastFeedMessage) {
func (b *Broadcaster) BroadcastMessages(messages []arbostypes.MessageWithMetadata, seq arbutil.MessageIndex) (err error) {
defer func() {
if r := recover(); r != nil {
log.Error("recovered error in BroadcastMessages", "recover", r)
log.Error("recovered error in BroadcastMessages", "recover", r, "backtrace", string(debug.Stack()))
err = errors.New("panic in BroadcastMessages")
}
}()
Expand Down

0 comments on commit 5b1871c

Please sign in to comment.