Skip to content

cmd/loop: fix route hint array parsing - #1213

Open
starius wants to merge 2 commits into
lightninglabs:masterfrom
starius:fix-cli-route-hints-array
Open

cmd/loop: fix route hint array parsing#1213
starius wants to merge 2 commits into
lightninglabs:masterfrom
starius:fix-cli-route-hints-array

Conversation

@starius

@starius starius commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Another approach for #1209. We can have only a single --route_hints with complete JSON, so the type should be cli.StringFlag. And then we don't need DisableSliceFlagSeparator and touching other flags (--utxo and --deposit_outpoint).

Treat --route_hints as a single JSON array instead of a repeatable string slice. This preserves commas in the JSON without disabling slice separators for unrelated UTXO and deposit flags.

Decode the outer array into raw JSON elements, then use protojson for each RouteHint protobuf. This follows protobuf JSON field naming and quoted uint64 semantics, and rejects unknown fields instead of silently accepting misspelled hints.

Reject empty RouteHint messages at the RPC boundary. An empty route would be encoded as an empty BOLT 11 r field, which zpay32 rejects when decoding the invoice.

Add recorded CLI sessions covering valid single, multiple, and multi-hop hints, malformed input, RPC-boundary validation, and comma-separated UTXO and deposit selections.

Pull Request Checklist

  • Add an entry to docs/release-notes/release-notes-next.md, or apply the
    no-changelog label (required by CI)

Treat --route_hints as a single JSON array instead of a repeatable
string slice. This preserves commas in the JSON without disabling slice
separators for unrelated UTXO and deposit flags.

Decode the outer array into raw JSON elements, then use protojson
for each RouteHint protobuf. This follows protobuf JSON field naming
and quoted uint64 semantics, and rejects unknown fields instead of
silently accepting misspelled hints.

Reject empty RouteHint messages at the RPC boundary. An empty route
would be encoded as an empty BOLT 11 r field, which zpay32 rejects
when decoding the invoice.

Add recorded CLI sessions covering valid single, multiple, and
multi-hop hints, malformed input, RPC-boundary validation, and
comma-separated UTXO and deposit selections.
@starius
starius requested a review from hieblmi August 27, 2026 00:28
The protobuf implementation intentionally varies the separator after its
error prefix between an ASCII space and a non-breaking space across
builds. This made recorded route hint sessions depend on the test binary
and fail CI despite identical parsing behavior.

Normalize the non-breaking space before returning the CLI error so the
user-facing message and recorded sessions remain stable across builds.
@starius
starius force-pushed the fix-cli-route-hints-array branch from 2862b4c to 328f302 Compare August 27, 2026 01:14
@starius
starius marked this pull request as ready for review August 27, 2026 06:04

@hieblmi hieblmi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, pending one finding.

if rpcHint.ChanId == 0 {
return zpay32.HopHint{}, fmt.Errorf("channel ID is zero")
}
if rpcHint.CltvExpiryDelta == 0 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Zero CLTV deltas are protocol-permitted. The new check in swapclient_server.go rejects every hint with cltv_expiry_delta == 0. BOLT 7 defines this as an unrestricted u16 and only requires it to equal the blocks subtracted; BOLT 11 carries that value into route hints without adding a nonzero constraint. This can reject a standards-permitted private-channel policy and breaks previously accepted gRPC requests. Keep the > MaxUint16 guard, but remove the zero check unless Loop intentionally documents a stricter API requirement. BOLT 7, BOLT 11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants