network: update CMDUncknown

Closes #1135
This commit is contained in:
Anna Shaleva 2020-07-08 15:25:58 +03:00
parent f46ed798f0
commit db5b42b601
4 changed files with 15 additions and 7 deletions

View file

@ -538,6 +538,7 @@ func (s *Server) handleMempoolCmd(p Peer) error {
// handleInvCmd processes the received inventory.
func (s *Server) handleGetDataCmd(p Peer, inv *payload.Inventory) error {
var notFound []util.Uint256
for _, hash := range inv.Hashes {
var msg *Message
@ -546,11 +547,15 @@ func (s *Server) handleGetDataCmd(p Peer, inv *payload.Inventory) error {
tx, _, err := s.chain.GetTransaction(hash)
if err == nil {
msg = NewMessage(CMDTX, tx)
} else {
notFound = append(notFound, hash)
}
case payload.BlockType:
b, err := s.chain.GetBlock(hash)
if err == nil {
msg = NewMessage(CMDBlock, b)
} else {
notFound = append(notFound, hash)
}
case payload.ConsensusType:
if cp := s.consensus.GetPayload(hash); cp != nil {
@ -571,6 +576,9 @@ func (s *Server) handleGetDataCmd(p Peer, inv *payload.Inventory) error {
}
}
}
if len(notFound) != 0 {
return p.EnqueueP2PMessage(NewMessage(CMDNotFound, payload.NewInventory(inv.Type, notFound)))
}
return nil
}