Skip to content

Cleanup lock orders #1773

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

Conversation

ViktorTigerstrom
Copy link
Contributor

This is based on #1772, so it can be marked as blocked on dependent pr for now. Will also leave it as draft until #1772 is merged.

The first commit moves the lock_order of pending_inbound_payments as well as pending_outbound_payments to before the channel_state lock, which is to be removed. This will simplify #1507.

The second commit pending_background_events into a separate lock order branch.

@@ -681,23 +674,25 @@ pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, M, T, F, L> = ChannelManage
// |
// |__`forward_htlcs`
// |
// |__`channel_state`
// |__`pending_background_events`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd just like to ask if process_background_events through timer_tick_occurred can be called by a thread while another thread has other locks acquired? If so, I'll drop the second commit that moves this.

Copy link
Contributor Author

@ViktorTigerstrom ViktorTigerstrom Nov 2, 2022

Choose a reason for hiding this comment

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

I've realized in hindsight that this question is rather stupid, as "background threads" acquiring pending_background_events is fine even if other threads are holding other locks at the same time. We just need to ensure that every single thread acquires the locks according to the lock order in that specific thread only to avoid deadlocks.

@codecov-commenter
Copy link

codecov-commenter commented Oct 15, 2022

Codecov Report

Base: 90.79% // Head: 90.76% // Decreases project coverage by -0.03% ⚠️

Coverage data is based on head (a9f3e45) compared to base (6772609).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1773      +/-   ##
==========================================
- Coverage   90.79%   90.76%   -0.04%     
==========================================
  Files          87       87              
  Lines       46969    46979      +10     
  Branches    46969    46979      +10     
==========================================
- Hits        42646    42640       -6     
- Misses       4323     4339      +16     
Impacted Files Coverage Δ
lightning/src/ln/channelmanager.rs 85.17% <100.00%> (+0.01%) ⬆️
lightning/src/chain/onchaintx.rs 94.71% <0.00%> (-0.69%) ⬇️
lightning-net-tokio/src/lib.rs 76.73% <0.00%> (-0.31%) ⬇️
lightning/src/util/events.rs 38.13% <0.00%> (-0.27%) ⬇️
lightning/src/ln/peer_channel_encryptor.rs 93.38% <0.00%> (-0.25%) ⬇️
lightning/src/ln/functional_tests.rs 96.88% <0.00%> (-0.12%) ⬇️
lightning/src/chain/channelmonitor.rs 91.16% <0.00%> (-0.06%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

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

As the `channel_state` lock will be removed, this PR prepare for that by
flipping the lock order for `pending_inbound_payments` and
`pending_outbound_payments` locks to before the `channel_state` lock.
@ViktorTigerstrom
Copy link
Contributor Author

Closing this due to most of this already having been addressed through #1772.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants