Skip to content

Conversation

@Forostovec
Copy link
Contributor

State history uses 1-based IDs, and rawdb.ReadStateHistory maps an ID to the ancient index by subtracting one (id-1). Therefore, the last ID equals the number of ancient items (head), not head-1.
Using last := head - 1 incorrectly treats Ancients() as the last 0-based index, which causes:

  • Skipping the newest history (ID head) when iterating [start, end].
  • Rejecting valid single-ID ranges due to first >= last being true when only one item exists (first == last).
  • Potential invalid reads or underflow handling in empty-store scenarios.

The corrected logic aligns with 1-based ID semantics used across pathdb (e.g., oldest ID is tail+1) and with rawdb’s accessor contracts.

@rjl493456442 rjl493456442 self-assigned this Nov 5, 2025
}
// Make sure the range is valid
if first >= last {
if first > last {
Copy link
Member

Choose a reason for hiding this comment

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

first == last is allowed for querying single item

Copy link
Contributor Author

Choose a reason for hiding this comment

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

first == last is allowed for querying single item

added test

Copy link
Member

Choose a reason for hiding this comment

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

What I meant is you shouldn't change the condition here.
Please revert to first >= last

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What I meant is you shouldn't change the condition here. Please revert to first >= last

sorry for misunderstanding

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