From ed4088fdbd835136562c81b99c40542bbc680782 Mon Sep 17 00:00:00 2001 From: Tudor Malene Date: Mon, 3 Jun 2024 12:51:12 +0100 Subject: [PATCH] small mempool fixes --- go/enclave/evm/evm_facade.go | 12 ++++++++++-- go/enclave/txpool/txpool.go | 14 +++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/go/enclave/evm/evm_facade.go b/go/enclave/evm/evm_facade.go index 5005f7b600..059b6f851e 100644 --- a/go/enclave/evm/evm_facade.go +++ b/go/enclave/evm/evm_facade.go @@ -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. @@ -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 @@ -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 diff --git a/go/enclave/txpool/txpool.go b/go/enclave/txpool/txpool.go index 6deca4a1a4..efcd3dd3af 100644 --- a/go/enclave/txpool/txpool.go +++ b/go/enclave/txpool/txpool.go @@ -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" @@ -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, }) } @@ -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() }