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

Remove traces downloader #639

Merged
merged 2 commits into from
Oct 31, 2024

Conversation

janezpodhostnik
Copy link
Contributor

@janezpodhostnik janezpodhostnik commented Oct 30, 2024

ref: #638

Description

Traces will get generated locally.


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

Release Notes

  • New Features

    • No new features added.
  • Bug Fixes

    • Streamlined error handling for gas price parsing.
  • Refactor

    • Removed trace-related functionality across various components, simplifying the application and reducing complexity.
    • Updated configuration options by removing trace-related fields.
  • Chores

    • Adjusted dependency management to categorize certain dependencies as indirect.
  • Tests

    • Removed unit tests related to trace ingestion functionality.

Copy link
Contributor

coderabbitai bot commented Oct 30, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes in this pull request involve the removal of trace-related functionality across multiple files, including the Makefile, bootstrap/bootstrap.go, cmd/run/cmd.go, config/config.go, and several files in the services/traces directory. The modifications simplify the mock generation process and eliminate configurations and methods associated with trace management. As a result, the application will no longer handle transaction traces, streamlining the bootstrap process and the command configuration.

Changes

File Change Summary
Makefile Removed mock generation command for services/traces.
bootstrap/bootstrap.go Removed Traces field from Storages, traces field from Bootstrap, and methods for trace downloading.
cmd/run/cmd.go Simplified error handling for gas price parsing; removed trace-related flags and logic.
config/config.go Deleted fields related to trace configuration: TracesBucketName, TracesEnabled, TracesBackfillStartHeight, TracesBackfillEndHeight.
go.mod Removed cloud.google.com/go/storage and google.golang.org/api from direct dependencies, added as indirect.
services/traces/downloader.go Deleted file containing Downloader interface and GCPDownloader struct for trace downloading.
services/traces/engine.go Deleted file containing Engine struct and methods for trace ingestion.
services/traces/engine_test.go Deleted file with unit tests for trace ingestion logic.
services/traces/mocks/Downloader.go Deleted mock implementation of Downloader interface.

Possibly related PRs

Suggested labels

Improvement, EVM

Suggested reviewers

  • peterargue
  • zhangchiqing
  • ramtinms
  • m-Peter

🐰 In the garden, the traces are gone,
No more paths where the shadows have shone.
The mockery's light shines bright and clear,
As we hop along without any fear!
Simplified paths, a new way to play,
In the fields of code, we dance and sway! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
cmd/run/cmd.go (1)

Trace-related code still exists in the codebase

The trace functionality hasn't been completely removed. There are still several trace-related components that need attention:

  • bootstrap/bootstrap.go: Contains trace indexer and storage initialization
  • api/debug.go: Has trace configuration and API endpoints
  • metrics/: Contains trace download metrics
  • README.md: Still documents trace-related configuration options
🔗 Analysis chain

Line range hint 1-359: Verify complete removal of trace-related configurations.

The trace-related flags have been removed as traces will now be generated locally. Let's verify that all trace-related code has been completely removed.


Let me gather more information about the trace-related code to ensure we have a complete picture.


Let me do one final check to ensure we haven't missed any trace-related code, particularly in the bootstrap package since it handles initialization.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify complete removal of trace-related code
# Test 1: Search for any remaining trace-related flags or configurations
echo "Searching for trace-related flags..."
rg -i "trace.*flag|trace.*config" 

# Test 2: Search for any remaining trace-related function calls or variables
echo "Searching for trace-related functions or variables..."
rg -i "trace.*backfill|trace.*bucket|trace.*download"

# Test 3: Search for any TODO comments about traces
echo "Searching for trace-related TODOs..."
rg -i "todo.*trace"

Length of output: 1903


Script:

#!/bin/bash
# Search for trace-related code in configuration files
echo "Searching for trace configuration in config package..."
rg -i "trace" config/

# Search for trace-related imports
echo "Searching for trace-related imports..."
rg -i "trace.*\"$" 

# Search for trace-related struct fields and types
echo "Searching for trace-related structs and types..."
ast-grep --pattern 'type $_ struct {
  $$$
  Trace$_ $_
  $$$
}'

# Check for any trace-related command flags in other command files
echo "Searching for trace-related flags in cmd directory..."
rg -i "trace.*flag" cmd/

Length of output: 715


Script:

