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

Start sui-test-validator (local network) inside docker container #15279

Closed
thaonx opened this issue Dec 8, 2023 · 16 comments
Closed

Start sui-test-validator (local network) inside docker container #15279

thaonx opened this issue Dec 8, 2023 · 16 comments
Assignees

Comments

@thaonx
Copy link

thaonx commented Dec 8, 2023

I want to setup a Sui local network inside a Docker container utilizing the sui-test-validator binary. However, a challenge arises as the sui-test-validator exclusively listens on 127.0.0.1, resulting inaccessible from the host machine.

https://github.com/MystenLabs/sui/blob/main/crates/sui-test-validator/src/main.rs#L139C9-L139C25

  fullnode_address: Some(format!("127.0.0.1:{}", fullnode_rpc_port)),

To address this limitation, I propose the addition of a configurable option fullnode_rpc_host, within the sui-test-validator. This enhancement would allow users to set fullnode_rpc_host to 0.0.0.0, enabling binding to all available network interfaces and facilitating accessibility from the host machine.

@thaonx thaonx changed the title Start sui-test-validator (local network) insider docker container Start sui-test-validator (local network) inside docker container Dec 9, 2023
@stefan-mysten
Copy link
Contributor

The change was merged. @thaonx let us know if it does not work as expected!

@qpb8023
Copy link

qpb8023 commented Dec 20, 2023

@thaonx @stefan-mysten I am using the latest code and this problem still exists. Have you verified it?

Starting Sui validator with config: ClusterTestOpt {
    env: NewLocal,
    faucet_address: Some(
        "127.0.0.1:9123",
    ),
    fullnode_address: Some(
        "0.0.0.0:9000",
    ),
    epoch_duration_ms: Some(
        60000,
    ),
    indexer_address: None,
    use_indexer_v2: false,
    pg_address: postgres:*****@localhost:5432/sui_indexer,
    use_indexer_experimental_methods: false,
    config_dir: None,
    graphql_address: None,
}

Fullnode RPC URL: http://127.0.0.1:9000
Faucet URL: http://0.0.0.0:9123

@stefan-mysten
Copy link
Contributor

@qpb8023 thanks for raising this up. I have not tried it, can you provide a dockerfile?

@stefan-mysten stefan-mysten reopened this Dec 20, 2023
@qpb8023
Copy link

qpb8023 commented Dec 23, 2023

@stefan-mysten
I did not deploy using docker, but directly deployed sui-test-validator on the cloud server and opened ports 9000 and 9123. However, the rpc and facuet of the sui-test-validator compiled by the latest main branch can only access on the cloud server. Local access to the server and access through the external network are still unavailable. The problem should be at https://github.com/MystenLabs/sui/blob/main/crates/sui-test-validator/src/main.rs#L154C4-L154C4.

start command

sui genesis -f --with-faucet --working-dir=/data/genesis
./sui-test-validator --config-dir /data/genesis

@stefan-mysten
Copy link
Contributor

Thanks @qpb8023, I'll look into it.

@stefan-mysten
Copy link
Contributor

stefan-mysten commented Dec 23, 2023

I don't have a cloud server to try, but running it locally on commit becfc52387ccfb6a9c68d7ab8ae5edaa95f5b664 I get:

🚀 sui % sui-test-validator          
Graphql port not provided. Graphql service will not run.
`with_indexer` flag unset. Indexer service will not run.
Starting Sui validator with config: ClusterTestOpt {
    env: NewLocal,
    faucet_address: Some(
        "127.0.0.1:9123",
    ),
    fullnode_address: Some(
        "0.0.0.0:9000",
    ),
    epoch_duration_ms: Some(
        60000,
    ),
    indexer_address: None,
    use_indexer_v2: false,
    pg_address: postgres:*****@localhost:5432/sui_indexer,
    use_indexer_experimental_methods: false,
    config_dir: None,
    graphql_address: None,
}

And doing a cURL I get:

