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

Cache submitter gas block #1465

Merged
merged 8 commits into from
Oct 20, 2023
Merged

Cache submitter gas block #1465

merged 8 commits into from
Oct 20, 2023

Conversation

dwasse
Copy link
Collaborator

@dwasse dwasse commented Oct 19, 2023

Description
Adds a gasBlockCache to submitter so that we can use a cached value in the event that the HeaderByNumber RPC call fails.

Additional context
Also fixes a bug where we fail to get the gas block properly, but continue with setting gas price and are at risk of getting nullptr.

Summary by CodeRabbit

  • New Feature: Enhanced the transaction submission process in the Etherego platform by introducing a caching mechanism for gas blocks across different chains. This will improve the speed and efficiency of transactions, particularly for users interacting with multiple chains.
  • Refactor: Updated the GitHub workflow for better label management. Transitioned from a third-party action to a built-in GitHub action for adding and removing labels, enhancing the maintainability and reliability of our development process.
  • Test: Added new tests to ensure the correct functioning of the gas block caching mechanism, ensuring a more robust and reliable transaction submission process.

@dwasse dwasse requested a review from trajan0x as a code owner October 19, 2023 19:55
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 19, 2023

Walkthrough

This update introduces caching for gas blocks in different chains to improve performance. It also refines the GitHub workflow for label management, replacing a third-party action with a built-in GitHub action for better maintainability.

Changes

File Summary
ethergo/submitter/... Introduced a cache for gas blocks in different chains. Updated functions to support this change and added tests to ensure correct behavior.
.github/workflows/go.yml Replaced the third-party andymckay/labeler action with the built-in actions/github-script action for label management in GitHub workflow.

🐇

In the land of code, where logic intertwines,

A rabbit hops, leaving traces of lines.

With each hop, a problem's unfurled,

Yet solved with grace, in this digital world.

Now gas blocks cached, chains run with glee,

And labels managed with built-in decree.

So here's to the code, ever so bright,

Hop on, CodeRabbit, continue your flight! 🚀


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 go Pull requests that update Go code size/s labels Oct 19, 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 dcda614 and 62f02fb.
Files selected for processing (3)
  • ethergo/submitter/export_test.go (4 hunks)
  • ethergo/submitter/submitter.go (7 hunks)
  • ethergo/submitter/submitter_test.go (3 hunks)
Additional comments (Suppressed): 11
ethergo/submitter/submitter_test.go (3)
  • 2-9: The import of math/big has been moved from the bottom of the import block to the top. This change is acceptable as it does not affect the functionality of the code. However, it's a good practice to group standard library imports together and separate them from third-party imports for better readability.

  • 22-25: The import of math/big has been removed from this block. Ensure that this does not affect any functionality in the code that relies on this package.

  • 76-107: The new TestGetGasBlock function tests the GetGasBlock method's behavior in both successful and failed HeaderByNumber RPC call scenarios, and verifies the caching behavior when the RPC call fails. This is a good addition as it covers different scenarios and ensures that the caching mechanism works as expected.

ethergo/submitter/export_test.go (4)
  • 3-9: The import of math/big has been removed. Ensure that this does not affect any existing functionality that relies on this package.

  • 13-16: The import of math/big has been removed. Ensure that this does not affect any existing functionality that relies on this package.

  • 86-93: The GetGasBlock function has been added to the TestTransactionSubmitter interface. Ensure that all implementations of this interface have been updated accordingly.

  • 100-106: The GetGasBlock function has been implemented in the txSubmitterImpl struct. This function is a wrapper around the getGasBlock function, which is presumably a private function in the same struct.

ethergo/submitter/submitter.go (4)
  • 64-71: The addition of gasBlockCache to the txSubmitterImpl struct is a good move for performance optimization. It allows the caching of gas blocks for different chains, which can reduce the number of RPC calls when the HeaderByNumber call fails. However, please ensure that the cache is properly managed to avoid potential memory leaks or stale data.

  • 80-93: The NewTransactionSubmitter function has been updated to initialize the gasBlockCache. This is a good practice as it ensures that the cache is ready for use when the transaction submitter is created.

  • 375-382: The getGasBlock function now accepts a chainID parameter. This is a breaking change and all calls to this function throughout the codebase should be updated to match the new signature. Also, the error handling has been improved to return the error when the gas block retrieval fails, which prevents a potential null pointer exception.

  • 412-434: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [397-434]

The getGasBlock function has been updated to support the caching mechanism. If the HeaderByNumber RPC call fails, the function will attempt to load the gas block from the cache. If the gas block is not in the cache, an error is returned. This is a good approach as it provides a fallback mechanism when the RPC call fails. However, please ensure that the cache is updated regularly to avoid serving stale data.

@codecov
Copy link

codecov bot commented Oct 19, 2023

Codecov Report

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

Comparison is base (4416f0a) 50.69210% compared to head (48d19f0) 50.84105%.
Report is 19 commits behind head on master.

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #1465         +/-   ##
===================================================
+ Coverage   50.69210%   50.84105%   +0.14894%     
===================================================
  Files            356         366         +10     
  Lines          24274       25147        +873     
  Branches         267         268          +1     
===================================================
+ Hits           12305       12785        +480     
- Misses         10775       11122        +347     
- Partials        1194        1240         +46     
Flag Coverage Δ
agents 45.27423% <ø> (-1.50052%) ⬇️
cctp-relayer 63.33333% <ø> (?)
ethergo 60.92061% <91.66667%> (+0.47243%) ⬆️
explorer 25.43225% <ø> (ø)
omnirpc 53.12024% <ø> (-0.07611%) ⬇️
promexporter 41.02564% <ø> (?)
scribe 52.02703% <ø> (+0.01714%) ⬆️

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

