Skip to content

Commit

Permalink
blockchain: get rid of database as an argument in fetchInputUtxos
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kcalvinalvin committed Mar 5, 2024
1 parent a254998 commit 78b158d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
6 changes: 3 additions & 3 deletions blockchain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 5 additions & 9 deletions blockchain/utxoviewpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,15 +666,11 @@ 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 {
return view.fetchUtxosFromCache(cache, view.findInputsToFetch(block))
}
// Request the input utxos from the cache.
return view.fetchUtxosMain(db, view.findInputsToFetch(block))
// 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))
}

// NewUtxoViewpoint returns a new empty unspent transaction output view.
Expand Down
2 changes: 1 addition & 1 deletion blockchain/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 78b158d

Please sign in to comment.