Skip to content

Conversation

KushnerykPavel
Copy link
Contributor

resolve #332

Add checking header presence.

@KushnerykPavel
Copy link
Contributor Author

Hello, @Wondertan ! Could you please review ?

@Wondertan
Copy link
Member

Hello, thanks for the ping, I will get to reviewing it around next week.

Copy link
Member

@Wondertan Wondertan left a 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 {
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

changed is constant here

@Wondertan
Copy link
Member

@KushnerykPavel, do you plan to finish the PR?

@KushnerykPavel
Copy link
Contributor Author

@KushnerykPavel, do you plan to finish the PR?

Of course! thank you!

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.

perf: optimize advancing head and receding tail
2 participants