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

How do we connect to a local node? #222

Closed
forgetso opened this issue Feb 23, 2023 · 6 comments
Closed

How do we connect to a local node? #222

forgetso opened this issue Feb 23, 2023 · 6 comments

Comments

@forgetso
Copy link

forgetso commented Feb 23, 2023

There is a westend.json spec in the smoldot repo. I'm trying to replicate this for a local development node. I've output my chain-spec from the substrate node using

./usr/local/bin/substrate-contracts-node build-spec --raw > ~/dev.json

Which gave me this:

{
  "name": "Development",
  "id": "dev",
  "chainType": "Development",
  "bootNodes": [
    "/ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEPsX7bCdL4UiNXXm1hhq3w8THhozFMWWwet9nykHVCwY"
  ],
  "telemetryEndpoints": null,
  "protocolId": "rpc",
  "properties": null,
  "codeSubstitutes": {},
  "genesis": {
    "raw": {
      "top": {
        "0x26aa394eea5630e07c48ae0c9558cef74e7b9012096b41c4eb3aaf947f6ea429": "0x0000",
        "0x26aa394eea5630e07c48ae0c9558cef75684a022a34dd8bfa2baaf44f172b710": "0x01",
        "0x26aa394eea5630e07c48ae0c9558cef78a42f33323cb5ced3b44dd825fda9fcc": "0x4545454545454545454545454545454545454545454545454545454545454545",
        "0x26aa394eea5630e07c48ae0c9558cef7a44704b568d21667356a5a050c118746b4def25cfda6ef3a00000000": "0x4545454545454545454545454545454545454545454545454545454545454545",
        "0x26aa394eea5630e07c48ae0c9558cef7a7fd6c28836b9a28522dc924110cf439": "0x01",

I also saw a demo-chain-specs/dev.json in this repo that contains pretty much the same stuff, including the same boot nodes. So I copied my dev.json over demo-chain-specs/dev.json.

To try and run a light client connecting to my local node I've replaced all instances of westend.json with dev.json and I've changed the port to 9966 as my local node is using 9944. This gives me the following output:

(base) ➜  javascript git:(main) ✗ npm start

> [email protected] start
> node prepare.mjs --debug && rimraf ./dist && npm run buildModules && node demo/demo.mjs

/home/user/.rustup/toolchains/1.67.0-x86_64-unknown-linux-gnu/bin/cargo
info: component 'rust-std' for target 'wasm32-wasi' is up to date
    Finished dev [optimized + debuginfo] target(s) in 0.17s

> [email protected] buildModules
> tsc -p tsconfig-mjs.json && tsc -p tsconfig-cjs.json && bash fix-package-type.sh

JSON-RPC server now listening on port 9966
Please visit one of:
- dev: https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944%2Fdev
- westmint: https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944%2Fwestmint
- polkadot: https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944%2Fpolkadot
- acala: https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944%2Facala
- ksmcc3: https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944%2Fksmcc3
- statemine: https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944%2Fstatemine
- karura: https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944%2Fkarura
- rococo_v2_2: https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944%2Frococo_v2_2
- contracts-rococo: https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944%2Fcontracts-rococo

[11:54:45.933] [smoldot] Smoldot v0.7.12
[11:54:46.265] [smoldot] Chain initialization complete for dev. Name: "Development". Genesis hash: 0x3487…f6cc. State root hash: 0x4923fe03e70e397fc323e0cbc45523f04db2b936d69e022be38680b21aa5bb93. Network identity: 12D3KooWSKhbUyUybHw16maicP3u9T63cJT5zFAaF7oCTWa6BS6H. Chain specification or database starting at: 0x3487…f6cc (#0)
[11:54:54.265] [connections] Timeout when trying to reach bootnode 12D3KooWEPsX7bCdL4UiNXXm1hhq3w8THhozFMWWwet9nykHVCwY through /ip4/127.0.0.1/tcp/30333

How do I get smoldot to connect to my development chain? Do I need to replace the bootNodes values with some kind of local URL?

 "/ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEPsX7bCdL4UiNXXm1hhq3w8THhozFMWWwet9nykHVCwY"

This doesn't look like an address that smoldot would be able to reach. Is it like this as the node was running in docker?

I also tried running generate_chain_spec.sh as follows:

#!/bin/sh

# Small script to grab the chain specification of a running node.

echo '{"id":53,"jsonrpc":"2.0","method":"sync_state_genSyncSpec","params":[true]}' |
    websocat -n1 -B 99999999 ws://127.0.0.1:9944 |
    jq .result > chain_spec.json

However this outputted null in the chain_spec.json.

The command I'm using to run the substrate node is:

CMD exec /bin/bash -c "substrate-contracts-node --dev -d ./chain-data --unsafe-ws-external --rpc-external --prometheus-external -lerror,runtime::contracts=debug"
@forgetso
Copy link
Author

forgetso commented Feb 23, 2023

Ok, I see the bootNodes are libp2p multiaddresses which is why they have this format. Presumably I need to enable libp2p networking on my substrate node. Is this right?

@tomaka
Copy link
Contributor

tomaka commented Feb 23, 2023

If you're running your node in Docker, then its ports aren't publicly reachable from the outside unless you pass appropriate CLI options.
This is a Docker-specific problem, though, which has nothing to do with smoldot.

I need to enable libp2p networking on my substrate node. Is this right?

Unless your Substrate is very heavily modified, libp2p isn't something that you enable or disable. It's always there.

@forgetso
Copy link
Author

forgetso commented Feb 23, 2023

My ports 9944 and 9933 are reachable outside of docker as I use this node from polkadot apps and also from a local JavaScript project.

These are the ports exposed in the docker file:

EXPOSE 30333 9933 9944 9615

Are there some other ports that smoldot needs enabled?

Thanks for the tip about libp2p. I'm using the default substrate contracts node so there are no custom mods.

@forgetso
Copy link
Author

Ok, so I had exposed the ports in the Dockerfile but not in my docker compose file. I added 30333 and smoldot was able to find the substrate contracts node. It then hit the following issue from smoldot:

[13:36:11.137] [smoldot] Smoldot v0.7.12
[13:36:11.416] [smoldot] Chain initialization complete for dev. Name: "Development". Genesis hash: 0x3487…f6cc. State root hash: 0x4923fe03e70e397fc323e0cbc45523f04db2b936d69e022be38680b21aa5bb93. Network identity: 12D3KooWA5cnYUdW2Wfg8xWqeLCwY6zA5i2QKYisc9nmGxHP3EXt. Chain specification or database starting at: 0x3487…f6cc (#0)
Smoldot has panicked while executing task `sync-service-dev`. This is a bug in smoldot. Please open an issue at https://github.com/smol-dot/smoldot/issues with the following message:
panicked at 'internal error: entered unreachable code', /home/chris/dev/prosopo/smoldot/light-base/src/sync_service/standalone.rs:942:53

@forgetso
Copy link
Author

Seems like this is an issue with the substrate contracts node which is runs in instant_seal mode. I switched over to substrate branch polkadot-v0.9.37 and smoldot is successfully syncing the development chain.

[13:46:42.300] [smoldot] Chain initialization complete for dev. Name: "Development". Genesis hash: 0x64da…adfe. State root hash: 0x56f1b0c44c23bbb69d07b58bfd259b9155451d0b3e69d5c5310a2b72b0118b38. Network identity: 12D3KooWCEq9auR8YEYxsQKbzzWknmEG6VUEpC7p5DP7fFd8GBWU. Chain specification or database starting at: 0x64da…adfe (#0)
[13:46:52.512] [sync-service-dev] GrandPa warp sync in progress. Block: #56 (0x0xd018…f5d4). Peer attempt: 12D3KooWKGrthLCDH3rK3R9W7BfMLbrET6eaVAFsw5ES9jEAsnzn.
[13:46:54.100] [smoldot_light::runtime_service] Unresolved host function in runtime: `env`:`ext_default_child_storage_read_version_1`. Smoldot might encounter errors later on. Please report this issue in https://github.com/smol-dot/smoldot
[13:46:54.100] [runtime-dev] Successfully compiled runtime. Spec version: 268. Size of `:code`: 1.6 MiB.
[13:47:02.852] [sync-service-dev] GrandPa warp sync in progress. Block: #60 (0x0x1792…77b0). Peer attempt: 12D3KooWKGrthLCDH3rK3R9W7BfMLbrET6eaVAFsw5ES9jEAsnzn.
[13:47:13.346] [sync-service-dev] GrandPa warp sync in progress. Block: #63 (0x0x7745…26df). Peer attempt: 12D3KooWKGrthLCDH3rK3R9W7BfMLbrET6eaVAFsw5ES9jEAsnzn.
[13:47:23.917] [sync-service-dev] GrandPa warp sync in progress. Block: #67 (0x0x148b…abf8). Peer attempt: 12D3KooWKGrthLCDH3rK3R9W7BfMLbrET6eaVAFsw5ES9jEAsnzn.
[13:47:34.292] [sync-service-dev] GrandPa warp sync in progress. Block: #70 (0x0x6538…95a9). Peer attempt: 12D3KooWKGrthLCDH3rK3R9W7BfMLbrET6eaVAFsw5ES9jEAsnzn.
[13:47:41.574] [smoldot] Smoldot v0.7.12. Current memory usage: 50.1 MiB. Average download: 2.4 MiB/s. Average upload: 5.5 kiB/s.
[13:47:44.814] [sync-service-dev] GrandPa warp sync in progress. Block: #74 (0x0xf14f…b119). Peer attempt: 12D3KooWKGrthLCDH3rK3R9W7BfMLbrET6eaVAFsw5ES9jEAsnzn.

@tomaka
Copy link
Contributor

tomaka commented Feb 23, 2023

It is not syncing successfully, due to #166

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

No branches or pull requests

2 participants