peer: use new fetchLastChanUpdate method to populate the ChannelLinkConfig

This commit is contained in:
Olaoluwa Osuntokun 2018-04-03 20:12:03 -07:00
parent 8b520377bb
commit ffabb17ce6
No known key found for this signature in database
GPG key ID: 964EA263DD637C21

36
peer.go
View file

@ -413,8 +413,9 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
Peer: p, Peer: p,
DecodeHopIterators: p.server.sphinx.DecodeHopIterators, DecodeHopIterators: p.server.sphinx.DecodeHopIterators,
ExtractErrorEncrypter: p.server.sphinx.ExtractErrorEncrypter, ExtractErrorEncrypter: p.server.sphinx.ExtractErrorEncrypter,
GetLastChannelUpdate: createGetLastUpdate(p.server.chanRouter, FetchLastChannelUpdate: fetchLastChanUpdate(
p.PubKey(), lnChan.ShortChanID()), p.server.chanRouter, p.PubKey(),
),
DebugHTLC: cfg.DebugHTLC, DebugHTLC: cfg.DebugHTLC,
HodlHTLC: cfg.HodlHTLC, HodlHTLC: cfg.HodlHTLC,
Registry: p.server.invoices, Registry: p.server.invoices,
@ -1389,8 +1390,9 @@ out:
Peer: p, Peer: p,
DecodeHopIterators: p.server.sphinx.DecodeHopIterators, DecodeHopIterators: p.server.sphinx.DecodeHopIterators,
ExtractErrorEncrypter: p.server.sphinx.ExtractErrorEncrypter, ExtractErrorEncrypter: p.server.sphinx.ExtractErrorEncrypter,
GetLastChannelUpdate: createGetLastUpdate(p.server.chanRouter, FetchLastChannelUpdate: fetchLastChanUpdate(
p.PubKey(), newChanReq.channel.ShortChanID()), p.server.chanRouter, p.PubKey(),
),
DebugHTLC: cfg.DebugHTLC, DebugHTLC: cfg.DebugHTLC,
HodlHTLC: cfg.HodlHTLC, HodlHTLC: cfg.HodlHTLC,
Registry: p.server.invoices, Registry: p.server.invoices,
@ -1906,21 +1908,20 @@ func (p *peer) PubKey() [33]byte {
// TODO(roasbeef): make all start/stop mutexes a CAS // TODO(roasbeef): make all start/stop mutexes a CAS
// createGetLastUpdate returns the handler which serve as a source of the last // fetchLastChanUpdate returns a function which is able to retrieve the last
// update of the channel in a form of lnwire update message. // channel update for a target channel.
func createGetLastUpdate(router *routing.ChannelRouter, func fetchLastChanUpdate(router *routing.ChannelRouter,
pubKey [33]byte, chanID lnwire.ShortChannelID) func() (*lnwire.ChannelUpdate, pubKey [33]byte) func(lnwire.ShortChannelID) (*lnwire.ChannelUpdate, error) {
error) {
return func() (*lnwire.ChannelUpdate, error) { return func(cid lnwire.ShortChannelID) (*lnwire.ChannelUpdate, error) {
info, edge1, edge2, err := router.GetChannelByID(chanID) info, edge1, edge2, err := router.GetChannelByID(cid)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if edge1 == nil || edge2 == nil { if edge1 == nil || edge2 == nil {
return nil, errors.Errorf("unable to find "+ return nil, errors.Errorf("unable to find "+
"channel by ShortChannelID(%v)", chanID) "channel by ShortChannelID(%v)", cid)
} }
// If we're the outgoing node on the first edge, then that // If we're the outgoing node on the first edge, then that
@ -1933,7 +1934,7 @@ func createGetLastUpdate(router *routing.ChannelRouter,
local = edge1 local = edge1
} }
update := &lnwire.ChannelUpdate{ update := lnwire.ChannelUpdate{
ChainHash: info.ChainHash, ChainHash: info.ChainHash,
ShortChannelID: lnwire.NewShortChanIDFromInt(local.ChannelID), ShortChannelID: lnwire.NewShortChanIDFromInt(local.ChannelID),
Timestamp: uint32(local.LastUpdate.Unix()), Timestamp: uint32(local.LastUpdate.Unix()),
@ -1948,9 +1949,12 @@ func createGetLastUpdate(router *routing.ChannelRouter,
return nil, err return nil, err
} }
hswcLog.Debugf("Sending latest channel_update: %v", hswcLog.Tracef("Sending latest channel_update: %v",
spew.Sdump(update)) newLogClosure(func() string {
return spew.Sdump(update)
}),
)
return update, nil return &update, nil
} }
} }