Skip to content

Commit

Permalink
Merge branch 'master' into batch-size-moving-average
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower authored Dec 18, 2023
2 parents 2473808 + 9306bea commit 8f87a79
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions arbnode/dataposter/data_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ func (p *DataPoster) evalMaxFeeCapExpr(backlogOfBatches uint64, elapsed time.Dur
return resultBig, nil
}

var big4 = big.NewInt(4)

// The dataPosterBacklog argument should *not* include extraBacklog (it's added in in this function)
func (p *DataPoster) feeAndTipCaps(ctx context.Context, nonce uint64, gasLimit uint64, lastFeeCap *big.Int, lastTipCap *big.Int, dataCreatedAt time.Time, dataPosterBacklog uint64) (*big.Int, *big.Int, error) {
config := p.config()
Expand Down Expand Up @@ -468,17 +470,35 @@ func (p *DataPoster) feeAndTipCaps(ctx context.Context, nonce uint64, gasLimit u
latestBalance := p.balance
balanceForTx := new(big.Int).Set(latestBalance)
if config.AllocateMempoolBalance && !p.usingNoOpStorage {
// We reserve half the balance for the first transaction, and then split the remaining balance for all after that.
// We split the transactions into three groups:
// - The first transaction gets 1/2 of the balance.
// - The first half of transactions get 1/3 of the balance split among them.
// - The remaining transactions get the remaining 1/6 of the balance split among them.
// This helps ensure batch posting is reliable under a variety of fee conditions.
// With noop storage, we don't try to replace-by-fee, so we don't need to worry about this.
balanceForTx.Div(balanceForTx, common.Big2)
if nonce != softConfNonce && config.MaxMempoolTransactions > 1 {
// Compared to dividing the remaining transactions by balance equally,
// the first half of transactions should get a 4/3 weight,
// and the remaining half should get a 2/3 weight.
// This makes sure the average weight is 1, and the first half of transactions
// have twice the weight of the second half of transactions.
// The +1 and -1 here are to account for the first transaction being handled separately.
if nonce > softConfNonce && nonce < softConfNonce+1+(config.MaxMempoolTransactions-1)/2 {
balanceForTx.Mul(balanceForTx, big4)
} else {
balanceForTx.Mul(balanceForTx, common.Big2)
}
balanceForTx.Div(balanceForTx, common.Big3)
// After weighting, split the balance between each of the transactions
// other than the first tx which already got half.
// balanceForTx /= config.MaxMempoolTransactions-1
balanceForTx.Div(balanceForTx, arbmath.UintToBig(config.MaxMempoolTransactions-1))
}
}
balanceFeeCap := arbmath.BigDivByUint(balanceForTx, gasLimit)
if arbmath.BigGreaterThan(newFeeCap, balanceFeeCap) {
log.Error(
log.Warn(
"lack of L1 balance prevents posting transaction with desired fee cap",
"balance", latestBalance,
"maxTransactions", config.MaxMempoolTransactions,
Expand Down

0 comments on commit 8f87a79

Please sign in to comment.