From b96d57e88f9877ce239c49310fccf6b315731728 Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Mon, 14 Apr 2025 15:30:00 +0200 Subject: [PATCH] lnwallet: add AuxHtlcView --- lnwallet/aux_signer.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lnwallet/aux_signer.go b/lnwallet/aux_signer.go index 510b64b5d..90a4325f6 100644 --- a/lnwallet/aux_signer.go +++ b/lnwallet/aux_signer.go @@ -5,6 +5,7 @@ import ( "github.com/lightningnetwork/lnd/fn/v2" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/lntypes" + "github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/tlv" ) @@ -13,6 +14,37 @@ import ( // signatures within the custom data for an existing HTLC. var htlcCustomSigType tlv.TlvType65543 +// AuxHtlcView is a struct that contains a safe copy of an HTLC view that can +// be used by aux components. +type AuxHtlcView struct { + // NextHeight is the height of the commitment transaction that will be + // created using this view. + NextHeight uint64 + + // Updates is a Dual of the Local and Remote HTLCs. + Updates lntypes.Dual[[]AuxHtlcDescriptor] + + // FeePerKw is the fee rate in sat/kw of the commitment transaction. + FeePerKw chainfee.SatPerKWeight +} + +// newAuxHtlcView creates a new safe copy of the HTLC view that can be used by +// aux components. +// +// NOTE: This function should only be called while holding the channel's read +// lock, since the underlying local/remote payment descriptors are accessed +// directly. +func newAuxHtlcView(v *HtlcView) AuxHtlcView { + return AuxHtlcView{ + NextHeight: v.NextHeight, + Updates: lntypes.Dual[[]AuxHtlcDescriptor]{ + Local: fn.Map(v.Updates.Local, newAuxHtlcDescriptor), + Remote: fn.Map(v.Updates.Remote, newAuxHtlcDescriptor), + }, + FeePerKw: v.FeePerKw, + } +} + // AuxHtlcDescriptor is a struct that contains the information needed to sign or // verify an HTLC for custom channels. type AuxHtlcDescriptor struct { @@ -99,6 +131,9 @@ func (a *AuxHtlcDescriptor) RemoveHeight( // newAuxHtlcDescriptor creates a new AuxHtlcDescriptor from a payment // descriptor. +// +// NOTE: This function should only be called while holding the channel's read +// lock, since the underlying payment descriptors are accessed directly. func newAuxHtlcDescriptor(p *paymentDescriptor) AuxHtlcDescriptor { return AuxHtlcDescriptor{ ChanID: p.ChanID,