Add a few log error messages.

In addition to returning errors to the caller, log the error with a prefix
in a few key places that helps identify the origin for errors.  In some
cases, the underlying error comes from a different subsystem such as the
SQL database driver and the error messages can be fairly generic.
This commit is contained in:
Dave Collins 2013-07-24 12:31:14 -05:00
parent f219ed5baf
commit 1deeb05627
2 changed files with 5 additions and 0 deletions

View file

@ -19,6 +19,7 @@ func (b *BlockChain) maybeAcceptBlock(block *btcutil.Block) error {
// if this is the genesis block.
prevNode, err := b.getPrevNodeFromBlock(block)
if err != nil {
log.Errorf("getPrevNodeFromBlock: %v", err)
return err
}
@ -34,6 +35,7 @@ func (b *BlockChain) maybeAcceptBlock(block *btcutil.Block) error {
blockHeader := block.MsgBlock().Header
expectedDifficulty, err := b.calcNextRequiredDifficulty(prevNode, block)
if err != nil {
log.Errorf("calcNextRequiredDifficulty: %v", err)
return err
}
blockDifficulty := blockHeader.Bits
@ -47,6 +49,7 @@ func (b *BlockChain) maybeAcceptBlock(block *btcutil.Block) error {
// the last several blocks (medianTimeBlocks).
medianTime, err := b.calcPastMedianTime(prevNode)
if err != nil {
log.Errorf("calcPastMedianTime: %v", err)
return err
}
if !blockHeader.Timestamp.After(medianTime) {
@ -147,6 +150,7 @@ func (b *BlockChain) maybeAcceptBlock(block *btcutil.Block) error {
// also handles validation of the transaction scripts.
err = b.connectBestChain(newNode, block)
if err != nil {
log.Errorf("connectBestChain: %v", err)
return err
}

View file

@ -413,6 +413,7 @@ func (b *BlockChain) calcPastMedianTime(startNode *blockNode) (time.Time, error)
var err error
iterNode, err = b.getPrevNodeFromNode(iterNode)
if err != nil {
log.Errorf("getPrevNodeFromNode: %v", err)
return time.Time{}, err
}
}