diff --git a/utils/fork_mainnet.sh b/utils/fork_mainnet.sh new file mode 100644 index 00000000..5b403b29 --- /dev/null +++ b/utils/fork_mainnet.sh @@ -0,0 +1,2 @@ +#!/usr/bin/bash +./creditcoin-fork --bin target/release/sxt-node --orig chainspecs/raw/mainnet-spec.json --base dev --name "SxT Fork" -o sxt-fork.json --rpc wss://archive.mainnet.sxt.network:443 diff --git a/utils/fork_mainnet_local.sh b/utils/fork_mainnet_local.sh new file mode 100755 index 00000000..45219507 --- /dev/null +++ b/utils/fork_mainnet_local.sh @@ -0,0 +1,5 @@ +#!/usr/bin/bash +# This is an example command to fork a node running on localhost that is synced to SxT Mainnet. +# The fork will be based on dev, but maintain the state from SxT Mainnet allowing for tests of +# runtime upgrades and storage migrations +./creditcoin-fork --bin target/release/sxt-node --orig chainspecs/raw/mainnet-spec.json diff --git a/utils/test-runtime.sh b/utils/test-runtime.sh new file mode 100755 index 00000000..caf65836 --- /dev/null +++ b/utils/test-runtime.sh @@ -0,0 +1,69 @@ +#!/usr/bin/bash +# This script, assumes you are running from the root of the sxt-node project directory. It downloads the mainnet +# snapshot into a local docker container, runs the container, then executes the fork binary against the running +# container. + +# Where to find utility scripts that we'll use such as wait-for-node.sh +UTILS_DIR=utils + +# Download the snapshot into the docker container +docker run -it --rm \ + --platform linux/amd64 \ + -v sxt-mainnet-data:/data \ + --entrypoint=bash \ + ghcr.io/spaceandtimefdn/sxt-node:mainnet-v1.17.0 \ + -c ' + set -ex + # Optional step if you want to keep a backup of the old database, can be deleted later + if [ -d /data/chains ]; then + mv /data/chains $(mktemp -d -p /data backup.XXXX) + fi + + # Download and unpack the snapshot + if [ ! -d /data/chains ]; then + cd /data + curl -O "https://blocks.testnet.sxt.network/snapshots/2026-01-29/sxt-mainnet.tar.gz" + curl -O "https://blocks.testnet.sxt.network/snapshots/2026-01-29/sxt-mainnet.sha1" + sha1sum --check sxt-mainnet.sha1 + mkdir -p chains + tar xvf sxt-mainnet.tar.gz -C chains + rm sxt-mainnet.tar.gz sxt-mainnet.sha1 + cd - + fi + '; + +# Start a node from dockerfile with the mainnet chainspec, no peers, so that it does not progress. +# This is important for exporting the state without accidentally pruning it mid-export. +docker run -d --restart always \ + --platform linux/amd64 \ + -v sxt-mainnet-data:/data \ + -v sxt-validator-key:/key \ + -v sxt-node-key:/node-key \ + -p 30333:30333/tcp \ + -p 9615:9615/tcp \ + -p 9944:9944/tcp \ + --env HYPER_KZG_PUBLIC_SETUP_DIRECTORY=/data \ + ghcr.io/spaceandtimefdn/sxt-node:mainnet-v1.17.0 \ + --base-path /data \ + --chain /opt/chainspecs/mainnet-spec.json \ + --keystore-path /key \ + --hyper-kzg-public-setup-release-degree "02" \ + --hyper-kzg-public-setup-sha256 1821173e2452afb5ad77ff8ef740140cd5e57b9b847d8b6edb81e04897b1efe4 \ + --node-key-file /node-key/subkey.key; + +# Run 'wait-for-node.sh' +bash ${UTILS_DIR}/wait-for-node.sh; + +# download and run creditcoin-fork +if [ ! -f ./creditcoin-fork ]; then + echo "Downloading fork utility!"; + curl https://github.com/gluwa/creditcoin-fork/releases/download/0.2.1/creditcoin-fork -o creditcoin-fork; + chmod +x creditcoin-fork; +fi + +# Create the fork by exporting the state and writing it to a new chainspec file +./creditcoin-fork --bin target/release/sxt-node --orig chainspecs/raw/mainnet-spec.json -o fork.json; + +# Start a node with the newly forked chainspec as alice, so we produce blocks, and using the node binary +# that generated the chain spec +./target/release/sxt-node --chain fork.json --alice --unsafe-force-node-key-generation; diff --git a/utils/wait-for-node.sh b/utils/wait-for-node.sh new file mode 100755 index 00000000..a10fb793 --- /dev/null +++ b/utils/wait-for-node.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Wait for a Substrate node to be ready +# Note: both WS and HTTP are served via the same port +TARGET_URL=${1:-http://127.0.0.1:9944} +CURL_PARAMS="-H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' $TARGET_URL" + +COUNTER=0 +MAX_ATTEMPTS=50 + +# Make sure there is a node running at TARGET_URL +while [[ "$(eval curl -s -o /dev/null -w '%{http_code}' "$CURL_PARAMS")" != "200" && $COUNTER -lt $MAX_ATTEMPTS ]]; do + echo "INFO: $COUNTER - Node not ready yet..." + (( COUNTER=COUNTER+1 )) + sleep 50 +done + +if [ $COUNTER -ge $MAX_ATTEMPTS ]; then + echo "ERROR: Node did not become ready after $MAX_ATTEMPTS attempts" + exit 1 +fi + +# Verify we can actually get metadata +set -e +eval curl "$CURL_PARAMS" > /dev/null