From ca7cb8c875463139b1fa8948ecb16b860c0ed713 Mon Sep 17 00:00:00 2001 From: "Owain G. Ainsworth" Date: Mon, 30 Sep 2013 23:43:14 +0100 Subject: [PATCH] move the intiial chain cache generation into bm. Blockmanager is otherwise the only current consumer of chain and it is messy to do it outside of it. --- blockmanager.go | 13 +++++++++++-- server.go | 8 ++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/blockmanager.go b/blockmanager.go index 08d7fb40..5e211ad2 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -545,7 +545,7 @@ func (b *blockManager) Stop() error { // newBlockManager returns a new bitcoin block manager. // Use Start to begin processing asynchronous block and inv updates. -func newBlockManager(s *server) *blockManager { +func newBlockManager(s *server) (*blockManager, error) { chainNotify := make(chan *btcchain.Notification) bm := blockManager{ server: s, @@ -562,7 +562,16 @@ func newBlockManager(s *server) *blockManager { quit: make(chan bool), } bm.blockChain.DisableVerify(cfg.VerifyDisabled) - return &bm + + log.Infof("[BMGR] Generating initial block node index. This may " + + "take a while...") + err := bm.blockChain.GenerateInitialIndex() + if err != nil { + return nil, err + } + log.Infof("[BMGR] Block index generation complete") + + return &bm, nil } // removeRegressionDB removes the existing regression test database if running diff --git a/server.go b/server.go index 95bfab2e..b9e0458d 100644 --- a/server.go +++ b/server.go @@ -608,15 +608,11 @@ func newServer(addr string, db btcdb.Db, btcnet btcwire.BitcoinNet) (*server, er quit: make(chan bool), db: db, } - s.blockManager = newBlockManager(&s) - - log.Infof("[BMGR] Generating initial block node index. This may " + - "take a while...") - err = s.blockManager.blockChain.GenerateInitialIndex() + bm, err := newBlockManager(&s) if err != nil { return nil, err } - log.Infof("[BMGR] Block index generation complete") + s.blockManager = bm if !cfg.DisableRPC { s.rpcServer, err = newRPCServer(&s)