Skip to content

Commit 863f449

Browse files
authored
Merge branch 'cowprotocol:main' into main
2 parents 9a80bbb + d33bcfa commit 863f449

File tree

6 files changed

+49
-29
lines changed

6 files changed

+49
-29
lines changed

crates/database/src/ethflow_orders.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ AND t.order_uid is null
140140
AND eo.valid_to < $1
141141
AND o.sell_amount = oq.sell_amount
142142
AND (1.0 - o.buy_amount / GREATEST(oq.buy_amount,1)) >= $3
143-
AND eo.valid_to - extract(epoch from creation_timestamp)::int > $2
143+
AND eo.valid_to - extract(epoch from o.creation_timestamp)::int > $2
144144
"#;
145145
sqlx::query_as(QUERY)
146146
.bind(since_valid_to)

crates/database/src/trades.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use {
33
bigdecimal::BigDecimal,
44
futures::stream::BoxStream,
55
sqlx::PgConnection,
6-
tracing::instrument,
6+
tracing::{Instrument, info_span, instrument},
77
};
88

99
#[derive(Clone, Debug, Default, Eq, PartialEq, sqlx::FromRow)]
@@ -21,12 +21,11 @@ pub struct TradesQueryRow {
2121
pub auction_id: Option<AuctionId>,
2222
}
2323

24-
#[instrument(skip_all)]
2524
pub fn trades<'a>(
2625
ex: &'a mut PgConnection,
2726
owner_filter: Option<&'a Address>,
2827
order_uid_filter: Option<&'a OrderUid>,
29-
) -> BoxStream<'a, Result<TradesQueryRow, sqlx::Error>> {
28+
) -> instrument::Instrumented<BoxStream<'a, Result<TradesQueryRow, sqlx::Error>>> {
3029
const COMMON_QUERY: &str = r#"
3130
SELECT
3231
t.block_number,
@@ -72,6 +71,7 @@ LEFT OUTER JOIN LATERAL (
7271
.bind(owner_filter)
7372
.bind(order_uid_filter)
7473
.fetch(ex)
74+
.instrument(info_span!("trades"))
7575
}
7676

7777
#[derive(Clone, Debug, Default, Eq, PartialEq, sqlx::FromRow)]
@@ -214,6 +214,7 @@ mod tests {
214214
expected: &[TradesQueryRow],
215215
) {
216216
let mut filtered = trades(db, owner_filter, order_uid_filter)
217+
.into_inner()
217218
.try_collect::<Vec<_>>()
218219
.await
219220
.unwrap();
@@ -287,6 +288,7 @@ mod tests {
287288

288289
let now = std::time::Instant::now();
289290
trades(&mut db, Some(&ByteArray([2u8; 20])), None)
291+
.into_inner()
290292
.try_collect::<Vec<_>>()
291293
.await
292294
.unwrap();

crates/ethrpc/src/extensions.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use {
44
serde::{Deserialize, Serialize},
55
std::collections::HashMap,
6-
tracing::instrument,
6+
tracing::{Instrument, instrument::Instrumented},
77
web3::{
88
self,
99
Transport,
@@ -23,20 +23,19 @@ where
2323
call: CallRequest,
2424
block: BlockId,
2525
overrides: HashMap<H160, StateOverride>,
26-
) -> CallFuture<Bytes, T::Out>;
26+
) -> Instrumented<CallFuture<Bytes, T::Out>>;
2727
}
2828

2929
impl<T> EthExt<T> for web3::api::Eth<T>
3030
where
3131
T: Transport,
3232
{
33-
#[instrument(skip_all)]
3433
fn call_with_state_overrides(
3534
&self,
3635
call: CallRequest,
3736
block: BlockId,
3837
overrides: StateOverrides,
39-
) -> CallFuture<Bytes, T::Out> {
38+
) -> Instrumented<CallFuture<Bytes, T::Out>> {
4039
let call = helpers::serialize(&call);
4140
let block = helpers::serialize(&block);
4241
let overrides = helpers::serialize(&overrides);
@@ -45,6 +44,7 @@ where
4544
self.transport()
4645
.execute("eth_call", vec![call, block, overrides]),
4746
)
47+
.instrument(tracing::info_span!("eth_call"))
4848
}
4949
}
5050

crates/orderbook/src/database/trades.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ impl TradeRetrieving for Postgres {
3636
filter.owner.map(|owner| ByteArray(owner.0)).as_ref(),
3737
filter.order_uid.map(|uid| ByteArray(uid.0)).as_ref(),
3838
)
39+
.into_inner()
3940
.map_err(anyhow::Error::from)
4041
.try_collect::<Vec<TradesQueryRow>>()
4142
.await?;

database/README.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ Associates the 32 bytes contract app data with the corresponding full app data.
1414

