Skip to content

integrate fast sync to start wizard#280

Open
benjamin202410 wants to merge 4 commits into
masterfrom
add-fast-sync
Open

integrate fast sync to start wizard#280
benjamin202410 wants to merge 4 commits into
masterfrom
add-fast-sync

Conversation

@benjamin202410

@benjamin202410 benjamin202410 commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Added fast-sync support for mainnet and testnet node startup.
    • Added automatic fast-sync pivot discovery during setup and node start.
    • Added tools to calculate the pivot values (pivot number, hash, and state root).
  • Documentation
    • Expanded environment setup examples to support full|fast sync mode and fast-sync pivot variables.
    • Documented how to run the pivot calculation tools and what they output.
  • Bug Fixes
    • Added validation and clear errors when fast-sync pivot settings are missing/invalid.
    • Automatically falls back to full synchronization if pivot discovery fails.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a13c33b3-e270-423b-8209-17629e11ab48

📥 Commits

Reviewing files that changed from the base of the PR and between 2ccc29d and bccfdb5.

📒 Files selected for processing (3)
  • mainnet/start-node.sh
  • start-wizard.sh
  • testnet/start-apothem.sh
🚧 Files skipped from review as they are similar to previous changes (3)
  • testnet/start-apothem.sh
  • mainnet/start-node.sh
  • start-wizard.sh

📝 Walkthrough

Walkthrough

Changes

Fast-sync support

Layer / File(s) Summary
Pivot calculation scripts
tools/get_pivot*.sh, tools/README.md
Adds JSON-RPC and genesis-based pivot calculation, validation, output formatting, usage documentation, and dependency details.
Wizard fast-sync collection
start-wizard.sh
Adds automatic pivot retrieval, validation, storage, fallback to full sync, and updated configuration preview handling.
Sync-mode startup wiring
mainnet/env.example, testnet/env.example, mainnet/start-node.sh, testnet/start-apothem.sh
Documents fast-sync variables and passes validated pivot arguments to node startup commands.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant start-wizard.sh
  participant PivotScript
  participant RPC
  participant NodeStartup
  start-wizard.sh->>PivotScript: calculate FASTSYNC_PIVOT_* values
  PivotScript->>RPC: query epoch, block, and state-root data
  RPC-->>PivotScript: return pivot data
  PivotScript-->>start-wizard.sh: return validated variables
  start-wizard.sh->>NodeStartup: write sync configuration
  NodeStartup->>NodeStartup: append pivot arguments for fast sync
Loading

Possibly related PRs

Suggested reviewers: wanwiset25, AnilChinchawale

🚥 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 clearly reflects the main change: adding fast-sync support, especially in the start wizard.
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.
✨ 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 add-fast-sync

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.

@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: 3

🤖 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 `@tools/get_pivot_more.sh`:
- Around line 6-13: Add --max-time 30 to all three curl invocations in the
script, including the calls assigned to epoch_response and the other RPC
requests, so each request terminates instead of hanging indefinitely.
- Line 67: Redirect the debug output in get_pivot_more.sh from stdout to stderr
by appending >&2 to the echo "current_epoch: $current_epoch" statement, matching
get_pivot.sh and preserving sourceable stdout.

In `@tools/get_pivot.sh`:
- Around line 6-13: Add --max-time 30 to all three curl invocations in
get_pivot.sh, including the calls used for epoch_response and the requests
around the other RPC lookups, so each request terminates instead of hanging
indefinitely.
🪄 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: c269de69-d975-4963-a00f-a5908f419d9c

📥 Commits

Reviewing files that changed from the base of the PR and between 3975349 and 2ccc29d.

📒 Files selected for processing (8)
  • mainnet/env.example
  • mainnet/start-node.sh
  • start-wizard.sh
  • testnet/env.example
  • testnet/start-apothem.sh
  • tools/README.md
  • tools/get_pivot.sh
  • tools/get_pivot_more.sh

