mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-18 14:04:46 +00:00
mempool: move errors to be public (#6613)
## Description Move mempool errors to be public, this is used in handling abci error codes
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
package mempool
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrTxInCache is returned to the client if we saw tx earlier
|
||||
ErrTxInCache = errors.New("tx already exists in cache")
|
||||
)
|
||||
|
||||
// ErrTxTooLarge defines an error when a transaction is too big to be sent in a
|
||||
// message to other peers.
|
||||
type ErrTxTooLarge struct {
|
||||
Max int
|
||||
Actual int
|
||||
}
|
||||
|
||||
func (e ErrTxTooLarge) Error() string {
|
||||
return fmt.Sprintf("Tx too large. Max size is %d, but got %d", e.Max, e.Actual)
|
||||
}
|
||||
|
||||
// ErrMempoolIsFull defines an error where Tendermint and the application cannot
|
||||
// handle that much load.
|
||||
type ErrMempoolIsFull struct {
|
||||
NumTxs int
|
||||
MaxTxs int
|
||||
TxsBytes int64
|
||||
MaxTxsBytes int64
|
||||
}
|
||||
|
||||
func (e ErrMempoolIsFull) Error() string {
|
||||
return fmt.Sprintf(
|
||||
"mempool is full: number of txs %d (max: %d), total txs bytes %d (max: %d)",
|
||||
e.NumTxs,
|
||||
e.MaxTxs,
|
||||
e.TxsBytes,
|
||||
e.MaxTxsBytes,
|
||||
)
|
||||
}
|
||||
|
||||
// ErrPreCheck defines an error where a transaction fails a pre-check.
|
||||
type ErrPreCheck struct {
|
||||
Reason error
|
||||
}
|
||||
|
||||
func (e ErrPreCheck) Error() string {
|
||||
return e.Reason.Error()
|
||||
}
|
||||
|
||||
// IsPreCheckError returns true if err is due to pre check failure.
|
||||
func IsPreCheckError(err error) bool {
|
||||
return errors.As(err, &ErrPreCheck{})
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/tendermint/tendermint/internal/mempool"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
pubmempool "github.com/tendermint/tendermint/pkg/mempool"
|
||||
"github.com/tendermint/tendermint/proxy"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
@@ -216,7 +217,7 @@ func (mem *CListMempool) CheckTx(
|
||||
}
|
||||
|
||||
if txSize > mem.config.MaxTxBytes {
|
||||
return mempool.ErrTxTooLarge{
|
||||
return pubmempool.ErrTxTooLarge{
|
||||
Max: mem.config.MaxTxBytes,
|
||||
Actual: txSize,
|
||||
}
|
||||
@@ -224,7 +225,7 @@ func (mem *CListMempool) CheckTx(
|
||||
|
||||
if mem.preCheck != nil {
|
||||
if err := mem.preCheck(tx); err != nil {
|
||||
return mempool.ErrPreCheck{
|
||||
return pubmempool.ErrPreCheck{
|
||||
Reason: err,
|
||||
}
|
||||
}
|
||||
@@ -247,7 +248,7 @@ func (mem *CListMempool) CheckTx(
|
||||
// its non-trivial since invalid txs can become valid,
|
||||
// but they can spam the same tx with little cost to them atm.
|
||||
if loaded {
|
||||
return mempool.ErrTxInCache
|
||||
return pubmempool.ErrTxInCache
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,7 +364,7 @@ func (mem *CListMempool) isFull(txSize int) error {
|
||||
)
|
||||
|
||||
if memSize >= mem.config.Size || int64(txSize)+txsBytes > mem.config.MaxTxsBytes {
|
||||
return mempool.ErrMempoolIsFull{
|
||||
return pubmempool.ErrMempoolIsFull{
|
||||
NumTxs: memSize,
|
||||
MaxTxs: mem.config.Size,
|
||||
TxsBytes: txsBytes,
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmrand "github.com/tendermint/tendermint/libs/rand"
|
||||
"github.com/tendermint/tendermint/libs/service"
|
||||
pubmempool "github.com/tendermint/tendermint/pkg/mempool"
|
||||
"github.com/tendermint/tendermint/proxy"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
@@ -82,7 +83,7 @@ func checkTxs(t *testing.T, mp mempool.Mempool, count int, peerID uint16) types.
|
||||
// Skip invalid txs.
|
||||
// TestMempoolFilters will fail otherwise. It asserts a number of txs
|
||||
// returned.
|
||||
if mempool.IsPreCheckError(err) {
|
||||
if pubmempool.IsPreCheckError(err) {
|
||||
continue
|
||||
}
|
||||
t.Fatalf("CheckTx failed: %v while checking #%d tx", err, i)
|
||||
@@ -455,7 +456,7 @@ func TestMempool_CheckTxChecksTxSize(t *testing.T) {
|
||||
if !testCase.err {
|
||||
require.NoError(t, err, caseString)
|
||||
} else {
|
||||
require.Equal(t, err, mempool.ErrTxTooLarge{
|
||||
require.Equal(t, err, pubmempool.ErrTxTooLarge{
|
||||
Max: maxTxSize,
|
||||
Actual: testCase.len,
|
||||
}, caseString)
|
||||
@@ -503,7 +504,7 @@ func TestMempoolTxsBytes(t *testing.T) {
|
||||
|
||||
err = mp.CheckTx(context.Background(), []byte{0x05}, nil, mempool.TxInfo{})
|
||||
if assert.Error(t, err) {
|
||||
assert.IsType(t, mempool.ErrMempoolIsFull{}, err)
|
||||
assert.IsType(t, pubmempool.ErrMempoolIsFull{}, err)
|
||||
}
|
||||
|
||||
// 6. zero after tx is rechecked and removed due to not being valid anymore
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/tendermint/tendermint/internal/mempool"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
pubmempool "github.com/tendermint/tendermint/pkg/mempool"
|
||||
"github.com/tendermint/tendermint/proxy"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
@@ -224,7 +225,7 @@ func (txmp *TxMempool) CheckTx(
|
||||
|
||||
txSize := len(tx)
|
||||
if txSize > txmp.config.MaxTxBytes {
|
||||
return mempool.ErrTxTooLarge{
|
||||
return pubmempool.ErrTxTooLarge{
|
||||
Max: txmp.config.MaxTxBytes,
|
||||
Actual: txSize,
|
||||
}
|
||||
@@ -232,7 +233,7 @@ func (txmp *TxMempool) CheckTx(
|
||||
|
||||
if txmp.preCheck != nil {
|
||||
if err := txmp.preCheck(tx); err != nil {
|
||||
return mempool.ErrPreCheck{
|
||||
return pubmempool.ErrPreCheck{
|
||||
Reason: err,
|
||||
}
|
||||
}
|
||||
@@ -252,7 +253,7 @@ func (txmp *TxMempool) CheckTx(
|
||||
if wtx != nil && ok {
|
||||
// We already have the transaction stored and the we've already seen this
|
||||
// transaction from txInfo.SenderID.
|
||||
return mempool.ErrTxInCache
|
||||
return pubmempool.ErrTxInCache
|
||||
}
|
||||
|
||||
txmp.logger.Debug("tx exists already in cache", "tx_hash", tx.Hash())
|
||||
@@ -707,7 +708,7 @@ func (txmp *TxMempool) canAddTx(wtx *WrappedTx) error {
|
||||
)
|
||||
|
||||
if numTxs >= txmp.config.Size || int64(wtx.Size())+sizeBytes > txmp.config.MaxTxsBytes {
|
||||
return mempool.ErrMempoolIsFull{
|
||||
return pubmempool.ErrMempoolIsFull{
|
||||
NumTxs: numTxs,
|
||||
MaxTxs: txmp.config.Size,
|
||||
TxsBytes: sizeBytes,
|
||||
|
||||
Reference in New Issue
Block a user