Reformat periodic block height ouput and add time.

Closes #9.
This commit is contained in:
Dave Collins 2013-10-10 18:24:23 -05:00
parent 9772626dd8
commit 3d62b24fe1

View file

@ -6,6 +6,7 @@ package main
import ( import (
"container/list" "container/list"
"fmt"
"github.com/conformal/btcchain" "github.com/conformal/btcchain"
"github.com/conformal/btcdb" "github.com/conformal/btcdb"
"github.com/conformal/btcutil" "github.com/conformal/btcutil"
@ -226,7 +227,7 @@ func (b *blockManager) handleDonePeerMsg(peers *list.List, p *peer) {
// logBlockHeight logs a new block height as an information message to show // logBlockHeight logs a new block height as an information message to show
// progress to the user. In order to prevent spam, it limits logging to one // progress to the user. In order to prevent spam, it limits logging to one
// message every 10 seconds with duration and totals included. // message every 10 seconds with duration and totals included.
func (b *blockManager) logBlockHeight(numTx, height int64) { func (b *blockManager) logBlockHeight(numTx, height int64, latestHash *btcwire.ShaHash) {
b.receivedLogBlocks++ b.receivedLogBlocks++
b.receivedLogTx += numTx b.receivedLogTx += numTx
@ -240,6 +241,13 @@ func (b *blockManager) logBlockHeight(numTx, height int64) {
durationMillis := int64(duration / time.Millisecond) durationMillis := int64(duration / time.Millisecond)
tDuration := 10 * time.Millisecond * time.Duration(durationMillis/10) tDuration := 10 * time.Millisecond * time.Duration(durationMillis/10)
// Attempt to get the timestamp of the latest block.
blockTimeStr := ""
block, err := b.server.db.FetchBlockBySha(latestHash)
if err == nil {
blockTimeStr = fmt.Sprintf(", %s", block.MsgBlock().Header.Timestamp)
}
// Log information about new block height. // Log information about new block height.
blockStr := "blocks" blockStr := "blocks"
if b.receivedLogBlocks == 1 { if b.receivedLogBlocks == 1 {
@ -249,9 +257,9 @@ func (b *blockManager) logBlockHeight(numTx, height int64) {
if b.receivedLogTx == 1 { if b.receivedLogTx == 1 {
txStr = "transaction" txStr = "transaction"
} }
log.Infof("BMGR: Processed %d %s (%d %s) in the last %s - Block "+ log.Infof("BMGR: Processed %d %s in the last %s (%d %s, height %d%s)",
"height %d", b.receivedLogBlocks, blockStr, b.receivedLogTx, b.receivedLogBlocks, blockStr, tDuration, b.receivedLogTx,
txStr, tDuration, height) txStr, height, blockTimeStr)
b.receivedLogBlocks = 0 b.receivedLogBlocks = 0
b.receivedLogTx = 0 b.receivedLogTx = 0
@ -350,12 +358,13 @@ func (b *blockManager) handleBlockMsg(bmsg *blockMsg) {
} }
// Log info about the new block height. // Log info about the new block height.
_, height, err := b.server.db.NewestSha() latestHash, height, err := b.server.db.NewestSha()
if err != nil { if err != nil {
log.Warnf("BMGR: Failed to obtain latest sha - %v", err) log.Warnf("BMGR: Failed to obtain latest sha - %v", err)
return return
} }
b.logBlockHeight(int64(len(bmsg.block.MsgBlock().Transactions)), height) b.logBlockHeight(int64(len(bmsg.block.MsgBlock().Transactions)), height,
latestHash)
// Sync the db to disk. // Sync the db to disk.
b.server.db.Sync() b.server.db.Sync()