blockchain: get rid of database as an argument in fetchInputUtxos

Allowing the caller to fetch from either the database or the cache
resulted in inconsistencies if the cache were ever to be dirty.
Removing this option eliminates this problem.
This commit is contained in:
Calvin Kim 2024-03-06 02:42:33 +09:00
parent a254998bc5
commit 78b158dc56
3 changed files with 9 additions and 13 deletions

View File

@ -960,7 +960,7 @@ func (b *BlockChain) reorganizeChain(detachNodes, attachNodes *list.List) error
// Load all of the utxos referenced by the block that aren't
// already in the view.
err = view.fetchInputUtxos(nil, b.utxoCache, block)
err = view.fetchInputUtxos(b.utxoCache, block)
if err != nil {
return err
}
@ -1027,7 +1027,7 @@ func (b *BlockChain) reorganizeChain(detachNodes, attachNodes *list.List) error
// checkConnectBlock gets skipped, we still need to update the UTXO
// view.
if b.index.NodeStatus(n).KnownValid() {
err = view.fetchInputUtxos(nil, b.utxoCache, block)
err = view.fetchInputUtxos(b.utxoCache, block)
if err != nil {
return err
}
@ -1089,7 +1089,7 @@ func (b *BlockChain) reorganizeChain(detachNodes, attachNodes *list.List) error
// Load all of the utxos referenced by the block that aren't
// already in the view.
err := view.fetchInputUtxos(nil, b.utxoCache, block)
err := view.fetchInputUtxos(b.utxoCache, block)
if err != nil {
return err
}

View File

@ -666,16 +666,12 @@ func (view *UtxoViewpoint) findInputsToFetch(block *btcutil.Block) []wire.OutPoi
// fetchInputUtxos loads the unspent transaction outputs for the inputs
// referenced by the transactions in the given block into the view from the
// database or the cache as needed. In particular, referenced entries that
// are earlier in the block are added to the view and entries that are already
// in the view are not modified.
func (view *UtxoViewpoint) fetchInputUtxos(db database.DB, cache *utxoCache, block *btcutil.Block) error {
if cache != nil {
// cache as needed. In particular, referenced entries that are earlier in
// the block are added to the view and entries that are already in the view
// are not modified.
func (view *UtxoViewpoint) fetchInputUtxos(cache *utxoCache, block *btcutil.Block) error {
return view.fetchUtxosFromCache(cache, view.findInputsToFetch(block))
}
// Request the input utxos from the cache.
return view.fetchUtxosMain(db, view.findInputsToFetch(block))
}
// NewUtxoViewpoint returns a new empty unspent transaction output view.
func NewUtxoViewpoint() *UtxoViewpoint {

View File

@ -1084,7 +1084,7 @@ func (b *BlockChain) checkConnectBlock(node *blockNode, block *btcutil.Block, vi
//
// These utxo entries are needed for verification of things such as
// transaction inputs, counting pay-to-script-hashes, and scripts.
err := view.fetchInputUtxos(nil, b.utxoCache, block)
err := view.fetchInputUtxos(b.utxoCache, block)
if err != nil {
return err
}