-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
op-service: Refactor EthClient
with ReceiptsProvider
abstraction
#8130
Conversation
a38d79b
to
987402c
Compare
987402c
to
b26adb6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good generally, I just think we need to preserve the ability to reuse the receipts we do get before an error with the basic rpc kind. Everything else I think gets everything or nothing.
b26adb6
to
5267327
Compare
@coderabbitai review |
WalkthroughWalkthroughThe changes revolve around the Ethereum client configuration and receipt fetching in an Ethereum-Optimism service. A new Changes
TipsChat with CodeRabbit Bot (
|
There was a problem hiding this 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
Configuration used: CodeRabbit UI
Files selected for processing (4)
- op-service/sources/eth_client.go (6 hunks)
- op-service/sources/receipts.go (8 hunks)
- op-service/sources/reth_db.go (2 hunks)
- op-service/sources/reth_db_stub.go (1 hunks)
Additional comments: 10
op-service/sources/eth_client.go (6)
63-70: The addition of the
RethDBPath
field in theEthClientConfig
struct is a significant change that enables the use of therethdb
receipts fetcher. This is a good example of extending functionality while maintaining backward compatibility.82-96: The conditional logic in the
Check
method ensures that theRethDBPath
is only used whenrethdb
support is built into the binary. This is a good practice to prevent runtime errors due to misconfiguration.107-120: The
EthClient
struct has been refactored to include arecProvider
field, which is an instance of theReceiptsProvider
interface. This change improves modularity and allows for different implementations of receipt fetching.126-128: The
payloadsCache
field in theEthClient
struct is a cache for payloads by hash, which is consistent with the other caching strategies in the client.134-150: The
NewEthClient
function has been updated to use the newrecProvider
field and the new configuration options. This change is necessary to integrate the new receipts fetching logic.314-333: The
FetchReceipts
method has been updated to use therecProvider
to fetch receipts. This change aligns with the refactor to use theReceiptsProvider
interface and improves the method's flexibility.op-service/sources/receipts.go (4)
385-388: The new constants
RPCKindBasic
,RPCKindAny
, andRPCKindStandard
have been added to theRPCProviderKind
type. Ensure that these new kinds are integrated and handled whereverRPCProviderKind
is used throughout the codebase.400-401: The
RPCKindStandard
constant has been added to theRPCProviderKinds
slice. Verify that this addition is reflected in all relevant parts of the codebase, such as configuration parsing and validation.558-569: The
AvailableReceiptsFetchingMethods
function has been updated to handle the newRPCKindBasic
,RPCKindAny
, andRPCKindStandard
kinds. Verify that the logic for selecting available methods aligns with the intended behavior for these new kinds.574-580: The
PickBestReceiptsFetchingMethod
function has been updated with logic specific toRPCKindAlchemy
. Ensure that the cost-benefit analysis for usingAlchemyGetTransactionReceipts
over other methods is correct and that the threshold oftxCount > 250/15
is appropriate.
Semgrep found 6 Named return arguments to functions must be appended with an underscore ( Semgrep found 1
Inputs to functions must be prepended with an underscore ( |
There was a problem hiding this 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
Configuration used: CodeRabbit UI
Files selected for processing (1)
- op-service/sources/receipts_test.go (1 hunks)
Additional comments: 2
op-service/sources/receipts_test.go (2)
574-648: The
TestBasicRPCReceiptsFetcherConcurrency
function correctly tests the concurrency of fetching receipts as described in the summary. It sets up a mock RPC, starts multiple fetchers, and asserts the results, ensuring that the expected number of calls toBatchCallContext
is less than the number of fetchers, which implies that some calls are being shared and not made concurrently. The use of a barrier channel to synchronize the start of the fetchers is a good practice for concurrency testing. The function also logs the JSON representation of the fetched receipts, which could be useful for debugging.650-657: The
requireEqualReceipt
helper function is present and used within theTestBasicRPCReceiptsFetcherConcurrency
function to compare receipts, as described in the summary. This function ensures that the expected and actual receipts are equal by comparing their JSON representations.
e01f9ca
to
c56ab2f
Compare
c56ab2f
to
0745c50
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Description
This PR adds a
ReceiptsProvider
abstraction to theEthClient
and extracts any receipts fetching logic into separate provider implementations.It's an implementation of this proposed design.
Changes
receipts.go
toreceipts_rpc.go
, which increased the diff. But all types and functions around the rpc kind (RPCKind...
,AvailableReceiptsFetchingMethods
,PickBestReceiptsFetchingMethod
, ...) were moved over but otherwise not modified.Tests
All existing tests of receipts fetching pass. And a bunch of new tests were added
IterativeBatchCall
,Additional context
This refactor provides the basis for allowing for more modular implementations around receipts fetching.
EthClient
(this isn't done in this PR yet, but now easily possible).EthClient
without leaking implementation details into it.Possible Follow-ups
InfoAndTxHashesByHash
method toEthClient
(see one comment below).RethDBReceiptsFetcher
#8225EthClient
for header and block requests.Metadata