Skip to content
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
39 changes: 38 additions & 1 deletion cmd/litcli/ln.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,41 @@ func payInvoice(cliCtx *cli.Context) error {
)
}

// addInvoiceUnsupportedFlags is the set of flags that are inherited from
// lncli's addinvoice command but don't apply to Taproot Asset invoices. The
// addInvoice action below never reads these, so we strip them to avoid
// presenting options that have no effect.
var addInvoiceUnsupportedFlags = map[string]struct{}{
// The final-hop CLTV delta isn't applied to asset invoices.
"cltv_expiry_delta": {},

// Blinded paths aren't supported for asset invoices; the relevant hop
// hints are added as part of the RFQ process instead.
"blind": {},
"min_real_blinded_hops": {},
"num_blinded_hops": {},
"max_blinded_paths": {},
"blinded_path_omit_node": {},
"blinded_path_incoming_channel_list": {},
}

// withoutUnsupportedAddInvoiceFlags returns the given flags with the ones that
// don't apply to Taproot Asset invoices (see addInvoiceUnsupportedFlags)
// removed.
func withoutUnsupportedAddInvoiceFlags(flags []cli.Flag) []cli.Flag {
filtered := make([]cli.Flag, 0, len(flags))
for _, flag := range flags {
_, unsupported := addInvoiceUnsupportedFlags[flag.GetName()]
if unsupported {
continue
}

filtered = append(filtered, flag)
}

return filtered
}
Comment on lines +716 to +728

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

In urfave/cli (v1), flag.GetName() returns the raw Name string, which can contain comma-separated aliases (e.g., "blind, b"). If any of the inherited flags are defined with aliases now or in the future, addInvoiceUnsupportedFlags[flag.GetName()] will fail to match, and the unsupported flag will not be filtered out.

To make this robust against aliases, we should split the flag name by "," and trim whitespace before checking against the unsupported map.

func withoutUnsupportedAddInvoiceFlags(flags []cli.Flag) []cli.Flag {
	filtered := make([]cli.Flag, 0, len(flags))
	for _, flag := range flags {
		var unsupported bool
		for _, part := range strings.Split(flag.GetName(), ",") {
			if _, ok := addInvoiceUnsupportedFlags[strings.TrimSpace(part)]; ok {
				unsupported = true
				break
			}
		}
		if unsupported {
			continue
		}

		filtered = append(filtered, flag)
	}

	return filtered
}


var addInvoiceCommand = cli.Command{
Name: "addinvoice",
Category: commands.AddInvoiceCommand.Category,
Expand All @@ -703,7 +738,9 @@ var addInvoiceCommand = cli.Command{
ArgsUsage: "[--asset_id=X | --group_key=X] --asset_amount=Y " +
"[--rfq_peer_pubkey=Z] ",
Flags: append(
commands.AddInvoiceCommand.Flags,
withoutUnsupportedAddInvoiceFlags(
commands.AddInvoiceCommand.Flags,
),
cli.StringFlag{
Name: "asset_id",
Usage: "the asset ID of the asset to receive; cannot " +
Expand Down
37 changes: 37 additions & 0 deletions cmd/litcli/ln_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"testing"

"github.com/stretchr/testify/require"
)

// TestAddInvoiceCommandFlags ensures that the litcli addinvoice command keeps
// the flags its action actually reads (including the asset-specific ones it
// adds) while dropping the inherited lncli flags that don't apply to Taproot
// Asset invoices.
func TestAddInvoiceCommandFlags(t *testing.T) {
t.Parallel()

flagNames := make(map[string]struct{})
for _, flag := range addInvoiceCommand.Flags {
flagNames[flag.GetName()] = struct{}{}
}
Comment on lines +16 to +19

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Similar to the implementation in ln.go, flag.GetName() can return a string containing aliases (e.g., "blind, b"). If a flag has aliases, flagNames[flag.GetName()] will store the full string, and checking flagNames["blind"] will return false even though the flag is still present. This can lead to false positives in the test.

We should split and trim the flag names here as well to ensure all names and aliases are correctly populated in the map. Note that you will need to import "strings" in this test file.

Suggested change
flagNames := make(map[string]struct{})
for _, flag := range addInvoiceCommand.Flags {
flagNames[flag.GetName()] = struct{}{}
}
flagNames := make(map[string]struct{})
for _, flag := range addInvoiceCommand.Flags {
for _, part := range strings.Split(flag.GetName(), ",") {
flagNames[strings.TrimSpace(part)] = struct{}{}
}
}


// Flags that the addInvoice action reads must remain available.
expected := []string{
"memo", "preimage", "amt", "amt_msat", "description_hash",
"fallback_addr", "expiry", "private", "amp",
"asset_id", "group_key", "asset_amount", "rfq_peer_pubkey",
}
for _, name := range expected {
_, ok := flagNames[name]
require.Truef(t, ok, "expected flag %q to be present", name)
}

// Flags that don't apply to asset invoices must be removed.
for name := range addInvoiceUnsupportedFlags {
_, ok := flagNames[name]
require.Falsef(t, ok, "expected flag %q to be removed", name)
}
}
6 changes: 6 additions & 0 deletions docs/release-notes/release-notes-0.17.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
of being masked by a confusing `no request values found for request: <id>`
error.

* [Hide unsupported flags from `litcli ln
addinvoice`](https://github.com/lightninglabs/lightning-terminal/pull/1335):
The `addinvoice` command no longer advertises the blinded-path flags or
`--cltv_expiry_delta`, which were inherited from `lncli` but have no effect on
Taproot Asset invoices.

### Functional Changes/Additions

### Technical and Architectural Updates
Expand Down
Loading