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:
commit
9710134f70
9
peer.go
9
peer.go
@ -121,6 +121,10 @@ type peer struct {
|
||||
addr *lnwire.NetAddress
|
||||
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
|
||||
// established. It will be zero for peers that did not successfully
|
||||
// Start().
|
||||
@ -241,6 +245,8 @@ func newPeer(conn net.Conn, connReq *connmgr.ConnReq, server *server,
|
||||
conn: conn,
|
||||
addr: addr,
|
||||
|
||||
activeSignal: make(chan struct{}),
|
||||
|
||||
inbound: inbound,
|
||||
connReq: connReq,
|
||||
|
||||
@ -369,6 +375,9 @@ func (p *peer) Start() error {
|
||||
go p.channelManager()
|
||||
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
|
||||
// that must be resent for borked channels.
|
||||
if len(msgs) > 0 {
|
||||
|
12
server.go
12
server.go
@ -3207,6 +3207,18 @@ func (s *server) OpenChannel(
|
||||
}
|
||||
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
|
||||
// confirmation target.
|
||||
if req.fundingFeePerKw == 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user