From 4cee2a48cc0df440e11bc4e68d057b205bbfd72f Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 17 Feb 2015 12:38:30 -0800 Subject: [PATCH] Separate addrindex tx fetch error messages * Decouple logging and handling of distinct error messages for cases of failed tx look up. * This also fixes a bug wherein the `addrindexer` failed to lookup a tx (since it didn't exist), but continued since the returned error was nil. --- chainindexer.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/chainindexer.go b/chainindexer.go index ed2fa440..7d8b274e 100644 --- a/chainindexer.go +++ b/chainindexer.go @@ -6,6 +6,7 @@ package main import ( "container/heap" + "fmt" "runtime" "sync" "sync/atomic" @@ -239,7 +240,7 @@ func (a *addrIndexer) indexManager() { addrIndex, err := a.indexBlockAddrs(indexJob.blk) if err != nil { adxrLog.Errorf("Unable to index transactions of"+ - " block %v", err) + " block: %v", err) a.server.Stop() goto fin } @@ -400,7 +401,7 @@ out: addrIndex, err := a.indexBlockAddrs(indexJob.blk) if err != nil { adxrLog.Errorf("Unable to index transactions of"+ - " block %v", err) + " block: %v", err) a.server.Stop() break out } @@ -467,9 +468,13 @@ func (a *addrIndexer) indexBlockAddrs(blk *btcutil.Block) (database.BlockAddrInd // Lookup and fetch the referenced output's tx. prevOut := txIn.PreviousOutPoint txList, err := a.server.db.FetchTxBySha(&prevOut.Hash) - if err != nil || len(txList) == 0 { - adxrLog.Errorf("Couldn't get referenced "+ - "txOut (%v): %v", prevOut, err) + if len(txList) == 0 { + return nil, fmt.Errorf("transaction %v not found", + prevOut.Hash) + } + if err != nil { + adxrLog.Errorf("Error fetching tx %v: %v", + prevOut.Hash, err) return nil, err } prevOutTx := txList[len(txList)-1]