From 7383ead106f1cc67a78a38a4d5b66379acfc802b Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sat, 14 May 2016 12:33:27 -0400 Subject: [PATCH] updates for new tmsp protobuf --- mempool/mempool.go | 28 ++++++++++++++++------------ rpc/core/mempool.go | 7 ++++--- state/execution.go | 8 ++++---- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/mempool/mempool.go b/mempool/mempool.go index 638e17013..87a185ef2 100644 --- a/mempool/mempool.go +++ b/mempool/mempool.go @@ -112,8 +112,12 @@ func (mem *Mempool) CheckTx(tx types.Tx, cb func(*tmsp.Response)) (err error) { if _, exists := mem.cacheMap[string(tx)]; exists { if cb != nil { cb(&tmsp.Response{ - Code: tmsp.CodeType_BadNonce, // TODO or duplicate tx - Log: "Duplicate transaction (ignored)", + Value: &tmsp.Response_CheckTx{ + &tmsp.ResponseCheckTx{ + Code: tmsp.CodeType_BadNonce, // TODO or duplicate tx + Log: "Duplicate transaction (ignored)", + }, + }, }) } return nil @@ -150,18 +154,18 @@ func (mem *Mempool) resCb(req *tmsp.Request, res *tmsp.Response) { } func (mem *Mempool) resCbNormal(req *tmsp.Request, res *tmsp.Response) { - switch res.Type { - case tmsp.MessageType_CheckTx: - if res.Code == tmsp.CodeType_OK { + switch r := res.Value.(type) { + case *tmsp.Response_CheckTx: + if r.CheckTx.Code == tmsp.CodeType_OK { mem.counter++ memTx := &mempoolTx{ counter: mem.counter, height: int64(mem.height), - tx: req.Data, + tx: req.GetCheckTx().Tx, } mem.txs.PushBack(memTx) } else { - log.Info("Bad Transaction", "res", res) + log.Info("Bad Transaction", "res", r) // ignore bad transaction // TODO: handle other retcodes } @@ -171,14 +175,14 @@ func (mem *Mempool) resCbNormal(req *tmsp.Request, res *tmsp.Response) { } func (mem *Mempool) resCbRecheck(req *tmsp.Request, res *tmsp.Response) { - switch res.Type { - case tmsp.MessageType_CheckTx: + switch r := res.Value.(type) { + case *tmsp.Response_CheckTx: memTx := mem.recheckCursor.Value.(*mempoolTx) - if !bytes.Equal(req.Data, memTx.tx) { + if !bytes.Equal(req.GetCheckTx().Tx, memTx.tx) { PanicSanity(Fmt("Unexpected tx response from proxy during recheck\n"+ - "Expected %X, got %X", req.Data, memTx.tx)) + "Expected %X, got %X", r.CheckTx.Data, memTx.tx)) } - if res.Code == tmsp.CodeType_OK { + if r.CheckTx.Code == tmsp.CodeType_OK { // Good, nothing to do. } else { // Tx became invalidated due to newly committed block. diff --git a/rpc/core/mempool.go b/rpc/core/mempool.go index d06fca8b2..b0e5c0c43 100644 --- a/rpc/core/mempool.go +++ b/rpc/core/mempool.go @@ -28,10 +28,11 @@ func BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) { return nil, fmt.Errorf("Error broadcasting transaction: %v", err) } res := <-resCh + r := res.GetCheckTx() return &ctypes.ResultBroadcastTx{ - Code: res.Code, - Data: res.Data, - Log: res.Log, + Code: r.Code, + Data: r.Data, + Log: r.Log, }, nil } diff --git a/state/execution.go b/state/execution.go index d2b027c84..230bceb29 100644 --- a/state/execution.go +++ b/state/execution.go @@ -61,16 +61,16 @@ func (s *State) execBlockOnProxyApp(evsw *events.EventSwitch, proxyAppConn proxy // Execute transactions and get hash proxyCb := func(req *tmsp.Request, res *tmsp.Response) { - switch res.Type { - case tmsp.MessageType_AppendTx: + switch r := res.Value.(type) { + case *tmsp.Response_AppendTx: // TODO: make use of res.Log // TODO: make use of this info // Blocks may include invalid txs. // reqAppendTx := req.(tmsp.RequestAppendTx) - if res.Code == tmsp.CodeType_OK { + if r.AppendTx.Code == tmsp.CodeType_OK { validTxs += 1 } else { - log.Debug("Invalid tx", "code", res.Code, "log", res.Log) + log.Debug("Invalid tx", "code", r.AppendTx.Code, "log", r.AppendTx.Log) invalidTxs += 1 } }