KomodoPlatform / komodo-defi-framework

This is the official Komodo DeFi Framework repository
https://komodoplatform.com/en/docs/komodo-defi-framework/
97 stars 88 forks source link

Share EVM Web3 Instances for Platform Coin and Tokens to Reduce Open Websocket Connections #2071

Open shamardy opened 4 months ago

shamardy commented 4 months ago

Needed after this PR https://github.com/KomodoPlatform/komodo-defi-framework/pull/2058 is merged ref. https://github.com/KomodoPlatform/komodo-defi-framework/pull/2058#discussion_r1499053370

mariocynicys commented 1 week ago

I don't think we keep different open connections here.

We do clone the transport here: https://github.com/KomodoPlatform/komodo-defi-framework/blob/2e21532a3012ad040d7da896559bfe63f5d9382f/mm2src/coins/eth/v2_activation.rs#L376

Which is defined like this: https://github.com/KomodoPlatform/komodo-defi-framework/blob/2e21532a3012ad040d7da896559bfe63f5d9382f/mm2src/coins/eth/web3_transport/websocket_transport.rs#L43-L58

Nearly everything is shared/Arc<ed, only WebsocketTransportNode & GuiAuthValidationGenerator are cloned.

The websocket corresponding to the instance is stored (and dropped) in WebsocketTransport::start_connection_loop: https://github.com/KomodoPlatform/komodo-defi-framework/blob/2e21532a3012ad040d7da896559bfe63f5d9382f/mm2src/coins/eth/web3_transport/websocket_transport.rs#L260-L275

Which is guarded not to run twice by let _guard = self.connection_guard.lock().await; and connection_guard is also shared on cloning, so we would never open two connections for different tickers.

Note Don't forget to still PR [this](https://github.com/KomodoPlatform/komodo-defi-framework/tree/share-web3) if this issue is closed without a PR.