Syncing a light node from a trusted hash
This guide goes over how to sync a DA light node from a trusted hash. The example uses the Mocha testnet. You will need to adjust the commands accordingly for Mainnet Beta, Arabica, or a custom network.
If you already have a data store for your node, you need to remove it before syncing from a trusted hash:
rm -rf ~/.celestia-light-mocha-4/datarm -rf ~/.celestia-light-mocha-4/dataYou also cannot sync to a height earlier than the data availability sampling (DAS) start height. If you want data from height n, start syncing from at least height n.
WARNING
Syncing to a trusted hash means that you will not sample the entire chain. This adds a trust assumption that you trust the history of the chain up to that point and that you trust the entity where you get the hash from. In this example, the trusted entity is a consensus endpoint or Celenium.
Historical queries
WARNING
Default light nodes no longer support historical queries. By default, nodes maintain a sliding window of headers, bounded by Tail and Head headers. Requests with height below the Tail are rejected.
This is, however, temporary, and lazy header fetching will be available with Backward Sync.
To retain the ability to request older queries with light nodes, use the new configuration fields to set an absolute header that the node will sync from:
Header.Syncer.SyncFromHeight: Set the height from which the node will syncHeader.Syncer.SyncFromHash: Set the hash from which the node will sync
By configuring these fields, your light node will maintain history from the specified height onward, allowing you to query historical data from that point.
General Approach
Get trusted height & hash from a consensus endpoint or Celenium.
Initialize the node store
shcelestia light init --p2p.network <network>celestia light init --p2p.network <network>Set the trusted height & hash in your config file
- Open your
config.tomlat.celestia-light/config.toml(or.celestia-light-<other-network>/config.toml) - Set
Header.Syncer.SyncFromHeightto the trusted height (e.g.SyncFromHeight = 123456) - Set
Header.Syncer.SyncFromHashto the trusted hash (e.g.SyncFromHash = "<hash_of_block_n>", with no0xprefix.)
- Open your
Run the node:
celestia light start --p2p.network <network> --core.ip <consensus-node-rpc> --core.port <port>celestia light start --p2p.network <network> --core.ip <consensus-node-rpc> --core.port <port>Automated Approach
You can automate the process of setting the trusted height and hash using the following commands for Mocha testnet:
1. Initialize the node store (if not already done)
celestia light init --p2p.network mochacelestia light init --p2p.network mocha2. Get and set the trusted height and hash automatically
# Get both the height and hash values in a single call
read -r TRUSTED_HEIGHT TRUSTED_HASH <<<"$(curl -s https://rpc-mocha.pops.one/header | jq -r '.result.header | "\(.height) \(.last_block_id.hash)"')" && export TRUSTED_HEIGHT TRUSTED_HASH
# Use sed to find and replace the SyncFromHeight value in the config file (macOS version)
sed -i '' "s/SyncFromHeight = .*/SyncFromHeight = $TRUSTED_HEIGHT/" ~/.celestia-light-mocha-4/config.toml
# Add/update the SyncFromHash value
sed -i '' "s/SyncFromHash = .*/SyncFromHash = \"$TRUSTED_HASH\"/" ~/.celestia-light-mocha-4/config.toml
# Display the updated values to confirm
echo "SyncFromHeight updated to: $TRUSTED_HEIGHT"
echo "SyncFromHash updated to: $TRUSTED_HASH"# Get both the height and hash values in a single call
read -r TRUSTED_HEIGHT TRUSTED_HASH <<<"$(curl -s https://rpc-mocha.pops.one/header | jq -r '.result.header | "\(.height) \(.last_block_id.hash)"')" && export TRUSTED_HEIGHT TRUSTED_HASH
# Use sed to find and replace the SyncFromHeight value in the config file (macOS version)
sed -i '' "s/SyncFromHeight = .*/SyncFromHeight = $TRUSTED_HEIGHT/" ~/.celestia-light-mocha-4/config.toml
# Add/update the SyncFromHash value
sed -i '' "s/SyncFromHash = .*/SyncFromHash = \"$TRUSTED_HASH\"/" ~/.celestia-light-mocha-4/config.toml
# Display the updated values to confirm
echo "SyncFromHeight updated to: $TRUSTED_HEIGHT"
echo "SyncFromHash updated to: $TRUSTED_HASH"3. Start the node
celestia light start --p2p.network mocha --core.ip rpc-mocha.pops.one --core.port 9090celestia light start --p2p.network mocha --core.ip rpc-mocha.pops.one --core.port 9090TIP
For Linux users, remove the empty string ('') after -i in the sed commands:
sed -i "s/SyncFromHeight = .*/SyncFromHeight = $TRUSTED_HEIGHT/" ~/.celestia-light-mocha-4/config.toml
sed -i "s/SyncFromHash = .*/SyncFromHash = \"$TRUSTED_HASH\"/" ~/.celestia-light-mocha-4/config.tomlsed -i "s/SyncFromHeight = .*/SyncFromHeight = $TRUSTED_HEIGHT/" ~/.celestia-light-mocha-4/config.toml
sed -i "s/SyncFromHash = .*/SyncFromHash = \"$TRUSTED_HASH\"/" ~/.celestia-light-mocha-4/config.tomlFor service operators
If you're using multiple light nodes for similar services like tracking the same rollup, it is recommended to use the same hash and height for all services using the same starting height.