Skip to content

Commit 5cf911a

Browse files
authored
Merge pull request #1764 from cfromknecht/isolate-fwdpkg-to-live-links
htlcswitch/link: only resovle+gc fwdpkgs for live channels
2 parents c41ea48 + 211a029 commit 5cf911a

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

htlcswitch/link.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -847,18 +847,23 @@ func (l *channelLink) htlcManager() {
847847

848848
// After cleaning up any memory pertaining to incoming packets, we now
849849
// replay our forwarding packages to handle any htlcs that can be
850-
// processed locally, or need to be forwarded out to the switch.
851-
if err := l.resolveFwdPkgs(); err != nil {
852-
l.fail(LinkFailureError{code: ErrInternalError},
853-
"unable to resolve fwd pkgs: %v", err)
854-
return
855-
}
850+
// processed locally, or need to be forwarded out to the switch. We will
851+
// only attempt to resolve packages if our short chan id indicates that
852+
// the channel is not pending, otherwise we should have no htlcs to
853+
// reforward.
854+
if l.ShortChanID() != sourceHop {
855+
if err := l.resolveFwdPkgs(); err != nil {
856+
l.fail(LinkFailureError{code: ErrInternalError},
857+
"unable to resolve fwd pkgs: %v", err)
858+
return
859+
}
856860

857-
// With our link's in-memory state fully reconstructed, spawn a
858-
// goroutine to manage the reclamation of disk space occupied by
859-
// completed forwarding packages.
860-
l.wg.Add(1)
861-
go l.fwdPkgGarbager()
861+
// With our link's in-memory state fully reconstructed, spawn a
862+
// goroutine to manage the reclamation of disk space occupied by
863+
// completed forwarding packages.
864+
l.wg.Add(1)
865+
go l.fwdPkgGarbager()
866+
}
862867

863868
out:
864869
for {
@@ -1770,6 +1775,11 @@ func (l *channelLink) UpdateShortChanID() (lnwire.ShortChannelID, error) {
17701775
}
17711776
}()
17721777

1778+
// Now that the short channel ID has been properly updated, we can begin
1779+
// garbage collecting any forwarding packages we create.
1780+
l.wg.Add(1)
1781+
go l.fwdPkgGarbager()
1782+
17731783
return sid, nil
17741784
}
17751785

0 commit comments

Comments
 (0)