From edf3dbe00cc245fbc7f8590699f21da55db6cbd5 Mon Sep 17 00:00:00 2001 From: Matt Krump Date: Tue, 27 Mar 2018 16:16:27 -0500 Subject: [PATCH] Add starting block arg check --- cmd/sync.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/sync.go b/cmd/sync.go index 85dd33be..9f2ec0ad 100644 --- a/cmd/sync.go +++ b/cmd/sync.go @@ -59,17 +59,21 @@ func backFillAllBlocks(blockchain core.Blockchain, blockRepository datastore.Blo func sync() { ticker := time.NewTicker(pollingInterval) defer ticker.Stop() - blockchain := geth.NewBlockchain(ipc) - if blockchain.LastBlock().Int64() == 0 { + + lastBlock := blockchain.LastBlock().Int64() + if lastBlock == 0 { log.Fatal("geth initial: state sync not finished") } + _startingBlockNumber := int64(startingBlockNumber) + if _startingBlockNumber > lastBlock { + log.Fatal("starting block number > current block number") + } + db := utils.LoadPostgres(databaseConfig, blockchain.Node()) blockRepository := repositories.BlockRepository{DB: &db} validator := history.NewBlockValidator(blockchain, blockRepository, 15) - missingBlocksPopulated := make(chan int) - _startingBlockNumber := int64(startingBlockNumber) go backFillAllBlocks(blockchain, blockRepository, missingBlocksPopulated, _startingBlockNumber) for {