Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Build executable heap with baseFee when London fork is enabled #1857

Merged
merged 23 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions state/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,34 +489,32 @@ func (t *Transition) nonceCheck(msg *types.Transaction) error {
}

// checkDynamicFees checks correctness of the EIP-1559 feature-related fields.
// Basically, makes sure gas tip cap and gas fee cap are good.
// Basically, makes sure gas tip cap and gas fee cap are good for dynamic and legacy transactions
func (t *Transition) checkDynamicFees(msg *types.Transaction) error {
if msg.Type != types.DynamicFeeTx {
return nil
}

if msg.GasFeeCap.BitLen() == 0 && msg.GasTipCap.BitLen() == 0 {
return nil
}
if msg.Type == types.DynamicFeeTx {
if msg.GasFeeCap.BitLen() == 0 && msg.GasTipCap.BitLen() == 0 {
return nil
}

if l := msg.GasFeeCap.BitLen(); l > 256 {
return fmt.Errorf("%w: address %v, GasFeeCap bit length: %d", ErrFeeCapVeryHigh,
msg.From.String(), l)
}
if l := msg.GasFeeCap.BitLen(); l > 256 {
return fmt.Errorf("%w: address %v, GasFeeCap bit length: %d", ErrFeeCapVeryHigh,
msg.From.String(), l)
}

if l := msg.GasTipCap.BitLen(); l > 256 {
return fmt.Errorf("%w: address %v, GasTipCap bit length: %d", ErrTipVeryHigh,
msg.From.String(), l)
}
if l := msg.GasTipCap.BitLen(); l > 256 {
return fmt.Errorf("%w: address %v, GasTipCap bit length: %d", ErrTipVeryHigh,
msg.From.String(), l)
}

if msg.GasFeeCap.Cmp(msg.GasTipCap) < 0 {
return fmt.Errorf("%w: address %v, GasTipCap: %s, GasFeeCap: %s", ErrTipAboveFeeCap,
msg.From.String(), msg.GasTipCap, msg.GasFeeCap)
if msg.GasFeeCap.Cmp(msg.GasTipCap) < 0 {
return fmt.Errorf("%w: address %v, GasTipCap: %s, GasFeeCap: %s", ErrTipAboveFeeCap,
msg.From.String(), msg.GasTipCap, msg.GasFeeCap)
}
}

// This will panic if baseFee is nil, but basefee presence is verified
// as part of header validation.
if msg.GasFeeCap.Cmp(t.ctx.BaseFee) < 0 {
if msg.GetGasFeeCap().Cmp(t.ctx.BaseFee) < 0 {
return fmt.Errorf("%w: address %v, GasFeeCap: %s, BaseFee: %s", ErrFeeCapTooLow,
msg.From.String(), msg.GasFeeCap, t.ctx.BaseFee)
}
Expand Down Expand Up @@ -1156,9 +1154,11 @@ func checkAndProcessTx(msg *types.Transaction, t *Transition) error {
return NewTransitionApplicationError(err, true)
}

// 2. check dynamic fees of the transaction
if err := t.checkDynamicFees(msg); err != nil {
return NewTransitionApplicationError(err, true)
// 2. check dynamic fees of the transaction when london fork is enabled
if t.config.London {
if err := t.checkDynamicFees(msg); err != nil {
return NewTransitionApplicationError(err, true)
}
}

// 3. caller has enough balance to cover transaction
Expand Down
5 changes: 3 additions & 2 deletions txpool/account.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package txpool

import (
"math/big"
"sync"
"sync/atomic"

Expand Down Expand Up @@ -44,7 +45,7 @@ func (m *accountsMap) exists(addr types.Address) bool {

// getPrimaries collects the heads (first-in-line transaction)
// from each of the promoted queues.
func (m *accountsMap) getPrimaries() (primaries []*types.Transaction) {
func (m *accountsMap) getPrimaries(baseFee uint64) (primaries []*types.Transaction) {
m.Range(func(key, value interface{}) bool {
addressKey, ok := key.(types.Address)
rachit77 marked this conversation as resolved.
Show resolved Hide resolved
if !ok {
Expand All @@ -57,7 +58,7 @@ func (m *accountsMap) getPrimaries() (primaries []*types.Transaction) {
defer account.promoted.unlock()

// add head of the queue
if tx := account.promoted.peek(); tx != nil {
if tx := account.promoted.peek(); tx != nil && tx.GetGasFeeCap().Cmp(new(big.Int).SetUint64(baseFee)) >= 0 {
igorcrevar marked this conversation as resolved.
Show resolved Hide resolved
primaries = append(primaries, tx)
}

Expand Down
4 changes: 2 additions & 2 deletions txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func (p *TxPool) AddTx(tx *types.Transaction) error {
// ready for execution. (primaries)
func (p *TxPool) Prepare() {
// fetch primary from each account
primaries := p.accounts.getPrimaries()
primaries := p.accounts.getPrimaries(p.GetBaseFee())

// create new executables queue with base fee and initial transactions (primaries)
p.executables = newPricesQueue(p.GetBaseFee(), primaries)
rachit77 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -385,7 +385,7 @@ func (p *TxPool) Pop(tx *types.Transaction) {
p.updatePending(-1)

// update executables
if tx := account.promoted.peek(); tx != nil {
if tx := account.promoted.peek(); tx != nil && tx.GetGasFeeCap().Cmp(new(big.Int).SetUint64(p.GetBaseFee())) >= 0 {
p.executables.push(tx)
}
}
Expand Down
Loading