lnd: introduce the utxoNursery which incubates outputs until maturity

This commit introduces the utxoNursery. The duty of the utxoNursery is
to watch over CSV-locked immature outputs until they’ve fully matured.
An output is mature once both its sequence lock indicated by the CSV op
code within its output has become active. Once an output is mature the
nursery sweeps the outputs in batches into the source wallet.

The utxoNursery executes its duties once a commitment transaction has
been broadcast on-chain.
This commit is contained in:
Olaoluwa Osuntokun
2016-09-12 12:37:51 -07:00
parent d0353b2864
commit bfa2a1d698
3 changed files with 317 additions and 0 deletions

View File

@@ -55,6 +55,8 @@ type server struct {
routingMgr *routing.RoutingManager
utxoNursery *utxoNursery
newPeers chan *peer
donePeers chan *peer
queries chan interface{}
@@ -104,6 +106,8 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
// TODO(roasbeef): remove
s.invoices.addInvoice(1000*1e8, *debugPre)
s.utxoNursery = newUtxoNursery(notifier, wallet)
// Create a new routing manager with ourself as the sole node within
// the graph.
s.routingMgr = routing.NewRoutingManager(graph.NewID(s.lightningID), nil)
@@ -145,6 +149,9 @@ func (s *server) Start() error {
if err := s.htlcSwitch.Start(); err != nil {
return err
}
if err := s.utxoNursery.Start(); err != nil {
return err
}
s.routingMgr.Start()
s.wg.Add(1)
@@ -175,6 +182,7 @@ func (s *server) Stop() error {
s.fundingMgr.Stop()
s.routingMgr.Stop()
s.htlcSwitch.Stop()
s.utxoNursery.Stop()
s.lnwallet.Shutdown()