mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-18 21:35:24 +01:00
Merge pull request #8815 from yyforyongyu/fix-edge-policy
trivial: fix linter errors and return verbose errors
This commit is contained in:
commit
931b3dc0c3
@ -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
|
||||
|
@ -958,7 +958,7 @@ func initBreachedState(t *testing.T) (*BreachArbitrator,
|
||||
// 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
|
||||
// observing a breach.
|
||||
alice, bob, err := createInitChannels(t, 1)
|
||||
alice, bob, err := createInitChannels(t)
|
||||
require.NoError(t, err, "unable to create test channels")
|
||||
|
||||
// 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,
|
||||
// with 5 BTC allocated to each side. Within the channel, Alice is the
|
||||
// initiator.
|
||||
func createInitChannels(t *testing.T, revocationWindow int) (
|
||||
func createInitChannels(t *testing.T) (
|
||||
*lnwallet.LightningChannel, *lnwallet.LightningChannel, error) {
|
||||
|
||||
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
|
||||
// having Alice and Bob extend their revocation windows to each other.
|
||||
err = initRevocationWindows(channelAlice, channelBob, revocationWindow)
|
||||
err = initRevocationWindows(channelAlice, channelBob)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -2408,7 +2408,7 @@ func createInitChannels(t *testing.T, revocationWindow int) (
|
||||
// commitment state machines.
|
||||
//
|
||||
// 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()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -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
|
||||
|
@ -1188,7 +1188,7 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel,
|
||||
// If this is a zero-conf channel, then we will wait
|
||||
// for it to be confirmed before announcing it to the
|
||||
// greater network.
|
||||
err := f.waitForZeroConfChannel(channel, pendingChanID)
|
||||
err := f.waitForZeroConfChannel(channel)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed waiting for zero "+
|
||||
"channel: %v", err)
|
||||
@ -3605,9 +3605,7 @@ func (f *Manager) annAfterSixConfs(completeChan *channeldb.OpenChannel,
|
||||
// waitForZeroConfChannel is called when the state is addedToRouterGraph with
|
||||
// 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.
|
||||
func (f *Manager) waitForZeroConfChannel(c *channeldb.OpenChannel,
|
||||
pendingID [32]byte) error {
|
||||
|
||||
func (f *Manager) waitForZeroConfChannel(c *channeldb.OpenChannel) error {
|
||||
// First we'll check whether the channel is confirmed on-chain. If it
|
||||
// is already confirmed, the chainntnfs subsystem will return with the
|
||||
// confirmed tx. Otherwise, we'll wait here until confirmation occurs.
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
@ -1089,7 +1089,7 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) (
|
||||
return
|
||||
}
|
||||
|
||||
shutdownMsg = fn.Some[lnwire.Shutdown](*shutdown)
|
||||
shutdownMsg = fn.Some(*shutdown)
|
||||
})
|
||||
if shutdownInfoErr != nil {
|
||||
return nil, shutdownInfoErr
|
||||
@ -2938,7 +2938,7 @@ func (p *Brontide) restartCoopClose(lnChan *lnwallet.LightningChannel) (
|
||||
})
|
||||
|
||||
// An error other than ErrNoShutdownInfo was returned
|
||||
case err != nil && !errors.Is(err, channeldb.ErrNoShutdownInfo):
|
||||
case !errors.Is(err, channeldb.ErrNoShutdownInfo):
|
||||
return nil, err
|
||||
|
||||
case errors.Is(err, channeldb.ErrNoShutdownInfo):
|
||||
|
@ -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
|
||||
@ -5677,7 +5677,7 @@ sendLoop:
|
||||
func (r *rpcServer) SendPaymentSync(ctx context.Context,
|
||||
nextPayment *lnrpc.SendRequest) (*lnrpc.SendResponse, error) {
|
||||
|
||||
return r.sendPaymentSync(ctx, &rpcPaymentRequest{
|
||||
return r.sendPaymentSync(&rpcPaymentRequest{
|
||||
SendRequest: nextPayment,
|
||||
})
|
||||
}
|
||||
@ -5698,12 +5698,12 @@ func (r *rpcServer) SendToRouteSync(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return r.sendPaymentSync(ctx, paymentRequest)
|
||||
return r.sendPaymentSync(paymentRequest)
|
||||
}
|
||||
|
||||
// sendPaymentSync is the synchronous variant of sendPayment. It will block and
|
||||
// wait until the payment has been fully completed.
|
||||
func (r *rpcServer) sendPaymentSync(ctx context.Context,
|
||||
func (r *rpcServer) sendPaymentSync(
|
||||
nextPayment *rpcPaymentRequest) (*lnrpc.SendResponse, error) {
|
||||
|
||||
// We don't allow payments to be sent while the daemon itself is still
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user