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

View File

@ -255,7 +255,7 @@ type fundingConfig struct {
// SendAnnouncement is used by the FundingManager to send
// announcement messages to the Gossiper to possibly broadcast
// 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
// 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
// to the Router's topology.
if err = f.cfg.SendAnnouncement(ann.chanAnn); err != nil {
if routing.IsError(err, routing.ErrOutdated, routing.ErrIgnored) {
fndgLog.Debugf("Router rejected ChannelAnnouncement: %v",
err)
} else {
return fmt.Errorf("error sending channel "+
"announcement: %v", err)
errChan := f.cfg.SendAnnouncement(ann.chanAnn)
select {
case err := <-errChan:
if err != nil {
if routing.IsError(err, routing.ErrOutdated,
routing.ErrIgnored) {
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) {
fndgLog.Debugf("Router rejected ChannelUpdate: %v", err)
} else {
return fmt.Errorf("error sending channel "+
"update: %v", err)
errChan = f.cfg.SendAnnouncement(ann.chanUpdateAnn)
select {
case err := <-errChan:
if err != nil {
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
@ -2516,14 +2532,23 @@ func (f *fundingManager) announceChannel(localIDKey, remoteIDKey, localFundingKe
// because addToRouterGraph previously send the ChannelAnnouncement and
// the ChannelUpdate announcement messages. The channel proof and node
// announcements are broadcast to the greater network.
if err = f.cfg.SendAnnouncement(ann.chanProof); err != nil {
if routing.IsError(err, routing.ErrOutdated, routing.ErrIgnored) {
fndgLog.Debugf("Router rejected AnnounceSignatures: %v",
err)
} else {
fndgLog.Errorf("Unable to send channel proof: %v", err)
return err
errChan := f.cfg.SendAnnouncement(ann.chanProof)
select {
case err := <-errChan:
if err != nil {
if routing.IsError(err, routing.ErrOutdated,
routing.ErrIgnored) {
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
@ -2536,15 +2561,25 @@ func (f *fundingManager) announceChannel(localIDKey, remoteIDKey, localFundingKe
return err
}
if err := f.cfg.SendAnnouncement(&nodeAnn); err != nil {
if routing.IsError(err, routing.ErrOutdated, routing.ErrIgnored) {
fndgLog.Debugf("Router rejected NodeAnnouncement: %v",
err)
} else {
fndgLog.Errorf("Unable to send node announcement: %v", err)
return err
errChan = f.cfg.SendAnnouncement(&nodeAnn)
select {
case err := <-errChan:
if err != nil {
if routing.IsError(err, routing.ErrOutdated,
routing.ErrIgnored) {
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
}

View File

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