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

Perf fixes #1678

Merged
merged 1 commit into from
Dec 4, 2023
Merged

Perf fixes #1678

merged 1 commit into from
Dec 4, 2023

Conversation

tudor-malene
Copy link
Collaborator

Why this change is needed

to improve performance

What changes were made as part of this PR

  • use the cached head block to avoid slow query
  • add "isCanonical" check to queries to hit the [height, is_canonical] index (hopefully)

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

- add canonical condition to sql to hit the index
Copy link

coderabbitai bot commented Dec 4, 2023

Walkthrough

The changes involve a shift in the method for retrieving the head block within the enclave's logic, moving from a storage-based approach to one that utilizes a block processor. Additionally, there's an update to SQL queries to filter for canonical batches when fetching transaction lists and counts, ensuring that only data associated with canonical batches is considered.

Changes

File Path Change Summary
.../enclave/enclave.go Updated methods to retrieve the head block using l1BlockProcessor.GetHead() instead of storage.FetchHeadBlock().
.../storage/enclavedb/batch.go Modified SQL queries to include where batch.is_canonical=true condition, filtering for canonical batches.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link
Collaborator

@BedrockSquirrel BedrockSquirrel left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7a2bbaf and c813400.
Files selected for processing (2)
  • go/enclave/enclave.go (2 hunks)
  • go/enclave/storage/enclavedb/batch.go (1 hunks)
Additional comments: 2
go/enclave/enclave.go (1)
  • 322-328: The change from storage.FetchHeadBlock() to l1BlockProcessor.GetHead() in the Status method is consistent with the PR's performance objectives. However, ensure that the error handling is robust, especially since the comment on line 327 suggests that failing to fetch the L1 head block might be normal during startup.
go/enclave/storage/enclavedb/batch.go (1)
  • 47-48: The changes to the SQL queries queryTxList and queryTxCountList correctly implement the performance improvement by adding the where batch.is_canonical=true condition. This should leverage the [height, is_canonical] index more effectively as intended in the PR objectives. Ensure that the rest of the system expects and correctly handles the now potentially reduced result set due to this new filter.

Comment on lines 1472 to 1476
var hash common.L1BlockHash
l1Head, err := e.storage.FetchHeadBlock()
l1Head, err := e.l1BlockProcessor.GetHead()
// todo - handle error
if err == nil {
hash = l1Head.Hash()
Copy link

Choose a reason for hiding this comment

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

The rejectBlockErr method has been updated to use l1BlockProcessor.GetHead() instead of storage.FetchHeadBlock(). It is important to handle the potential error from GetHead() call properly. Currently, there is a todo comment indicating that error handling needs to be addressed. This should be resolved to ensure that errors are handled correctly and do not lead to unexpected behavior.

l1Head, err := e.l1BlockProcessor.GetHead()
- // todo - handle error
+ if err != nil {
+     // Handle the error appropriately
+ }
if err == nil {

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
var hash common.L1BlockHash
l1Head, err := e.storage.FetchHeadBlock()
l1Head, err := e.l1BlockProcessor.GetHead()
// todo - handle error
if err == nil {
hash = l1Head.Hash()
var hash common.L1BlockHash
l1Head, err := e.l1BlockProcessor.GetHead()
if err != nil {
// Handle the error appropriately
}
if err == nil {
hash = l1Head.Hash()

@tudor-malene tudor-malene merged commit fb50c7b into main Dec 4, 2023
2 checks passed
@tudor-malene tudor-malene deleted the tudor/fix_performance branch December 4, 2023 12:32
tudor-malene added a commit that referenced this pull request Dec 8, 2023
- add canonical condition to sql to hit the index

(cherry picked from commit fb50c7b)
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