()
| 422 | } |
| 423 | |
| 424 | func (this *BlockSyncMgr) syncHeader() { |
| 425 | if !this.server.reachMinConnection() { |
| 426 | return |
| 427 | } |
| 428 | if this.tryGetSyncHeaderLock() { |
| 429 | return |
| 430 | } |
| 431 | defer this.releaseSyncHeaderLock() |
| 432 | |
| 433 | if this.getFlightHeaderCount() >= SYNC_MAX_FLIGHT_HEADER_SIZE { |
| 434 | return |
| 435 | } |
| 436 | curBlockHeight := this.ledger.GetCurrentBlockHeight() |
| 437 | |
| 438 | curHeaderHeight := this.ledger.GetCurrentHeaderHeight() |
| 439 | //Waiting for block catch up header |
| 440 | if curHeaderHeight-curBlockHeight >= SYNC_MAX_HEADER_FORWARD_SIZE { |
| 441 | return |
| 442 | } |
| 443 | NextHeaderId := curHeaderHeight + 1 |
| 444 | reqNode := this.getNextNode(NextHeaderId) |
| 445 | if reqNode == nil { |
| 446 | return |
| 447 | } |
| 448 | this.addFlightHeader(reqNode.GetID(), NextHeaderId) |
| 449 | |
| 450 | headerHash := this.ledger.GetCurrentHeaderHash() |
| 451 | msg := msgpack.NewHeadersReq(headerHash) |
| 452 | err := this.server.Send(reqNode, msg, false) |
| 453 | if err != nil { |
| 454 | log.Warn("[p2p]syncHeader failed to send a new headersReq") |
| 455 | } else { |
| 456 | this.appendReqTime(reqNode.GetID()) |
| 457 | } |
| 458 | |
| 459 | log.Infof("Header sync request height:%d", NextHeaderId) |
| 460 | } |
| 461 | |
| 462 | func (this *BlockSyncMgr) syncBlock() { |
| 463 | if this.tryGetSyncBlockLock() { |
no test coverage detected