mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-08 06:15:33 +00:00
mempool: don't return an error on checktx with the same tx (#6199)
This commit is contained in:
@@ -277,13 +277,17 @@ func (mem *CListMempool) CheckTx(tx types.Tx, cb func(*abci.Response), txInfo Tx
|
||||
// so we only record the sender for txs still in the mempool.
|
||||
if e, ok := mem.txsMap.Load(TxKey(tx)); ok {
|
||||
memTx := e.(*clist.CElement).Value.(*mempoolTx)
|
||||
memTx.senders.LoadOrStore(txInfo.SenderID, true)
|
||||
_, loaded := 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 ErrTxInCache
|
||||
}
|
||||
}
|
||||
|
||||
return ErrTxInCache
|
||||
mem.logger.Debug("tx exists already in cache", "tx_hash", tx.Hash())
|
||||
return nil
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -190,9 +190,7 @@ func TestMempoolUpdate(t *testing.T) {
|
||||
err := mempool.Update(1, []types.Tx{[]byte{0x01}}, abciResponses(1, abci.CodeTypeOK), nil, nil)
|
||||
require.NoError(t, err)
|
||||
err = mempool.CheckTx([]byte{0x01}, nil, TxInfo{})
|
||||
if assert.Error(t, err) {
|
||||
assert.Equal(t, ErrTxInCache, err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
// 2. Removes valid txs from the mempool
|
||||
@@ -245,15 +243,11 @@ func TestMempool_KeepInvalidTxsInCache(t *testing.T) {
|
||||
|
||||
// a must be added to the cache
|
||||
err = mempool.CheckTx(a, nil, TxInfo{})
|
||||
if assert.Error(t, err) {
|
||||
assert.Equal(t, ErrTxInCache, err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
// b must remain in the cache
|
||||
err = mempool.CheckTx(b, nil, TxInfo{})
|
||||
if assert.Error(t, err) {
|
||||
assert.Equal(t, ErrTxInCache, err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
// 2. An invalid transaction must remain in the cache
|
||||
@@ -266,11 +260,6 @@ func TestMempool_KeepInvalidTxsInCache(t *testing.T) {
|
||||
|
||||
err := mempool.CheckTx(a, nil, TxInfo{})
|
||||
require.NoError(t, err)
|
||||
|
||||
err = mempool.CheckTx(a, nil, TxInfo{})
|
||||
if assert.Error(t, err) {
|
||||
assert.Equal(t, ErrTxInCache, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,14 +109,7 @@ if [[ $APPEND_TX_CODE != 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
echo "... sending tx. expect error"
|
||||
|
||||
# second time should get rejected by the mempool (return error and non-zero code)
|
||||
sendTx $TX true
|
||||
|
||||
|
||||
echo "... sending tx. expect no error"
|
||||
echo "... sending new tx. expect no error"
|
||||
|
||||
# now, TX=01 should pass, with no error
|
||||
TX=01
|
||||
|
||||
Reference in New Issue
Block a user