Skip to content
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

[r2r] use task manager to enable lightning #1513

Merged
merged 8 commits into from
Nov 9, 2022
Merged

[r2r] use task manager to enable lightning #1513

merged 8 commits into from
Nov 9, 2022

Conversation

shamardy
Copy link
Collaborator

@shamardy shamardy commented Oct 27, 2022

This PR is needed to write the next WebDEX-lightning integration step (How to enable lightning) https://github.com/KomodoPlatform/air_dex/issues/644

  • Used task manager for L2 coins activation.
  • Activate lightning using task manager.
  • Moved BackgroundProcessor back into LightningCoin struct since it now gets dropped when calling stop RPC as a result of this PR [r2r] Stop spawned futures #1490 (Network graph, channel manager and scorer now get persisted on stop).
  • Moved start_lightning function to coins_activation crate to be able to update in progress status.

@shamardy shamardy changed the title [wip] use task manager to enable lightning [r2r] use task manager to enable lightning Nov 1, 2022
sergeyboyko0791
sergeyboyko0791 previously approved these changes Nov 3, 2022
Copy link

@sergeyboyko0791 sergeyboyko0791 left a comment

Choose a reason for hiding this comment

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

Awesome! I have nothing critical to add

@@ -189,6 +190,7 @@ pub async fn init_peer_manager(
// If the user wishes to preserve privacy, addresses should likely contain only Tor Onion addresses.
let listening_addr = myipaddr(ctx).await.map_to_mm(EnableLightningError::InvalidAddress)?;
// If the listening port is used start_lightning should return an error early
// Todo: when deactivating coin the address should be unbinded, listener seems to not be dropped for some reason, should also add a unit test for this after fixing it

Choose a reason for hiding this comment

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

If I'm not mistaken, it's not unbinded due to the following conditions:

  1. disable_coin doesn't stop the spawned futures Deactivate tokens when platform coin is deactivated #1493
  2. LightningCoin is removed from the CoinsContext::coins collection, but the inner fields like LightningCoin::platform, LightningCoin::peer_manager etc are shared pointers that seem to be hold in spawned futures, so they never drop.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

LightningCoin::peer_manager etc are shared pointers that seem to be hold in spawned futures, so they never drop.

Thanks for the detailed explanation, for LightningCoin::peer_manager both connect_outbound and setup_inbound from LDK's lightning_net_tokio crate spawn futures that hold the peer manager's Arc https://github.com/KomodoPlatform/atomicDEX-API/blob/fe2be27f0c96ddf5d366f5e915ea5347d1e48e43/mm2src/coins/lightning/ln_p2p.rs#L52 https://github.com/KomodoPlatform/atomicDEX-API/blob/fe2be27f0c96ddf5d366f5e915ea5347d1e48e43/mm2src/coins/lightning/ln_p2p.rs#L174
Do you think passing a weak reference to PeerManager to these functions instead can solve the problem? this of course will require a PR to be opened and accepted in rust-lightning but I don't think they will object to that. The alternative is to import lightning_net_tokio crate to mm2 and do these fixes inside mm2.

Choose a reason for hiding this comment

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

If I remember correctly, you said DM these futures are aborted, and PeerManager and other shared data are released on stop RPC call. This means that if we abort all futures correctly, you can pass Arc pointer.
But since now we don't abort the coin related futures on disable_coin, the TcpListener is not dropped.

But anyway I think it's worth to pass Weak pointer everywhere to avoid possible undesirable cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If I remember correctly, you said DM these futures are aborted, and PeerManager and other shared data are released on stop RPC call.

That is correct, I was able to re-bind to the same address:port after calling stop

lightning = "0.0.110"
lightning-background-processor = "0.0.110"
lightning-invoice = { version = "0.18.0", features = ["serde"] }

Choose a reason for hiding this comment

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

One line break :)

@artemii235
Copy link
Member

@shamardy Could you please solve git conflicts and ping Sergey for the next review iteration then?

Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

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

🔥

@shamardy
Copy link
Collaborator Author

shamardy commented Nov 9, 2022

@sergeyboyko0791 this is ready for next review iteration/Re-approval :)

@artemii235 artemii235 merged commit a7b8e12 into dev Nov 9, 2022
@artemii235 artemii235 deleted the enable_ln_task branch November 9, 2022 11:58
@shamardy shamardy mentioned this pull request Feb 17, 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.

3 participants