mirror of
https://github.com/btcsuite/btcd.git
synced 2024-11-19 09:50:08 +01:00
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:
parent
a254998bc5
commit
78b158dc56
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user