Files Coverage Δ
packages/contracts-core/contracts/Destination.sol 87.50000% <100.00000%> (ø)
packages/contracts-core/contracts/GasOracle.sol 100.00000% <100.00000%> (ø)
packages/contracts-core/contracts/Origin.sol 95.45455% <100.00000%> (+0.21644%) ⬆️
packages/contracts-core/contracts/Summit.sol 96.59091% <100.00000%> (ø)
...ages/contracts-core/contracts/hubs/SnapshotHub.sol 83.19328% <100.00000%> (ø)
.../contracts-core/contracts/inbox/StatementInbox.sol 89.74359% <100.00000%> (ø)
...ontracts-core/contracts/manager/BondingManager.sol 86.58537% <100.00000%> (ø)
.../contracts-core/contracts/manager/LightManager.sol 96.66667% <100.00000%> (ø)
ethergo/submitter/submitter.go 59.51557% <91.66667%> (+6.99757%) ⬆️

... and 21 files with indirect coverage changes

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

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 62f02fb and db17819.
Files selected for processing (1)
  • ethergo/submitter/submitter.go (7 hunks)
Additional comments (Suppressed): 6
ethergo/submitter/submitter.go (6)
  • 64-71: The addition of gasBlockCache to the txSubmitterImpl struct is a good approach to mitigate the risk of a null pointer when failing to get the gas block. It's a map that stores the gas block for different chains, which can be used as a fallback when fetching the gas block from the chain fails.

  • 80-93: The NewTransactionSubmitter function is updated to initialize the gasBlockCache map. This is a necessary step to ensure that the cache is ready for use when the transaction submitter is created.

  • 374-381: The setGasPrice function now passes the chainID to the getGasBlock function. This is a change in the function signature of getGasBlock, so ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 398-402: The getGasBlock function signature has been updated to include the chainID parameter. This is necessary for the function to fetch the correct gas block from the cache when the HeaderByNumber RPC call fails.

  • 411-426: The getGasBlock function has been modified to retrieve the gas block from the cache if the HeaderByNumber RPC call fails. This is a good fallback mechanism that can prevent null pointer errors when the RPC call fails. However, it's important to note that the cached gas block might not be the latest one if the cache hasn't been updated recently.

  • 428-431: The getGasBlock function now caches the latest gas block after successfully fetching it from the chain. This ensures that the cache is always updated with the latest gas block, which can be used as a fallback when the HeaderByNumber RPC call fails.

@github-actions github-actions bot added the M-ci Module: CI label Oct 19, 2023
@trajan0x
Copy link
Contributor

trajan0x commented Oct 19, 2023

Trying to fix add-label action, as it seems the andymckay/labeler action has been deprecated for over a year: Whatever caused this was probably an issue between #1399 and now

image

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: 2

Commits Files that changed from the base of the PR and between db17819 and cccaf4a.
Files selected for processing (1)
  • .github/workflows/go.yml (1 hunks)

.github/workflows/go.yml Outdated Show resolved Hide resolved
.github/workflows/go.yml Outdated 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 cccaf4a and 39a9274.
Files selected for processing (1)
  • .github/workflows/go.yml (1 hunks)
Files skipped from review due to trivial changes (1)
  • .github/workflows/go.yml

@github-actions github-actions bot removed the M-ci Module: CI label Oct 20, 2023
Copy link
Contributor

@trajan0x trajan0x left a comment

Choose a reason for hiding this comment

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

LGTM

ethergo/submitter/submitter.go Outdated 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 39a9274 and 48d19f0.
Files ignored due to filter (10)
  • agents/go.mod
  • agents/go.sum
  • contrib/promexporter/go.mod
  • contrib/promexporter/go.sum
  • ethergo/go.mod
  • ethergo/go.sum
  • services/cctp-relayer/go.mod
  • services/cctp-relayer/go.sum
  • services/omnirpc/go.mod
  • services/omnirpc/go.sum
Files selected for processing (1)
  • ethergo/submitter/submitter.go (7 hunks)
Additional comments (Suppressed): 6
ethergo/submitter/submitter.go (6)
  • 4-17: The import of github.com/puzpuzpuz/xsync/v2 is new and is used for the lastGasBlockCache in the txSubmitterImpl struct. Ensure that this package is added to the project dependencies.

  • 65-72: The lastGasBlockCache field has been added to the txSubmitterImpl struct. This cache is used to store the last gas block for a given chain. This is a good addition as it can improve performance by reducing the number of RPC calls to get the gas block.

  • 81-94: The NewTransactionSubmitter function has been updated to initialize the lastGasBlockCache field in the txSubmitterImpl struct. This is a necessary change to ensure that the cache is properly initialized when a new transaction submitter is created.

  • 376-382: The getGasBlock function now takes an additional chainID parameter. This change is necessary to support the new caching behavior. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 399-403: The getGasBlock function signature has been updated to include a chainID parameter. This change is necessary to support the new caching behavior. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 412-433: The getGasBlock function has been updated to use the lastGasBlockCache when the HeaderByNumber RPC call fails. This is a good change as it can improve performance by reducing the number of RPC calls. However, it's important to note that this could potentially lead to using stale gas block data if the cache is not updated frequently enough.

@trajan0x
Copy link
Contributor

are agents flaking here? Or did I introduce a regression?

@dwasse
Copy link
Collaborator Author

dwasse commented Oct 20, 2023

are agents flaking here? Or did I introduce a regression?

Hard to say- the retry settings on the agents CI may be too lenient. Checking locally

@dwasse dwasse merged commit 826fa32 into master Oct 20, 2023
52 checks passed
@dwasse dwasse deleted the feat/submitter-gas-block branch October 20, 2023 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code needs-go-generate-agents size/s
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants