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

move fetch metadata to a separate crate subxt_utils_fetchmetadata #1829

Merged
merged 17 commits into from
Oct 24, 2024

Conversation

niklasad1
Copy link
Member

@niklasad1 niklasad1 commented Oct 14, 2024

Close #1812

This PR moves the fetch metadata to a separate crate and also makes it optional for the subxt macro/codegen use it behind a feature flag.

So, if one disables jsonrpsee in subxt then the following would end-up in a compile error:

#[subxt(runtime_metadata_insecure_url = "ws://localhost:9944")]
mod runtime {}

fn main() {}
error: 'runtime_metadata_insecure_url' requires the 'runtime-metadata-insecure-url' feature to be enabled
  --> src/main.rs:75:1
   |
75 | #[subxt::subxt(runtime_metadata_insecure_url = "ws://localhost:9944")]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the attribute macro `subxt::subxt` (in Nightly builds, run with -Z macro-backtrace for more info)

@niklasad1 niklasad1 requested a review from a team as a code owner October 14, 2024 16:55
codegen/src/error.rs Outdated Show resolved Hide resolved
@@ -6,7 +6,7 @@
//! This is used by the `#[subxt]` macro and `subxt codegen` CLI command, but can also
//! be used directly if preferable.

#![deny(unused_crate_dependencies, missing_docs)]
Copy link
Member Author

Choose a reason for hiding this comment

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

we are using cargo-machete anyway for unused deps and I don't want to add

#[cfg(all(feature = "jsonrpsee", not(feature = "fetch-metadata))] use {tokio as _, url as _}

macro/src/lib.rs Outdated Show resolved Hide resolved
codegen/Cargo.toml Outdated Show resolved Hide resolved
@@ -25,11 +26,12 @@ quote = { workspace = true }
syn = { workspace = true }
scale-info = { workspace = true }
subxt-metadata = { workspace = true }
jsonrpsee = { workspace = true, features = ["async-client", "client-ws-transport-tls", "http-client"], optional = true }
jsonrpsee = { workspace = true, features = ["ws-client", "http-client"], optional = true }
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess this means that, without importing jsonrpsee myself to enable TLS features, that we won't be able to use fetch-metadata with httpS urls?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes without jsonrpsee it will only work to fetch metadata from a file or runtime path...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, I meant that based on these feature changes, jsonrpsee won't work with TLS urls now unless I import it in my top level package to enable them or something like that!

Copy link
Member Author

Choose a reason for hiding this comment

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

ooooh, tls enabled by default by the ws-client and http-client :P

macro/Cargo.toml Outdated Show resolved Hide resolved
fetch-metadata/Cargo.toml Outdated Show resolved Hide resolved
utils/src/lib.rs Outdated Show resolved Hide resolved
macro/Cargo.toml Outdated
@@ -16,6 +16,7 @@ description = "Generate types and helpers for interacting with Substrate runtime
[features]
web = ["subxt-codegen/web"]
runtime-path = ["polkadot-sdk"]
runtime-metadata-insecure-url = ["subxt-utils/fetch-metadata-url"]
Copy link
Collaborator

@jsdw jsdw Oct 24, 2024

Choose a reason for hiding this comment

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

Nit: Just to align with the above I'd call it runtime-url orrr, rename both to match the attrs so we have:

runtime-metadata-path
runtime-metadata-insecure-url

utils/src/macros.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@jsdw jsdw left a comment

Choose a reason for hiding this comment

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

Looks good; A step in the right direction I think!

I'm still on the fence over having one utils crate versus several (because feature flags make everything messier) but this is a step up from the current state :)

@niklasad1 niklasad1 changed the title macros: feature-gate jsonrpsee/fetch metadata url move fetch metadata to a separate crate subxt_utils_fetchmetadata Oct 24, 2024
Copy link
Collaborator

@lexnv lexnv left a comment

Choose a reason for hiding this comment

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

Nice! Had a brief view over the PR and looks solid 👍

@jsdw jsdw merged commit dc0795b into master Oct 24, 2024
13 checks passed
@jsdw jsdw deleted the na-feature-gate-jsonrpsee-macro branch October 24, 2024 13:45
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.

subxt: brings in tls dependencies when default-features = false && features = ["native"]
3 participants