Skip to content

Commit 98ce91a

Browse files
committed
added more checks
1 parent bb49588 commit 98ce91a

File tree

1 file changed

+63
-13
lines changed

1 file changed

+63
-13
lines changed

pool_creation.sh

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,6 @@ setup_and_extract_keys() {
107107
account=$(echo "$output" | grep "SS58 Address:" | awk '{$1=$2=""; print $0}' | sed 's/^[ \t]*//;s/[ \t]*$//')
108108
echo "$account" > "$SECRET_DIR/account.txt"
109109
fi
110-
if [ ! -f "$SECRET_DIR/node_key.txt" ]; then
111-
output=$(./sugarfunge-node/target/release/sugarfunge-node key generate-node-key 2>&1)
112-
echo "$output"
113-
node_key=$(echo "$output" | tr ' ' '\n' | tail -n 1)
114-
echo "$node_key" > "$SECRET_DIR/node_key.txt"
115-
116-
node_peerid=$(echo "$output" | head -n 1)
117-
echo "$node_peerid" > "$SECRET_DIR/node_peerid.txt"
118-
fi
119110
}
120111

121112
# Function to insert keys into the node
@@ -248,6 +239,21 @@ setup_gofula_service() {
248239
echo "$gofula_service_file_path does not exist."
249240
fi
250241

242+
# Initialize go-fula and extract the blox peer ID
243+
init_output=$(/home/$USER/go-fula/go-fula --config /home/$USER/.fula/config.yaml --initOnly)
244+
blox_peer_id=$(echo "$init_output" | grep "blox peer ID" | awk '{print $5}')
245+
# Check if blox_peer_id is empty and exit with an error if it is
246+
if [ -z "$blox_peer_id" ]; then
247+
echo "Error: Failed to extract blox peer ID. Exiting."
248+
exit 1
249+
fi
250+
251+
echo "Extracted blox peer ID: $blox_peer_id"
252+
253+
# Save the blox peer ID to the file
254+
echo "$blox_peer_id" > "$SECRET_DIR/node_peerid.txt"
255+
echo "Blox peer ID saved to $SECRET_DIR/node_peerid.txt"
256+
251257
# Create the service file using the provided path
252258
sudo bash -c "cat > '$gofula_service_file_path'" << EOF
253259
[Unit]
@@ -403,6 +409,47 @@ verify_pool_creation() {
403409
fi
404410
}
405411

412+
generate_node_key() {
413+
config_path="/home/$USER/.fula/config.yaml"
414+
echo "Checking identity in $config_path..."
415+
416+
# Check if the identity field exists and has a value
417+
identity=$(yq e '.identity' "$config_path")
418+
419+
if [ -z "$identity" ]; then
420+
echo "Error: 'identity' field is missing or empty in $config_path."
421+
exit 1
422+
else
423+
echo "'identity' field is present in $config_path: $identity"
424+
new_key=$(/home/$USER/go-fula/go-fula --config "$config_path" --generateNodeKey | grep -E '^[a-f0-9]{64}$')
425+
426+
# Check if the node_key file exists and has different content
427+
if [ ! -f "$SECRET_DIR/node_key.txt" ] || [ "$new_key" != "$(cat $SECRET_DIR/node_key.txt)" ]; then
428+
echo "$new_key" > "$SECRET_DIR/node_key.txt"
429+
echo "Node key saved to $SECRET_DIR/node_key.txt"
430+
else
431+
echo "Node key file already exists and is up to date."
432+
fi
433+
434+
# Generate the peer ID from the node key
435+
generated_peer_id=$(./target/release/sugarfunge-node key inspect-node-key --file "$SECRET_DIR/node_key.txt")
436+
437+
# Read the stored peer ID from the file
438+
stored_peer_id=$(cat "$SECRET_DIR/node_peerid.txt")
439+
440+
# Compare the generated peer ID with the stored peer ID
441+
if [ "$generated_peer_id" != "$stored_peer_id" ]; then
442+
echo "Error: The generated peer ID does not match the stored peer ID."
443+
echo "Generated peer ID: $generated_peer_id"
444+
echo "Stored peer ID: $stored_peer_id"
445+
exit 1
446+
else
447+
echo "The generated peer ID matches the stored peer ID: $generated_peer_id"
448+
fi
449+
fi
450+
}
451+
452+
406453
check_services_status() {
407454
echo "Checking status of services..."
408455

@@ -485,7 +532,13 @@ main() {
485532

486533
# Generate a strong password and save it
487534
generate_password
488-
535+
536+
# Setup and start go-fula service
537+
setup_gofula_service
538+
539+
# Generate Peer ID for node
540+
generate_node_key
541+
489542
# Setup and extract keys
490543
setup_and_extract_keys
491544

@@ -504,9 +557,6 @@ main() {
504557
# Setup and start API service
505558
setup_api_service
506559

507-
# Setup and start go-fula service
508-
setup_gofula_service
509-
510560
cleanup
511561

512562
unset MASTER_SEED

0 commit comments

Comments
 (0)