-
Notifications
You must be signed in to change notification settings - Fork 91
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
Make settlement indexing compatible with smart contract solvers #3177
Comments
Why do we ultimately need to extract With that, we probably need to extract the |
Also, in all of the examples you provided, EOA (non-solver) -> helper() -> settle() |
I was not aware of that. Was there a reason we didn't delete it already?
True, there is an underlying assumption that was not mentioned here. Any address that is allowed to call the helper contract transitively also needs to be a solver. Otherwise anybody could call the helper contract to steal surplus from user orders without posting any bond. |
I thought we will need it since we planned to implement circuit breaker in autopilot as well, but we never did, so right now it's not used. |
After implementing this in #3233, I think we probably don't need an e2e test for this task, but rather an example of transaction calldata where smart contract solver is used. |
# Description Implements first part of #3177 # Changes - [ ] Uses `trace_transaction` function to get traces and extract the calldata of `settle` call ## How to test Existing tests show that no regression bugs were introduced. Final e2e test should cover this part of the code. Although by manually testing the `trace_transaction` I am pretty sure the code is correct. <!-- ## Related Issues Fixes # -->
Background
The
autopilot
indexes transactions withSettlement
events coming from the settlement contract. It decodes the call data for the call and extracts some relevant information from it.This code splits the entire calldata of the tx into data (
settle()
call) and metadata (auction_id
added at the end). Thedata
later gets parsed here.That logic only works if an EOA directly called
settle()
. If instead there was a smart contract solver (or some other helper contract for that matter) the calldata of the transaction would not contain the call to thesettle()
function but rather to some other contract. This is a completely different function call which would cause the current decoding logic to fail.To accommodate these new use cases we'd have to make use of
trace_call
functionality. That way we could resimulate the entire transaction, step through the individual traces and find the trace for the actualsettle()
call (target address is settlement contract and function selector is0x13d79a0b
).Details
The suggested course of action looks like this:
1. implement actual change
First of all we need a convenient way to resimulate a tx and get trace calls out of it. This should be easily doable by calling
web3.trace().transaction(settlement_tx_hash)
.This will return a bunch of traces from the particular tx_hash which needs to be parsed to get the correct
gas_used
,calldata
and thesolver
that actually initiated the call.To identify the actual
settle()
call find the trace whereaction.to == 0x9008d19f58aabd9ed0d60971565aa8510560ab41
andaction.input.starts_with(0x13d79a0b)
.Naively we could assume that whoever calls
settle()
is the actual solver address but that does not work with helper contracts that sit between solver contract and settlement contract.To handle these correctly we could configure a list of allow listed helper contracts. Start from
settle()
and go up the call stack until the caller is no longer one of the configured contracts.That would allow us to correctly identify the real solver address for all these cases (from regular to exotic):
EOA -> settle()
EOA -> helper() -> settle()
EOA -> helper() -> helper() -> settle()
EOA -> SC solver -> helper() -> helper() -> settle()
2. e2e test
Ultimately this change should be tested by an e2e test. Examples can be found here. For the CI to correctly pick up the new test it should be flagged with
#[ignore]
and the name should start withlocal_node
(to indicate that it should be run withanvil
).Here is how the CI will run the tests. To run the tests yourself you can run the same command locally. Just make sure to also run the necessary DB docker containers too (run
docker compose up -d
in the root directory).The biggest hurdle will likely be setting up a smart contract solver for the e2e test. The problem is that this feature is not supported out of the box by the reference driver. So in order to test this you'll likely have to create a mock driver that you can tell which exact API response to return. For inspiration take a lock at the existing mock solver.
Acceptance criteria
Ultimately the e2e test should assert that the data indexed in the DB is correct.
The text was updated successfully, but these errors were encountered: