MCPcopy Create free account
hub / github.com/DNAProject/DNA / syncHeader

Method syncHeader

p2pserver/block_sync.go:424–460  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

422}
423
424func (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
462func (this *BlockSyncMgr) syncBlock() {
463 if this.tryGetSyncBlockLock() {

Callers 2

syncMethod · 0.95
OnHeaderReceiveMethod · 0.95

Calls 14

tryGetSyncHeaderLockMethod · 0.95
releaseSyncHeaderLockMethod · 0.95
getFlightHeaderCountMethod · 0.95
getNextNodeMethod · 0.95
addFlightHeaderMethod · 0.95
appendReqTimeMethod · 0.95
WarnFunction · 0.92
InfofFunction · 0.92
reachMinConnectionMethod · 0.80
GetCurrentBlockHeightMethod · 0.65
GetIDMethod · 0.65

Tested by

no test coverage detected