server: all references to primary interfaces are now through chainControl
This commit is contained in:
parent
770d6b136f
commit
25dc294cf0
16
peer.go
16
peer.go
@ -289,8 +289,8 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
|
||||
continue
|
||||
}
|
||||
|
||||
lnChan, err := lnwallet.NewLightningChannel(p.server.lnwallet.Signer,
|
||||
p.server.chainNotifier, p.server.feeEstimator, dbChan)
|
||||
lnChan, err := lnwallet.NewLightningChannel(p.server.cc.signer,
|
||||
p.server.cc.chainNotifier, p.server.cc.feeEstimator, dbChan)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -1098,7 +1098,7 @@ func (p *peer) handleInitClosingSigned(req *htlcswitch.ChanClose, msg *lnwire.Cl
|
||||
},
|
||||
}
|
||||
|
||||
_, bestHeight, err := p.server.bio.GetBestBlock()
|
||||
_, bestHeight, err := p.server.cc.chainIO.GetBestBlock()
|
||||
if err != nil {
|
||||
req.Err <- err
|
||||
return
|
||||
@ -1107,9 +1107,9 @@ func (p *peer) handleInitClosingSigned(req *htlcswitch.ChanClose, msg *lnwire.Cl
|
||||
// Finally, launch a goroutine which will request to be notified by the
|
||||
// ChainNotifier once the closure transaction obtains a single
|
||||
// confirmation.
|
||||
notifier := p.server.chainNotifier
|
||||
go waitForChanToClose(uint32(bestHeight), notifier, req.Err,
|
||||
req.ChanPoint, &closingTxid, func() {
|
||||
notifier := p.server.cc.chainNotifier
|
||||
go waitForChanToClose(uint32(bestHeight), notifier, req.err,
|
||||
req.ChanPoint, closingTxid, func() {
|
||||
|
||||
// First, we'll mark the database as being fully closed
|
||||
// so we'll no longer watch for its ultimate closure
|
||||
@ -1168,7 +1168,7 @@ func (p *peer) handleResponseClosingSigned(msg *lnwire.ClosingSigned,
|
||||
}
|
||||
closeTxid := closeTx.TxHash()
|
||||
|
||||
_, bestHeight, err := p.server.bio.GetBestBlock()
|
||||
_, bestHeight, err := p.server.cc.chainIO.GetBestBlock()
|
||||
if err != nil {
|
||||
peerLog.Errorf("unable to get best height: %v", err)
|
||||
}
|
||||
@ -1206,7 +1206,7 @@ func (p *peer) handleResponseClosingSigned(msg *lnwire.ClosingSigned,
|
||||
// Finally, we'll launch a goroutine to watch the network for the
|
||||
// confirmation of the closing transaction, and mark the channel as
|
||||
// such within the database (once it's confirmed").
|
||||
notifier := p.server.chainNotifier
|
||||
notifier := p.server.cc.chainNotifier
|
||||
go waitForChanToClose(uint32(bestHeight), notifier, nil, chanPoint,
|
||||
&closeTxid, func() {
|
||||
// Now that the closing transaction has been confirmed,
|
||||
|
34
rpcserver.go
34
rpcserver.go
@ -116,7 +116,7 @@ func (r *rpcServer) sendCoinsOnChain(paymentMap map[string]int64) (*chainhash.Ha
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return r.server.lnwallet.SendOutputs(outputs)
|
||||
return r.server.cc.wallet.SendOutputs(outputs)
|
||||
}
|
||||
|
||||
// SendCoins executes a request to send coins to a particular address. Unlike
|
||||
@ -168,7 +168,7 @@ func (r *rpcServer) NewAddress(ctx context.Context,
|
||||
addrType = lnwallet.PubKeyHash
|
||||
}
|
||||
|
||||
addr, err := r.server.lnwallet.NewAddress(addrType, false)
|
||||
addr, err := r.server.cc.wallet.NewAddress(addrType, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -182,7 +182,7 @@ func (r *rpcServer) NewAddress(ctx context.Context,
|
||||
func (r *rpcServer) NewWitnessAddress(ctx context.Context,
|
||||
in *lnrpc.NewWitnessAddressRequest) (*lnrpc.NewAddressResponse, error) {
|
||||
|
||||
addr, err := r.server.lnwallet.NewAddress(lnwallet.WitnessPubKey, false)
|
||||
addr, err := r.server.cc.wallet.NewAddress(lnwallet.WitnessPubKey, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -465,7 +465,7 @@ func (r *rpcServer) OpenChannelSync(ctx context.Context,
|
||||
|
||||
// Creation of channels before the wallet syncs up is currently
|
||||
// disallowed.
|
||||
isSynced, err := r.server.lnwallet.IsSynced()
|
||||
isSynced, err := r.server.cc.wallet.IsSynced()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -564,7 +564,7 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
|
||||
return err
|
||||
}
|
||||
|
||||
_, bestHeight, err := r.server.bio.GetBestBlock()
|
||||
_, bestHeight, err := r.server.cc.chainIO.GetBestBlock()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -606,7 +606,7 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
|
||||
}
|
||||
|
||||
errChan = make(chan error, 1)
|
||||
notifier := r.server.chainNotifier
|
||||
notifier := r.server.cc.chainNotifier
|
||||
go waitForChanToClose(uint32(bestHeight), notifier, errChan, chanPoint,
|
||||
closingTxid, func() {
|
||||
// Respond to the local subsystem which
|
||||
@ -689,8 +689,8 @@ func (r *rpcServer) fetchActiveChannel(chanPoint wire.OutPoint) (*lnwallet.Light
|
||||
|
||||
// Otherwise, we create a fully populated channel state machine which
|
||||
// uses the db channel as backing storage.
|
||||
return lnwallet.NewLightningChannel(r.server.lnwallet.Signer, nil,
|
||||
r.server.feeEstimator, dbChan)
|
||||
return lnwallet.NewLightningChannel(r.server.cc.wallet.Signer, nil,
|
||||
r.server.cc.feeEstimator, dbChan)
|
||||
}
|
||||
|
||||
// forceCloseChan executes a unilateral close of the target channel by
|
||||
@ -715,7 +715,7 @@ func (r *rpcServer) forceCloseChan(channel *lnwallet.LightningChannel) (*chainha
|
||||
channel.ChannelPoint(), newLogClosure(func() string {
|
||||
return spew.Sdump(closeTx)
|
||||
}))
|
||||
if err := r.server.lnwallet.PublishTransaction(closeTx); err != nil {
|
||||
if err := r.server.cc.wallet.PublishTransaction(closeTx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -766,12 +766,12 @@ func (r *rpcServer) GetInfo(ctx context.Context,
|
||||
|
||||
idPub := r.server.identityPriv.PubKey().SerializeCompressed()
|
||||
|
||||
bestHash, bestHeight, err := r.server.bio.GetBestBlock()
|
||||
bestHash, bestHeight, err := r.server.cc.chainIO.GetBestBlock()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get best block info: %v", err)
|
||||
}
|
||||
|
||||
isSynced, err := r.server.lnwallet.IsSynced()
|
||||
isSynced, err := r.server.cc.wallet.IsSynced()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to sync PoV of the wallet "+
|
||||
"with current best block in the main chain: %v", err)
|
||||
@ -817,7 +817,7 @@ func (r *rpcServer) ListPeers(ctx context.Context,
|
||||
// In order to display the total number of satoshis of outbound
|
||||
// (sent) and inbound (recv'd) satoshis that have been
|
||||
// transported through this peer, we'll sum up the sent/recv'd
|
||||
// values for each of the active channels we ahve with the
|
||||
// values for each of the active channels we have with the
|
||||
// peer.
|
||||
chans := serverPeer.ChannelSnapshots()
|
||||
for _, c := range chans {
|
||||
@ -854,7 +854,7 @@ func (r *rpcServer) ListPeers(ctx context.Context,
|
||||
func (r *rpcServer) WalletBalance(ctx context.Context,
|
||||
in *lnrpc.WalletBalanceRequest) (*lnrpc.WalletBalanceResponse, error) {
|
||||
|
||||
balance, err := r.server.lnwallet.ConfirmedBalance(1, in.WitnessOnly)
|
||||
balance, err := r.server.cc.wallet.ConfirmedBalance(1, in.WitnessOnly)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -935,7 +935,7 @@ func (r *rpcServer) PendingChannels(ctx context.Context,
|
||||
}
|
||||
}
|
||||
|
||||
_, currentHeight, err := r.server.bio.GetBestBlock()
|
||||
_, currentHeight, err := r.server.cc.chainIO.GetBestBlock()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1568,7 +1568,7 @@ func (r *rpcServer) SubscribeInvoices(req *lnrpc.InvoiceSubscription,
|
||||
func (r *rpcServer) SubscribeTransactions(req *lnrpc.GetTransactionsRequest,
|
||||
updateStream lnrpc.Lightning_SubscribeTransactionsServer) error {
|
||||
|
||||
txClient, err := r.server.lnwallet.SubscribeTransactions()
|
||||
txClient, err := r.server.cc.wallet.SubscribeTransactions()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -1609,8 +1609,8 @@ func (r *rpcServer) SubscribeTransactions(req *lnrpc.GetTransactionsRequest,
|
||||
func (r *rpcServer) GetTransactions(context.Context,
|
||||
*lnrpc.GetTransactionsRequest) (*lnrpc.TransactionDetails, error) {
|
||||
|
||||
// TODO(roasbeef): add pagination support
|
||||
transactions, err := r.server.lnwallet.ListTransactionDetails()
|
||||
// TODO(btcsuite): add pagination support
|
||||
transactions, err := r.server.cc.wallet.ListTransactionDetails()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
58
server.go
58
server.go
@ -15,14 +15,12 @@ import (
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/brontide"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"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/lightningnetwork/lnd/routing/chainview"
|
||||
"github.com/roasbeef/btcd/btcec"
|
||||
"github.com/roasbeef/btcd/connmgr"
|
||||
"github.com/roasbeef/btcutil"
|
||||
@ -44,7 +42,7 @@ type server struct {
|
||||
identityPriv *btcec.PrivateKey
|
||||
|
||||
// nodeSigner is an implementation of the MessageSigner implementation
|
||||
// that's backed by the identituy private key of the running lnd node.
|
||||
// that's backed by the identity private key of the running lnd node.
|
||||
nodeSigner *nodeSigner
|
||||
|
||||
// lightningID is the sha256 of the public key corresponding to our
|
||||
@ -61,13 +59,10 @@ type server struct {
|
||||
|
||||
rpcServer *rpcServer
|
||||
|
||||
chainNotifier chainntnfs.ChainNotifier
|
||||
|
||||
bio lnwallet.BlockChainIO
|
||||
lnwallet *lnwallet.LightningWallet
|
||||
feeEstimator lnwallet.FeeEstimator
|
||||
cc *chainControl
|
||||
|
||||
fundingMgr *fundingManager
|
||||
|
||||
chanDB *channeldb.DB
|
||||
|
||||
htlcSwitch *htlcswitch.Switch
|
||||
@ -108,12 +103,8 @@ type server struct {
|
||||
|
||||
// newServer creates a new instance of the server which is to listen using the
|
||||
// passed listener address.
|
||||
func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
|
||||
bio lnwallet.BlockChainIO, fundingSigner lnwallet.MessageSigner,
|
||||
wallet *lnwallet.LightningWallet, estimator lnwallet.FeeEstimator,
|
||||
chanDB *channeldb.DB, chainView chainview.FilteredChainView) (*server, error) {
|
||||
|
||||
privKey, err := wallet.GetIdentitykey()
|
||||
func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl) (*server, error) {
|
||||
privKey, err := cc.wallet.GetIdentitykey()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -129,14 +120,12 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
|
||||
|
||||
serializedPubKey := privKey.PubKey().SerializeCompressed()
|
||||
s := &server{
|
||||
lnwallet: wallet,
|
||||
bio: bio,
|
||||
chainNotifier: notifier,
|
||||
chanDB: chanDB,
|
||||
feeEstimator: estimator,
|
||||
cc: cc,
|
||||
|
||||
invoices: newInvoiceRegistry(chanDB),
|
||||
utxoNursery: newUtxoNursery(chanDB, notifier, wallet),
|
||||
|
||||
utxoNursery: newUtxoNursery(chanDB, cc.chainNotifier, cc.wallet),
|
||||
|
||||
identityPriv: privKey,
|
||||
nodeSigner: newNodeSigner(privKey),
|
||||
@ -250,8 +239,8 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
|
||||
|
||||
s.chanRouter, err = routing.New(routing.Config{
|
||||
Graph: chanGraph,
|
||||
Chain: bio,
|
||||
ChainView: chainView,
|
||||
Chain: cc.chainIO,
|
||||
ChainView: cc.chainView,
|
||||
SendToSwitch: func(firstHop *btcec.PublicKey,
|
||||
htlcAdd *lnwire.UpdateAddHTLC) ([32]byte, error) {
|
||||
firstHopPub := firstHop.SerializeCompressed()
|
||||
@ -264,7 +253,7 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
|
||||
|
||||
s.discoverSrv, err = discovery.New(discovery.Config{
|
||||
Broadcast: s.broadcastMessage,
|
||||
Notifier: s.chainNotifier,
|
||||
Notifier: s.cc.chainNotifier,
|
||||
Router: s.chanRouter,
|
||||
SendToPeer: s.sendToPeer,
|
||||
TrickleDelay: time.Millisecond * 300,
|
||||
@ -276,8 +265,8 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
|
||||
}
|
||||
|
||||
s.rpcServer = newRPCServer(s)
|
||||
s.breachArbiter = newBreachArbiter(wallet, chanDB, notifier,
|
||||
s.htlcSwitch, s.bio, s.feeEstimator)
|
||||
s.breachArbiter = newBreachArbiter(cc.wallet, chanDB, cc.chainNotifier,
|
||||
s.htlcSwitch, s.cc.chainIO, s.cc.feeEstimator)
|
||||
|
||||
var chanIDSeed [32]byte
|
||||
if _, err := rand.Read(chanIDSeed[:]); err != nil {
|
||||
@ -286,16 +275,16 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
|
||||
|
||||
s.fundingMgr, err = newFundingManager(fundingConfig{
|
||||
IDKey: s.identityPriv.PubKey(),
|
||||
Wallet: wallet,
|
||||
ChainIO: s.bio,
|
||||
Notifier: s.chainNotifier,
|
||||
FeeEstimator: s.feeEstimator,
|
||||
Wallet: cc.wallet,
|
||||
ChainIO: s.cc.chainIO,
|
||||
Notifier: s.cc.chainNotifier,
|
||||
FeeEstimator: s.cc.feeEstimator,
|
||||
SignMessage: func(pubKey *btcec.PublicKey, msg []byte) (*btcec.Signature, error) {
|
||||
if pubKey.IsEqual(s.identityPriv.PubKey()) {
|
||||
return s.nodeSigner.SignMessage(pubKey, msg)
|
||||
}
|
||||
|
||||
return fundingSigner.SignMessage(pubKey, msg)
|
||||
return cc.msgSigner.SignMessage(pubKey, msg)
|
||||
},
|
||||
SendAnnouncement: func(msg lnwire.Message) error {
|
||||
s.discoverSrv.ProcessLocalAnnouncement(msg,
|
||||
@ -315,8 +304,8 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
|
||||
for _, channel := range dbChannels {
|
||||
if chanID.IsChanPoint(channel.ChanID) {
|
||||
return lnwallet.NewLightningChannel(
|
||||
wallet.Signer, notifier,
|
||||
s.feeEstimator,
|
||||
cc.signer, cc.chainNotifier,
|
||||
cc.feeEstimator,
|
||||
channel)
|
||||
}
|
||||
}
|
||||
@ -364,7 +353,7 @@ func (s *server) Start() error {
|
||||
// sufficient number of confirmations, or when the input for the
|
||||
// funding transaction is spent in an attempt at an uncooperative close
|
||||
// by the counterparty.
|
||||
if err := s.chainNotifier.Start(); err != nil {
|
||||
if err := s.cc.chainNotifier.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -413,7 +402,7 @@ func (s *server) Stop() error {
|
||||
}
|
||||
|
||||
// Shutdown the wallet, funding manager, and the rpc server.
|
||||
s.chainNotifier.Stop()
|
||||
s.cc.chainNotifier.Stop()
|
||||
s.rpcServer.Stop()
|
||||
s.fundingMgr.Stop()
|
||||
s.chanRouter.Stop()
|
||||
@ -421,7 +410,8 @@ func (s *server) Stop() error {
|
||||
s.utxoNursery.Stop()
|
||||
s.breachArbiter.Stop()
|
||||
s.discoverSrv.Stop()
|
||||
s.lnwallet.Shutdown()
|
||||
s.cc.wallet.Shutdown()
|
||||
s.cc.chainView.Stop()
|
||||
|
||||
// Signal all the lingering goroutines to quit.
|
||||
close(s.quit)
|
||||
|
Loading…
Reference in New Issue
Block a user