🚀 ~ %  curl --location --request POST 'http://0.0.0.0:9000' \
--header 'Content-Type: application/json' \
--data-raw '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "sui_getChainIdentifier",
  "params": []
}' | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   131  100    44  100    87   8316  16443 --:--:-- --:--:-- --:--:--  127k
{
  "jsonrpc": "2.0",
  "result": "bfa5779f",
  "id": 1
}

When you say local access to the server and access through the external network are still unavailable, which local access are you referring to, and what server? Are you saying that when issuing the command on the server you cannot query the network?

@qpb8023
Copy link

qpb8023 commented Dec 25, 2023

@stefan-mysten Sorry, my statement is wrong. I compiled the latest sui-test-validator (commit: db37e3c) on the server with the IP address 192.168.6.6, and then started sui-test-validator
command: RUST_LOG="off,sui_node=info" ./sui-test-validator
Log output:

RUST_LOG="off,sui_node=info" ./sui-test-validator
Graphql port not provided. Graphql service will not run.
`with_indexer` flag unset. Indexer service will not run.
Starting Sui validator with config: ClusterTestOpt {
     env: NewLocal,
     faucet_address: Some(
         "127.0.0.1:9123",
     ),
     fullnode_address: Some(
         "0.0.0.0:9000",
     ),
     epoch_duration_ms: Some(
         60000,
     ),
     indexer_address: None,
     use_indexer_v2: false,
     pg_address: postgres:*****@localhost:5432/sui_indexer,
     use_indexer_experimental_methods: false,
     config_dir: None,
     graphql_address: None,
}

2023-12-25T02:06:48.877869Z INFO sui_node: no http kv store url provided, using local db only
2023-12-25T02:06:48.883592Z INFO sui_node: Sui JSON-RPC server listening on 127.0.0.1:9000 local_addr=127.0.0.1:9000
2023-12-25T02:06:48.883669Z INFO sui_node: SuiNode started!

I execute on the server with IP address 192.168.6.6

curl --location --request POST 'http://127.0.0.1:9000' \
--header 'Content-Type: application/json' \
--data-raw '{
   "jsonrpc": "2.0",
   "id": 1,
   "method": "sui_getTotalTransactionBlocks",
   "params": []
}'
{"jsonrpc":"2.0","result":"5","id":1}

This is ok, but I execute curl --location --request POST 'http://192.168.6.6:9000' \ --header 'Content-Type: application/json' \ --data-raw '{ "jsonrpc": "2.0", "id": 1, "method": "sui_getTotalTransactionBlocks", "params": [] }'
on my mac, this will not return any results. I can ensure that my mac can normally access the server with IP address 192.168.6.6, and the server's port 9000 is open.

@thaonx
Copy link
Author

thaonx commented Dec 26, 2023

@thaonx @stefan-mysten I am using the latest code and this problem still exists. Have you verified it?

Starting Sui validator with config: ClusterTestOpt {
    env: NewLocal,
    faucet_address: Some(
        "127.0.0.1:9123",
    ),
    fullnode_address: Some(
        "0.0.0.0:9000",
    ),
    epoch_duration_ms: Some(
        60000,
    ),
    indexer_address: None,
    use_indexer_v2: false,
    pg_address: postgres:*****@localhost:5432/sui_indexer,
    use_indexer_experimental_methods: false,
    config_dir: None,
    graphql_address: None,
}

Fullnode RPC URL: http://127.0.0.1:9000
Faucet URL: http://0.0.0.0:9123

hi @qpb8023, I havn't tried this yet, still waiting for the release. But I have found alternative solution to start a Localnet in docker. Just run sui genesis then sui start , it listens on 0.0.0.0 by default.
I am not quite sure what is the difference with sui-test-validator, but it sui start works for me.

@stefan-mysten
Copy link
Contributor

stefan-mysten commented Dec 26, 2023

@thaonx @stefan-mysten I am using the latest code and this problem still exists. Have you verified it?

