mempool: make error throwing for CheckTx consistent (#8817)

This commit is contained in:
Callum Waters
2022-06-21 18:51:50 +02:00
committed by GitHub
parent 83526cacbc
commit 4322f7d0b9
2 changed files with 9 additions and 9 deletions
+2 -6
View File
@@ -242,17 +242,13 @@ func (mem *CListMempool) CheckTx(
// so we only record the sender for txs still in the mempool.
if e, ok := mem.txsMap.Load(tx.Key()); ok {
memTx := e.(*clist.CElement).Value.(*mempoolTx)
_, loaded := memTx.senders.LoadOrStore(txInfo.SenderID, true)
memTx.senders.LoadOrStore(txInfo.SenderID, true)
// TODO: consider punishing peer for dups,
// 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 types.ErrTxInCache
}
}
mem.logger.Debug("tx exists already in cache", "tx_hash", tx.Hash())
return nil
return types.ErrTxInCache
}
if ctx == nil {
+7 -3
View File
@@ -200,7 +200,7 @@ func TestMempoolUpdate(t *testing.T) {
err := mp.Update(1, []types.Tx{[]byte{0x01}}, abciResponses(1, abci.CodeTypeOK), nil, nil)
require.NoError(t, err)
err = mp.CheckTx(context.Background(), []byte{0x01}, nil, mempool.TxInfo{})
require.NoError(t, err)
assert.Error(t, err)
}
// 2. Removes valid txs from the mempool
@@ -305,11 +305,15 @@ func TestMempool_KeepInvalidTxsInCache(t *testing.T) {
// a must be added to the cache
err = mp.CheckTx(context.Background(), a, nil, mempool.TxInfo{})
require.NoError(t, err)
if assert.Error(t, err) {
assert.Equal(t, types.ErrTxInCache, err)
}
// b must remain in the cache
err = mp.CheckTx(context.Background(), b, nil, mempool.TxInfo{})
require.NoError(t, err)
if assert.Error(t, err) {
assert.Equal(t, types.ErrTxInCache, err)
}
}
// 2. An invalid transaction must remain in the cache