Browse Source

updates for new tmsp protobuf

pull/215/head
Ethan Buchman 8 years ago
parent
commit
7383ead106
3 changed files with 24 additions and 19 deletions
  1. +16
    -12
      mempool/mempool.go
  2. +4
    -3
      rpc/core/mempool.go
  3. +4
    -4
      state/execution.go

+ 16
- 12
mempool/mempool.go 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 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.


+ 4
- 3
rpc/core/mempool.go View File

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


+ 4
- 4
state/execution.go View File

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


Loading…
Cancel
Save