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

More verbose error message for unsupported or invalid tx type #1954

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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 @@ -143,9 +143,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
Loading