Merge pull request #8815 from yyforyongyu/fix-edge-policy

trivial: fix linter errors and return verbose errors
This commit is contained in:
Oliver Gugger authored and GitHub committed 2024-06-10 12:48:59 -06:00
commit 931b3dc0c3
8 files changed
+38 -37

No files matched your search

+14 -11
View File
@@ -1349,7 +1349,7 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
edges, edgeIndex, chanIndex, zombieIndex, edges, edgeIndex, chanIndex, zombieIndex,
chanID, false, false, chanID, false, false,
) )
if err != nil && err != ErrEdgeNotFound { if err != nil && !errors.Is(err, ErrEdgeNotFound) {
return err return err
} }
@@ -1610,7 +1610,7 @@ func (c *ChannelGraph) DisconnectBlockAtHeight(height uint32) (
edges, edgeIndex, chanIndex, zombieIndex, edges, edgeIndex, chanIndex, zombieIndex,
k, false, false, k, false, false,
) )
if err != nil && err != ErrEdgeNotFound { if err != nil && !errors.Is(err, ErrEdgeNotFound) {
return err return err
} }
} }
@@ -2410,7 +2410,7 @@ func (c *ChannelGraph) FetchChanInfos(tx kvdb.RTx, chanIDs []uint64) (
edgeIndex, cidBytes[:], edgeIndex, cidBytes[:],
) )
switch { switch {
case err == ErrEdgeNotFound: case errors.Is(err, ErrEdgeNotFound):
continue continue
case err != nil: case err != nil:
return err return err
@@ -2667,7 +2667,7 @@ func (c *ChannelGraph) UpdateEdgePolicy(edge *models.ChannelEdgePolicy,
// Silence ErrEdgeNotFound so that the batch can // Silence ErrEdgeNotFound so that the batch can
// succeed, but propagate the error via local state. // succeed, but propagate the error via local state.
if err == ErrEdgeNotFound { if errors.Is(err, ErrEdgeNotFound) {
edgeNotFound = true edgeNotFound = true
return nil return nil
} }
@@ -3323,14 +3323,14 @@ func (c *ChannelGraph) FetchChannelEdgesByOutpoint(op *wire.OutPoint) (
} }
chanID := chanIndex.Get(b.Bytes()) chanID := chanIndex.Get(b.Bytes())
if chanID == nil { 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 // If the channel is found to exists, then we'll first retrieve
// the general information for the channel. // the general information for the channel.
edge, err := fetchChanEdgeInfo(edgeIndex, chanID) edge, err := fetchChanEdgeInfo(edgeIndex, chanID)
if err != nil { if err != nil {
return err return fmt.Errorf("%w: chanID=%x", err, chanID)
} }
edgeInfo = &edge edgeInfo = &edge
@@ -3339,7 +3339,7 @@ func (c *ChannelGraph) FetchChannelEdgesByOutpoint(op *wire.OutPoint) (
// edges. // edges.
e1, e2, err := fetchChanEdgePolicies(edgeIndex, edges, chanID) e1, e2, err := fetchChanEdgePolicies(edgeIndex, edges, chanID)
if err != nil { if err != nil {
return err return fmt.Errorf("failed to find policy: %w", err)
} }
policy1 = e1 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 // If it doesn't exist, we'll quickly check our zombie index to
// see if we've previously marked it as so. // 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 // If the zombie index doesn't exist, or the edge is not
// marked as a zombie within it, then we'll return the // marked as a zombie within it, then we'll return the
// original ErrEdgeNotFound error. // original ErrEdgeNotFound error.
@@ -4411,7 +4411,8 @@ func fetchChanEdgePolicies(edgeIndex kvdb.RBucket, edges kvdb.RBucket,
edgeInfo := edgeIndex.Get(chanID) edgeInfo := edgeIndex.Get(chanID)
if edgeInfo == nil { 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 // 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] node1Pub := edgeInfo[:33]
edge1, err := fetchChanEdgePolicy(edges, chanID, node1Pub) edge1, err := fetchChanEdgePolicy(edges, chanID, node1Pub)
if err != nil { 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 // 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] node2Pub := edgeInfo[33:66]
edge2, err := fetchChanEdgePolicy(edges, chanID, node2Pub) edge2, err := fetchChanEdgePolicy(edges, chanID, node2Pub)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, fmt.Errorf("%w: node2Pub=%x", ErrEdgeNotFound,
node2Pub)
} }
return edge1, edge2, nil return edge1, edge2, nil
+4 -4
View File
@@ -958,7 +958,7 @@ func initBreachedState(t *testing.T) (*BreachArbitrator,
// Create a pair of channels using a notifier that allows us to signal // Create a pair of channels using a notifier that allows us to signal
// a spend of the funding transaction. Alice's channel will be the on // a spend of the funding transaction. Alice's channel will be the on
// observing a breach. // observing a breach.
alice, bob, err := createInitChannels(t, 1) alice, bob, err := createInitChannels(t)
require.NoError(t, err, "unable to create test channels") require.NoError(t, err, "unable to create test channels")
// Instantiate a breach arbiter to handle the breach of alice's channel. // Instantiate a breach arbiter to handle the breach of alice's channel.
@@ -2150,7 +2150,7 @@ func createTestArbiter(t *testing.T, contractBreaches chan *ContractBreachEvent,
// createInitChannels creates two initialized test channels funded with 10 BTC, // createInitChannels creates two initialized test channels funded with 10 BTC,
// with 5 BTC allocated to each side. Within the channel, Alice is the // with 5 BTC allocated to each side. Within the channel, Alice is the
// initiator. // initiator.
func createInitChannels(t *testing.T, revocationWindow int) ( func createInitChannels(t *testing.T) (
*lnwallet.LightningChannel, *lnwallet.LightningChannel, error) { *lnwallet.LightningChannel, *lnwallet.LightningChannel, error) {
aliceKeyPriv, aliceKeyPub := btcec.PrivKeyFromBytes( aliceKeyPriv, aliceKeyPub := btcec.PrivKeyFromBytes(
@@ -2395,7 +2395,7 @@ func createInitChannels(t *testing.T, revocationWindow int) (
// Now that the channel are open, simulate the start of a session by // Now that the channel are open, simulate the start of a session by
// having Alice and Bob extend their revocation windows to each other. // having Alice and Bob extend their revocation windows to each other.
err = initRevocationWindows(channelAlice, channelBob, revocationWindow) err = initRevocationWindows(channelAlice, channelBob)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@@ -2408,7 +2408,7 @@ func createInitChannels(t *testing.T, revocationWindow int) (
// commitment state machines. // commitment state machines.
// //
// TODO(conner) remove code duplication // TODO(conner) remove code duplication
func initRevocationWindows(chanA, chanB *lnwallet.LightningChannel, windowSize int) error { func initRevocationWindows(chanA, chanB *lnwallet.LightningChannel) error {
aliceNextRevoke, err := chanA.NextRevocationKey() aliceNextRevoke, err := chanA.NextRevocationKey()
if err != nil { if err != nil {
return err return err
+8 -8
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 // If the channel cannot be found, it is most likely a leftover
// message for a channel that was closed, so we can consider it // message for a channel that was closed, so we can consider it
// stale. // stale.
if err == channeldb.ErrEdgeNotFound { if errors.Is(err, channeldb.ErrEdgeNotFound) {
return true return true
} }
if err != nil { 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 // If the channel cannot be found, it is most likely a leftover
// message for a channel that was closed, so we can consider it // message for a channel that was closed, so we can consider it
// stale. // stale.
if err == channeldb.ErrEdgeNotFound { if errors.Is(err, channeldb.ErrEdgeNotFound) {
return true return true
} }
if err != nil { if err != nil {
@@ -2750,12 +2750,12 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
defer d.channelMtx.Unlock(graphScid.ToUint64()) defer d.channelMtx.Unlock(graphScid.ToUint64())
chanInfo, e1, e2, err := d.cfg.Router.GetChannelByID(graphScid) chanInfo, e1, e2, err := d.cfg.Router.GetChannelByID(graphScid)
switch err { switch {
// No error, break. // No error, break.
case nil: case err == nil:
break break
case channeldb.ErrZombieEdge: case errors.Is(err, channeldb.ErrZombieEdge):
err = d.processZombieUpdate(chanInfo, graphScid, upd) err = d.processZombieUpdate(chanInfo, graphScid, upd)
if err != nil { if err != nil {
log.Debug(err) log.Debug(err)
@@ -2768,11 +2768,11 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
// needed to ensure the edge exists in the graph before // needed to ensure the edge exists in the graph before
// applying the update. // applying the update.
fallthrough fallthrough
case channeldb.ErrGraphNotFound: case errors.Is(err, channeldb.ErrGraphNotFound):
fallthrough fallthrough
case channeldb.ErrGraphNoEdgesFound: case errors.Is(err, channeldb.ErrGraphNoEdgesFound):
fallthrough fallthrough
case channeldb.ErrEdgeNotFound: case errors.Is(err, channeldb.ErrEdgeNotFound):
// If the edge corresponding to this ChannelUpdate was not // If the edge corresponding to this ChannelUpdate was not
// found in the graph, this might be a channel in the process // found in the graph, this might be a channel in the process
// of being opened, and we haven't processed our own // of being opened, and we haven't processed our own
+2 -4
View File
@@ -1188,7 +1188,7 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel,
// If this is a zero-conf channel, then we will wait // If this is a zero-conf channel, then we will wait
// for it to be confirmed before announcing it to the // for it to be confirmed before announcing it to the
// greater network. // greater network.
err := f.waitForZeroConfChannel(channel, pendingChanID) err := f.waitForZeroConfChannel(channel)
if err != nil { if err != nil {
return fmt.Errorf("failed waiting for zero "+ return fmt.Errorf("failed waiting for zero "+
"channel: %v", err) "channel: %v", err)
@@ -3605,9 +3605,7 @@ func (f *Manager) annAfterSixConfs(completeChan *channeldb.OpenChannel,
// waitForZeroConfChannel is called when the state is addedToRouterGraph with // waitForZeroConfChannel is called when the state is addedToRouterGraph with
// a zero-conf channel. This will wait for the real confirmation, add the // a zero-conf channel. This will wait for the real confirmation, add the
// confirmed SCID to the router graph, and then announce after six confs. // confirmed SCID to the router graph, and then announce after six confs.
func (f *Manager) waitForZeroConfChannel(c *channeldb.OpenChannel, func (f *Manager) waitForZeroConfChannel(c *channeldb.OpenChannel) error {
pendingID [32]byte) error {
// First we'll check whether the channel is confirmed on-chain. If it // First we'll check whether the channel is confirmed on-chain. If it
// is already confirmed, the chainntnfs subsystem will return with the // is already confirmed, the chainntnfs subsystem will return with the
// confirmed tx. Otherwise, we'll wait here until confirmation occurs. // confirmed tx. Otherwise, we'll wait here until confirmation occurs.
+2 -2
View File
@@ -195,7 +195,7 @@ func (m *ChanStatusManager) start() error {
// have been pruned from the channel graph but not yet from our // 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 // set of channels. We'll skip it as we can't determine its
// initial state. // initial state.
case err == channeldb.ErrEdgeNotFound: case errors.Is(err, channeldb.ErrEdgeNotFound):
log.Warnf("Unable to find channel policies for %v, "+ log.Warnf("Unable to find channel policies for %v, "+
"skipping. This is typical if the channel is "+ "skipping. This is typical if the channel is "+
"in the process of closing.", c.FundingOutpoint) "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 // that the channel has been closed. Thus we remove the
// outpoint from the set of tracked outpoints to prevent // outpoint from the set of tracked outpoints to prevent
// further attempts. // further attempts.
if err == channeldb.ErrEdgeNotFound { if errors.Is(err, channeldb.ErrEdgeNotFound) {
log.Debugf("Removing channel(%v) from "+ log.Debugf("Removing channel(%v) from "+
"consideration for passive disabling", "consideration for passive disabling",
outpoint) outpoint)
+3 -3
View File
@@ -974,7 +974,7 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) (
info, p1, p2, err := graph.FetchChannelEdgesByOutpoint( info, p1, p2, err := graph.FetchChannelEdgesByOutpoint(
&chanPoint, &chanPoint,
) )
if err != nil && err != channeldb.ErrEdgeNotFound { if err != nil && !errors.Is(err, channeldb.ErrEdgeNotFound) {
return nil, err return nil, err
} }
@@ -1089,7 +1089,7 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) (
return return
} }
shutdownMsg = fn.Some[lnwire.Shutdown](*shutdown) shutdownMsg = fn.Some(*shutdown)
}) })
if shutdownInfoErr != nil { if shutdownInfoErr != nil {
return nil, shutdownInfoErr return nil, shutdownInfoErr
@@ -2938,7 +2938,7 @@ func (p *Brontide) restartCoopClose(lnChan *lnwallet.LightningChannel) (
}) })
// An error other than ErrNoShutdownInfo was returned // An error other than ErrNoShutdownInfo was returned
case err != nil && !errors.Is(err, channeldb.ErrNoShutdownInfo): case !errors.Is(err, channeldb.ErrNoShutdownInfo):
return nil, err return nil, err
case errors.Is(err, channeldb.ErrNoShutdownInfo): case errors.Is(err, channeldb.ErrNoShutdownInfo):
+4 -4
View File
@@ -2891,7 +2891,7 @@ func abandonChanFromGraph(chanGraph *channeldb.ChannelGraph,
// the graph, so we'll return a nil error. // the graph, so we'll return a nil error.
chanID, err := chanGraph.ChannelID(chanPoint) chanID, err := chanGraph.ChannelID(chanPoint)
switch { switch {
case err == channeldb.ErrEdgeNotFound: case errors.Is(err, channeldb.ErrEdgeNotFound):
return nil return nil
case err != nil: case err != nil:
return err return err
@@ -5677,7 +5677,7 @@ sendLoop:
func (r *rpcServer) SendPaymentSync(ctx context.Context, func (r *rpcServer) SendPaymentSync(ctx context.Context,
nextPayment *lnrpc.SendRequest) (*lnrpc.SendResponse, error) { nextPayment *lnrpc.SendRequest) (*lnrpc.SendResponse, error) {
return r.sendPaymentSync(ctx, &rpcPaymentRequest{ return r.sendPaymentSync(&rpcPaymentRequest{
SendRequest: nextPayment, SendRequest: nextPayment,
}) })
} }
@@ -5698,12 +5698,12 @@ func (r *rpcServer) SendToRouteSync(ctx context.Context,
return nil, err return nil, err
} }
return r.sendPaymentSync(ctx, paymentRequest) return r.sendPaymentSync(paymentRequest)
} }
// sendPaymentSync is the synchronous variant of sendPayment. It will block and // sendPaymentSync is the synchronous variant of sendPayment. It will block and
// wait until the payment has been fully completed. // wait until the payment has been fully completed.
func (r *rpcServer) sendPaymentSync(ctx context.Context, func (r *rpcServer) sendPaymentSync(
nextPayment *rpcPaymentRequest) (*lnrpc.SendResponse, error) { nextPayment *rpcPaymentRequest) (*lnrpc.SendResponse, error) {
// We don't allow payments to be sent while the daemon itself is still // We don't allow payments to be sent while the daemon itself is still
+1 -1
View File
@@ -1266,7 +1266,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
info, e1, e2, err := s.graphDB.FetchChannelEdgesByID( info, e1, e2, err := s.graphDB.FetchChannelEdgesByID(
scid.ToUint64(), scid.ToUint64(),
) )
if err == channeldb.ErrEdgeNotFound { if errors.Is(err, channeldb.ErrEdgeNotFound) {
// This is unlikely but there is a slim chance of this // This is unlikely but there is a slim chance of this
// being hit if lnd was killed via SIGKILL and the // being hit if lnd was killed via SIGKILL and the
// funding manager was stepping through the delete // funding manager was stepping through the delete