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

feat(channels): wasm, coin balance and socket impl #1978

Merged
merged 52 commits into from
Oct 27, 2023

Conversation

onur-ozkan
Copy link
Member

@onur-ozkan onur-ozkan commented Sep 29, 2023

New Event: COIN_BALANCE:

It's now implemented for Tendermint Protocol(will cause panics with todo for any other coins).

The way it works:

1- Subscribe to the account address using websocket
2- On any message(this means our address either sent tx or recieved tx), get the current balance
3- If the balance is changed(different than the previously broadcasted event) then broadcast it to mm2 clients.

Sample configuration:

"event_stream_configuration": {
    "access_control_allow_origin": "*",
    "active_events": {
      "NETWORK": { "stream_interval_seconds": 1.5 },
      "COIN_BALANCE": {} # stream_interval_seconds is ignored for the balance events, it's not required to define it.
    }
}

Native:

Same as #1945, for triggering COIN_BALANCE event, enable any tendermint based coin and send/recieve some funds on that address.

WASM:

Event streaming on WASM can be tested easily with https://github.com/KomodoPlatform/react-komodefi-wasm.

  • Build:
    Build mm2 with wasm-pack build --release mm2src/mm2_bin_lib --target web --out-dir ../../target/target-wasm-release

  • soft-linking(or file/dir replacement directly):

    atomicDEX-API/target/target-wasm-release/mm2lib.js to react-komodefi-wasm/src/js/mm2.js

    atomicDEX-API/target/target-wasm-release/snippets to react-komodefi-wasm/src/js/snippets

    atomicDEX-API/target/target-wasm-release/mm2lib_bg.wasm to react-komodefi-wasm/public/mm2_bg.wasm

  • Add ATOM-TEST coin:

    Append the following json value to the coins file:

      {
      "coin": "ATOM-TEST",
      "avg_blocktime": 5,
      "protocol": {
        "type": "TENDERMINT",
        "protocol_data": {
          "decimals": 6,
          "denom": "uatom",
          "account_prefix": "cosmos",
          "chain_id": "theta-testnet-001"
        }
      },
      "derivation_path": "m/44'/118'"
    }
  • Worker file:

    Create react-komodefi-wasm/worker.js file with the following content:

    self.addEventListener('message', function(event) {
      console.log(event.data);
    });
  • Test the network and balance events:

    Network events should start being logged on console right away when mm2 is started, for the balance events, you have to enable tendermint based coins, an example ATOM-TEST which we added to coins file. For that, execute the following RPC:

    {
      "userpass": "testpsw",
      "method":"enable_tendermint_with_assets",
      "mmrpc":"2.0",
      "params": {
        "ticker": "ATOM-TEST",
        "tokens_params": [],
        "rpc_urls": [
      	  "https://rpc.sentry-02.theta-testnet.polypore.xyz"
        ],
        "tx_history": false
      },
      "id": 0
    }

    After the activation, when your address gets/sends TX, you should be able to see COIN_BALANCE event on the console logs.

KomodoPlatform/tokio-tungstenite-wasm

There is no socket library that supports Native + WASM platforms with async/await & Send+Sync(without those supports, handling events(specially COIN_BALANCE) will cause i/o blocking and resource-intensive situations on the runtime). I had to fork a few of the existing ones and do some changes. This fork should be super easy to maintain for us, as it's just a wrapper around tokio-tungstenite and web-sys. Most of the effort on this fork will be bumping the dependencies when needed.

Signed-off-by: ozkanonur <work@onurozkan.dev>
Signed-off-by: ozkanonur <work@onurozkan.dev>
Signed-off-by: ozkanonur <work@onurozkan.dev>
Signed-off-by: ozkanonur <work@onurozkan.dev>
Signed-off-by: ozkanonur <work@onurozkan.dev>
Signed-off-by: ozkanonur <work@onurozkan.dev>
Signed-off-by: ozkanonur <work@onurozkan.dev>
Signed-off-by: ozkanonur <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Signed-off-by: onur-ozkan <work@onurozkan.dev>
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.

Thank you for the fixes! Next review iteration!

@shamardy
Copy link
Collaborator

shamardy commented Oct 9, 2023

For spawning the transaction history futures, this problem still remains. It could be fixed in a separate PR.

Opened an issue for the above #1986

Signed-off-by: onur-ozkan <work@onurozkan.dev>
shamardy
shamardy previously approved these changes Oct 10, 2023
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.

🔥

@shamardy
Copy link
Collaborator

@KomodoPlatform/qa how to test wasm event streaming and COIN_BALANCE event for tendermint can be found here #1978 (comment)

smk762
smk762 previously approved these changes Oct 10, 2023
Copy link

@smk762 smk762 left a comment

Choose a reason for hiding this comment

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

Working here, thanks.
image
image

@shamardy shamardy dismissed stale reviews from smk762 and themself via b3d774c October 27, 2023 14:07
@shamardy shamardy merged commit 1224c03 into dev Oct 27, 2023
30 checks passed
@shamardy shamardy deleted the shared-event-channels-wasm branch October 27, 2023 14:56
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.

5 participants