Skip to content

Use new NoopAddHtlc TLV when sending assets with default above-dust anchor amt #1567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
8 changes: 8 additions & 0 deletions rfqmsg/noop_add_active.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build dev

package rfqmsg

// SetNoopAdd flags the HTLC as a noop_add.
func (h *Htlc) SetNoopAdd() {
h.NoopAdd = true
}
6 changes: 6 additions & 0 deletions rfqmsg/noop_add_inactive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//go:build !dev

package rfqmsg

// SetNoopAdd flags the HTLC as a noop_add.
func (h *Htlc) SetNoopAdd() {}
13 changes: 13 additions & 0 deletions rfqmsg/records.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -135,6 +143,11 @@ func (h *Htlc) Records() []tlv.Record {
records = append(records, r.Record())
})

if h.NoopAdd {
r := tlv.NewPrimitiveRecord[lnwallet.NoopAddHtlcType](true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing to update in the bLIPs.

records = append(records, r.Record())
}

return records
}

Expand Down
15 changes: 14 additions & 1 deletion tapchannel/aux_traffic_shaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems the aspect related to the reserve that you mentioned isn't in this PR yet?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not updated yet and it's on the LND PR, here we don't really have access to the channel state so we only decide whether we flag the noop to LND or not

if err != nil {
return 0, nil, err
}

return totalAmount, updatedRecords, nil
}

if htlc.RfqID.ValOpt().IsNone() {
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 10 additions & 4 deletions tapchannel/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Loading