') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Add HTLCHandlingFailed event by jurvis · Pull Request #1403 · lightningdevkit/rust-lightning · GitHub
Skip to content

Add HTLCHandlingFailed event - #1403

Merged
jkczyz merged 3 commits into
lightningdevkit:mainfrom
jurvis:jurvis/add-paymentforwardingfailed-event
Jul 26, 2022
Merged

Add HTLCHandlingFailed event#1403
jkczyz merged 3 commits into
lightningdevkit:mainfrom
jurvis:jurvis/add-paymentforwardingfailed-event

Conversation

@jurvis

@jurvisjurvis commented Apr 2, 2022

Copy link
Copy Markdown
Contributor

Addresses #1392

When forward_htlcs is empty, forward_event does not get set, so I assume that means that represents an instance where forwarding has failed since we have no HTLCs to forward (?). may be completely off here.

if possible, I will like some help finding the test where this event is suppose to be called 😄 thanks!

edit: functional_tests helped me find those failing tests 😅 will fix

@jurvis

jurvis commented Apr 3, 2022

Copy link
Copy Markdown
ContributorAuthor

hey @TheBlueMatt, some of the tests affected by this change use the expect_pending_htlcs_forwardable_ignore! macro that hardcodes a count of events it expects to 1.

this makes sense; since we only send the PendingHTLCsForwardable event once when we fail backward. however, we probably need a new macro for expecting potentially the additional count of PaymentForwardingFailed events. Before I work on this change, I just wanted to ask and see if you may be aware of a better way of doing this + if the place in ChannelManager where I push PaymentForwardedFailed even makes sense at this current moment.

thanks!

@TheBlueMattTheBlueMatt 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.

As for the test macros/updates, yes, this kind of change tends to end up with a ton of test changes spewn throughout. Hopefully my comment below may make it simplier (actually just update the expect_pending_htlcs_forwardable_ignore/expect_pending_htlcs_forwardable macro(s) to detect the new event, with either a new argument to indicate at the test-sites if its required or something like PaymentFailedConditions to set a list of conditions and pass that in.

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@jurvis

Copy link
Copy Markdown
ContributorAuthor

@TheBlueMatt got it! thanks for the guidance 😄

@jurvis
jurvisforce-pushed the jurvis/add-paymentforwardingfailed-event branch from 2b96fe0 to d16f1aaCompareApril 7, 2022 05:53
@codecov-commenter

codecov-commenter commented Apr 7, 2022

Copy link
Copy Markdown

Codecov Report

Merging #1403 (6c5af58) into main (5cca9a0) will increase coverage by 0.90%.
The diff coverage is 92.24%.

❗ Current head 6c5af58 differs from pull request most recent head 8f0d9b0. Consider uploading reports for the commit 8f0d9b0 to get more accurate results

@@ Coverage Diff @@## main #1403 +/- ##
==========================================
+ Coverage 90.87% 91.77% +0.90% 
==========================================
Files 80 80 Lines 44645 49595 +4950 Branches 44645 49595 +4950 ==========================================
+ Hits 40569 45518 +4949 - Misses 4076 4077 +1 
Impacted FilesCoverage Δ
lightning/src/chain/mod.rs68.18% <ø> (ø)
lightning/src/util/events.rs39.50% <46.15%> (-0.04%)⬇️
lightning/src/ln/channelmanager.rs87.99% <83.92%> (+2.90%)⬆️
lightning/src/ln/functional_tests.rs98.30% <97.70%> (+1.20%)⬆️
lightning/src/chain/chainmonitor.rs97.97% <100.00%> (+0.01%)⬆️
lightning/src/chain/channelmonitor.rs90.97% <100.00%> (+0.01%)⬆️
lightning/src/ln/chanmon_update_fail_tests.rs97.71% <100.00%> (ø)
lightning/src/ln/channel.rs88.78% <100.00%> (+0.03%)⬆️
lightning/src/ln/functional_test_utils.rs96.78% <100.00%> (+1.54%)⬆️
lightning/src/ln/monitor_tests.rs100.00% <100.00%> (ø)
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5cca9a0...8f0d9b0. Read the comment docs.

@jurvisjurvis left a comment

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I think I have implemented this PR to the fullest of my knowledge of how things work... I added some comments in places I want to call out because I'm not 100% confident of them.

Also need some help in places, specifically with identifying when to not send our node_id as the sink_node_id

Comment threadlightning/src/ln/functional_test_utils.rs
Comment threadlightning/src/ln/functional_test_utils.rs Outdated
Comment threadlightning/src/ln/functional_tests.rs Outdated
Comment threadlightning/src/ln/functional_tests.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
@jurvis
jurvis marked this pull request as ready for review April 10, 2022 16:08
Comment threadlightning/src/ln/channelmanager.rs Outdated
@jurvis

Copy link
Copy Markdown
ContributorAuthor

update: still working on this PR. stepping away to catch up with some other deadlines. hope to make my next iteration by end of the week :)

@jurvis
jurvisforce-pushed the jurvis/add-paymentforwardingfailed-event branch 2 times, most recently from a5a23df to bb6d9bdCompareApril 20, 2022 14:59
@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Looks like this is starting to shape up! Let me know when you want another round of review on this.

@jurvis

jurvis commented Apr 23, 2022

Copy link
Copy Markdown
ContributorAuthor

@TheBlueMatt yeah I just got a little stuck finding the counterparty_node_id at some of the fail_htlc_backwards_internal call-sites and had a question in an old comment thread: #1403 (comment)

