From 9f7625d6992e56fdd76dc0c88797964988bc68d2 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 6 Nov 2019 16:10:37 +0300 Subject: [PATCH] core: don't do useless DB reads if nothing was persisted --- pkg/core/blockchain.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index d33ee264a..ac8ca3365 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -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,