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 12, 2022
1 parent 34be23d commit 88f3b03
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 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
9 changes: 6 additions & 3 deletions internal/blockchain/utxobackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
)

const (
// initialUtxoDatabaseVersion indicates the initial UTXO database version.
initialUtxoDatabaseVersion = 1

// currentUtxoDatabaseVersion indicates the current UTXO database version.
currentUtxoDatabaseVersion = 3

Expand Down Expand Up @@ -716,8 +719,8 @@ func (l *levelDbUtxoBackend) createUtxoBackendInfo(blockDBVersion uint32) error
// 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: initialUtxoDatabaseVersion,
compVer: initialCompressionVersion,
utxoVer: utxoVer,
created: time.Now(),
})
Expand Down Expand Up @@ -829,7 +832,7 @@ func (l *levelDbUtxoBackend) PutUtxos(utxos map[wire.OutPoint]*UtxoEntry,
}

// Upgrade upgrades the UTXO backend by applying all possible upgrades
// iteratively as needed.
// iteractively as needed.
func (l *levelDbUtxoBackend) Upgrade(ctx context.Context, b *BlockChain) error {
// Upgrade the UTXO database as needed.
return upgradeUtxoDb(ctx, b.db, l)
Expand Down

0 comments on commit 88f3b03

Please sign in to comment.