Browse Source

types: move mempool error for consistency (#6875)

This is a little change just to make things more consistent ahead of
the 0.35 release.
pull/6880/head
Sam Kleinman 3 years ago
committed by GitHub
parent
commit
c4df8a3840
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 15 deletions
  1. +4
    -5
      internal/mempool/v0/clist_mempool.go
  2. +3
    -4
      internal/mempool/v0/clist_mempool_test.go
  3. +4
    -5
      internal/mempool/v1/mempool.go
  4. +1
    -1
      types/mempool.go

+ 4
- 5
internal/mempool/v0/clist_mempool.go View File

@ -14,7 +14,6 @@ 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"
)
@ -217,7 +216,7 @@ func (mem *CListMempool) CheckTx(
}
if txSize > mem.config.MaxTxBytes {
return pubmempool.ErrTxTooLarge{
return types.ErrTxTooLarge{
Max: mem.config.MaxTxBytes,
Actual: txSize,
}
@ -225,7 +224,7 @@ func (mem *CListMempool) CheckTx(
if mem.preCheck != nil {
if err := mem.preCheck(tx); err != nil {
return pubmempool.ErrPreCheck{
return types.ErrPreCheck{
Reason: err,
}
}
@ -248,7 +247,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 pubmempool.ErrTxInCache
return types.ErrTxInCache
}
}
@ -364,7 +363,7 @@ func (mem *CListMempool) isFull(txSize int) error {
)
if memSize >= mem.config.Size || int64(txSize)+txsBytes > mem.config.MaxTxsBytes {
return pubmempool.ErrMempoolIsFull{
return types.ErrMempoolIsFull{
NumTxs: memSize,
MaxTxs: mem.config.Size,
TxsBytes: txsBytes,


+ 3
- 4
internal/mempool/v0/clist_mempool_test.go View File

@ -23,7 +23,6 @@ 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 +81,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 pubmempool.IsPreCheckError(err) {
if types.IsPreCheckError(err) {
continue
}
t.Fatalf("CheckTx failed: %v while checking #%d tx", err, i)
@ -455,7 +454,7 @@ func TestMempool_CheckTxChecksTxSize(t *testing.T) {
if !testCase.err {
require.NoError(t, err, caseString)
} else {
require.Equal(t, err, pubmempool.ErrTxTooLarge{
require.Equal(t, err, types.ErrTxTooLarge{
Max: maxTxSize,
Actual: testCase.len,
}, caseString)
@ -503,7 +502,7 @@ func TestMempoolTxsBytes(t *testing.T) {
err = mp.CheckTx(context.Background(), []byte{0x05}, nil, mempool.TxInfo{})
if assert.Error(t, err) {
assert.IsType(t, pubmempool.ErrMempoolIsFull{}, err)
assert.IsType(t, types.ErrMempoolIsFull{}, err)
}
// 6. zero after tx is rechecked and removed due to not being valid anymore


+ 4
- 5
internal/mempool/v1/mempool.go View File

@ -14,7 +14,6 @@ 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"
)
@ -239,7 +238,7 @@ func (txmp *TxMempool) CheckTx(
txSize := len(tx)
if txSize > txmp.config.MaxTxBytes {
return pubmempool.ErrTxTooLarge{
return types.ErrTxTooLarge{
Max: txmp.config.MaxTxBytes,
Actual: txSize,
}
@ -247,7 +246,7 @@ func (txmp *TxMempool) CheckTx(
if txmp.preCheck != nil {
if err := txmp.preCheck(tx); err != nil {
return pubmempool.ErrPreCheck{
return types.ErrPreCheck{
Reason: err,
}
}
@ -267,7 +266,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 pubmempool.ErrTxInCache
return types.ErrTxInCache
}
txmp.logger.Debug("tx exists already in cache", "tx_hash", tx.Hash())
@ -728,7 +727,7 @@ func (txmp *TxMempool) canAddTx(wtx *WrappedTx) error {
)
if numTxs >= txmp.config.Size || int64(wtx.Size())+sizeBytes > txmp.config.MaxTxsBytes {
return pubmempool.ErrMempoolIsFull{
return types.ErrMempoolIsFull{
NumTxs: numTxs,
MaxTxs: txmp.config.Size,
TxsBytes: sizeBytes,


pkg/mempool/errors.go → types/mempool.go View File


Loading…
Cancel
Save