discovery/gossiper: update to latest NotifyWhenOnline changes

This commit is contained in:
Wilmer Paulino 2018-07-05 18:19:35 -07:00
parent 04c5eba194
commit 6d4da72156
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
2 changed files with 18 additions and 14 deletions

@ -107,7 +107,9 @@ type Config struct {
// NotifyWhenOnline is a function that allows the gossiper to be
// notified when a certain peer comes online, allowing it to
// retry sending a peer message.
NotifyWhenOnline func(peer *btcec.PublicKey, connectedChan chan<- struct{})
//
// NOTE: The peerChan channel must be buffered.
NotifyWhenOnline func(peer *btcec.PublicKey, peerChan chan<- lnpeer.Peer)
// ProofMatureDelta the number of confirmations which is needed before
// exchange the channel announcement proofs.
@ -2399,13 +2401,13 @@ func (d *AuthenticatedGossiper) sendAnnSigReliably(
"to peer(%x): %v. Will retry when online.",
remotePeer.SerializeCompressed(), err)
connected := make(chan struct{})
d.cfg.NotifyWhenOnline(remotePeer, connected)
peerChan := make(chan lnpeer.Peer, 1)
d.cfg.NotifyWhenOnline(remotePeer, peerChan)
select {
case <-connected:
case <-peerChan:
// Retry sending.
log.Infof("peer %x reconnected. Retry sending"+
log.Infof("Peer %x reconnected. Retry sending"+
" AnnounceSignatures.",
remotePeer.SerializeCompressed())

@ -1187,9 +1187,9 @@ func TestSignatureAnnouncementRetry(t *testing.T) {
// We expect the gossiper to register for a notification when the peer
// comes back online, so keep track of the channel it wants to get
// notified on.
notifyPeers := make(chan chan<- struct{}, 1)
notifyPeers := make(chan chan<- lnpeer.Peer, 1)
ctx.gossiper.cfg.NotifyWhenOnline = func(peer *btcec.PublicKey,
connectedChan chan<- struct{}) {
connectedChan chan<- lnpeer.Peer) {
notifyPeers <- connectedChan
}
@ -1208,7 +1208,7 @@ func TestSignatureAnnouncementRetry(t *testing.T) {
// Since sending this local announcement proof to the remote will fail,
// the gossiper should register for a notification when the remote is
// online again.
var conChan chan<- struct{}
var conChan chan<- lnpeer.Peer
select {
case conChan = <-notifyPeers:
case <-time.After(2 * time.Second):
@ -1372,9 +1372,9 @@ func TestSignatureAnnouncementRetryAtStartup(t *testing.T) {
msg ...lnwire.Message) error {
return fmt.Errorf("intentional error in SendToPeer")
}
notifyPeers := make(chan chan<- struct{}, 1)
notifyPeers := make(chan chan<- lnpeer.Peer, 1)
ctx.gossiper.cfg.NotifyWhenOnline = func(peer *btcec.PublicKey,
connectedChan chan<- struct{}) {
connectedChan chan<- lnpeer.Peer) {
notifyPeers <- connectedChan
}
@ -1392,7 +1392,7 @@ func TestSignatureAnnouncementRetryAtStartup(t *testing.T) {
// Since sending to the remote peer will fail, the gossiper should
// register for a notification when it comes back online.
var conChan chan<- struct{}
var conChan chan<- lnpeer.Peer
select {
case conChan = <-notifyPeers:
case <-time.After(2 * time.Second):
@ -1431,7 +1431,7 @@ func TestSignatureAnnouncementRetryAtStartup(t *testing.T) {
return fmt.Errorf("intentional error in SendToPeer")
},
NotifyWhenOnline: func(peer *btcec.PublicKey,
connectedChan chan<- struct{}) {
connectedChan chan<- lnpeer.Peer) {
notifyPeers <- connectedChan
},
Router: ctx.gossiper.cfg.Router,
@ -1607,9 +1607,9 @@ func TestSignatureAnnouncementFullProofWhenRemoteProof(t *testing.T) {
return nil
}
notifyPeers := make(chan chan<- struct{}, 1)
notifyPeers := make(chan chan<- lnpeer.Peer, 1)
ctx.gossiper.cfg.NotifyWhenOnline = func(peer *btcec.PublicKey,
connectedChan chan<- struct{}) {
connectedChan chan<- lnpeer.Peer) {
notifyPeers <- connectedChan
}
@ -2146,6 +2146,8 @@ type mockPeer struct {
quit chan struct{}
}
var _ lnpeer.Peer = (*mockPeer)(nil)
func (p *mockPeer) SendMessage(_ bool, msgs ...lnwire.Message) error {
if p.sentMsgs == nil && p.quit == nil {
return nil