From f771a45f0093e75a481c191547f36b09556bdd9d Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 26 Nov 2024 19:36:12 +0100 Subject: [PATCH 1/7] Move chainspecs into a dedicated directory --- Dockerfile | 2 +- .../plain_spec_devnet.json | 0 .../plain_spec_finney.json | 0 .../plain_spec_testfinney.json | 0 .../raw_spec_devnet.json | 0 .../raw_spec_finney.json | 0 .../raw_spec_testfinney.json | 0 scripts/build_all_chainspecs.sh | 67 +++++++++++++------ scripts/run/subtensor.sh | 2 +- 9 files changed, 50 insertions(+), 21 deletions(-) rename plain_spec_devnet.json => chainspecs/plain_spec_devnet.json (100%) rename plain_spec_finney.json => chainspecs/plain_spec_finney.json (100%) rename plain_spec_testfinney.json => chainspecs/plain_spec_testfinney.json (100%) rename raw_spec_devnet.json => chainspecs/raw_spec_devnet.json (100%) rename raw_spec_finney.json => chainspecs/raw_spec_finney.json (100%) rename raw_spec_testfinney.json => chainspecs/raw_spec_testfinney.json (100%) diff --git a/Dockerfile b/Dockerfile index 9edb2749b..cb54646bb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/plain_spec_devnet.json b/chainspecs/plain_spec_devnet.json similarity index 100% rename from plain_spec_devnet.json rename to chainspecs/plain_spec_devnet.json diff --git a/plain_spec_finney.json b/chainspecs/plain_spec_finney.json similarity index 100% rename from plain_spec_finney.json rename to chainspecs/plain_spec_finney.json diff --git a/plain_spec_testfinney.json b/chainspecs/plain_spec_testfinney.json similarity index 100% rename from plain_spec_testfinney.json rename to chainspecs/plain_spec_testfinney.json diff --git a/raw_spec_devnet.json b/chainspecs/raw_spec_devnet.json similarity index 100% rename from raw_spec_devnet.json rename to chainspecs/raw_spec_devnet.json diff --git a/raw_spec_finney.json b/chainspecs/raw_spec_finney.json similarity index 100% rename from raw_spec_finney.json rename to chainspecs/raw_spec_finney.json diff --git a/raw_spec_testfinney.json b/chainspecs/raw_spec_testfinney.json similarity index 100% rename from raw_spec_testfinney.json rename to chainspecs/raw_spec_testfinney.json diff --git a/scripts/build_all_chainspecs.sh b/scripts/build_all_chainspecs.sh index 03727b728..29128be6c 100755 --- a/scripts/build_all_chainspecs.sh +++ b/scripts/build_all_chainspecs.sh @@ -2,38 +2,67 @@ set -e -echo "*** Building node..." -cargo build -p node-subtensor - -echo "*** Building new chainspecs..." +raw_finney="chainspecs/raw_spec_finney.json" +raw_testfinney="chainspecs/raw_spec_testfinney.json" +plain_finney="chainspecs/plain_spec_finney.json" +plain_testfinney="chainspecs/plain_spec_testfinney.json" finney_genesis_temp=$(mktemp) testfinney_genesis_temp=$(mktemp) raw_spec_finney_temp=$(mktemp) raw_spec_testfinney_temp=$(mktemp) +save_genesis() { + jq -r ".genesis" "$1" >"$2" +} + +buildspec() { + local chain="$1" + shift + ./target/debug/node-subtensor build-spec --chain "$chain" "$@" +} + +# 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" +} + +cleanup() { + rm -f "$finney_genesis_temp" \ + "$testfinney_genesis_temp" \ + "$raw_spec_finney_temp" \ + "$raw_spec_testfinney_temp" +} + +# SCRIPT + +echo "*** Building new chainspecs..." + +echo "*** Building node..." +cargo build -p node-subtensor + # 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" +save_genesis "$raw_finney" "$finney_genesis_temp" +save_genesis "$raw_testfinney" "$testfinney_genesis_temp" # 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 +buildspec finney --raw >"$raw_spec_finney_temp" +buildspec finney >"$plain_finney" -./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 +buildspec test_finney --raw >"$raw_spec_testfinney_temp" +buildspec test_finney >"$plain_testfinney" echo "*** Updating genesis..." -# 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. - -# 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 +# 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. +update_genesis "$finney_genesis_temp" "$raw_spec_finney_temp" "$raw_finney" +update_genesis "$testfinney_genesis_temp" "$raw_spec_testfinney_temp" \ + "$raw_testfinney" -# Cleanup -rm -f "$finney_genesis_temp" "$testfinney_genesis_temp" "$raw_spec_finney_temp" "$raw_spec_testfinney_temp" +cleanup echo "*** Done!" diff --git a/scripts/run/subtensor.sh b/scripts/run/subtensor.sh index 66ba32d3c..05baa7a76 100755 --- a/scripts/run/subtensor.sh +++ b/scripts/run/subtensor.sh @@ -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 \ From 4640bf815e5e3814d4a8bd44f5155af4501a5b94 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 27 Nov 2024 16:33:04 +0100 Subject: [PATCH 2/7] Fix build_all_chainspecs rewrite plain specs genesis --- scripts/build_all_chainspecs.sh | 70 +++++++++++++++++---------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/scripts/build_all_chainspecs.sh b/scripts/build_all_chainspecs.sh index 29128be6c..69393d247 100755 --- a/scripts/build_all_chainspecs.sh +++ b/scripts/build_all_chainspecs.sh @@ -1,17 +1,19 @@ #!/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 raw_finney="chainspecs/raw_spec_finney.json" -raw_testfinney="chainspecs/raw_spec_testfinney.json" plain_finney="chainspecs/plain_spec_finney.json" +raw_testfinney="chainspecs/raw_spec_testfinney.json" plain_testfinney="chainspecs/plain_spec_testfinney.json" -finney_genesis_temp=$(mktemp) -testfinney_genesis_temp=$(mktemp) -raw_spec_finney_temp=$(mktemp) -raw_spec_testfinney_temp=$(mktemp) - save_genesis() { jq -r ".genesis" "$1" >"$2" } @@ -28,41 +30,43 @@ update_genesis() { jq --slurpfile genesis "$1" '.genesis = $genesis[0]' "$2" >"$3" } -cleanup() { - rm -f "$finney_genesis_temp" \ - "$testfinney_genesis_temp" \ - "$raw_spec_finney_temp" \ - "$raw_spec_testfinney_temp" -} +update_spec() { + local chain="$1" + local raw_path="$2" + local plain_path="$3" -# SCRIPT + raw_genesis_temp=$(mktemp) + plain_genesis_temp=$(mktemp) + raw_spec_temp=$(mktemp) + plain_spec_temp=$(mktemp) -echo "*** Building new chainspecs..." + echo "*** Backing up genesis for '$chain'..." -echo "*** Building node..." -cargo build -p node-subtensor + save_genesis "$raw_path" "$raw_genesis_temp" + save_genesis "$plain_path" "$plain_genesis_temp" -# Save old genesis state before doing anything -save_genesis "$raw_finney" "$finney_genesis_temp" -save_genesis "$raw_testfinney" "$testfinney_genesis_temp" + echo "*** Building new chainspec for '$chain'..." -# Build new chainspecs -buildspec finney --raw >"$raw_spec_finney_temp" -buildspec finney >"$plain_finney" + # Build new chainspecs + buildspec "$chain" >"$plain_spec_temp" + buildspec "$chain" --raw >"$raw_spec_temp" -buildspec test_finney --raw >"$raw_spec_testfinney_temp" -buildspec test_finney >"$plain_testfinney" + echo "*** Restoring genesis in '$chain'..." -echo "*** Updating genesis..." + update_genesis "$raw_genesis_temp" "$raw_spec_temp" "$raw_path" + update_genesis "$plain_genesis_temp" "$plain_spec_temp" "$plain_path" -# 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. -update_genesis "$finney_genesis_temp" "$raw_spec_finney_temp" "$raw_finney" -update_genesis "$testfinney_genesis_temp" "$raw_spec_testfinney_temp" \ - "$raw_testfinney" + # 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 +update_spec finney "$raw_finney" "$plain_finney" +update_spec test_finney "$raw_testfinney" "$plain_testfinney" echo "*** Done!" From 55caaa34bfa9779c39981efafdaf7bd0f0401858 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 27 Nov 2024 16:46:20 +0100 Subject: [PATCH 3/7] Add devnet to chainspec generating script --- scripts/build_all_chainspecs.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/build_all_chainspecs.sh b/scripts/build_all_chainspecs.sh index 69393d247..b0f21b7a6 100755 --- a/scripts/build_all_chainspecs.sh +++ b/scripts/build_all_chainspecs.sh @@ -13,6 +13,8 @@ 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" @@ -68,5 +70,6 @@ cargo build -p node-subtensor update_spec finney "$raw_finney" "$plain_finney" update_spec test_finney "$raw_testfinney" "$plain_testfinney" +update_spec devnet "$raw_devnet" "$plain_devnet" echo "*** Done!" From 90338a7676800ff77ecde0d346cc82131111405f Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 27 Nov 2024 17:01:29 +0100 Subject: [PATCH 4/7] Update bootnode in testnet --- node/src/chain_spec/testnet.rs | 2 +- scripts/build_all_chainspecs.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/node/src/chain_spec/testnet.rs b/node/src/chain_spec/testnet.rs index a3b3d8b62..aee20ed99 100644 --- a/node/src/chain_spec/testnet.rs +++ b/node/src/chain_spec/testnet.rs @@ -51,7 +51,7 @@ pub fn finney_testnet_config() -> Result { ) .with_name("Bittensor") .with_boot_nodes(vec![ - "/dns/bootnode.test.chain.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr" + "/dns/bootnode.test.chain.opentensor.ai/tcp/30333/p2p/12D3KooWEKUzXbgbJzCnAGcCLFwcEbDBp9ixa3aVVgJ5smiX1fSJ" .parse() .unwrap(), ]) diff --git a/scripts/build_all_chainspecs.sh b/scripts/build_all_chainspecs.sh index b0f21b7a6..1e291b47f 100755 --- a/scripts/build_all_chainspecs.sh +++ b/scripts/build_all_chainspecs.sh @@ -23,7 +23,7 @@ save_genesis() { buildspec() { local chain="$1" shift - ./target/debug/node-subtensor build-spec --chain "$chain" "$@" + ./target/debug/node-subtensor build-spec --chain "$chain" --disable-default-bootnode "$@" } # Update genesis in new chainspecs using the extracted genesis data from the From 145919116b42a98f4b425ed4b8075cf82cea1751 Mon Sep 17 00:00:00 2001 From: ales-otf Date: Wed, 27 Nov 2024 17:10:58 +0000 Subject: [PATCH 5/7] Update chainspecs --- chainspecs/plain_spec_finney.json | 2 +- chainspecs/plain_spec_testfinney.json | 4 ++-- chainspecs/raw_spec_testfinney.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/chainspecs/plain_spec_finney.json b/chainspecs/plain_spec_finney.json index 78f340d6f..76b58a624 100644 --- a/chainspecs/plain_spec_finney.json +++ b/chainspecs/plain_spec_finney.json @@ -105141,4 +105141,4 @@ } } } -} \ No newline at end of file +} diff --git a/chainspecs/plain_spec_testfinney.json b/chainspecs/plain_spec_testfinney.json index b636180b9..07b2f1ed3 100644 --- a/chainspecs/plain_spec_testfinney.json +++ b/chainspecs/plain_spec_testfinney.json @@ -3,7 +3,7 @@ "id": "bittensor", "chainType": "Development", "bootNodes": [ - "/dns/bootnode.test.chain.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr" + "/dns/bootnode.test.chain.opentensor.ai/tcp/30333/p2p/12D3KooWEKUzXbgbJzCnAGcCLFwcEbDBp9ixa3aVVgJ5smiX1fSJ" ], "telemetryEndpoints": null, "protocolId": "bittensor", @@ -71,4 +71,4 @@ } } } -} \ No newline at end of file +} diff --git a/chainspecs/raw_spec_testfinney.json b/chainspecs/raw_spec_testfinney.json index 08eabf415..fa408eb9d 100644 --- a/chainspecs/raw_spec_testfinney.json +++ b/chainspecs/raw_spec_testfinney.json @@ -3,7 +3,7 @@ "id": "bittensor", "chainType": "Development", "bootNodes": [ - "/dns/bootnode.test.chain.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr" + "/dns/bootnode.test.chain.opentensor.ai/tcp/30333/p2p/12D3KooWEKUzXbgbJzCnAGcCLFwcEbDBp9ixa3aVVgJ5smiX1fSJ" ], "telemetryEndpoints": null, "protocolId": "bittensor", From b1fc5914fd8585c177a0398525662a5b0e6c3db1 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 27 Nov 2024 21:06:02 +0100 Subject: [PATCH 6/7] Bring back testnet bootnode --- node/src/chain_spec/testnet.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/chain_spec/testnet.rs b/node/src/chain_spec/testnet.rs index aee20ed99..a3b3d8b62 100644 --- a/node/src/chain_spec/testnet.rs +++ b/node/src/chain_spec/testnet.rs @@ -51,7 +51,7 @@ pub fn finney_testnet_config() -> Result { ) .with_name("Bittensor") .with_boot_nodes(vec![ - "/dns/bootnode.test.chain.opentensor.ai/tcp/30333/p2p/12D3KooWEKUzXbgbJzCnAGcCLFwcEbDBp9ixa3aVVgJ5smiX1fSJ" + "/dns/bootnode.test.chain.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr" .parse() .unwrap(), ]) From b55e3e166565a1ad2df740a20d6e7be8056896d5 Mon Sep 17 00:00:00 2001 From: ales-otf Date: Wed, 27 Nov 2024 20:12:56 +0000 Subject: [PATCH 7/7] Update chainspecs --- chainspecs/plain_spec_testfinney.json | 2 +- chainspecs/raw_spec_testfinney.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/chainspecs/plain_spec_testfinney.json b/chainspecs/plain_spec_testfinney.json index 07b2f1ed3..820acd6d3 100644 --- a/chainspecs/plain_spec_testfinney.json +++ b/chainspecs/plain_spec_testfinney.json @@ -3,7 +3,7 @@ "id": "bittensor", "chainType": "Development", "bootNodes": [ - "/dns/bootnode.test.chain.opentensor.ai/tcp/30333/p2p/12D3KooWEKUzXbgbJzCnAGcCLFwcEbDBp9ixa3aVVgJ5smiX1fSJ" + "/dns/bootnode.test.chain.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr" ], "telemetryEndpoints": null, "protocolId": "bittensor", diff --git a/chainspecs/raw_spec_testfinney.json b/chainspecs/raw_spec_testfinney.json index fa408eb9d..08eabf415 100644 --- a/chainspecs/raw_spec_testfinney.json +++ b/chainspecs/raw_spec_testfinney.json @@ -3,7 +3,7 @@ "id": "bittensor", "chainType": "Development", "bootNodes": [ - "/dns/bootnode.test.chain.opentensor.ai/tcp/30333/p2p/12D3KooWEKUzXbgbJzCnAGcCLFwcEbDBp9ixa3aVVgJ5smiX1fSJ" + "/dns/bootnode.test.chain.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr" ], "telemetryEndpoints": null, "protocolId": "bittensor",