From 3cfa737b331c8a99b242e576a9266ba9b51b74c7 Mon Sep 17 00:00:00 2001 From: JoeGruff Date: Wed, 12 Oct 2022 16:57:46 +0900 Subject: [PATCH] utxocache: Set new backend info with version one. When starting a utxo database that does not have db info yet, the version must be the initial one so set as such rather than the current version. This ensures crucial updates are not skipped. --- internal/blockchain/compress.go | 4 ++++ internal/blockchain/utxobackend.go | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/internal/blockchain/compress.go b/internal/blockchain/compress.go index 4f3a542666..955cc8996e 100644 --- a/internal/blockchain/compress.go +++ b/internal/blockchain/compress.go @@ -13,6 +13,10 @@ import ( "github.com/decred/dcrd/txscript/v4" ) +// initialCompressionVersion is the initial script compression version of the +// database. +const initialCompressionVersion = 1 + // currentCompressionVersion is the current script compression version of the // database. const currentCompressionVersion = 1 diff --git a/internal/blockchain/utxobackend.go b/internal/blockchain/utxobackend.go index 47cd70c0fb..2442da6357 100644 --- a/internal/blockchain/utxobackend.go +++ b/internal/blockchain/utxobackend.go @@ -713,11 +713,23 @@ func (l *levelDbUtxoBackend) createUtxoBackendInfo(blockDBVersion uint32) error utxoVer = 1 } + // Utxo Backend info was added at blockDbVersion 9. Opening a db before + // that will make it here and the utxo database must go through + // updates. Both the utxo database version and compression version were + // 1 at that time. A blockDbVersion after 9 means this is a new empty + // database so the newest version is set. + utxoDatabaseVersion := 1 + compressionVersion := 1 + if blockDBVersion > 9 { + utxoDatabaseVersion = currentUtxoDatabaseVersion + compressionVersion = currentCompressionVersion + } + // Write the creation and version information to the database. return l.Update(func(tx UtxoBackendTx) error { return l.dbPutUtxoBackendInfo(tx, &UtxoBackendInfo{ - version: currentUtxoDatabaseVersion, - compVer: currentCompressionVersion, + version: uint32(utxoDatabaseVersion), + compVer: uint32(compressionVersion), utxoVer: utxoVer, created: time.Now(), })