1515
See [here](https://github.com/cowprotocol/services/issues/1465) for more details. In this table the contract app data is either the old unixfs based scheme, or the new keccak scheme. The new scheme can be validated by keccak-256 hashing the full app data, which should produce the contract app data. The old scheme cannot be validated.
1616

17-
Column | Type | Nullable | Details
18-
---------------------|-------|----------|-------
19-
contract\_app\_data | bytea | not null | 32 bytes. Referenced by `orders.app_data`.
20-
full\_app\_data | bytea | not null | Is utf-8 but not stored as string because the raw bytes are important for hashing.
17+
Column | Type | Nullable | Details
18+
----------------------|------- |----------|-------
19+
contract\_app\_data | bytea | not null | 32 bytes. Referenced by `orders.app_data`.
20+
full\_app\_data | bytea | not null | Is utf-8 but not stored as string because the raw bytes are important for hashing.
21+
creation\_timestamp | timestamptz | not null | when the entry was created or when column was added (DEFAULT NOW() for new and 1970-01-01 for historical data)
2122

2223
Indexes:
2324
- "app\_data\_pkey" PRIMARY KEY, btree (`contract_app_data`)
@@ -61,7 +62,7 @@ Indexes:
6162

6263
### competition\_auctions
6364

64-
Contains all auctions for which a valid solver competition exists.
65+
Contains all auctions for which a valid solver competition exists.
6566

6667
Column | Type | Nullable | Details
6768
---------------|---------|----------|--------
@@ -202,7 +203,7 @@ Indexes:
202203

203204
### order\_execution
204205

205-
Contains metainformation for trades, required for reward computations that cannot be recovered from the blockchain and are not stored in a persistent manner somewhere else.
206+
Contains metainformation for trades, required for reward computations that cannot be recovered from the blockchain and are not stored in a persistent manner somewhere else.
206207
Protocol fee tokens/amounts are stored in the same order as fee policies in fee_policies table.
207208

208209
Column | Type | Nullable | Details
@@ -230,17 +231,18 @@ Indexes:
230231

231232
Quotes that an order was created with. These quotes get stored persistently and can be used to evaluate how accurate the quoted fee predicted the execution cost that actually happened on-chain.
232233

233-
Column | Type | Nullable | Details
234-
--------------------|---------|----------|--------
235-
order\_uid | bytea | not null | order that this quote belongs to
236-
gas\_amount | double | not null | estimated gas used by the quote used to create this order with
237-
gas\_price | double | not null | gas price at the time of order creation
238-
sell\_token\_price | double | not null | ether-denominated price of sell\_token at the time of quoting. The ether value of `x` sell\_tokens is `x * sell_token_price`.
239-
sell\_amount | numeric | not null | sell\_amount of the quote used to create the order with
240-
buy\_amount | numeric | not null | buy\_amount of the quote used to create the order with
241-
solver | bytea | not null | public address of the solver that provided this quote
242-
verified | boolean | not null | information if quote was verified
243-
metadata | json | not null | additional data associated with the quote in json format
234+
Column | Type | Nullable | Details
235+
---------------------|-------------|----------|--------
236+
order\_uid | bytea | not null | order that this quote belongs to
237+
gas\_amount | double | not null | estimated gas used by the quote used to create this order with
238+
gas\_price | double | not null | gas price at the time of order creation
239+
sell\_token\_price | double | not null | ether-denominated price of sell\_token at the time of quoting. The ether value of `x` sell\_tokens is `x * sell_token_price`.
240+
sell\_amount | numeric | not null | sell\_amount of the quote used to create the order with
241+
buy\_amount | numeric | not null | buy\_amount of the quote used to create the order with
242+
solver | bytea | not null | public address of the solver that provided this quote
243+
verified | boolean | not null | information if quote was verified
244+
metadata | json | not null | additional data associated with the quote in json format
245+
creation\_timestamp | timestamptz | not null | when the entry was created (DEFAULT NOW() for new and 1970-01-01 for historical data)
244246

245247
Indexes:
246248
- PRIMARY KEY: btree(`order_uid`)
@@ -354,7 +356,7 @@ All solutions reported by solvers, that were part of a solver competition. A sol
354356

355357
Column | Type | Nullable | Details
356358
---------------|-----------|----------|--------
357-
auction\_id | bigint | not null | auction for which the solution was proposed
359+
auction\_id | bigint | not null | auction for which the solution was proposed
358360
uid | bigint | not null | unique id of the proposed solution within a single auction
359361
id | numeric | not null | id of the proposed solution as reported by the solver
360362
solver | bytea | not null | solver submission address
@@ -369,11 +371,11 @@ Indexes:
369371

370372
### proposed\_trade\_executions
371373

372-
Contains all order executions for proposed solutions.
374+
Contains all order executions for proposed solutions.
373375

374376
Column | Type | Nullable | Details
375377
----------------|----------|----------|--------
376-
auction\_id | bigint | not null | auction for which the order was executed
378+
auction\_id | bigint | not null | auction for which the order was executed
377379
solution_uid | bigint | not null | `uid` from `proposed\_solutions`
378380
order_uid | bigint | not null | id of the order
379381
executed\_sell | numeric | not null | the effective amount that left the user's wallet including all fees
@@ -388,7 +390,7 @@ Solvers report orders they solved on each competition. Orders that don't exist i
388390

389391
Column | Type | Nullable | Details
390392
--------------|--------------------|----------|--------
391-
auction\_id | bigint | not null | auction for which the order was executed
393+
auction\_id | bigint | not null | auction for which the order was executed
392394
solution_uid | bigint | not null | `uid` from `proposed\_solutions`
393395
order_uid | bigint | not null | id of the order
394396
sell\_token | numeric | not null | the effective amount that left the user's wallet including all fees
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- This adds `creation_timestamp` column to `app_data`, `order_quotes`
2+
-- in order to help data ingestion for our analytics team
3+
4+
ALTER TABLE app_data
5+
ADD COLUMN creation_timestamp timestamptz NOT NULL SET DEFAULT '1970-01-01 00:00:00+00'::timestamptz;
6+
7+
ALTER TABLE order_quotes
8+
ADD COLUMN creation_timestamp timestamptz NOT NULL SET DEFAULT '1970-01-01 00:00:00+00'::timestamptz;
9+
10+
-- Set default for future inserts
11+
ALTER TABLE app_data
12+
ALTER COLUMN creation_timestamp SET DEFAULT NOW();
13+
14+
ALTER TABLE order_quotes
15+
ALTER COLUMN creation_timestamp SET DEFAULT NOW();

0 commit comments

Comments
 (0)