[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