Skip to content

Commit

Permalink
utxocache: Set new backend info with version one.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JoeGruffins committed Oct 13, 2022
1 parent 34be23d commit 3cfa737
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions internal/blockchain/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions internal/blockchain/utxobackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
Expand Down

0 comments on commit 3cfa737

Please sign in to comment.