diff --git a/cmd/geth/main.go b/cmd/geth/main.go index b789356dce7a..bd79bc64882d 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -360,7 +360,6 @@ func geth(ctx *cli.Context) error { // miner. func startNode(ctx *cli.Context, stack *node.Node) { debug.Memsize.Add("node", stack) - // Start up the node itself utils.StartNode(stack) diff --git a/eth/backend.go b/eth/backend.go index e4f98360dbee..95dbebe873b6 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -24,6 +24,7 @@ import ( "runtime" "sync" "sync/atomic" + "time" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -231,6 +232,15 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { return nil, err } + // Check for invalid shutdown + invalidShutdown, _ := chainDb.Get([]byte("unsafe-shutdown")) + if invalidShutdown != nil { + log.Error("unsafe shutdown detected", "time", string(invalidShutdown)) + } + // Create an invalid shutdown in database in case the app crashed + if err = chainDb.Put([]byte("unsafe-shutdown"), []byte(time.Now().String())); err != nil { + log.Warn("Failed to record possible future unsafe shutdown", "err", err) + } return eth, nil } @@ -567,6 +577,9 @@ func (s *Ethereum) Stop() error { s.lesServer.Stop() } + if err := s.chainDb.Delete([]byte("unsafe-shutdown")); err != nil { + log.Error("err", err) + } // Then stop everything else. s.bloomIndexer.Close() close(s.closeBloomHandler) diff --git a/les/client.go b/les/client.go index 34a654e22d1e..14fec7597e1e 100644 --- a/les/client.go +++ b/les/client.go @@ -168,6 +168,16 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) { log.Warn("Ultra light client is enabled", "trustedNodes", len(leth.handler.ulc.keys), "minTrustedFraction", leth.handler.ulc.fraction) leth.blockchain.DisableCheckFreq() } + + // Check for invalid shutdown + invalidShutdown, _ := chainDb.Get([]byte("unsafe-shutdown")) + if invalidShutdown != nil { + log.Error("unsafe shutdown detected", "time", string(invalidShutdown)) + } + // Create an invalid shutdown in database in case the app crashed + if err = chainDb.Put([]byte("unsafe-shutdown"), []byte(time.Now().String())); err != nil { + log.Warn("Failed to record possible future unsafe shutdown", "err", err) + } return leth, nil } @@ -303,6 +313,11 @@ func (s *LightEthereum) Stop() error { s.txPool.Stop() s.engine.Close() s.eventMux.Stop() + // Delete the unsafe shutdown from DB if shutting down safely + if err := s.chainDb.Delete([]byte("unsafe-shutdown")); err != nil { + log.Error("err", err) + } + s.chainDb.Close() s.wg.Wait() log.Info("Light ethereum stopped")