Skip to content

Commit

Permalink
small mempool fixes (#1943)
Browse files Browse the repository at this point in the history
  • Loading branch information
tudor-malene authored Jun 3, 2024
1 parent b335bd1 commit c0bf408
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
12 changes: 10 additions & 2 deletions go/enclave/evm/evm_facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import (
gethrpc "github.com/ten-protocol/go-ten/lib/gethfork/rpc"
)

var ErrGasNotEnoughForL1 = errors.New("gas limit too low to pay for execution and l1 fees")

// ExecuteTransactions
// header - the header of the rollup where this transaction will be included
// fromTxIndex - for the receipts and events, the evm needs to know for each transaction the order in which it was executed in the block.
Expand Down Expand Up @@ -91,7 +93,12 @@ func ExecuteTransactions(
if err != nil {
tCountRollback++
result[t.Tx.Hash()] = err
logger.Info("Failed to execute tx:", log.TxKey, t.Tx.Hash(), log.CtrErrKey, err)
// only log tx execution errors if they are unexpected
logFailedTx := logger.Info
if errors.Is(err, gethcore.ErrNonceTooHigh) || errors.Is(err, gethcore.ErrNonceTooLow) || errors.Is(err, gethcore.ErrFeeCapTooLow) || errors.Is(err, ErrGasNotEnoughForL1) {
logFailedTx = logger.Debug
}
logFailedTx("Failed to execute tx:", log.TxKey, t.Tx.Hash(), log.CtrErrKey, err)
continue
}
result[t.Tx.Hash()] = r
Expand Down Expand Up @@ -160,8 +167,9 @@ func executeTransaction(

// The gas limit of the transaction (evm message) should always be higher than the gas overhead
// used to cover the l1 cost
// todo - this check has to be added to the mempool as well
if msg.GasLimit < l1Gas.Uint64() {
return nil, fmt.Errorf("gas limit set by user is too low to pay for execution and l1 fees. Want at least: %d have: %d", l1Gas, msg.GasLimit)
return nil, fmt.Errorf("%w. Want at least: %d have: %d", ErrGasNotEnoughForL1, l1Gas, msg.GasLimit)
}

// Remove the gas overhead for l1 publishing from the gas limit in order to define
Expand Down
14 changes: 9 additions & 5 deletions go/enclave/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import (
"math/big"
"strings"
"sync"
_ "unsafe"

gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/holiman/uint256"

// unsafe package imported in order to link to a private function in go-ethereum.
// This allows us to validate transactions against the tx pool rules.
_ "unsafe"

gethlog "github.com/ethereum/go-ethereum/log"
"github.com/ten-protocol/go-ten/go/common/log"

gethcommon "github.com/ethereum/go-ethereum/common"
gethtxpool "github.com/ethereum/go-ethereum/core/txpool"
"github.com/ethereum/go-ethereum/core/txpool/legacypool"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -67,9 +69,11 @@ func (t *TxPool) Start() error {

// PendingTransactions returns all pending transactions grouped per address and ordered per nonce
func (t *TxPool) PendingTransactions() map[gethcommon.Address][]*gethtxpool.LazyTransaction {
// todo
// todo - for now using the base fee from the block
baseFee := t.Chain.CurrentBlock().BaseFee
return t.pool.Pending(gethtxpool.PendingFilter{
// BaseFee:
BaseFee: uint256.NewInt(baseFee.Uint64()),
OnlyPlainTxs: true,
})
}

Expand Down Expand Up @@ -121,5 +125,5 @@ func (t *TxPool) Close() error {
t.logger.Error("Could not close legacy pool", log.ErrKey, err)
}
}()
return t.legacyPool.Close()
return t.pool.Close()
}

0 comments on commit c0bf408

Please sign in to comment.