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] Stop spawned futures #1490

Merged
merged 32 commits into from
Oct 17, 2022
Merged

[r2r] Stop spawned futures #1490

merged 32 commits into from
Oct 17, 2022

Conversation

sergeyboyko0791
Copy link

@sergeyboyko0791 sergeyboyko0791 commented Oct 3, 2022

  • Spawn Transaction History V1 as a future, not in a separate thread.
  • Add AbortableSystem with the ability to create Future subsystems
  • Use MmFutSpawner within mm2_libp2p::AtomicDexBehaviour
  • Spawn kick-started swaps as futures, not in separate threads.

* Store abort handles by associated `FutureId` not to keep them forever
* Remove `wio::Timeout`
* Add `FutureSpawner` trait to `executor`
* Kick-start swaps by spawning them as futures, not as threads
* Remove `common::executor::spawn_boxed`
* Delete `common/executor.rs` file
* Leave Spawn traits in `spawner.rs` only
* Add `AbortableSpawnerWeak`
* Rename `CoinFutureSpawner` to `CoinFutSpawner`
* Rename `MmSpawner` to `MmFutSpawner`
* `spawn_gossipsub` takes an `SwarmRuntime` instance to spawn futures
* Add `SwapWatcherLock`
* Remove `SwapsContext::shutdown_rx`
* Remove `spawn_abortable_with_settings`
* Allow to create an abortable subsystem that will be aborted if the linked supersystem is aborted.
@sergeyboyko0791 sergeyboyko0791 changed the title [wip] Stop spawned futures [r2r] Stop spawned futures Oct 7, 2022
@sergeyboyko0791
Copy link
Author

This PR affects the following parts:

@sergeyboyko0791 sergeyboyko0791 self-assigned this Oct 7, 2022
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.

Thanks for the PR! That's the first and very brief review iteration. I think I will have quite a few questions on the next one :)

mm2src/common/executor/native_executor.rs Outdated Show resolved Hide resolved
# Conflicts:
#	mm2src/coins/eth.rs
#	mm2src/coins/lightning.rs
#	mm2src/coins/qrc20.rs
#	mm2src/coins/solana/spl.rs
#	mm2src/coins/utxo/slp.rs
#	mm2src/coins/z_coin.rs
#	mm2src/mm2_main/src/mm2_tests.rs
#	mm2src/mm2_test_helpers/src/for_tests.rs
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.

Second review, quite brief again.

mm2src/coins/utxo/rpc_clients.rs Outdated Show resolved Hide resolved
mm2src/mm2_core/src/mm_ctx.rs Show resolved Hide resolved
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.

A couple of questions.

mm2src/mm2_net/src/wasm_ws.rs Outdated Show resolved Hide resolved
mm2src/common/executor/abortable_system/abortable_queue.rs Outdated Show resolved Hide resolved
@sergeyboyko0791 sergeyboyko0791 changed the title [r2r] Stop spawned futures [wip] Stop spawned futures Oct 12, 2022
* Add `AbortableQueue` field into `ElectrumClientImpl`, `ElectrumConnection`
* Pass a spawner to `ws_transport`
* Remove `wasm_ws::ClosingState` by replacing it with `ClosedState`
Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

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

Great Work! Just reviewed the lightning related parts for now, will review the rest of the PR in more details in the next iteration.

mm2src/coins/lightning/ln_events.rs Outdated Show resolved Hide resolved
* Increase `WASM_BINDGEN_TEST_TIMEOUT` to 180 seconds
* Avoid unnecessary `spawn` usage
* Avoid using `allow(dead_code)`
* Add `spawn_local_abortable` to `wasm_executor`
* Avoid unnecessary `spawn_local` usage at `webusb_driver`
@sergeyboyko0791 sergeyboyko0791 changed the title [wip] Stop spawned futures [r2r] Stop spawned futures Oct 13, 2022
@sergeyboyko0791
Copy link
Author

@artemii235 @shamardy PR is ready for the next review iteration

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.

Next iteration.
@sergeyboyko0791 Also a question: should we maybe call spawner().abort_all() in the disable_coin RPC?

mm2src/mm2_main/src/rpc.rs Show resolved Hide resolved
mm2src/coins/lightning/ln_utils.rs Show resolved Hide resolved
@sergeyboyko0791
Copy link
Author

sergeyboyko0791 commented Oct 13, 2022

This definitely makes sense as some futures may hold a shared pointer to the coin. But I think we first need to fix #1493
For example, if we abort BTC's related futures, Lightning won't work correctly, but its maker/taker orders won't be cancelled.

Also a question: should we maybe call spawner().abort_all() in the disable_coin RPC?

I can leave a comment in this issue

cc: @artemii235

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.

Thanks for the great work!

Copy link

@caglaryucekaya caglaryucekaya left a comment

Choose a reason for hiding this comment

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

Great work!

/// It's used to spawn futures that can be aborted immediately or after a timeout
/// on the [`MmArc::stop`] function call.
pub abortable_system: AbortableQueue,
/// The abortable system is pinned to the `MmCtx` context.

Choose a reason for hiding this comment

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

Duplicate comment

Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

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

Thanks for this great enhancement!

// Notify shutdown listeners.
self.graceful_shutdown_registry.abort_all();
// Abort spawned futures.
self.abortable_system.abort_all();

#[cfg(not(target_arch = "wasm32"))]
self.background_processors.lock().unwrap().drain();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess background processors can be moved back to LightningCoin as before since they will be dropped now with the coins on calling stop, I added this to the lightning integration checklist #1045 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stop and release spawned futures immediately on stop RPC call
4 participants