funding: make SendAnnouncement return error chan instead of error

This commit is contained in:
Johan T. Halseth 2018-08-20 14:28:11 +02:00
parent 4b04e1afd1
commit 67d36eb79d
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
2 changed files with 65 additions and 31 deletions

@ -255,7 +255,7 @@ type fundingConfig struct {
// SendAnnouncement is used by the FundingManager to send // SendAnnouncement is used by the FundingManager to send
// announcement messages to the Gossiper to possibly broadcast // announcement messages to the Gossiper to possibly broadcast
// to the greater network. // to the greater network.
SendAnnouncement func(msg lnwire.Message) error SendAnnouncement func(msg lnwire.Message) chan error
// NotifyWhenOnline allows the FundingManager to register with a // NotifyWhenOnline allows the FundingManager to register with a
// subsystem that will notify it when the peer comes online. This is // subsystem that will notify it when the peer comes online. This is
@ -2078,22 +2078,38 @@ func (f *fundingManager) addToRouterGraph(completeChan *channeldb.OpenChannel,
// Send ChannelAnnouncement and ChannelUpdate to the gossiper to add // Send ChannelAnnouncement and ChannelUpdate to the gossiper to add
// to the Router's topology. // to the Router's topology.
if err = f.cfg.SendAnnouncement(ann.chanAnn); err != nil { errChan := f.cfg.SendAnnouncement(ann.chanAnn)
if routing.IsError(err, routing.ErrOutdated, routing.ErrIgnored) { select {
fndgLog.Debugf("Router rejected ChannelAnnouncement: %v", case err := <-errChan:
err) if err != nil {
} else { if routing.IsError(err, routing.ErrOutdated,
return fmt.Errorf("error sending channel "+ routing.ErrIgnored) {
"announcement: %v", err) fndgLog.Debugf("Router rejected "+
"ChannelAnnouncement: %v", err)
} else {
return fmt.Errorf("error sending channel "+
"announcement: %v", err)
}
} }
case <-f.quit:
return ErrFundingManagerShuttingDown
} }
if err = f.cfg.SendAnnouncement(ann.chanUpdateAnn); err != nil {
if routing.IsError(err, routing.ErrOutdated, routing.ErrIgnored) { errChan = f.cfg.SendAnnouncement(ann.chanUpdateAnn)
fndgLog.Debugf("Router rejected ChannelUpdate: %v", err) select {
} else { case err := <-errChan:
return fmt.Errorf("error sending channel "+ if err != nil {
"update: %v", err) if routing.IsError(err, routing.ErrOutdated,
routing.ErrIgnored) {
fndgLog.Debugf("Router rejected "+
"ChannelUpdate: %v", err)
} else {
return fmt.Errorf("error sending channel "+
"update: %v", err)
}
} }
case <-f.quit:
return ErrFundingManagerShuttingDown
} }
// As the channel is now added to the ChannelRouter's topology, the // As the channel is now added to the ChannelRouter's topology, the
@ -2516,14 +2532,23 @@ func (f *fundingManager) announceChannel(localIDKey, remoteIDKey, localFundingKe
// because addToRouterGraph previously send the ChannelAnnouncement and // because addToRouterGraph previously send the ChannelAnnouncement and
// the ChannelUpdate announcement messages. The channel proof and node // the ChannelUpdate announcement messages. The channel proof and node
// announcements are broadcast to the greater network. // announcements are broadcast to the greater network.
if err = f.cfg.SendAnnouncement(ann.chanProof); err != nil { errChan := f.cfg.SendAnnouncement(ann.chanProof)
if routing.IsError(err, routing.ErrOutdated, routing.ErrIgnored) { select {
fndgLog.Debugf("Router rejected AnnounceSignatures: %v", case err := <-errChan:
err) if err != nil {
} else { if routing.IsError(err, routing.ErrOutdated,
fndgLog.Errorf("Unable to send channel proof: %v", err) routing.ErrIgnored) {
return err fndgLog.Debugf("Router rejected "+
"AnnounceSignatures: %v", err)
} else {
fndgLog.Errorf("Unable to send channel "+
"proof: %v", err)
return err
}
} }
case <-f.quit:
return ErrFundingManagerShuttingDown
} }
// Now that the channel is announced to the network, we will also // Now that the channel is announced to the network, we will also
@ -2536,15 +2561,25 @@ func (f *fundingManager) announceChannel(localIDKey, remoteIDKey, localFundingKe
return err return err
} }
if err := f.cfg.SendAnnouncement(&nodeAnn); err != nil { errChan = f.cfg.SendAnnouncement(&nodeAnn)
if routing.IsError(err, routing.ErrOutdated, routing.ErrIgnored) { select {
fndgLog.Debugf("Router rejected NodeAnnouncement: %v", case err := <-errChan:
err) if err != nil {
} else { if routing.IsError(err, routing.ErrOutdated,
fndgLog.Errorf("Unable to send node announcement: %v", err) routing.ErrIgnored) {
return err fndgLog.Debugf("Router rejected "+
"NodeAnnouncement: %v", err)
} else {
fndgLog.Errorf("Unable to send node "+
"announcement: %v", err)
return err
}
} }
case <-f.quit:
return ErrFundingManagerShuttingDown
} }
return nil return nil
} }

@ -738,11 +738,10 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl,
CurrentNodeAnnouncement: func() (lnwire.NodeAnnouncement, error) { CurrentNodeAnnouncement: func() (lnwire.NodeAnnouncement, error) {
return s.genNodeAnnouncement(true) return s.genNodeAnnouncement(true)
}, },
SendAnnouncement: func(msg lnwire.Message) error { SendAnnouncement: func(msg lnwire.Message) chan error {
errChan := s.authGossiper.ProcessLocalAnnouncement( return s.authGossiper.ProcessLocalAnnouncement(
msg, privKey.PubKey(), msg, privKey.PubKey(),
) )
return <-errChan
}, },
NotifyWhenOnline: s.NotifyWhenOnline, NotifyWhenOnline: s.NotifyWhenOnline,
TempChanIDSeed: chanIDSeed, TempChanIDSeed: chanIDSeed,