Skip to content

feat: add fast sync pivot support to mainnet and testnet start scripts#276

Open
wgr523 wants to merge 2 commits into
masterfrom
fixfastsync-new
Open

feat: add fast sync pivot support to mainnet and testnet start scripts#276
wgr523 wants to merge 2 commits into
masterfrom
fixfastsync-new

Conversation

@wgr523

@wgr523 wgr523 commented May 29, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • New Features

    • Node startup scripts now accept SYNC_MODE (default: full) and support a validated fast-sync pivot trio that is applied to node startup when provided.
    • Added helper scripts that query RPC endpoints to generate the fast-sync pivot env variables.
  • Documentation

    • Updated mainnet and testnet docs to describe SYNC_MODE, the fast-sync pivot variables, and the corresponding node flags.

@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds environment-driven configuration to both mainnet and testnet node startup scripts. Each script now supports SYNC_MODE to override the default sync mode and FASTSYNC_PIVOT environment variables to configure fast-sync pivot parameters, with validation requiring all three pivot variables together before building and appending the corresponding XDC command-line arguments.

Changes

Node Startup Configuration

Layer / File(s) Summary
SYNC_MODE environment variable support
mainnet/start-node.sh, testnet/start-apothem.sh
Both scripts read the optional SYNC_MODE environment variable to override the default sync_mode=full, logging which source was used.
Fast-sync pivot configuration validation and flag building
mainnet/start-node.sh, testnet/start-apothem.sh
Both scripts validate that all three FASTSYNC_PIVOT_NUMBER, FASTSYNC_PIVOT_HASH, and FASTSYNC_PIVOT_ROOT variables are provided together; if any are set incompletely, the script logs an error and exits with status 1; otherwise builds corresponding --fastsyncpivot* flag arguments.
Append fast-sync arguments to XDC command
mainnet/start-node.sh, testnet/start-apothem.sh
Both scripts append the validated fast-sync pivot argument array to the main args list passed to XDC at startup.
Fast sync pivot helper scripts
mainnet/get_pivot_for_fast_sync.sh, testnet/get_pivot_for_fast_sync.sh
New scripts call RPC endpoints to compute pivot block number/hash/stateRoot, validate responses, and print a heredoc with SYNC_MODE=fast plus FASTSYNC_PIVOT_* env assignments.
Documentation updates
mainnet/README.md, testnet/README.md
Docs updated to document SYNC_MODE, GC_MODE, the Fast Sync Pivot env vars, and --fastsyncpivot* CLI flags and usage instructions.

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers:

  • wanwiset25
  • anunay-xin
  • AnilChinchawale

