core: add Close() to blockchainer, implement it to properly close chain
Before it the deferred function in Run() was actually never able to properly close the Store, so we weren't synching the latest state to the disk.
This commit is contained in:
parent
d33083e1e1
commit
b05754deac
8 changed files with 50 additions and 23 deletions
|
@ -154,14 +154,11 @@ func dumpDB(ctx *cli.Context) error {
|
|||
defer outStream.Close()
|
||||
writer := io.NewBinWriterFromIO(outStream)
|
||||
|
||||
grace, cancel := context.WithCancel(newGraceContext())
|
||||
defer cancel()
|
||||
|
||||
chain, err := initBlockChain(cfg)
|
||||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
go chain.Run(grace)
|
||||
go chain.Run()
|
||||
|
||||
chainHeight := chain.BlockHeight()
|
||||
if skip+count > chainHeight {
|
||||
|
@ -182,6 +179,7 @@ func dumpDB(ctx *cli.Context) error {
|
|||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
}
|
||||
chain.Close()
|
||||
return nil
|
||||
}
|
||||
func restoreDB(ctx *cli.Context) error {
|
||||
|
@ -204,14 +202,11 @@ func restoreDB(ctx *cli.Context) error {
|
|||
defer inStream.Close()
|
||||
reader := io.NewBinReaderFromIO(inStream)
|
||||
|
||||
grace, cancel := context.WithCancel(newGraceContext())
|
||||
defer cancel()
|
||||
|
||||
chain, err := initBlockChain(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
go chain.Run(grace)
|
||||
go chain.Run()
|
||||
|
||||
var allBlocks uint32
|
||||
reader.ReadLE(&allBlocks)
|
||||
|
@ -243,6 +238,7 @@ func restoreDB(ctx *cli.Context) error {
|
|||
return cli.NewExitError(fmt.Errorf("failed to add block %d: %s", i, err), 1)
|
||||
}
|
||||
}
|
||||
chain.Close()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -272,7 +268,7 @@ func startServer(ctx *cli.Context) error {
|
|||
errChan := make(chan error)
|
||||
monitoring := metrics.NewMetricsService(cfg.ApplicationConfiguration.Monitoring)
|
||||
|
||||
go chain.Run(grace)
|
||||
go chain.Run()
|
||||
go server.Start(errChan)
|
||||
go rpcServer.Start(errChan)
|
||||
go monitoring.Start()
|
||||
|
@ -295,6 +291,7 @@ Main:
|
|||
shutdownErr = errors.Wrap(serverErr, "Error encountered whilst shutting down server")
|
||||
}
|
||||
monitoring.ShutDown()
|
||||
chain.Close()
|
||||
break Main
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue