VDB-302 Sleep when no missing blocks in lightSync (#129)

* Sleep when no missing blocks in lightSync

* Fix tests and error propagation

* Correct geth.log to logrus
This commit is contained in:
Edvard Hübinette
2019-01-11 10:58:41 +01:00
committed by GitHub
parent 77209d3b62
commit ebca338b1e
9 changed files with 83 additions and 30 deletions
+8 -1
View File
@@ -11,13 +11,20 @@ import (
func PopulateMissingHeaders(blockchain core.BlockChain, headerRepository datastore.HeaderRepository, startingBlockNumber int64) (int, error) {
lastBlock := blockchain.LastBlock().Int64()
headerAlreadyExists, err := headerRepository.HeaderExists(lastBlock)
if err != nil {
log.Error("Error in checking header in PopulateMissingHeaders: ", err)
return 0, err
} else if headerAlreadyExists {
return 0, nil
}
blockNumbers := headerRepository.MissingBlockNumbers(startingBlockNumber, lastBlock, blockchain.Node().ID)
blockNumbers, err := headerRepository.MissingBlockNumbers(startingBlockNumber, lastBlock, blockchain.Node().ID)
if err != nil {
log.Error("Error getting missing block numbers in PopulateMissingHeaders: ", err)
return 0, err
}
log.Printf("Backfilling %d blocks\n\n", len(blockNumbers))
_, err = RetrieveAndUpdateHeaders(blockchain, headerRepository, blockNumbers)
if err != nil {