Comment thread tools/get_pivot_more.sh
Comment on lines +6 to +13
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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Add --max-time to all curl calls to prevent indefinite hangs.

Same issue as tools/get_pivot.sh — the three curl invocations (lines 6, 70, 91) have no timeout. A non-responsive RPC endpoint will hang the script and, when invoked from the wizard, hang the entire setup with no user-visible feedback.

🔒 Proposed fix — add `--max-time 30` to each curl call
-epoch_response=$(curl -s -X POST "$RPC_URL" \
+epoch_response=$(curl -s --max-time 30 -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 -s --max-time 30 -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 -s --max-time 30 -X POST "$RPC_URL" \
   -H "Content-Type: application/json" \
   -d "{
     \"jsonrpc\": \"2.0\",
     \"method\": \"eth_getBlockByHash\",
     \"params\": [\"$block_hash\", false],
     \"id\": 1
   }")

Also applies to: 70-77, 91-98

🤖 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 `@tools/get_pivot_more.sh` around lines 6 - 13, Add --max-time 30 to all three
curl invocations in the script, including the calls assigned to epoch_response
and the other RPC requests, so each request terminates instead of hanging
indefinitely.

Comment thread tools/get_pivot_more.sh
--arg switch "$switchEpoch" \
'(($round | tonumber) / ($epoch | tonumber) | floor) + ($switch | tonumber)')

echo "current_epoch: $current_epoch"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Redirect debug output to stderr for consistency with get_pivot.sh.

get_pivot.sh sends echo "Current epoch: …" >&2 (line 37), but this script prints echo "current_epoch: …" to stdout. The README states the output "can be sourced directly" — this line will break source <(./get_pivot_more.sh) with a command not found error. The wizard's grep-based parsing handles it, but direct usage is affected.

🛡️ Proposed fix
-echo "current_epoch: $current_epoch"
+echo "current_epoch: $current_epoch" >&2
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
echo "current_epoch: $current_epoch"
echo "current_epoch: $current_epoch" >&2
🤖 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 `@tools/get_pivot_more.sh` at line 67, Redirect the debug output in
get_pivot_more.sh from stdout to stderr by appending >&2 to the echo
"current_epoch: $current_epoch" statement, matching get_pivot.sh and preserving
sourceable stdout.

Comment thread tools/get_pivot.sh
Comment on lines +6 to +13
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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Add --max-time to all curl calls to prevent indefinite hangs.

None of the three curl invocations (lines 6, 40, 61) specify a timeout. If the RPC endpoint accepts the connection but never responds, the script blocks indefinitely. In the wizard context (start-wizard.sh captures stdout and discards stderr with 2>/dev/null), the user gets no feedback and the full-sync fallback never triggers.

🔒 Proposed fix — add `--max-time 30` to each curl call
-epoch_response=$(curl -s -X POST "$RPC_URL" \
+epoch_response=$(curl -s --max-time 30 -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 -s --max-time 30 -X POST "$RPC_URL" \
   -H "Content-Type: application/json" \
   -d "{
     \"jsonrpc\": \"2.0\",
     \"method\": \"XDPoS_getBlockInfoByV2EpochNum\",
     \"params\": [$current_epoch],
     \"id\": 1
   }")
-block_details=$(curl -s -X POST "$RPC_URL" \
+block_details=$(curl -s --max-time 30 -X POST "$RPC_URL" \
   -H "Content-Type: application/json" \
   -d "{
     \"jsonrpc\": \"2.0\",
     \"method\": \"eth_getBlockByHash\",
     \"params\": [\"$block_hash\", false],
     \"id\": 1
   }")

Also applies to: 40-47, 61-68

🤖 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 `@tools/get_pivot.sh` around lines 6 - 13, Add --max-time 30 to all three curl
invocations in get_pivot.sh, including the calls used for epoch_response and the
requests around the other RPC lookups, so each request terminates instead of
hanging indefinitely.

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.

1 participant