Browse Source

mempool: don't return an error on checktx with the same tx (#6199)

callum/e2e-timeout
Callum Waters 4 years ago
committed by GitHub
parent
commit
90fe178b52
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 24 deletions
  1. +6
    -2
      mempool/clist_mempool.go
  2. +3
    -14
      mempool/clist_mempool_test.go
  3. +1
    -8
      test/app/counter_test.sh

+ 6
- 2
mempool/clist_mempool.go View File

@ -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()


+ 3
- 14
mempool/clist_mempool_test.go View File

@ -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)
}
}
}


+ 1
- 8
test/app/counter_test.sh View File

@ -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


Loading…
Cancel
Save