paritytech / subxt

Interact with Substrate based nodes in Rust or WebAssembly
Other
391 stars 236 forks source link

the trait bound `Client: subxt::backend::rpc::RpcClientT` is not satisfied #1521

Closed ltfschoen closed 2 months ago

ltfschoen commented 3 months ago

Why do I get the following error in this PR https://github.com/ltfschoen/subxt/pull/1#issue-2229557186 when i run the following, which generates the metadata associated with a Polkadot SDK Substrate Node that i'm running locally and then runs the example in ./examples/substrate-node-example/src/main.rs? i've tried to use the "newtype pattern"...

subxt metadata  --url ws://127.0.0.1:9944 > ./artifacts/substrate_node_metadata.scale
cd examples/substrate-node-example
cargo run --bin substrate-node-example

error:

error[E0277]: the trait bound `Client: subxt::backend::rpc::RpcClientT` is not satisfied
  --> src/main.rs:93:63
   |
93 |     let api = OnlineClient::<PolkadotConfig>::from_rpc_client(rpc.clone()).await?;
   |               ----------------------------------------------- ^^^^^^^^^^^ the trait `subxt::backend::rpc::RpcClientT` is not implemented for `Client`, which is required by `Client: Into<RpcClient>`
   |               |
   |               required by a bound introduced by this call
   |
   = help: the following other types implement trait `subxt::backend::rpc::RpcClientT`:
             Box<T>
             jsonrpsee_core::client::async_client::Client
             Arc<T>
   = note: required for `RpcClient` to implement `std::convert::From<Client>`
   = note: required for `Client` to implement `Into<RpcClient>`
note: required by a bound in `OnlineClient::<T>::from_rpc_client`
  --> /Users/luke/code/clones/github/ltfschoen/subxt/subxt/src/client/online_client.rs:85:26
   |
84 |     pub async fn from_rpc_client(
   |                  --------------- required by a bound in this associated function
85 |         rpc_client: impl Into<RpcClient>,
   |                          ^^^^^^^^^^^^^^^ required by this bound in `OnlineClient::<T>::from_rpc_client`

error[E0599]: no method named `system_name` found for struct `Client` in the current scope
   --> src/main.rs:100:13
    |
100 |         rpc.system_name().await?,
    |             ^^^^^^^^^^^ method not found in `Client`

error[E0599]: no method named `system_health` found for struct `Client` in the current scope
   --> src/main.rs:101:13
    |
101 |         rpc.system_health().await?,
    |             ^^^^^^^^^^^^^ method not found in `Client`

error[E0599]: no method named `system_properties` found for struct `Client` in the current scope
   --> src/main.rs:102:13
    |
102 |         rpc.system_properties().await?,
    |             ^^^^^^^^^^^^^^^^^ method not found in `Client`

error[E0599]: no method named `system_chain` found for struct `Client` in the current scope
   --> src/main.rs:103:13
    |
103 |         rpc.system_chain().await?
    |             ^^^^^^^^^^^^ method not found in `Client`
niklasad1 commented 3 months ago

Hey Luke

It's easier that you use the reconnecting-client from subxt (enable it with --feature unstable-reconnecting-rpc-client) otherwise you have to implement RpcClientT trait from subxt for the reconnecting client.

To elaborate if you depend directly on the reconnecting-rpc-client, you need this impl

ltfschoen commented 3 months ago

you need this impl

thanks, i believe i did that in this commit https://github.com/ltfschoen/subxt/pull/1/commits/ae2272f3d2a50feada491d5a76a358defe78362b, but i still get the same error, where i ran it with:

RUST_LOG="jsonrpsee=trace,reconnecting_jsonrpsee_ws_client=trace" cargo run --bin substrate-node-example --features unstable-reconnecting-rpc-client
david9991 commented 3 months ago

@ltfschoen Try to add 'unstable-light-client' and 'jsonrpsee' features to your subxt package. subxt = { version = "0.35.2", features = ["unstable-light-client", "jsonrpsee"] }

niklasad1 commented 2 months ago

I added some comments to your branch how to fix the compilation errors you got. You need to add the following to your Cargo.toml in your branch:

subxt = { path = "../subxt", features = ["unstable-reconnecting-rpc-client"] }
# remove the reconnecting-rpc-client dependency and use it from subxt

As this works in the subxt example, it should work Re-open the issue if it doesn't work...

ltfschoen commented 2 months ago

ltfschoen#1 (comment)

thanks, yes it worked using your suggestion in this commit https://github.com/ltfschoen/subxt/pull/1/commits/e12183fa7c1f3db3c3e410e9341244524d3ea42e, so we can close the issue.

first i ran the polkadot-sdk node with:

cargo build

RUST_LOG=debug RUST_BACKTRACE=1 ./target/debug/substrate-node \
  --dev \
  --validator \
  --alice \
  --name "Substrate Clawbird-dev" \
  --base-path "/tmp/substrate" \
  --port 30333 \
  --rpc-port 9944 \
  --rpc-cors=all \
  --rpc-methods=Unsafe \
  --rpc-external \
  --unsafe-rpc-external \
  --node-key 0000000000000000000000000000000000000000000000000000000000000001 \
  --log debug,sync=debug,grandpa=debug \
  --detailed-log-output \
  --enable-log-reloading \
  --prometheus-external \
  --telemetry-url 'wss://telemetry.polkadot.io/submit/ 0' \
  -lruntime=debug

then ran the example with

RUST_LOG="jsonrpsee=trace,reconnecting_rpc_client=trace" cargo run --bin substrate-node-example

which outputs

Connected via RPC
XXX Creating bounded vec
thread 'main' panicked at src/main.rs:120:56:
called `Result::unwrap()` on an `Err` value: [115, 112, 101, 99, 105, 97, 108, 49]

where [115, 112, 101, 99, 105, 97, 108, 49] corresponds to b"special1" on this line of code.

but i don't understand why that errors, since the value is less than 32 chars long, which i thought would be allowable.

i can only overcome that error if i change Lines 119 to 122 shown below

                (
                         Data::Raw0(b"special1".to_vec().try_into().unwrap()),
            Data::Raw0(b"special2".to_vec().try_into().unwrap()),
        ),

to instead just use Data::None as shown below:

    (Data::None, Data::None),

so if i do that it'll run past line 127 and out put "XXX Creating identity info" but then it outputs the following error:

XXX Creating identity info
thread 'main' panicked at src/main.rs:136:57:
called `Result::unwrap()` on an `Err` value: [110, 97, 109, 101]

where [110, 97, 109, 101] corresponds to name on the line 136 display: Data::Raw0(b"name".to_vec().try_into().unwrap()), https://github.com/ltfschoen/subxt/pull/1/commits/e12183fa7c1f3db3c3e410e9341244524d3ea42e#diff-2383e11ebe67e1cad1eb504eae6fd615c67f90a72a920ede03d8340516acdacbR136.

but again i don't understand why that happens either, since it is also a value less than 32 characters long, which i thought would be allowable.