From 938dfa1517afc469abfeb3249b297b4e03a5c48c Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 20 Jun 2014 08:35:14 -0500 Subject: [PATCH] Only log rollbacks for detached txstore blocks. Instead of logging whenever there is a chain fork + reorg, only log if a detached block affects the wallet in some manner. --- acctmgr.go | 2 -- txstore/tx.go | 9 +++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/acctmgr.go b/acctmgr.go index 82bedb3..0294b7a 100644 --- a/acctmgr.go +++ b/acctmgr.go @@ -619,8 +619,6 @@ func (am *AccountManager) RegisterNewAccount(a *Account) error { // Rollback rolls back each managed Account to the state before the block // specified by height and hash was connected to the main chain. func (am *AccountManager) Rollback(height int32, hash *btcwire.ShaHash) error { - log.Infof("Rolling back tx history since block height %v", height) - for _, a := range am.AllAccounts() { if err := a.TxStore.Rollback(height); err != nil { return err diff --git a/txstore/tx.go b/txstore/tx.go index 1dfb0d8..1076f13 100644 --- a/txstore/tx.go +++ b/txstore/tx.go @@ -808,6 +808,15 @@ func (s *Store) Rollback(height int32) error { detached := s.blocks[i:] s.blocks = s.blocks[:i] for _, b := range detached { + movedTxs := len(b.txs) + // Don't include coinbase transaction with number of moved txs. + // There should always be at least one tx in a block collection, + // and if there is a coinbase, it would be at index 0. + if b.txs[0].tx.Index() == 0 { + movedTxs-- + } + log.Infof("Rolling back block %d (%d transactions marked "+ + "unconfirmed)", b.Height, movedTxs) delete(s.blockIndexes, b.Block.Height) for _, r := range b.txs { oldTxIndex := r.Tx().Index()