From 0485d56fca6c45f72f2e3c6c1a635ae437a15cf7 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, 11 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 07686f58f..455db3733 100644 --- a/go.mod +++ b/go.mod @@ -128,7 +128,7 @@ require ( github.com/lightninglabs/lightning-node-connect/gbn v1.0.1 // indirect github.com/lightninglabs/lightning-node-connect/mailbox v1.0.1 // indirect github.com/lightninglabs/neutrino v0.16.1 // indirect - github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb // indirect + github.com/lightningnetwork/lightning-onion v1.2.1-0.20240815225420-8b40adf04ab9 // indirect github.com/lightningnetwork/lnd/healthcheck v1.2.6 // indirect github.com/lightningnetwork/lnd/kvdb v1.4.16 // indirect github.com/lightningnetwork/lnd/queue v1.1.1 // indirect @@ -217,3 +217,7 @@ 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-20250626140435-ed6a7abee9af + +replace github.com/lightningnetwork/lnd/sqldb => github.com/GeorgeTsagk/lnd/sqldb v0.0.0-20250626140435-ed6a7abee9af diff --git a/go.sum b/go.sum index 59acf9013..37600d0be 100644 --- a/go.sum +++ b/go.sum @@ -603,6 +603,10 @@ 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-20250626140435-ed6a7abee9af h1:NukAv3Ldq6GBOFH+ozrntQ4Pv9gEJ5GiGtpfI6KkxhU= +github.com/GeorgeTsagk/lnd v0.0.0-20250626140435-ed6a7abee9af/go.mod h1:FelbuiQdzwyEbHng3XsODMBKfXUGgz6JZcWtN9uwuE4= +github.com/GeorgeTsagk/lnd/sqldb v0.0.0-20250626140435-ed6a7abee9af h1:O3HkVpUPI6SrC+zSF7Esc1Drqhor2Yndi8Bx2QUO9A8= +github.com/GeorgeTsagk/lnd/sqldb v0.0.0-20250626140435-ed6a7abee9af/go.mod h1:c/vWoQfcxu6FAfHzGajkIQi7CEIeIZFhhH4DYh1BJpc= 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= @@ -1147,10 +1151,8 @@ github.com/lightninglabs/neutrino/cache v1.1.2 h1:C9DY/DAPaPxbFC+xNNEI/z1SJY9GS3 github.com/lightninglabs/neutrino/cache v1.1.2/go.mod h1:XJNcgdOw1LQnanGjw8Vj44CvguYA25IMKjWFZczwZuo= github.com/lightninglabs/protobuf-go-hex-display v1.34.2-hex-display h1:w7FM5LH9Z6CpKxl13mS48idsu6F+cEZf0lkyiV+Dq9g= 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.1-beta.rc1.0.20250623232057-b48e2763a798 h1:nSnOCqilf+ynsJlTOVOoNXEhjjxTrvcv6jxMyUlZJJE= -github.com/lightningnetwork/lnd v0.19.1-beta.rc1.0.20250623232057-b48e2763a798/go.mod h1:iHZ/FHFK00BqV6qgDkZZfqWE3LGtgE0U5KdO5WrM+eQ= +github.com/lightningnetwork/lightning-onion v1.2.1-0.20240815225420-8b40adf04ab9 h1:6D3LrdagJweLLdFm1JNodZsBk6iU4TTsBBFLQ4yiXfI= +github.com/lightningnetwork/lightning-onion v1.2.1-0.20240815225420-8b40adf04ab9/go.mod h1:EDqJ3MuZIbMq0QI1czTIKDJ/GS8S14RXPwapHw8cw6w= 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= @@ -1163,8 +1165,6 @@ github.com/lightningnetwork/lnd/kvdb v1.4.16 h1:9BZgWdDfjmHRHLS97cz39bVuBAqMc4/p github.com/lightningnetwork/lnd/kvdb v1.4.16/go.mod h1:HW+bvwkxNaopkz3oIgBV6NEnV4jCEZCACFUcNg4xSjM= github.com/lightningnetwork/lnd/queue v1.1.1 h1:99ovBlpM9B0FRCGYJo6RSFDlt8/vOkQQZznVb18iNMI= github.com/lightningnetwork/lnd/queue v1.1.1/go.mod h1:7A6nC1Qrm32FHuhx/mi1cieAiBZo5O6l8IBIoQxvkz4= -github.com/lightningnetwork/lnd/sqldb v1.0.10 h1:ZLV7TGwjnKupVfCd+DJ43MAc9BKVSFCnvhpSPGKdN3M= -github.com/lightningnetwork/lnd/sqldb v1.0.10/go.mod h1:c/vWoQfcxu6FAfHzGajkIQi7CEIeIZFhhH4DYh1BJpc= github.com/lightningnetwork/lnd/ticker v1.1.1 h1:J/b6N2hibFtC7JLV77ULQp++QLtCwT6ijJlbdiZFbSM= github.com/lightningnetwork/lnd/ticker v1.1.1/go.mod h1:waPTRAAcwtu7Ji3+3k+u/xH5GHovTsCoSVpho0KDvdA= github.com/lightningnetwork/lnd/tlv v1.3.2 h1:MO4FCk7F4k5xPMqVZF6Nb/kOpxlwPrUQpYjmyKny5s0= From a647204bc76fda9b28b38fbc5cf686d9ac280795 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/aux_features.go | 9 +++++++++ rfqmsg/aux_features_dev.go | 8 ++++++++ rfqmsg/records.go | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 rfqmsg/aux_features.go create mode 100644 rfqmsg/aux_features_dev.go diff --git a/rfqmsg/aux_features.go b/rfqmsg/aux_features.go new file mode 100644 index 000000000..97fb2d48f --- /dev/null +++ b/rfqmsg/aux_features.go @@ -0,0 +1,9 @@ +//go:build !dev + +package rfqmsg + +var ( + // UseNoOpHTLCs is set to false, as we don't want to enable it for + // production builds. + UseNoOpHTLCs = false +) diff --git a/rfqmsg/aux_features_dev.go b/rfqmsg/aux_features_dev.go new file mode 100644 index 000000000..81bae01c9 --- /dev/null +++ b/rfqmsg/aux_features_dev.go @@ -0,0 +1,8 @@ +//go:build dev + +package rfqmsg + +var ( + // UseNoOpHTLCs is set to true, as we want to enable it for dev builds. + UseNoOpHTLCs = true +) diff --git a/rfqmsg/records.go b/rfqmsg/records.go index b896f6ad6..c0c91075f 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,9 +143,19 @@ 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 } +// SetNoopAdd flags the HTLC as a noop_add. +func (h *Htlc) SetNoopAdd(noopActive bool) { + h.NoopAdd = noopActive +} + // Encode serializes the Htlc to the given io.Writer. func (h *Htlc) Encode(w io.Writer) error { tlvRecords := h.Records() From 72e654d2c2b4b8bd68ac38184fd1a329914b1917 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 547c84549..0d826d3a4 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 d963c73f266a943f9b69147c387a374bca4eecf6 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..d9af9b623 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(rfqmsg.UseNoOpHTLCs) + 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(rfqmsg.UseNoOpHTLCs) + updatedRecords, err := htlc.ToCustomRecords() if err != nil { return 0, nil, fmt.Errorf("error encoding HTLC blob: %w", err)