-
Notifications
You must be signed in to change notification settings - Fork 92
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
Observe multiple contracts for ETH flow #3249
Conversation
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.
Approach looks like it should work but I think the code in the refunder could be simplified quite a lot.
.map(|contract| { | ||
contract | ||
.orders(ethcontract::tokens::Bytes(order_hash)) | ||
.batch_call(&mut batch) |
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.
The refunder
uses our auto batching logic under the hood. If make use of this this function would probably end up being a lot easier to read.
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.
Not sure what are you referring to exactly.
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.
The underlying HttpTransport
automatically batches individual RPC calls together. So instead of manually calling .batch_call()
you can simple do things like join_all(rpc_calls)
and it will do the same thing while being a lot easier to read.
@@ -98,63 +93,55 @@ impl RefundService { | |||
async fn identify_uids_refunding_status_via_web3_calls( | |||
&self, | |||
refundable_order_uids: Vec<EthOrderPlacement>, | |||
) -> Result<Vec<OrderUid>> { | |||
) -> Vec<(OrderUid, Vec<CoWSwapEthFlowAddress>)> { |
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.
Given that an OrderUid
can only belong to a single contract we can ditch the vector. And I would suggest to simply copy the contract type instead of messing around with the address to make the code easier to read. The refunder is doing barely any work anyway so I think we should optimize for readability over performance here.
) -> Vec<(OrderUid, Vec<CoWSwapEthFlowAddress>)> { | |
) -> Vec<(OrderUid, CoWSwapEthFlow)> { |
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.
Using contract instead of address is not convenient since PartialEq and Hash are not implemented for CoWSwapEthFlow
crates/autopilot/src/database/onchain_order_events/event_retriever.rs
Outdated
Show resolved
Hide resolved
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, assuming all the comments above will be addressed.
Pushed some changes directly:
|
LG. |
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.
I went quickly through the code and the changes look reasonable to me, everything is consistent with my understanding of the contract and the refunder.
Description
Implements the idea explained here: #3248 (comment)
The Ethflow contract of interest: https://etherscan.io/address/0x40a50cf069e992aa4536211b23f286ef88752187#code (probably useful to better review and understand refunder code changes)
This solution has a limitation: we can't specify a block number to start indexing the new contract. Upon autopilot restart, indexing resumes from the latest block recorded in the database. This approach assumes synchronized and atomic insertion of events for both the old and new contracts.
As a result, new contract events will only be indexed from the point when the new contract address is added to the autopilot configuration.
This is acceptable under the following assumptions:
Changes
EthFlowRefundRetriever
andCoWSwapOnchainOrdersContract
are now observing multiple ethflow contracts at the same time.How to test
Existing e2e tests.
Updated refunder e2e test to simulate two orders being created on two different ethflow contracts and being properly refunded.
I also manually verified (through observing logs on e2e tests) that indexing from multiple contracts works properly.