# StateSync

## Instruction

#### Create a shell script as \`sync.sh\`

```
#!/bin/bash

SNAP_RPC="https://migaloo-rpc.kalia.network:443"

LATEST_HEIGHT=$(curl -s $SNAP_RPC/block | jq -r .result.block.header.height); \
BLOCK_HEIGHT=$((LATEST_HEIGHT - 2000)); \
TRUST_HASH=$(curl -s "$SNAP_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)

sed -i.bak -E "s|^(enable[[:space:]]+=[[:space:]]+).*$|\1true| ; \
s|^(rpc_servers[[:space:]]+=[[:space:]]+).*$|\1\"$SNAP_RPC,$SNAP_RPC\"| ; \
s|^(trust_height[[:space:]]+=[[:space:]]+).*$|\1$BLOCK_HEIGHT| ; \
s|^(trust_hash[[:space:]]+=[[:space:]]+).*$|\1\"$TRUST_HASH\"|" $HOME/.migalood/config/config.toml

cp $HOME/.migalood/data/priv_validator_state.json $HOME/.migalood/priv_validator_state.json.backup

```

#### Stop the service and reset the data

```
sudo systemctl stop migalood
migalood tendermint unsafe-reset-all --home $HOME/.migalood
```

#### Run these codes after created \`sync.sh\`

```
chmod +x sync.sh
./sync.sh
```

#### Restart the service&#x20;

```
cp $HOME/.migalood/priv_validator_state.json.backup $HOME/.migalood/data/priv_validator_state.json
sudo systemctl restart migalood 
```

#### Check the logs&#x20;

```
sudo journalctl -u migalood -f -o cat --no-hostname 
```


---

# 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://docs.kalia.network/mainnet/migaloo/statesync.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.
