forked from jl777/SuperNET
-
Notifications
You must be signed in to change notification settings - Fork 118
feat(channels): wasm, coin balance and socket impl #1978
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
Changes from 40 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
9f74dcf
implement stremaing infrastructure
onur-ozkan 8e688c1
create basic client for SSE testing
onur-ozkan 6c1998d
update examples README
onur-ozkan 5ee822b
implement client-side event filtering
onur-ozkan b8e997a
add explanatory comments in sse module
onur-ozkan 04df80c
update SSE client example documentation
onur-ozkan fae50e4
format wasm html example
onur-ozkan b8eca5e
stream network events
onur-ozkan be685af
manage event streaming dynamically
onur-ozkan e6ba1c3
leave perf improvement TODO note
onur-ozkan c58a7d5
avoid serializing events on http side
onur-ozkan 79245d1
fix wasm error
onur-ozkan 99f87c8
update SSE data type
onur-ozkan 90996c5
implement `EventBehaviour`
onur-ozkan 8445f35
save configuration in mm2 context
onur-ozkan 7d727fe
update doc-comment of `stream_channel_controller` in `MmCtx`
onur-ozkan 2e942af
optimize `mm2src/mm2_event_stream/src/lib.rs`
onur-ozkan c761a39
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into pu…
onur-ozkan 6cd2c2c
cross-compatible tests for streaming channels
onur-ozkan a7a2064
enable wasm tests to be executed with wasm-pack
onur-ozkan f6056ea
implement WASM support for event streaming
onur-ozkan 1e476d2
[WIP] concurrent balance loop controller
onur-ozkan 945fece
add explanation comment lines
onur-ozkan 2d68ca9
create `CoinBalanceEvent`
onur-ozkan 61668ac
impl `handle_balance_stream` for `MmCoin` trait
onur-ozkan 619bac8
update interval rule for coin balance event
onur-ozkan eaac0c1
save dev state
onur-ozkan 212f4dd
save dev state
onur-ozkan 188dade
WIP parse denoms from ws events
onur-ozkan f95568c
impl address handling and TLS support
onur-ozkan 041aebb
denom to ticker conversion
onur-ozkan 0f712e3
broadcast events when balance is changed
onur-ozkan 633987a
create `http_uri_to_ws_address`
onur-ozkan eff5c9a
handle socket related panics/connection failures
onur-ozkan 8a0577c
use komodo fork of websocket lib for WASM support
onur-ozkan 8f478a4
get full compatibility on native + WASM sockets
onur-ozkan a2d6295
enable rustls feature
onur-ozkan e626950
broadcast network events only when data changes
onur-ozkan 3758cdc
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into sh…
onur-ozkan 6f668e2
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into sh…
onur-ozkan c3afd29
refactor balance stream impl design
onur-ozkan 5464064
ref `active_ticker_and_decimals_from_denom` to be O(1)
onur-ozkan 3c50310
replace plain json with `jsonrpc_core::MethodCall`
onur-ozkan 35e58e4
explain how to examine incoming data from tendermint socket
onur-ozkan 0e41ae7
update helper logs for Tendermint COIN_BALANCE event
onur-ozkan 7e19003
fix minor notes
onur-ozkan 799e4e8
upgrade from weak pointer for Tendermint to Mm context
onur-ozkan dbb2b22
handle event initializations
onur-ozkan d7bd0d7
remove `NotInitialized` variant in `EventInitStatus`
onur-ozkan 7ccf765
return EventInitStatus::Failed if tx isn't present
onur-ozkan 28048c8
Merge remote-tracking branch 'origin/dev' into shared-event-channels-…
shamardy b3d774c
update adex-cli cargo.lock
shamardy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| use crate::{CoinsContext, MmCoin, MmCoinEnum}; | ||
| use async_trait::async_trait; | ||
| use common::{executor::{SpawnFuture, Timer}, | ||
| log::info}; | ||
| use mm2_core::mm_ctx::MmArc; | ||
| use mm2_event_stream::{behaviour::EventBehaviour, EventStreamConfiguration}; | ||
| use std::sync::atomic::Ordering; | ||
|
|
||
| /// Event tag for broadcasting balance events | ||
| pub(crate) const COIN_BALANCE_EVENT_TAG: &str = "COIN_BALANCE"; | ||
|
|
||
| pub struct CoinBalanceEvent { | ||
| ctx: MmArc, | ||
| } | ||
|
|
||
| impl CoinBalanceEvent { | ||
| pub fn new(ctx: MmArc) -> Self { Self { ctx } } | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl EventBehaviour for CoinBalanceEvent { | ||
| const EVENT_NAME: &'static str = COIN_BALANCE_EVENT_TAG; | ||
|
|
||
| async fn handle(self, _interval: f64) { | ||
| let cctx = CoinsContext::from_ctx(&self.ctx).expect("Unexpected internal panic."); | ||
|
|
||
| // Events that are already fired | ||
| let mut event_pool: Vec<String> = vec![]; | ||
|
|
||
| loop { | ||
| let coins_mutex = cctx.coins.lock().await; | ||
|
onur-ozkan marked this conversation as resolved.
Outdated
|
||
|
|
||
| let coins: Vec<MmCoinEnum> = coins_mutex | ||
| .values() | ||
| .filter_map(|coin| { | ||
| // We loop this over and over, so it's not necessary to sequentially load the atomics all over | ||
| // the threads, since the cost of it is way too higher than the `AtomicOrdering::Relaxed` | ||
| if coin.is_available.load(Ordering::Relaxed) { | ||
| Some(coin.inner.clone()) | ||
| } else { | ||
| None | ||
| } | ||
| }) | ||
| .collect(); | ||
|
onur-ozkan marked this conversation as resolved.
Outdated
|
||
|
|
||
| // Similar to above, we don't need to held the lock(which will block all other processes that depends | ||
| // on this lock(like coin activation)) since we loop this over continuously. | ||
| drop(coins_mutex); | ||
|
|
||
| // Handle balance streaming concurrently for each coin | ||
| for coin in coins { | ||
| let ticker = coin.ticker().to_owned(); | ||
|
|
||
| if event_pool.contains(&ticker) { | ||
| continue; | ||
| } | ||
|
|
||
| match coin { | ||
| MmCoinEnum::UtxoCoin(inner) => { | ||
| self.ctx.spawner().spawn(inner.handle_balance_stream(self.ctx.clone())) | ||
| }, | ||
| MmCoinEnum::QtumCoin(inner) => { | ||
| self.ctx.spawner().spawn(inner.handle_balance_stream(self.ctx.clone())) | ||
| }, | ||
| MmCoinEnum::Qrc20Coin(inner) => { | ||
| self.ctx.spawner().spawn(inner.handle_balance_stream(self.ctx.clone())) | ||
| }, | ||
| MmCoinEnum::EthCoin(inner) => { | ||
| self.ctx.spawner().spawn(inner.handle_balance_stream(self.ctx.clone())) | ||
| }, | ||
| MmCoinEnum::ZCoin(inner) => self.ctx.spawner().spawn(inner.handle_balance_stream(self.ctx.clone())), | ||
| MmCoinEnum::Bch(inner) => self.ctx.spawner().spawn(inner.handle_balance_stream(self.ctx.clone())), | ||
| MmCoinEnum::SlpToken(inner) => { | ||
| self.ctx.spawner().spawn(inner.handle_balance_stream(self.ctx.clone())) | ||
| }, | ||
| MmCoinEnum::Tendermint(inner) => { | ||
| self.ctx.spawner().spawn(inner.handle_balance_stream(self.ctx.clone())) | ||
|
onur-ozkan marked this conversation as resolved.
Outdated
|
||
| }, | ||
| MmCoinEnum::TendermintToken(inner) => { | ||
| self.ctx.spawner().spawn(inner.handle_balance_stream(self.ctx.clone())) | ||
| }, | ||
| #[cfg(not(target_arch = "wasm32"))] | ||
| MmCoinEnum::LightningCoin(inner) => { | ||
| self.ctx.spawner().spawn(inner.handle_balance_stream(self.ctx.clone())) | ||
| }, | ||
| MmCoinEnum::Test(inner) => self.ctx.spawner().spawn(inner.handle_balance_stream(self.ctx.clone())), | ||
| #[cfg(all( | ||
| feature = "enable-solana", | ||
| not(target_os = "ios"), | ||
| not(target_os = "android"), | ||
| not(target_arch = "wasm32") | ||
| ))] | ||
| MmCoinEnum::SolanaCoin(inner) => { | ||
| self.ctx.spawner().spawn(inner.handle_balance_stream(self.ctx.clone())) | ||
| }, | ||
| #[cfg(all( | ||
| feature = "enable-solana", | ||
| not(target_os = "ios"), | ||
| not(target_os = "android"), | ||
| not(target_arch = "wasm32") | ||
| ))] | ||
| MmCoinEnum::SplToken(inner) => { | ||
| self.ctx.spawner().spawn(inner.handle_balance_stream(self.ctx.clone())) | ||
| }, | ||
| } | ||
|
|
||
| event_pool.push(ticker); | ||
|
onur-ozkan marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| Timer::sleep(5.).await; | ||
|
onur-ozkan marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
|
||
| fn spawn_if_active(self, config: &EventStreamConfiguration) { | ||
| if let Some(event) = config.get_event(Self::EVENT_NAME) { | ||
| info!( | ||
| "{} event is activated. `stream_interval_seconds`({}) has no effect for this event.", | ||
| Self::EVENT_NAME, | ||
| event.stream_interval_seconds | ||
| ); | ||
| self.ctx.spawner().spawn(self.handle(event.stream_interval_seconds)); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.