Skip to content

Commit

Permalink
Error kind detection bug fix (0xPolygon#1769)
Browse files Browse the repository at this point in the history
  • Loading branch information
begmaroman authored Aug 2, 2023
1 parent 65c9a3e commit 75c5324
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
12 changes: 10 additions & 2 deletions jsonrpc/eth_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,16 @@ func (e *Eth) EstimateGas(arg *txnArgs, rawNum *BlockNumber) (interface{}, error

// Checks if executor level valid gas errors occurred
isGasApplyError := func(err error) bool {
// Not linting this as the underlying error is actually wrapped
return errors.Is(err, state.ErrNotEnoughIntrinsicGas)
if errors.Is(err, state.ErrNotEnoughIntrinsicGas) {
return true
}

var expected *state.TransitionApplicationError
if errors.As(err, &expected) {
return errors.Is(expected.Err, state.ErrNotEnoughIntrinsicGas)
}

return false
}

// Checks if EVM level valid gas errors occurred
Expand Down
10 changes: 5 additions & 5 deletions state/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,11 @@ func (t *Transition) checkDynamicFees(msg *types.Transaction) error {
// surfacing of these errors reject the transaction thus not including it in the block

var (
ErrNonceIncorrect = fmt.Errorf("incorrect nonce")
ErrNotEnoughFundsForGas = fmt.Errorf("not enough funds to cover gas costs")
ErrBlockLimitReached = fmt.Errorf("gas limit reached in the pool")
ErrIntrinsicGasOverflow = fmt.Errorf("overflow in intrinsic gas calculation")
ErrNotEnoughIntrinsicGas = fmt.Errorf("not enough gas supplied for intrinsic gas costs")
ErrNonceIncorrect = errors.New("incorrect nonce")
ErrNotEnoughFundsForGas = errors.New("not enough funds to cover gas costs")
ErrBlockLimitReached = errors.New("gas limit reached in the pool")
ErrIntrinsicGasOverflow = errors.New("overflow in intrinsic gas calculation")
ErrNotEnoughIntrinsicGas = errors.New("not enough gas supplied for intrinsic gas costs")

// ErrTipAboveFeeCap is a sanity error to ensure no one is able to specify a
// transaction with a tip higher than the total fee cap.
Expand Down
6 changes: 3 additions & 3 deletions txrelayer/txrelayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (t *TxRelayerImpl) sendTransactionLocked(txn *ethgo.Transaction, key ethgo.

nonce, err := t.client.Eth().GetNonce(key.Address(), ethgo.Pending)
if err != nil {
return ethgo.ZeroHash, err
return ethgo.ZeroHash, fmt.Errorf("failed to get nonce: %w", err)
}

txn.Nonce = nonce
Expand All @@ -115,7 +115,7 @@ func (t *TxRelayerImpl) sendTransactionLocked(txn *ethgo.Transaction, key ethgo.
if txn.GasPrice == 0 {
gasPrice, err := t.Client().Eth().GasPrice()
if err != nil {
return ethgo.ZeroHash, err
return ethgo.ZeroHash, fmt.Errorf("failed to get gas price: %w", err)
}

txn.GasPrice = gasPrice + (gasPrice * gasPricePercent / 100)
Expand All @@ -124,7 +124,7 @@ func (t *TxRelayerImpl) sendTransactionLocked(txn *ethgo.Transaction, key ethgo.
if txn.Gas == 0 {
gasLimit, err := t.client.Eth().EstimateGas(ConvertTxnToCallMsg(txn))
if err != nil {
return ethgo.ZeroHash, err
return ethgo.ZeroHash, fmt.Errorf("failed to estimate gas: %w", err)
}

txn.Gas = gasLimit + (gasLimit * gasLimitPercent / 100)
Expand Down

0 comments on commit 75c5324

Please sign in to comment.