zombienet icon indicating copy to clipboard operation
zombienet copied to clipboard

How to specify the collator's RPC port?

Open AuroraLantean opened this issue 2 years ago • 4 comments

Hi @pepoviola I need a RPC port to deploy Ethereum smart contracts into my parachain's EVM. and the EVM endpoint would look like http://127.0.0.1:xxxx

My current network file:

[relaychain]
default_image = "docker.io/parity/polkadot:{{POLKADOT_VERSION}}"
default_command = "polkadot"
default_args = [ "-lparachain=debug" ]
chain = "rococo-local"

  [[relaychain.nodes]]
  name = "alice"
  validator = true

  [[relaychain.nodes]]
  name = "bob"
  validator = true

[[parachains]]
id = 2000
cumulus_based = true

  [parachains.collator]
  name = "collator01"
  image = "{{COLLATOR_URL}}"
  command = "parachain-collator"
  args = ["-lparachain=debug"]
  
[types.Header]
number = "u64"
parent_hash = "Hash"
post_state = "Hash"

Now when I run Zombienet, I got this from the console log:

parachain-collator --name collator01 --node-key 5e123980fad4770d9ab5b7df7bbee8499943822a8555d11995e8203210065342 --chain /tmp/zombie-7777a966fceaf2c9ff0d46f9a5d9aa5a_-38485-NbMcMKykG6mQ/collator01/cfg/rococo-local-2000.json --base-path /tmp/zombie-7777a966fceaf2c9ff0d46f9a5d9aa5a_-38485-NbMcMKykG6mQ/collator01/data --listen-addr /ip4/0.0.0.0/tcp/33493/ws --rpc-port 42567 --ws-port 32777 --prometheus-external --prometheus-port 38427 --rpc-cors all --unsafe-rpc-external --rpc-methods unsafe --unsafe-ws-external --collator --force-authoring -lparachain=debug -- --chain /tmp/zombie-7777a966fceaf2c9ff0d46f9a5d9aa5a_-38485-NbMcMKykG6mQ/collator01/cfg/rococo-local.json --execution wasm --port 35237 --ws-port 42705 --rpc-port 46031

I see there are two RPC ports: --rpc-port 42567 and --rpc-port 46031

After testing, the first RPC port is working.

How can I get such port number programmatically in my JS script? I guess it is somewhere below?

const { wsUri, userDefinedTypes } = networkInfo.nodesByName[nodeName];
	const api = await zombie.connect(wsUri, userDefinedTypes);
	const validator = await api.query.session.validators();

Why are these ports random? Can we predetermine the collator RPC port?

From this https://github.com/paritytech/zombienet/blob/main/docs/src/network-definition-spec.md, it seems I can set the node RPC port, but not collator RPC port!??

I tried to add RPC port 6969 to the network file in the collator section:

  [parachains.collator]
  name = "collator01"
  image = "{{COLLATOR_URL}}"
  command = "hero-collator"
  args = ["-lparachain=debug --rpc-port 6969"]

then this error happened:

	launching collator01
		 with command: hero-collator --name collator01 --node-key 5e123980fad4770d9ab5b7df7bbee8499943822a8555d11995e8203210065342 --chain /tmp/zombie-b840ed3dd0b3680171b1bf161fb0e953_-12203-8fro5A1jGhKr/collator01/cfg/rococo-local-2000.json --base-path /tmp/zombie-b840ed3dd0b3680171b1bf161fb0e953_-12203-8fro5A1jGhKr/collator01/data --listen-addr /ip4/0.0.0.0/tcp/45925/ws --rpc-port 42015 --ws-port 43165 --prometheus-external --prometheus-port 44691 --rpc-cors all --unsafe-rpc-external --rpc-methods unsafe --unsafe-ws-external --collator --force-authoring -lparachain=debug --rpc-port 6969 -- --chain /tmp/zombie-b840ed3dd0b3680171b1bf161fb0e953_-12203-8fro5A1jGhKr/collator01/cfg/rococo-local.json --execution wasm --port 46741 --ws-port 34309 --rpc-port 40619

Error: Timeout(60) for node : collator01
    at NativeClient.<anonymous> (/snapshot/zombienet/dist/providers/native/nativeClient.js)
    at Generator.next (<anonymous>)
    at fulfilled (/snapshot/zombienet/dist/providers/native/nativeClient.js)

So adding the RPC port makes the Zombienet to have 2 RPC ports for the collator and that does not work! How can I set the RPC port? Thank

AuroraLantean avatar Aug 31 '22 08:08 AuroraLantean

You need to specify the --rpc-port in your network file in Zombienet tests.

See how I can specify port 6969 to be my collator RPC port:

  [parachains.collator]
  name = "collator01"
  image = "{{COLLATOR_URL}}"
  command = "parachain-collator"
  args = ["-lparachain=debug"]
  rpc_port = 6969

AuroraLantean avatar Sep 01 '22 08:09 AuroraLantean

Hi @AuroraLantean, thanks for the feedback. The documentation is currently outdated, but you can set the ports (rpc/ws/p2p/prometheus) on collators and relay chain nodes. I will update the docs asap.

Also, about the two rpc-port flags

I see there are two RPC ports: --rpc-port 42567 and --rpc-port 46031

This is because the collator has a embedded full-node of the relay chain, and the flags after -- are the ones related to this full-node.

Thanks!

pepoviola avatar Sep 01 '22 09:09 pepoviola

@pepoviola I just found out that specifying RPC port in parachain by rpc_port = 6969 is ignored by zombienet-linux v1.2.58, but not ignored by zombienet-linux v1.2.56... could you confirm?

Also this is test can pass in zombienet-linux v1.2.56:

bob: log line matches "Imported new block." within 10 seconds

but in zombienet-linux v1.2.58, that same test failed:

Timeout(10), "getting log pattern Imported new block. within 10 secs".

Thanks

AuroraLantean avatar Sep 02 '22 09:09 AuroraLantean

Hi @AuroraLantean, thanks for reporting this. I fix the port management in this pr. Also, the test are passing in v1.2.58

    ✔ alice: is up (62ms)
    ✔ bob: is up
    ✔ alice: reports block height is at least 10 within 200 seconds (51275ms)
    ✔ alice: log line contains "Imported #12" within 20 seconds (10025ms)
    ✔ alice: log line matches glob "*rted #1*" within 10 seconds
    ✔ alice: log line matches "Imported #[0-9]+" within 10 seconds

	 Deleting network


  6 passing (1m)

Thanks!

pepoviola avatar Sep 02 '22 10:09 pepoviola