From 73576ef6b2f2530c7b6085236df6cce324ce1ca6 Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Tue, 27 May 2025 12:53:44 +0200 Subject: [PATCH 1/4] (temp)build: bump lnd --- go.mod | 6 ++++-- go.sum | 12 ++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 3b55e726e..46da3f1eb 100644 --- a/go.mod +++ b/go.mod @@ -9,8 +9,8 @@ require ( github.com/btcsuite/btcd/btcutil/psbt v1.1.10 github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c - github.com/btcsuite/btclog/v2 v2.0.1-0.20250110154127-3ae4bf1cb318 - github.com/btcsuite/btcwallet v0.16.13 + github.com/btcsuite/btclog/v2 v2.0.1-0.20250602222548-9967d19bb084 + github.com/btcsuite/btcwallet v0.16.14 github.com/btcsuite/btcwallet/wallet/txsizes v1.2.5 github.com/btcsuite/btcwallet/wtxmgr v1.5.6 github.com/caddyserver/certmagic v0.17.2 @@ -217,3 +217,5 @@ replace github.com/golang-migrate/migrate/v4 => github.com/lightninglabs/migrate // Note this is a temproary replace and will be removed when taprpc is tagged. replace github.com/lightninglabs/taproot-assets/taprpc => ./taprpc + +replace github.com/lightningnetwork/lnd => github.com/GeorgeTsagk/lnd v0.0.0-20250616111006-7b25935ec491 diff --git a/go.sum b/go.sum index e1238493e..1900461b1 100644 --- a/go.sum +++ b/go.sum @@ -603,6 +603,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/GeorgeTsagk/lnd v0.0.0-20250616111006-7b25935ec491 h1:ft7+6ej3Qsz0FBT3ga9Wl+umomKwZDqmFqFh4iqxNlU= +github.com/GeorgeTsagk/lnd v0.0.0-20250616111006-7b25935ec491/go.mod h1:E2avtpklJPZc9Mzgpy1Gs6Sx/nUxA45Gn9B49L9aai4= github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g= @@ -666,11 +668,11 @@ github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0/go.mod h1:7SFka0XMvUgj3hfZtyd github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c h1:4HxD1lBUGUddhzgaNgrCPsFWd7cGYNpeFUgd9ZIgyM0= github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c/go.mod h1:w7xnGOhwT3lmrS4H3b/D1XAXxvh+tbhUm8xeHN2y3TQ= -github.com/btcsuite/btclog/v2 v2.0.1-0.20250110154127-3ae4bf1cb318 h1:oCjIcinPt7XQ644MP/22JcjYEC84qRc3bRBH0d7Hhd4= -github.com/btcsuite/btclog/v2 v2.0.1-0.20250110154127-3ae4bf1cb318/go.mod h1:XItGUfVOxotJL8kkuk2Hj3EVow5KCugXl3wWfQ6K0AE= +github.com/btcsuite/btclog/v2 v2.0.1-0.20250602222548-9967d19bb084 h1:y3bvkt8ki0KX35eUEU8XShRHusz1S+55QwXUTmxn888= +github.com/btcsuite/btclog/v2 v2.0.1-0.20250602222548-9967d19bb084/go.mod h1:XItGUfVOxotJL8kkuk2Hj3EVow5KCugXl3wWfQ6K0AE= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= -github.com/btcsuite/btcwallet v0.16.13 h1:JGu+wrihQ0I00ODb3w92JtBPbrHxZhbcvU01O+e+lKw= -github.com/btcsuite/btcwallet v0.16.13/go.mod h1:H6dfoZcWPonM2wbVsR2ZBY0PKNZKdQyLAmnX8vL9JFA= +github.com/btcsuite/btcwallet v0.16.14 h1:CofysgmI1ednkLsXontAdBoXJkbiim7unXnFKhLLjnE= +github.com/btcsuite/btcwallet v0.16.14/go.mod h1:H6dfoZcWPonM2wbVsR2ZBY0PKNZKdQyLAmnX8vL9JFA= github.com/btcsuite/btcwallet/wallet/txauthor v1.3.5 h1:Rr0njWI3r341nhSPesKQ2JF+ugDSzdPoeckS75SeDZk= github.com/btcsuite/btcwallet/wallet/txauthor v1.3.5/go.mod h1:+tXJ3Ym0nlQc/iHSwW1qzjmPs3ev+UVWMbGgfV1OZqU= github.com/btcsuite/btcwallet/wallet/txrules v1.2.2 h1:YEO+Lx1ZJJAtdRrjuhXjWrYsmAk26wLTlNzxt2q0lhk= @@ -1149,8 +1151,6 @@ github.com/lightninglabs/protobuf-go-hex-display v1.34.2-hex-display h1:w7FM5LH9 github.com/lightninglabs/protobuf-go-hex-display v1.34.2-hex-display/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb h1:yfM05S8DXKhuCBp5qSMZdtSwvJ+GFzl94KbXMNB1JDY= github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb/go.mod h1:c0kvRShutpj3l6B9WtTsNTBUtjSmjZXbJd9ZBRQOSKI= -github.com/lightningnetwork/lnd v0.19.0-beta h1:/8i2UdARiEpI2iAmPoSDcwZSSEuWqXyfsMxz/mLGbdw= -github.com/lightningnetwork/lnd v0.19.0-beta/go.mod h1:hu6zo1zcznx7nViiFlJY8qGDwwGw5LNLdGJ7ICz5Ysc= github.com/lightningnetwork/lnd/cert v1.2.2 h1:71YK6hogeJtxSxw2teq3eGeuy4rHGKcFf0d0Uy4qBjI= github.com/lightningnetwork/lnd/cert v1.2.2/go.mod h1:jQmFn/Ez4zhDgq2hnYSw8r35bqGVxViXhX6Cd7HXM6U= github.com/lightningnetwork/lnd/clock v1.1.1 h1:OfR3/zcJd2RhH0RU+zX/77c0ZiOnIMsDIBjgjWdZgA0= From 972a3f7bb88565c7f71ce24e1b157b4935b8a14b Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Tue, 27 May 2025 12:48:26 +0200 Subject: [PATCH 2/4] rfqmsg: add noop option to HTLC We add a new noop flag to the HTLC which, when set, will produce the corresponding TLV record. We also hide this feature behind the dev flag, as we ultimately want to be backwards compatible via some feature bit related peer messages. --- rfqmsg/noop_add_active.go | 8 ++++++++ rfqmsg/noop_add_inactive.go | 6 ++++++ rfqmsg/records.go | 13 +++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 rfqmsg/noop_add_active.go create mode 100644 rfqmsg/noop_add_inactive.go diff --git a/rfqmsg/noop_add_active.go b/rfqmsg/noop_add_active.go new file mode 100644 index 000000000..141443376 --- /dev/null +++ b/rfqmsg/noop_add_active.go @@ -0,0 +1,8 @@ +//go:build dev + +package rfqmsg + +// SetNoopAdd flags the HTLC as a noop_add. +func (h *Htlc) SetNoopAdd() { + h.NoopAdd = true +} diff --git a/rfqmsg/noop_add_inactive.go b/rfqmsg/noop_add_inactive.go new file mode 100644 index 000000000..c9559f886 --- /dev/null +++ b/rfqmsg/noop_add_inactive.go @@ -0,0 +1,6 @@ +//go:build !dev + +package rfqmsg + +// SetNoopAdd flags the HTLC as a noop_add. +func (h *Htlc) SetNoopAdd() {} diff --git a/rfqmsg/records.go b/rfqmsg/records.go index b896f6ad6..0144ce122 100644 --- a/rfqmsg/records.go +++ b/rfqmsg/records.go @@ -12,6 +12,7 @@ import ( "github.com/lightninglabs/taproot-assets/asset" "github.com/lightninglabs/taproot-assets/fn" "github.com/lightninglabs/taproot-assets/rfqmath" + "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/tlv" ) @@ -59,6 +60,13 @@ type Htlc struct { // RfqID is the RFQ ID that corresponds to the HTLC. RfqID tlv.OptionalRecordT[HtlcRfqIDType, ID] + + // NoopAdd is a flag that indicates whether this HTLC should be marked + // as a noop_add for LND. A noop_add HTLC behaves identically to a + // normal HTLC except for the settlement step, where the satoshi amount + // is returned back to the sender, but the commitment blob is still + // updated to reflect the asset balance changes. + NoopAdd bool } // NewHtlc creates a new Htlc record with the given funded assets. @@ -135,6 +143,11 @@ func (h *Htlc) Records() []tlv.Record { records = append(records, r.Record()) }) + if h.NoopAdd { + r := tlv.NewPrimitiveRecord[lnwallet.NoopAddHtlcType](true) + records = append(records, r.Record()) + } + return records } From 83f103ad7a15854dd8950664d5434c624e370200 Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Tue, 27 May 2025 12:50:50 +0200 Subject: [PATCH 3/4] tapchannel: detect both HTLC add types Since we now have two different candidate types for adding HTLCs, we use the helper method that checks against both of them. --- tapchannel/commitment.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tapchannel/commitment.go b/tapchannel/commitment.go index 2d1ac4855..7970d56f9 100644 --- a/tapchannel/commitment.go +++ b/tapchannel/commitment.go @@ -98,12 +98,12 @@ func ComputeView(ourBalance, theirBalance uint64, remoteHtlcIndex := make(map[uint64]lnwallet.AuxHtlcDescriptor) for _, entry := range original.Updates.Local { - if entry.EntryType == lnwallet.Add { + if entry.IsAdd() { localHtlcIndex[entry.HtlcIndex] = entry } } for _, entry := range original.Updates.Remote { - if entry.EntryType == lnwallet.Add { + if entry.IsAdd() { remoteHtlcIndex[entry.HtlcIndex] = entry } } @@ -115,6 +115,9 @@ func ComputeView(ourBalance, theirBalance uint64, case lnwallet.Add: continue + case lnwallet.NoopAdd: + continue + // Fee updates don't concern us at the asset level. case lnwallet.FeeUpdate: continue @@ -162,6 +165,9 @@ func ComputeView(ourBalance, theirBalance uint64, case lnwallet.Add: continue + case lnwallet.NoopAdd: + continue + // Fee updates don't concern us at the asset level. case lnwallet.FeeUpdate: continue @@ -207,7 +213,7 @@ func ComputeView(ourBalance, theirBalance uint64, // settled HTLCs, and debiting the chain state balance due to any newly // added HTLCs. for _, entry := range original.Updates.Local { - isAdd := entry.EntryType == lnwallet.Add + isAdd := entry.IsAdd() // Skip any entries that aren't adds or adds that were already // settled or failed by a child HTLC entry we processed above. @@ -249,7 +255,7 @@ func ComputeView(ourBalance, theirBalance uint64, newView.OurUpdates = append(newView.OurUpdates, decodedEntry) } for _, entry := range original.Updates.Remote { - isAdd := entry.EntryType == lnwallet.Add + isAdd := entry.IsAdd() // Skip any entries that aren't adds or adds that were already // settled or failed by a child HTLC entry we processed above. From 723311b77566d8209d6cb0962888a1c6f0b0b7d1 Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Tue, 27 May 2025 12:53:33 +0200 Subject: [PATCH 4/4] tapchannel: trigger noop HTLCs on ProduceHtlcExtraData Whenever we use the default above-dust anchor amount to send an HTLC with assets we also set the noop flag on the HTLC, which will produce the according noop HTLC record and signal to LND that the satoshi amount should be returned to the sender. --- tapchannel/aux_traffic_shaper.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tapchannel/aux_traffic_shaper.go b/tapchannel/aux_traffic_shaper.go index e687ae4e8..2b171b82b 100644 --- a/tapchannel/aux_traffic_shaper.go +++ b/tapchannel/aux_traffic_shaper.go @@ -431,7 +431,14 @@ func (s *AuxTrafficShaper) ProduceHtlcExtraData(totalAmount lnwire.MilliSatoshi, if htlc.Amounts.Val.Sum() > 0 { log.Tracef("Already have asset amount (sum %d) in HTLC, not "+ "producing extra data", htlc.Amounts.Val.Sum()) - return totalAmount, htlcCustomRecords, nil + + htlc.SetNoopAdd() + updatedRecords, err := htlc.ToCustomRecords() + if err != nil { + return 0, nil, err + } + + return totalAmount, updatedRecords, nil } if htlc.RfqID.ValOpt().IsNone() { @@ -496,6 +503,12 @@ func (s *AuxTrafficShaper) ProduceHtlcExtraData(totalAmount lnwire.MilliSatoshi, // amount that should be sent on-chain, which is a value in satoshi that // is just above the dust limit. htlcAmountMSat := rfqmath.DefaultOnChainHtlcMSat + + // Now we set the flag that marks this HTLC as a noop_add, which means + // that the above dust will eventually return to us. This means that + // only the assets will be sent and not any btc balance. + htlc.SetNoopAdd() + updatedRecords, err := htlc.ToCustomRecords() if err != nil { return 0, nil, fmt.Errorf("error encoding HTLC blob: %w", err)