Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic bisecting schedule logic can be simplified #333

Closed
milosevic opened this issue Jun 17, 2020 · 3 comments
Closed

Basic bisecting schedule logic can be simplified #333

milosevic opened this issue Jun 17, 2020 · 3 comments
Assignees
Labels
light-client Issues/features which involve the light client question Further information is requested

Comments

@milosevic
Copy link
Contributor

milosevic commented Jun 17, 2020

In the basic bisection schedule implementation, see

pub fn basic_bisecting_schedule(
light_store: &dyn LightStore,
current_height: Height,
target_height: Height,
) -> Height {
let trusted_height = light_store
.highest(VerifiedStatus::Verified)
.map(|lb| lb.height())
.unwrap();
if trusted_height == current_height && trusted_height < target_height {
target_height
} else if trusted_height < current_height && trusted_height < target_height {
midpoint(trusted_height, current_height)
} else if trusted_height == target_height {
target_height
} else {
midpoint(current_height, target_height)
}
}

lines 70 to 74 shouldn't be needed.

In my understanding, There are only two scenarios in which basic_bisecting_schedule is called (in case verification of header failed), and they are covered by lines:

if trusted_height == current_height && trusted_height < target_height {
target_height
} else if trusted_height < current_height && trusted_height < target_height {
midpoint(trusted_height, current_height)

Also trusted_height should always be smaller than target_height.

@milosevic milosevic added light-client Issues/features which involve the light client question Further information is requested labels Jun 17, 2020
@ebuchman
Copy link
Member

Similar to my comment in #294 (comment), some of which still applies

@romac
Copy link
Member

romac commented Jun 25, 2020

Inlining #294 (comment):

Also a note about the scheduler. It's a bit hard to read the bisection logic out of it.

  • Can we use single word variable names like trusted, next, and target to make this more readable in cases like this where it's obvious we're dealing with heights and no other types?
  • The conditional block is hard to read. Can we clarify the cases somehow by relying on relationships that should always hold when verifying into the future, like (?) :
    • trusted <= next
    • trusted <= target
    • next <= target
  • If the above conditions are true, it's hard to understand that last branch of the conditional (it would never trigger?)
  • How to reconcile previous point with need to schedule into the past? Split the schedule function in two ?

@ebuchman
Copy link
Member

I think this has been completed? Let me know if not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
light-client Issues/features which involve the light client question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants