lnd: properly initialize entities of new contractcourt package
This commit is contained in:
parent
bfbec1c5d3
commit
24a16b4f49
4
log.go
4
log.go
@ -14,6 +14,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/autopilot"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/contractcourt"
|
||||
"github.com/lightningnetwork/lnd/discovery"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
@ -70,6 +71,7 @@ var (
|
||||
crtrLog = backendLog.Logger("CRTR")
|
||||
btcnLog = backendLog.Logger("BTCN")
|
||||
atplLog = backendLog.Logger("ATPL")
|
||||
cnctLog = backendLog.Logger("CNCT")
|
||||
)
|
||||
|
||||
// Initialize package-global logger variables.
|
||||
@ -83,6 +85,7 @@ func init() {
|
||||
routing.UseLogger(crtrLog)
|
||||
neutrino.UseLogger(btcnLog)
|
||||
autopilot.UseLogger(atplLog)
|
||||
contractcourt.UseLogger(cnctLog)
|
||||
}
|
||||
|
||||
// subsystemLoggers maps each subsystem identifier to its associated logger.
|
||||
@ -103,6 +106,7 @@ var subsystemLoggers = map[string]btclog.Logger{
|
||||
"CRTR": crtrLog,
|
||||
"BTCN": btcnLog,
|
||||
"ATPL": atplLog,
|
||||
"CNCT": cnctLog,
|
||||
}
|
||||
|
||||
// initLogRotator initializes the logging rotator to write logs to logFile and
|
||||
|
23
peer.go
23
peer.go
@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/lightningnetwork/lnd/brontide"
|
||||
"github.com/lightningnetwork/lnd/contractcourt"
|
||||
|
||||
"bytes"
|
||||
|
||||
@ -294,8 +295,10 @@ func (p *peer) Start() error {
|
||||
// channels returned by the database.
|
||||
func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
|
||||
for _, dbChan := range chans {
|
||||
lnChan, err := lnwallet.NewLightningChannel(p.server.cc.signer,
|
||||
p.server.cc.chainNotifier, p.server.cc.feeEstimator, dbChan)
|
||||
lnChan, err := lnwallet.NewLightningChannel(
|
||||
p.server.cc.signer, p.server.cc.chainNotifier,
|
||||
p.server.witnessBeacon, dbChan,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -390,6 +393,12 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
|
||||
FwrdingPolicy: *forwardingPolicy,
|
||||
FeeEstimator: p.server.cc.feeEstimator,
|
||||
BlockEpochs: blockEpoch,
|
||||
PreimageCache: p.server.witnessBeacon,
|
||||
UpdateContractSignals: func(signals *contractcourt.ContractSignals) error {
|
||||
return p.server.chainArb.UpdateContractSignals(
|
||||
*chanPoint, signals,
|
||||
)
|
||||
},
|
||||
SyncStates: true,
|
||||
}
|
||||
link := htlcswitch.NewChannelLink(linkCfg, lnChan,
|
||||
@ -1280,6 +1289,12 @@ out:
|
||||
FwrdingPolicy: p.server.cc.routingPolicy,
|
||||
FeeEstimator: p.server.cc.feeEstimator,
|
||||
BlockEpochs: blockEpoch,
|
||||
PreimageCache: p.server.witnessBeacon,
|
||||
UpdateContractSignals: func(signals *contractcourt.ContractSignals) error {
|
||||
return p.server.chainArb.UpdateContractSignals(
|
||||
*chanPoint, signals,
|
||||
)
|
||||
},
|
||||
SyncStates: false,
|
||||
}
|
||||
link := htlcswitch.NewChannelLink(linkConfig, newChan,
|
||||
@ -1550,8 +1565,8 @@ func (p *peer) finalizeChanClosure(chanCloser *channelCloser) {
|
||||
chanCloser.cfg.channel.CancelObserver()
|
||||
|
||||
// Next, we'll launch a goroutine which will request to be notified by
|
||||
// the ChainNotifier once the closure
|
||||
// transaction obtains a single confirmation.
|
||||
// the ChainNotifier once the closure transaction obtains a single
|
||||
// confirmation.
|
||||
notifier := p.server.cc.chainNotifier
|
||||
|
||||
// If any error happens during waitForChanToClose, forward it to
|
||||
|
@ -1,3 +1,5 @@
|
||||
// +build !rpctest
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@ -7,6 +9,7 @@ import (
|
||||
"github.com/btcsuite/btclog"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/contractcourt"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
@ -23,6 +26,7 @@ func init() {
|
||||
lnwallet.UseLogger(btclog.Disabled)
|
||||
htlcswitch.UseLogger(btclog.Disabled)
|
||||
channeldb.UseLogger(btclog.Disabled)
|
||||
contractcourt.UseLogger(btclog.Disabled)
|
||||
}
|
||||
|
||||
// TestPeerChannelClosureAcceptFeeResponder tests the shutdown responder's
|
||||
|
73
server.go
73
server.go
@ -17,8 +17,10 @@ import (
|
||||
"github.com/lightningnetwork/lnd/autopilot"
|
||||
"github.com/lightningnetwork/lnd/brontide"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/contractcourt"
|
||||
"github.com/lightningnetwork/lnd/discovery"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing"
|
||||
"github.com/roasbeef/btcd/blockchain"
|
||||
@ -87,7 +89,11 @@ type server struct {
|
||||
chanDB *channeldb.DB
|
||||
|
||||
htlcSwitch *htlcswitch.Switch
|
||||
|
||||
invoices *invoiceRegistry
|
||||
|
||||
witnessBeacon contractcourt.WitnessBeacon
|
||||
|
||||
breachArbiter *breachArbiter
|
||||
|
||||
chanRouter *routing.ChannelRouter
|
||||
@ -96,6 +102,8 @@ type server struct {
|
||||
|
||||
utxoNursery *utxoNursery
|
||||
|
||||
chainArb *contractcourt.ChainArbitrator
|
||||
|
||||
sphinx *htlcswitch.OnionProcessor
|
||||
|
||||
connMgr *connmgr.ConnManager
|
||||
@ -162,6 +170,8 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
|
||||
quit: make(chan struct{}),
|
||||
}
|
||||
|
||||
s.witnessBeacon = NewPreimageBeacon(s.invoices, chanDB.NewWitnessCache())
|
||||
|
||||
// If the debug HTLC flag is on, then we invoice a "master debug"
|
||||
// invoice which all outgoing payments will be sent and all incoming
|
||||
// HTLCs with the debug R-Hash immediately settled.
|
||||
@ -343,6 +353,55 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
|
||||
s.htlcSwitch.CloseLink(chanPoint, closureType, 0)
|
||||
}
|
||||
|
||||
s.chainArb = contractcourt.NewChainArbitrator(contractcourt.ChainArbitratorConfig{
|
||||
ChainHash: *activeNetParams.GenesisHash,
|
||||
// TODO(roasbeef): properly configure
|
||||
// * needs to be << or specified final hop time delta
|
||||
BroadcastDelta: defaultBroadcastDelta,
|
||||
NewSweepAddr: func() ([]byte, error) {
|
||||
return newSweepPkScript(cc.wallet)
|
||||
},
|
||||
PublishTx: cc.wallet.PublishTransaction,
|
||||
DeliverResolutionMsg: func(msgs ...contractcourt.ResolutionMsg) error {
|
||||
for _, msg := range msgs {
|
||||
err := s.htlcSwitch.ProcessContractResolution(msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
IncubateOutputs: func(chanPoint wire.OutPoint,
|
||||
commitRes *lnwallet.CommitOutputResolution,
|
||||
outHtlcRes *lnwallet.OutgoingHtlcResolution,
|
||||
inHtlcRes *lnwallet.IncomingHtlcResolution) error {
|
||||
|
||||
var (
|
||||
inRes []lnwallet.IncomingHtlcResolution
|
||||
outRes []lnwallet.OutgoingHtlcResolution
|
||||
)
|
||||
if inHtlcRes != nil {
|
||||
inRes = append(inRes, *inHtlcRes)
|
||||
}
|
||||
if outHtlcRes != nil {
|
||||
outRes = append(outRes, *outHtlcRes)
|
||||
}
|
||||
|
||||
return s.utxoNursery.IncubateOutputs(
|
||||
chanPoint, commitRes, outRes, inRes,
|
||||
)
|
||||
},
|
||||
PreimageDB: s.witnessBeacon,
|
||||
Notifier: cc.chainNotifier,
|
||||
Signer: cc.wallet.Cfg.Signer,
|
||||
FeeEstimator: cc.feeEstimator,
|
||||
ChainIO: cc.chainIO,
|
||||
MarkLinkInactive: func(chanPoint wire.OutPoint) error {
|
||||
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
|
||||
return s.htlcSwitch.RemoveLink(chanID)
|
||||
},
|
||||
}, chanDB)
|
||||
|
||||
s.breachArbiter = newBreachArbiter(&BreachConfig{
|
||||
CloseLink: closeLink,
|
||||
DB: chanDB,
|
||||
@ -354,6 +413,16 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
|
||||
PublishTransaction: cc.wallet.PublishTransaction,
|
||||
Signer: cc.wallet.Cfg.Signer,
|
||||
Store: newRetributionStore(chanDB),
|
||||
UpdateCloseSignal: func(op *wire.OutPoint,
|
||||
ucs chan *lnwallet.UnilateralCloseSummary) error {
|
||||
|
||||
signals := &contractcourt.ContractSignals{
|
||||
HtlcUpdates: make(chan []channeldb.HTLC),
|
||||
UniCloseSignal: ucs,
|
||||
}
|
||||
|
||||
return s.chainArb.UpdateContractSignals(*op, signals)
|
||||
},
|
||||
})
|
||||
|
||||
// Create the connection manager which will be responsible for
|
||||
@ -405,6 +474,9 @@ func (s *server) Start() error {
|
||||
if err := s.utxoNursery.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.chainArb.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.breachArbiter.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -461,6 +533,7 @@ func (s *server) Stop() error {
|
||||
s.utxoNursery.Stop()
|
||||
s.breachArbiter.Stop()
|
||||
s.authGossiper.Stop()
|
||||
s.chainArb.Stop()
|
||||
s.cc.wallet.Shutdown()
|
||||
s.cc.chainView.Stop()
|
||||
s.connMgr.Stop()
|
||||
|
Loading…
Reference in New Issue
Block a user