Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions database/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,18 @@ Indexes:

Stores data and metadata of [`Settlement`](https://github.com/cowprotocol/contracts/blob/main/src/contracts/GPv2Settlement.sol#L67-L68) events emitted from the settlement contract.

Column | Type | Nullable | Details
---------------|--------|----------|--------
block\_number | bigint | not null | block in which the settlement happened
log\_index | bigint | not null | index in which the event was emitted
solver | bytea | not null | public address of the executing solver
tx\_hash | bytea | not null | transaction hash in which the settlement got executed
auction\_id | bigint | nullable | corresponding auction ID that initiated the settlement
solution\_uid | bigint | nullable | corresponding winning solver's solution UID, which is also used to identify settlements from the current environment
Column | Type | Nullable | Details
-----------------------|----------------|----------|--------
block\_number | bigint | not null | block in which the settlement happened
log\_index | bigint | not null | index in which the event was emitted
solver | bytea | not null | public address of the executing solver
tx\_hash | bytea | not null | transaction hash in which the settlement got executed
auction\_id | bigint | nullable | corresponding auction ID that initiated the settlement
solution\_uid | bigint | nullable | corresponding winning solver's solution UID, which is also used to identify settlements from the current environment
gas\_used | numeric(78, 0) | nullable | gas consumed by the settlement transaction, read from the transaction receipt
effective\_gas\_price | numeric(78, 0) | nullable | gas price actually paid per unit of gas (in wei), read from the transaction receipt

The total on-chain cost of a settlement is `gas_used * effective_gas_price`. Both columns are populated by the `autopilot`'s settlement observer and are only set for settlements observed after the migration that added them; historical rows were not backfilled, so consumers (e.g. the `orderbook` attributing gas cost to individual trades and orders) must handle `NULL`.

Indexes:
- PRIMARY KEY: btree(`block_number`,`log_index`)
Expand Down
11 changes: 11 additions & 0 deletions database/sql/V116__settlement_gas_cost.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Store the actual on-chain gas cost of each settlement transaction.
--
-- These values are read from the transaction receipt by the autopilot's
-- settlement observer, letting the orderbook attribute a real gas cost
-- to individual trades and orders.
--
-- Nullable: only populated for settlements observed after this migration is
-- deployed (no historical backfill).
ALTER TABLE settlements
ADD COLUMN gas_used numeric(78, 0),
ADD COLUMN effective_gas_price numeric(78, 0);
Comment on lines +9 to +11

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The bot reminder asks to update the DB README when adding columns. The settlements table docs still don't list gas_used / effective_gas_price — worth adding the two rows so the schema doc stays in sync.

Type/naming look good: numeric(78,0) matches the u256 convention used elsewhere (and the existing gas_used numeric(78,0) in V048__create_settlement_rewards.sql), and nullable additive columns are backward-compatible with the k8s rollout overlap.

Loading