-
Notifications
You must be signed in to change notification settings - Fork 26
Optimize advancing head #337
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
base: main
Are you sure you want to change the base?
Optimize advancing head #337
Conversation
Hello, @Wondertan ! Could you please review ? |
Hello, thanks for the ping, I will get to reviewing it around next week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR, as it is, doesn't achieve the goal behind the issue. To be frank, it makes it even worse. For every single header, it checks if it exists and reads it up, which is now two reads instead of one. What it should be doing is the following:
- check if nextHeight exists
- and if so, continue until it finds the nextHeight that doesn't
- once we hit a non-existing nextHeight, read the last existing one and return it
- that is, we read the whole header only once and only if hit the wall
} | ||
|
||
// hasHeaderAt checks if a header exists at the given height by checking both pending headers and the height indexer. | ||
func (s *Store[H]) hasHeaderAt(ctx context.Context, height uint64) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this implementation into HasAt
. The current implementation makes a risky assumption about everything being available between Tail and Head. While logic in go-header aims to have everything between Tail and Head available, it doesn't guarantee that to be the case at all times. Besides, the current HasAt
doesn't check for headers outside of the Tail-Head range, which is an allowed case.
ctx, done := s.withReadTransaction(ctx) | ||
defer done() | ||
|
||
debugLog := !changed && log.Level() == zapcore.DebugLevel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed is constant here
@KushnerykPavel, do you plan to finish the PR? |
Of course! thank you! |
resolve #332
Add checking header presence.