Skip to content

Commit

Permalink
Handle unset base fee
Browse files Browse the repository at this point in the history
Not necessary for celo, but for pre EIP-1559 tests.
  • Loading branch information
palango committed Nov 7, 2023
1 parent f5a28c8 commit b651c95
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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)

Expand All @@ -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
}

0 comments on commit b651c95

Please sign in to comment.