Skip to content

bug: Flashloans: wrong solver address saved to database #3335

@sunce86

Description

@sunce86

Problem

The example order having flashloan was executed on Sepolia: https://explorer.cow.fi/sepolia/orders/0xe5e140e989a8ab8a66a8fe70d3dbd1095935d6a9355a21752c7f7a50d9e3e49b35ed9a9d1122a1544e031cc92fcc7ea599e28d9c67dc304c

Backend expects that proper solver (submission address) is saved to the database table settlements::solver. Instead, when order contains a flashloan, flashloan router address is saved instead of solver submission address.

The reason for this is settlement event containing flashloan router address as solver.

One function that depends on this is find_settlement_transaction: https://github.com/cowprotocol/services/blob/main/crates/database/src/settlements.rs#L6-L22
Edit: another dependency: https://github.com/cowprotocol/services/blob/main/crates/database/src/solver_competition.rs#L202

There are at least two ways to handle this:

  1. Order onchain events before inserting into database (specifically, make sure flashloan event comes after the settlement event), then when handling flashloan event, take solver address and overwrite settlement event entry that is already processed. This requires flashloan event to contain tx hash and solver address(only solver address, since tx_hash is retrievable for every onchain event), because we could have more than one settlement in the same block.

  2. Create a new database table to store flashloan events, then the backend code has to be aware that this indirection is not automatic and needs to handle it properly.

I don't have a strong opinion which solution is better. (1) makes settlement::solver easier to use across other sql queries, however it does introduce a difference between onchain event and what is stored in the database, which may or may not turn out as a bad decision in the future.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingtrack:maintenancemaintenance track

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions