inital commit, which is clearly not initial

Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
Uncle Stretch
2024-10-03 15:38:52 +03:00
commit 66719626bb
178 changed files with 41709 additions and 0 deletions

42
scripts/bags-generator.sh Executable file
View File

@@ -0,0 +1,42 @@
#!/bin/bash
set -e
runtime="casper"
bags=200
while getopts r:b:t:e: flag
do
case "${flag}" in
r) runtime=${OPTARG};;
b) bags=${OPTARG};;
t) total=${OPTARG};;
e) existential=${OPTARG};;
esac
done
if [[ -z "$total" ]]; then
echo "### ERROR: -t flag (total supply) should be set."
exit
fi
if [[ -z "$existential" ]]; then
echo "### ERROR: -e flag (existential deposit) should be set."
exit
fi
echo -e "### ${runtime} runtime will be used with ${bags} bags"
echo -e "### while total issuance is ${total} and existential deposit ${existential}"
read -p "### Do you want to regenerate 'bags_thresholds.rs' file? (Y/n)? " answer
if [ $answer != ${answer#[Yy]} ]; then
cargo run --package ghost-voter-bags -- \
--n-bags=${bags} \
--runtime=${runtime} \
--output=$PWD/runtime/${runtime}/src/bag_thresholds.rs \
--total-issuance=${total} \
--minimum-balance=${existential}
echo "### Bags generated succefully"
else
exit
fi

29
scripts/build-only-wasm.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/usr/bin/env sh
# Script for building only WASM binary of the given project.
set -e
PROJECT_ROOT=`git rev-parse -show-toplevel`
if [ "$#" -lt 1 ]; then
echo "You need to pass the name of the crate you want to compile!"
exit 1
fi
WASM_BUILDER_RUNNER="$PROJECT_ROOT/target/release/wbuild-runner/$1"
if [ -z "$2" ]; then
export WASM_TARGET_DIRECTORY=$(pwd)
else
export WASM_TARGET_DIRECTORY=$2
fi
if [ -d $WASM_BUILDER_RUNNER ]; then
export DEBUG=false
export OUT_DIR="$PROJECT_ROOT/target/release/build"
cargo run --release --manifest-path="$WASM_BUILDER_RUNNER/Cargo.toml" \
| grep -vE "cargo:rerun-if-|Executing build command"
else
cargo build --release -p $1
fi

18
scripts/common.sh Executable file
View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
ROOT=`dirname "$0"`
# A list of directories which contain wasm projects.
SRCS=(
"runtime/wasm"
)
# Make pushd/popd silent.
pushd () {
command pushd "$@" > /dev/null
}
popd () {
command popd "$@" > /dev/null
}

16
scripts/header-prefixer.sh Executable file
View File

@@ -0,0 +1,16 @@
#!/bin/sh
ROOT_PATH="${1:-}"
FILES=$(find ./"$ROOT_PATH" -type f -name '*.rs')
for f in $FILES; do
if (grep License $f); then
echo "[-] Already prefixed $f"
else
printf "\n" | cat file_header.txt - $f > $f.new
mv $f.new $f
echo "[+] License header copied to $f"
fi
done
echo "[+] All files have been processed"

48
scripts/prepare-test-net.sh Executable file
View File

@@ -0,0 +1,48 @@
#!/usr/bin/env bash
set -e
if [ "$#" -ne 1 ]; then
echo "Please provide the number of initial validators!"
exit 1
fi
generate_account_id() {
./target/release/ghostkey inspect ${3:-} ${4:-} "$SECRET//$1//$2" | grep "Account ID" | awk '{ print $3 }'
}
generate_address() {
./target/release/ghostkey inspect ${3:-} ${4:-} "$SECRET//$1//$2" | grep "SS58 Address" | awk '{ print $3 }'
}
generate_public_key() {
./target/release/ghostkey inspect ${3:-} ${4:-} "$SECRET//$1//$2" | grep "Public key (hex)" | awk '{ print $4 }'
}
generate_address_and_account_id() {
ACCOUNT=$(generate_account_id $1 $2 $3)
ADDRESS=$(generate_address $1 $2 $3)
if ${4:-false}; then
INTO="unchecked_into"
else
INTO="into"
fi
printf "//$ADDRESS\nhex![\"${ACCOUNT#'0x'}\"].$INTO(),"
}
V_NUM=$1
AUTHORITIES=""
for i in $(seq 1 $V_NUM); do
AUTHORITIES+="(\n"
AUTHORITIES+="$(generate_address_and_account_id $i stash)\n"
AUTHORITIES+="$(generate_address_and_account_id $i controller)\n"
AUTHORITIES+="$(generate_address_and_account_id $i babe '--scheme sr25519' true)\n"
AUTHORITIES+="$(generate_address_and_account_id $i grandpa '--scheme ed25519' true)\n"
AUTHORITIES+="$(generate_address_and_account_id $i authority_discovery '--scheme sr25519' true)\n"
AUTHORITIES+="$(generate_address_and_account_id $i slow_clap '--scheme sr25519' true)\n"
AUTHORITIES+="),\n"
done
printf "$AUTHORITIES"

29
scripts/release.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/use/bin/env bash
set -e
# This script is to be run when we are happy with release candidate.
# It accepts a single argument: version, in the format 'v1.2.3'
version="$1"
if [ -z "$version" ]; then
echo "No version specified, cannot continue"
exit 1
fi
if [[ ! "$version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Version should be in the format v1.2.3"
exit 1
fi
echo '[+] Checking out the release branch'
git checkout release
echo '[+] Pulling latest version of the release branch from github'
git pull
echo '[+] Attempting to merge the release-candidate branch to the release branch'
git merge "$version"
echo '[+] Tagging the release'
git tag -s -m "$version" "$version"
echo '[+] Pushing the release branch and tag to github. A new release will be created shortly'
git push origin release
git push origin "refs/tags/$version"

169
scripts/run-all-benches.sh Executable file
View File

@@ -0,0 +1,169 @@
#!/bin/bash
# This script has three parts which all use the Substrate runtime:
# - Pallet benchmarking to update the pallet weights
# - Overhead benchmarking for the Extrinsic and Block weight
# - Machine benchmarking
while getopts 'bfp:v' flag; do
case "${flag}" in
b)
# skip build
skip_build='true';;
f)
# fail in any sub-command in a pipe fails
set -o pipefail
# fail of undeclared variables
set -u
#fail if any sub-command fails
set -e
# fail on traps
set -E
;;
p)
# start at pallet
start_pallet="${OPTARG}"
;;
v)
# echo all executed commands
set -x
;;
*)
# exit early
echo "Bad options. Chech script"
exit 1
;;
esac
done
if [ "$skip_build" != true ]
then
echo "[+] Compiling Node with 'runtime-benchmarks' features"
cargo build --release --locked --features=runtime-benchmarks
fi
EXECUTABLE=./target/release/ghost
RUNTIME="casper"
EXCLUDED_PALLETS=(
# helper pallets
"pallet_election_provider_support_benchmarking"
# pallets without automatic benchmarking
# "pallet_babe"
# "pallet_grandpa"
"pallet_bags_list"
"frame_system"
"pallet_staking"
"pallet_offences"
)
# Load all pallet names in an array
ALL_PALLETS=($(
$EXECUTABLE benchmark pallet --list=pallets --no-csv-header --chain=${RUNTIME}-dev
))
# Filter out the excluded pallets by concatenating the arrays and discarding duplicates
PALLETS=($({ printf '%s\n' "${ALL_PALLETS[@]}" "${EXCLUDED_PALLETS[@]}"; } | sort | uniq -u))
echo "[+] Benchmarking ${#PALLETS[@]} pallets by excluding ${#EXCLUDED_PALLETS[@]} from ${#ALL_PALLETS[@]}"
# Define the error file
ERR_FILE="benchmarking_errors.txt"
# Delete the error file before each one
rm -f $ERR_FILE
for PALLET in "${PALLETS[@]}"; do
# If `-p` is used, skip benchmark until the start pallet.
if [ ! -z "$start_pallet" ] && [ "$start_pallet" != "$PALLET" ]
then
echo "[+] Skipping ${PALLET}..."
continue
else
unset start_pallet
fi
FOLDER="$(echo "${PALLET#*_}" | tr '_' '-')";
WEIGHT_FILE="./runtime/${RUNTIME}/src/weights/${PALLET}.rs"
echo "[+] Benchmarking $PALLET for $RUNTIME with weight file $WEIGHT_FILE";
OUTPUT=$(
$EXECUTABLE benchmark pallet \
--chain="${RUNTIME}-dev" \
--steps=50 \
--repeat=20 \
--pallet="$PALLET" \
--extrinsic="*" \
--wasm-execution=compiled \
--heap-pages=4096 \
--header=./file_header.txt \
--output=${WEIGHT_FILE} 2>&1
)
if [ $? -ne 0 ]; then
echo "$OUTPUT" >> "$ERR_FILE"
echo "[-] Failed to benchmark $PALLET. Error written to #ERR_FILE; continuing..."
fi
done
# # Update the block and extrinsic overhead weights
# echo "[+] Benchmarking block and extrinsic overheads..."
# OUTPUT=$(
# $EXECUTABLE benchmark overhead \
# --chain="${RUNTIME}-dev" \
# --wasm-execution=compiled \
# --weight-path="./runtime/${RUNTIME}/constants/src/weights/" \
# --header=./file_header.txt \
# --warmup=10 \
# --repeat=100 2>&1
# )
# if [ $? -ne 0 ]; then
# echo "$OUTPUT" >> "$ERR_FILE"
# echo "[-] Failed to benchmark the block and extrinsic weight. Error written to #ERR_FILE; continuing..."
# fi
#
# echo "[+] Benchmarking the machine..."
# OUTPUT=$(
# $EXECUTABLE benchmark machine --chain=${RUNTIME}-dev 2>&1
# )
# if [ $? -ne 0 ]; then
# # Do not write the error file since it is not a benchmarking error
# echo "[-] Failed the machine benchmark:\n$OUTPUT"
# fi
#
# echo "[+] Benchmarking the RocksDb storage..."
# OUTPUT=$(
# $EXECUTABLE benchmark storage \
# --chain="${RUNTIME}-dev" \
# --state-version=0 \
# --mul=1.1 \
# --weight-path="./runtime/${RUNTIME}/constants/src/weights/" \
# --header=./file_header.txt 2>&1
# )
# if [ $? -ne 0 ]; then
# echo "$OUTPUT" >> "$ERR_FILE"
# echo "[-] Failed to benchmark the RocksDb storage. Error written to $ERR_FILE; continuing..."
# fi
#
# echo "[+] Benchmarking the ParityDb storage..."
# OUTPUT=$(
# $EXECUTABLE benchmark storage \
# --chain="${RUNTIME}-dev" \
# --state-version=0 \
# --mul=1.1 \
# --database=paritydb \
# --weight-path="./runtime/${RUNTIME}/constants/src/weights/" \
# --header=./file_header.txt 2>&1
# )
# if [ $? -ne 0 ]; then
# echo "$OUTPUT" >> "$ERR_FILE"
# echo "[-] Failed to benchmark the ParityDb storage. Error written to $ERR_FILE; continuing..."
# fi
# Check if the error file exists
if [ -f "$ERR_FILE" ]; then
echo "[-] Some benchmarks failed. See: $ERR_FILE"
exit 1
else
echo "[+] All benchmarks passed"
exit 0
fi

16
scripts/run-local-network.sh Executable file
View File

@@ -0,0 +1,16 @@
#!/usr/bin/env bash
OFFSET="$2"
PORT=$((30333+OFFSET))
RPC_PORT=$((9933+OFFSET))
KEY=$((OFFSET+1))
NODE_KEY="000000000000000000000000000000000000000000000000000000000000000${KEY}"
./target/release/ghost \
--chain "casper-local" \
--tmp \
--port=${PORT} \
--rpc-port=${RPC_PORT} \
--rpc-cors all \
--node-key=${NODE_KEY} \
--"$1"

122
scripts/two-node-local-net.sh Executable file
View File

@@ -0,0 +1,122 @@
#!/usr/bin/env bash
# Run two node local net.
# Unlike the docker-compose script in the /docker folder, this version builds
# the nodes based on the current state of the code, instead of depending in a
# published version.
set -e
# chainspec defaults to ghost-local if no arguments are passed to this script;
# if arguments are passed in, the first is the chainspec
chainspec="${1:-ghost-local}"
# PROJECT_ROOT=$(git rev-parse --show-toplevel)
source "$(dirname "$0")"/common.sh
# cd "$PROJECT_ROOT"
last_modified_rust_file=$(
find . -path ./target -prune -o -type f -name '*.rs' -printf '%T@ %p\n' |
sort -nr |
head -1 |
cut -d' ' -f2-
)
ghost="target/release/ghost"
# ensure the ghost binary exists and is up to date
if [ ! -x "$ghost" ] || [ "$ghost" -ot "$last_modified_rust_file" ]; then
# cargo build --release
echo "[+] Build needed"
fi
# setup variables
node_offset=0
declare -a node_pids
declare -a node_pipes
# create a sed expression which injects the node name and stream type into
# each line
function make_sed_expr() {
name="$1"
type="$2"
printf "s/^/%8s %s: /" "$name" "$type"
}
# turn a string into a flag
function flagify() {
printf -- '--%s' "$(tr '[:upper:]' '[:lower:]' <<< "$1")"
}
# start a node and label its output
#
# this function takes a single argument, the node name.
# the name must be one of those which can be passed to the ghost binary, in
# un-flagged form, one of:
# alice, bob, charlie, dave, eve, ferdie, one, two
function run_node() {
name="$1"
# create a named pipe so we can get the node's PID while also sedding
# its output
local stdout
local stderr
stdout=$(mktemp --dry-run --tmpdir)
stderr=$(mktemp --dry-run --tmpdir)
mkfifo "$stdout"
mkfifo "$stderr"
node_pipes+=("$stdout")
node_pipes+=("$stderr")
# compute ports from offset
local port=$((30333+node_offset))
local rpc_port=$((9933+node_offset))
local ws_port=$((9944+node_offset))
node_offset=$((node_offset+1))
echo "$(flagify "$name")"
echo "--node-key 000000000000000000000000000000000000000000000000000000000000000${node_offset}"
# start the node
# "$ghost" \
# --chain "$chainspec" \
# --tmp \
# --port "$port" \
# --rpc-port "$rpc_port" \
# --rpc-cors all \
# --node-key 0000000000000000000000000000000000000000000000000000000000000001 \
# "$(flagify "$name")" \
# > "$stdout" \
# 2> "$stderr" \
# &
# local pid=$!
# node_pids+=("$pid")
#
# # send output from the stdout pipe to stdout, prepending the node name
# sed -e "$(make_sed_expr "$name" "OUT")" "$stdout" >&1 &
# # send output from the stderr pipe to stderr, prepending the none name
# sed -e "$(make_sed_expr "$name" "ERR")" "$stderr" >&2 &
}
# clean up the nodes when the script exits
function finish {
for node_pid in "${node_pids[@]}"; do
kill -9 "$node_pid"
done
for node_pipe in "${node_pipes[@]}"; do
rm "$node_pipe"
done
}
trap finish EXIT
# start the nodes
run_node Alice
run_node Bob
# now wait; this will exit on its own only if both subprocess exit
# the practical implication, as both subprocesses are supposed to run
# forever, is that this script will also run forever, until killed, ath which
# point the exit trap should kill the subprocesses
wait