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

Move chainspecs to a dedicated directory #1025

Merged
merged 7 commits into from
Nov 29, 2024
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ EXPOSE 30333 9933 9944
FROM $BASE_IMAGE AS subtensor

# Copy all chainspec files
COPY --from=builder /build/*.json /
COPY --from=builder /build/chainspecs/*.json /

# Copy final binary
COPY --from=builder /build/target/production/node-subtensor /usr/local/bin
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -105141,4 +105141,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@
}
}
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
84 changes: 60 additions & 24 deletions scripts/build_all_chainspecs.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,75 @@
#!/bin/bash

# The genesis is not allowed to change. Since the wasm genesis will change
# depending on the system architecture used, we need to extract the genesis from
# the old chain specs and insert them into the new chain specs to ensure there
# are no genesis mismatch issues.

# This script updates the chain spec files keeping the genesis unchanged.

set -e

echo "*** Building node..."
cargo build -p node-subtensor
raw_finney="chainspecs/raw_spec_finney.json"
plain_finney="chainspecs/plain_spec_finney.json"
raw_testfinney="chainspecs/raw_spec_testfinney.json"
plain_testfinney="chainspecs/plain_spec_testfinney.json"
raw_devnet="chainspecs/raw_spec_devnet.json"
plain_devnet="chainspecs/plain_spec_devnet.json"

save_genesis() {
jq -r ".genesis" "$1" >"$2"
}

buildspec() {
local chain="$1"
shift
./target/debug/node-subtensor build-spec --chain "$chain" --disable-default-bootnode "$@"
}

echo "*** Building new chainspecs..."
# Update genesis in new chainspecs using the extracted genesis data from the
# temporary files
update_genesis() {
jq --slurpfile genesis "$1" '.genesis = $genesis[0]' "$2" >"$3"
}

finney_genesis_temp=$(mktemp)
testfinney_genesis_temp=$(mktemp)
raw_spec_finney_temp=$(mktemp)
raw_spec_testfinney_temp=$(mktemp)
update_spec() {
local chain="$1"
local raw_path="$2"
local plain_path="$3"

# Save old genesis state before doing anything
jq -r ".genesis" raw_spec_finney.json >"$finney_genesis_temp"
jq -r ".genesis" raw_spec_testfinney.json >"$testfinney_genesis_temp"
raw_genesis_temp=$(mktemp)
plain_genesis_temp=$(mktemp)
raw_spec_temp=$(mktemp)
plain_spec_temp=$(mktemp)

# Build new chainspecs
./target/debug/node-subtensor build-spec --raw --chain finney >"$raw_spec_finney_temp"
./target/debug/node-subtensor build-spec --chain finney >plain_spec_finney.json
echo "*** Backing up genesis for '$chain'..."

./target/debug/node-subtensor build-spec --raw --chain test_finney >"$raw_spec_testfinney_temp"
./target/debug/node-subtensor build-spec --chain test_finney >plain_spec_testfinney.json
save_genesis "$raw_path" "$raw_genesis_temp"
save_genesis "$plain_path" "$plain_genesis_temp"

echo "*** Updating genesis..."
echo "*** Building new chainspec for '$chain'..."

# The genesis is not allowed to change. Since the wasm genesis will change depending on the system
# architecture used, we need to extract the genesis from the old chain specs and insert them into
# the new chain specs to ensure there are no genesis mismatch issues.
# Build new chainspecs
buildspec "$chain" >"$plain_spec_temp"
buildspec "$chain" --raw >"$raw_spec_temp"

# Update genesis in new chainspecs using the extracted genesis data from the temporary files
jq --slurpfile genesis "$finney_genesis_temp" '.genesis = $genesis[0]' "$raw_spec_finney_temp" >raw_spec_finney.json
jq --slurpfile genesis "$testfinney_genesis_temp" '.genesis = $genesis[0]' "$raw_spec_testfinney_temp" >raw_spec_testfinney.json
echo "*** Restoring genesis in '$chain'..."

update_genesis "$raw_genesis_temp" "$raw_spec_temp" "$raw_path"
update_genesis "$plain_genesis_temp" "$plain_spec_temp" "$plain_path"

# cleanup
rm -f "$raw_genesis_temp" "$plain_genesis_temp" "$raw_spec_temp" \
"$plain_spec_temp"
}

# SCRIPT

echo "*** Building node..."
cargo build -p node-subtensor

# Cleanup
rm -f "$finney_genesis_temp" "$testfinney_genesis_temp" "$raw_spec_finney_temp" "$raw_spec_testfinney_temp"
update_spec finney "$raw_finney" "$plain_finney"
update_spec test_finney "$raw_testfinney" "$plain_testfinney"
update_spec devnet "$raw_devnet" "$plain_devnet"

echo "*** Done!"
2 changes: 1 addition & 1 deletion scripts/run/subtensor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function run_command() {
# Command to run subtensor
$F_BIN_PATH \
--base-path /tmp/blockchain \
--chain ./raw_spec_finney.json \
--chain ./chainspecs/raw_spec_finney.json \
--rpc-external --rpc-cors all \
--no-mdns \
--rpc-max-connections 10000 --in-peers 500 --out-peers 500 \
Expand Down