updates for new tmsp protobuf

This commit is contained in:
Ethan Buchman 2016-05-14 12:33:27 -04:00
parent b2e612fb79
commit 7383ead106
3 changed files with 24 additions and 19 deletions

View File

@ -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 _, exists := mem.cacheMap[string(tx)]; exists {
if cb != nil { if cb != nil {
cb(&tmsp.Response{ cb(&tmsp.Response{
Value: &tmsp.Response_CheckTx{
&tmsp.ResponseCheckTx{
Code: tmsp.CodeType_BadNonce, // TODO or duplicate tx Code: tmsp.CodeType_BadNonce, // TODO or duplicate tx
Log: "Duplicate transaction (ignored)", Log: "Duplicate transaction (ignored)",
},
},
}) })
} }
return nil 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) { func (mem *Mempool) resCbNormal(req *tmsp.Request, res *tmsp.Response) {
switch res.Type { switch r := res.Value.(type) {
case tmsp.MessageType_CheckTx: case *tmsp.Response_CheckTx:
if res.Code == tmsp.CodeType_OK { if r.CheckTx.Code == tmsp.CodeType_OK {
mem.counter++ mem.counter++
memTx := &mempoolTx{ memTx := &mempoolTx{
counter: mem.counter, counter: mem.counter,
height: int64(mem.height), height: int64(mem.height),
tx: req.Data, tx: req.GetCheckTx().Tx,
} }
mem.txs.PushBack(memTx) mem.txs.PushBack(memTx)
} else { } else {
log.Info("Bad Transaction", "res", res) log.Info("Bad Transaction", "res", r)
// ignore bad transaction // ignore bad transaction
// TODO: handle other retcodes // 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) { func (mem *Mempool) resCbRecheck(req *tmsp.Request, res *tmsp.Response) {
switch res.Type { switch r := res.Value.(type) {
case tmsp.MessageType_CheckTx: case *tmsp.Response_CheckTx:
memTx := mem.recheckCursor.Value.(*mempoolTx) 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"+ 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. // Good, nothing to do.
} else { } else {
// Tx became invalidated due to newly committed block. // Tx became invalidated due to newly committed block.

View File

@ -28,10 +28,11 @@ func BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
return nil, fmt.Errorf("Error broadcasting transaction: %v", err) return nil, fmt.Errorf("Error broadcasting transaction: %v", err)
} }
res := <-resCh res := <-resCh
r := res.GetCheckTx()
return &ctypes.ResultBroadcastTx{ return &ctypes.ResultBroadcastTx{
Code: res.Code, Code: r.Code,
Data: res.Data, Data: r.Data,
Log: res.Log, Log: r.Log,
}, nil }, nil
} }

View File

@ -61,16 +61,16 @@ func (s *State) execBlockOnProxyApp(evsw *events.EventSwitch, proxyAppConn proxy
// Execute transactions and get hash // Execute transactions and get hash
proxyCb := func(req *tmsp.Request, res *tmsp.Response) { proxyCb := func(req *tmsp.Request, res *tmsp.Response) {
switch res.Type { switch r := res.Value.(type) {
case tmsp.MessageType_AppendTx: case *tmsp.Response_AppendTx:
// TODO: make use of res.Log // TODO: make use of res.Log
// TODO: make use of this info // TODO: make use of this info
// Blocks may include invalid txs. // Blocks may include invalid txs.
// reqAppendTx := req.(tmsp.RequestAppendTx) // reqAppendTx := req.(tmsp.RequestAppendTx)
if res.Code == tmsp.CodeType_OK { if r.AppendTx.Code == tmsp.CodeType_OK {
validTxs += 1 validTxs += 1
} else { } 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 invalidTxs += 1
} }
} }