chore: add current provisioning state before migration

This commit is contained in:
Jesús Pérez 2025-09-22 23:11:41 +01:00
parent a9703b4748
commit 50745b0f22
660 changed files with 88126 additions and 0 deletions

View file

@ -0,0 +1,96 @@
# Polkadot Solochain Environment Configuration
# Generated by provisioning system
POLKADOT_VERSION={{ polkadot_solochain.version }}
POLKADOT_RUN_USER={{ polkadot_solochain.run_user.name }}
POLKADOT_RUN_GROUP={{ polkadot_solochain.run_user.group }}
POLKADOT_RUN_USER_HOME={{ polkadot_solochain.run_user.home }}
POLKADOT_WORK_PATH={{ polkadot_solochain.work_path }}
POLKADOT_CONFIG_PATH={{ polkadot_solochain.config_path }}
POLKADOT_BIN_PATH={{ polkadot_solochain.bin_path }}
POLKADOT_NODE_BINARY={{ polkadot_solochain.node_binary }}
# Data and Storage Paths
POLKADOT_BASE_PATH={{ polkadot_solochain.base_path }}
POLKADOT_KEYSTORE_PATH={{ polkadot_solochain.keystore_path }}
# Network Configuration
POLKADOT_CHAIN={{ polkadot_solochain.network.chain_id }}
POLKADOT_NETWORK_NAME={{ polkadot_solochain.network.name }}
POLKADOT_LISTEN_ADDR="{{ polkadot_solochain.network.listen_addr }}"
{% if polkadot_solochain.network.public_addr is defined %}
POLKADOT_PUBLIC_ADDR="{{ polkadot_solochain.network.public_addr }}"
{% endif %}
{% if polkadot_solochain.network.node_key is defined %}
POLKADOT_NODE_KEY="{{ polkadot_solochain.network.node_key }}"
{% endif %}
POLKADOT_MAX_PEERS={{ polkadot_solochain.network.max_peers }}
POLKADOT_RESERVED_ONLY={{ polkadot_solochain.network.reserved_only | lower }}
# Bootnodes and Reserved Nodes
{% if polkadot_solochain.network.bootnodes %}
POLKADOT_BOOTNODES="{{ polkadot_solochain.network.bootnodes | join(',') }}"
{% endif %}
{% if polkadot_solochain.network.reserved_nodes %}
POLKADOT_RESERVED_NODES="{{ polkadot_solochain.network.reserved_nodes | join(',') }}"
{% endif %}
# RPC Configuration
POLKADOT_RPC_ENABLED={{ polkadot_solochain.rpc.enabled | lower }}
POLKADOT_RPC_BIND_ADDR={{ polkadot_solochain.rpc.bind_addr }}
POLKADOT_RPC_PORT={{ polkadot_solochain.rpc.port }}
POLKADOT_WS_PORT={{ polkadot_solochain.rpc.ws_port }}
POLKADOT_HTTP_PORT={{ polkadot_solochain.rpc.http_port }}
POLKADOT_RPC_MAX_CONNECTIONS={{ polkadot_solochain.rpc.max_connections }}
POLKADOT_RPC_CORS="{{ polkadot_solochain.rpc.cors | join(',') }}"
POLKADOT_RPC_METHODS="{{ polkadot_solochain.rpc.methods | join(',') }}"
# Consensus Configuration
POLKADOT_CONSENSUS_ALGORITHM={{ polkadot_solochain.consensus.algorithm }}
POLKADOT_FINALITY={{ polkadot_solochain.consensus.finality }}
POLKADOT_BLOCK_TIME={{ polkadot_solochain.consensus.block_time }}
POLKADOT_EPOCH_DURATION={{ polkadot_solochain.consensus.epoch_duration }}
# Runtime Configuration
POLKADOT_RUNTIME_NAME={{ polkadot_solochain.runtime.name }}
POLKADOT_RUNTIME_VERSION={{ polkadot_solochain.runtime.version }}
POLKADOT_PVM_ENABLED={{ polkadot_solochain.runtime.pvm_enabled | lower }}
POLKADOT_WASM_EXECUTION={{ polkadot_solochain.runtime.wasm_execution }}
POLKADOT_HEAP_PAGES={{ polkadot_solochain.runtime.heap_pages }}
POLKADOT_MAX_BLOCK_WEIGHT={{ polkadot_solochain.runtime.max_block_weight }}
POLKADOT_MAX_BLOCK_LENGTH={{ polkadot_solochain.runtime.max_block_length }}
# Execution and Performance
POLKADOT_EXECUTION_STRATEGY={{ polkadot_solochain.execution_strategy }}
{% if polkadot_solochain.wasm_runtime_overrides is defined %}
POLKADOT_WASM_RUNTIME_OVERRIDES={{ polkadot_solochain.wasm_runtime_overrides }}
{% endif %}
POLKADOT_PRUNING={{ polkadot_solochain.pruning }}
POLKADOT_STATE_CACHE_SIZE={{ polkadot_solochain.state_cache_size }}
# Logging Configuration
POLKADOT_LOG_LEVEL={{ polkadot_solochain.log_level }}
{% if polkadot_solochain.log_targets %}
POLKADOT_LOG_TARGETS="{{ polkadot_solochain.log_targets | join(',') }}"
{% endif %}
# Development and Validator Configuration
POLKADOT_DEV_MODE={{ polkadot_solochain.dev_mode | lower }}
POLKADOT_ALICE_VALIDATOR={{ polkadot_solochain.alice_validator | lower }}
# Validator Configuration
POLKADOT_VALIDATOR_ENABLED={{ polkadot_solochain.validator.enabled | lower }}
POLKADOT_KEY_TYPE={{ polkadot_solochain.validator.key_type }}
{% if polkadot_solochain.validator.session_keys is defined %}
POLKADOT_SESSION_KEYS="{{ polkadot_solochain.validator.session_keys }}"
{% endif %}
{% if polkadot_solochain.validator.validator_id is defined %}
POLKADOT_VALIDATOR_ID="{{ polkadot_solochain.validator.validator_id }}"
{% endif %}
# Telemetry Configuration
POLKADOT_TELEMETRY_ENABLED={{ polkadot_solochain.telemetry.enabled | lower }}
{% if polkadot_solochain.telemetry.url is defined %}
POLKADOT_TELEMETRY_URL="{{ polkadot_solochain.telemetry.url }}"
{% endif %}
POLKADOT_TELEMETRY_VERBOSITY={{ polkadot_solochain.telemetry.verbosity }}

View file

@ -0,0 +1,156 @@
#!/bin/bash
# Info: Script to generate and manage Polkadot solochain keys
# Author: Provisioning System
set -e
POLKADOT_BIN_PATH="{{ polkadot_solochain.bin_path }}"
POLKADOT_NODE_BINARY="{{ polkadot_solochain.node_binary }}"
POLKADOT_BASE_PATH="{{ polkadot_solochain.base_path }}"
POLKADOT_CONFIG_PATH="{{ polkadot_solochain.config_path }}"
POLKADOT_RUN_USER="{{ polkadot_solochain.run_user.name }}"
CHAIN_SPEC_FILE="{{ polkadot_solochain.config_path }}/{{ polkadot_solochain.network.chain_id }}.json"
echo "Polkadot Solochain Key Management"
echo "================================="
# Function to generate Aura keys
generate_aura_key() {
local seed="$1"
local name="$2"
echo "Generating Aura key for $name..."
sudo -u "$POLKADOT_RUN_USER" "$POLKADOT_BIN_PATH/$POLKADOT_NODE_BINARY" key insert \
--base-path "$POLKADOT_BASE_PATH" \
--chain "$CHAIN_SPEC_FILE" \
--scheme Sr25519 \
--suri "$seed" \
--key-type aura \
--password-interactive < /dev/null
}
# Function to generate GRANDPA keys
generate_grandpa_key() {
local seed="$1"
local name="$2"
echo "Generating GRANDPA key for $name..."
sudo -u "$POLKADOT_RUN_USER" "$POLKADOT_BIN_PATH/$POLKADOT_NODE_BINARY" key insert \
--base-path "$POLKADOT_BASE_PATH" \
--chain "$CHAIN_SPEC_FILE" \
--scheme Ed25519 \
--suri "$seed" \
--key-type gran \
--password-interactive < /dev/null
}
# Function to generate session keys
generate_session_keys() {
echo "Generating session keys..."
# Generate random session keys
AURA_SEED="$(openssl rand -hex 32)"
GRANDPA_SEED="$(openssl rand -hex 32)"
# Insert keys
generate_aura_key "0x$AURA_SEED" "validator"
generate_grandpa_key "0x$GRANDPA_SEED" "validator"
# Save seeds for reference
echo "AURA_SEED=0x$AURA_SEED" > "$POLKADOT_CONFIG_PATH/validator-seeds"
echo "GRANDPA_SEED=0x$GRANDPA_SEED" >> "$POLKADOT_CONFIG_PATH/validator-seeds"
chmod 600 "$POLKADOT_CONFIG_PATH/validator-seeds"
chown "$POLKADOT_RUN_USER:$POLKADOT_RUN_USER" "$POLKADOT_CONFIG_PATH/validator-seeds"
echo "Session keys generated and saved to $POLKADOT_CONFIG_PATH/validator-seeds"
}
# Function to generate development keys (Alice, Bob, etc.)
generate_dev_keys() {
echo "Setting up development keys..."
# Alice
generate_aura_key "//Alice" "Alice"
generate_grandpa_key "//Alice" "Alice"
# Bob (if needed for multi-node setup)
if [ "$1" = "multi" ]; then
generate_aura_key "//Bob" "Bob"
generate_grandpa_key "//Bob" "Bob"
# Charlie
generate_aura_key "//Charlie" "Charlie"
generate_grandpa_key "//Charlie" "Charlie"
fi
echo "Development keys configured"
}
# Function to list existing keys
list_keys() {
echo "Listing existing keys in keystore..."
if [ -d "$POLKADOT_BASE_PATH/chains/{{ polkadot_solochain.network.chain_id }}/keystore" ]; then
ls -la "$POLKADOT_BASE_PATH/chains/{{ polkadot_solochain.network.chain_id }}/keystore"
else
echo "No keystore found at $POLKADOT_BASE_PATH/chains/{{ polkadot_solochain.network.chain_id }}/keystore"
fi
}
# Function to show public keys
show_public_keys() {
echo "Extracting public keys..."
if command -v jq >/dev/null 2>&1; then
# Extract public keys from chain spec if available
if [ -f "$CHAIN_SPEC_FILE" ]; then
echo "Aura authorities:"
jq -r '.genesis.runtime.aura.authorities[]?' "$CHAIN_SPEC_FILE" 2>/dev/null || echo "No Aura authorities found"
echo "GRANDPA authorities:"
jq -r '.genesis.runtime.grandpa.authorities[]?[0]' "$CHAIN_SPEC_FILE" 2>/dev/null || echo "No GRANDPA authorities found"
fi
else
echo "jq not available - install jq to extract public keys from chain spec"
fi
}
# Main command handling
case "${1:-help}" in
"session")
generate_session_keys
;;
"dev")
generate_dev_keys "${2:-single}"
;;
"list")
list_keys
;;
"public")
show_public_keys
;;
"clean")
echo "Removing all keys from keystore..."
if [ -d "$POLKADOT_BASE_PATH/chains/{{ polkadot_solochain.network.chain_id }}/keystore" ]; then
sudo -u "$POLKADOT_RUN_USER" rm -rf "$POLKADOT_BASE_PATH/chains/{{ polkadot_solochain.network.chain_id }}/keystore"/*
echo "Keystore cleaned"
else
echo "No keystore found"
fi
;;
"help"|*)
echo "Usage: $0 [command]"
echo ""
echo "Commands:"
echo " session Generate random session keys for validator"
echo " dev [multi] Generate development keys (Alice, Bob, Charlie if multi)"
echo " list List existing keys in keystore"
echo " public Show public keys from chain specification"
echo " clean Remove all keys from keystore"
echo " help Show this help message"
echo ""
echo "Examples:"
echo " $0 dev # Generate Alice keys for development"
echo " $0 dev multi # Generate Alice, Bob, Charlie keys"
echo " $0 session # Generate random validator keys"
echo " $0 list # Show current keystore contents"
;;
esac

View file

@ -0,0 +1,245 @@
#!/bin/bash
# Info: Script to install Polkadot Solochain
# Author: Provisioning System
# Release: 1.0
# Date: 2025-07-24
USAGE="install-polkadot-solochain.sh"
[ "$1" == "-h" ] && echo "$USAGE" && exit 1
[ -r "env-polkadot-solochain" ] && . ./env-polkadot-solochain
POLKADOT_VERSION=${POLKADOT_VERSION:-stable2024}
POLKADOT_TEMPLATE_REPO="https://github.com/paritytech/polkadot-sdk-solochain-template.git"
POLKADOT_RUN_USER=${POLKADOT_RUN_USER:-polkadot}
POLKADOT_RUN_GROUP=${POLKADOT_RUN_GROUP:-polkadot}
POLKADOT_RUN_USER_HOME=${POLKADOT_RUN_USER_HOME:-/home/polkadot}
POLKADOT_WORK_PATH=${POLKADOT_WORK_PATH:-/var/lib/polkadot}
POLKADOT_CONFIG_PATH=${POLKADOT_CONFIG_PATH:-/etc/polkadot}
POLKADOT_BIN_PATH=${POLKADOT_BIN_PATH:-/usr/local/bin}
POLKADOT_NODE_BINARY=${POLKADOT_NODE_BINARY:-solochain-template-node}
POLKADOT_BUILD_PATH="/opt/polkadot-solochain-build"
POLKADOT_BASE_PATH=${POLKADOT_BASE_PATH:-/var/lib/polkadot/data}
POLKADOT_KEYSTORE_PATH=${POLKADOT_KEYSTORE_PATH:-/var/lib/polkadot/keystore}
POLKADOT_SYSTEMCTL_MODE=${POLKADOT_SYSTEMCTL_MODE:-enabled}
echo "Installing Polkadot Solochain ${POLKADOT_VERSION}..."
# Install system dependencies
echo "Installing system dependencies..."
if command -v apt-get >/dev/null 2>&1; then
apt-get update
apt-get install -y curl git build-essential pkg-config libssl-dev protobuf-compiler clang cmake
elif command -v yum >/dev/null 2>&1; then
yum groupinstall -y "Development Tools"
yum install -y curl git openssl-devel protobuf-compiler clang cmake pkg-config
elif command -v dnf >/dev/null 2>&1; then
dnf groupinstall -y "Development Tools"
dnf install -y curl git openssl-devel protobuf-compiler clang cmake pkg-config
else
echo "Package manager not found. Please install dependencies manually."
exit 1
fi
# Install Rust if not present
if ! command -v rustc >/dev/null 2>&1; then
echo "Installing Rust..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
rustup default stable
rustup target add wasm32-unknown-unknown
fi
# Create user and group
if ! id "$POLKADOT_RUN_USER" &>/dev/null; then
groupadd -r "$POLKADOT_RUN_GROUP"
useradd -r -g "$POLKADOT_RUN_GROUP" -d "$POLKADOT_RUN_USER_HOME" -s /bin/bash -c "Polkadot service user" "$POLKADOT_RUN_USER"
fi
# Create directories
mkdir -p "$POLKADOT_CONFIG_PATH"
mkdir -p "$POLKADOT_WORK_PATH"
mkdir -p "$POLKADOT_BASE_PATH"
mkdir -p "$POLKADOT_KEYSTORE_PATH"
mkdir -p "$POLKADOT_RUN_USER_HOME"
mkdir -p "$POLKADOT_BUILD_PATH"
# Clone and build Polkadot solochain template
echo "Cloning Polkadot solochain template..."
cd "$POLKADOT_BUILD_PATH"
if [ ! -d "polkadot-sdk-solochain-template" ]; then
git clone "$POLKADOT_TEMPLATE_REPO" polkadot-sdk-solochain-template
fi
cd polkadot-sdk-solochain-template
# Checkout specific version if needed
if [ "$POLKADOT_VERSION" != "stable2024" ] && [ "$POLKADOT_VERSION" != "latest" ]; then
git checkout "$POLKADOT_VERSION" || echo "Version $POLKADOT_VERSION not found, using default branch"
fi
echo "Building Polkadot solochain node (this may take 20-30 minutes)..."
export RUST_LOG=info
# Build the node
cargo build --release
if [ ! -f "target/release/$POLKADOT_NODE_BINARY" ]; then
echo "Failed to build Polkadot solochain node"
exit 1
fi
# Install binary
echo "Installing binary..."
cp "target/release/$POLKADOT_NODE_BINARY" "$POLKADOT_BIN_PATH/"
chmod +x "$POLKADOT_BIN_PATH/$POLKADOT_NODE_BINARY"
# Create chain specification if not exists
echo "Generating chain specification..."
if [ ! -f "$POLKADOT_CONFIG_PATH/local-testnet.json" ]; then
cd "$POLKADOT_BUILD_PATH/polkadot-sdk-solochain-template"
# Generate raw chain spec
"$POLKADOT_BIN_PATH/$POLKADOT_NODE_BINARY" build-spec --disable-default-bootnode --chain local > "$POLKADOT_CONFIG_PATH/local-testnet-plain.json"
"$POLKADOT_BIN_PATH/$POLKADOT_NODE_BINARY" build-spec --chain "$POLKADOT_CONFIG_PATH/local-testnet-plain.json" --raw --disable-default-bootnode > "$POLKADOT_CONFIG_PATH/local-testnet.json"
fi
# Create node key if not exists
if [ ! -f "$POLKADOT_CONFIG_PATH/node-key" ] && [ -z "$POLKADOT_NODE_KEY" ]; then
echo "Generating node key..."
openssl rand -hex 32 > "$POLKADOT_CONFIG_PATH/node-key"
fi
# Create runtime configuration
cat > "$POLKADOT_CONFIG_PATH/runtime-config.json" << EOF
{
"name": "${POLKADOT_RUNTIME_NAME:-solochain-template}",
"version": "${POLKADOT_RUNTIME_VERSION:-1.0.0}",
"pvm_enabled": ${POLKADOT_PVM_ENABLED:-true},
"wasm_execution": "${POLKADOT_WASM_EXECUTION:-compiled}",
"heap_pages": ${POLKADOT_HEAP_PAGES:-64}
}
EOF
# Set ownership
chown -R "$POLKADOT_RUN_USER:$POLKADOT_RUN_GROUP" "$POLKADOT_WORK_PATH"
chown -R "$POLKADOT_RUN_USER:$POLKADOT_RUN_GROUP" "$POLKADOT_BASE_PATH"
chown -R "$POLKADOT_RUN_USER:$POLKADOT_RUN_GROUP" "$POLKADOT_KEYSTORE_PATH"
chown -R "$POLKADOT_RUN_USER:$POLKADOT_RUN_GROUP" "$POLKADOT_RUN_USER_HOME"
chown -R "$POLKADOT_RUN_USER:$POLKADOT_RUN_GROUP" "$POLKADOT_CONFIG_PATH"
# Create systemd service file
cat > /etc/systemd/system/polkadot-solochain.service << EOF
[Unit]
Description=Polkadot Solochain Node
Documentation=https://docs.polkadot.com/
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=$POLKADOT_RUN_USER
Group=$POLKADOT_RUN_GROUP
EnvironmentFile=$POLKADOT_CONFIG_PATH/node.env
WorkingDirectory=$POLKADOT_WORK_PATH
ExecStart=$POLKADOT_BIN_PATH/$POLKADOT_NODE_BINARY \\
--base-path $POLKADOT_BASE_PATH \\
--chain $POLKADOT_CONFIG_PATH/local-testnet.json \\
--port 30333 \\
--rpc-port ${POLKADOT_RPC_PORT:-9944} \\
--rpc-bind-addr ${POLKADOT_RPC_BIND_ADDR:-127.0.0.1} \\
--validator \\
--name \${POLKADOT_NODE_NAME:-SolochainNode} \\
--execution ${POLKADOT_EXECUTION_STRATEGY:-wasm} \\
--state-cache-size ${POLKADOT_STATE_CACHE_SIZE:-67108864} \\
--log ${POLKADOT_LOG_LEVEL:-info}
Restart=always
RestartSec=10
# Security settings
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=$POLKADOT_WORK_PATH $POLKADOT_BASE_PATH $POLKADOT_KEYSTORE_PATH $POLKADOT_CONFIG_PATH
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
# Resource limits
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
# Create environment file for systemd service
cat > "$POLKADOT_CONFIG_PATH/node.env" << EOF
POLKADOT_NODE_NAME=${POLKADOT_NETWORK_NAME:-SolochainNode}
RUST_LOG=${POLKADOT_LOG_LEVEL:-info}
EOF
# Load additional environment variables from template if available
if [ -f "env-polkadot-solochain" ]; then
cat env-polkadot-solochain >> "$POLKADOT_CONFIG_PATH/node.env"
fi
# Initialize keys for development if in dev mode
if [ "${POLKADOT_DEV_MODE:-false}" = "true" ] || [ "${POLKADOT_ALICE_VALIDATOR:-false}" = "true" ]; then
echo "Setting up development keys..."
sudo -u "$POLKADOT_RUN_USER" "$POLKADOT_BIN_PATH/$POLKADOT_NODE_BINARY" key insert \
--base-path "$POLKADOT_BASE_PATH" \
--chain "$POLKADOT_CONFIG_PATH/local-testnet.json" \
--scheme Sr25519 \
--suri "//Alice" \
--key-type aura \
--password-interactive < /dev/null || true
sudo -u "$POLKADOT_RUN_USER" "$POLKADOT_BIN_PATH/$POLKADOT_NODE_BINARY" key insert \
--base-path "$POLKADOT_BASE_PATH" \
--chain "$POLKADOT_CONFIG_PATH/local-testnet.json" \
--scheme Ed25519 \
--suri "//Alice" \
--key-type gran \
--password-interactive < /dev/null || true
fi
# Enable and start service
systemctl daemon-reload
systemctl "$POLKADOT_SYSTEMCTL_MODE" polkadot-solochain.service
if [ "$POLKADOT_SYSTEMCTL_MODE" = "enabled" ]; then
systemctl start polkadot-solochain.service
# Wait a moment for service to start
sleep 5
fi
echo "Polkadot Solochain installation completed!"
echo "Service: polkadot-solochain.service"
echo "RPC endpoint: ws://${POLKADOT_RPC_BIND_ADDR:-127.0.0.1}:${POLKADOT_RPC_PORT:-9944}"
echo "HTTP RPC endpoint: http://${POLKADOT_RPC_BIND_ADDR:-127.0.0.1}:${POLKADOT_HTTP_PORT:-9933}"
echo "Configuration: $POLKADOT_CONFIG_PATH/"
echo "Data directory: $POLKADOT_BASE_PATH"
echo "Keystore: $POLKADOT_KEYSTORE_PATH"
echo ""
echo "Connect with Polkadot-JS Apps:"
echo "https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F${POLKADOT_RPC_BIND_ADDR:-127.0.0.1}%3A${POLKADOT_RPC_PORT:-9944}"
# Display service status
if systemctl is-active --quiet polkadot-solochain.service; then
echo "✅ Polkadot solochain service is running"
else
echo "⚠️ Polkadot solochain service status:"
systemctl status polkadot-solochain.service --no-pager -l
fi
# Cleanup build directory if requested
if [ "${POLKADOT_CLEANUP_BUILD:-false}" = "true" ]; then
echo "Cleaning up build directory..."
rm -rf "$POLKADOT_BUILD_PATH"
fi

View file

@ -0,0 +1,77 @@
[Unit]
Description=Polkadot Solochain Node with PVM Support
Documentation=https://docs.polkadot.com/
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User={{ polkadot_solochain.run_user.name }}
Group={{ polkadot_solochain.run_user.group }}
EnvironmentFile={{ polkadot_solochain.config_path }}/node.env
WorkingDirectory={{ polkadot_solochain.work_path }}
ExecStart={{ polkadot_solochain.bin_path }}/{{ polkadot_solochain.node_binary }} \
--base-path {{ polkadot_solochain.base_path }} \
--chain {{ polkadot_solochain.config_path }}/{{ polkadot_solochain.network.chain_id }}.json \
--name {{ polkadot_solochain.network.name }} \
--listen-addr {{ polkadot_solochain.network.listen_addr }} \
{% if polkadot_solochain.network.public_addr is defined %}
--public-addr {{ polkadot_solochain.network.public_addr }} \
{% endif %}
--rpc-port {{ polkadot_solochain.rpc.ws_port }} \
--rpc-bind-addr {{ polkadot_solochain.rpc.bind_addr }} \
--rpc-cors {{ polkadot_solochain.rpc.cors | join(',') }} \
--rpc-methods {{ polkadot_solochain.rpc.methods | join(',') }} \
--max-peers {{ polkadot_solochain.network.max_peers }} \
--execution {{ polkadot_solochain.execution_strategy }} \
--state-cache-size {{ polkadot_solochain.state_cache_size }} \
--pruning {{ polkadot_solochain.pruning }} \
{% if polkadot_solochain.runtime.pvm_enabled %}
--wasm-execution {{ polkadot_solochain.runtime.wasm_execution }} \
{% endif %}
{% if polkadot_solochain.validator.enabled %}
--validator \
{% endif %}
{% if polkadot_solochain.network.reserved_only %}
--reserved-only \
{% endif %}
{% if polkadot_solochain.network.bootnodes %}
{% for bootnode in polkadot_solochain.network.bootnodes %}
--bootnode {{ bootnode }} \
{% endfor %}
{% endif %}
{% if polkadot_solochain.network.reserved_nodes %}
{% for reserved in polkadot_solochain.network.reserved_nodes %}
--reserved-node {{ reserved }} \
{% endfor %}
{% endif %}
{% if polkadot_solochain.telemetry.enabled and polkadot_solochain.telemetry.url is defined %}
--telemetry-url "{{ polkadot_solochain.telemetry.url }} {{ polkadot_solochain.telemetry.verbosity }}" \
{% endif %}
{% if polkadot_solochain.dev_mode %}
--dev \
{% endif %}
--log {{ polkadot_solochain.log_level }}
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
RestartSec=10
# Security settings
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths={{ polkadot_solochain.work_path }} {{ polkadot_solochain.base_path }} {{ polkadot_solochain.keystore_path }} {{ polkadot_solochain.config_path }}
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
# Resource limits
LimitNOFILE=65536
{% if polkadot_solochain.runtime.pvm_enabled %}
# Additional memory for PVM operations
MemoryMax=4G
{% endif %}
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,146 @@
#!/bin/bash
# Info: Polkadot Solochain preparation script
# Author: Provisioning System
# Release: 1.0
echo "Preparing Polkadot Solochain installation..."
# Load environment variables
[ -r "env-polkadot-solochain" ] && . ./env-polkadot-solochain
# Check if required tools are available
command -v curl >/dev/null 2>&1 || { echo "curl is required but not installed." >&2; exit 1; }
command -v git >/dev/null 2>&1 || { echo "git is required but not installed." >&2; exit 1; }
command -v systemctl >/dev/null 2>&1 || { echo "systemctl is required but not installed." >&2; exit 1; }
# Check if Rust is available or if we need to install it
if ! command -v rustc >/dev/null 2>&1; then
echo "Rust not found - will be installed during setup"
else
RUST_VERSION=$(rustc --version | awk '{print $2}')
echo "Found Rust version: $RUST_VERSION"
fi
# Check for essential build tools
if ! command -v gcc >/dev/null 2>&1 && ! command -v clang >/dev/null 2>&1; then
echo "No C compiler found. GCC or Clang is required for building."
fi
# Validate configuration
if [ -z "$POLKADOT_VERSION" ]; then
echo "POLKADOT_VERSION must be set" >&2
exit 1
fi
# Check available disk space (Polkadot build requires significant space)
AVAILABLE_SPACE=$(df /opt 2>/dev/null | awk 'NR==2 {print $4}' || echo "0")
REQUIRED_SPACE=5000000 # 5GB in KB
if [ "$AVAILABLE_SPACE" -ne "0" ] && [ "$AVAILABLE_SPACE" -lt "$REQUIRED_SPACE" ]; then
echo "Warning: Low disk space. Polkadot build requires at least 5GB free space."
echo "Available: $(($AVAILABLE_SPACE / 1024))MB, Required: $(($REQUIRED_SPACE / 1024))MB"
fi
# Check available memory (Rust compilation is memory intensive)
if command -v free >/dev/null 2>&1; then
FREE_MEMORY=$(free -m | awk '/^Mem:/{print $7}')
if [ "$FREE_MEMORY" -lt 2048 ]; then
echo "Warning: Less than 2GB of free memory. Polkadot compilation may be slow or fail."
echo "Consider adding swap space or using a machine with more RAM."
fi
fi
# Check port availability
RPC_PORT=${POLKADOT_RPC_PORT:-9944}
WS_PORT=${POLKADOT_WS_PORT:-9944}
HTTP_PORT=${POLKADOT_HTTP_PORT:-9933}
P2P_PORT=30333
for port in $RPC_PORT $WS_PORT $HTTP_PORT $P2P_PORT; do
if command -v netstat >/dev/null 2>&1; then
if netstat -tuln | grep -q ":$port "; then
echo "Warning: Port $port appears to be in use"
fi
elif command -v ss >/dev/null 2>&1; then
if ss -tuln | grep -q ":$port "; then
echo "Warning: Port $port appears to be in use"
fi
fi
done
# Validate network configuration
if [ -n "$POLKADOT_PUBLIC_ADDR" ]; then
echo "Public address configured: $POLKADOT_PUBLIC_ADDR"
fi
if [ -n "$POLKADOT_BOOTNODES" ]; then
echo "Bootnodes configured: $POLKADOT_BOOTNODES"
fi
# Validate runtime configuration
if [ "${POLKADOT_PVM_ENABLED:-true}" = "true" ]; then
echo "PVM (Polkadot Virtual Machine) support enabled"
fi
case "${POLKADOT_WASM_EXECUTION:-compiled}" in
"compiled"|"interpreted")
echo "WASM execution mode: ${POLKADOT_WASM_EXECUTION}"
;;
*)
echo "Invalid WASM execution mode: ${POLKADOT_WASM_EXECUTION}" >&2
exit 1
;;
esac
# Validate consensus configuration
case "${POLKADOT_CONSENSUS_ALGORITHM:-aura}" in
"aura"|"babe")
echo "Consensus algorithm: ${POLKADOT_CONSENSUS_ALGORITHM}"
;;
*)
echo "Invalid consensus algorithm: ${POLKADOT_CONSENSUS_ALGORITHM}" >&2
exit 1
;;
esac
# Check development mode settings
if [ "${POLKADOT_DEV_MODE:-false}" = "true" ]; then
echo "Development mode enabled - Alice validator keys will be configured"
fi
# Validate validator configuration
if [ "${POLKADOT_VALIDATOR_ENABLED:-false}" = "true" ]; then
echo "Validator mode enabled"
if [ -z "$POLKADOT_SESSION_KEYS" ] && [ "${POLKADOT_DEV_MODE:-false}" != "true" ]; then
echo "Warning: Validator enabled but no session keys configured"
fi
fi
# Check telemetry configuration
if [ "${POLKADOT_TELEMETRY_ENABLED:-false}" = "true" ]; then
if [ -z "$POLKADOT_TELEMETRY_URL" ]; then
echo "Warning: Telemetry enabled but no URL configured"
else
echo "Telemetry enabled: $POLKADOT_TELEMETRY_URL"
fi
fi
# Validate pruning configuration
case "${POLKADOT_PRUNING:-256}" in
"archive"|[0-9]*)
echo "Pruning configuration: ${POLKADOT_PRUNING}"
;;
*)
echo "Invalid pruning configuration: ${POLKADOT_PRUNING}" >&2
exit 1
;;
esac
echo "Preparation completed successfully."
echo ""
echo "Build information:"
echo "- This installation will clone and build the Polkadot solochain template"
echo "- Build time: 20-30 minutes on modern hardware"
echo "- PVM support: ${POLKADOT_PVM_ENABLED:-true}"
echo "- Consensus: ${POLKADOT_CONSENSUS_ALGORITHM:-aura} + ${POLKADOT_FINALITY:-grandpa}"
echo "- RPC ports: ${RPC_PORT} (WS), ${HTTP_PORT} (HTTP)"
echo "- Data path: ${POLKADOT_BASE_PATH:-/var/lib/polkadot/data}"

View file

@ -0,0 +1,2 @@
info = "polkadot-solochain"
release = "1.0"

View file

@ -0,0 +1,52 @@
# Polkadot Virtual Machine (PVM) Runtime Configuration
# Generated by provisioning system
[runtime]
name = "{{ polkadot_solochain.runtime.name }}"
version = "{{ polkadot_solochain.runtime.version }}"
pvm_enabled = {{ polkadot_solochain.runtime.pvm_enabled | lower }}
[execution]
wasm_execution = "{{ polkadot_solochain.runtime.wasm_execution }}"
native_execution_available = true
heap_pages = {{ polkadot_solochain.runtime.heap_pages }}
[limits]
max_block_weight = {{ polkadot_solochain.runtime.max_block_weight }}
max_block_length = {{ polkadot_solochain.runtime.max_block_length }}
max_extrinsic_weight = {{ (polkadot_solochain.runtime.max_block_weight * 0.75) | int }}
[pallets]
{% for pallet in polkadot_solochain.runtime.pallets %}
{{ pallet }} = true
{% endfor %}
{% if polkadot_solochain.runtime.pvm_enabled %}
[pvm]
# Polkadot Virtual Machine specific configurations
enabled = true
version = "1.0"
# PVM execution parameters
max_code_size = 2097152 # 2MB
max_heap_pages = {{ polkadot_solochain.runtime.heap_pages }}
max_stack_size = 1048576 # 1MB
max_memory_pages = 1024
# WebAssembly runtime parameters
wasm_instantiation_strategy = "legacy-instance-reuse"
wasm_bulk_memory = true
wasm_reference_types = false
wasm_simd = false
wasm_multi_value = true
# Runtime cache configuration
runtime_cache_size = 8
{% endif %}
[performance]
state_cache_size = {{ polkadot_solochain.state_cache_size }}
database_cache = 128
{% if polkadot_solochain.wasm_runtime_overrides is defined %}
wasm_runtime_overrides_dir = "{{ polkadot_solochain.wasm_runtime_overrides }}"
{% endif %}