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/autopilot"
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/contractcourt"
|
||||||
"github.com/lightningnetwork/lnd/discovery"
|
"github.com/lightningnetwork/lnd/discovery"
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
@ -70,6 +71,7 @@ var (
|
|||||||
crtrLog = backendLog.Logger("CRTR")
|
crtrLog = backendLog.Logger("CRTR")
|
||||||
btcnLog = backendLog.Logger("BTCN")
|
btcnLog = backendLog.Logger("BTCN")
|
||||||
atplLog = backendLog.Logger("ATPL")
|
atplLog = backendLog.Logger("ATPL")
|
||||||
|
cnctLog = backendLog.Logger("CNCT")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Initialize package-global logger variables.
|
// Initialize package-global logger variables.
|
||||||
@ -83,6 +85,7 @@ func init() {
|
|||||||
routing.UseLogger(crtrLog)
|
routing.UseLogger(crtrLog)
|
||||||
neutrino.UseLogger(btcnLog)
|
neutrino.UseLogger(btcnLog)
|
||||||
autopilot.UseLogger(atplLog)
|
autopilot.UseLogger(atplLog)
|
||||||
|
contractcourt.UseLogger(cnctLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
// subsystemLoggers maps each subsystem identifier to its associated logger.
|
// subsystemLoggers maps each subsystem identifier to its associated logger.
|
||||||
@ -103,6 +106,7 @@ var subsystemLoggers = map[string]btclog.Logger{
|
|||||||
"CRTR": crtrLog,
|
"CRTR": crtrLog,
|
||||||
"BTCN": btcnLog,
|
"BTCN": btcnLog,
|
||||||
"ATPL": atplLog,
|
"ATPL": atplLog,
|
||||||
|
"CNCT": cnctLog,
|
||||||
}
|
}
|
||||||
|
|
||||||
// initLogRotator initializes the logging rotator to write logs to logFile and
|
// initLogRotator initializes the logging rotator to write logs to logFile and
|
||||||
|
27
peer.go
27
peer.go
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/lightningnetwork/lnd/brontide"
|
"github.com/lightningnetwork/lnd/brontide"
|
||||||
|
"github.com/lightningnetwork/lnd/contractcourt"
|
||||||
|
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
||||||
@ -294,8 +295,10 @@ func (p *peer) Start() error {
|
|||||||
// channels returned by the database.
|
// channels returned by the database.
|
||||||
func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
|
func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
|
||||||
for _, dbChan := range chans {
|
for _, dbChan := range chans {
|
||||||
lnChan, err := lnwallet.NewLightningChannel(p.server.cc.signer,
|
lnChan, err := lnwallet.NewLightningChannel(
|
||||||
p.server.cc.chainNotifier, p.server.cc.feeEstimator, dbChan)
|
p.server.cc.signer, p.server.cc.chainNotifier,
|
||||||
|
p.server.witnessBeacon, dbChan,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -390,7 +393,13 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
|
|||||||
FwrdingPolicy: *forwardingPolicy,
|
FwrdingPolicy: *forwardingPolicy,
|
||||||
FeeEstimator: p.server.cc.feeEstimator,
|
FeeEstimator: p.server.cc.feeEstimator,
|
||||||
BlockEpochs: blockEpoch,
|
BlockEpochs: blockEpoch,
|
||||||
SyncStates: true,
|
PreimageCache: p.server.witnessBeacon,
|
||||||
|
UpdateContractSignals: func(signals *contractcourt.ContractSignals) error {
|
||||||
|
return p.server.chainArb.UpdateContractSignals(
|
||||||
|
*chanPoint, signals,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
SyncStates: true,
|
||||||
}
|
}
|
||||||
link := htlcswitch.NewChannelLink(linkCfg, lnChan,
|
link := htlcswitch.NewChannelLink(linkCfg, lnChan,
|
||||||
uint32(currentHeight))
|
uint32(currentHeight))
|
||||||
@ -1280,7 +1289,13 @@ out:
|
|||||||
FwrdingPolicy: p.server.cc.routingPolicy,
|
FwrdingPolicy: p.server.cc.routingPolicy,
|
||||||
FeeEstimator: p.server.cc.feeEstimator,
|
FeeEstimator: p.server.cc.feeEstimator,
|
||||||
BlockEpochs: blockEpoch,
|
BlockEpochs: blockEpoch,
|
||||||
SyncStates: false,
|
PreimageCache: p.server.witnessBeacon,
|
||||||
|
UpdateContractSignals: func(signals *contractcourt.ContractSignals) error {
|
||||||
|
return p.server.chainArb.UpdateContractSignals(
|
||||||
|
*chanPoint, signals,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
SyncStates: false,
|
||||||
}
|
}
|
||||||
link := htlcswitch.NewChannelLink(linkConfig, newChan,
|
link := htlcswitch.NewChannelLink(linkConfig, newChan,
|
||||||
uint32(currentHeight))
|
uint32(currentHeight))
|
||||||
@ -1550,8 +1565,8 @@ func (p *peer) finalizeChanClosure(chanCloser *channelCloser) {
|
|||||||
chanCloser.cfg.channel.CancelObserver()
|
chanCloser.cfg.channel.CancelObserver()
|
||||||
|
|
||||||
// Next, we'll launch a goroutine which will request to be notified by
|
// Next, we'll launch a goroutine which will request to be notified by
|
||||||
// the ChainNotifier once the closure
|
// the ChainNotifier once the closure transaction obtains a single
|
||||||
// transaction obtains a single confirmation.
|
// confirmation.
|
||||||
notifier := p.server.cc.chainNotifier
|
notifier := p.server.cc.chainNotifier
|
||||||
|
|
||||||
// If any error happens during waitForChanToClose, forward it to
|
// If any error happens during waitForChanToClose, forward it to
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// +build !rpctest
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -7,6 +9,7 @@ import (
|
|||||||
"github.com/btcsuite/btclog"
|
"github.com/btcsuite/btclog"
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/contractcourt"
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
@ -23,6 +26,7 @@ func init() {
|
|||||||
lnwallet.UseLogger(btclog.Disabled)
|
lnwallet.UseLogger(btclog.Disabled)
|
||||||
htlcswitch.UseLogger(btclog.Disabled)
|
htlcswitch.UseLogger(btclog.Disabled)
|
||||||
channeldb.UseLogger(btclog.Disabled)
|
channeldb.UseLogger(btclog.Disabled)
|
||||||
|
contractcourt.UseLogger(btclog.Disabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestPeerChannelClosureAcceptFeeResponder tests the shutdown responder's
|
// TestPeerChannelClosureAcceptFeeResponder tests the shutdown responder's
|
||||||
|
77
server.go
77
server.go
@ -17,8 +17,10 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/autopilot"
|
"github.com/lightningnetwork/lnd/autopilot"
|
||||||
"github.com/lightningnetwork/lnd/brontide"
|
"github.com/lightningnetwork/lnd/brontide"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/contractcourt"
|
||||||
"github.com/lightningnetwork/lnd/discovery"
|
"github.com/lightningnetwork/lnd/discovery"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing"
|
"github.com/lightningnetwork/lnd/routing"
|
||||||
"github.com/roasbeef/btcd/blockchain"
|
"github.com/roasbeef/btcd/blockchain"
|
||||||
@ -86,8 +88,12 @@ type server struct {
|
|||||||
|
|
||||||
chanDB *channeldb.DB
|
chanDB *channeldb.DB
|
||||||
|
|
||||||
htlcSwitch *htlcswitch.Switch
|
htlcSwitch *htlcswitch.Switch
|
||||||
invoices *invoiceRegistry
|
|
||||||
|
invoices *invoiceRegistry
|
||||||
|
|
||||||
|
witnessBeacon contractcourt.WitnessBeacon
|
||||||
|
|
||||||
breachArbiter *breachArbiter
|
breachArbiter *breachArbiter
|
||||||
|
|
||||||
chanRouter *routing.ChannelRouter
|
chanRouter *routing.ChannelRouter
|
||||||
@ -96,6 +102,8 @@ type server struct {
|
|||||||
|
|
||||||
utxoNursery *utxoNursery
|
utxoNursery *utxoNursery
|
||||||
|
|
||||||
|
chainArb *contractcourt.ChainArbitrator
|
||||||
|
|
||||||
sphinx *htlcswitch.OnionProcessor
|
sphinx *htlcswitch.OnionProcessor
|
||||||
|
|
||||||
connMgr *connmgr.ConnManager
|
connMgr *connmgr.ConnManager
|
||||||
@ -162,6 +170,8 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
|
|||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.witnessBeacon = NewPreimageBeacon(s.invoices, chanDB.NewWitnessCache())
|
||||||
|
|
||||||
// If the debug HTLC flag is on, then we invoice a "master debug"
|
// If the debug HTLC flag is on, then we invoice a "master debug"
|
||||||
// invoice which all outgoing payments will be sent and all incoming
|
// invoice which all outgoing payments will be sent and all incoming
|
||||||
// HTLCs with the debug R-Hash immediately settled.
|
// 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.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{
|
s.breachArbiter = newBreachArbiter(&BreachConfig{
|
||||||
CloseLink: closeLink,
|
CloseLink: closeLink,
|
||||||
DB: chanDB,
|
DB: chanDB,
|
||||||
@ -354,6 +413,16 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
|
|||||||
PublishTransaction: cc.wallet.PublishTransaction,
|
PublishTransaction: cc.wallet.PublishTransaction,
|
||||||
Signer: cc.wallet.Cfg.Signer,
|
Signer: cc.wallet.Cfg.Signer,
|
||||||
Store: newRetributionStore(chanDB),
|
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
|
// 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 {
|
if err := s.utxoNursery.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := s.chainArb.Start(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := s.breachArbiter.Start(); err != nil {
|
if err := s.breachArbiter.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -461,6 +533,7 @@ func (s *server) Stop() error {
|
|||||||
s.utxoNursery.Stop()
|
s.utxoNursery.Stop()
|
||||||
s.breachArbiter.Stop()
|
s.breachArbiter.Stop()
|
||||||
s.authGossiper.Stop()
|
s.authGossiper.Stop()
|
||||||
|
s.chainArb.Stop()
|
||||||
s.cc.wallet.Shutdown()
|
s.cc.wallet.Shutdown()
|
||||||
s.cc.chainView.Stop()
|
s.cc.chainView.Stop()
|
||||||
s.connMgr.Stop()
|
s.connMgr.Stop()
|
||||||
|
Loading…
Reference in New Issue
Block a user