-
Notifications
You must be signed in to change notification settings - Fork 97
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
Request the transaction history from UTXO RPCs only when balance is changed. #612
Comments
Would also nice to measure traffic usage using address with significant number of transactions before making optimizations. Then measure it again after optimization is done and provide results here. It might be done as internal metric collecting the data transferred by ElectrumClient, specific design decisions are up to you, we may discuss them in person when you start working on this task. |
In https://github.com/ca333/komodoDEX/issues/349 we're going to gather such metrics via decentralized gossip. Having the history traffic measurements available to us would be very useful The easiest way to share these measurements with the gossiping UI code is probably to log them. |
There are several implementation questions:
What should be the emotion, the tags are right and are useful? |
So the history loading is something that has a beginning, works for some time and then has an end, right? I mean, once we loaded a history for a coin we don't need to do that anymore, or if we do, it's unlikely to take much traffic? If yes, then this sounds like a good fit for a dashboard entry. Dashboard will print the current version of the status periodically and then will print it last final time when the operation is marked as finished (IIRC). Like it does for the state of the swap. And it was designed specifically to track ongoing continuous operations with minimal interference to the normal tracing / signal-oriented log. Should have probably mentioned it earlier. But
Most probably not. If history loading takes a lot of traffic then we'll be thinking on how to reduce it but we won't be thinking about what IPs it uses. But we should probably add the coin's ticker to the tags.
Mobile UIs not using native, but we'll be needing the ETH stats just as much as the UTXO ones.
The parsable data should all be in tags, like P.S. I think that dashboarding the background operations in MM is a good idea even regardless of the traffic measurement, and to boot it saves us from doing extra periodic requests to MM, but I should probably mention that it's also feasible to implement this by adding the traffic fields to https://developers.atomicdex.io/basic-docs/atomicdex/atomicdex-api.html#my-tx-history ? |
History loading repeats over time, we need to fetch it again and again from coin RPC when balance is updated. The balance check is now missing so tx_history_loop fetches history every 30 seconds from Electrum which always returns full transactions history without paging support (that is already mentioned in the initial description of the issue).
As Artem mentioned you may create a status similar to https://github.com/KomodoPlatform/atomicDEX-API/blob/7d10c66c033ae4e6cfccaea318e2bddc3db7ea35/mm2src/lp_swap/maker_swap.rs#L1018 But what I'm unsure of: we may have dozens of active coins, won't the log be overloaded with dozens of periodical messages since history fetching loop actually never ends? E.g.
IP headers size calculation is not mandatory, it's negligible overhead.
It will be also nice, we can extend this idea not only to coin RPC clients traffic measurement, we actually need other metrics, e.g. ordermatching protocol traffic usage, and these metrics might be not only network related. We possibly need an abstraction for such purpose, there're also metrics and more widely used prometheus crate. I think it might be nice feature to integrate a widely used OS solution for metrics collection, it already has pretty visualization capabilities. |
I see. Nasty! Thanks for the reminder! The |
As far as I understand the
The best way I see is collect metrics and record it every specified time (eg 5 min or less for the tests).
Recording the log entry above may be little difficult, because the count of request and response bytes should be passed from corresponding connection loop to the RPC client API. But it may be useful later, not only for measuring the history request traffic. If it is planned in the future, the way is suitable for this. Else I can add other history metrics:
where the I also suggest to measure and record all RPC client traffic. |
A couple of ideas.
cc @cipig |
I would like to avoid running additional stuff on the electrums, if that is possible. |
@cipig
AFAIK we didn't get any reports that Electrum connectivity is getting blocked by any provider.
Sure, we may integrate block explorers API too in the future (e.g. Insight).
As I can see from docs And in summary the idea of such tx history fetching from Electrum was to avoid dependency on 3rd party blockchain explorer services. So to have history you need to run Electrum open source server only which has standardized API. |
And we won't, until our network is larger. We know such providers exist though.
I take it the tx history information is public and hence we can proxy it from any server, not necessarily from the electrum ones?
If the transaction history happens to take much traffic then we'll have to redesign it per https://github.com/ca333/komodoDEX/issues/349. |
There was a request some time ago to use open-source Insight explorer API as 1 of UTXO coins operational mode, it's in backlog as of now, it will be implemented later - #618
Electrum servers can use 80/443 ports, Electrums support WS protocol which is fine for pure browser environments. So even if all non-HTTP ports are blocked we can solve the problem by simple reconfiguration. Users also can use TOR proxy or VPNs to mitigate the problem. And I would like to deal with 1 thing at time, this issue is about history fetching optimization with Electrum operational mode and corresponding metrics collection, not about Electrum can be potentially blocked. |
And what is also important: we're not only persons using Electrum. Electrum based wallets and server is popular software that is used by millions people to manage their coins, I guess if there were any massive blocking attempts there would be some news about that, however I'm not able to find such reports by searching |
I cede you the point, Artem. In the realm of cryptocurrency, Electrum is among the more used technologies, it is Firewall friendly, using the 80/443 ports, and we might very well follow its pattern. (Speaking of which, is there already an issue to use Electrum ports 80/443 in MM?) And it follows that we don't need to proxy Electrum in its entirety. But Electrum pagination is a known problem which brings us back to the issue at hand. Any thoughts on proxying Electrum tx history in order to reverse, paginate and compress it? P.S.
Human behavior follows certain patterns or established social habits ("rules of fair play" per Jordan Peterson). One of such patterns is that people talk about providers in the forums that discuss the providers. It is exceedingly rare to see provider gossip overflowing into subject of specific technologies and their implementation. Note also, that we're not talking so much about blocking but about traffic prioritization, which is actually hard to detect, sneaky. And if something does exists, it does not follow that you (or any of us) have heard about it. That would be a false premise and I sincerely advise you to use a better logic. |
Not yet, it requires additional DNS configuration, current electrum servers addresses maintained by cipi follow the
Ì'm not thinking that if I didn't heard about something it doesn't exist, I'm making an
Vuse "bad ISPs DB" is example of such overflowing 🙂 And there's similar community supported list by TOR. Maybe something similar already exists in context of blockchain-related projects. Or maybe we will create something by ourselves sometime 🙂 |
That will not work, since all coins are running on the same server (or 3 of them), and each server has only one port 80. |
* Add `metrics` crate dependency * Implement custom observer and exporter for the MM logging purposes * Add unit tests
@ArtemGr I think It's not a big issue if we fetch the history only when balance is changed. |
Good idea on collecting the metrics!
added to my list. |
@ArtemGr I want to do This comment is two years old. Can you say is it important to keep tags unordering? if I added tags sorting, UI applications would work correctly? |
Might affect https://github.com/ca333/komodoDEX/blob/e3a1d2ab39edb7719ee58f829d11a910277f1705/lib/services/mm_service.dart#L453, but it's NP as currently the UI is bundled with a specific version of MM, so we'll just update the UI code if the ordering of swap tags is flipped. |
* Add and implement metrics module #612 * Add `metrics` crate dependency * Implement custom observer and exporter for the MM logging purposes * Add unit tests * Refactor the metrics module to use it in MmCtx * Make Metrics::receiver the Constructable<Receiver> * Add metrics: mm_metrics::Metrics field to the MmCtx * Add MmArc::init_metrics() method * Add the mm_metrics using to measure rpc electrum traffic * Add ctx: MmWeak as field to ElectrumClientImpl * Pass ctx: MmWeak to connect_loop * Add traffic measurement for NativeClient * Incapsulate transport traffic metrics into TransportMetrics trait * Create CoinTransportMetrics implemented TransportMetrics trait * Replace the mm_counter! using within electrum's connect_loop and NativeClient::transport * Replace Arc<dyn TransportMetrics> to Box<dyn TransportMetrics> * Add clone_into_box method to TransportMetrics to clone Box's content * Add traffic measurement for Web3Transport - etomic coin's rpc client * Replace ctx: MmWeak by log_state: LogArc within Metrics, change dashboard formatting * Add LogArc, LogWeak like to MmArc, MmWeak * Replace log: LogState by log: LogArc within MmCtx * Record metrics to dashboard with the same labels in one line * Make the TransportMetrics more abstract * Rename TransportMetrics to RpcTransportEventHandler * Replace Box<Trait> by Arc<Trait> to avoid excess dynamic memory allocation * Replace one shared handler by vector of shared handlers within RPC clients * Add `metrics` method to MarketMaker * Add method * Implement custom JsonObserver and use it to collect metrics in Json * Add tx_history metrics collection to ETH, ERC20, NATIVE, ELECTRUM tx_history * Add metrics * Add an integration test to check request the transaction history from UTXO RPCs only when balance is changed * Fix warnings * Change metrics format * Replace metrics from tags to message * Remove tags sorting * Request the transaction history from Electrum RCP only when balance is changed #612 * Add prometheus HTTP exporter * Add prometheus graceful shutdown on MM context dropped * Fix merge conflicts * Implement Debug for RpcTransportEventHandler trait * Add ability to disable metrics recording to log
Implemented, closing. |
Any hints on how we can use the new measurement functionality to measure MM traffic? |
The documentation has been published recently, I think recommended way for GUIs is to call API and parse the metrics from JSON: https://developers.komodoplatform.com/basic-docs/atomicdex/atomicdex-tutorials/atomicdex-metrics.html#api-calling |
Awesome, thanks! |
@ArtemGr, I decided not to reorder the dashboard tags. I hope you haven't changed GUI's code. |
@sergeyboyko0791, Nope, everything's intact. Appreciate the update. |
https://github.com/KomodoPlatform/atomicDEX-API/blob/9884f181d8f990f57208484f1fdb20e9ed0e0882/mm2src/coins/utxo.rs#L1485
The tx_history fetching loop starts as background thread to download address transaction history providing instant access from local database.
It might consume a lot of traffic in Electrum case - blockchain-scripthash-get-history method always returns
full
history of address which might contain a lot of records. As of now this request is repeated every 30 seconds again and again even if there're no new records.We can easily avoid it by checking balance - the result has way lower size, so in general it'll look like:
The text was updated successfully, but these errors were encountered: