fundingmanager: change funding messages to use server.sendToPeer

Previously, during the channel funding process, peers sent wire
messages using peer.queueMsg. By switching to server.sendToPeer, the
fundingManager is more resilient to network connection issues or system
restarts during the funding process. With server.sendToPeer, if a peer
gets disconnected, the daemon can attempt to reconnect and continue the
process using the peer’s public key ID.
This commit is contained in:
bryanvu authored and Olaoluwa Osuntokun committed 2017-02-21 19:21:19 -08:00
1 parent 69faebfcae
commit b21bd351e8
7 files changed
+923 -680

No files matched your search

+29 -2
View File
@@ -196,7 +196,16 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
s.rpcServer = newRpcServer(s)
s.breachArbiter = newBreachArbiter(wallet, chanDB, notifier, s.htlcSwitch)
s.fundingMgr = newFundingManager(wallet, s.breachArbiter)
s.fundingMgr, err = newFundingManager(FundingConfig{
Wallet: wallet,
ArbiterChan: s.breachArbiter.newContracts,
SendToPeer: s.sendToPeer,
FindPeer: s.findPeer,
})
if err != nil {
return nil, err
}
// TODO(roasbeef): introduce closure and config system to decouple the
// initialization above ^
@@ -398,6 +407,24 @@ func (s *server) sendToPeer(target *btcec.PublicKey, msgs ...lnwire.Message) err
}
}
// findPeer will return the peer that corresponds to the passed in public key.
// This function is used by the funding manager, allowing it to update the
// daemon's local representation of the remote peer.
func (s *server) findPeer(peerKey *btcec.PublicKey) (*peer, error) {
serializedIDKey := string(peerKey.SerializeCompressed())
s.peersMtx.RLock()
peer := s.peersByPub[serializedIDKey]
s.peersMtx.RUnlock()
if peer == nil {
return nil, errors.New("Peer not found. Pubkey: " +
string(peerKey.SerializeCompressed()))
}
return peer, nil
}
// peerConnected is a function that handles initialization a newly connected
// peer by adding it to the server's global list of all active peers, and
// starting all the goroutines the peer needs to function properly.
@@ -801,7 +828,7 @@ func (s *server) handleOpenChanReq(req *openChanReq) {
// of blocking on this request which is exported as a synchronous
// request to the outside world.
// TODO(roasbeef): server semaphore to restrict num goroutines
go s.fundingMgr.initFundingWorkflow(targetPeer, req)
go s.fundingMgr.initFundingWorkflow(targetPeer.addr, req)
}
// ConnectToPeer requests that the server connect to a Lightning Network peer