-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy pathlocalnet.sh
More file actions
executable file
·146 lines (121 loc) · 3.82 KB
/
localnet.sh
File metadata and controls
executable file
·146 lines (121 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# If binaries are compiled in CI then skip this script
if [ -n "$BUILT_IN_CI" ]; then
echo "[*] BUILT_IN_CI is set to '$BUILT_IN_CI'. Skipping script..."
exit 0
fi
# Check if `--no-purge` passed as a parameter
NO_PURGE=0
# Check if `--build-only` passed as parameter
BUILD_ONLY=0
for arg in "$@"; do
if [ "$arg" = "--no-purge" ]; then
NO_PURGE=1
elif [ "$arg" = "--build-only" ]; then
BUILD_ONLY=1
fi
done
# Determine the directory this script resides in. This allows invoking it from any location.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
# The base directory of the subtensor project
BASE_DIR="$SCRIPT_DIR/.."
# Get the value of fast_runtime from the first argument
fast_runtime=${1:-"True"}
# Define the target directory for compilation
if [ "$fast_runtime" == "False" ]; then
# Block of code to execute if fast_runtime is False
echo "fast_runtime is Off"
: "${CHAIN:=local}"
: "${BUILD_BINARY:=1}"
: "${FEATURES:="pow-faucet"}"
BUILD_DIR="$BASE_DIR/target/non-fast-runtime"
else
# Block of code to execute if fast_runtime is not False
echo "fast_runtime is On"
: "${CHAIN:=local}"
: "${BUILD_BINARY:=1}"
: "${FEATURES:="pow-faucet fast-runtime"}"
BUILD_DIR="$BASE_DIR/target/fast-runtime"
fi
# Ensure the build directory exists
mkdir -p "$BUILD_DIR"
SPEC_PATH="${SCRIPT_DIR}/specs/"
FULL_PATH="$SPEC_PATH$CHAIN.json"
# Kill any existing nodes which may have not exited correctly after a previous run.
pkill -9 'node-subtensor'
if [ ! -d "$SPEC_PATH" ]; then
echo "*** Creating directory ${SPEC_PATH}..."
mkdir -p "$SPEC_PATH"
fi
if [[ "$BUILD_BINARY" == "1" ]]; then
echo "*** Building substrate binary..."
BUILD_CMD=(
cargo build
--workspace
--profile=release
--features "$FEATURES"
--manifest-path "$BASE_DIR/Cargo.toml"
)
if [[ -n "$CARGO_BUILD_TARGET" ]]; then
echo "[+] Cross-compiling for target: $CARGO_BUILD_TARGET"
BUILD_CMD+=(--target "$CARGO_BUILD_TARGET")
else
echo "[+] Building for host architecture"
fi
CARGO_TARGET_DIR="$BUILD_DIR" "${BUILD_CMD[@]}"
echo "*** Binary compiled"
fi
echo "*** Building chainspec..."
"$BUILD_DIR/release/node-subtensor" build-spec --disable-default-bootnode --raw --chain "$CHAIN" >"$FULL_PATH"
echo "*** Chainspec built and output to file"
# Generate node keys
"$BUILD_DIR/release/node-subtensor" key generate-node-key --chain="$FULL_PATH" --base-path /tmp/one
"$BUILD_DIR/release/node-subtensor" key generate-node-key --chain="$FULL_PATH" --base-path /tmp/two
if [ $NO_PURGE -eq 1 ]; then
echo "*** Purging previous state skipped..."
else
echo "*** Purging previous state..."
"$BUILD_DIR/release/node-subtensor" purge-chain -y --base-path /tmp/two --chain="$FULL_PATH" >/dev/null 2>&1
"$BUILD_DIR/release/node-subtensor" purge-chain -y --base-path /tmp/one --chain="$FULL_PATH" >/dev/null 2>&1
echo "*** Previous chainstate purged"
fi
if [ $BUILD_ONLY -eq 0 ]; then
echo "*** Starting localnet nodes..."
one_start=(
"$BUILD_DIR/release/node-subtensor"
--base-path /tmp/one
--chain="$FULL_PATH"
--one
--port 30334
--rpc-port 9944
--validator
--rpc-cors=all
--allow-private-ipv4
--discover-local
--unsafe-force-node-key-generation
)
two_start=(
"$BUILD_DIR/release/node-subtensor"
--base-path /tmp/two
--chain="$FULL_PATH"
--two
--port 30335
--rpc-port 9945
--validator
--rpc-cors=all
--allow-private-ipv4
--discover-local
--unsafe-force-node-key-generation
)
# Provide RUN_IN_DOCKER local environment variable if run script in the docker image
if [ "${RUN_IN_DOCKER}" == "1" ]; then
one_start+=(--unsafe-rpc-external)
two_start+=(--unsafe-rpc-external)
fi
trap 'pkill -P $$' EXIT SIGINT SIGTERM
(
("${one_start[@]}" 2>&1) &
("${two_start[@]}" 2>&1)
wait
)
fi