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

Last indexed cleanup scribe/agents testing optimization #1409

Merged
merged 6 commits into from
Oct 10, 2023

Conversation

nautsimon
Copy link
Contributor

@nautsimon nautsimon commented Sep 28, 2023

Description
The long standing behavior of last indexed has been that it is mutated whenever a log is seen and processed on that block. This behavior spawned a workaround in the gRPC server where the last block indexed lagged one block behind the last block stored in scribe. This workaround spawned more workarounds in the agents test suite where the simulated backends had to bump their head blocks by one to retrieve all data from scribe.

Last indexed should transmit the last indexed block, if there are still logs that have not been indexed in that block, then that block should not be considered the last indexed block. This PR fixes this.

Remedying this behavior will clean up testing and will reduce complexity on downstream dependancies (agents testing suite).

Summary by CodeRabbit

Release Notes:

  • New Feature: Introduced a lastBlockSeen variable in indexer.go to improve the accuracy of tracking the last indexed block.
  • Refactor: Modified the toBlock variable assignment in server.go to ensure it is set to the latest value of latestScribeBlock.
  • New Feature: Added a Verbose field in config.go to enable verbose logging.
  • Bug Fix: Enhanced error handling in scribe.go by adding error messages for chain context cancellation and chain indexer errors.
  • Documentation: Updated the description of the Scribe service in cmd.md for clarity.

@nautsimon nautsimon requested a review from trajan0x as a code owner September 28, 2023 16:05
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 28, 2023

Walkthrough

The changes primarily focus on improving the accuracy of tracking the last indexed block in the Scribe service. A new variable lastBlockSeen is introduced to ensure all logs from the last block are processed before updating the last indexed value. Additionally, verbose logging is enabled, and error handling is improved in the chain context cancellation and chain indexer running process.

Changes

File Path Summary
.../indexer/indexer.go Introduced lastBlockSeen to accurately track the last block processed. Updated saveLastIndexed function to prevent premature updates of the last indexed value.
.../grpc/server/server.go Modified toBlock variable assignment to ensure it's set to the latest value of latestScribeBlock.
.../config/config.go Added a new Verbose field to the Config struct to enable verbose logging.
.../service/scribe.go Improved error handling in the Start method of the Scribe struct for chain context cancellation and chain indexer running process.
.../cmd/cmd.md Minor change in the description of the Scribe service for clarity.

🐇

"In the land of code, where logic is the road,

Changes come and go, as the winds of progress blow.

With each line we refine, a story does it define,

Of a journey, oh so fine, in the realm of ones and nines." 🎉


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.
  • Additionally, enter @coderabbitai pause to halt the bot's ongoing reviews as any issue or review comment. To
    resume reviews, enter @coderabbitai resume as any issue or review comment.

@github-actions github-actions bot added the go Pull requests that update Go code label Sep 28, 2023
@codecov
Copy link

codecov bot commented Sep 28, 2023

Codecov Report

Attention: 16 lines in your changes are missing coverage. Please review.

Comparison is base (9947d7d) 50.51623% compared to head (7d0faa3) 51.15537%.
Report is 19 commits behind head on master.

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #1409         +/-   ##
===================================================
+ Coverage   50.51623%   51.15537%   +0.63913%     
===================================================
  Files            343         366         +23     
  Lines          24117       25057        +940     
  Branches         277         267         -10     
