server: make extractChannelUpdate extract from set of potential policies

This commit is contained in:
Johan T. Halseth 2018-08-22 09:32:44 +02:00
parent 229fd88289
commit de5e9e139c
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
2 changed files with 22 additions and 12 deletions

@ -2139,6 +2139,6 @@ func fetchLastChanUpdate(s *server,
local = edge1
}
return extractChannelUpdate(info, local)
return extractChannelUpdate(pubKey[:], info, local)
}
}

@ -2953,6 +2953,18 @@ func (s *server) fetchLastChanUpdateByOutPoint(op wire.OutPoint) (
return nil, err
}
pubKey := s.identityPriv.PubKey().SerializeCompressed()
return extractChannelUpdate(pubKey, info, edge1, edge2)
}
// extractChannelUpdate attempts to retrieve a lnwire.ChannelUpdate message
// from an edge's info and a set of routing policies.
// NOTE: the passed policies can be nil.
func extractChannelUpdate(ownerPubKey []byte,
info *channeldb.ChannelEdgeInfo,
policies ...*channeldb.ChannelEdgePolicy) (
*lnwire.ChannelUpdate, error) {
// Helper function to extract the owner of the given policy.
owner := func(edge *channeldb.ChannelEdgePolicy) []byte {
var pubKey *btcec.PublicKey
@ -2972,21 +2984,19 @@ func (s *server) fetchLastChanUpdateByOutPoint(op wire.OutPoint) (
}
// Extract the channel update from the policy we own, if any.
ourPubKey := s.identityPriv.PubKey().SerializeCompressed()
if edge1 != nil && bytes.Equal(ourPubKey, owner(edge1)) {
return extractChannelUpdate(info, edge1)
for _, edge := range policies {
if edge != nil && bytes.Equal(ownerPubKey, owner(edge)) {
return createChannelUpdate(info, edge)
}
}
if edge2 != nil && bytes.Equal(ourPubKey, owner(edge2)) {
return extractChannelUpdate(info, edge2)
return nil, fmt.Errorf("unable to extract ChannelUpdate for channel %v",
info.ChannelPoint)
}
return nil, fmt.Errorf("unable to find channel(%v)", op)
}
// extractChannelUpdate retrieves a lnwire.ChannelUpdate message from an edge's
// info and routing policy.
func extractChannelUpdate(info *channeldb.ChannelEdgeInfo,
// createChannelUpdate reconstructs a signed ChannelUpdate from the given edge
// info and policy.
func createChannelUpdate(info *channeldb.ChannelEdgeInfo,
policy *channeldb.ChannelEdgePolicy) (*lnwire.ChannelUpdate, error) {
update := &lnwire.ChannelUpdate{