From 0d935b2717837b02465ef0daba1e1d2dc4fbf545 Mon Sep 17 00:00:00 2001 From: Ryan Staudt Date: Fri, 7 May 2021 13:50:52 -0500 Subject: [PATCH] blockchain: Flush UTXO DB after init utxoSetState. This forces the UTXO database to flush to disk after initializing the UTXO set state for the first time. This is necessary so that if the block database is flushed, and then an unclean shutdown occurs, the UTXO cache will know where to start from when recovering on startup. --- blockchain/utxocache.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/blockchain/utxocache.go b/blockchain/utxocache.go index cc13d317..a33cc9ef 100644 --- a/blockchain/utxocache.go +++ b/blockchain/utxocache.go @@ -717,6 +717,15 @@ func (c *UtxoCache) Initialize(b *BlockChain, tip *blockNode) error { if err != nil { return err } + + // Flush the UTXO database to persist the initialized state. This is + // necessary so that if the block database is flushed, and then an unclean + // shutdown occurs, the UTXO cache will know where to start from when + // recovering on startup. + err = c.db.Flush() + if err != nil { + return err + } } // Set the last flush hash and the last eviction height from the saved state