Skip to content

Commit 06ae435

Browse files
authored
Codebase-wide formatting (#1167)
Update the formatting on the whole codebase to match the driver, like discussed before. This does not change default options, but rather standardizes formatting for things that are otherwise not formatted consistently. This will cause merge conflicts. Once this is approved, I'm going to ping everybody with the exact date when I intend to merge this so we can minimize the impact.
1 parent f0b9067 commit 06ae435

File tree

324 files changed

+7553
-5860
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

324 files changed

+7553
-5860
lines changed

crates/alerter/src/main.rs

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
// This application observes the order book api and tries to determine if the solver is down. It
2-
// does this by checking if no trades have been made recently and if so checking if it finds a
3-
// matchable order according to an external price api (0x). If this is the case it alerts.
4-
5-
use anyhow::{Context, Result};
6-
use chrono::{DateTime, Utc};
7-
use clap::Parser;
8-
use model::{
9-
order::{OrderClass, OrderKind, OrderStatus, OrderUid, BUY_ETH_ADDRESS},
10-
u256_decimal,
1+
// This application observes the order book api and tries to determine if the
2+
// solver is down. It does this by checking if no trades have been made recently
3+
// and if so checking if it finds a matchable order according to an external
4+
// price api (0x). If this is the case it alerts.
5+
6+
use {
7+
anyhow::{Context, Result},
8+
chrono::{DateTime, Utc},
9+
clap::Parser,
10+
model::{
11+
order::{OrderClass, OrderKind, OrderStatus, OrderUid, BUY_ETH_ADDRESS},
12+
u256_decimal,
13+
},
14+
primitive_types::{H160, U256},
15+
prometheus::IntGauge,
16+
reqwest::Client,
17+
std::{
18+
collections::HashMap,
19+
time::{Duration, Instant},
20+
},
21+
url::Url,
1122
};
12-
use primitive_types::{H160, U256};
13-
use prometheus::IntGauge;
14-
use reqwest::Client;
15-
use std::{
16-
collections::HashMap,
17-
time::{Duration, Instant},
18-
};
19-
use url::Url;
2023

2124
#[derive(Debug, serde::Deserialize, Eq, PartialEq)]
2225
#[serde(rename_all = "camelCase")]
@@ -103,7 +106,8 @@ impl OrderBookApi {
103106
}
104107
}
105108

106-
// Converts the eth placeholder address to weth. Leaves other addresses untouched.
109+
// Converts the eth placeholder address to weth. Leaves other addresses
110+
// untouched.
107111
fn convert_eth_to_weth(token: H160) -> H160 {
108112
let weth: H160 = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
109113
.parse()
@@ -186,8 +190,8 @@ struct Alerter {
186190
// Expose a prometheus metric so that we can use our Grafana alert infrastructure.
187191
//
188192
// Set to 0 or 1 depending on whether our alert condition is satisfied which is that there
189-
// hasn't been a trade for some time and that there is an order that has been matchable for some
190-
// time.
193+
// hasn't been a trade for some time and that there is an order that has been matchable for
194+
// some time.
191195
no_trades_but_matchable_order: IntGauge,
192196
api_get_order_min_interval: Duration,
193197
}
@@ -246,8 +250,8 @@ impl Alerter {
246250
let mut closed_orders: Vec<Order> = orders.into_values().map(|(order, _)| order).collect();
247251
// Keep only orders that were open last update and are not open this update.
248252
closed_orders.retain(|order| !self.open_orders.contains_key(&order.uid));
249-
// We're trying to find an order that has been filled. Try market orders first because they
250-
// are more likely to be.
253+
// We're trying to find an order that has been filled. Try market orders first
254+
// because they are more likely to be.
251255
closed_orders.sort_unstable_by_key(|order| match order.class {
252256
OrderClass::Market => 0u8,
253257
OrderClass::Limit(_) => 1,
@@ -278,13 +282,15 @@ impl Alerter {
278282
self.no_trades_but_matchable_order.set(0);
279283
// Delete all matchable timestamps.
280284
//
281-
// If we didn't do this what could happen is that first we mark an order as matchable
282-
// at t0. Then a trade happens so we skip the matchable update loop below because if
283-
// there was a recent trade we don't want to alert anyway. Then no trade happens for
284-
// long enough that we want to alert and the order is again matchable.
285-
// In this case we would alert immediately even though it could be the case that the
286-
// order wasn't matchable and just now became matchable again. We would wrongly assume
287-
// it has been matchable since t0 but we did not check this between now and then.
285+
// If we didn't do this what could happen is that first we mark an order as
286+
// matchable at t0. Then a trade happens so we skip the matchable
287+
// update loop below because if there was a recent trade we don't
288+
// want to alert anyway. Then no trade happens for long enough that
289+
// we want to alert and the order is again matchable. In this case
290+
// we would alert immediately even though it could be the case that the
291+
// order wasn't matchable and just now became matchable again. We would wrongly
292+
// assume it has been matchable since t0 but we did not check this
293+
// between now and then.
288294
for (_, instant) in self.open_orders.values_mut() {
289295
*instant = None;
290296
}
@@ -325,9 +331,8 @@ impl Alerter {
325331
impl AlertConfig {
326332
fn alert(&self, order: &Order) {
327333
tracing::error!(
328-
"No orders have been settled in the last {} seconds \
329-
even though order {} is solvable and has a price that \
330-
allows it to be settled according to 0x.",
334+
"No orders have been settled in the last {} seconds even though order {} is solvable \
335+
and has a price that allows it to be settled according to 0x.",
331336
self.time_without_trade.as_secs(),
332337
order.uid,
333338
);
@@ -372,8 +377,8 @@ struct Arguments {
372377
)]
373378
min_alert_interval: Duration,
374379

375-
/// How many errors in the update loop (fetching solvable orders or querying 0x) in a row
376-
/// must happen before we alert about them.
380+
/// How many errors in the update loop (fetching solvable orders or querying
381+
/// 0x) in a row must happen before we alert about them.
377382
#[clap(long, env, default_value = "5")]
378383
errors_in_a_row_before_alert: u32,
379384

@@ -383,7 +388,8 @@ struct Arguments {
383388
#[clap(long, env, default_value = "9588")]
384389
metrics_port: u16,
385390

386-
/// Minimum time between get order requests to the api. Without this the api can rate limit us.
391+
/// Minimum time between get order requests to the api. Without this the api
392+
/// can rate limit us.
387393
#[clap(long, env, default_value = "0.2", value_parser = shared::arguments::duration_from_seconds)]
388394
api_get_order_min_interval: Duration,
389395
}

crates/autopilot/src/arguments.rs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
use crate::limit_orders::QuotingStrategy;
2-
use primitive_types::H160;
3-
use shared::{
4-
arguments::display_option, bad_token::token_owner_finder, http_client, price_estimation,
1+
use {
2+
crate::limit_orders::QuotingStrategy,
3+
primitive_types::H160,
4+
shared::{
5+
arguments::display_option,
6+
bad_token::token_owner_finder,
7+
http_client,
8+
price_estimation,
9+
},
10+
std::{net::SocketAddr, num::NonZeroUsize, time::Duration},
11+
url::Url,
512
};
6-
use std::{net::SocketAddr, num::NonZeroUsize, time::Duration};
7-
use url::Url;
813

914
#[derive(clap::Parser)]
1015
pub struct Arguments {
@@ -23,13 +28,14 @@ pub struct Arguments {
2328
#[clap(flatten)]
2429
pub price_estimation: price_estimation::Arguments,
2530

26-
/// Address of the ethflow contract. If not specified, eth-flow orders are disabled.
31+
/// Address of the ethflow contract. If not specified, eth-flow orders are
32+
/// disabled.
2733
#[clap(long, env)]
2834
pub ethflow_contract: Option<H160>,
2935

3036
/// Timestamp at which we should start indexing eth-flow contract events.
31-
/// If there are already events in the database for a date later than this, then this date is
32-
/// ignored and can be omitted.
37+
/// If there are already events in the database for a date later than this,
38+
/// then this date is ignored and can be omitted.
3339
#[clap(long, env)]
3440
pub ethflow_indexing_start: Option<u64>,
3541

@@ -41,24 +47,27 @@ pub struct Arguments {
4147
#[clap(long, env, default_value = "0.0.0.0:9589")]
4248
pub metrics_address: SocketAddr,
4349

44-
/// Url of the Postgres database. By default connects to locally running postgres.
50+
/// Url of the Postgres database. By default connects to locally running
51+
/// postgres.
4552
#[clap(long, env, default_value = "postgresql://")]
4653
pub db_url: Url,
4754

4855
/// Skip syncing past events (useful for local deployments)
4956
#[clap(long, env)]
5057
pub skip_event_sync: bool,
5158

52-
/// List of token addresses that should be allowed regardless of whether the bad token detector
53-
/// thinks they are bad. Base tokens are automatically allowed.
59+
/// List of token addresses that should be allowed regardless of whether the
60+
/// bad token detector thinks they are bad. Base tokens are
61+
/// automatically allowed.
5462
#[clap(long, env, use_value_delimiter = true)]
5563
pub allowed_tokens: Vec<H160>,
5664

5765
/// List of token addresses to be ignored throughout service
5866
#[clap(long, env, use_value_delimiter = true)]
5967
pub unsupported_tokens: Vec<H160>,
6068

61-
/// The amount of time in seconds a classification of a token into good or bad is valid for.
69+
/// The amount of time in seconds a classification of a token into good or
70+
/// bad is valid for.
6271
#[clap(
6372
long,
6473
env,
@@ -71,7 +80,8 @@ pub struct Arguments {
7180
#[clap(long, env, default_value = "200")]
7281
pub pool_cache_lru_size: NonZeroUsize,
7382

74-
/// Which estimators to use to estimate token prices in terms of the chain's native token.
83+
/// Which estimators to use to estimate token prices in terms of the chain's
84+
/// native token.
7585
#[clap(
7686
long,
7787
env,
@@ -94,8 +104,8 @@ pub struct Arguments {
94104
#[clap(long, env, use_value_delimiter = true)]
95105
pub banned_users: Vec<H160>,
96106

97-
/// If the auction hasn't been updated in this amount of time the pod fails the liveness check.
98-
/// Expects a value in seconds.
107+
/// If the auction hasn't been updated in this amount of time the pod fails
108+
/// the liveness check. Expects a value in seconds.
99109
#[clap(
100110
long,
101111
env,
@@ -104,8 +114,8 @@ pub struct Arguments {
104114
)]
105115
pub max_auction_age: Duration,
106116

107-
/// If a limit order surplus fee is older than this, it will get refreshed. Expects a value in
108-
/// seconds.
117+
/// If a limit order surplus fee is older than this, it will get refreshed.
118+
/// Expects a value in seconds.
109119
#[clap(
110120
long,
111121
env,
@@ -153,7 +163,8 @@ pub struct Arguments {
153163
#[clap(long, env, value_parser = shared::arguments::duration_from_seconds)]
154164
pub network_block_interval: Option<Duration>,
155165

156-
/// Defines which strategies to apply when updating the `surplus_fee` of limit orders.
166+
/// Defines which strategies to apply when updating the `surplus_fee` of
167+
/// limit orders.
157168
#[clap(long, env, use_value_delimiter = true)]
158169
pub quoting_strategies: Vec<QuotingStrategy>,
159170
}

crates/autopilot/src/auction_transaction.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
1-
//! This module is responsible for associating auction ids with transaction hashes.
1+
//! This module is responsible for associating auction ids with transaction
2+
//! hashes.
23
//!
34
//! see database/sql/V037__auction_transaction.sql
45
//!
5-
//! When we put settlement transactions on chain there is no reliable way to know the transaction
6-
//! hash because we can create multiple transactions with different gas prices. What we do know is
7-
//! the account and nonce that the transaction will have which is enough to uniquely identify it.
6+
//! When we put settlement transactions on chain there is no reliable way to
7+
//! know the transaction hash because we can create multiple transactions with
8+
//! different gas prices. What we do know is the account and nonce that the
9+
//! transaction will have which is enough to uniquely identify it.
810
//!
9-
//! We build an association between account-nonce and tx hash by backfilling settlement events with
10-
//! the account and nonce of their tx hash. This happens in an always running background task.
11+
//! We build an association between account-nonce and tx hash by backfilling
12+
//! settlement events with the account and nonce of their tx hash. This happens
13+
//! in an always running background task.
1114
//!
12-
//! Alternatively we could change the event insertion code to do this but I (vk) would like to keep
13-
//! that code as fast as possible to not slow down event insertion which also needs to deal with
14-
//! reorgs. It is also nicer from a code organization standpoint.
15-
16-
use std::time::Duration;
17-
18-
use anyhow::{anyhow, Context, Result};
19-
use primitive_types::H256;
20-
use shared::{
21-
current_block::CurrentBlockStream, ethrpc::Web3, event_handling::MAX_REORG_BLOCK_COUNT,
15+
//! Alternatively we could change the event insertion code to do this but I (vk)
16+
//! would like to keep that code as fast as possible to not slow down event
17+
//! insertion which also needs to deal with reorgs. It is also nicer from a code
18+
//! organization standpoint.
19+
20+
use {
21+
crate::database::Postgres,
22+
anyhow::{anyhow, Context, Result},
23+
primitive_types::H256,
24+
shared::{
25+
current_block::CurrentBlockStream,
26+
ethrpc::Web3,
27+
event_handling::MAX_REORG_BLOCK_COUNT,
28+
},
29+
std::time::Duration,
30+
web3::types::TransactionId,
2231
};
23-
use web3::types::TransactionId;
24-
25-
use crate::database::Postgres;
2632

2733
pub struct AuctionTransactionUpdater {
2834
pub web3: Web3,
@@ -92,9 +98,7 @@ impl AuctionTransactionUpdater {
9298

9399
#[cfg(test)]
94100
mod tests {
95-
use super::*;
96-
use sqlx::Executor;
97-
use std::sync::Arc;
101+
use {super::*, sqlx::Executor, std::sync::Arc};
98102

99103
#[tokio::test]
100104
#[ignore]

crates/autopilot/src/database.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ pub mod orders;
77
mod quotes;
88
pub mod recent_settlements;
99

10-
use sqlx::{PgConnection, PgPool};
11-
use std::time::Duration;
10+
use {
11+
sqlx::{PgConnection, PgPool},
12+
std::time::Duration,
13+
};
1214

1315
#[derive(Debug, Clone)]
1416
pub struct Postgres(pub PgPool);

crates/autopilot/src/database/auction.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
use super::Postgres;
2-
use anyhow::{Context, Result};
3-
use database::{auction::AuctionId, quotes::QuoteKind};
4-
use futures::{StreamExt, TryStreamExt};
5-
use model::{auction::Auction, order::Order};
1+
use {
2+
super::Postgres,
3+
anyhow::{Context, Result},
4+
database::{auction::AuctionId, quotes::QuoteKind},
5+
futures::{StreamExt, TryStreamExt},
6+
model::{auction::Auction, order::Order},
7+
};
68

79
pub struct SolvableOrders {
810
pub orders: Vec<Order>,
911
pub latest_settlement_block: u64,
1012
}
11-
use chrono::{DateTime, Utc};
12-
use model::quote::QuoteId;
13-
use shared::{
14-
db_order_conversions::full_order_into_model_order,
15-
event_storing_helpers::{create_db_search_parameters, create_quote_row},
16-
order_quoting::{QuoteData, QuoteSearchParameters, QuoteStoring},
13+
use {
14+
chrono::{DateTime, Utc},
15+
model::quote::QuoteId,
16+
shared::{
17+
db_order_conversions::full_order_into_model_order,
18+
event_storing_helpers::{create_db_search_parameters, create_quote_row},
19+
order_quoting::{QuoteData, QuoteSearchParameters, QuoteStoring},
20+
},
1721
};
1822

1923
#[async_trait::async_trait]

crates/autopilot/src/database/auction_transaction.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
use anyhow::Context;
2-
use database::{auction_transaction::SettlementEvent, byte_array::ByteArray};
3-
use primitive_types::H160;
1+
use {
2+
anyhow::Context,
3+
database::{auction_transaction::SettlementEvent, byte_array::ByteArray},
4+
primitive_types::H160,
5+
};
46

57
impl super::Postgres {
68
pub async fn update_settlement_tx_info(

crates/autopilot/src/database/ethflow_events/event_retriever.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
//! A component that listens exclusively for `OrderRefund` events of the ethflow contract.
2-
use ethcontract::{contract::AllEventsBuilder, transport::DynTransport, H160, H256};
3-
use hex_literal::hex;
4-
use shared::{ethrpc::Web3, event_handling::EventRetrieving};
1+
//! A component that listens exclusively for `OrderRefund` events of the ethflow
2+
//! contract.
3+
use {
4+
ethcontract::{contract::AllEventsBuilder, transport::DynTransport, H160, H256},
5+
hex_literal::hex,
6+
shared::{ethrpc::Web3, event_handling::EventRetrieving},
7+
};
58

69
const ORDER_REFUND_TOPIC: H256 = H256(hex!(
710
"195271068a288191e4b265c641a56b9832919f69e9e7d6c2f31ba40278aeb85a"
@@ -23,8 +26,9 @@ impl EventRetrieving for EthFlowRefundRetriever {
2326

2427
fn get_events(&self) -> AllEventsBuilder<DynTransport, Self::Event> {
2528
let mut events = AllEventsBuilder::new(self.web3.clone(), self.address, None);
26-
// Filter out events that we don't want to listen for in the contract. `Self` is designed to
27-
// only pick up refunding events. Adding a filter also makes the query more efficient.
29+
// Filter out events that we don't want to listen for in the contract. `Self` is
30+
// designed to only pick up refunding events. Adding a filter also makes
31+
// the query more efficient.
2832
events.filter = events.filter.topic0(vec![ORDER_REFUND_TOPIC].into());
2933
events
3034
}

0 commit comments

Comments
 (0)