Skip to content

Commit

Permalink
blockchain: Remove error from LatestBlockLocator.
Browse files Browse the repository at this point in the history
This removes the error return from the LatestBlockLocator function since
it can never fail and ends up causing unneeded error checking.
  • Loading branch information
davecgh committed Jan 11, 2021
1 parent 9568d1a commit c715121
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
4 changes: 2 additions & 2 deletions blockchain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1886,11 +1886,11 @@ func (b *BlockChain) BlockLocatorFromHash(hash *chainhash.Hash) BlockLocator {
// main (best) chain.
//
// This function is safe for concurrent access.
func (b *BlockChain) LatestBlockLocator() (BlockLocator, error) {
func (b *BlockChain) LatestBlockLocator() BlockLocator {
b.chainLock.RLock()
locator := b.bestChain.BlockLocator(nil)
b.chainLock.RUnlock()
return locator, nil
return locator
}

// extractDeploymentIDVersions returns a map of all deployment IDs within the
Expand Down
20 changes: 5 additions & 15 deletions internal/netsync/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,7 @@ func (m *SyncManager) startSync() {
// to send.
m.requestedBlocks = make(map[chainhash.Hash]struct{})

blkLocator, err := m.cfg.Chain.LatestBlockLocator()
if err != nil {
log.Errorf("Failed to get block locator for the latest block: %v",
err)
return
}
blkLocator := m.cfg.Chain.LatestBlockLocator()
locator := chainBlockLocatorToHashes(blkLocator)

log.Infof("Syncing to block height %d from peer %v",
Expand Down Expand Up @@ -1009,17 +1004,12 @@ func (m *SyncManager) handleBlockMsg(bmsg *blockMsg) {
onMainChain := !isOrphan && forkLen == 0
if isOrphan {
orphanRoot := m.orphanRoot(blockHash)
blkLocator, err := m.cfg.Chain.LatestBlockLocator()
blkLocator := m.cfg.Chain.LatestBlockLocator()
locator := chainBlockLocatorToHashes(blkLocator)
err := peer.PushGetBlocksMsg(locator, orphanRoot)
if err != nil {
log.Warnf("Failed to get block locator for the latest block: %v",
log.Warnf("Failed to push getblocksmsg for the latest block: %v",
err)
} else {
locator := chainBlockLocatorToHashes(blkLocator)
err = peer.PushGetBlocksMsg(locator, orphanRoot)
if err != nil {
log.Warnf("Failed to push getblocksmsg for the latest block: "+
"%v", err)
}
}
} else {
// When the block is not an orphan, log information about it and
Expand Down

0 comments on commit c715121

Please sign in to comment.