mirror of
https://github.com/btcsuite/btcd.git
synced 2026-08-20 13:27:31 +02:00
blockchain: Add utxoStateConsistency read and write functions
This change is part of the effort to add utxocache support to btcd. The utxoStateConsistency indicates what the last block that the utxo cache got flush at. This is useful for recovery purposes as if the node is unexpectdly shut down, we know which block to start rebuilding the utxo state from.
This commit is contained in:
parent
27cf70216f
commit
fc65744134
1 changed files with 19 additions and 0 deletions
|
|
@ -51,6 +51,10 @@ var (
|
|||
// chain state.
|
||||
chainStateKeyName = []byte("chainstate")
|
||||
|
||||
// utxoStateConsistencyKeyName is the name of the db key used to store the
|
||||
// consistency status of the utxo state.
|
||||
utxoStateConsistencyKeyName = []byte("utxostateconsistency")
|
||||
|
||||
// spendJournalVersionKeyName is the name of the db key used to store
|
||||
// the version of the spend journal currently in the database.
|
||||
spendJournalVersionKeyName = []byte("spendjournalversion")
|
||||
|
|
@ -1014,6 +1018,21 @@ func dbPutBestState(dbTx database.Tx, snapshot *BestState, workSum *big.Int) err
|
|||
return dbTx.Metadata().Put(chainStateKeyName, serializedData)
|
||||
}
|
||||
|
||||
// dbPutUtxoStateConsistency uses an existing database transaction to
|
||||
// update the utxo state consistency status with the given parameters.
|
||||
func dbPutUtxoStateConsistency(dbTx database.Tx, hash *chainhash.Hash) error {
|
||||
// Store the utxo state consistency status into the database.
|
||||
return dbTx.Metadata().Put(utxoStateConsistencyKeyName, hash[:])
|
||||
}
|
||||
|
||||
// dbFetchUtxoStateConsistency uses an existing database transaction to retrieve
|
||||
// the utxo state consistency status from the database. The code is 0 when
|
||||
// nothing was found.
|
||||
func dbFetchUtxoStateConsistency(dbTx database.Tx) []byte {
|
||||
// Fetch the serialized data from the database.
|
||||
return dbTx.Metadata().Get(utxoStateConsistencyKeyName)
|
||||
}
|
||||
|
||||
// createChainState initializes both the database and the chain state to the
|
||||
// genesis block. This includes creating the necessary buckets and inserting
|
||||
// the genesis block, so it must only be called on an uninitialized database.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue