From 53254c79b46a5059c6176facdc2fb1a8fe896a6d Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Tue, 8 Apr 2025 19:52:51 +0200 Subject: [PATCH] lnwallet: add FetchLatestHTLCView to LightningChannel We add a public method for the lightning channel to expose the latest HtlcView. This is used in a follow up commit by the channel link. --- lnwallet/channel.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index ab064fbd4..2c1e3a252 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -2704,6 +2704,20 @@ func (v *HtlcView) AuxTheirUpdates() []AuxHtlcDescriptor { return fn.Map(v.Updates.Remote, newAuxHtlcDescriptor) } +// FetchLatestAuxHTLCView returns the latest HTLC view of the lightning channel +// as a safe copy that can be used outside the wallet code in concurrent access. +func (lc *LightningChannel) FetchLatestAuxHTLCView() AuxHtlcView { + // This read lock is important, because we access both the local and + // remote log indexes as well as the underlying payment descriptors of + // the HTLCs when creating the view. + lc.RLock() + defer lc.RUnlock() + + return newAuxHtlcView(lc.fetchHTLCView( + lc.updateLogs.Remote.logIndex, lc.updateLogs.Local.logIndex, + )) +} + // fetchHTLCView returns all the candidate HTLC updates which should be // considered for inclusion within a commitment based on the passed HTLC log // indexes.