#!/bin/bash
# Search for trace-related code in bootstrap package
echo "Searching for trace-related code in bootstrap..."
rg -i "trace" bootstrap/

# Search for any remaining trace-related configuration or initialization
echo "Searching for trace initialization..."
ast-grep --pattern 'func $_($$_) {
  $$$
  trace$_
  $$$
}'

# Check for any trace-related environment variables
echo "Searching for trace-related environment variables..."
rg -i "trace.*env|env.*trace"

Length of output: 663

bootstrap/bootstrap.go (2)

Line range hint 486-505: Improve error handling in storage initialization

The storage initialization could benefit from better error handling to ensure proper cleanup in case of partial initialization failures.

Consider implementing a cleanup mechanism:

 func setupStorage(
     config *config.Config,
     client *requester.CrossSporkClient,
     logger zerolog.Logger,
 ) (*Storages, error) {
     // create pebble storage from the provided database root directory
     store, err := pebble.New(config.DatabaseDir, logger)
     if err != nil {
         return nil, err
     }
+    // Ensure cleanup on error
+    var storages *Storages
+    defer func() {
+        if err != nil && store != nil {
+            if cerr := store.Close(); cerr != nil {
+                logger.Error().Err(cerr).Msg("failed to cleanup storage on error")
+            }
+        }
+    }()

     blocks := pebble.NewBlocks(store, config.FlowNetworkID)
     // ... rest of the initialization ...

     return &Storages{
         Storage:      store,
         Blocks:       blocks,
         Transactions: pebble.NewTransactions(store),
         Receipts:     pebble.NewReceipts(store),
         Accounts:     pebble.NewAccounts(store),
         Traces:       pebble.NewTraces(store),
     }, nil
 }

Line range hint 507-547: Enhance error handling in Run function

The Run function could benefit from better cleanup handling when services fail to start. Currently, if a service fails to start, previously started services aren't properly stopped.

