Replace glog.Fatal by glog.Error to allow to run deferred functions

This commit is contained in:
Martin Boehm 2018-03-01 11:22:37 +01:00
parent 34400f5b2b
commit 665a3d1230

View File

@ -125,14 +125,16 @@ func main() {
if *rollbackHeight >= 0 { if *rollbackHeight >= 0 {
bestHeight, _, err := index.GetBestBlock() bestHeight, _, err := index.GetBestBlock()
if err != nil { if err != nil {
glog.Fatalf("rollbackHeight: %v", err) glog.Error("rollbackHeight: ", err)
return
} }
if uint32(*rollbackHeight) > bestHeight { if uint32(*rollbackHeight) > bestHeight {
glog.Infof("nothing to rollback, rollbackHeight %d, bestHeight: %d", *rollbackHeight, bestHeight) glog.Infof("nothing to rollback, rollbackHeight %d, bestHeight: %d", *rollbackHeight, bestHeight)
} else { } else {
err = index.DisconnectBlocks(uint32(*rollbackHeight), bestHeight) err = index.DisconnectBlocks(uint32(*rollbackHeight), bestHeight)
if err != nil { if err != nil {
glog.Fatalf("rollbackHeight: %v", err) glog.Error("rollbackHeight: ", err)
return
} }
} }
return return
@ -140,7 +142,8 @@ func main() {
if *synchronize { if *synchronize {
if err := resyncIndex(nil); err != nil { if err := resyncIndex(nil); err != nil {
glog.Fatal("resyncIndex ", err) glog.Error("resyncIndex ", err)
return
} }
} }
@ -148,7 +151,8 @@ func main() {
if *httpServerBinding != "" { if *httpServerBinding != "" {
httpServer, err = server.NewHTTPServer(*httpServerBinding, *certFiles, index, mempool) httpServer, err = server.NewHTTPServer(*httpServerBinding, *certFiles, index, mempool)
if err != nil { if err != nil {
glog.Fatal("https: ", err) glog.Error("https: ", err)
return
} }
go func() { go func() {
err = httpServer.Run() err = httpServer.Run()
@ -156,7 +160,8 @@ func main() {
if err.Error() == "http: Server closed" { if err.Error() == "http: Server closed" {
glog.Info(err) glog.Info(err)
} else { } else {
glog.Fatal(err) glog.Error(err)
return
} }
} }
}() }()
@ -166,7 +171,8 @@ func main() {
if *socketIoBinding != "" { if *socketIoBinding != "" {
socketIoServer, err = server.NewSocketIoServer(*socketIoBinding, *certFiles, index, mempool, chain, *explorerURL) socketIoServer, err = server.NewSocketIoServer(*socketIoBinding, *certFiles, index, mempool, chain, *explorerURL)
if err != nil { if err != nil {
glog.Fatal("socketio: ", err) glog.Error("socketio: ", err)
return
} }
go func() { go func() {
err = socketIoServer.Run() err = socketIoServer.Run()
@ -174,7 +180,8 @@ func main() {
if err.Error() == "http: Server closed" { if err.Error() == "http: Server closed" {
glog.Info(err) glog.Info(err)
} else { } else {
glog.Fatal(err) glog.Error(err)
return
} }
} }
}() }()
@ -197,7 +204,8 @@ func main() {
} else { } else {
mq, err = bchain.NewMQ(*zeroMQBinding, mqHandler) mq, err = bchain.NewMQ(*zeroMQBinding, mqHandler)
if err != nil { if err != nil {
glog.Fatal("mq: ", err) glog.Error("mq: ", err)
return
} }
} }
} }
@ -213,10 +221,12 @@ func main() {
if address != "" { if address != "" {
script, err := bchain.AddressToOutputScript(address) script, err := bchain.AddressToOutputScript(address)
if err != nil { if err != nil {
glog.Fatalf("GetTransactions %v", err) glog.Error("GetTransactions ", err)
return
} }
if err = index.GetTransactions(script, height, until, printResult); err != nil { if err = index.GetTransactions(script, height, until, printResult); err != nil {
glog.Fatalf("GetTransactions %v", err) glog.Error("GetTransactions ", err)
return
} }
} else if !*synchronize { } else if !*synchronize {
if err = connectBlocksParallelInChunks( if err = connectBlocksParallelInChunks(
@ -225,7 +235,8 @@ func main() {
*syncChunk, *syncChunk,
*syncWorkers, *syncWorkers,
); err != nil { ); err != nil {
glog.Fatalf("connectBlocksParallelInChunks %v", err) glog.Error("connectBlocksParallelInChunks ", err)
return
} }
} }
} }
@ -271,7 +282,7 @@ func syncIndexLoop() {
// resync index about every 15 minutes if there are no chanSyncIndex requests, with debounce 1 second // resync index about every 15 minutes if there are no chanSyncIndex requests, with debounce 1 second
tickAndDebounce(resyncIndexPeriodMs*time.Millisecond, debounceResyncIndexMs*time.Millisecond, chanSyncIndex, func() { tickAndDebounce(resyncIndexPeriodMs*time.Millisecond, debounceResyncIndexMs*time.Millisecond, chanSyncIndex, func() {
if err := resyncIndex(onNewBlockHash); err != nil { if err := resyncIndex(onNewBlockHash); err != nil {
glog.Error("syncIndexLoop", err) glog.Error("syncIndexLoop ", errors.ErrorStack(err))
} }
}) })
glog.Info("syncIndexLoop stopped") glog.Info("syncIndexLoop stopped")
@ -289,7 +300,7 @@ func syncMempoolLoop() {
// resync mempool about every minute if there are no chanSyncMempool requests, with debounce 1 second // resync mempool about every minute if there are no chanSyncMempool requests, with debounce 1 second
tickAndDebounce(resyncMempoolPeriodMs*time.Millisecond, debounceResyncMempoolMs*time.Millisecond, chanSyncMempool, func() { tickAndDebounce(resyncMempoolPeriodMs*time.Millisecond, debounceResyncMempoolMs*time.Millisecond, chanSyncMempool, func() {
if err := mempool.Resync(onNewTxAddr); err != nil { if err := mempool.Resync(onNewTxAddr); err != nil {
glog.Error("syncMempoolLoop", err) glog.Error("syncMempoolLoop ", errors.ErrorStack(err))
} }
}) })
glog.Info("syncMempoolLoop stopped") glog.Info("syncMempoolLoop stopped")