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

Panic upon establishing client connection #1171

Closed
ggwpez opened this issue Sep 24, 2023 · 3 comments · Fixed by #1174
Closed

Panic upon establishing client connection #1171

ggwpez opened this issue Sep 24, 2023 · 3 comments · Fixed by #1174

Comments

@ggwpez
Copy link
Member

ggwpez commented Sep 24, 2023

I am trying to connect to different nodes with the Subxt library and hit this panic when connecting to a specific node: RuntimeCall exists in V14; qed.
Can you please make this an error instead of a panic so my program does not crash?

Stack trace

thread 'main' panicked at 'RuntimeCall exists in V14; qed', /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/subxt-metadata-0.31.0/src/from_into/v14.rs:319:10
stack backtrace:
   0: rust_begin_unwind
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/panicking.rs:593:5
   1: core::panicking::panic_fmt
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/panicking.rs:67:14
   2: core::panicking::panic_display
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/panicking.rs:150:5
   3: core::panicking::panic_str
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/panicking.rs:134:5
   4: core::option::expect_failed
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/option.rs:1952:5
   5: core::option::Option<T>::expect
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/option.rs:898:21
   6: subxt_metadata::from_into::v14::generate_outer_enums
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/subxt-metadata-0.31.0/src/from_into/v14.rs:311:21
   7: subxt_metadata::from_into::v14::v14_to_v15
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/subxt-metadata-0.31.0/src/from_into/v14.rs:156:23
   8: subxt_metadata::from_into::v14::<impl core::convert::TryFrom<frame_metadata::v14::RuntimeMetadataV14> for subxt_metadata::Metadata>::try_from
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/subxt-metadata-0.31.0/src/from_into/v14.rs:15:9
   9: <T as core::convert::TryInto<U>>::try_into
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/convert/mod.rs:755:9
  10: <subxt_metadata::Metadata as parity_scale_codec::codec::Decode>::decode
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/subxt-metadata-0.31.0/src/lib.rs:640:57
  11: <subxt::metadata::metadata_type::Metadata as parity_scale_codec::codec::Decode>::decode
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/subxt-0.31.0/src/metadata/metadata_type.rs:71:9
  12: subxt::rpc::rpc::Rpc<T>::metadata::{{closure}}
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/subxt-0.31.0/src/rpc/rpc.rs:401:34
  13: subxt::client::online_client::OnlineClient<T>::fetch_latest_stable_metadata::{{closure}}
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/subxt-0.31.0/src/client/online_client.rs:158:24
  14: subxt::client::online_client::OnlineClient<T>::fetch_metadata::{{closure}}
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/subxt-0.31.0/src/client/online_client.rs:144:57
  15: <futures_util::future::maybe_done::MaybeDone<Fut> as core::future::future::Future>::poll
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.28/src/future/maybe_done.rs:95:38
  16: <futures_util::future::join::Join3<Fut1,Fut2,Fut3> as core::future::future::Future>::poll
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.28/src/future/join.rs:55:33
  17: subxt::client::online_client::OnlineClient<T>::from_rpc_client::{{closure}}
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/subxt-0.31.0/src/client/online_client.rs:95:10
  18: subxt::client::online_client::OnlineClient<T>::from_url::{{closure}}
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/subxt-0.31.0/src/client/online_client.rs:79:57
  19: subquery::endpoints::{{closure}}::{{closure}}::{{closure}}
             at ./src/main.rs:46:42
  20: <futures_util::stream::futures_unordered::FuturesUnordered<Fut> as futures_core::stream::Stream>::poll_next
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.28/src/stream/futures_unordered/mod.rs:518:17
  21: futures_util::stream::stream::StreamExt::poll_next_unpin
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.28/src/stream/stream/mod.rs:1632:9
  22: <futures_util::stream::stream::buffer_unordered::BufferUnordered<St> as futures_core::stream::Stream>::poll_next
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.28/src/stream/stream/buffer_unordered.rs:75:15
  23: <futures_util::stream::stream::collect::Collect<St,C> as core::future::future::Future>::poll
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.28/src/stream/stream/collect.rs:50:26
  24: subquery::endpoints::{{closure}}
             at ./src/main.rs:59:10
  25: subquery::main::{{closure}}
             at ./src/main.rs:12:26
  26: tokio::runtime::park::CachedParkThread::block_on::{{closure}}
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/park.rs:282:63
  27: tokio::runtime::coop::with_budget
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/coop.rs:107:5
  28: tokio::runtime::coop::budget
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/coop.rs:73:5
  29: tokio::runtime::park::CachedParkThread::block_on
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/park.rs:282:31
  30: tokio::runtime::context::blocking::BlockingRegionGuard::block_on
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/context/blocking.rs:66:9
  31: tokio::runtime::scheduler::multi_thread::MultiThread::block_on::{{closure}}
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/scheduler/multi_thread/mod.rs:87:13
  32: tokio::runtime::context::runtime::enter_runtime
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/context/runtime.rs:65:16
  33: tokio::runtime::scheduler::multi_thread::MultiThread::block_on
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/scheduler/multi_thread/mod.rs:86:9
  34: tokio::runtime::runtime::Runtime::block_on
             at /Users/vados/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/runtime.rs:349:45
  35: subquery::main
             at ./src/main.rs:20:5
  36: core::ops::function::FnOnce::call_once
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Code for reproduction is here: subquery.zip (just cargo r).

@lexnv
Copy link
Collaborator

lexnv commented Sep 25, 2023

Hey Oliver,

Subxt is expecting the RuntimeCall and RuntimeEvent to be part of the metadata V14 for substrate-based chains.
This is part of converting the metadata V14 to the V15 format.

Indeed for some custom chains, this assumption might not hold true. I'm wondering are you targeting a live-chain or a local-node? 🤔

To avoid the panic, I believe we could extend generate_runtime_error_type()

@jsdw
Copy link
Collaborator

jsdw commented Sep 25, 2023

I'm curious to know when a RuntimeCall would ever not exist in a chain. But I agree that we should at least make it an error and not a panic (we should avoid panicking when user provided data (ie the metadata) isn't the format we expect).

The code to reproduce basically extracts endpoints from https://github.com/polkadot-js/apps/blob/master/packages/apps-config/src/endpoints/productionRelayPolkadot.ts and then tries to build a client from each of them, so I guess that one of those is missing a RuntimeCall, so let's also find out which one if we can, and look at its metadata!

@lexnv
Copy link
Collaborator

lexnv commented Sep 25, 2023

The following url was causing the panic "wss://c1.hashed.live:443".

Inspecting the metadata of that chain concluded that the RuntimeCall enum was not present in the portable registry. However, a Call enum was present which contained identical information:

            "id": 293,
            "type": {
              "path": [
                "hashed_parachain_runtime",
                "Call"
              ],
              "def": {
                "variant": {
                  "variants": [
                    {
                      "name": "System",
                      "fields": [
                        {
                          "type": 134,
                          "typeName": "self::sp_api_hidden_includes_construct_runtime::hidden_include::dispatch\n::CallableCallFor<System, Runtime>"
                        }
                      ],
                      "index": 0

As such have created a PR that:

  • try to find RuntimeCall enum in portable registry
  • try to find Call enum in portable registry
  • if fallback fails, then generate a RuntimeCall enum

Idem for RuntimeEvent and RuntimeError. Tested the PR against Oliver's example and it works fine so far.

Thanks again Oliver for raising this!

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 a pull request may close this issue.

3 participants