# Setting up Snark Stopper

## Description

The script will be useful for those who run the Block Producer and Snark Worker on the same server. Worker uses all your CPU cores 100%, which negatively affects the block producer. The script allows you to stop the Worker Snark 3 minutes before the block is produced and turn it on again after 10 minutes.

{% hint style="info" %}
This script was created by the user @whataday2day#1271\
<https://github.com/c29r3/mina-snark-stopper>
{% endhint %}

## Preparation

### Install JSON

```
sudo apt install jq -y
```

### Install the git package if it is not installed on the server:

```
yes | sudo apt install git
```

{% hint style="info" %}
Your snark worker should be RUNNING.
{% endhint %}

Check the config file. There are several options that you can remap.

Unblock the private network:

```
sudo iptables -D OUTPUT -d 172.16.0.0/12 -j DROP
```

### 1. Install without Docker:

{% hint style="info" %}
You need to run in a new TMUX session
{% endhint %}

```
sudo apt-get update \
&& sudo apt-get install python3-venv tmux git -y \
&& git clone https://github.com/c29r3/mina-snark-stopper.git \
&& cd mina-snark-stopper \
&& python3 -m venv venv \
&& source ./venv/bin/activate \
&& pip3 install -r requirements.txt
```

Now you need to add your public key and Worker fee to the stopper config. Open the config with the command:

```
nano $HOME/mina-snark-stopper/config.yml
```

In the `WORKER_PUB_KEY: YOUR_PUBLIC_KEY` line, change `YOUR_PUBLIC_KEY` to `$MINA_PUBLIC_KEY` In the line `WORKER_FEE: 1`, replace the commission value, for example, from 1 to 0.025&#x20;

Done.

### 1.1 Run

```
tmux new -s snark-stopper -d venv/bin/python3 snark-stopper.py
```

Logs:

```
tmux attach -t snark-stopper
```

### 2. Install with Docker:

Download the config file:

```
curl -s https://raw.githubusercontent.com/c29r3/mina-snark-stopper/master/config.yml > config.yml; \
touch snark_stopper.log
```

Now you need to add your public key and Worker commission to the stopper config. \
Open the config with the command:

```
nano $HOME/config.yml
```

In the `WORKER_PUB_KEY: YOUR_PUBLIC_KEY` line, change `YOUR_PUBLIC_KEY` to `$MINA_PUBLIC_KEY` In the line `WORKER_FEE: 1`, replace the commission value, for example, from 1 to 0.025&#x20;

Run container:

```
touch snark_stopper.log; \
chmod 666 snark_stopper.log; \
sudo docker run -d \
--volume $(pwd)/config.yml:/mina/config.yml \
--volume $(pwd)/snark_stopper.log:/mina/snark_stopper.log \
--net=host \
--restart always \
--name snark-stopper \
c29r3/snark-stopper
```

Logs:

```
sudo docker logs -f snark-stopper
```

### 3. Troubleshooting

If the snark-stopper can't connect to port `3085`:

Check port availability:

```
nc -t -vv localhost 3085
```

Output should be something like this:\
`Connection to localhost 3085 port [tcp/*] succeeded!`

If the connection hangs, then the following options are possible:

* Access to port `3085` is blocked via ufw\iptables
* You did not add a docker container flag `-p 127.0.0.1:3085:3085`
* Node is not synced yet. For this reason the stopper can't connect

Port responds, but the stopper still can't connect:

```
sudo iptables -D OUTPUT -d 172.16.0.0/12 -j DROP
```

it's because of the blocking of private subnets that the docker uses.

**Update docker image**

After running the command below, go to step 2

```
sudo docker rm -f snark-stopper \
&& sudo docker pull c29r3/snark-stopper
```

### 4. How to Update

Delete the config file and container and download the new image:

```
sudo docker rm -f snark-stopper; \
curl -s https://raw.githubusercontent.com/c29r3/mina-snark-stopper/master/config.yml > config.yml; \
sudo docker pull c29r3/snark-stopper
```

Then we continue from point 1 or 2.

### 5. Uninstall

```
rm -rf mina-snark-stopper \
&& sudo docker rm -f snark-stopper \
&& sudo docker system prune -af
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://minanode.staketab.com/english/setting-up-snark-stopper.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