Starting Sui validator with config: ClusterTestOpt {
    env: NewLocal,
    faucet_address: Some(
        "127.0.0.1:9123",
    ),
    fullnode_address: Some(
        "0.0.0.0:9000",
    ),
    epoch_duration_ms: Some(
        60000,
    ),
    indexer_address: None,
    use_indexer_v2: false,
    pg_address: postgres:*****@localhost:5432/sui_indexer,
    use_indexer_experimental_methods: false,
    config_dir: None,
    graphql_address: None,
}

Fullnode RPC URL: http://127.0.0.1:9000
Faucet URL: http://0.0.0.0:9123

hi @qpb8023, I have tried this yet, still waiting for the release. But I have found alternative solution to start a Localnet in docker. Just run sui genesis then sui start , it listens on 0.0.0.0 by default. I am not quite sure what is the difference with sui-test-validator, it it works for me.

sui-test-validator starts a faucet too, so if you do not need a faucet @qpb8023 you can indeed use sui genesis and sui start.

In the near future we will merge the two commands as it is a bit confusing to users.

@thaonx
Copy link
Author

thaonx commented Dec 27, 2023

sui-test-validator starts a faucet too

I also start faucet in entrypoint.sh in the same docker container.

#!/bin/bash

# check if /root/.sui exists
if [ ! -d "/root/.sui" ]; then
    # create /root/.sui
    /usr/local/bin/sui genesis
fi

# start sui local network
echo "Starting Sui Localnet ..."
RUST_LOG="off,sui_node=info" /usr/local/bin/sui start &

while ! curl -s http://127.0.0.1:9000 > /dev/null; do echo Waiting for Sui Localnet ...; sleep 3; done
echo "Sui Localnet is ready!"

echo "Starting Sui Faucet ..."
/usr/local/bin/sui-faucet --num-coins 10  --write-ahead-log /tmp/sui-facucel.wal --host-ip 0.0.0.0 --port 9123 &

while ! curl -s http://127.0.0.1:9123 > /dev/null; do echo Waiting for Sui Faucet ...; sleep 3; done
echo "Sui Faucet is ready!"

wait

Either or you can start seperate container for faucet, just need change the RPC endpoint to [localnet container name]:9000

@stefan-mysten
Copy link
Contributor

@thaonx If I understand correctly, it works for you now.
@qpb8023 are you still encountering issues when following the other approach described by @thaonx?

@qpb8023
Copy link

qpb8023 commented Jan 3, 2024

@thaonx @stefan-mysten Run sui genesis then sui start its ok, but sui-test-validator --config-dir there are still problems. I can only call rpc on the machine where sui-test-validator is started. I can‘t call rpc on another computer to get a response.

@stefan-mysten
Copy link
Contributor

Thanks for confirming this. We have some upcoming work on these commands, so I put a note to have a look at this!

@tbocek
Copy link

tbocek commented Jan 30, 2024

I'm also running into this issue. It says:

local-sui-1 | Fullnode RPC URL: http://127.0.0.1:9000
local-sui-1 | Faucet URL: http://0.0.0.0:9123

And the commit fd09307 makes the Faucet work, but not yet the Fullnode RPC, which is still 127.0.0.1

@rony-arnac
Copy link

Hey, is there a plan to fix the 127.0.0.1 issue?

It's still not 0.0.0.0 :(

Keys saved as Base64 with 33 bytes flag || privkey ($BASE64_STR).
To see Bech32 format encoding, use sui keytool export $SUI_ADDRESS where
$SUI_ADDRESS can be found with sui keytool list. Or use sui keytool convert $BASE64_STR.
Fullnode RPC URL: http://127.0.0.1:9000
Keys saved as Base64 with 33 bytes flag || privkey ($BASE64_STR).
To see Bech32 format encoding, use sui keytool export $SUI_ADDRESS where
$SUI_ADDRESS can be found with sui keytool list. Or use sui keytool convert $BASE64_STR.
Faucet URL: http://0.0.0.0:9123

@stefan-mysten
Copy link
Contributor

stefan-mysten commented Jul 22, 2024

Sorry for the delay on this. Now sui start starts by default all services on 0.0.0.0 and their respective ports. See #18607.

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.

6 participants