core: don't do useless DB reads if nothing was persisted

This commit is contained in:
Roman Khimov 2019-11-06 16:10:37 +03:00
parent 90d4299f0b
commit 9f7625d699

View file

@ -492,18 +492,18 @@ func (bc *Blockchain) persist() error {
if err != nil {
return err
}
bHeight, err := storage.CurrentBlockHeight(bc.store)
if err != nil {
return err
}
oldHeight := atomic.SwapUint32(&bc.persistedHeight, bHeight)
diff := bHeight - oldHeight
storedHeaderHeight, _, err := storage.CurrentHeaderHeight(bc.store)
if err != nil {
return err
}
if persisted > 0 {
bHeight, err := storage.CurrentBlockHeight(bc.store)
if err != nil {
return err
}
oldHeight := atomic.SwapUint32(&bc.persistedHeight, bHeight)
diff := bHeight - oldHeight
storedHeaderHeight, _, err := storage.CurrentHeaderHeight(bc.store)
if err != nil {
return err
}
log.WithFields(log.Fields{
"persistedBlocks": diff,
"persistedKeys": persisted,