server: Stop main loop from blocking when RPC server is not running.

When the RPC server is not running a buffered transaction notification

channel fills and eventually blocks.  This commit ensures that the

channel continues to be drained irrespective of the RPC server status.
This commit is contained in:
Jonathan Gillham 2016-04-06 19:20:01 +01:00 committed by Dave Collins
parent e08038115b
commit 391d5e4a01

View file

@ -1954,14 +1954,10 @@ func (s *server) UpdatePeerHeights(latestBlkSha *wire.ShaHash, latestHeight int3
}
}
// rebroadcastHandler keeps track of user submitted inventories that we have
// sent out but have not yet made it into a block. We periodically rebroadcast
// them in case our peers restarted or otherwise lost track of them.
func (s *server) rebroadcastHandler() {
// Wait 5 min before first tx rebroadcast.
timer := time.NewTimer(5 * time.Minute)
pendingInvs := make(map[wire.InvVect]interface{})
// relayTransactionsHandler relays transactions sent on relayNtfnChan to other
// peers and to the RPC infrastructure if necessary. It must be run as a
// goroutine.
func (s *server) relayTransactionsHandler() {
out:
for {
select {
@ -1976,9 +1972,38 @@ out:
// Potentially notify any getblocktemplate long poll clients
// about stale block templates due to the new transaction.
s.rpcServer.gbtWorkState.NotifyMempoolTx(s.txMemPool.LastUpdated())
s.rpcServer.gbtWorkState.NotifyMempoolTx(
s.txMemPool.LastUpdated())
}
case <-s.quit:
break out
}
}
// Drain channels before exiting so nothing is left waiting around to send.
cleanup:
for {
select {
case <-s.relayNtfnChan:
default:
break cleanup
}
}
s.wg.Done()
}
// rebroadcastHandler keeps track of user submitted inventories that we have
// sent out but have not yet made it into a block. We periodically rebroadcast
// them in case our peers restarted or otherwise lost track of them.
func (s *server) rebroadcastHandler() {
// Wait 5 min before first tx rebroadcast.
timer := time.NewTimer(5 * time.Minute)
pendingInvs := make(map[wire.InvVect]interface{})
out:
for {
select {
case riv := <-s.modifyRebroadcastInv:
switch msg := riv.(type) {
// Incoming InvVects are added to our map of RPC txs.
@ -2047,6 +2072,9 @@ func (s *server) Start() {
s.wg.Add(1)
go s.peerHandler()
s.wg.Add(1)
go s.relayTransactionsHandler()
if s.nat != nil {
s.wg.Add(1)
go s.upnpUpdateThread()