utxonursery: use a two value read from the epoch chan for graceful shutdown

Within the utoxNursery we now use a two value read fro the block epoch
channel in order to exit early if/when the ChainNotifier begins the
shutdown process before the signal reaches the utxoNursery.
This commit is contained in:
Olaoluwa Osuntokun 2016-12-15 13:55:15 -08:00
parent f29b496b76
commit 343cd7779f
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -96,6 +96,8 @@ func (u *utxoNursery) Stop() error {
// Once an output is mature, it will be swept into the wallet at the earlier
// possible height.
func (u *utxoNursery) incubator() {
defer u.wg.Done()
// Register with the notifier to receive notifications for each newly
// connected block.
newBlocks, err := u.notifier.RegisterBlockEpochNtfn()
@ -163,7 +165,15 @@ out:
utxnLog.Infof("Outpoint %v now mid-stage, will mature "+
"at height %v (delay of %v)", midUtxo.outPoint,
maturityHeight, midUtxo.blocksToMaturity)
case epoch := <-newBlocks.Epochs:
case epoch, ok := <-newBlocks.Epochs:
// If the epoch channel has been closed, then the
// ChainNotifier is exiting which means the daemon is
// as well. Therefore, we exit early also in order to
// ensure the daemon shutsdown gracefully, yet swiftly.
if !ok {
return
}
// A new block has just been connected, check to see if
// we have any new outputs that can be swept into the
// wallet.
@ -210,8 +220,6 @@ out:
break out
}
}
u.wg.Done()
}
// createSweepTx creates a final sweeping transaction with all witnesses in