-
Notifications
You must be signed in to change notification settings - Fork 951
Set custom tlvs to update_add_htlc
via the htlc_accepted_hook
#8433
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
Set custom tlvs to update_add_htlc
via the htlc_accepted_hook
#8433
Conversation
a9bd415
to
b0c1c55
Compare
this PR is necessary for LSPS2 - doesn't conclude LSPS2. |
Excellent change @nepet 🚀 |
common/htlc_wire.c
Outdated
@@ -51,6 +53,17 @@ struct existing_htlc *new_existing_htlc(const tal_t *ctx, | |||
existing->failed = failed_htlc_dup(existing, failed); | |||
else | |||
existing->failed = NULL; | |||
if (extra_tlvs) { | |||
existing->extra_tlvs = tal_dup_talarr(existing, struct tlv_field, extra_tlvs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the function called with take()
on the extra_htlcs
this ends up reparenting the array, but then creates copies in the for
loop below. Leaving the old .value
stranded. Please don't make the type TAKES
, it might result in slightly more copies, but it means we can tal_free()
it in the caller and clean up the child allocations along with it, which would otherwise be left dangling here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And yes, tal_dup_talarr
being magic in the sense it sometimes just reparents is weird :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but a flat array with pointers is already playing dangerously. I've fixed this though (existing callers don't care, but it's still good).
common/htlc_wire.c
Outdated
u8 *tmp_pptr = tal_arr(tmpctx, u8, 0); | ||
towire_tlvstream_raw(&tmp_pptr, added->extra_tlvs); | ||
|
||
towire_bool(pptr, true); | ||
towire_u16(pptr, tal_bytelen(tmp_pptr)); | ||
towire_u8_array(pptr, tmp_pptr, | ||
tal_bytelen(tmp_pptr)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're doing this at least twice (manual serialization), maybe we want to encapsulate this in a towire_tlvstream_prefixed
? Probably for a followup PR, not necessary here.
/* FIXME: save extra_tlvs in db! But: check the implications that a | ||
* spammy peer - giving us big extra tlvs - would have on our database. | ||
* Right now, not saving the extra tlvs in the db seems OK as it is | ||
* only relevant in the case that I forward but restart in the middle | ||
* of a payment. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice that messages in the LN protocol are limited to 65KiB, and update_add_htlc
contains at least a 1365B onion, so 64KiB is the natural limit for the extra_tlvs (and there are other fields that constrain further), as such a limit on pending HTLCs is likely sufficient to also limit the DB space used for extra TLVs.
@plugin.init() | ||
def on_init(**kwargs): | ||
global custom_tlvs | ||
custom_tlvs = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to have no effect, with the above declaration of custom_tlvs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the changed Christian suggested (at the end).
common/htlc_wire.c
Outdated
@@ -51,6 +53,17 @@ struct existing_htlc *new_existing_htlc(const tal_t *ctx, | |||
existing->failed = failed_htlc_dup(existing, failed); | |||
else | |||
existing->failed = NULL; | |||
if (extra_tlvs) { | |||
existing->extra_tlvs = tal_dup_talarr(existing, struct tlv_field, extra_tlvs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but a flat array with pointers is already playing dangerously. I've fixed this though (existing callers don't care, but it's still good).
We currently only consider known tlv types in the internal representation of a htlc. This commit adds the remaining unknown tlv fields to the htlc as well. This is in prepareation to forward these to the htlc_accepted_hook. Signed-off-by: Peter Neuroth <[email protected]>
This appends the extra_tlvs to the internal wire htlcs "added" and "existing" for the extra tlvs to be handed to lightningd. Signed-off-by: Peter Neuroth <[email protected]>
This appends the extra_tlvs to the internal channeld_offer_htlc wire msg. We also recombine the extra_tlvs with the blinded path key for forwarding htlcs. Signed-off-by: Peter Neuroth <[email protected]>
Add serializing and deserializing of the extra tlvs to to the htlc_accepted_hook to allow plugin users to replace the tlv stream that is attached to the update_add_htlc message on forwards. Signed-off-by: Peter Neuroth <[email protected]>
Adds some testcases for custom tlvs, set by a htlc_accepted_hook. We check that the custom tlvs replace the update_add_htlc_tlvs and get forwarded to the peer. We also check that a malformed tlv will result in a **BROKEN** behaviour. Signed-off-by: Peter Neuroth <[email protected]>
Changelog-Added: The `htlc_accepted_hook` now gets the TLV-stream attached to the HTLC passed through as `extra_tlvs` and can replace it. Signed-off-by: Peter Neuroth <[email protected]>
There was a problem with a ‘highlight’ that was misunderstood as a spelling mistake in lib-wally. Since ‘hightlight’ is already filtered out, we simply instruct grep to ignore upper/lower case when filtering. Signed-off-by: Peter Neuroth <[email protected]>
The rare case happened where a lockfile sha-sum contained a "Ctlv" which spell-check complained about. Stupid lockfiles that don't know it is actually "cltv"! Signed-off-by: Peter Neuroth <[email protected]>
Reported-by: Christian Decker Signed-off-by: Rusty Russell <[email protected]>
And make sure we check the length properly in fromwire! Signed-off-by: Rusty Russell <[email protected]>
a0045af
to
7c929d7
Compare
New flake8 (thanks uv) got stricter, so fixed test plugin. |
6fbc5d0
into
ElementsProject:master
Important
25.09 FREEZE July 28TH: Non-bugfix PRs not ready by this date will wait for 25.12.
RC1 is scheduled on August 11th
The final release is scheduled for September 1st.
Checklist
Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:
This PR allows plugins that registered to th
htlc_accepted_hook
to get and replace the TLV-streamupdate_add_htlc_tlvs
attached to incommingupdate_add_htlc
messages, adding a new HTLC.If a plugin want's to replace the TLV-stream with custom TLVS, it needs to return
Specifying
extra_tlvs
will replace the TLV-stream attached to the HTLC (also the blinding path-key) and will be - in case of a forward - forwarded as theupdate_add_htlc_tlvs
to the peer.This PR is a necessary precondition to implement the LSPS2 protocol and Resolves #6663