VDB-104 improve lightsync ui (#125)

* Return PopulateMissingHeaders early if the sync is at the head of the chain

* Squelch logging if no blocks to sync

* Fix broken test

* Refactor repository tests
This commit is contained in:
Edvard Hübinette
2018-12-14 12:11:48 +01:00
committed by GitHub
parent 670741616e
commit a3e8633aff
7 changed files with 97 additions and 99 deletions
+11 -4
View File
@@ -10,13 +10,20 @@ import (
func PopulateMissingHeaders(blockchain core.BlockChain, headerRepository datastore.HeaderRepository, startingBlockNumber int64) (int, error) {
lastBlock := blockchain.LastBlock().Int64()
blockRange := headerRepository.MissingBlockNumbers(startingBlockNumber, lastBlock, blockchain.Node().ID)
log.Printf("Backfilling %d blocks\n\n", len(blockRange))
_, err := RetrieveAndUpdateHeaders(blockchain, headerRepository, blockRange)
headerAlreadyExists, err := headerRepository.HeaderExists(lastBlock)
if err != nil {
return 0, err
} else if headerAlreadyExists {
return 0, nil
}
blockNumbers := headerRepository.MissingBlockNumbers(startingBlockNumber, lastBlock, blockchain.Node().ID)
log.Printf("Backfilling %d blocks\n\n", len(blockNumbers))
_, err = RetrieveAndUpdateHeaders(blockchain, headerRepository, blockNumbers)
if err != nil {
return 0, err
}
return len(blockRange), nil
return len(blockNumbers), nil
}
func RetrieveAndUpdateHeaders(chain core.BlockChain, headerRepository datastore.HeaderRepository, blockNumbers []int64) (int, error) {