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

Method OnBlockReceive

p2pserver/block_sync.go:590–616  ·  view source on GitHub ↗

OnBlockReceive receive block from net

(fromID uint64, blockSize uint32, block *types.Block,
	merkleRoot common.Uint256)

Source from the content-addressed store, hash-verified

588
589// OnBlockReceive receive block from net
590func (this *BlockSyncMgr) OnBlockReceive(fromID uint64, blockSize uint32, block *types.Block,
591 merkleRoot common.Uint256) {
592 height := block.Header.Height
593 blockHash := block.Hash()
594 log.Tracef("[p2p]OnBlockReceive Height:%d", height)
595 flightInfo := this.getFlightBlock(blockHash, fromID)
596 if flightInfo != nil {
597 t := (time.Now().UnixNano() - flightInfo.GetStartTime().UnixNano()) / int64(time.Millisecond)
598 s := float32(blockSize) / float32(t) * 1000.0 / 1024.0
599 this.addNewSpeed(fromID, s)
600 }
601
602 this.delFlightBlock(blockHash)
603 curHeaderHeight := this.ledger.GetCurrentHeaderHeight()
604 nextHeader := curHeaderHeight + 1
605 if height > nextHeader {
606 return
607 }
608 curBlockHeight := this.ledger.GetCurrentBlockHeight()
609 if height <= curBlockHeight {
610 return
611 }
612
613 this.addBlockCache(fromID, block, merkleRoot)
614 go this.saveBlock()
615 this.syncBlock()
616}
617
618//OnAddNode to node list when a new node added
619func (this *BlockSyncMgr) OnAddNode(nodeId uint64) {

Callers

nothing calls this directly

Calls 11

getFlightBlockMethod · 0.95
addNewSpeedMethod · 0.95
delFlightBlockMethod · 0.95
addBlockCacheMethod · 0.95
saveBlockMethod · 0.95
syncBlockMethod · 0.95
TracefFunction · 0.92
GetStartTimeMethod · 0.80
HashMethod · 0.65
GetCurrentBlockHeightMethod · 0.65

Tested by

no test coverage detected