@@ -222,7 +222,7 @@ func (b *Builder) Start() error {
222222 // channels from the graph based on their spentness, but whether they
223223 // are considered zombies or not. We will start zombie pruning after a
224224 // small delay, to avoid slowing down startup of lnd.
225- if b .cfg .AssumeChannelValid {
225+ if b .cfg .AssumeChannelValid { //nolint:nestif
226226 time .AfterFunc (b .cfg .FirstTimePruneDelay , func () {
227227 select {
228228 case <- b .quit :
@@ -256,6 +256,7 @@ func (b *Builder) Start() error {
256256 if err != nil && ! errors .Is (
257257 err , channeldb .ErrGraphNoEdgesFound ,
258258 ) {
259+
259260 return err
260261 }
261262
@@ -290,7 +291,9 @@ func (b *Builder) Start() error {
290291 // from the graph in order to ensure we maintain a tight graph
291292 // of "useful" nodes.
292293 err = b .cfg .Graph .PruneGraphNodes ()
293- if err != nil && err != channeldb .ErrGraphNodesNotFound {
294+ if err != nil &&
295+ ! errors .Is (err , channeldb .ErrGraphNodesNotFound ) {
296+
294297 return err
295298 }
296299 }
@@ -344,8 +347,8 @@ func (b *Builder) syncGraphWithChain() error {
344347 switch {
345348 // If the graph has never been pruned, or hasn't fully been
346349 // created yet, then we don't treat this as an explicit error.
347- case err == channeldb .ErrGraphNeverPruned :
348- case err == channeldb .ErrGraphNotFound :
350+ case errors . Is ( err , channeldb .ErrGraphNeverPruned ) :
351+ case errors . Is ( err , channeldb .ErrGraphNotFound ) :
349352 default :
350353 return err
351354 }
@@ -355,7 +358,6 @@ func (b *Builder) syncGraphWithChain() error {
355358 pruneHeight , pruneHash )
356359
357360 switch {
358-
359361 // If the graph has never been pruned, then we can exit early as this
360362 // entails it's being created for the first time and hasn't seen any
361363 // block or created channels.
@@ -388,34 +390,40 @@ func (b *Builder) syncGraphWithChain() error {
388390 }
389391
390392 pruneHash , pruneHeight , err = b .cfg .Graph .PruneTip ()
391- if err != nil {
392- switch {
393- // If at this point the graph has never been pruned, we
394- // can exit as this entails we are back to the point
395- // where it hasn't seen any block or created channels,
396- // alas there's nothing left to prune.
397- case err == channeldb .ErrGraphNeverPruned :
398- return nil
399- case err == channeldb .ErrGraphNotFound :
400- return nil
401- default :
402- return err
403- }
393+ switch {
394+ // If at this point the graph has never been pruned, we can exit
395+ // as this entails we are back to the point where it hasn't seen
396+ // any block or created channels, alas there's nothing left to
397+ // prune.
398+ case errors .Is (err , channeldb .ErrGraphNeverPruned ):
399+ return nil
400+
401+ case errors .Is (err , channeldb .ErrGraphNotFound ):
402+ return nil
403+
404+ case err != nil :
405+ return err
406+
407+ default :
404408 }
405- mainBlockHash , err = b .cfg .Chain .GetBlockHash (int64 (pruneHeight ))
409+
410+ mainBlockHash , err = b .cfg .Chain .GetBlockHash (
411+ int64 (pruneHeight ),
412+ )
406413 if err != nil {
407414 return err
408415 }
409416 }
410417
411- log .Infof ("Syncing channel graph from height=%v (hash=%v) to height=%v " +
412- "(hash=%v)" , pruneHeight , pruneHash , bestHeight , bestHash )
418+ log .Infof ("Syncing channel graph from height=%v (hash=%v) to " +
419+ "height=%v (hash=%v)" , pruneHeight , pruneHash , bestHeight ,
420+ bestHash )
413421
414422 // If we're not yet caught up, then we'll walk forward in the chain
415423 // pruning the channel graph with each new block that hasn't yet been
416424 // consumed by the channel graph.
417425 var spentOutputs []* wire.OutPoint
418- for nextHeight := pruneHeight + 1 ; nextHeight <= uint32 (bestHeight ); nextHeight ++ {
426+ for nextHeight := pruneHeight + 1 ; nextHeight <= uint32 (bestHeight ); nextHeight ++ { //nolint:lll
419427 // Break out of the rescan early if a shutdown has been
420428 // requested, otherwise long rescans will block the daemon from
421429 // shutting down promptly.
@@ -462,6 +470,7 @@ func (b *Builder) syncGraphWithChain() error {
462470
463471 log .Infof ("Graph pruning complete: %v channels were closed since " +
464472 "height %v" , len (closedChans ), pruneHeight )
473+
465474 return nil
466475}
467476
@@ -615,7 +624,11 @@ func (b *Builder) pruneZombieChans() error {
615624 }
616625
617626 for _ , u := range oldEdges {
618- filterPruneChans (u .Info , u .Policy1 , u .Policy2 )
627+ err = filterPruneChans (u .Info , u .Policy1 , u .Policy2 )
628+ if err != nil {
629+ return fmt .Errorf ("error filtering channels to " +
630+ "prune: %w" , err )
631+ }
619632 }
620633
621634 log .Infof ("Pruning %v zombie channels" , len (chansToPrune ))
@@ -640,7 +653,7 @@ func (b *Builder) pruneZombieChans() error {
640653 // With the channels pruned, we'll also attempt to prune any nodes that
641654 // were a part of them.
642655 err = b .cfg .Graph .PruneGraphNodes ()
643- if err != nil && err != channeldb .ErrGraphNodesNotFound {
656+ if err != nil && ! errors . Is ( err , channeldb .ErrGraphNodesNotFound ) {
644657 return fmt .Errorf ("unable to prune graph nodes: %w" , err )
645658 }
646659
@@ -761,7 +774,6 @@ func (b *Builder) networkHandler() {
761774 }
762775
763776 for {
764-
765777 // If there are stats, resume the statTicker.
766778 if ! b .stats .Empty () {
767779 b .statTicker .Resume ()
@@ -793,12 +805,14 @@ func (b *Builder) networkHandler() {
793805
794806 // Since this block is stale, we update our best height
795807 // to the previous block.
796- blockHeight := uint32 ( chainUpdate .Height )
808+ blockHeight := chainUpdate .Height
797809 atomic .StoreUint32 (& b .bestHeight , blockHeight - 1 )
798810
799811 // Update the channel graph to reflect that this block
800812 // was disconnected.
801- _ , err := b .cfg .Graph .DisconnectBlockAtHeight (blockHeight )
813+ _ , err := b .cfg .Graph .DisconnectBlockAtHeight (
814+ blockHeight ,
815+ )
802816 if err != nil {
803817 log .Errorf ("unable to prune graph with stale " +
804818 "block: %v" , err )
@@ -836,7 +850,9 @@ func (b *Builder) networkHandler() {
836850 "height=%v, got height=%v" ,
837851 currentHeight + 1 , chainUpdate .Height )
838852
839- err := b .getMissingBlocks (currentHeight , chainUpdate )
853+ err := b .getMissingBlocks (
854+ currentHeight , chainUpdate ,
855+ )
840856 if err != nil {
841857 log .Errorf ("unable to retrieve missing" +
842858 "blocks: %v" , err )
@@ -1136,6 +1152,8 @@ func makeFundingScript(bitcoinKey1, bitcoinKey2 []byte,
11361152// channel/edge update network update. If the update didn't affect the internal
11371153// state of the draft due to either being out of date, invalid, or redundant,
11381154// then error is returned.
1155+ //
1156+ //nolint:funlen
11391157func (b * Builder ) processUpdate (msg interface {},
11401158 op ... batch.SchedulerOption ) error {
11411159
@@ -1166,7 +1184,9 @@ func (b *Builder) processUpdate(msg interface{},
11661184 _ , _ , exists , isZombie , err := b .cfg .Graph .HasChannelEdge (
11671185 msg .ChannelID ,
11681186 )
1169- if err != nil && err != channeldb .ErrGraphNoEdgesFound {
1187+ if err != nil &&
1188+ ! errors .Is (err , channeldb .ErrGraphNoEdgesFound ) {
1189+
11701190 return errors .Errorf ("unable to check for edge " +
11711191 "existence: %v" , err )
11721192 }
@@ -1188,7 +1208,8 @@ func (b *Builder) processUpdate(msg interface{},
11881208 // ChannelAnnouncement from the gossiper.
11891209 scid := lnwire .NewShortChanIDFromInt (msg .ChannelID )
11901210 if b .cfg .AssumeChannelValid || b .cfg .IsAlias (scid ) {
1191- if err := b .cfg .Graph .AddChannelEdge (msg , op ... ); err != nil {
1211+ err := b .cfg .Graph .AddChannelEdge (msg , op ... )
1212+ if err != nil {
11921213 return fmt .Errorf ("unable to add edge: %w" , err )
11931214 }
11941215 log .Tracef ("New channel discovered! Link " +
@@ -1206,6 +1227,8 @@ func (b *Builder) processUpdate(msg interface{},
12061227 channelID := lnwire .NewShortChanIDFromInt (msg .ChannelID )
12071228 fundingTx , err := b .fetchFundingTxWrapper (& channelID )
12081229 if err != nil {
1230+ //nolint:lll
1231+ //
12091232 // In order to ensure we don't erroneously mark a
12101233 // channel as a zombie due to an RPC failure, we'll
12111234 // attempt to string match for the relevant errors.
@@ -1253,13 +1276,15 @@ func (b *Builder) processUpdate(msg interface{},
12531276 // formed. If this check fails, then this channel either
12541277 // doesn't exist, or isn't the one that was meant to be created
12551278 // according to the passed channel proofs.
1256- fundingPoint , err := chanvalidate .Validate (& chanvalidate.Context {
1257- Locator : & chanvalidate.ShortChanIDChanLocator {
1258- ID : channelID ,
1279+ fundingPoint , err := chanvalidate .Validate (
1280+ & chanvalidate.Context {
1281+ Locator : & chanvalidate.ShortChanIDChanLocator {
1282+ ID : channelID ,
1283+ },
1284+ MultiSigPkScript : fundingPkScript ,
1285+ FundingTx : fundingTx ,
12591286 },
1260- MultiSigPkScript : fundingPkScript ,
1261- FundingTx : fundingTx ,
1262- })
1287+ )
12631288 if err != nil {
12641289 // Mark the edge as a zombie so we won't try to
12651290 // re-validate it on start up.
@@ -1336,16 +1361,20 @@ func (b *Builder) processUpdate(msg interface{},
13361361
13371362 edge1Timestamp , edge2Timestamp , exists , isZombie , err :=
13381363 b .cfg .Graph .HasChannelEdge (msg .ChannelID )
1339- if err != nil && err != channeldb .ErrGraphNoEdgesFound {
1364+ if err != nil && ! errors .Is (
1365+ err , channeldb .ErrGraphNoEdgesFound ,
1366+ ) {
1367+
13401368 return errors .Errorf ("unable to check for edge " +
13411369 "existence: %v" , err )
1342-
13431370 }
13441371
13451372 // If the channel is marked as a zombie in our database, and
13461373 // we consider this a stale update, then we should not apply the
13471374 // policy.
1348- isStaleUpdate := time .Since (msg .LastUpdate ) > b .cfg .ChannelPruneExpiry
1375+ isStaleUpdate := time .Since (msg .LastUpdate ) >
1376+ b .cfg .ChannelPruneExpiry
1377+
13491378 if isZombie && isStaleUpdate {
13501379 return newErrf (ErrIgnored , "ignoring stale update " +
13511380 "(flags=%v|%v) for zombie chan_id=%v" ,
@@ -1368,7 +1397,6 @@ func (b *Builder) processUpdate(msg interface{},
13681397 // that edge. If this message has a timestamp not strictly
13691398 // newer than what we already know of we can exit early.
13701399 switch {
1371-
13721400 // A flag set of 0 indicates this is an announcement for the
13731401 // "first" node in the channel.
13741402 case msg .ChannelFlags & lnwire .ChanUpdateDirection == 0 :
@@ -1448,7 +1476,7 @@ func (b *Builder) fetchFundingTxWrapper(chanID *lnwire.ShortChannelID) (
14481476// short channel ID.
14491477//
14501478// TODO(roasbeef): replace with call to GetBlockTransaction? (would allow to
1451- // later use getblocktxn)
1479+ // later use getblocktxn).
14521480func (b * Builder ) fetchFundingTx (
14531481 chanID * lnwire.ShortChannelID ) (* wire.MsgTx , error ) {
14541482
@@ -1702,6 +1730,7 @@ func (b *Builder) AddProof(chanID lnwire.ShortChannelID,
17021730 }
17031731
17041732 info .AuthProof = proof
1733+
17051734 return b .cfg .Graph .UpdateChannelEdge (info )
17061735}
17071736
@@ -1739,6 +1768,7 @@ func (b *Builder) IsKnownEdge(chanID lnwire.ShortChannelID) bool {
17391768 _ , _ , exists , isZombie , _ := b .cfg .Graph .HasChannelEdge (
17401769 chanID .ToUint64 (),
17411770 )
1771+
17421772 return exists || isZombie
17431773}
17441774
@@ -1754,7 +1784,6 @@ func (b *Builder) IsStaleEdgePolicy(chanID lnwire.ShortChannelID,
17541784 if err != nil {
17551785 log .Debugf ("Check stale edge policy got error: %v" , err )
17561786 return false
1757-
17581787 }
17591788
17601789 // If we know of the edge as a zombie, then we'll make some additional
0 commit comments