===================================================
+ Hits           12183       12818        +635     
- Misses         10724       10966        +242     
- Partials        1210        1273         +63     
Flag Coverage Δ
agents 46.96731% <ø> (-0.33212%) ⬇️
cctp-relayer 63.33333% <ø> (?)
explorer 25.43225% <ø> (ø)
promexporter 41.02564% <ø> (?)
scribe 52.21130% <50.00000%> (+0.33205%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
packages/sdk-router/src/constants/addresses.ts 100.00000% <100.00000%> (ø)
packages/sdk-router/src/constants/chainIds.ts 100.00000% <100.00000%> (ø)
packages/sdk-router/src/constants/index.ts 100.00000% <100.00000%> (ø)
packages/sdk-router/src/constants/testValues.ts 100.00000% <100.00000%> (ø)
packages/sdk-router/src/operations/bridge.ts 100.00000% <100.00000%> (ø)
packages/sdk-router/src/operations/index.ts 100.00000% <100.00000%> (ø)
packages/sdk-router/src/router/index.ts 100.00000% <100.00000%> (ø)
packages/sdk-router/src/router/query.ts 100.00000% <100.00000%> (ø)
...ackages/sdk-router/src/router/synapseCCTPRouter.ts 100.00000% <100.00000%> (ø)
...ages/sdk-router/src/router/synapseCCTPRouterSet.ts 100.00000% <100.00000%> (ø)
... and 12 more

... and 15 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nautsimon nautsimon requested a review from dwasse September 28, 2023 16:07
Copy link
Contributor

@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

Commits Files that changed from the base of the PR and between 179be0f and d4acc27.
Files selected for processing (1)
  • services/scribe/service/indexer/indexer.go (2 hunks)
Additional comments (Suppressed): 1
services/scribe/service/indexer/indexer.go (1)
  • 229-241: The new logic ensures that the last indexed value is only updated when all logs from the last block have been processed. This is a significant improvement over the previous implementation where the last indexed value was updated prematurely. The error handling and logging are also appropriately done.

services/scribe/service/indexer/indexer.go Show resolved Hide resolved
Copy link
Contributor

@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: 0

Commits Files that changed from the base of the PR and between d4acc27 and 3e4e1a0.
Files selected for processing (2)
  • services/scribe/grpc/server/server.go (1 hunks)
  • services/scribe/service/indexer/indexer.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • services/scribe/grpc/server/server.go
Additional comments (Suppressed): 2
services/scribe/service/indexer/indexer.go (2)
  • 180-186: The introduction of lastBlockSeen variable is a good approach to track the last block number processed by the indexer. This will help in ensuring that the last indexed value is only updated when all logs from the last block have been processed, preventing premature updates. However, it's important to ensure that this change doesn't introduce any race conditions or synchronization issues if multiple goroutines are accessing and modifying this variable concurrently.

  • 229-241: The modification to the saveLastIndexed function call is well thought out. By checking if lastBlockSeen < log.BlockNumber before updating the last indexed block, you're ensuring that all logs from the last block have been processed. This prevents premature updates of the last indexed block and reduces complexity for downstream dependencies. However, please verify that there are no side effects due to this change in other parts of the codebase that rely on the saveLastIndexed function.

- err = x.saveLastIndexed(storeCtx, log.BlockNumber)
+ if lastBlockSeen < log.BlockNumber {
+     err = x.saveLastIndexed(storeCtx, lastBlockSeen)
+     if err != nil {
+         logger.ReportIndexerError(err, x.indexerConfig, logger.StoreError)
+         return fmt.Errorf("could not store last indexed: %w", err)
+     }
+     lastBlockSeen = log.BlockNumber
+ }

@nautsimon nautsimon changed the title Last indexed cleanup scribe/agents Last indexed cleanup scribe/agents testing optimization Sep 28, 2023
Copy link
Contributor

@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: 0

Commits Files that changed from the base of the PR and between 3e4e1a0 and 4cd1efd.
Files selected for processing (2)
  • services/scribe/config/config.go (1 hunks)
  • services/scribe/service/scribe.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • services/scribe/config/config.go
Additional comments (Suppressed): 4
services/scribe/service/scribe.go (4)
  • 85-85: The error message has been updated to include the error from the chain context cancellation. This provides more detailed information about the error, which can be useful for debugging.

  • 92-92: The error message has been updated to include the error from the chain indexer. This provides more detailed information about the error, which can be useful for debugging.

  • 85-85: Ensure that the updated error message does not break any error handling that relies on the specific text of the old error message.

  • 92-92: Ensure that the updated error message does not break any error handling that relies on the specific text of the old error message.

Copy link
Contributor

@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: 0

Commits Files that changed from the base of the PR and between 4cd1efd and 7d0faa3.
Files selected for processing (1)
  • services/scribe/cmd/cmd.md (1 hunks)
Files skipped from review due to trivial changes (1)
  • services/scribe/cmd/cmd.md

@nautsimon nautsimon merged commit 2c5d20d into master Oct 10, 2023
52 checks passed
@nautsimon nautsimon deleted the feat/update-last-indexed-scribe branch October 10, 2023 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants