blockchain/indexers: ensure the cfindex gets inputs

This commit is contained in:
Olaoluwa Osuntokun 2018-07-06 12:38:17 -07:00
parent 102ca293f6
commit 298efd8359
No known key found for this signature in database
GPG key ID: 964EA263DD637C21
2 changed files with 11 additions and 36 deletions

View file

@ -83,6 +83,17 @@ type CfIndex struct {
// Ensure the CfIndex type implements the Indexer interface. // Ensure the CfIndex type implements the Indexer interface.
var _ Indexer = (*CfIndex)(nil) var _ Indexer = (*CfIndex)(nil)
// Ensure the CfIndex type implements the NeedsInputser interface.
var _ NeedsInputser = (*CfIndex)(nil)
// NeedsInputs signals that the index requires the referenced inputs in order
// to properly create the index.
//
// This implements the NeedsInputser interface.
func (idx *CfIndex) NeedsInputs() bool {
return true
}
// Init initializes the hash-based cf index. This is part of the Indexer // Init initializes the hash-based cf index. This is part of the Indexer
// interface. // interface.
func (idx *CfIndex) Init() error { func (idx *CfIndex) Init() error {

View file

@ -494,42 +494,6 @@ func dbFetchTx(dbTx database.Tx, hash *chainhash.Hash) (*wire.MsgTx, error) {
return &msgTx, nil return &msgTx, nil
} }
// makeUtxoView creates a mock unspent transaction output view by using the
// transaction index in order to look up all inputs referenced by the
// transactions in the block. This is sometimes needed when catching indexes up
// because many of the txouts could actually already be spent however the
// associated scripts are still required to index them.
func makeUtxoView(dbTx database.Tx, block *btcutil.Block, interrupt <-chan struct{}) (*blockchain.UtxoViewpoint, error) {
view := blockchain.NewUtxoViewpoint()
for txIdx, tx := range block.Transactions() {
// Coinbases do not reference any inputs. Since the block is
// required to have already gone through full validation, it has
// already been proven on the first transaction in the block is
// a coinbase.
if txIdx == 0 {
continue
}
// Use the transaction index to load all of the referenced
// inputs and add their outputs to the view.
for _, txIn := range tx.MsgTx().TxIn {
originOut := &txIn.PreviousOutPoint
originTx, err := dbFetchTx(dbTx, &originOut.Hash)
if err != nil {
return nil, err
}
view.AddTxOuts(btcutil.NewTx(originTx), 0)
}
if interruptRequested(interrupt) {
return nil, errInterruptRequested
}
}
return view, nil
}
// ConnectBlock must be invoked when a block is extending the main chain. It // ConnectBlock must be invoked when a block is extending the main chain. It
// keeps track of the state of each index it is managing, performs some sanity // keeps track of the state of each index it is managing, performs some sanity
// checks, and invokes each indexer. // checks, and invokes each indexer.