server: handle case where both policies are not present in fetchLastChanUpdateByOutPoint
This commit is contained in:
parent
5deffd228c
commit
4581aa313c
46
server.go
46
server.go
@ -2964,32 +2964,48 @@ func (s *server) announceChanStatus(op wire.OutPoint, disabled bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetchLastChanUpdateByOutPoint fetches the latest update for a channel from
|
// fetchLastChanUpdateByOutPoint fetches the latest policy for our direction of
|
||||||
// our point of view.
|
// a channel, and crafts a new ChannelUpdate with this policy. Returns an error
|
||||||
func (s *server) fetchLastChanUpdateByOutPoint(op wire.OutPoint) (*lnwire.ChannelUpdate, error) {
|
// in case our ChannelEdgePolicy is not found in the database.
|
||||||
|
func (s *server) fetchLastChanUpdateByOutPoint(op wire.OutPoint) (
|
||||||
|
*lnwire.ChannelUpdate, error) {
|
||||||
|
|
||||||
|
// Get the edge info and policies for this channel from the graph.
|
||||||
graph := s.chanDB.ChannelGraph()
|
graph := s.chanDB.ChannelGraph()
|
||||||
info, edge1, edge2, err := graph.FetchChannelEdgesByOutpoint(&op)
|
info, edge1, edge2, err := graph.FetchChannelEdgesByOutpoint(&op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if edge1 == nil || edge2 == nil {
|
// Helper function to extract the owner of the given policy.
|
||||||
return nil, fmt.Errorf("unable to find channel(%v)", op)
|
owner := func(edge *channeldb.ChannelEdgePolicy) []byte {
|
||||||
|
var pubKey *btcec.PublicKey
|
||||||
|
switch {
|
||||||
|
case edge.Flags&lnwire.ChanUpdateDirection == 0:
|
||||||
|
pubKey, _ = info.NodeKey1()
|
||||||
|
case edge.Flags&lnwire.ChanUpdateDirection == 1:
|
||||||
|
pubKey, _ = info.NodeKey2()
|
||||||
|
}
|
||||||
|
|
||||||
|
// If pubKey was not found, just return nil.
|
||||||
|
if pubKey == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubKey.SerializeCompressed()
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're the outgoing node on the first edge, then that
|
// Extract the channel update from the policy we own, if any.
|
||||||
// means the second edge is our policy. Otherwise, the first
|
|
||||||
// edge is our policy.
|
|
||||||
var local *channeldb.ChannelEdgePolicy
|
|
||||||
|
|
||||||
ourPubKey := s.identityPriv.PubKey().SerializeCompressed()
|
ourPubKey := s.identityPriv.PubKey().SerializeCompressed()
|
||||||
if bytes.Equal(edge1.Node.PubKeyBytes[:], ourPubKey) {
|
if edge1 != nil && bytes.Equal(ourPubKey, owner(edge1)) {
|
||||||
local = edge2
|
return extractChannelUpdate(info, edge1)
|
||||||
} else {
|
|
||||||
local = edge1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return extractChannelUpdate(info, local)
|
if edge2 != nil && bytes.Equal(ourPubKey, owner(edge2)) {
|
||||||
|
return extractChannelUpdate(info, edge2)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("unable to find channel(%v)", op)
|
||||||
}
|
}
|
||||||
|
|
||||||
// extractChannelUpdate retrieves a lnwire.ChannelUpdate message from an edge's
|
// extractChannelUpdate retrieves a lnwire.ChannelUpdate message from an edge's
|
||||||
|
Loading…
Reference in New Issue
Block a user