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= 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 } 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) 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.