Skip to content

Conversation

akostylev0
Copy link
Member

No description provided.

@akostylev0 akostylev0 requested a review from Copilot July 4, 2025 14:19
Copy link

@Copilot 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 redesigns the Routed trait to return a BlockAvailability enum instead of separate boolean flags, enabling richer routing decisions.

  • Refactors ShardBounds::contains_seqno and contains_lt to return BlockAvailability.
  • Replaces Registry::contains/contains_not_available with a unified Registry::available, merging per-shard availability and adding unit tests.
  • Updates all Routed implementations (in cursor/client, tracked_client, and route.rs) and defines the new BlockAvailability enum in router/mod.rs.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tonlibjson-client/src/cursor/shard_bounds.rs Refactored contains_seqno & contains_lt to return BlockAvailability
tonlibjson-client/src/cursor/registry.rs Replaced contains* with available(), introduced merge logic, added tests
tonlibjson-client/src/cursor/client.rs Updated Routed impl to call available()
ton-liteserver-client/src/tracked_client.rs Updated Routed impl to return BlockAvailability
ton-client-util/src/router/route.rs Switched route filtering to use the new availability enum
ton-client-util/src/router/mod.rs Added BlockAvailability enum and updated the Routed trait
Comments suppressed due to low confidence (3)

tonlibjson-client/src/cursor/shard_bounds.rs:69

  • [nitpick] The method name contains_seqno now returns a BlockAvailability enum rather than a boolean. Consider renaming it to availability_for_seqno or get_seqno_availability for clearer intent.
    pub fn contains_seqno(&self, seqno: Seqno) -> BlockAvailability {

tonlibjson-client/src/cursor/registry.rs:151

  • There are unit tests for the contains_lt path but none for the contains_seqno/availableSeqno branch. Consider adding tests covering available, not available, and unknown cases for sequence numbers.
                bounds.contains_seqno(*seqno)

ton-client-util/src/router/mod.rs:18

  • [nitpick] The new BlockAvailability enum lacks documentation comments. Adding a brief docstring for each variant (e.g., what NotPresent vs Unknown means) will help future maintainers.
pub enum BlockAvailability {

}

impl<S> Routed for TrackedClient<S> {
fn available(&self, chain: &i32, criteria: &BlockCriteria) -> BlockAvailability {
Copy link

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

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

This implementation only returns Available or NotPresent. To fully support the BlockAvailability enum, handle cases where blocks are known but missing (NotAvailable) and when no information is available (Unknown).

Copilot uses AI. Check for mistakes.

Comment on lines +118 to +141
if matches!(result, BlockAvailability::Available) {
return BlockAvailability::Available;
}

let availability = bounds.contains_lt(*lt);

if matches!(result, BlockAvailability::NotAvailable) {
return match availability {
BlockAvailability::Available => BlockAvailability::Available,
_ => BlockAvailability::NotAvailable,
};
}

if matches!(result, BlockAvailability::Unknown) {
return match availability {
BlockAvailability::Available => BlockAvailability::Available,
BlockAvailability::NotAvailable => {
BlockAvailability::NotAvailable
}
_ => BlockAvailability::Unknown,
};
}

availability
Copy link

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

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

[nitpick] The fold logic for merging BlockAvailability values is quite dense. Consider extracting a helper function (e.g., merge_availability) to improve readability and reduce nested match blocks.

Suggested change
if matches!(result, BlockAvailability::Available) {
return BlockAvailability::Available;
}
let availability = bounds.contains_lt(*lt);
if matches!(result, BlockAvailability::NotAvailable) {
return match availability {
BlockAvailability::Available => BlockAvailability::Available,
_ => BlockAvailability::NotAvailable,
};
}
if matches!(result, BlockAvailability::Unknown) {
return match availability {
BlockAvailability::Available => BlockAvailability::Available,
BlockAvailability::NotAvailable => {
BlockAvailability::NotAvailable
}
_ => BlockAvailability::Unknown,
};
}
availability
merge_availability(result, bounds.contains_lt(*lt))

Copilot uses AI. Check for mistakes.

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