Merge pull request #3566 from wpaulino/wait-until-peer-active

peer+server: wait until peer is active to begin channel opening process
This commit is contained in:
Conner Fromknecht 2019-10-01 17:36:32 -07:00 committed by GitHub
commit 9710134f70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

@ -121,6 +121,10 @@ type peer struct {
addr *lnwire.NetAddress addr *lnwire.NetAddress
pubKeyBytes [33]byte pubKeyBytes [33]byte
// activeSignal when closed signals that the peer is now active and
// ready to process messages.
activeSignal chan struct{}
// startTime is the time this peer connection was successfully // startTime is the time this peer connection was successfully
// established. It will be zero for peers that did not successfully // established. It will be zero for peers that did not successfully
// Start(). // Start().
@ -241,6 +245,8 @@ func newPeer(conn net.Conn, connReq *connmgr.ConnReq, server *server,
conn: conn, conn: conn,
addr: addr, addr: addr,
activeSignal: make(chan struct{}),
inbound: inbound, inbound: inbound,
connReq: connReq, connReq: connReq,
@ -369,6 +375,9 @@ func (p *peer) Start() error {
go p.channelManager() go p.channelManager()
go p.pingHandler() go p.pingHandler()
// Signal to any external processes that the peer is now active.
close(p.activeSignal)
// Now that the peer has started up, we send any channel sync messages // Now that the peer has started up, we send any channel sync messages
// that must be resent for borked channels. // that must be resent for borked channels.
if len(msgs) > 0 { if len(msgs) > 0 {

@ -3207,6 +3207,18 @@ func (s *server) OpenChannel(
} }
s.mu.RUnlock() s.mu.RUnlock()
// We'll wait until the peer is active before beginning the channel
// opening process.
select {
case <-peer.activeSignal:
case <-peer.quit:
req.err <- fmt.Errorf("peer %x disconnected", pubKeyBytes)
return req.updates, req.err
case <-s.quit:
req.err <- ErrServerShuttingDown
return req.updates, req.err
}
// If the fee rate wasn't specified, then we'll use a default // If the fee rate wasn't specified, then we'll use a default
// confirmation target. // confirmation target.
if req.fundingFeePerKw == 0 { if req.fundingFeePerKw == 0 {