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: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand All @@ -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=
Expand Down
9 changes: 9 additions & 0 deletions rfqmsg/aux_features.go
Original file line number Diff line number Diff line change
@@ -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
)
8 changes: 8 additions & 0 deletions rfqmsg/aux_features_dev.go
Original file line number Diff line number Diff line change
@@ -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
)
18 changes: 18 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,9 +143,19 @@ 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
}

// SetNoopAdd flags the HTLC as a noop_add.
func (h *Htlc) SetNoopAdd(noopActive bool) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this method, since we can just set the field directly, since it's exported?

h.NoopAdd = noopActive
}

// Encode serializes the Htlc to the given io.Writer.
func (h *Htlc) Encode(w io.Writer) error {
tlvRecords := h.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(rfqmsg.UseNoOpHTLCs)
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(rfqmsg.UseNoOpHTLCs)

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