Skip to content

Conversation

@michaelgpt
Copy link
Contributor

Replace head - 1 with head.saturating_sub(1) in sync error handling to prevent panic when attempting to rollback from height 0.

Fixes integer underflow that occurs when:

  • Chain is empty (head = 0)
  • Sync encounters processing errors
  • Error handler attempts rollback to height -1

This prevents node crashes during initial sync with empty database.

Resolves: [AN-263]

Replace `head - 1` with `head.saturating_sub(1)` in sync error handling
to prevent panic when attempting to rollback from height 0.

Fixes integer underflow that occurs when:
- Chain is empty (head = 0)
- Sync encounters processing errors
- Error handler attempts rollback to height -1

This prevents node crashes during initial sync with empty database.

Resolves: [AN-263]
@michaelgpt michaelgpt requested a review from Copilot July 30, 2025 13:40
@michaelgpt michaelgpt self-assigned this Jul 30, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a critical integer underflow bug that causes node crashes during sync rollback operations when the chain is empty (height 0). The fix replaces arithmetic subtraction with saturating subtraction to prevent panics.

  • Replaces head - 1 and prev_height - 1 with saturating subtraction equivalents
  • Prevents node crashes during initial sync with empty database
  • Addresses error handling in two critical sync rollback scenarios

Improve the error handling in the rollback process by adding specific warnings for missing blocks when attempting to rollback from height 0. This change prevents unnecessary panic and provides clearer logging for rollback failures, enhancing the robustness of the chain's error management.

Resolves: [AN-263]
Enhance the error handling during the rollback process by adding a specific check for when the head is at 0, preventing attempts to rollback from an invalid state. This change improves logging clarity and prevents unnecessary errors during chain operations.

Resolves: [AN-263]
@michaelgpt michaelgpt merged commit bb200b9 into main Jul 30, 2025
3 of 4 checks passed
@michaelgpt michaelgpt deleted the AN-263-alys-integer-underflow-panic-during-chain-sync-rollback branch July 30, 2025 14:01
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