Skip to content

Setup Support for delaying ChannelMonitorUpdate flight until an Event completes - #2111

Merged
TheBlueMatt merged 4 commits into
lightningdevkit:mainfrom
TheBlueMatt:2023-03-sent-persist-order-prep
May 4, 2023
Merged

Setup Support for delaying ChannelMonitorUpdate flight until an Event completes#2111
TheBlueMatt merged 4 commits into
lightningdevkit:mainfrom
TheBlueMatt:2023-03-sent-persist-order-prep

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

This does all the work that will be required to pause ChannelMonitorUpdate flight until an Event completes, but doesn't actually use the new behavior. Sadly, I think we should consider splitting this work across release, as the commit Track an EventCompletionAction for after an Event is processed indicates -

Note that this gets dangerously close to breaking forwards
compatibility - if we have an `Event` with an
`EventCompletionAction` tied to it, we persist a new, even, TLV in
the `ChannelManager`. Hopefully this should be uncommon, as it
implies an `Event` was delayed until after a full round-trip to a
peer.

Still, I'm open to discussion on it - Events generally should be reliably processed before a full round-trip happens, and it sucks to fix major bugs across releases just over worry of a hopefully-very-rare race breaking forwards, but not backwards, compat.

@TheBlueMattTheBlueMatt added this to the 0.0.115 milestone Mar 17, 2023
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 3 times, most recently from 2aae7c8 to 91707fbCompareMarch 17, 2023 07:04
@codecov-commenter

codecov-commenter commented Mar 17, 2023

Copy link
Copy Markdown

Codecov Report

Patch coverage: 69.12% and project coverage change: +0.56 🎉

Comparison is base (88c63e9) 91.57% compared to head (880d88e) 92.14%.

❗ Current head 880d88e differs from pull request most recent head 9c36735. Consider uploading reports for the commit 9c36735 to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@ Coverage Diff @@## main #2111 +/- ##
==========================================
+ Coverage 91.57% 92.14% +0.56% 
==========================================
Files 104 105 +1 Lines 51930 61222 +9292 Branches 51930 61222 +9292 ==========================================
+ Hits 47556 56410 +8854 - Misses 4374 4812 +438 
Impacted FilesCoverage Δ
lightning/src/ln/channelmanager.rs90.47% <50.00%> (+1.66%)⬆️
lightning/src/ln/channel.rs92.64% <92.70%> (+2.62%)⬆️
lightning/src/ln/chanmon_update_fail_tests.rs98.61% <100.00%> (ø)
lightning/src/ln/functional_tests.rs98.25% <100.00%> (ø)
lightning/src/ln/outbound_payment.rs89.56% <100.00%> (-0.08%)⬇️

... and 21 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 91707fb to c595331CompareMarch 17, 2023 21:09
@wpaulino
wpaulino self-requested a review March 21, 2023 20:02
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 3 times, most recently from 57bebe7 to 9852b84CompareMarch 28, 2023 22:01
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
log_bytes!(self.channel_id));
self.pending_monitor_updates.push(monitor_update);
return Ok(self.pending_monitor_updates.last().unwrap());
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);

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.

Do you see any benefit in tracking the flown/dispatched pending updates in a separate Vec?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Uhhhhhhhhhh. Maybe? Not sure yet, honestly. It would clean up a bit of code, and make some other code a bit more complicated, kinda a wash, but I'm not 100% sure where this is gonna end up , I think this is all of the holding logic we're gonna need for it, but if we find some other bug in there in the future we could end up with more going on in the struct and a two-struct approach will be confusing.

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channel.rs
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 9852b84 to 2ba5289CompareMarch 30, 2023 23:53

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

Feel free to squash the existing fixups

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 2 times, most recently from ae76ed0 to 08ae599CompareApril 5, 2023 18:48
@wpaulino

Copy link
Copy Markdown
Contributor

Feel free to squash, will give it a final pass after a second reviewer.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed without further changes.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Fixed a silent rebase conflict as well as a bug that the further upstream lockorder detection surfaced.

@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 7014813 to a626549CompareApril 13, 2023 21:03
@TheBlueMattTheBlueMatt added this to the 0.0.116 milestone Apr 17, 2023
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Actually, gonna slip this cause it should really go in the same release as its followup, which isn't gonna make 115.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 6f1263d to 87bcf91CompareApril 17, 2023 20:55
@wpaulino
wpaulino self-requested a review April 18, 2023 17:29
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 87bcf91 to 51c3b37CompareApril 28, 2023 04:55
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Rebased.

@wpaulino

Copy link
Copy Markdown
Contributor

Will do another full pass after squash

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