Consider implementing a more robust error handling approach:

 func Run(ctx context.Context, cfg *config.Config, ready chan struct{}) error {
     boot, err := New(cfg)
     if err != nil {
         return err
     }
+    // Ensure cleanup on error
+    var startupError error
+    defer func() {
+        if startupError != nil {
+            boot.StopEventIngestion()
+            boot.StopMetricsServer()
+            boot.StopAPIServer()
+            boot.StopProfilerServer()
+        }
+    }()

     if err := boot.StartEventIngestion(ctx); err != nil {
-        return fmt.Errorf("failed to start event ingestion engine: %w", err)
+        startupError = fmt.Errorf("failed to start event ingestion engine: %w", err)
+        return startupError
     }

     if err := boot.StartAPIServer(ctx); err != nil {
-        return fmt.Errorf("failed to start API server: %w", err)
+        startupError = fmt.Errorf("failed to start API server: %w", err)
+        return startupError
     }

     if err := boot.StartMetricsServer(ctx); err != nil {
-        return fmt.Errorf("failed to start metrics server: %w", err)
+        startupError = fmt.Errorf("failed to start metrics server: %w", err)
+        return startupError
     }

     if err := boot.StartProfilerServer(ctx); err != nil {
-        return fmt.Errorf("failed to start profiler server: %w", err)
+        startupError = fmt.Errorf("failed to start profiler server: %w", err)
+        return startupError
     }

     // mark ready
     close(ready)

     // if context is canceled start shutdown
     <-ctx.Done()
     boot.logger.Warn().Msg("bootstrap received context cancellation, stopping services")

     boot.StopEventIngestion()
     boot.StopMetricsServer()
     boot.StopAPIServer()
+    boot.StopProfilerServer()

     return nil
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1d6f350 and 89411be.

📒 Files selected for processing (9)
  • Makefile (0 hunks)
  • bootstrap/bootstrap.go (1 hunks)
  • cmd/run/cmd.go (1 hunks)
  • config/config.go (0 hunks)
  • go.mod (2 hunks)
  • services/traces/downloader.go (0 hunks)
  • services/traces/engine.go (0 hunks)
  • services/traces/engine_test.go (0 hunks)
  • services/traces/mocks/Downloader.go (0 hunks)
💤 Files with no reviewable changes (6)
  • Makefile
  • config/config.go
  • services/traces/downloader.go
  • services/traces/engine.go
  • services/traces/engine_test.go
  • services/traces/mocks/Downloader.go
🔇 Additional comments (4)
go.mod (2)

34-34: LGTM: Correctly moved cloud.google.com/go/storage to indirect dependencies.

The change aligns with the removal of traces downloader functionality, as the storage SDK is no longer directly used but remains as a transitive dependency.


202-202: LGTM: Correctly moved google.golang.org/api to indirect dependencies.

The change is consistent with removing direct GCP API interactions while maintaining the dependency for transitive usage by other packages.

cmd/run/cmd.go (1)

75-77: LGTM: Simplified gas price error handling.

The error handling for invalid gas price has been simplified by directly returning an error when parsing fails. This change improves code readability while maintaining the same functionality.

bootstrap/bootstrap.go (1)

245-245: Verify complete removal of trace functionality

The code appears to have incomplete removal of trace-related components. While the PR objective and AI summary indicate that traces will be generated locally and the traces downloader should be removed, several trace-related components still exist:

  1. The Traces field in the Storages struct is still present
  2. The NewTraces(store) initialization in setupStorage is still active
  3. The debugAPI is still being initialized with trace storage

This could lead to:

  • Orphaned code that's no longer used
  • Potential runtime issues if trace functionality is partially removed

Let's verify the trace-related code that might need cleanup:

Also applies to: 500-500

if b.config.TracesEnabled {
debugAPI = api.NewDebugAPI(b.storages.Traces, b.storages.Blocks, b.logger, b.collector)
}
var debugAPI = api.NewDebugAPI(b.storages.Traces, b.storages.Blocks, b.logger, b.collector)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Review debugAPI initialization after trace changes

The debugAPI initialization is now unconditional and still depends on trace storage. If traces are to be generated locally as mentioned in the PR objective, the debugAPI might need to be updated to work with the new local trace generation mechanism.

Consider updating the debugAPI initialization to:

  1. Use the new local trace generation mechanism
  2. Handle cases where trace storage might not be available
-var debugAPI = api.NewDebugAPI(b.storages.Traces, b.storages.Blocks, b.logger, b.collector)
+// TODO: Update to use local trace generation
+var debugAPI = api.NewDebugAPI(b.storages.Blocks, b.logger, b.collector)

Committable suggestion was skipped due to low confidence.

Copy link
Collaborator

@m-Peter m-Peter left a comment

Choose a reason for hiding this comment

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

LGTM! 👏
We can also remove the relevant CLI flags for traces on https://github.com/onflow/flow-evm-gateway/blob/main/README.md#configuration-flags.

@ramtinms
Copy link
Contributor

I think we should only do this, when we have a local solution, so maybe the PR should target the feature branch.

@m-Peter m-Peter changed the base branch from main to feature/local-tx-reexecution October 30, 2024 20:36
@m-Peter
Copy link
Collaborator

m-Peter commented Oct 30, 2024

I think we should only do this, when we have a local solution, so maybe the PR should target the feature branch.

@ramtinms Good point, I updated the base branch, to the feature branch we use.

@@ -222,14 +222,10 @@ The application can be configured using the following flags at runtime:
| `stream-limit` | `10` | Rate-limit for client events sent per second |
| `rate-limit` | `50` | Requests per second limit for clients over any protocol (ws/http) |
| `address-header` | `""` | Header for client IP when server is behind a proxy |
| `heartbeat-interval` | `100` | Interval for AN event subscription heartbeats |
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot to remove this earlier

@janezpodhostnik
Copy link
Contributor Author

@m-Peter Thanks for changing the base, this should definitely only go into the feature branch.

We can hold off on merging this if it causes you any conflicts.

Copy link
Collaborator

@m-Peter m-Peter left a comment

Choose a reason for hiding this comment

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

LGTM!

@m-Peter
Copy link
Collaborator

m-Peter commented Oct 31, 2024

@m-Peter Thanks for changing the base, this should definitely only go into the feature branch.

We can hold off on merging this if it causes you any conflicts.

@janezpodhostnik I would say let's merge this, since I also need the changes for enabled the DebugAPI 👍
It doesn't cause me any conflicts.

@janezpodhostnik janezpodhostnik merged commit 8472396 into feature/local-tx-reexecution Oct 31, 2024
2 checks passed
@m-Peter m-Peter deleted the janez/remove-traces branch October 31, 2024 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

3 participants