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

zcash_client_backend: Add a Tor client that can fetch USD/ZEC exchange rates #1422

Merged
merged 5 commits into from
Jul 18, 2024

Conversation

str4d
Copy link
Contributor

@str4d str4d commented Jun 14, 2024

Closes #1416.

# Tor
# - `arti-client` depends on `rusqlite`, and a version mismatch there causes a compilation
# failure due to incompatible `libsqlite3-sys` versions.
arti-client = { version = "0.11", default-features = false, features = ["compression", "rustls", "tokio"] }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After #1421 we are no longer constrained by ring, but we are still constrained here by rusqlite which is why I only bumped this from 0.9 to 0.11, not to the latest 0.19. We should separately look at bumping rusqlite, subject to the CocoaPods issue above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ugh, we can't actually avoid cross-version ring dependencies, because tor-rtcompat depends on both a rustls version that uses ring 0.17, and the x509-signature crate that uses ring 0.16. We'd need to use the older arti-client version etc. that uses the older rustls. Given that the most recent release of Arti is also still in this state, I'm inclined to just leave it as-is (we're at least down to a single version of rustls) and see how it goes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I confirmed that this still happens to work on iOS, so I think we should just leave it as-is for now, and if I have time I'll try to contribute a change to Arti that migrates away from x509-signature.

Copy link

codecov bot commented Jun 15, 2024

Codecov Report

Attention: Patch coverage is 0% with 71 lines in your changes missing coverage. Please review.

Project coverage is 63.90%. Comparing base (eaa43b4) to head (ac5bac9).

Files Patch % Lines
zcash_client_backend/src/tor/http.rs 0.00% 62 Missing ⚠️
zcash_client_backend/src/tor/http/cryptex.rs 0.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1422      +/-   ##
==========================================
- Coverage   64.19%   63.90%   -0.30%     
==========================================
  Files         130      132       +2     
  Lines       15423    15494      +71     
==========================================
  Hits         9901     9901              
- Misses       5522     5593      +71     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Base automatically changed from dep-bip32 to main June 17, 2024 23:04
@str4d str4d force-pushed the zcb-tor branch 2 times, most recently from bb54d4e to e5ff573 Compare June 18, 2024 00:11
@str4d str4d marked this pull request as ready for review June 18, 2024 00:11
@str4d str4d force-pushed the zcb-tor branch 2 times, most recently from 746e168 to b5a3c2c Compare June 19, 2024 18:02
Cargo.lock Outdated Show resolved Hide resolved
@str4d str4d force-pushed the zcb-tor branch 5 times, most recently from 89fe473 to f618ca3 Compare June 25, 2024 16:43
@str4d str4d force-pushed the zcb-tor branch 2 times, most recently from 4d4575a to 361653b Compare June 28, 2024 16:44
nuttycom
nuttycom previously approved these changes Jul 1, 2024
Copy link
Contributor

@nuttycom nuttycom left a comment

Choose a reason for hiding this comment

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

utACK 361653b

I'm surprised that exchange_rate.rs hardcodes the set of permitted handlers. That seems pretty inflexible for third-party users.

zcash_client_backend/src/tor.rs Outdated Show resolved Hide resolved
zcash_client_backend/src/tor.rs Show resolved Hide resolved
zcash_client_backend/src/tor/http.rs Show resolved Hide resolved
zcash_client_backend/src/tor/http/exchange_rate.rs Outdated Show resolved Hide resolved
@str4d
Copy link
Contributor Author

str4d commented Jul 2, 2024

Rebased on main to fix merge conflict in changelog.

@str4d
Copy link
Contributor Author

str4d commented Jul 2, 2024

Force-pushed to remove unnecessary tor_dir permissions changes, and address CI lints.

nuttycom
nuttycom previously approved these changes Jul 3, 2024
Copy link
Contributor

@nuttycom nuttycom left a comment

Choose a reason for hiding this comment

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

re-utACK ced6316

@str4d
Copy link
Contributor Author

str4d commented Jul 15, 2024

Force-pushed to not pass ExchangePair through to the individual queriers. Only two exchanges offer actual USD/ZEC pairs (the rest are USDT/ZEC), and even if we could get data for e.g. GBP/ZEC that wouldn't help with arbitrary fiat currencies.

Instead, we will always query for USD(T)/ZEC, and then use a forex rate for TARGET/USD to adjust, once I can find a suitable free source of forex data.

@str4d
Copy link
Contributor Author

str4d commented Jul 17, 2024

Rebased on main after TEX address support landed.

Copy link
Contributor

@nuttycom nuttycom left a comment

Choose a reason for hiding this comment

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

I think that the implementation of get_exchange_rate is excessively restrictive - it does not permit either the exclusion of data providers or the addition of providers without forking the crate. If the API is released as-is, it will require a breaking API change to remedy that, and I don't see a good reason for not adding the necessary abstraction layer when introducing the API to begin with.

zcash_client_backend/src/tor/http/exchange_rate.rs Outdated Show resolved Hide resolved
zcash_client_backend/src/tor/http/exchange_rate.rs Outdated Show resolved Hide resolved
@str4d str4d force-pushed the zcb-tor branch 2 times, most recently from 0ccfdb2 to 675490e Compare July 18, 2024 01:26
@str4d
Copy link
Contributor Author

str4d commented Jul 18, 2024

Force-pushed to rework the exchange rate API to allow callers to customise the exchanges (or define their own data sources).

Copy link
Contributor

@nuttycom nuttycom left a comment

Choose a reason for hiding this comment

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

utACK 675490e with nonblocking nit & questions.

zcash_client_backend/src/tor/http/cryptex.rs Outdated Show resolved Hide resolved
zcash_client_backend/src/tor/http/cryptex.rs Outdated Show resolved Hide resolved
str4d added 2 commits July 18, 2024 17:53
This fetches price data from multiple exchanges over Tor, and takes the
median of the successful responses.

Closes #1416.
Currently only unauthenticated connections are supported (i.e. no API
keys can be configured). However, AFAICT none of these exchanges provide
non-IP-based rate limits for authenticated connections to public APIs,
so authentication wouldn't help to make connections over Tor more
reliable.
@str4d
Copy link
Contributor Author

str4d commented Jul 18, 2024

Force-pushed to address review comments.

Copy link
Contributor

@nuttycom nuttycom left a comment

Choose a reason for hiding this comment

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

re-utACK ac5bac9

@str4d str4d merged commit 1ef11c2 into main Jul 18, 2024
26 of 28 checks passed
@str4d str4d deleted the zcb-tor branch July 18, 2024 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zcash_client_backend: Add Arti-based Tor client for fetching USD/ZEC exchange rates
2 participants