From 07c2105aa5b05d49b62454837f19ec33ed56032f Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 21 Oct 2019 11:05:10 +0300 Subject: [PATCH] core: log values from the store in persist() We're about stored values here, so print those, which avoids blocking in bc.HeaderHeight() and removes duplication between blockHeight and persistedHeight. Fixes saving the blockchain on exit (deferred function in Run() blocked in persist()). Test modification was required because storeBlocks() doesn't actually save headers and thus TestGetTransaction started to fail on persist(). --- pkg/core/blockchain.go | 9 ++++++--- pkg/core/blockchain_test.go | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 2946633ff..3cbf95afa 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -488,13 +488,16 @@ func (bc *Blockchain) persist() error { oldHeight := atomic.SwapUint32(&bc.persistedHeight, bHeight) diff := bHeight - oldHeight + storedHeaderHeight, _, err := storage.CurrentHeaderHeight(bc.store) + if err != nil { + return err + } if persisted > 0 { log.WithFields(log.Fields{ "persistedBlocks": diff, "persistedKeys": persisted, - "headerHeight": bc.HeaderHeight(), - "blockHeight": bc.BlockHeight(), - "persistedHeight": atomic.LoadUint32(&bc.persistedHeight), + "headerHeight": storedHeaderHeight, + "blockHeight": bHeight, "took": time.Since(start), }).Info("blockchain persist completed") } diff --git a/pkg/core/blockchain_test.go b/pkg/core/blockchain_test.go index 9e3b5a515..f99114893 100644 --- a/pkg/core/blockchain_test.go +++ b/pkg/core/blockchain_test.go @@ -134,10 +134,12 @@ func TestGetTransaction(t *testing.T) { b1 := getDecodedBlock(t, 1) block := getDecodedBlock(t, 2) bc := newTestChain(t) + // Turn verification off, because these blocks are really from some other chain + // and can't be verified, but we don't care about that in this test. + bc.config.VerifyBlocks = false - // These are from some kind of different chain, so can't be added via AddBlock(). - assert.Nil(t, bc.storeBlock(b1)) - assert.Nil(t, bc.storeBlock(block)) + assert.Nil(t, bc.AddBlock(b1)) + assert.Nil(t, bc.AddBlock(block)) // Test unpersisted and persisted access for j := 0; j < 2; j++ {