"I am a rabbit in the shell, digging through each line,
SYNC_MODE set, pivots found — the configs all align.
From RPC hops to node-start drops, the flags now fit just so,
I nibble logs and skip through docs, then hop away — off I go! 🐰"

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main change: adding fast sync pivot support to both mainnet and testnet start scripts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fixfastsync-new

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@mainnet/get_pivot_for_fast_sync.sh`:
- Around line 11-18: The RPC curl calls (creating epoch_response, block_response
and block_details for methods XDPoS_getMasternodesByNumber,
XDPoS_getBlockInfoByEpochNum and eth_getBlockByHash) lack fail-fast flags and
timeouts and the block_details response is missing the jq .error guard; update
each curl invocation to include --fail and sensible timeouts (e.g.,
--connect-timeout and --max-time) and optional retry flags, and after fetching
block_details add the same jq error check used for epoch_response/block_response
(test .error and exit on failure) before accessing .result.stateRoot so
transport/http failures don’t produce confusing jq parse errors.

In `@mainnet/README.md`:
- Around line 46-50: The README currently suggests using `bash
get_pivot_for_fast_sync.sh >> .env`, which can append duplicate FASTSYNC_PIVOT_*
entries; update the instructions to instead write the script output to a
temporary file and replace or update existing FASTSYNC_PIVOT_* keys in `.env`
(or overwrite `.env` safely), e.g., run `get_pivot_for_fast_sync.sh` to a temp
file and then copy/merge its FASTSYNC_PIVOT_* values into `.env` replacing any
existing keys; reference the script name `get_pivot_for_fast_sync.sh` and the
`FASTSYNC_PIVOT_*` env keys so readers know which values must be replaced rather
than blindly appended.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8f12e204-7943-469a-9f46-37e6a0c502bb

📥 Commits

Reviewing files that changed from the base of the PR and between 91a4332 and 3b0d432.

📒 Files selected for processing (4)
  • mainnet/README.md
  • mainnet/get_pivot_for_fast_sync.sh
  • testnet/README.md
  • testnet/get_pivot_for_fast_sync.sh
✅ Files skipped from review due to trivial changes (1)
  • testnet/README.md

Comment on lines +11 to +18
epoch_response=$(curl -s -X POST "$RPC_URL" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "XDPoS_getMasternodesByNumber",
"params": ["latest"],
"id": 1
}')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify helper scripts currently use bare `curl -s` without timeout/fail flags.
rg -n --type=sh -C2 '\bcurl\s+-s\b' mainnet/get_pivot_for_fast_sync.sh testnet/get_pivot_for_fast_sync.sh

Repository: XinFinOrg/XinFin-Node

Length of output: 2120


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n --type=sh '\bcurl\b' mainnet/get_pivot_for_fast_sync.sh
echo "----"
rg -n --type=sh '\bcurl\s+-s\b' mainnet/get_pivot_for_fast_sync.sh

Repository: XinFinOrg/XinFin-Node

Length of output: 372


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show only the relevant call sites with line numbers
sed -n '1,120p' mainnet/get_pivot_for_fast_sync.sh | nl -ba | sed -n '1,120p'
echo "----"
nl -ba mainnet/get_pivot_for_fast_sync.sh | sed -n '1,110p' | sed -n '8,30p'
echo "----"
nl -ba mainnet/get_pivot_for_fast_sync.sh | sed -n '45,65p'
echo "----"
nl -ba mainnet/get_pivot_for_fast_sync.sh | sed -n '65,90p'

Repository: XinFinOrg/XinFin-Node

Length of output: 108


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "---- mainnet/get_pivot_for_fast_sync.sh (top area) ----"
cat -n mainnet/get_pivot_for_fast_sync.sh | sed -n '1,140p' | sed -n '1,90p'

echo "---- mainnet/get_pivot_for_fast_sync.sh (lines 40-90) ----"
cat -n mainnet/get_pivot_for_fast_sync.sh | sed -n '40,90p'

Repository: XinFinOrg/XinFin-Node

Length of output: 5534


Add fail-fast + timeout controls to all RPC curl calls.

All three JSON-RPC requests (XDPoS_getMasternodesByNumber, XDPoS_getBlockInfoByEpochNum, eth_getBlockByHash) use curl -s without --fail and without timeouts/retries, so HTTP/transport failures can hang and/or surface later as confusing jq parse issues. Also, .error is checked only for the first two responses; the eth_getBlockByHash response doesn’t have the same guard.

Suggested hardening
+curl_opts=(--silent --show-error --fail --connect-timeout 5 --max-time 20 --retry 3 --retry-delay 1)
-epoch_response=$(curl -s -X POST "$RPC_URL" \
+epoch_response=$(curl "${curl_opts[@]}" -X POST "$RPC_URL" \
   -H "Content-Type: application/json" \
   -d '{
     "jsonrpc": "2.0",
     "method": "XDPoS_getMasternodesByNumber",
     "params": ["latest"],
     "id": 1
   }')
 
-block_info_response=$(curl -s -X POST "$RPC_URL" \
+block_info_response=$(curl "${curl_opts[@]}" -X POST "$RPC_URL" \
   -H "Content-Type: application/json" \
   -d "{
     \"jsonrpc\": \"2.0\",
     \"method\": \"XDPoS_getBlockInfoByEpochNum\",
     \"params\": [$current_epoch],
     \"id\": 1
   }")
 
-block_details=$(curl -s -X POST "$RPC_URL" \
+block_details=$(curl "${curl_opts[@]}" -X POST "$RPC_URL" \
   -H "Content-Type: application/json" \
   -d "{
     \"jsonrpc\": \"2.0\",
     \"method\": \"eth_getBlockByHash\",
     \"params\": [\"$block_hash\", false],
     \"id\": 1
   }")

Add the same jq .error check pattern for block_details before reading .result.stateRoot.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@mainnet/get_pivot_for_fast_sync.sh` around lines 11 - 18, The RPC curl calls
(creating epoch_response, block_response and block_details for methods
XDPoS_getMasternodesByNumber, XDPoS_getBlockInfoByEpochNum and
eth_getBlockByHash) lack fail-fast flags and timeouts and the block_details
response is missing the jq .error guard; update each curl invocation to include
--fail and sensible timeouts (e.g., --connect-timeout and --max-time) and
optional retry flags, and after fetching block_details add the same jq error
check used for epoch_response/block_response (test .error and exit on failure)
before accessing .result.stateRoot so transport/http failures don’t produce
confusing jq parse errors.

Comment thread mainnet/README.md
Comment on lines +46 to +50
> Run `bash get_pivot_for_fast_sync.sh` to extract a fresh pivot (block number, hash, and state root) from a public XinFin RPC node. The script prints the values in `.env` format, so you can append the output directly:
>
> ```bash
> bash get_pivot_for_fast_sync.sh >> .env
> ```

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Avoid repeatedly appending duplicate pivot keys to .env.

Using >> .env every time can accumulate conflicting FASTSYNC_PIVOT_* values. Recommend documenting a replace/edit flow (or overwrite to a temp file, then copy values) instead of repeated append.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@mainnet/README.md` around lines 46 - 50, The README currently suggests using
`bash get_pivot_for_fast_sync.sh >> .env`, which can append duplicate
FASTSYNC_PIVOT_* entries; update the instructions to instead write the script
output to a temporary file and replace or update existing FASTSYNC_PIVOT_* keys
in `.env` (or overwrite `.env` safely), e.g., run `get_pivot_for_fast_sync.sh`
to a temp file and then copy/merge its FASTSYNC_PIVOT_* values into `.env`
replacing any existing keys; reference the script name
`get_pivot_for_fast_sync.sh` and the `FASTSYNC_PIVOT_*` env keys so readers know
which values must be replaced rather than blindly appended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants