From 83e27ae7dbfdca779e9f6b7db148fb295481030e Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Tue, 17 Jun 2014 08:38:34 -0500 Subject: [PATCH] Remove unused goroutine. --- cmd.go | 3 --- rpcclient.go | 13 ----------- rpcserver.go | 62 ---------------------------------------------------- 3 files changed, 78 deletions(-) diff --git a/cmd.go b/cmd.go index 909371e..e1bd652 100644 --- a/cmd.go +++ b/cmd.go @@ -185,9 +185,6 @@ func main() { go StoreNotifiedMempoolRecvTxs(NotifiedRecvTxChans.add, NotifiedRecvTxChans.remove, NotifiedRecvTxChans.access) - go NotifyBalanceSyncer(NotifyBalanceSyncerChans.add, - NotifyBalanceSyncerChans.remove, - NotifyBalanceSyncerChans.access) // Start client connection to a btcd chain server. Attempt // reconnections if the client could not be successfully connected. diff --git a/rpcclient.go b/rpcclient.go index fe2ad22..2d56510 100644 --- a/rpcclient.go +++ b/rpcclient.go @@ -127,19 +127,6 @@ func (n blockConnected) handleNotification() error { curBlock.BlockStamp = *bs curBlock.Unlock() - // btcd notifies btcwallet about transactions first, and then sends - // the new block notification. New balance notifications for txs - // in blocks are therefore sent here after all tx notifications - // have arrived and finished being processed by the handlers. - workers := NotifyBalanceRequest{ - block: *n.hash, - wg: make(chan *sync.WaitGroup), - } - NotifyBalanceSyncerChans.access <- workers - if wg := <-workers.wg; wg != nil { - wg.Wait() - NotifyBalanceSyncerChans.remove <- *n.hash - } AcctMgr.Grab() AcctMgr.BlockNotify(bs) AcctMgr.Release() diff --git a/rpcserver.go b/rpcserver.go index ce6dfa0..3f98191 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -2734,65 +2734,3 @@ func StoreNotifiedMempoolRecvTxs(add, remove chan btcwire.OutPoint, } } } - -// NotifyBalanceSyncerChans holds channels for accessing -// the NotifyBalanceSyncer goroutine. -var NotifyBalanceSyncerChans = struct { - add chan NotifyBalanceWorker - remove chan btcwire.ShaHash - access chan NotifyBalanceRequest -}{ - add: make(chan NotifyBalanceWorker), - remove: make(chan btcwire.ShaHash), - access: make(chan NotifyBalanceRequest), -} - -// NotifyBalanceWorker holds a block hash to add a worker to -// NotifyBalanceSyncer and uses a chan to returns the WaitGroup -// which should be decremented with Done after the worker is finished. -type NotifyBalanceWorker struct { - block btcwire.ShaHash - wg chan *sync.WaitGroup -} - -// NotifyBalanceRequest is used by the blockconnected notification handler -// to access and wait on the the WaitGroup for workers currently processing -// transactions for a block. If no handlers have been added, a nil -// WaitGroup is returned. -type NotifyBalanceRequest struct { - block btcwire.ShaHash - wg chan *sync.WaitGroup -} - -// NotifyBalanceSyncer maintains a map of block hashes to WaitGroups -// for worker goroutines that must finish before it is safe to notify -// websocket clientss of a new balance in the blockconnected notification -// handler. -func NotifyBalanceSyncer(add chan NotifyBalanceWorker, - remove chan btcwire.ShaHash, - access chan NotifyBalanceRequest) { - - m := make(map[btcwire.ShaHash]*sync.WaitGroup) - - for { - select { - case worker := <-add: - wg, ok := m[worker.block] - if !ok { - wg = &sync.WaitGroup{} - m[worker.block] = wg - } - wg.Add(1) - m[worker.block] = wg - worker.wg <- wg - - case block := <-remove: - if _, ok := m[block]; ok { - delete(m, block) - } - - case req := <-access: - req.wg <- m[req.block] - } - } -}