> For the complete documentation index, see [llms.txt](https://ciferai.gitbook.io/nodevalidator/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ciferai.gitbook.io/nodevalidator/3.-state-synchronization.md).

# 3. State Synchronization

Before a node can actively participate in a blockchain network, it must undergo a process called state synchronization. This essential step involves downloading and verifying the entire history of the blockchain, from its inception (the genesis block) to the most recent block.

By synchronizing its state, a node ensures it has a complete and accurate record of all transactions and events that have occurred on the network. This comprehensive understanding is vital for several reasons:

* **Validating Transactions:** Nodes must verify the authenticity of new transactions and ensure they adhere to network rules.
* **Consensus Participation:** To contribute to the consensus mechanism and secure the network, a node needs a complete view of the blockchain's history.
* **Processing Queries:** Nodes often handle requests for information about past transactions or account balances, requiring access to historical data.

In essence, state synchronization is the foundational step that equips a node to become a fully functional and trusted participant in the blockchain ecosystem.

## 3.1 Query for the Latest Block

To ensure your node has the most up-to-date information, you'll need to retrieve the latest block height and hash from a trusted node. This information will be used to configure your node for state synchronization.

Use the following command to retrieve the trust height and trust hash of the latest block on a trusted node:

{% code overflow="wrap" %}

```bash
$ curl -s http:/34.128.114.243:26657/commit | jq "{height: .result.signed_header.header.height, hash: .result.signed_header.commit.block_id.hash}"
```

{% endcode %}

This command will display a JSON response with the height and hash of the latest block.

{% code overflow="wrap" %}

```json
{
  "height": "264382",
  "hash": "DB8E5522FDA2B4A9BBE488FE46CF2BEF14CC36938A1A60BE4B48BAF4F74827FB"
}
```

{% endcode %}

## 3.2 Configure State Synchronization

Once you have the latest block height and hash, you'll need to update your node's configuration file to enable state synchronization.

* Locate the `config.toml` file in your Cifer node's configuration directory (typically `.cifer/config`).
* Enable state sync by setting the `enable` in`[statesync]` section to `true`.
* Replace `trust_height` and `trust_hash` with the values obtained in [**"3.1 Query for the Latest Block"**](#id-3.1-query-for-the-latest-block):

{% code title="config.toml" overflow="wrap" %}

```toml
[statesync]
enable = true
rpc_servers = "<RPC_server_1>, <RPC_server_2>" # Replace with at least 2 validator RPC server addresses
trust_height = 264382 # Replace with the height from step 1
trust_hash = "DB8E5522FDA2B4A9BBE488FE46CF2BEF14CC36938A1A60BE4B48BAF4F74827FB"
trust_period = "" # Should be significantly smaller than the unbonding period
```

{% endcode %}

## 3.3 Restart your Node

To apply the configuration changes and initiate state synchronization, restart your Cifer node.

Stop the currently running Cifer Chain instance by pressing q in the terminal window.

{% code overflow="wrap" %}

```bash
Press the 'q' key to stop serve

💿 Genesis state saved in /root/.ignite/local-chains/cifer/exported_genesis.json

𝓲 Stopped
```

{% endcode %}

Restart the blockchain using the following command:

{% code overflow="wrap" %}

```bash
$ ignite chain serve --reset-once
```

{% endcode %}

Your node will now begin the state synchronization process, downloading and verifying the blockchain data from the trust height up to the latest block. This process may take some time depending on the size of the blockchain.

> **Note:** Ensure you have sufficient disk space to accommodate the entire blockchain data.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://ciferai.gitbook.io/nodevalidator/3.-state-synchronization.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.
