[Fix] Avoid reqwest::blocking when fetching parameters#3241
Conversation
8caa7e3 to
f584af0
Compare
iamalwaysuncomfortable
left a comment
There was a problem hiding this comment.
As is this will break mobile without MobileTLS and needs to be explicitly tested.
| [target.'cfg(all(any(target_os = "android", target_os = "ios"), not(target_family = "wasm"), not(target_env = "sgx")))'.dependencies.reqwest] | ||
| version = "0.13" | ||
| default-features = false | ||
| features = ["blocking", "native-tls"] | ||
|
|
||
| [target.'cfg(all(not(any(target_os = "android", target_os = "ios")), not(target_family = "wasm"), not(target_env = "sgx")))'.dependencies.reqwest] | ||
| version = "0.13" | ||
| default-features = false | ||
| features = ["blocking", "rustls"] | ||
| [target.'cfg(all(not(target_family = "wasm"), not(target_env = "sgx")))'.dependencies.ureq] | ||
| workspace = true | ||
| features = ["rustls"] |
There was a problem hiding this comment.
This change will break mobile. We need to use nativetls for mobile targets, we'll test out the SDK changes based on this change, but the mobile changes need to be tested out as well if we're changing to ureq.
wasm should be safe since it uses a funky XMLHttpREquest object, but we'll test it explicitly.
There was a problem hiding this comment.
It now uses native-tls as before for those targets
| /// The remote URLs to fetch parameters from. | ||
| /// (only used when the `filesystem` feature is active) | ||
| #[cfg_attr(not(feature = "filesystem"), allow(dead_code))] |
There was a problem hiding this comment.
Why only gated for filesystem? Non-filesystems also download these.
There was a problem hiding this comment.
This is just to hide a warning during test builds about the constant not being used.
The change does not remove the constant, but just suppresses the warning. I will update the comment.
| } | ||
|
|
||
| #[cfg(all(not(feature = "wasm"), not(target_env = "sgx")))] | ||
| #[cfg(all(feature = "filesystem", not(feature = "wasm"), not(target_env = "sgx")))] |
There was a problem hiding this comment.
Why the sudden requirement of filesystem? Non-filesystem systems still perform downloads into buffers. I don't see any specific filesystem code in here, so why gate it behind this feature?
| #[cfg(all(feature = "filesystem", not(feature = "wasm"), not(target_env = "sgx")))] | |
| #[cfg(all(not(feature = "wasm"), not(target_env = "sgx")))] |
There was a problem hiding this comment.
Unless I misunderstood the impl_load_bytes_logic_remote macro, remote_fetch is only invoked when filesystem or wasm is active.
|
|
||
| /// The remote URLs to fetch parameters from. | ||
| /// (only used when the `filesystem` feature is active) | ||
| #[cfg_attr(not(feature = "filesystem"), allow(dead_code))] |
There was a problem hiding this comment.
Why only when filesystem is active?
e9f8ba9 to
d575dde
Compare
|
We cannot test on mobile right now, but this PR still uses the same version of |
9cca4de to
ead2d7c
Compare
| return Err($crate::errors::ParameterError::FilesystemDisabled); | ||
| } | ||
| } | ||
| // We need either the `filesystem` or `wasm` feature to load parameters. |
There was a problem hiding this comment.
The error says FilesystemDisabled, the comment says either filesystem or wasm are needed. Should we re-use RemoteFetchDisabled or make a new error type?
| /// On native `filesystem` targets: serves from the local cache directory if present; otherwise | ||
| /// iterates through `$remote_urls` in order, retrying on transient errors, and caches the first | ||
| /// verified download to disk. | ||
| /// On wasm targets: iterates through `$remote_urls` using `XmlHttpRequest`, verifying the |
There was a problem hiding this comment.
Should we mention sgx as well?
| ($remote_urls: expr, $local_dir: expr, $filename: expr, $metadata: expr, $expected_checksum: expr, $expected_size: expr) => { | ||
| cfg_if::cfg_if! { | ||
| if #[cfg(all(feature = "filesystem", not(feature="wasm")))] { | ||
| if #[cfg(feature = "wasm")] { |
There was a problem hiding this comment.
The refactor 8684be5 is very hard to audit due to the inversion of multiple related feature flags and the number of lines of code. Can we leave a more comprehensive refactor for a separate PR so we don't block snarkOS?
8080744 to
170fd55
Compare
|
How relevant is this PR now that #3248 is merged? |
170fd55 to
2e50de9
Compare
This change is needed for ProvableHQ/snarkOS#4220.
#3169 changed
snarkvm-parametersto usereqwest::blockinginstead ofcurl. The former causes issues in some snarkOS test because it spawns a newtokioruntime, which does not work when called from an activetokioruntime.f584af0 changes the parameter fetching logic to use
ureqinstead which does not spawn atokioruntime under the hood.Additionally, 47a827a cleans up the parameters macros and adds documentation. It also fixes #2931. The macros are still hard to read because of the many feature gates, but the change is an improvement.
Testing
cd wasm && wasm-pack test --node)snarkvm-consolebuilds. I could not build tests for parameters, but that seemed to be a pre-existing issue. I did not run any other tests, because I do not have SGX hardware,and did not have time to set up the simulator.Notes
wasmandsgxbuilds. I could not find any and used previous pull requests to figure out how to test them.wasmfeature, and we do not solely rely on `target_arch='wasm32'.