Browse Source

mempool: return error on cached txs

pull/918/head
Ethan Buchman 7 years ago
parent
commit
c9be2b89f9
1 changed files with 4 additions and 13 deletions
  1. +4
    -13
      mempool/mempool.go

+ 4
- 13
mempool/mempool.go View File

@ -3,6 +3,7 @@ package mempool
import ( import (
"bytes" "bytes"
"container/list" "container/list"
"fmt"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
@ -191,17 +192,7 @@ func (mem *Mempool) CheckTx(tx types.Tx, cb func(*abci.Response)) (err error) {
// CACHE // CACHE
if mem.cache.Exists(tx) { if mem.cache.Exists(tx) {
if cb != nil {
cb(&abci.Response{
Value: &abci.Response_CheckTx{
&abci.ResponseCheckTx{
Code: abci.CodeType_BadNonce, // TODO or duplicate tx
Log: "Duplicate transaction (ignored)",
},
},
})
}
return nil // TODO: return an error (?)
return fmt.Errorf("Tx already exists in cache")
} }
mem.cache.Push(tx) mem.cache.Push(tx)
// END CACHE // END CACHE
@ -245,7 +236,7 @@ func (mem *Mempool) resCbNormal(req *abci.Request, res *abci.Response) {
switch r := res.Value.(type) { switch r := res.Value.(type) {
case *abci.Response_CheckTx: case *abci.Response_CheckTx:
tx := req.GetCheckTx().Tx tx := req.GetCheckTx().Tx
if r.CheckTx.Code == abci.CodeType_OK {
if r.CheckTx.Code == abci.CodeTypeOK {
mem.counter++ mem.counter++
memTx := &mempoolTx{ memTx := &mempoolTx{
counter: mem.counter, counter: mem.counter,
@ -277,7 +268,7 @@ func (mem *Mempool) resCbRecheck(req *abci.Request, res *abci.Response) {
cmn.PanicSanity(cmn.Fmt("Unexpected tx response from proxy during recheck\n"+ cmn.PanicSanity(cmn.Fmt("Unexpected tx response from proxy during recheck\n"+
"Expected %X, got %X", r.CheckTx.Data, memTx.tx)) "Expected %X, got %X", r.CheckTx.Data, memTx.tx))
} }
if r.CheckTx.Code == abci.CodeType_OK {
if r.CheckTx.Code == abci.CodeTypeOK {
// Good, nothing to do. // Good, nothing to do.
} else { } else {
// Tx became invalidated due to newly committed block. // Tx became invalidated due to newly committed block.


Loading…
Cancel
Save