From b651c9524c5a00537203ef9a321c7aa503403f3d Mon Sep 17 00:00:00 2001 From: Paul Lange Date: Tue, 7 Nov 2023 15:41:03 +0100 Subject: [PATCH] Handle unset base fee Not necessary for celo, but for pre EIP-1559 tests. --- core/state_transition.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/core/state_transition.go b/core/state_transition.go index 668606fc57..7a5c3b66aa 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -254,27 +254,22 @@ type StateTransition struct { evm *vm.EVM // Celo additions - gasPriceMinimum *big.Int - backend *CeloBackend + backend *CeloBackend } // NewStateTransition initialises and returns a new state transition object. func NewStateTransition(evm *vm.EVM, msg *Message, gp *GasPool) *StateTransition { - gasPriceMinimum := evm.Context.BaseFee - // TODO(pl): Convert base fee into fee currency of necessary - backend := &CeloBackend{ chainConfig: nil, state: nil, } return &StateTransition{ - gp: gp, - evm: evm, - msg: msg, - state: evm.StateDB, - gasPriceMinimum: gasPriceMinimum, - backend: backend, + gp: gp, + evm: evm, + msg: msg, + state: evm.StateDB, + backend: backend, } } @@ -688,7 +683,7 @@ func (st *StateTransition) distributeTxFees() error { from := st.msg.From // Divide the transaction into a base (the minimum transaction fee) and tip (any extra, or min(max tip, feecap - GPM) if espresso). - baseTxFee := new(big.Int).Mul(gasUsed, st.gasPriceMinimum) + baseTxFee := new(big.Int).Mul(gasUsed, st.calculateGasPriceMinimum()) // No need to do effectiveTip calculation, because st.gasPrice == effectiveGasPrice, and effectiveTip = effectiveGasPrice - baseTxFee tipTxFee := new(big.Int).Sub(totalTxFee, baseTxFee) @@ -710,3 +705,13 @@ func (st *StateTransition) distributeTxFees() error { } return nil } + +func (st *StateTransition) calculateGasPriceMinimum() *big.Int { + gasPriceMinimum := st.evm.Context.BaseFee + if gasPriceMinimum == nil { + gasPriceMinimum = big.NewInt(0) + } + // TODO(pl): Convert base fee into fee currency of necessary + + return gasPriceMinimum +}