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().
This commit is contained in:
Roman Khimov 2019-10-21 11:05:10 +03:00
parent 70407f0c19
commit 07c2105aa5
2 changed files with 11 additions and 6 deletions

View file

@ -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")
}

View file

@ -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++ {