multi: return verbose errors when fetching edges

This commit is contained in:
yyforyongyu 2024-06-07 01:14:33 +08:00
parent 78cc1619d7
commit e61cba8d22
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868
6 changed files with 27 additions and 24 deletions

View file

@ -1349,7 +1349,7 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
edges, edgeIndex, chanIndex, zombieIndex,
chanID, false, false,
)
if err != nil && err != ErrEdgeNotFound {
if err != nil && !errors.Is(err, ErrEdgeNotFound) {
return err
}
@ -1610,7 +1610,7 @@ func (c *ChannelGraph) DisconnectBlockAtHeight(height uint32) (
edges, edgeIndex, chanIndex, zombieIndex,
k, false, false,
)
if err != nil && err != ErrEdgeNotFound {
if err != nil && !errors.Is(err, ErrEdgeNotFound) {
return err
}
}
@ -2410,7 +2410,7 @@ func (c *ChannelGraph) FetchChanInfos(tx kvdb.RTx, chanIDs []uint64) (
edgeIndex, cidBytes[:],
)
switch {
case err == ErrEdgeNotFound:
case errors.Is(err, ErrEdgeNotFound):
continue
case err != nil:
return err
@ -2667,7 +2667,7 @@ func (c *ChannelGraph) UpdateEdgePolicy(edge *models.ChannelEdgePolicy,
// Silence ErrEdgeNotFound so that the batch can
// succeed, but propagate the error via local state.
if err == ErrEdgeNotFound {
if errors.Is(err, ErrEdgeNotFound) {
edgeNotFound = true
return nil
}
@ -3323,14 +3323,14 @@ func (c *ChannelGraph) FetchChannelEdgesByOutpoint(op *wire.OutPoint) (
}
chanID := chanIndex.Get(b.Bytes())
if chanID == nil {
return ErrEdgeNotFound
return fmt.Errorf("%w: op=%v", ErrEdgeNotFound, op)
}
// If the channel is found to exists, then we'll first retrieve
// the general information for the channel.
edge, err := fetchChanEdgeInfo(edgeIndex, chanID)
if err != nil {
return err
return fmt.Errorf("%w: chanID=%x", err, chanID)
}
edgeInfo = &edge
@ -3339,7 +3339,7 @@ func (c *ChannelGraph) FetchChannelEdgesByOutpoint(op *wire.OutPoint) (
// edges.
e1, e2, err := fetchChanEdgePolicies(edgeIndex, edges, chanID)
if err != nil {
return err
return fmt.Errorf("failed to find policy: %w", err)
}
policy1 = e1
@ -3404,7 +3404,7 @@ func (c *ChannelGraph) FetchChannelEdgesByID(chanID uint64) (
// If it doesn't exist, we'll quickly check our zombie index to
// see if we've previously marked it as so.
if err == ErrEdgeNotFound {
if errors.Is(err, ErrEdgeNotFound) {
// If the zombie index doesn't exist, or the edge is not
// marked as a zombie within it, then we'll return the
// original ErrEdgeNotFound error.
@ -4411,7 +4411,8 @@ func fetchChanEdgePolicies(edgeIndex kvdb.RBucket, edges kvdb.RBucket,
edgeInfo := edgeIndex.Get(chanID)
if edgeInfo == nil {
return nil, nil, ErrEdgeNotFound
return nil, nil, fmt.Errorf("%w: chanID=%x", ErrEdgeNotFound,
chanID)
}
// The first node is contained within the first half of the edge
@ -4420,7 +4421,8 @@ func fetchChanEdgePolicies(edgeIndex kvdb.RBucket, edges kvdb.RBucket,
node1Pub := edgeInfo[:33]
edge1, err := fetchChanEdgePolicy(edges, chanID, node1Pub)
if err != nil {
return nil, nil, err
return nil, nil, fmt.Errorf("%w: node1Pub=%x", ErrEdgeNotFound,
node1Pub)
}
// Similarly, the second node is contained within the latter
@ -4428,7 +4430,8 @@ func fetchChanEdgePolicies(edgeIndex kvdb.RBucket, edges kvdb.RBucket,
node2Pub := edgeInfo[33:66]
edge2, err := fetchChanEdgePolicy(edges, chanID, node2Pub)
if err != nil {
return nil, nil, err
return nil, nil, fmt.Errorf("%w: node2Pub=%x", ErrEdgeNotFound,
node2Pub)
}
return edge1, edge2, nil

View file

@ -2119,7 +2119,7 @@ func (d *AuthenticatedGossiper) isMsgStale(msg lnwire.Message) bool {
// If the channel cannot be found, it is most likely a leftover
// message for a channel that was closed, so we can consider it
// stale.
if err == channeldb.ErrEdgeNotFound {
if errors.Is(err, channeldb.ErrEdgeNotFound) {
return true
}
if err != nil {
@ -2139,7 +2139,7 @@ func (d *AuthenticatedGossiper) isMsgStale(msg lnwire.Message) bool {
// If the channel cannot be found, it is most likely a leftover
// message for a channel that was closed, so we can consider it
// stale.
if err == channeldb.ErrEdgeNotFound {
if errors.Is(err, channeldb.ErrEdgeNotFound) {
return true
}
if err != nil {
@ -2750,12 +2750,12 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
defer d.channelMtx.Unlock(graphScid.ToUint64())
chanInfo, e1, e2, err := d.cfg.Router.GetChannelByID(graphScid)
switch err {
switch {
// No error, break.
case nil:
case err == nil:
break
case channeldb.ErrZombieEdge:
case errors.Is(err, channeldb.ErrZombieEdge):
err = d.processZombieUpdate(chanInfo, graphScid, upd)
if err != nil {
log.Debug(err)
@ -2768,11 +2768,11 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
// needed to ensure the edge exists in the graph before
// applying the update.
fallthrough
case channeldb.ErrGraphNotFound:
case errors.Is(err, channeldb.ErrGraphNotFound):
fallthrough
case channeldb.ErrGraphNoEdgesFound:
case errors.Is(err, channeldb.ErrGraphNoEdgesFound):
fallthrough
case channeldb.ErrEdgeNotFound:
case errors.Is(err, channeldb.ErrEdgeNotFound):
// If the edge corresponding to this ChannelUpdate was not
// found in the graph, this might be a channel in the process
// of being opened, and we haven't processed our own

View file

@ -195,7 +195,7 @@ func (m *ChanStatusManager) start() error {
// have been pruned from the channel graph but not yet from our
// set of channels. We'll skip it as we can't determine its
// initial state.
case err == channeldb.ErrEdgeNotFound:
case errors.Is(err, channeldb.ErrEdgeNotFound):
log.Warnf("Unable to find channel policies for %v, "+
"skipping. This is typical if the channel is "+
"in the process of closing.", c.FundingOutpoint)
@ -580,7 +580,7 @@ func (m *ChanStatusManager) disableInactiveChannels() {
// that the channel has been closed. Thus we remove the
// outpoint from the set of tracked outpoints to prevent
// further attempts.
if err == channeldb.ErrEdgeNotFound {
if errors.Is(err, channeldb.ErrEdgeNotFound) {
log.Debugf("Removing channel(%v) from "+
"consideration for passive disabling",
outpoint)

View file

@ -974,7 +974,7 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) (
info, p1, p2, err := graph.FetchChannelEdgesByOutpoint(
&chanPoint,
)
if err != nil && err != channeldb.ErrEdgeNotFound {
if err != nil && !errors.Is(err, channeldb.ErrEdgeNotFound) {
return nil, err
}

View file

@ -2891,7 +2891,7 @@ func abandonChanFromGraph(chanGraph *channeldb.ChannelGraph,
// the graph, so we'll return a nil error.
chanID, err := chanGraph.ChannelID(chanPoint)
switch {
case err == channeldb.ErrEdgeNotFound:
case errors.Is(err, channeldb.ErrEdgeNotFound):
return nil
case err != nil:
return err

View file

@ -1266,7 +1266,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
info, e1, e2, err := s.graphDB.FetchChannelEdgesByID(
scid.ToUint64(),
)
if err == channeldb.ErrEdgeNotFound {
if errors.Is(err, channeldb.ErrEdgeNotFound) {
// This is unlikely but there is a slim chance of this
// being hit if lnd was killed via SIGKILL and the
// funding manager was stepping through the delete