¶ Mysten Sui RPC endpoint detailsThis is a general guide on deploying an Mysten Sui RPC endpoint. |
As the ports for json RPC connectivity can vary between networks/clients, the default values for an Mysten Sui node are:
http://<your_ip_address>:9000
Before we can get our Mysten Sui node running, we need to install some necessary software.
we'll install some packages that we'll need or will at least be handy to have.
sudo apt install curl tzdata git ca-certificates build-essential libssl-dev pkg-config libclang-dev cmakewget jq node-ws telnet traceroute
Official Rust and Cargo docs available here.
(please don't blindly pipe stuff into bash, please verify the link to official docs above)
Run the below command to install Rust and Cargo.
curl https://sh.rustup.rs -sSf | sh
Verify installation by querying for version
cargo --version
With Rust and Cargo installed, we'll create some directories to stay organized and download the necessary packages
Create some new directories in your home directory so that we can keep our files organized.
mkdir -p /home/$USER/suiData/genesisFiles
mkdir /home/$USER/suiData/suidb && chown -R $USER: /home/$USER/suiData
Next, clone the MystemLabs/sui repository
git clone https://github.com/MystenLabs/sui.git
Next, change into the newly cloned directory
cd sui
In this next step, we will need to pay attention to which branch we checkout. in the included examples, we will be running a devnet node. You may want to specify testnet or just stick with the main branch.
git remote add upstream https://github.com/MystenLabs/sui
git fetch upstream
git checkout -B devnet --track upstream/devnet
create the configuration file at ~/suiData/fullnode.yaml
touch ~/suiData/fullnode.yaml
Then copy over the below and edit as necessary
# Update this value to the location you want Sui to store its database
db-path: "/home/$USER/suiData/suidb"
# 0.0.0.0 Sets the service to listen on any address.
network-address: "/dns/$YOUR.PUBLIC.IP.ADDRESS/tcp/8080/http"
metrics-address: "0.0.0.0:9184"
json-rpc-address: "0.0.0.0:9000"
# P2P Configurations
p2p-config:
listen-address: "0.0.0.0:9000"
seed-peers:
# Uncomment the one that is closest to where your node is hosted
# Amsterdam
# - address: /dns/ams-suifn-ss1.testnet.sui.io/udp/8084
# Singapore
# - address: /dns/sgp-suifn-ss2.testnet.sui.io/udp/8084
# Seoul
# - address: /dns/icn-suifn-ss3.testnet.sui.io/udp/8084
# Chicago:
# - address: "/dns/ord-suifn-ss4.testnet.sui.io/udp/8084"
# Set listening config
external-address: "/ip4/$YOUR.PUBLIC.IP.ADDRESS/udp/9000"
anemo-config:
# maximum number of peers you'd like your node to have connections with
max-concurrent-connections: 25
# Path to genesis file
genesis:
# Update this to the location of where the genesis file is stored
genesis-file-location: "/home/$USER/suiData/genesisFiles/genesis.blob"
# Enable pruning
# Uncomment the below lines if you'd like to enable pruning
# authority-store-pruning-config:
# objects-num-latest-versions-to-retain: 5
# objects-pruning-period-secs: 86400
# objects-pruning-initial-delay-secs: 3600
# num-latest-epoch-dbs-to-retain: 3
# epoch-db-pruning-period-secs: 3600
# enable-live-pruner: true
With the fullnode.yaml file created, we will need to download the genesis.blob file
Again, pay special attention to which genesis file you download. The example below is for devnet
Parent level genesis repository available here.
wget -O ~/suiData/genesisFiles/genesis.blob https://github.com/MystenLabs/sui-genesis/raw/main/devnet/genesis.blob
Compile the sui-node binary
bash -c '/home/$USER/.cargo/bin/cargo build --verbose --release -p sui-node'
Compile the (optional, but recommended) sui binary
bash -c '/home/$USER/.cargo/bin/cargo build --verbose --release -p sui'
Check/verify the installed version of your binaries
bash -c '/home/$USER/sui/target/release/sui --version'
Assuming all is well, we can continue on to creating our suid service
Create a service file at /etc/systemd/system/suid.service
nano /etc/systemd/system/suid.service
Copy and paste the below, modifying what is necessary
[Unit]
Description=Mysten Sui Node
After=network.target auditd.service
Wants=network.target
[Service]
Type=simple
User=$USER
WorkingDirectory=/home/$USER/sui/
TimeoutStartSec=0
TimeoutStopSec=120
ExecStart=/home/$USER/sui/target/release/sui-node --config-path /home/$USER/suiData/fullnode.yaml
Restart=always
RestartSec=20s
[Install]
WantedBy=multi-user.target
RequiredBy=swarm.service
Alias=suid.service
Once we have the service file created, we can start it with a simple command, but first, we'll reload our daemons to be sure that it detects the newly created service file.
sudo systemctl daemon-reload
Then,
sudo systemctl enable suid.service
sudo systemctl start suid.service
You can check the logs for the suid.service with journalctl
sudo journalctl -f -u suid.service
In the last section (below) we give an example bash script that will show the status of your Mysten Sui node.
If we want to check the status/state of the endpoints sync, we can simply query the RPC endpoint to see if the node is bootstrapped.
#!/bin/bash
# bold
b=$(tput bold)
# blue foreground
blue_fg=$(tput setaf 6)
# reset to default
reset=$(tput sgr0)
query_checkpoint() {
curl -q localhost:9184/metrics 2>/dev/null |grep '^highest_synced_checkpoint'
}
calculate_average() {
echo "Calculating average over 15s..."
# Get block height at 2s intervals
INTERVAL_00=$(curl -s --location --request POST 127.0.0.1:9000/ --header 'Content-Type: application/json' --data-raw '{ "jsonrpc":"2.0", "method":"sui_getTotalTransactionNumber","id":1
}' | jq -r .result)
sleep 5s
INTERVAL_01=$(curl -s --location --request POST 127.0.0.1:9000/ --header 'Content-Type: application/json' --data-raw '{ "jsonrpc":"2.0", "method":"sui_getTotalTransactionNumber","id":1
}' | jq -r .result)
sleep 5s
INTERVAL_02=$(curl -s --location --request POST 127.0.0.1:9000/ --header 'Content-Type: application/json' --data-raw '{ "jsonrpc":"2.0", "method":"sui_getTotalTransactionNumber","id":1
}' | jq -r .result)
sleep 5s
INTERVAL_03=$(curl -s --location --request POST 127.0.0.1:9000/ --header 'Content-Type: application/json' --data-raw '{ "jsonrpc":"2.0", "method":"sui_getTotalTransactionNumber","id":1
}' | jq -r .result)
#Calculate difference between each interval
COUNT_00=$((INTERVAL_03 - INTERVAL_02))
COUNT_01=$((INTERVAL_02 - INTERVAL_01))
COUNT_02=$((INTERVAL_01 - INTERVAL_00))
# Calculate average
SUM=$((COUNT_00 + COUNT_01 + COUNT_02))
COUNT=15
AVERAGE=$(echo $SUM / $COUNT | bc -l)
echo "Average blocks-per-second: ${blue_fg}$AVERAGE${reset}."
}
current_block() {
CURRENT_BLOCK=$(curl -s --location --request POST 127.0.0.1:9000/ --header 'Content-Type: application/json' --data-raw '{ "jsonrpc":"2.0", "method":"sui_getTotalTransactionNumber","id"
:1}' | jq -r .result)
echo "${blue_fg}$CURRENT_BLOCK${reset}"
}
echo "---------"
echo "${b}Highest Checkpoint:${reset}"
query_checkpoint
echo "---------"
echo "${b}Initial Block Height:${reset}"
current_block
echo "---------"
echo "${b}Average Blocks Per Second:${reset}"
calculate_average
echo "---------"
echo "${b}Current Block Height:${reset}"
current_block
echo "---------"
If you want to save the above as a bash script, you can run it whenever you like to see the status of your Mysten Sui node.