Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error handling after check tx #178

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions mempool/clist_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,13 @@ func (mem *CListMempool) reqResCb(
panic("recheck cursor is not nil in reqResCb")
}

mem.resCbFirstTime(tx, peerID, peerP2PID, res)
err := mem.resCbFirstTime(tx, peerID, peerP2PID, res)
if err != nil {
if externalCb != nil {
externalCb(abci.ToResponseException(err.Error()))
}
return
}

// update metrics
mem.metrics.Size.Set(float64(mem.Size()))
Expand Down Expand Up @@ -394,11 +400,11 @@ func (mem *CListMempool) resCbFirstTime(
peerID uint16,
peerP2PID p2p.ID,
res *abci.Response,
) {
) error {
switch r := res.Value.(type) {
case *abci.Response_CheckTx:
var postCheckErr error
if mem.postCheck != nil {
if (r.CheckTx.Code == abci.CodeTypeOK) && mem.postCheck != nil {
postCheckErr = mem.postCheck(tx, r.CheckTx)
}
if (r.CheckTx.Code == abci.CodeTypeOK) && postCheckErr == nil {
Expand All @@ -408,7 +414,7 @@ func (mem *CListMempool) resCbFirstTime(
// remove from cache (mempool might have a space later)
mem.cache.Remove(tx)
mem.logger.Error(err.Error())
return
return err
}

memTx := &mempoolTx{
Expand All @@ -432,10 +438,13 @@ func (mem *CListMempool) resCbFirstTime(
mem.metrics.FailedTxs.Add(1)
// remove from cache (it might be good later)
mem.cache.Remove(tx)
return postCheckErr
}
default:
// ignore other messages
}

return nil
}

// callback, which is called after the app rechecked the tx.
Expand Down
9 changes: 9 additions & 0 deletions rpc/core/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func BroadcastTxSync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcas
return nil, err
}
res := <-resCh
except := res.GetException()
if except != nil {
return nil, fmt.Errorf(except.Error)
}
r := res.GetCheckTx()
return &ctypes.ResultBroadcastTx{
Code: r.Code,
Expand Down Expand Up @@ -84,6 +88,11 @@ func BroadcastTxCommit(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadc
return nil, fmt.Errorf("error on broadcastTxCommit: %v", err)
}
checkTxResMsg := <-checkTxResCh
checkTxExcept := checkTxResMsg.GetException()
if checkTxExcept != nil {
env.Logger.Error("Error on broadcastTxCommit", "err", checkTxExcept.Error)
return nil, fmt.Errorf("error on broadcastTxCommit: %v", checkTxExcept.Error)
}
checkTxRes := checkTxResMsg.GetCheckTx()
if checkTxRes.Code != abci.CodeTypeOK {
return &ctypes.ResultBroadcastTxCommit{
Expand Down