Skip to content
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

Offers: bolt12 updated for latest draft. #5676

Merged
merged 32 commits into from
Nov 9, 2022

Commits on Nov 9, 2022

  1. common: catch up on latest routeblinding spec.

    This makes us match eed2ab0c30ad7f93e3b2641ca9d7ade32f3d121d
    ("Use `invalid_onion_blinding` everywhere").
    
    1. Numerous typographical changes.
    2. Make sure we *always* return WIRE_INVALID_ONION_BLINDING if
       we're in a blinded path.
    3. Handle p->total_msat correctly (MPP payments).
    4. Reorganize blinding handling just like spec order.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    6da922c View commit details
    Browse the repository at this point in the history
  2. lightningd: don't return normal errors on blinded path entry, either.

    This current spec is not strict enough: we might complain that the
    next peer is not connected, for example, which leaks information.
    
    So return WIRE_INVALID_ONION_BLINDING even if we're the first hop
    on the path, to be safe.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    873b599 View commit details
    Browse the repository at this point in the history
  3. common/onion: handle payment by node_id.

    In a blinded path, you can specify node_id instead of scid.  Handle
    that case.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    6652206 View commit details
    Browse the repository at this point in the history
  4. common/onion: split into decode and encode routines.

    Some places (e.g. the pay plugin) only need to construct onions,
    not decode them.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    a1459b2 View commit details
    Browse the repository at this point in the history
  5. plugins/libplugin-pay: hack in blinded path support.

    We simply take the first one, and route to the start of that.  Then we
    append the blinded path to the onion construction.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    2c3c996 View commit details
    Browse the repository at this point in the history
  6. common/blindedpath: expose API at a lower level.

    We actually want lightningd to create these, since it wants to put the
    path_id secret in the last element.  So best API is actually a generic
    one, rather than separate APIs to create first and last ones.
    
    And really, the more explicit initialization makes the users clearer.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    cbd44bb View commit details
    Browse the repository at this point in the history
  7. onion_message: don't use general secret, use per-message secret.

    We had a scheme where lightningd itself would put a per-node secret in
    the blinded path, then we'd tell the caller when it was used.  Then it
    simply checks the alias to determine if the correct path was used.
    
    But this doesn't work when we start to offer multiple blinded paths.
    So go for a far simpler scheme, where the secret is generated (and
    stored) by the caller, and hand it back to them.
    
    We keep the split "with secret" or "without secret" API, since I'm
    sure callers who don't care about the secret won't check that it
    doesn't exist!  And without that, someone can use a blinded path for a
    different message and get a response which may reveal the node.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    7e7174d View commit details
    Browse the repository at this point in the history
  8. invoice: invert check to reduce indentation.

    Instead of doing command_fail() in the else, do it immediately then
    unindent the normal path.
    
    No code changes.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    1f6cfe9 View commit details
    Browse the repository at this point in the history
  9. lightningd: temporarily ignore missing payment_secret for bolt12.

    We're going to mess with it in the next patch...
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    a640901 View commit details
    Browse the repository at this point in the history
  10. createinvoice: make a minimal blinded "path" in bolt12 invoice if non…

    …e presented.
    
    The "path" is just a message to ourselves.  This meets the minimal
    requirement for bolt12 invoices: that there be a blinded path (at
    least so we can use the path_id inside in place of "payment_secret").
    
    We expose the method to make this path_id to a common routine: offers
    will need this for generating more sophisticated paths.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    280af9b View commit details
    Browse the repository at this point in the history
  11. common/onion_decode: put the path_id into onion_payload->payment_secret.

    And check it in invoice.c, insead of a hack where we compare against invhash.
    Restore checking, too.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    ab14776 View commit details
    Browse the repository at this point in the history
  12. listincoming: add htlc_min_msat, public and peer_features fields.

    This is needed for offers to generate blinded paths.
    
    No documentation changes since listincoming is an undocumented
    internal hack interface which topology presents for production
    of routehints.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    36e06ff View commit details
    Browse the repository at this point in the history
  13. offers: monitor blockheight.

    We need this to create the payment_constraints for an invoice blinded path.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    f23cfbe View commit details
    Browse the repository at this point in the history
  14. offers: create a real blinded path, if necessary.

    It's just to a direct peer, and we only create one, but this is
    enough to test, and make payments to non-public nodes work.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    f7de717 View commit details
    Browse the repository at this point in the history
  15. common/bolt12: add code to generate offer_id, extract parts of streams.

    The new spec removes the offer_id, in favor of mirroring all the
    fields.  So we need a way of generating a convenient identifier to
    identify the offer, and this works.
    
    We also want to extract parts of streams elsewhere, so expose that.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    3c5012a View commit details
    Browse the repository at this point in the history
  16. common/bolt12: code to initialize invreqs from offers, invs from invr…

    …eqs.
    
    This is an important part of the coming spec: we mirror all fields,
    known and unknown.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    966030d View commit details
    Browse the repository at this point in the history
  17. common/features: add explicit bolt12 feature sets.

    The spec only specifies the mpp bit for invoices, but in
    general they are separate spaces.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    044ba3b View commit details
    Browse the repository at this point in the history
  18. offers: make them always unsigned.

    This is in preparation for the spec update where the signature field
    does not even exist.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    825c7ad View commit details
    Browse the repository at this point in the history
  19. offers: remove 'send-invoice' offers support.

    This has radically changed in the spec, so remove it now, and we'll
    reintroduce / rewrite it.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    b611cbc View commit details
    Browse the repository at this point in the history
  20. bolt12: import the latest spec, update to fit.

    I know this is an unforgivably large diff, but the spec has changed so
    much that most of this amounts to a rewrite.
    
    Some points:
    * We no longer have "offer_id" fields, we generate that locally, as all
      offer fields are mirrored into invoice_request and then invoice.
    * Because of that mirroring, field names all have explicit offer/invreq/invoice
      prefixes.
    * The `refund_for` fields have been removed from spec: will re-add locally later.
    * quantity_min was removed, max == 0 now mean "must specify a quantity".
    * I have put recurrence fields back in locally.
    
    This brings us to 655df03d8729c0918bdacac99eb13fdb0ee93345 ("BOLT 12:
    add explicit invoice_node_id.")
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    30f2afc View commit details
    Browse the repository at this point in the history
  21. bolt12: update to modern signature scheme.

    This changed, by popular demands.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    12f2433 View commit details
    Browse the repository at this point in the history
  22. devtools/bolt12-cli: fix decode to understand modern fields.

    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    efec399 View commit details
    Browse the repository at this point in the history
  23. bolt12: use spec field names, update decode API.

    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    095b532 View commit details
    Browse the repository at this point in the history
  24. decode: print unknown fields in bolt12 strings.

    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    5e5f808 View commit details
    Browse the repository at this point in the history
  25. offers: use existing copied fields.

    We no longer have to refer back to the offer for which we're making
    the invoice_request, or to the invoice_request we made for an invoice,
    as they are all mirrored (and we check!).
    
    It's clearer to simply look at the object directly.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    158f726 View commit details
    Browse the repository at this point in the history
  26. lightningd/invoice.c, plugins/fetchinvoice.c: use tlv_make_fields() i…

    …nstead of towire/fromwire hack.
    
    I forgot this existed!
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    36f39de View commit details
    Browse the repository at this point in the history
  27. bolt12: routines to hash the invreq parts.

    This gives us a unique identifier, by which we can match an invoice to
    their invoice_request.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    b792ad1 View commit details
    Browse the repository at this point in the history
  28. db: add invoicerequests table.

    We no longer use offers for "I want to send you money", but we'll use
    invoice_requests directly.  Create a new table for them, and
    associated functions.
    
    The "localofferid" for "pay" and "sendpay" is now "localinvreqid".
    This is an experimental-only option, so document the change under
    experimental only.
    
    Signed-off-by: Rusty Russell <[email protected]>
    Changelog-EXPERIMENTAL: JSON-RPC: `pay` and `sendpay` `localofferid` is now `localinvreqid`.
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    6eed623 View commit details
    Browse the repository at this point in the history
  29. lightningd: add "savetodb" argument to createinvoicerequest, add list…

    …invoicerequests/disableinvoicerequest
    
    This is how we put new invoice_requests into the db; this will be used
    by a new "invoicerequest" command which replaces "offerout".
    
    The API	is now the same as the offers api.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    3b17fe9 View commit details
    Browse the repository at this point in the history
  30. lightningd: re-add 'offerout' functionality, as 'invoicerequest'.

    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    89d462f View commit details
    Browse the repository at this point in the history
  31. bolt12: update comments to match latest spec.

    No code changes.
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    643d1b4 View commit details
    Browse the repository at this point in the history
  32. check: fix warnings from shellcheck 0.8.0

    And make errors gcc-style, so emacs can jump through the automatically.
    
    ```
    In devtools/reduce-includes.sh line 21:
    	    echo -n "-$LINE"
                     ^-- SC3037 (warning): In POSIX sh, echo flags are undefined.
    
    
    In devtools/reduce-includes.sh line 25:
    	    echo -n "."
                     ^-- SC3037 (warning): In POSIX sh, echo flags are undefined.
    
    
    In tools/rel.sh line 6:
    prefix=$(printf '%s\n' "${from#$common}" | sed 's@[^/][^/]*@..@g')
                                   ^-----^ SC2295 (info): Expansions inside ${..} need to be quoted separately, otherwise they match as patterns.
    
    Did you mean: 
    prefix=$(printf '%s\n' "${from#"$common"}" | sed 's@[^/][^/]*@..@g')
    
    
    In tools/rel.sh line 7:
    printf '%s\n' "$prefix/${to#$common}"
                                ^-----^ SC2295 (info): Expansions inside ${..} need to be quoted separately, otherwise they match as patterns.
    
    Did you mean: 
    printf '%s\n' "$prefix/${to#"$common"}"
    
    For more information:
      https://www.shellcheck.net/wiki/SC3037 -- In POSIX sh, echo flags are undef...
      https://www.shellcheck.net/wiki/SC2295 -- Expansions inside ${..} need to b...
    make: *** [Makefile:553: check-shellcheck] Error 123
    ```
    
    Signed-off-by: Rusty Russell <[email protected]>
    rustyrussell authored and cdecker committed Nov 9, 2022
    Configuration menu
    Copy the full SHA
    6c25666 View commit details
    Browse the repository at this point in the history