Comment threadlightning/src/ln/channelmanager.rs Outdated
@jurvis
jurvisforce-pushed the jurvis/add-paymentforwardingfailed-event branch 2 times, most recently from 0c07c76 to 6bb663fCompareMay 7, 2022 23:10
@jurvis

Copy link
Copy Markdown
ContributorAuthor

@TheBlueMatt not a PR I have super high confidence about getting right the first time, but will like to see how I can improve :D

@jurvis
jurvis requested a review from TheBlueMattMay 7, 2022 23:59

@TheBlueMattTheBlueMatt 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.

A number of comments about data provided and structure before I jump into reviewing all the creation sites for correctness.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
@jkczyz
jkczyz self-requested a review May 17, 2022 14:49
@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Looks like this needs rebase.

@jurvis
jurvisforce-pushed the jurvis/add-paymentforwardingfailed-event branch 4 times, most recently from 3b6131d to 7b52102CompareJune 3, 2022 02:30
Comment threadlightning/src/ln/functional_tests.rs Outdated
@jurvis

Copy link
Copy Markdown
ContributorAuthor

Please don't rebase PRs unless there's a conflict, it makes it very difficult to track changes to the PR vs upstream.

oops, sorry. thought I was being helpful, lol.

@jurvis
jurvisforce-pushed the jurvis/add-paymentforwardingfailed-event branch from 8e21ce2 to d6e0d0eCompareJuly 17, 2022 05:25
@jurvis

Copy link
Copy Markdown
ContributorAuthor

@TheBlueMatt I saw your comment in my email notifications but can't find it on GitHub for this line

you said:

Rather than asserting that the destination is in the expected set, lets assert that the destination is exactly the last entry in the destination vec, and remove it from the vec.

I'm looking to correct this, but when you say that "the destination is exactly the last entry in the destination vec," is this what you mean?:

$crate::util::events::Event::HTLCHandlingFailed { ref failed_next_destination, .. } => {
let destination = destinations.pop().unwrap();
assert_eq!(&destination, failed_next_destination);
},

because that seems to imply that the event order when calling get_and_clear_pending_events() is in reverse chronological order, but I don't think that's how it is right now 🤔 or am I misunderstanding something?

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Yea, sorry, I deleted that comment because I'm not sure we need/want tests to assert on a precise event ordering given a set of HTLCs get failed at the same time. In general we do want to avoid tests that just check that each of a series of events is in some set - we want to make sure all of the set get returned - but we don't want to be overly prescriptive in event ordering in case we change it in the future.

@jurvis
jurvisforce-pushed the jurvis/add-paymentforwardingfailed-event branch from d6e0d0e to 145e500CompareJuly 18, 2022 02:36
TheBlueMatt
TheBlueMatt previously approved these changes Jul 18, 2022

@TheBlueMattTheBlueMatt 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.

Code changes look good. Please make sure to wrap your commit messages (including descriptions) at 70-80 lines long.

Comment threadlightning/src/util/events.rs Outdated

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Largely looks good. Just a bunch of nits.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/ln/functional_test_utils.rs Outdated
Comment threadlightning/src/ln/functional_test_utils.rs Outdated
Comment threadlightning/src/ln/functional_test_utils.rs Outdated
Comment threadlightning/src/chain/chainmonitor.rs Outdated
Comment threadlightning/src/ln/functional_test_utils.rs Outdated
@jurvis
jurvisforce-pushed the jurvis/add-paymentforwardingfailed-event branch from 9f5b999 to 62c907fCompareJuly 19, 2022 17:37
@TheBlueMattTheBlueMatt self-assigned this Jul 19, 2022
@jurvis
jurvisforce-pushed the jurvis/add-paymentforwardingfailed-event branch from 62c907f to 6c5af58CompareJuly 19, 2022 23:21
@jurvis

Copy link
Copy Markdown
ContributorAuthor

cleaned up commit messages

@TheBlueMattTheBlueMatt 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.

Code LGTM, some doc notes but this should be basically ready.

Comment threadlightning/src/util/events.rs
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
@jurvis
jurvisforce-pushed the jurvis/add-paymentforwardingfailed-event branch from 6c5af58 to 5410e4aCompareJuly 22, 2022 00:38
Comment threadlightning/src/util/events.rs Outdated
@jurvis
jurvisforce-pushed the jurvis/add-paymentforwardingfailed-event branch from 5410e4a to 205aef4CompareJuly 22, 2022 20:43
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/ln/functional_test_utils.rs Outdated
Comment threadlightning/src/ln/functional_test_utils.rs Outdated
Adds a HTLCHandlingFailed that expresses failure by our node to process
a specific HTLC. A HTLCDestination enum is defined to express the
possible cases that causes the handling to fail.
@jurvis
jurvisforce-pushed the jurvis/add-paymentforwardingfailed-event branch from 205aef4 to 8f0d9b0CompareJuly 25, 2022 17:23
We add `HTLCHandlingFailedConditions` to express the failure parameters,
that will be enforced by a new macro, `expect_pending_htlcs_forwardable_conditions`.
@jurvis
jurvisforce-pushed the jurvis/add-paymentforwardingfailed-event branch from 8f0d9b0 to 3a7844aCompareJuly 25, 2022 17:29
In `ChannelManager::fail_htlc_backwards_internal`, we push a `HTLCHandlingFailed`
containing some information about the HTLC
@jurvis
jurvisforce-pushed the jurvis/add-paymentforwardingfailed-event branch from 3a7844a to ac842edCompareJuly 25, 2022 18:29
@jkczyz
jkczyz merged commit f0b8189 into lightningdevkit:mainJul 26, 2022
Sign up for freeto 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.

5 participants

@jurvis@codecov-commenter@TheBlueMatt@jkczyz@ViktorT-11