fix fee logic in TransitionDb (#887)

update fee_vault logic in TransitionDb
This commit is contained in:
HAOYUatHZ 2024-07-08 17:08:22 +08:00 committed by GitHub
parent b5dee527c4
commit 72577219c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -490,19 +490,19 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
effectiveTip = cmath.BigMin(msg.GasTipCap, new(big.Int).Sub(msg.GasFeeCap, st.evm.Context.BaseFee)) effectiveTip = cmath.BigMin(msg.GasTipCap, new(big.Int).Sub(msg.GasFeeCap, st.evm.Context.BaseFee))
} }
// The L2 Fee is the same as the fee that is charged in the normal geth codepath.
fee := big.NewInt(0)
if st.evm.Config.NoBaseFee && msg.GasFeeCap.Sign() == 0 && msg.GasTipCap.Sign() == 0 { if st.evm.Config.NoBaseFee && msg.GasFeeCap.Sign() == 0 && msg.GasTipCap.Sign() == 0 {
// Skip fee payment when NoBaseFee is set and the fee fields // Skip fee payment when NoBaseFee is set and the fee fields
// are 0. This avoids a negative effectiveTip being applied to // are 0. This avoids a negative effectiveTip being applied to
// the coinbase when simulating calls. // the coinbase when simulating calls.
} else { } else {
// The L2 Fee is the same as the fee that is charged in the normal geth fee = new(big.Int).SetUint64(st.gasUsed())
// codepath. Add the L1DataFee to the L2 fee for the total fee that is sent
// to the sequencer.
fee := new(big.Int).SetUint64(st.gasUsed())
fee.Mul(fee, effectiveTip) fee.Mul(fee, effectiveTip)
fee.Add(fee, st.l1DataFee)
st.state.AddBalance(st.evm.Context.Coinbase, fee) // TODO: change to `st.evm.FeeRecipient()`
} }
//Add the L1DataFee to the L2 fee for the total fee that is sent to the sequencer.
totalFee := fee.Add(fee, st.l1DataFee)
st.state.AddBalance(st.evm.FeeRecipient(), totalFee)
return &ExecutionResult{ return &ExecutionResult{
L1DataFee: st.l1DataFee, L1DataFee: st.l1DataFee,