server: make extractChannelUpdate extract from set of potential policies
This commit is contained in:
parent
229fd88289
commit
de5e9e139c
2
peer.go
2
peer.go
@ -2139,6 +2139,6 @@ func fetchLastChanUpdate(s *server,
|
|||||||
local = edge1
|
local = edge1
|
||||||
}
|
}
|
||||||
|
|
||||||
return extractChannelUpdate(info, local)
|
return extractChannelUpdate(pubKey[:], info, local)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
32
server.go
32
server.go
@ -2953,6 +2953,18 @@ func (s *server) fetchLastChanUpdateByOutPoint(op wire.OutPoint) (
|
|||||||
return nil, err
|
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.
|
// Helper function to extract the owner of the given policy.
|
||||||
owner := func(edge *channeldb.ChannelEdgePolicy) []byte {
|
owner := func(edge *channeldb.ChannelEdgePolicy) []byte {
|
||||||
var pubKey *btcec.PublicKey
|
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.
|
// Extract the channel update from the policy we own, if any.
|
||||||
ourPubKey := s.identityPriv.PubKey().SerializeCompressed()
|
for _, edge := range policies {
|
||||||
if edge1 != nil && bytes.Equal(ourPubKey, owner(edge1)) {
|
if edge != nil && bytes.Equal(ownerPubKey, owner(edge)) {
|
||||||
return extractChannelUpdate(info, edge1)
|
return createChannelUpdate(info, edge)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if edge2 != nil && bytes.Equal(ourPubKey, owner(edge2)) {
|
return nil, fmt.Errorf("unable to extract ChannelUpdate for channel %v",
|
||||||
return extractChannelUpdate(info, edge2)
|
info.ChannelPoint)
|
||||||
}
|
|
||||||
|
|
||||||
return nil, fmt.Errorf("unable to find channel(%v)", op)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// extractChannelUpdate retrieves a lnwire.ChannelUpdate message from an edge's
|
// createChannelUpdate reconstructs a signed ChannelUpdate from the given edge
|
||||||
// info and routing policy.
|
// info and policy.
|
||||||
func extractChannelUpdate(info *channeldb.ChannelEdgeInfo,
|
func createChannelUpdate(info *channeldb.ChannelEdgeInfo,
|
||||||
policy *channeldb.ChannelEdgePolicy) (*lnwire.ChannelUpdate, error) {
|
policy *channeldb.ChannelEdgePolicy) (*lnwire.ChannelUpdate, error) {
|
||||||
|
|
||||||
update := &lnwire.ChannelUpdate{
|
update := &lnwire.ChannelUpdate{
|
||||||
|
Loading…
Reference in New Issue
Block a user