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

Configuration of storage miners for the new transmission protocol version #55

Merged
merged 7 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 51 additions & 25 deletions scripts/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ set_node_mode() {
fi
}

function assign_ceseal_chain_to_local() {
#TODO: will deprecated in next version
yq -i eval "del(.node.chainWsUrl)" $config_file
function assign_ceseal_chain_to_local() {
yq -i eval ".ceseal.chainWsUrl=\"$local_chain_ws_url_in_docker\"" $config_file
}

Expand All @@ -138,9 +136,7 @@ function assign_miner_backup_chain_ws_urls() {
)
elif [[ $profile = "devnet" ]]; then
chain_urls=(
"wss://devnet-rpc.cess.cloud/ws-1/"
"wss://devnet-rpc.cess.cloud/ws/"
"wss://devnet-rpc.cess.cloud/ws-3/"
"wss://devnet-rpc.cess.network/ws/"
)
fi
if [[ -n $chain_urls ]]; then
Expand Down Expand Up @@ -280,10 +276,6 @@ function set_ceseal_endpoint() {
}

set_miner_chain_to_use() {
#TODO: will deprecated in next version
yq -i eval "del(.node.chainWsUrl)" $config_file
yq -i eval "del(.node.backupChainWsUrls)" $config_file

local current_external_chain=$(yq eval ".node.externalChain //0" $config_file)
local current_ws_url="$(yq eval ".miner.chainWsUrl //\"\"" $config_file)"
local prompt=
Expand All @@ -295,15 +287,17 @@ set_miner_chain_to_use() {

local to_set=
read -p "Enter cess rpc ws-url ($prompt): " to_set

if [[ -z $current_ws_url ]]; then
to_set='L'
fi
if [[ -z $to_set && ! -z $current_ws_url ]]; then
return
fi
local is_use_external_chain=
local url_value=
local is_local_to_external=
if [[ $to_set =~ ^[lL]?$ ]]; then
if [[ $current_external_chain -eq 0 ]]; then
if [[ $current_external_chain -eq 0 && ! -z $current_ws_url ]]; then
return
fi
is_use_external_chain=0
Expand Down Expand Up @@ -444,6 +438,46 @@ set_miner_port() {
done
}

set_miner_endpoint() {
local current="$(yq eval ".miner.apiendpoint //\"\"" $config_file)"
if [[ -z $current ]]; then
echo "Start configuring the endpoint to access Storage-Miner from the internet"
read -p " Do you need to automatically detect extranet address as endpoint? (y/n) " need_detect
if [[ $need_detect =~ ^[yY](es)?$ ]]; then
max_loop=3
for ((count = 0; count < max_loop; count++)); do
echo " Try to get your extranet IP ..."
local extIp=$(http_proxy= curl -fsSL ifconfig.net)
if [[ $? -eq 0 ]]; then
local port="$(yq eval ".miner.port //19999" $config_file)"
local endpoint="http://$extIp:$port"
echo " Your Storage-Miner endpoint is $endpoint"
yq -i eval ".miner.apiendpoint=\"$endpoint\"" $config_file
return 0
fi
done
if [ "$count" -eq "$max_loop" ]; then
echo " Failed to detect the extranet address." >&2
fi
fi
echo " You need to manually enter the endpoint."
fi
while true; do
if [ x"$current" != x"" ]; then
read -p "Enter cess storage API endpoint (current: $current, press enter to skip): " to_set
else
read -p "Enter cess storage API endpoint: " to_set
fi
to_set=$(echo "$to_set")
if [ x"$to_set" != x"" ]; then
yq -i eval ".miner.apiendpoint=\"$to_set\"" $config_file
break
elif [ x"$current" != x"" ]; then
break
fi
done
}

function set_miner_use_cpu_cores() {
local cpu_core_number=$(your_cpu_core_number)
local to_set=""
Expand Down Expand Up @@ -573,16 +607,6 @@ function pull_images_by_mode() {
return 0
}

function assign_miner_boot_addrs() {
local boot_domain="boot-miner-$profile.cess.cloud"
local boot_addr="_dnsaddr.$boot_domain"
if [ x"$mode" == x"storage" ]; then
yq -i eval ".miner.bootAddr=\"$boot_addr\"" $config_file
return 0
fi
return 1
}

function config_set_all() {
ensure_root

Expand All @@ -600,6 +624,7 @@ function config_set_all() {
assign_ceseal_chain_to_local
elif [ x"$mode" == x"storage" ]; then
set_miner_port
set_miner_endpoint
set_miner_chain_to_use
set_miner_income_account
set_miner_sign_phrase
Expand Down Expand Up @@ -686,7 +711,8 @@ config_generate() {
patch_wasm_override_if_testnet

if [[ $mode = "storage" ]]; then
assign_miner_boot_addrs
#TODO: will deprecated in next version
yq -i eval "del(.miner.bootAddr)" $config_file
assign_miner_backup_chain_ws_urls
fi

Expand Down Expand Up @@ -716,7 +742,7 @@ config_generate() {
cp -r $build_dir/.tmp/* $build_dir/

# change '["CMD", "nc", "-zv", "127.0.0.1", "15001"]' to ["CMD", "nc", "-zv", "127.0.0.1", "15001"] in docker-compose.yaml
yq eval '.' $build_dir/docker-compose.yaml | grep -n "test: " | awk '{print $1}'| cut -d':' -f1 | xargs -I {} sed -i "{}s/'//;{}s/\(.*\)'/\1/" $build_dir/docker-compose.yaml
yq eval '.' $build_dir/docker-compose.yaml | grep -n "test: " | awk '{print $1}' | cut -d':' -f1 | xargs -I {} sed -i "{}s/'//;{}s/\(.*\)'/\1/" $build_dir/docker-compose.yaml

rm -rf $build_dir/.tmp
local base_mode_path=/opt/cess/$mode
Expand Down Expand Up @@ -769,7 +795,7 @@ generate_node_key_if_need() {
local base_path="/opt/cess/data"
local image_tag=$profile
local chain_spec="cess-$profile"
docker run --rm -v $host_base_path:$base_path cesslab/cess-chain:$image_tag key generate-node-key --base-path $base_path --chain $chain_spec > /dev/null 2>&1
docker run --rm -v $host_base_path:$base_path cesslab/cess-chain:$image_tag key generate-node-key --base-path $base_path --chain $chain_spec >/dev/null 2>&1
}

patch_wasm_override_if_testnet() {
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

nodeadm_version="v0.5.10"
nodeadm_version="v0.6.0"
aliyun_address="region.cn-hangzhou.aliyuncs.com"

base_dir=/opt/cess/nodeadm
Expand Down