mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-29 16:52:15 +00:00
mempool: return error on cached txs
This commit is contained in:
parent
388f66c9b3
commit
c9be2b89f9
@ -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 {
|
return fmt.Errorf("Tx already exists in cache")
|
||||||
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 (?)
|
|
||||||
}
|
}
|
||||||
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…
x
Reference in New Issue
Block a user