Looks good

Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
$chan.get_latest_monitor_update_id() == $update_id
{
$chan.complete_one_mon_update($update_id);
if $chan.no_monitor_updates_pending() {

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.

I think we can use this check in channel_monitor_updated too (maybe redundant with @wpaulino's comment above). Or move this check into the handle_monitor_update_completion macro

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yea, I want to clean this logic up, mind if I do it in a followup, though? I have a handful of changes I'm working on to the monitor completion logic here that I can incorporate this into.

In the coming commits, we need to delay `ChannelMonitorUpdate`s
until future actions (specifically `Event` handling). However,
because we should only notify users once of a given
`ChannelMonitorUpdate` and they must be provided in-order, we need
to track which ones have or have not been given to users and, once
updating resumes, fly the ones that haven't already made it to
users.
To do this we simply add a `bool` in the `ChannelMonitorUpdate` set
stored in the `Channel` which indicates if an update flew and
decline to provide new updates back to the `ChannelManager` if any
updates have their flown bit unset.
Further, because we'll now by releasing `ChannelMonitorUpdate`s
which were already stored in the pending list, we now need to
support getting a `Completed` result for a monitor which isn't the
only pending monitor (or even out of order), thus we also rewrite
the way monitor updates are marked completed.
This will allow us to block `ChannelMonitorUpdate`s on `Event`
processing in the next commit.
Note that this gets dangerously close to breaking forwards
compatibility - if we have an `Event` with an
`EventCompletionAction` tied to it, we persist a new, even, TLV in
the `ChannelManager`. Hopefully this should be uncommon, as it
implies an `Event` was delayed until after a full round-trip to a
peer.
This adds handling of the new `EventCompletionAction`s after
`Event`s are handled, letting `ChannelMonitorUpdate`s which were
blocked fly after a relevant `Event`.
The previous commits set up the ability for us to hold
`ChannelMonitorUpdate`s which are pending until we're ready to pass
them to users and have them be applied. However, if the
`ChannelManager` is persisted while we're waiting to give the user
a `ChannelMonitorUpdate` we'll be confused on restart - seeing our
latest `ChannelMonitor` state as stale compared to our
`ChannelManager` - a critical error.
Luckily the solution is trivial, we simply need to store the
pending `ChannelMonitorUpdate` state and load it with the
`ChannelManager` data, allowing stale monitors on load as long as
we have the missing pending updates between where we are and the
latest `ChannelMonitor` state.
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 51c3b37 to 9dfe42cCompareMay 2, 2023 18:00
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed without further changes.

@valentinewallace

Copy link
Copy Markdown
Contributor

Looks good after @wpaulino takes another look!

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 880d88e to 9c36735CompareMay 4, 2023 19:29
wpaulino
wpaulino previously approved these changes May 4, 2023
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

oops sorry that commit was buggy, sec

valentinewallace
valentinewallace previously approved these changes May 4, 2023
@valentinewallace
valentinewallace dismissed their stale reviewMay 4, 2023 19:50

commit was buggy

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Actually, just gonna drop the last/new commit, its...hard, so we need to (a) handle_post_event_actions after we pending_events.drain(..num_events) as we only actually handle the post-event action if the event has been removed and (b) need to unset pending_events_processor and check if there are any remaining events both inside the same lock. Thus its kinda hard to change it around all that much without breaking it.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

The tests on #2112 failed with that commit, specifically, like all the tests.

@TheBlueMatt
TheBlueMatt merged commit e94647c into lightningdevkit:mainMay 4, 2023
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.

4 participants

@TheBlueMatt@codecov-commenter@wpaulino@valentinewallace
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Setup Support for delaying `ChannelMonitorUpdate` flight until an `Event` completes by TheBlueMatt · Pull Request #2111 · lightningdevkit/rust-lightning · GitHub
Skip to content

Setup Support for delaying ChannelMonitorUpdate flight until an Event completes - #2111

Merged
TheBlueMatt merged 4 commits into
lightningdevkit:mainfrom
TheBlueMatt:2023-03-sent-persist-order-prep
May 4, 2023
Merged

Setup Support for delaying ChannelMonitorUpdate flight until an Event completes#2111
TheBlueMatt merged 4 commits into
lightningdevkit:mainfrom
TheBlueMatt:2023-03-sent-persist-order-prep

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

This does all the work that will be required to pause ChannelMonitorUpdate flight until an Event completes, but doesn't actually use the new behavior. Sadly, I think we should consider splitting this work across release, as the commit Track an EventCompletionAction for after an Event is processed indicates -

Note that this gets dangerously close to breaking forwards
compatibility - if we have an `Event` with an
`EventCompletionAction` tied to it, we persist a new, even, TLV in
the `ChannelManager`. Hopefully this should be uncommon, as it
implies an `Event` was delayed until after a full round-trip to a
peer.

Still, I'm open to discussion on it - Events generally should be reliably processed before a full round-trip happens, and it sucks to fix major bugs across releases just over worry of a hopefully-very-rare race breaking forwards, but not backwards, compat.

@TheBlueMattTheBlueMatt added this to the 0.0.115 milestone Mar 17, 2023
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 3 times, most recently from 2aae7c8 to 91707fbCompareMarch 17, 2023 07:04
@codecov-commenter

codecov-commenter commented Mar 17, 2023

Copy link
Copy Markdown

Codecov Report

Patch coverage: 69.12% and project coverage change: +0.56 🎉

Comparison is base (88c63e9) 91.57% compared to head (880d88e) 92.14%.

❗ Current head 880d88e differs from pull request most recent head 9c36735. Consider uploading reports for the commit 9c36735 to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@ Coverage Diff @@## main #2111 +/- ##
==========================================
+ Coverage 91.57% 92.14% +0.56% 
==========================================
Files 104 105 +1 Lines 51930 61222 +9292 Branches 51930 61222 +9292 ==========================================
+ Hits 47556 56410 +8854 - Misses 4374 4812 +438 
Impacted FilesCoverage Δ
lightning/src/ln/channelmanager.rs90.47% <50.00%> (+1.66%)⬆️
lightning/src/ln/channel.rs92.64% <92.70%> (+2.62%)⬆️
lightning/src/ln/chanmon_update_fail_tests.rs98.61% <100.00%> (ø)
lightning/src/ln/functional_tests.rs98.25% <100.00%> (ø)
lightning/src/ln/outbound_payment.rs89.56% <100.00%> (-0.08%)⬇️

... and 21 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 91707fb to c595331CompareMarch 17, 2023 21:09
@wpaulino
wpaulino self-requested a review March 21, 2023 20:02
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 3 times, most recently from 57bebe7 to 9852b84CompareMarch 28, 2023 22:01
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
log_bytes!(self.channel_id));
self.pending_monitor_updates.push(monitor_update);
return Ok(self.pending_monitor_updates.last().unwrap());
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);

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.

Do you see any benefit in tracking the flown/dispatched pending updates in a separate Vec?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Uhhhhhhhhhh. Maybe? Not sure yet, honestly. It would clean up a bit of code, and make some other code a bit more complicated, kinda a wash, but I'm not 100% sure where this is gonna end up , I think this is all of the holding logic we're gonna need for it, but if we find some other bug in there in the future we could end up with more going on in the struct and a two-struct approach will be confusing.

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channel.rs
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 9852b84 to 2ba5289CompareMarch 30, 2023 23:53

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

Feel free to squash the existing fixups

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 2 times, most recently from ae76ed0 to 08ae599CompareApril 5, 2023 18:48
@wpaulino

Copy link
Copy Markdown
Contributor

Feel free to squash, will give it a final pass after a second reviewer.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed without further changes.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Fixed a silent rebase conflict as well as a bug that the further upstream lockorder detection surfaced.

@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 7014813 to a626549CompareApril 13, 2023 21:03
@TheBlueMattTheBlueMatt added this to the 0.0.116 milestone Apr 17, 2023
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Actually, gonna slip this cause it should really go in the same release as its followup, which isn't gonna make 115.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 6f1263d to 87bcf91CompareApril 17, 2023 20:55
@wpaulino
wpaulino self-requested a review April 18, 2023 17:29
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 87bcf91 to 51c3b37CompareApril 28, 2023 04:55
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Rebased.

@wpaulino

Copy link
Copy Markdown
Contributor

Will do another full pass after squash

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

Looks good

Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
$chan.get_latest_monitor_update_id() == $update_id
{
$chan.complete_one_mon_update($update_id);
if $chan.no_monitor_updates_pending() {

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.

I think we can use this check in channel_monitor_updated too (maybe redundant with @wpaulino's comment above). Or move this check into the handle_monitor_update_completion macro

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yea, I want to clean this logic up, mind if I do it in a followup, though? I have a handful of changes I'm working on to the monitor completion logic here that I can incorporate this into.

In the coming commits, we need to delay `ChannelMonitorUpdate`s
until future actions (specifically `Event` handling). However,
because we should only notify users once of a given
`ChannelMonitorUpdate` and they must be provided in-order, we need
to track which ones have or have not been given to users and, once
updating resumes, fly the ones that haven't already made it to
users.
To do this we simply add a `bool` in the `ChannelMonitorUpdate` set
stored in the `Channel` which indicates if an update flew and
decline to provide new updates back to the `ChannelManager` if any
updates have their flown bit unset.
Further, because we'll now by releasing `ChannelMonitorUpdate`s
which were already stored in the pending list, we now need to
support getting a `Completed` result for a monitor which isn't the
only pending monitor (or even out of order), thus we also rewrite
the way monitor updates are marked completed.
This will allow us to block `ChannelMonitorUpdate`s on `Event`
processing in the next commit.
Note that this gets dangerously close to breaking forwards
compatibility - if we have an `Event` with an
`EventCompletionAction` tied to it, we persist a new, even, TLV in
the `ChannelManager`. Hopefully this should be uncommon, as it
implies an `Event` was delayed until after a full round-trip to a
peer.
This adds handling of the new `EventCompletionAction`s after
`Event`s are handled, letting `ChannelMonitorUpdate`s which were
blocked fly after a relevant `Event`.
The previous commits set up the ability for us to hold
`ChannelMonitorUpdate`s which are pending until we're ready to pass
them to users and have them be applied. However, if the
`ChannelManager` is persisted while we're waiting to give the user
a `ChannelMonitorUpdate` we'll be confused on restart - seeing our
latest `ChannelMonitor` state as stale compared to our
`ChannelManager` - a critical error.
Luckily the solution is trivial, we simply need to store the
pending `ChannelMonitorUpdate` state and load it with the
`ChannelManager` data, allowing stale monitors on load as long as
we have the missing pending updates between where we are and the
latest `ChannelMonitor` state.
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 51c3b37 to 9dfe42cCompareMay 2, 2023 18:00
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed without further changes.

@valentinewallace

Copy link
Copy Markdown
Contributor

Looks good after @wpaulino takes another look!

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 880d88e to 9c36735CompareMay 4, 2023 19:29
wpaulino
wpaulino previously approved these changes May 4, 2023
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

oops sorry that commit was buggy, sec

valentinewallace
valentinewallace previously approved these changes May 4, 2023
@valentinewallace
valentinewallace dismissed their stale reviewMay 4, 2023 19:50

commit was buggy

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Actually, just gonna drop the last/new commit, its...hard, so we need to (a) handle_post_event_actions after we pending_events.drain(..num_events) as we only actually handle the post-event action if the event has been removed and (b) need to unset pending_events_processor and check if there are any remaining events both inside the same lock. Thus its kinda hard to change it around all that much without breaking it.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

The tests on #2112 failed with that commit, specifically, like all the tests.

@TheBlueMatt
TheBlueMatt merged commit e94647c into lightningdevkit:mainMay 4, 2023
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.

4 participants

@TheBlueMatt@codecov-commenter@wpaulino@valentinewallace
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Setup Support for delaying `ChannelMonitorUpdate` flight until an `Event` completes by TheBlueMatt · Pull Request #2111 · lightningdevkit/rust-lightning · GitHub
Skip to content

Setup Support for delaying ChannelMonitorUpdate flight until an Event completes - #2111

Merged
TheBlueMatt merged 4 commits into
lightningdevkit:mainfrom
TheBlueMatt:2023-03-sent-persist-order-prep
May 4, 2023
Merged

Setup Support for delaying ChannelMonitorUpdate flight until an Event completes#2111
TheBlueMatt merged 4 commits into
lightningdevkit:mainfrom
TheBlueMatt:2023-03-sent-persist-order-prep

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

This does all the work that will be required to pause ChannelMonitorUpdate flight until an Event completes, but doesn't actually use the new behavior. Sadly, I think we should consider splitting this work across release, as the commit Track an EventCompletionAction for after an Event is processed indicates -

Note that this gets dangerously close to breaking forwards
compatibility - if we have an `Event` with an
`EventCompletionAction` tied to it, we persist a new, even, TLV in
the `ChannelManager`. Hopefully this should be uncommon, as it
implies an `Event` was delayed until after a full round-trip to a
peer.

Still, I'm open to discussion on it - Events generally should be reliably processed before a full round-trip happens, and it sucks to fix major bugs across releases just over worry of a hopefully-very-rare race breaking forwards, but not backwards, compat.

@TheBlueMattTheBlueMatt added this to the 0.0.115 milestone Mar 17, 2023
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 3 times, most recently from 2aae7c8 to 91707fbCompareMarch 17, 2023 07:04
@codecov-commenter

codecov-commenter commented Mar 17, 2023

Copy link
Copy Markdown

Codecov Report

Patch coverage: 69.12% and project coverage change: +0.56 🎉

Comparison is base (88c63e9) 91.57% compared to head (880d88e) 92.14%.

❗ Current head 880d88e differs from pull request most recent head 9c36735. Consider uploading reports for the commit 9c36735 to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@ Coverage Diff @@## main #2111 +/- ##
==========================================
+ Coverage 91.57% 92.14% +0.56% 
==========================================
Files 104 105 +1 Lines 51930 61222 +9292 Branches 51930 61222 +9292 ==========================================
+ Hits 47556 56410 +8854 - Misses 4374 4812 +438 
Impacted FilesCoverage Δ
lightning/src/ln/channelmanager.rs90.47% <50.00%> (+1.66%)⬆️
lightning/src/ln/channel.rs92.64% <92.70%> (+2.62%)⬆️
lightning/src/ln/chanmon_update_fail_tests.rs98.61% <100.00%> (ø)
lightning/src/ln/functional_tests.rs98.25% <100.00%> (ø)
lightning/src/ln/outbound_payment.rs89.56% <100.00%> (-0.08%)⬇️

... and 21 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 91707fb to c595331CompareMarch 17, 2023 21:09
@wpaulino
wpaulino self-requested a review March 21, 2023 20:02
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 3 times, most recently from 57bebe7 to 9852b84CompareMarch 28, 2023 22:01
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
log_bytes!(self.channel_id));
self.pending_monitor_updates.push(monitor_update);
return Ok(self.pending_monitor_updates.last().unwrap());
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);

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.

Do you see any benefit in tracking the flown/dispatched pending updates in a separate Vec?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Uhhhhhhhhhh. Maybe? Not sure yet, honestly. It would clean up a bit of code, and make some other code a bit more complicated, kinda a wash, but I'm not 100% sure where this is gonna end up , I think this is all of the holding logic we're gonna need for it, but if we find some other bug in there in the future we could end up with more going on in the struct and a two-struct approach will be confusing.

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channel.rs
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 9852b84 to 2ba5289CompareMarch 30, 2023 23:53

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

Feel free to squash the existing fixups

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 2 times, most recently from ae76ed0 to 08ae599CompareApril 5, 2023 18:48
@wpaulino

Copy link
Copy Markdown
Contributor

Feel free to squash, will give it a final pass after a second reviewer.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed without further changes.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Fixed a silent rebase conflict as well as a bug that the further upstream lockorder detection surfaced.

@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 7014813 to a626549CompareApril 13, 2023 21:03
@TheBlueMattTheBlueMatt added this to the 0.0.116 milestone Apr 17, 2023
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Actually, gonna slip this cause it should really go in the same release as its followup, which isn't gonna make 115.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 6f1263d to 87bcf91CompareApril 17, 2023 20:55
@wpaulino
wpaulino self-requested a review April 18, 2023 17:29
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 87bcf91 to 51c3b37CompareApril 28, 2023 04:55
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Rebased.

@wpaulino

Copy link
Copy Markdown
Contributor

Will do another full pass after squash

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

Looks good

Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
$chan.get_latest_monitor_update_id() == $update_id
{
$chan.complete_one_mon_update($update_id);
if $chan.no_monitor_updates_pending() {

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.

I think we can use this check in channel_monitor_updated too (maybe redundant with @wpaulino's comment above). Or move this check into the handle_monitor_update_completion macro

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yea, I want to clean this logic up, mind if I do it in a followup, though? I have a handful of changes I'm working on to the monitor completion logic here that I can incorporate this into.

In the coming commits, we need to delay `ChannelMonitorUpdate`s
until future actions (specifically `Event` handling). However,
because we should only notify users once of a given
`ChannelMonitorUpdate` and they must be provided in-order, we need
to track which ones have or have not been given to users and, once
updating resumes, fly the ones that haven't already made it to
users.
To do this we simply add a `bool` in the `ChannelMonitorUpdate` set
stored in the `Channel` which indicates if an update flew and
decline to provide new updates back to the `ChannelManager` if any
updates have their flown bit unset.
Further, because we'll now by releasing `ChannelMonitorUpdate`s
which were already stored in the pending list, we now need to
support getting a `Completed` result for a monitor which isn't the
only pending monitor (or even out of order), thus we also rewrite
the way monitor updates are marked completed.
This will allow us to block `ChannelMonitorUpdate`s on `Event`
processing in the next commit.
Note that this gets dangerously close to breaking forwards
compatibility - if we have an `Event` with an
`EventCompletionAction` tied to it, we persist a new, even, TLV in
the `ChannelManager`. Hopefully this should be uncommon, as it
implies an `Event` was delayed until after a full round-trip to a
peer.
This adds handling of the new `EventCompletionAction`s after
`Event`s are handled, letting `ChannelMonitorUpdate`s which were
blocked fly after a relevant `Event`.
The previous commits set up the ability for us to hold
`ChannelMonitorUpdate`s which are pending until we're ready to pass
them to users and have them be applied. However, if the
`ChannelManager` is persisted while we're waiting to give the user
a `ChannelMonitorUpdate` we'll be confused on restart - seeing our
latest `ChannelMonitor` state as stale compared to our
`ChannelManager` - a critical error.
Luckily the solution is trivial, we simply need to store the
pending `ChannelMonitorUpdate` state and load it with the
`ChannelManager` data, allowing stale monitors on load as long as
we have the missing pending updates between where we are and the
latest `ChannelMonitor` state.
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 51c3b37 to 9dfe42cCompareMay 2, 2023 18:00
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed without further changes.

@valentinewallace

Copy link
Copy Markdown
Contributor

Looks good after @wpaulino takes another look!

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 880d88e to 9c36735CompareMay 4, 2023 19:29
wpaulino
wpaulino previously approved these changes May 4, 2023
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

oops sorry that commit was buggy, sec

valentinewallace
valentinewallace previously approved these changes May 4, 2023
@valentinewallace
valentinewallace dismissed their stale reviewMay 4, 2023 19:50

commit was buggy

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Actually, just gonna drop the last/new commit, its...hard, so we need to (a) handle_post_event_actions after we pending_events.drain(..num_events) as we only actually handle the post-event action if the event has been removed and (b) need to unset pending_events_processor and check if there are any remaining events both inside the same lock. Thus its kinda hard to change it around all that much without breaking it.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

The tests on #2112 failed with that commit, specifically, like all the tests.

@TheBlueMatt
TheBlueMatt merged commit e94647c into lightningdevkit:mainMay 4, 2023
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.

4 participants

@TheBlueMatt@codecov-commenter@wpaulino@valentinewallace
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', '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('^' + ".*" + ' Setup Support for delaying `ChannelMonitorUpdate` flight until an `Event` completes by TheBlueMatt · Pull Request #2111 · lightningdevkit/rust-lightning · GitHub
Skip to content

Setup Support for delaying ChannelMonitorUpdate flight until an Event completes - #2111

Merged
TheBlueMatt merged 4 commits into
lightningdevkit:mainfrom
TheBlueMatt:2023-03-sent-persist-order-prep
May 4, 2023
Merged

Setup Support for delaying ChannelMonitorUpdate flight until an Event completes#2111
TheBlueMatt merged 4 commits into
lightningdevkit:mainfrom
TheBlueMatt:2023-03-sent-persist-order-prep

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

This does all the work that will be required to pause ChannelMonitorUpdate flight until an Event completes, but doesn't actually use the new behavior. Sadly, I think we should consider splitting this work across release, as the commit Track an EventCompletionAction for after an Event is processed indicates -

Note that this gets dangerously close to breaking forwards
compatibility - if we have an `Event` with an
`EventCompletionAction` tied to it, we persist a new, even, TLV in
the `ChannelManager`. Hopefully this should be uncommon, as it
implies an `Event` was delayed until after a full round-trip to a
peer.

Still, I'm open to discussion on it - Events generally should be reliably processed before a full round-trip happens, and it sucks to fix major bugs across releases just over worry of a hopefully-very-rare race breaking forwards, but not backwards, compat.

@TheBlueMattTheBlueMatt added this to the 0.0.115 milestone Mar 17, 2023
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 3 times, most recently from 2aae7c8 to 91707fbCompareMarch 17, 2023 07:04
@codecov-commenter

codecov-commenter commented Mar 17, 2023

Copy link
Copy Markdown

Codecov Report

Patch coverage: 69.12% and project coverage change: +0.56 🎉

Comparison is base (88c63e9) 91.57% compared to head (880d88e) 92.14%.

❗ Current head 880d88e differs from pull request most recent head 9c36735. Consider uploading reports for the commit 9c36735 to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@ Coverage Diff @@## main #2111 +/- ##
==========================================
+ Coverage 91.57% 92.14% +0.56% 
==========================================
Files 104 105 +1 Lines 51930 61222 +9292 Branches 51930 61222 +9292 ==========================================
+ Hits 47556 56410 +8854 - Misses 4374 4812 +438 
Impacted FilesCoverage Δ
lightning/src/ln/channelmanager.rs90.47% <50.00%> (+1.66%)⬆️
lightning/src/ln/channel.rs92.64% <92.70%> (+2.62%)⬆️
lightning/src/ln/chanmon_update_fail_tests.rs98.61% <100.00%> (ø)
lightning/src/ln/functional_tests.rs98.25% <100.00%> (ø)
lightning/src/ln/outbound_payment.rs89.56% <100.00%> (-0.08%)⬇️

... and 21 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 91707fb to c595331CompareMarch 17, 2023 21:09
@wpaulino
wpaulino self-requested a review March 21, 2023 20:02
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 3 times, most recently from 57bebe7 to 9852b84CompareMarch 28, 2023 22:01
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
log_bytes!(self.channel_id));
self.pending_monitor_updates.push(monitor_update);
return Ok(self.pending_monitor_updates.last().unwrap());
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);

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.

Do you see any benefit in tracking the flown/dispatched pending updates in a separate Vec?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Uhhhhhhhhhh. Maybe? Not sure yet, honestly. It would clean up a bit of code, and make some other code a bit more complicated, kinda a wash, but I'm not 100% sure where this is gonna end up , I think this is all of the holding logic we're gonna need for it, but if we find some other bug in there in the future we could end up with more going on in the struct and a two-struct approach will be confusing.

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channel.rs
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 9852b84 to 2ba5289CompareMarch 30, 2023 23:53

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

Feel free to squash the existing fixups

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 2 times, most recently from ae76ed0 to 08ae599CompareApril 5, 2023 18:48
@wpaulino

Copy link
Copy Markdown
Contributor

Feel free to squash, will give it a final pass after a second reviewer.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed without further changes.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Fixed a silent rebase conflict as well as a bug that the further upstream lockorder detection surfaced.

@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 7014813 to a626549CompareApril 13, 2023 21:03
@TheBlueMattTheBlueMatt added this to the 0.0.116 milestone Apr 17, 2023
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Actually, gonna slip this cause it should really go in the same release as its followup, which isn't gonna make 115.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 6f1263d to 87bcf91CompareApril 17, 2023 20:55
@wpaulino
wpaulino self-requested a review April 18, 2023 17:29
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 87bcf91 to 51c3b37CompareApril 28, 2023 04:55
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Rebased.

@wpaulino

Copy link
Copy Markdown
Contributor

Will do another full pass after squash

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

Looks good

Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
$chan.get_latest_monitor_update_id() == $update_id
{
$chan.complete_one_mon_update($update_id);
if $chan.no_monitor_updates_pending() {

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.

I think we can use this check in channel_monitor_updated too (maybe redundant with @wpaulino's comment above). Or move this check into the handle_monitor_update_completion macro

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yea, I want to clean this logic up, mind if I do it in a followup, though? I have a handful of changes I'm working on to the monitor completion logic here that I can incorporate this into.

In the coming commits, we need to delay `ChannelMonitorUpdate`s
until future actions (specifically `Event` handling). However,
because we should only notify users once of a given
`ChannelMonitorUpdate` and they must be provided in-order, we need
to track which ones have or have not been given to users and, once
updating resumes, fly the ones that haven't already made it to
users.
To do this we simply add a `bool` in the `ChannelMonitorUpdate` set
stored in the `Channel` which indicates if an update flew and
decline to provide new updates back to the `ChannelManager` if any
updates have their flown bit unset.
Further, because we'll now by releasing `ChannelMonitorUpdate`s
which were already stored in the pending list, we now need to
support getting a `Completed` result for a monitor which isn't the
only pending monitor (or even out of order), thus we also rewrite
the way monitor updates are marked completed.
This will allow us to block `ChannelMonitorUpdate`s on `Event`
processing in the next commit.
Note that this gets dangerously close to breaking forwards
compatibility - if we have an `Event` with an
`EventCompletionAction` tied to it, we persist a new, even, TLV in
the `ChannelManager`. Hopefully this should be uncommon, as it
implies an `Event` was delayed until after a full round-trip to a
peer.
This adds handling of the new `EventCompletionAction`s after
`Event`s are handled, letting `ChannelMonitorUpdate`s which were
blocked fly after a relevant `Event`.
The previous commits set up the ability for us to hold
`ChannelMonitorUpdate`s which are pending until we're ready to pass
them to users and have them be applied. However, if the
`ChannelManager` is persisted while we're waiting to give the user
a `ChannelMonitorUpdate` we'll be confused on restart - seeing our
latest `ChannelMonitor` state as stale compared to our
`ChannelManager` - a critical error.
Luckily the solution is trivial, we simply need to store the
pending `ChannelMonitorUpdate` state and load it with the
`ChannelManager` data, allowing stale monitors on load as long as
we have the missing pending updates between where we are and the
latest `ChannelMonitor` state.
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 51c3b37 to 9dfe42cCompareMay 2, 2023 18:00
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed without further changes.

@valentinewallace

Copy link
Copy Markdown
Contributor

Looks good after @wpaulino takes another look!

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 880d88e to 9c36735CompareMay 4, 2023 19:29
wpaulino
wpaulino previously approved these changes May 4, 2023
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

oops sorry that commit was buggy, sec

valentinewallace
valentinewallace previously approved these changes May 4, 2023
@valentinewallace
valentinewallace dismissed their stale reviewMay 4, 2023 19:50

commit was buggy

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Actually, just gonna drop the last/new commit, its...hard, so we need to (a) handle_post_event_actions after we pending_events.drain(..num_events) as we only actually handle the post-event action if the event has been removed and (b) need to unset pending_events_processor and check if there are any remaining events both inside the same lock. Thus its kinda hard to change it around all that much without breaking it.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

The tests on #2112 failed with that commit, specifically, like all the tests.

@TheBlueMatt
TheBlueMatt merged commit e94647c into lightningdevkit:mainMay 4, 2023
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.

4 participants

@TheBlueMatt@codecov-commenter@wpaulino@valentinewallace
, '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" + ' Setup Support for delaying `ChannelMonitorUpdate` flight until an `Event` completes by TheBlueMatt · Pull Request #2111 · lightningdevkit/rust-lightning · GitHub
Skip to content

Setup Support for delaying ChannelMonitorUpdate flight until an Event completes - #2111

Merged
TheBlueMatt merged 4 commits into
lightningdevkit:mainfrom
TheBlueMatt:2023-03-sent-persist-order-prep
May 4, 2023
Merged

Setup Support for delaying ChannelMonitorUpdate flight until an Event completes#2111
TheBlueMatt merged 4 commits into
lightningdevkit:mainfrom
TheBlueMatt:2023-03-sent-persist-order-prep

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

This does all the work that will be required to pause ChannelMonitorUpdate flight until an Event completes, but doesn't actually use the new behavior. Sadly, I think we should consider splitting this work across release, as the commit Track an EventCompletionAction for after an Event is processed indicates -

Note that this gets dangerously close to breaking forwards
compatibility - if we have an `Event` with an
`EventCompletionAction` tied to it, we persist a new, even, TLV in
the `ChannelManager`. Hopefully this should be uncommon, as it
implies an `Event` was delayed until after a full round-trip to a
peer.

Still, I'm open to discussion on it - Events generally should be reliably processed before a full round-trip happens, and it sucks to fix major bugs across releases just over worry of a hopefully-very-rare race breaking forwards, but not backwards, compat.

@TheBlueMattTheBlueMatt added this to the 0.0.115 milestone Mar 17, 2023
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 3 times, most recently from 2aae7c8 to 91707fbCompareMarch 17, 2023 07:04
@codecov-commenter

codecov-commenter commented Mar 17, 2023

Copy link
Copy Markdown

Codecov Report

Patch coverage: 69.12% and project coverage change: +0.56 🎉

Comparison is base (88c63e9) 91.57% compared to head (880d88e) 92.14%.

❗ Current head 880d88e differs from pull request most recent head 9c36735. Consider uploading reports for the commit 9c36735 to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@ Coverage Diff @@## main #2111 +/- ##
==========================================
+ Coverage 91.57% 92.14% +0.56% 
==========================================
Files 104 105 +1 Lines 51930 61222 +9292 Branches 51930 61222 +9292 ==========================================
+ Hits 47556 56410 +8854 - Misses 4374 4812 +438 
Impacted FilesCoverage Δ
lightning/src/ln/channelmanager.rs90.47% <50.00%> (+1.66%)⬆️
lightning/src/ln/channel.rs92.64% <92.70%> (+2.62%)⬆️
lightning/src/ln/chanmon_update_fail_tests.rs98.61% <100.00%> (ø)
lightning/src/ln/functional_tests.rs98.25% <100.00%> (ø)
lightning/src/ln/outbound_payment.rs89.56% <100.00%> (-0.08%)⬇️

... and 21 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 91707fb to c595331CompareMarch 17, 2023 21:09
@wpaulino
wpaulino self-requested a review March 21, 2023 20:02
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 3 times, most recently from 57bebe7 to 9852b84CompareMarch 28, 2023 22:01
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
log_bytes!(self.channel_id));
self.pending_monitor_updates.push(monitor_update);
return Ok(self.pending_monitor_updates.last().unwrap());
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);

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.

Do you see any benefit in tracking the flown/dispatched pending updates in a separate Vec?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Uhhhhhhhhhh. Maybe? Not sure yet, honestly. It would clean up a bit of code, and make some other code a bit more complicated, kinda a wash, but I'm not 100% sure where this is gonna end up , I think this is all of the holding logic we're gonna need for it, but if we find some other bug in there in the future we could end up with more going on in the struct and a two-struct approach will be confusing.

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channel.rs
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 9852b84 to 2ba5289CompareMarch 30, 2023 23:53

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

Feel free to squash the existing fixups

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 2 times, most recently from ae76ed0 to 08ae599CompareApril 5, 2023 18:48
@wpaulino

Copy link
Copy Markdown
Contributor

Feel free to squash, will give it a final pass after a second reviewer.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed without further changes.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Fixed a silent rebase conflict as well as a bug that the further upstream lockorder detection surfaced.

@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 7014813 to a626549CompareApril 13, 2023 21:03
@TheBlueMattTheBlueMatt added this to the 0.0.116 milestone Apr 17, 2023
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Actually, gonna slip this cause it should really go in the same release as its followup, which isn't gonna make 115.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 6f1263d to 87bcf91CompareApril 17, 2023 20:55
@wpaulino
wpaulino self-requested a review April 18, 2023 17:29
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 87bcf91 to 51c3b37CompareApril 28, 2023 04:55
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Rebased.

@wpaulino

Copy link
Copy Markdown
Contributor

Will do another full pass after squash

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

Looks good

Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
$chan.get_latest_monitor_update_id() == $update_id
{
$chan.complete_one_mon_update($update_id);
if $chan.no_monitor_updates_pending() {

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.

I think we can use this check in channel_monitor_updated too (maybe redundant with @wpaulino's comment above). Or move this check into the handle_monitor_update_completion macro

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yea, I want to clean this logic up, mind if I do it in a followup, though? I have a handful of changes I'm working on to the monitor completion logic here that I can incorporate this into.

In the coming commits, we need to delay `ChannelMonitorUpdate`s
until future actions (specifically `Event` handling). However,
because we should only notify users once of a given
`ChannelMonitorUpdate` and they must be provided in-order, we need
to track which ones have or have not been given to users and, once
updating resumes, fly the ones that haven't already made it to
users.
To do this we simply add a `bool` in the `ChannelMonitorUpdate` set
stored in the `Channel` which indicates if an update flew and
decline to provide new updates back to the `ChannelManager` if any
updates have their flown bit unset.
Further, because we'll now by releasing `ChannelMonitorUpdate`s
which were already stored in the pending list, we now need to
support getting a `Completed` result for a monitor which isn't the
only pending monitor (or even out of order), thus we also rewrite
the way monitor updates are marked completed.
This will allow us to block `ChannelMonitorUpdate`s on `Event`
processing in the next commit.
Note that this gets dangerously close to breaking forwards
compatibility - if we have an `Event` with an
`EventCompletionAction` tied to it, we persist a new, even, TLV in
the `ChannelManager`. Hopefully this should be uncommon, as it
implies an `Event` was delayed until after a full round-trip to a
peer.
This adds handling of the new `EventCompletionAction`s after
`Event`s are handled, letting `ChannelMonitorUpdate`s which were
blocked fly after a relevant `Event`.
The previous commits set up the ability for us to hold
`ChannelMonitorUpdate`s which are pending until we're ready to pass
them to users and have them be applied. However, if the
`ChannelManager` is persisted while we're waiting to give the user
a `ChannelMonitorUpdate` we'll be confused on restart - seeing our
latest `ChannelMonitor` state as stale compared to our
`ChannelManager` - a critical error.
Luckily the solution is trivial, we simply need to store the
pending `ChannelMonitorUpdate` state and load it with the
`ChannelManager` data, allowing stale monitors on load as long as
we have the missing pending updates between where we are and the
latest `ChannelMonitor` state.
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 51c3b37 to 9dfe42cCompareMay 2, 2023 18:00
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed without further changes.

@valentinewallace

Copy link
Copy Markdown
Contributor

Looks good after @wpaulino takes another look!

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 880d88e to 9c36735CompareMay 4, 2023 19:29
wpaulino
wpaulino previously approved these changes May 4, 2023
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

oops sorry that commit was buggy, sec

valentinewallace
valentinewallace previously approved these changes May 4, 2023
@valentinewallace
valentinewallace dismissed their stale reviewMay 4, 2023 19:50

commit was buggy

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Actually, just gonna drop the last/new commit, its...hard, so we need to (a) handle_post_event_actions after we pending_events.drain(..num_events) as we only actually handle the post-event action if the event has been removed and (b) need to unset pending_events_processor and check if there are any remaining events both inside the same lock. Thus its kinda hard to change it around all that much without breaking it.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

The tests on #2112 failed with that commit, specifically, like all the tests.

@TheBlueMatt
TheBlueMatt merged commit e94647c into lightningdevkit:mainMay 4, 2023
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.

4 participants

@TheBlueMatt@codecov-commenter@wpaulino@valentinewallace
, '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('^' + ".*" + ' Setup Support for delaying `ChannelMonitorUpdate` flight until an `Event` completes by TheBlueMatt · Pull Request #2111 · lightningdevkit/rust-lightning · GitHub
Skip to content

Setup Support for delaying ChannelMonitorUpdate flight until an Event completes - #2111

Merged
TheBlueMatt merged 4 commits into
lightningdevkit:mainfrom
TheBlueMatt:2023-03-sent-persist-order-prep
May 4, 2023
Merged

Setup Support for delaying ChannelMonitorUpdate flight until an Event completes#2111
TheBlueMatt merged 4 commits into
lightningdevkit:mainfrom
TheBlueMatt:2023-03-sent-persist-order-prep

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

This does all the work that will be required to pause ChannelMonitorUpdate flight until an Event completes, but doesn't actually use the new behavior. Sadly, I think we should consider splitting this work across release, as the commit Track an EventCompletionAction for after an Event is processed indicates -

Note that this gets dangerously close to breaking forwards
compatibility - if we have an `Event` with an
`EventCompletionAction` tied to it, we persist a new, even, TLV in
the `ChannelManager`. Hopefully this should be uncommon, as it
implies an `Event` was delayed until after a full round-trip to a
peer.

Still, I'm open to discussion on it - Events generally should be reliably processed before a full round-trip happens, and it sucks to fix major bugs across releases just over worry of a hopefully-very-rare race breaking forwards, but not backwards, compat.

@TheBlueMattTheBlueMatt added this to the 0.0.115 milestone Mar 17, 2023
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 3 times, most recently from 2aae7c8 to 91707fbCompareMarch 17, 2023 07:04
@codecov-commenter

codecov-commenter commented Mar 17, 2023

Copy link
Copy Markdown

Codecov Report

Patch coverage: 69.12% and project coverage change: +0.56 🎉

Comparison is base (88c63e9) 91.57% compared to head (880d88e) 92.14%.

❗ Current head 880d88e differs from pull request most recent head 9c36735. Consider uploading reports for the commit 9c36735 to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@ Coverage Diff @@## main #2111 +/- ##
==========================================
+ Coverage 91.57% 92.14% +0.56% 
==========================================
Files 104 105 +1 Lines 51930 61222 +9292 Branches 51930 61222 +9292 ==========================================
+ Hits 47556 56410 +8854 - Misses 4374 4812 +438 
Impacted FilesCoverage Δ
lightning/src/ln/channelmanager.rs90.47% <50.00%> (+1.66%)⬆️
lightning/src/ln/channel.rs92.64% <92.70%> (+2.62%)⬆️
lightning/src/ln/chanmon_update_fail_tests.rs98.61% <100.00%> (ø)
lightning/src/ln/functional_tests.rs98.25% <100.00%> (ø)
lightning/src/ln/outbound_payment.rs89.56% <100.00%> (-0.08%)⬇️

... and 21 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 91707fb to c595331CompareMarch 17, 2023 21:09
@wpaulino
wpaulino self-requested a review March 21, 2023 20:02
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 3 times, most recently from 57bebe7 to 9852b84CompareMarch 28, 2023 22:01
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
log_bytes!(self.channel_id));
self.pending_monitor_updates.push(monitor_update);
return Ok(self.pending_monitor_updates.last().unwrap());
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);

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.

Do you see any benefit in tracking the flown/dispatched pending updates in a separate Vec?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Uhhhhhhhhhh. Maybe? Not sure yet, honestly. It would clean up a bit of code, and make some other code a bit more complicated, kinda a wash, but I'm not 100% sure where this is gonna end up , I think this is all of the holding logic we're gonna need for it, but if we find some other bug in there in the future we could end up with more going on in the struct and a two-struct approach will be confusing.

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channel.rs
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 9852b84 to 2ba5289CompareMarch 30, 2023 23:53

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

Feel free to squash the existing fixups

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 2 times, most recently from ae76ed0 to 08ae599CompareApril 5, 2023 18:48
@wpaulino

Copy link
Copy Markdown
Contributor

Feel free to squash, will give it a final pass after a second reviewer.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed without further changes.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Fixed a silent rebase conflict as well as a bug that the further upstream lockorder detection surfaced.

@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 7014813 to a626549CompareApril 13, 2023 21:03
@TheBlueMattTheBlueMatt added this to the 0.0.116 milestone Apr 17, 2023
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Actually, gonna slip this cause it should really go in the same release as its followup, which isn't gonna make 115.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 6f1263d to 87bcf91CompareApril 17, 2023 20:55
@wpaulino
wpaulino self-requested a review April 18, 2023 17:29
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 87bcf91 to 51c3b37CompareApril 28, 2023 04:55
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Rebased.

@wpaulino

Copy link
Copy Markdown
Contributor

Will do another full pass after squash

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

Looks good

Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
$chan.get_latest_monitor_update_id() == $update_id
{
$chan.complete_one_mon_update($update_id);
if $chan.no_monitor_updates_pending() {

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.

I think we can use this check in channel_monitor_updated too (maybe redundant with @wpaulino's comment above). Or move this check into the handle_monitor_update_completion macro

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yea, I want to clean this logic up, mind if I do it in a followup, though? I have a handful of changes I'm working on to the monitor completion logic here that I can incorporate this into.

In the coming commits, we need to delay `ChannelMonitorUpdate`s
until future actions (specifically `Event` handling). However,
because we should only notify users once of a given
`ChannelMonitorUpdate` and they must be provided in-order, we need
to track which ones have or have not been given to users and, once
updating resumes, fly the ones that haven't already made it to
users.
To do this we simply add a `bool` in the `ChannelMonitorUpdate` set
stored in the `Channel` which indicates if an update flew and
decline to provide new updates back to the `ChannelManager` if any
updates have their flown bit unset.
Further, because we'll now by releasing `ChannelMonitorUpdate`s
which were already stored in the pending list, we now need to
support getting a `Completed` result for a monitor which isn't the
only pending monitor (or even out of order), thus we also rewrite
the way monitor updates are marked completed.
This will allow us to block `ChannelMonitorUpdate`s on `Event`
processing in the next commit.
Note that this gets dangerously close to breaking forwards
compatibility - if we have an `Event` with an
`EventCompletionAction` tied to it, we persist a new, even, TLV in
the `ChannelManager`. Hopefully this should be uncommon, as it
implies an `Event` was delayed until after a full round-trip to a
peer.
This adds handling of the new `EventCompletionAction`s after
`Event`s are handled, letting `ChannelMonitorUpdate`s which were
blocked fly after a relevant `Event`.
The previous commits set up the ability for us to hold
`ChannelMonitorUpdate`s which are pending until we're ready to pass
them to users and have them be applied. However, if the
`ChannelManager` is persisted while we're waiting to give the user
a `ChannelMonitorUpdate` we'll be confused on restart - seeing our
latest `ChannelMonitor` state as stale compared to our
`ChannelManager` - a critical error.
Luckily the solution is trivial, we simply need to store the
pending `ChannelMonitorUpdate` state and load it with the
`ChannelManager` data, allowing stale monitors on load as long as
we have the missing pending updates between where we are and the
latest `ChannelMonitor` state.
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 51c3b37 to 9dfe42cCompareMay 2, 2023 18:00
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed without further changes.

@valentinewallace

Copy link
Copy Markdown
Contributor

Looks good after @wpaulino takes another look!

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 880d88e to 9c36735CompareMay 4, 2023 19:29
wpaulino
wpaulino previously approved these changes May 4, 2023
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

oops sorry that commit was buggy, sec

valentinewallace
valentinewallace previously approved these changes May 4, 2023
@valentinewallace
valentinewallace dismissed their stale reviewMay 4, 2023 19:50

commit was buggy

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Actually, just gonna drop the last/new commit, its...hard, so we need to (a) handle_post_event_actions after we pending_events.drain(..num_events) as we only actually handle the post-event action if the event has been removed and (b) need to unset pending_events_processor and check if there are any remaining events both inside the same lock. Thus its kinda hard to change it around all that much without breaking it.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

The tests on #2112 failed with that commit, specifically, like all the tests.

@TheBlueMatt
TheBlueMatt merged commit e94647c into lightningdevkit:mainMay 4, 2023
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.

4 participants

@TheBlueMatt@codecov-commenter@wpaulino@valentinewallace
, '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); } })(); })(); Setup Support for delaying `ChannelMonitorUpdate` flight until an `Event` completes by TheBlueMatt · Pull Request #2111 · lightningdevkit/rust-lightning · GitHub
Skip to content

Setup Support for delaying ChannelMonitorUpdate flight until an Event completes - #2111

Merged
TheBlueMatt merged 4 commits into
lightningdevkit:mainfrom
TheBlueMatt:2023-03-sent-persist-order-prep
May 4, 2023
Merged

Setup Support for delaying ChannelMonitorUpdate flight until an Event completes#2111
TheBlueMatt merged 4 commits into
lightningdevkit:mainfrom
TheBlueMatt:2023-03-sent-persist-order-prep

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

This does all the work that will be required to pause ChannelMonitorUpdate flight until an Event completes, but doesn't actually use the new behavior. Sadly, I think we should consider splitting this work across release, as the commit Track an EventCompletionAction for after an Event is processed indicates -

Note that this gets dangerously close to breaking forwards
compatibility - if we have an `Event` with an
`EventCompletionAction` tied to it, we persist a new, even, TLV in
the `ChannelManager`. Hopefully this should be uncommon, as it
implies an `Event` was delayed until after a full round-trip to a
peer.

Still, I'm open to discussion on it - Events generally should be reliably processed before a full round-trip happens, and it sucks to fix major bugs across releases just over worry of a hopefully-very-rare race breaking forwards, but not backwards, compat.

@TheBlueMattTheBlueMatt added this to the 0.0.115 milestone Mar 17, 2023
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 3 times, most recently from 2aae7c8 to 91707fbCompareMarch 17, 2023 07:04
@codecov-commenter

codecov-commenter commented Mar 17, 2023

Copy link
Copy Markdown

Codecov Report

Patch coverage: 69.12% and project coverage change: +0.56 🎉

Comparison is base (88c63e9) 91.57% compared to head (880d88e) 92.14%.

❗ Current head 880d88e differs from pull request most recent head 9c36735. Consider uploading reports for the commit 9c36735 to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@ Coverage Diff @@## main #2111 +/- ##
==========================================
+ Coverage 91.57% 92.14% +0.56% 
==========================================
Files 104 105 +1 Lines 51930 61222 +9292 Branches 51930 61222 +9292 ==========================================
+ Hits 47556 56410 +8854 - Misses 4374 4812 +438 
Impacted FilesCoverage Δ
lightning/src/ln/channelmanager.rs90.47% <50.00%> (+1.66%)⬆️
lightning/src/ln/channel.rs92.64% <92.70%> (+2.62%)⬆️
lightning/src/ln/chanmon_update_fail_tests.rs98.61% <100.00%> (ø)
lightning/src/ln/functional_tests.rs98.25% <100.00%> (ø)
lightning/src/ln/outbound_payment.rs89.56% <100.00%> (-0.08%)⬇️

... and 21 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 91707fb to c595331CompareMarch 17, 2023 21:09
@wpaulino
wpaulino self-requested a review March 21, 2023 20:02
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 3 times, most recently from 57bebe7 to 9852b84CompareMarch 28, 2023 22:01
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
log_bytes!(self.channel_id));
self.pending_monitor_updates.push(monitor_update);
return Ok(self.pending_monitor_updates.last().unwrap());
let fly_monitor = self.pending_monitor_updates.iter().all(|upd| upd.flown);

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.

Do you see any benefit in tracking the flown/dispatched pending updates in a separate Vec?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Uhhhhhhhhhh. Maybe? Not sure yet, honestly. It would clean up a bit of code, and make some other code a bit more complicated, kinda a wash, but I'm not 100% sure where this is gonna end up , I think this is all of the holding logic we're gonna need for it, but if we find some other bug in there in the future we could end up with more going on in the struct and a two-struct approach will be confusing.

Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channel.rs
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 9852b84 to 2ba5289CompareMarch 30, 2023 23:53

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

Feel free to squash the existing fixups

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch 2 times, most recently from ae76ed0 to 08ae599CompareApril 5, 2023 18:48
@wpaulino

Copy link
Copy Markdown
Contributor

Feel free to squash, will give it a final pass after a second reviewer.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed without further changes.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Fixed a silent rebase conflict as well as a bug that the further upstream lockorder detection surfaced.

@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 7014813 to a626549CompareApril 13, 2023 21:03
@TheBlueMattTheBlueMatt added this to the 0.0.116 milestone Apr 17, 2023
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Actually, gonna slip this cause it should really go in the same release as its followup, which isn't gonna make 115.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 6f1263d to 87bcf91CompareApril 17, 2023 20:55
@wpaulino
wpaulino self-requested a review April 18, 2023 17:29
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 87bcf91 to 51c3b37CompareApril 28, 2023 04:55
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Rebased.

@wpaulino

Copy link
Copy Markdown
Contributor

Will do another full pass after squash

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

Looks good

Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
$chan.get_latest_monitor_update_id() == $update_id
{
$chan.complete_one_mon_update($update_id);
if $chan.no_monitor_updates_pending() {

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.

I think we can use this check in channel_monitor_updated too (maybe redundant with @wpaulino's comment above). Or move this check into the handle_monitor_update_completion macro

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yea, I want to clean this logic up, mind if I do it in a followup, though? I have a handful of changes I'm working on to the monitor completion logic here that I can incorporate this into.

In the coming commits, we need to delay `ChannelMonitorUpdate`s
until future actions (specifically `Event` handling). However,
because we should only notify users once of a given
`ChannelMonitorUpdate` and they must be provided in-order, we need
to track which ones have or have not been given to users and, once
updating resumes, fly the ones that haven't already made it to
users.
To do this we simply add a `bool` in the `ChannelMonitorUpdate` set
stored in the `Channel` which indicates if an update flew and
decline to provide new updates back to the `ChannelManager` if any
updates have their flown bit unset.
Further, because we'll now by releasing `ChannelMonitorUpdate`s
which were already stored in the pending list, we now need to
support getting a `Completed` result for a monitor which isn't the
only pending monitor (or even out of order), thus we also rewrite
the way monitor updates are marked completed.
This will allow us to block `ChannelMonitorUpdate`s on `Event`
processing in the next commit.
Note that this gets dangerously close to breaking forwards
compatibility - if we have an `Event` with an
`EventCompletionAction` tied to it, we persist a new, even, TLV in
the `ChannelManager`. Hopefully this should be uncommon, as it
implies an `Event` was delayed until after a full round-trip to a
peer.
This adds handling of the new `EventCompletionAction`s after
`Event`s are handled, letting `ChannelMonitorUpdate`s which were
blocked fly after a relevant `Event`.
The previous commits set up the ability for us to hold
`ChannelMonitorUpdate`s which are pending until we're ready to pass
them to users and have them be applied. However, if the
`ChannelManager` is persisted while we're waiting to give the user
a `ChannelMonitorUpdate` we'll be confused on restart - seeing our
latest `ChannelMonitor` state as stale compared to our
`ChannelManager` - a critical error.
Luckily the solution is trivial, we simply need to store the
pending `ChannelMonitorUpdate` state and load it with the
`ChannelManager` data, allowing stale monitors on load as long as
we have the missing pending updates between where we are and the
latest `ChannelMonitor` state.
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 51c3b37 to 9dfe42cCompareMay 2, 2023 18:00
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed without further changes.

@valentinewallace

Copy link
Copy Markdown
Contributor

Looks good after @wpaulino takes another look!

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs
Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2023-03-sent-persist-order-prep branch from 880d88e to 9c36735CompareMay 4, 2023 19:29
wpaulino
wpaulino previously approved these changes May 4, 2023
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

oops sorry that commit was buggy, sec

valentinewallace
valentinewallace previously approved these changes May 4, 2023
@valentinewallace
valentinewallace dismissed their stale reviewMay 4, 2023 19:50

commit was buggy

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Actually, just gonna drop the last/new commit, its...hard, so we need to (a) handle_post_event_actions after we pending_events.drain(..num_events) as we only actually handle the post-event action if the event has been removed and (b) need to unset pending_events_processor and check if there are any remaining events both inside the same lock. Thus its kinda hard to change it around all that much without breaking it.

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

The tests on #2112 failed with that commit, specifically, like all the tests.

@TheBlueMatt
TheBlueMatt merged commit e94647c into lightningdevkit:mainMay 4, 2023
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.

4 participants

@TheBlueMatt@codecov-commenter@wpaulino@valentinewallace