Skip to content

Commit

Permalink
More verbose error message for unsupported or invalid tx type (#1954)
Browse files Browse the repository at this point in the history
  • Loading branch information
jelacamarko authored Oct 4, 2023
1 parent 1f8c9c6 commit d7a003a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
5 changes: 3 additions & 2 deletions txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,8 @@ func (p *TxPool) validateTx(tx *types.Transaction) error {
if tx.Type == types.StateTx {
metrics.IncrCounter([]string{txPoolMetrics, "invalid_tx_type"}, 1)

return ErrInvalidTxType
return fmt.Errorf("%w: type %d rejected, state transactions are not expected to be added to the pool",
ErrInvalidTxType, tx.Type)
}

// Check the transaction size to overcome DOS Attacks
Expand Down Expand Up @@ -622,7 +623,7 @@ func (p *TxPool) validateTx(tx *types.Transaction) error {
if !forks.London {
metrics.IncrCounter([]string{txPoolMetrics, "tx_type"}, 1)

return ErrTxTypeNotSupported
return fmt.Errorf("%w: type %d rejected, london hardfork is not enabled", ErrTxTypeNotSupported, tx.Type)
}

// DynamicFeeTx should be rejected if TxHashWithType fork is registered but not enabled for current block
Expand Down
32 changes: 29 additions & 3 deletions txpool/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,35 @@ func TestAddTxErrors(t *testing.T) {
tx := newTx(defaultAddr, 0, 1)
tx.Type = types.StateTx

assert.ErrorIs(t,
pool.addTx(local, signTx(tx)),
ErrInvalidTxType,
err := pool.addTx(local, signTx(tx))

assert.ErrorContains(t,
err,
ErrInvalidTxType.Error(),
)
assert.ErrorContains(t,
err,
"state transactions are not expected to be added to the pool",
)
})

t.Run("ErrTxTypeNotSupported London hardfork not enabled", func(t *testing.T) {
t.Parallel()
pool := setupPool()
pool.forks.RemoveFork(chain.London)

tx := newTx(defaultAddr, 0, 1)
tx.Type = types.DynamicFeeTx

err := pool.addTx(local, signTx(tx))

assert.ErrorContains(t,
err,
ErrTxTypeNotSupported.Error(),
)
assert.ErrorContains(t,
err,
"london hardfork is not enabled",
)
})

Expand Down

0 comments on commit d7a003a

Please sign in to comment.