OnBlockReceive receive block from net
(fromID uint64, blockSize uint32, block *types.Block, merkleRoot common.Uint256)
| 588 | |
| 589 | // OnBlockReceive receive block from net |
| 590 | func (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 |
| 619 | func (this *BlockSyncMgr) OnAddNode(nodeId uint64) { |
nothing calls this directly
no test coverage detected