Skip to content

Persist entire monitor if there is an error while applying monitor_update #2621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 29, 2023

Conversation

G8XSU
Copy link
Contributor

@G8XSU G8XSU commented Sep 29, 2023

Commit 1: Correctly mark chain_sync updates in test_utils

We were incorrectly marking updates as chain_sync
or not in test_utils based on whether monitor_update
is None or not. Instead, use UpdateOrigin to determine it.

Commit 2: Persist full monitor if there is an error while applying monitor_update

Motivation: When there is an error while applying monitor_update to a
channel_monitor, we don't want to persist a 'monitor_update' which
results in a failure to apply later while reading 'channel_monitor' with
updates from storage. Instead, we should persist the entire 'channel_monitor'
here, otherwise we might be stuck in unrecoverable state after restart.

// TODO: Write test-cases for this change.

@codecov-commenter
Copy link

codecov-commenter commented Sep 29, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (db41b87) 88.96% compared to head (976acd8) 89.00%.
Report is 34 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2621      +/-   ##
==========================================
+ Coverage   88.96%   89.00%   +0.03%     
==========================================
  Files         112      112              
  Lines       86337    86642     +305     
  Branches    86337    86642     +305     
==========================================
+ Hits        76812    77113     +301     
- Misses       7289     7290       +1     
- Partials     2236     2239       +3     
Files Coverage Δ
lightning/src/util/test_utils.rs 77.09% <100.00%> (+0.12%) ⬆️
lightning/src/chain/chainmonitor.rs 89.27% <75.00%> (+0.02%) ⬆️

... and 19 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TheBlueMatt TheBlueMatt added this to the 0.0.117 milestone Sep 29, 2023
@G8XSU G8XSU changed the title Persist full monitor if there is an error while applying monitor_update Persist entire monitor if there is an error while applying monitor_update Sep 29, 2023
@G8XSU
Copy link
Contributor Author

G8XSU commented Sep 29, 2023

Marking this review ready, will squash on request (and add PR description to commit msgs.)

@G8XSU G8XSU marked this pull request as ready for review September 29, 2023 19:19
@TheBlueMatt
Copy link
Collaborator

Yes, feel free to squash IMO. This patch has very little risk, so I think we shouldn't worry too much about landing it. Please also update the documentation on Persist::update_persisted_channel to note something about "During blockchain synchronization operations, and in some rare cases, ..." rather than just "During blockchain synchronization operations".

@G8XSU
Copy link
Contributor Author

G8XSU commented Sep 29, 2023

Will be squashing.

@G8XSU G8XSU force-pushed the dont-persist-erroneous-update branch 5 times, most recently from 0c9274b to 8119244 Compare September 29, 2023 21:13
@G8XSU G8XSU requested a review from TheBlueMatt September 29, 2023 21:14
@TheBlueMatt
Copy link
Collaborator

Please swap the test_utils changes for the first so that the first commit doesn't break tests.

@TheBlueMatt
Copy link
Collaborator

Otherwise LGTM.

@G8XSU G8XSU force-pushed the dont-persist-erroneous-update branch from 8119244 to 0f94992 Compare September 29, 2023 21:25
wpaulino
wpaulino previously approved these changes Sep 29, 2023
@wpaulino
Copy link
Contributor

CI is not happy:

error: unresolved link to `ChannelMonitorUpdate::update_id`
  --> lightning/src/chain/chainmonitor.rs:56:56
   |
56 |         /// implementation). This corresponds to an actual [`ChannelMonitorUpdate::update_id`] field
   |                                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `ChannelMonitorUpdate` in scope
   |

error: unresolved link to `ChannelMonitor::get_latest_update_id`
  --> lightning/src/chain/chainmonitor.rs:57:13
   |
57 |         /// and [`ChannelMonitor::get_latest_update_id`].
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `ChannelMonitor` in scope

error: unresolved link to `ChainMonitor`
  --> lightning/src/chain/chainmonitor.rs:60:20
   |
60 |         /// generating [`ChainMonitor`] and does *not* correspond to any on-disk IDs.
   |                          ^^^^^^^^^^^^ no item named `ChainMonitor` in scope
   |

// still be changed. Therefore, we should persist the updated monitor despite the error.
// We don't want to persist a `monitor_update` which results in a failure to apply later
// while reading `channel_monitor` with updates from storage. Instead, we should persist
// the entire `channel_monitor` here.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can make this "Instead, we should persist the entire channel_monitor here, otherwise we will fail to initialize this monitor during restart."

But wasn't sure if it adds more confusion.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The previous sentence makes that clear imo.

@G8XSU G8XSU force-pushed the dont-persist-erroneous-update branch 2 times, most recently from d7b50bf to bfcb6ff Compare September 29, 2023 22:24
@G8XSU G8XSU requested a review from wpaulino September 29, 2023 22:34
We were incorrectly marking updates as chain_sync
or not in test_utils based on whether monitor_update
is None or not. Instead, use UpdateOrigin to determine it.
Motivation: When there is an error while applying monitor_update to a
channel_monitor,  we don't want to persist a 'monitor_update' which
results in a failure to apply later while reading 'channel_monitor' with
updates from storage. Instead, we should persist the entire 'channel_monitor'
here.
@G8XSU G8XSU force-pushed the dont-persist-erroneous-update branch from bfcb6ff to 976acd8 Compare September 29, 2023 23:27
@G8XSU G8XSU requested a review from wpaulino September 29, 2023 23:27
@TheBlueMatt TheBlueMatt merged commit f534ce2 into lightningdevkit:main Sep 29, 2023
@valentinewallace valentinewallace mentioned this pull request Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants