handleRsp handles the verified response from the validator and if the tx is valid, add it to the tx pool, or remove it from the pending list
(rsp *types.CheckResponse)
| 90 | // the tx is valid, add it to the tx pool, or remove it from the pending |
| 91 | // list |
| 92 | func (worker *txPoolWorker) handleRsp(rsp *types.CheckResponse) { |
| 93 | if rsp.WorkerId != worker.workId { |
| 94 | return |
| 95 | } |
| 96 | |
| 97 | worker.mu.Lock() |
| 98 | defer worker.mu.Unlock() |
| 99 | |
| 100 | pt, ok := worker.pendingTxList[rsp.Hash] |
| 101 | if !ok { |
| 102 | return |
| 103 | } |
| 104 | if rsp.ErrCode != errors.ErrNoError { |
| 105 | //Verify fail |
| 106 | log.Debugf("handleRsp: validator %d transaction %x invalid: %s", |
| 107 | rsp.Type, rsp.Hash, rsp.ErrCode.Error()) |
| 108 | delete(worker.pendingTxList, rsp.Hash) |
| 109 | worker.server.removePendingTx(rsp.Hash, rsp.ErrCode) |
| 110 | return |
| 111 | } |
| 112 | |
| 113 | if tc.STATEFUL_MASK&(0x1<<rsp.Type) != 0 && rsp.Height < worker.server.getHeight() { |
| 114 | // If validator's height is less than the required one, re-validate it. |
| 115 | worker.sendReq2StatefulV(pt.req) |
| 116 | pt.valTime = time.Now() |
| 117 | return |
| 118 | } |
| 119 | |
| 120 | if pt.flag&(0x1<<rsp.Type) == 0 { |
| 121 | retAttr := &tc.TXAttr{ |
| 122 | Height: rsp.Height, |
| 123 | Type: rsp.Type, |
| 124 | ErrCode: rsp.ErrCode, |
| 125 | } |
| 126 | pt.flag |= (0x1 << rsp.Type) |
| 127 | pt.ret = append(pt.ret, retAttr) |
| 128 | } |
| 129 | |
| 130 | if pt.flag&0xf == tc.VERIFY_MASK { |
| 131 | worker.putTxPool(pt) |
| 132 | delete(worker.pendingTxList, rsp.Hash) |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | /* Check if the transaction need to be sent to validator to verify |
| 137 | * when time out. |
no test coverage detected