Skip to content

Commit 31f7320

Browse files
Multi gas refund for retryable tx path
1 parent 93055f6 commit 31f7320

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

arbos/tx_processor.go

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,29 @@ func (p *TxProcessor) EndTxHook(gasLeft uint64, usedMultiGas multigas.MultiGas,
539539
p.state.Restrict(err)
540540
shouldRefundMultiGas := gasModel == l2pricing.GasModelMultiGasConstraints
541541

542+
multiGasRefund := func(singleDimCost *big.Int, usedMultiGas multigas.MultiGas, from common.Address) error {
543+
correctedCost, err := p.state.L2PricingState().MultiDimensionalPriceForGas(usedMultiGas)
544+
if err != nil {
545+
return err
546+
}
547+
548+
amount := new(big.Int).Sub(singleDimCost, correctedCost)
549+
if amount.Sign() > 0 {
550+
err := util.TransferBalance(
551+
&networkFeeAccount,
552+
&from,
553+
amount,
554+
p.evm,
555+
scenario,
556+
tracing.BalanceChangeTransferNetworkRefund, // TODO: clarify reason
557+
)
558+
p.state.Restrict(err)
559+
} else if amount.Sign() < 0 {
560+
log.Warn("multi dimensional gas price exceeded simple gas price", "amount", amount)
561+
}
562+
return nil
563+
}
564+
542565
if underlyingTx != nil && underlyingTx.Type() == types.ArbitrumRetryTxType {
543566
inner, _ := underlyingTx.GetInner().(*types.ArbitrumRetryTx)
544567
effectiveBaseFee := inner.GasFeeCap
@@ -560,6 +583,13 @@ func (p *TxProcessor) EndTxHook(gasLeft uint64, usedMultiGas multigas.MultiGas,
560583
log.Error("Uh oh, Geth didn't refund the user", inner.From, gasRefund)
561584
}
562585

586+
// Multi-dimensional refund (retryable tx path)
587+
if shouldRefundMultiGas {
588+
singleCost := arbmath.BigMulByUint(effectiveBaseFee, gasUsed)
589+
err = multiGasRefund(singleCost, usedMultiGas, inner.From)
590+
p.state.Restrict(err)
591+
}
592+
563593
maxRefund := new(big.Int).Set(inner.MaxRefund)
564594
refund := func(refundFrom common.Address, amount *big.Int, reason tracing.BalanceChangeReason) {
565595
const errLog = "fee address doesn't have enough funds to give user refund"
@@ -687,23 +717,8 @@ func (p *TxProcessor) EndTxHook(gasLeft uint64, usedMultiGas multigas.MultiGas,
687717

688718
// Multi-dimensional refund (normal tx path)
689719
if shouldRefundMultiGas {
690-
detailedPrice, err := p.state.L2PricingState().MultiDimensionalPriceForGas(usedMultiGas)
720+
err = multiGasRefund(totalCost, usedMultiGas, p.msg.From)
691721
p.state.Restrict(err)
692-
693-
amount := new(big.Int).Sub(totalCost, detailedPrice)
694-
if amount.Sign() > 0 {
695-
err := util.TransferBalance(
696-
&networkFeeAccount,
697-
&p.msg.From,
698-
amount,
699-
p.evm,
700-
scenario,
701-
tracing.BalanceChangeTransferNetworkRefund, // TODO: clarify reason
702-
)
703-
p.state.Restrict(err)
704-
} else if amount.Sign() < 0 {
705-
log.Warn("multi dimensional gas price exceeded simple gas price", "amount", amount)
706-
}
707722
}
708723

709724
if p.msg.GasPrice.Sign() > 0 { // in tests, gas price could be 0

0 commit comments

Comments
 (0)