|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Check if `--no-purge` passed as a parameter |
| 4 | +NO_PURGE=0 |
| 5 | +for arg in "$@"; do |
| 6 | + if [ "$arg" = "--no-purge" ]; then |
| 7 | + NO_PURGE=1 |
| 8 | + break |
| 9 | + fi |
| 10 | +done |
| 11 | + |
| 12 | +# Determine the directory this script resides in. This allows invoking it from any location. |
| 13 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" |
| 14 | + |
| 15 | +# The base directory of the subtensor project |
| 16 | +BASE_DIR="$SCRIPT_DIR/.." |
| 17 | + |
| 18 | +# get parameters |
| 19 | +# Get the value of fast_blocks from the first argument |
| 20 | +fast_blocks=${1:-"True"} |
| 21 | + |
| 22 | +# Check the value of fast_blocks |
| 23 | +if [ "$fast_blocks" == "False" ]; then |
| 24 | + # Block of code to execute if fast_blocks is False |
| 25 | + echo "fast_blocks is Off" |
| 26 | + : "${CHAIN:=local}" |
| 27 | + : "${BUILD_BINARY:=1}" |
| 28 | + : "${FEATURES:="pow-faucet"}" |
| 29 | +else |
| 30 | + # Block of code to execute if fast_blocks is not False |
| 31 | + echo "fast_blocks is On" |
| 32 | + : "${CHAIN:=local}" |
| 33 | + : "${BUILD_BINARY:=1}" |
| 34 | + : "${FEATURES:="pow-faucet fast-blocks"}" |
| 35 | +fi |
| 36 | + |
| 37 | +SPEC_PATH="${SCRIPT_DIR}/specs/" |
| 38 | +FULL_PATH="$SPEC_PATH$CHAIN.json" |
| 39 | + |
| 40 | +# Kill any existing nodes which may have not exited correctly after a previous |
| 41 | +# run. |
| 42 | +pkill -9 'node-subtensor' |
| 43 | + |
| 44 | +if [ ! -d "$SPEC_PATH" ]; then |
| 45 | + echo "*** Creating directory ${SPEC_PATH}..." |
| 46 | + mkdir $SPEC_PATH |
| 47 | +fi |
| 48 | + |
| 49 | +if [[ $BUILD_BINARY == "1" ]]; then |
| 50 | + echo "*** Building substrate binary..." |
| 51 | + cargo build --profile=release --workspace --features "$FEATURES" --manifest-path "$BASE_DIR/Cargo.toml" |
| 52 | + echo "*** Binary compiled" |
| 53 | +fi |
| 54 | + |
| 55 | +echo "*** Building chainspec..." |
| 56 | +"$BASE_DIR/target/release/node-subtensor" build-spec --disable-default-bootnode --raw --chain $CHAIN >$FULL_PATH |
| 57 | +echo "*** Chainspec built and output to file" |
| 58 | + |
| 59 | +# generate node keys |
| 60 | +$BASE_DIR/target/release/node-subtensor key generate-node-key --chain="$FULL_PATH" --base-path ../chain-states/dev-state/alice |
| 61 | +$BASE_DIR/target/release/node-subtensor key generate-node-key --chain="$FULL_PATH" --base-path ../chain-states/dev-state/bob |
| 62 | + |
| 63 | +if [ $NO_PURGE -eq 1 ]; then |
| 64 | + echo "*** Purging previous state skipped..." |
| 65 | +else |
| 66 | + echo "*** Purging previous state..." |
| 67 | + "$BASE_DIR/target/release/node-subtensor" purge-chain -y --base-path ../chain-states/dev-state/bob --chain="$FULL_PATH" >/dev/null 2>&1 |
| 68 | + "$BASE_DIR/target/release/node-subtensor" purge-chain -y --base-path ../chain-states/dev-state/alice --chain="$FULL_PATH" >/dev/null 2>&1 |
| 69 | + echo "*** Previous chainstate purged" |
| 70 | +fi |
| 71 | + |
| 72 | +echo "*** Starting localnet nodes..." |
| 73 | +alice_start=( |
| 74 | + "$BASE_DIR/target/release/node-subtensor" |
| 75 | + --dev |
| 76 | + --base-path ../chain-states/dev-state/alice |
| 77 | + # --chain="$FULL_PATH" |
| 78 | + --alice |
| 79 | + --port 30334 |
| 80 | + --rpc-port 9944 |
| 81 | + --validator |
| 82 | + --rpc-cors=all |
| 83 | + --allow-private-ipv4 |
| 84 | + --discover-local |
| 85 | + --unsafe-force-node-key-generation |
| 86 | + --offchain-worker=Never |
| 87 | +) |
| 88 | + |
| 89 | +bob_start=( |
| 90 | + "$BASE_DIR"/target/release/node-subtensor |
| 91 | + --base-path ../chain-states/dev-state/bob |
| 92 | + --chain="$FULL_PATH" |
| 93 | + --bob |
| 94 | + --port 30335 |
| 95 | + --rpc-port 9945 |
| 96 | + --validator |
| 97 | + --rpc-cors=all |
| 98 | + --allow-private-ipv4 |
| 99 | + --discover-local |
| 100 | + --unsafe-force-node-key-generation |
| 101 | +) |
| 102 | + |
| 103 | +trap 'pkill -P $$' EXIT SIGINT SIGTERM |
| 104 | + |
| 105 | +( |
| 106 | + ("${alice_start[@]}" 2>&1) |
| 107 | + # ("${bob_start[@]}" 2>&1) |
| 108 | + wait |
| 109 | +) |
0 commit comments