Skip to content

Commit

Permalink
Update rust to 2024 edition (#3294)
Browse files Browse the repository at this point in the history
# Description
Rust 1.85 brought the 2024 edition and with it a few goodies (mostly
async closures, and removed footguns around lifetimes in match
statements)

# Changes
- ~~`cargo update`~~ (this was recommended by the upgrade guide but
caused e2e tests to become unreliable - let's address this separately)
- `cargo fix --edition`
- 1 fix that wasn't automatically done
- changed all editions to 2024
- `cargo +nightly fmt`

Ended up mostly being formatting changes, though.

## How to test
existing e2e should continue to work
  • Loading branch information
MartinquaXD authored Feb 26, 2025
1 parent 0785e2f commit 97ddf0c
Show file tree
Hide file tree
Showing 292 changed files with 1,153 additions and 1,029 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
resolver = "2"
resolver = "3"
members = ["crates/*"]

[workspace.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/alerter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "alerter"
version = "0.1.0"
authors = ["Gnosis Developers <developers@gnosis.io>", "Cow Protocol Developers <dev@cow.fi>"]
edition = "2021"
edition = "2024"
license = "MIT OR Apache-2.0"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/alerter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use {
anyhow::{Context, Result},
clap::Parser,
model::order::{OrderClass, OrderKind, OrderStatus, OrderUid, BUY_ETH_ADDRESS},
model::order::{BUY_ETH_ADDRESS, OrderClass, OrderKind, OrderStatus, OrderUid},
number::serialization::HexOrDecimalU256,
primitive_types::{H160, U256},
prometheus::IntGauge,
Expand Down
2 changes: 1 addition & 1 deletion crates/app-data/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "app-data"
version = "0.1.0"
authors = ["Cow Protocol Developers <dev@cow.fi>"]
edition = "2021"
edition = "2024"
license = "MIT OR Apache-2.0"

[dependencies]
Expand Down
8 changes: 4 additions & 4 deletions crates/app-data/src/app_data.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use {
crate::{app_data_hash::hash_full_app_data, AppDataHash, Hooks},
anyhow::{anyhow, Context, Result},
crate::{AppDataHash, Hooks, app_data_hash::hash_full_app_data},
anyhow::{Context, Result, anyhow},
primitive_types::{H160, U256},
serde::{de, Deserialize, Deserializer, Serialize, Serializer},
serde::{Deserialize, Deserializer, Serialize, Serializer, de},
std::{fmt, fmt::Display},
};

Expand Down Expand Up @@ -260,7 +260,7 @@ mod tests {
use {super::*, crate::Hook, ethcontract::H160};

macro_rules! assert_app_data {
($s:expr, $e:expr $(,)?) => {{
($s:expr_2021, $e:expr_2021 $(,)?) => {{
let s = $s;
let a = Validator::default().validate(s.as_ref()).unwrap();
assert_eq!(a.protocol, $e);
Expand Down
2 changes: 1 addition & 1 deletion crates/app-data/src/app_data_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//! [0]: https://github.com/cowprotocol/services/issues/1465
use {
serde::{de, Deserializer, Serializer},
serde::{Deserializer, Serializer, de},
serde_with::serde::{Deserialize, Serialize},
std::{
borrow::Cow,
Expand Down
2 changes: 1 addition & 1 deletion crates/app-data/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use {
bytes_hex::BytesHex,
primitive_types::H160,
serde::{Deserialize, Serialize},
serde_with::{serde_as, DisplayFromStr},
serde_with::{DisplayFromStr, serde_as},
std::{
fmt,
fmt::{Debug, Formatter},
Expand Down
2 changes: 1 addition & 1 deletion crates/autopilot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "autopilot"
version = "0.1.0"
authors = ["Cow Protocol Developers <dev@cow.fi>"]
edition = "2021"
edition = "2024"
license = "GPL-3.0-or-later"

[lib]
Expand Down
21 changes: 11 additions & 10 deletions crates/autopilot/src/arguments.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
crate::{domain::fee::FeeFactor, infra},
anyhow::{anyhow, ensure, Context},
anyhow::{Context, anyhow, ensure},
clap::ValueEnum,
primitive_types::{H160, U256},
shared::{
Expand Down Expand Up @@ -426,10 +426,9 @@ impl FromStr for Solver {
ensure!(parts.len() >= 3, "not enough arguments for external solver");
let (name, url) = (parts[0], parts[1]);
let url: Url = url.parse()?;
let submission_account = if let Ok(value) = Arn::from_str(parts[2]) {
Account::Kms(value)
} else {
Account::Address(H160::from_str(parts[2]).context("failed to parse submission")?)
let submission_account = match Arn::from_str(parts[2]) {
Ok(value) => Account::Kms(value),
_ => Account::Address(H160::from_str(parts[2]).context("failed to parse submission")?),
};

let fairness_threshold = match parts.get(3) {
Expand Down Expand Up @@ -624,11 +623,13 @@ mod test {
];

for policy in policies {
assert!(FeePolicy::from_str(policy)
.err()
.unwrap()
.to_string()
.contains("Factor must be in the range [0, 1)"),)
assert!(
FeePolicy::from_str(policy)
.err()
.unwrap()
.to_string()
.contains("Factor must be in the range [0, 1)"),
)
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/autopilot/src/boundary/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
pub use {
crate::database::{
competition::Competition,
order_events::{store_order_events, OrderEventLabel},
order_events::{OrderEventLabel, store_order_events},
},
database,
model::{
DomainSeparator,
interaction::InteractionData,
order::{
BuyTokenDestination,
Expand All @@ -18,9 +19,8 @@ pub use {
},
signature::{EcdsaSignature, Signature, SigningScheme},
solver_competition::SolverCompetitionDB,
DomainSeparator,
},
shared::order_validation::{is_order_outside_market_price, Amounts},
shared::order_validation::{Amounts, is_order_outside_market_price},
};
use {crate::domain, ethrpc::Web3, std::collections::HashMap, url::Url};

Expand Down
2 changes: 1 addition & 1 deletion crates/autopilot/src/database/competition.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use {
anyhow::Context,
database::{
Address,
auction::AuctionId,
auction_participants::Participant,
auction_prices::AuctionPrice,
byte_array::ByteArray,
settlement_scores::Score,
surplus_capturing_jit_order_owners,
Address,
},
derive_more::Debug,
model::solver_competition::SolverCompetitionDB,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! A component that listens exclusively for `OrderRefund` events of the ethflow
//! contract.
use {
ethcontract::{contract::AllEventsBuilder, transport::DynTransport, H160, H256},
ethcontract::{H160, H256, contract::AllEventsBuilder, transport::DynTransport},
hex_literal::hex,
shared::{ethrpc::Web3, event_handling::EventRetrieving},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Implements the logic for indexing `OrderRefund` events of the ethflow
//! contract.
use {
crate::database::{events::bytes_to_order_uid, Postgres},
crate::database::{Postgres, events::bytes_to_order_uid},
anyhow::Result,
database::ethflow_orders::Refund,
ethrpc::block_stream::RangeInclusive,
Expand Down
8 changes: 4 additions & 4 deletions crates/autopilot/src/database/events.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use {
anyhow::{anyhow, Context, Result},
anyhow::{Context, Result, anyhow},
contracts::gpv2_settlement::{
Event as ContractEvent,
event_data::{
OrderInvalidated as ContractInvalidation,
PreSignature as ContractPreSignature,
Settlement as ContractSettlement,
Trade as ContractTrade,
},
Event as ContractEvent,
},
database::{
byte_array::ByteArray,
events::{Event, EventIndex, Invalidation, PreSignature, Settlement, Trade},
OrderUid,
PgTransaction,
byte_array::ByteArray,
events::{Event, EventIndex, Invalidation, PreSignature, Settlement, Trade},
},
ethcontract::{Event as EthContractEvent, EventMetadata},
number::conversions::u256_to_big_decimal,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
use {
super::{OnchainOrderCustomData, OnchainOrderParsing},
crate::database::events::meta_to_event_index,
anyhow::{anyhow, Context, Result},
anyhow::{Context, Result, anyhow},
chrono::Duration,
contracts::{
GPv2Settlement,
cowswap_onchain_orders::{
event_data::OrderPlacement as ContractOrderPlacement,
Event as ContractEvent,
event_data::OrderPlacement as ContractOrderPlacement,
},
deployment_block,
GPv2Settlement,
},
database::{
PgTransaction,
byte_array::ByteArray,
ethflow_orders::EthOrderPlacement,
events::EventIndex,
onchain_broadcasted_orders::OnchainOrderPlacement,
orders::{ExecutionTime, Interaction, Order},
PgTransaction,
},
ethcontract::Event as EthContractEvent,
ethrpc::{
block_stream::{block_by_number, block_number_to_block_number_hash, BlockNumberHash},
Web3,
block_stream::{BlockNumberHash, block_by_number, block_number_to_block_number_hash},
},
hex_literal::hex,
model::time::now_in_epoch_seconds,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
contracts::cowswap_onchain_orders,
ethcontract::{contract::AllEventsBuilder, transport::DynTransport, H160, H256},
ethcontract::{H160, H256, contract::AllEventsBuilder, transport::DynTransport},
hex_literal::hex,
shared::{ethrpc::Web3, event_handling::EventRetrieving},
};
Expand Down
36 changes: 18 additions & 18 deletions crates/autopilot/src/database/onchain_order_events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,33 @@ pub mod event_retriever;

use {
super::{
events::{bytes_to_order_uid, meta_to_event_index},
Metrics as DatabaseMetrics,
Postgres,
events::{bytes_to_order_uid, meta_to_event_index},
},
anyhow::{anyhow, bail, Context, Result},
anyhow::{Context, Result, anyhow, bail},
app_data::AppDataHash,
chrono::{TimeZone, Utc},
contracts::cowswap_onchain_orders::{
event_data::{OrderInvalidation, OrderPlacement as ContractOrderPlacement},
Event as ContractEvent,
event_data::{OrderInvalidation, OrderPlacement as ContractOrderPlacement},
},
database::{
PgTransaction,
byte_array::ByteArray,
events::EventIndex,
onchain_broadcasted_orders::{OnchainOrderPlacement, OnchainOrderPlacementError},
orders::{insert_quotes, Order, OrderClass},
PgTransaction,
orders::{Order, OrderClass, insert_quotes},
},
ethcontract::{Event as EthContractEvent, H160},
ethrpc::{
block_stream::{timestamp_of_block_in_seconds, RangeInclusive},
Web3,
block_stream::{RangeInclusive, timestamp_of_block_in_seconds},
},
futures::{stream, StreamExt},
futures::{StreamExt, stream},
itertools::multiunzip,
model::{
DomainSeparator,
order::{
BuyTokenDestination,
OrderData,
Expand All @@ -38,7 +39,6 @@ use {
SellTokenSource,
},
signature::SigningScheme,
DomainSeparator,
},
number::conversions::u256_to_big_decimal,
shared::{
Expand All @@ -51,9 +51,9 @@ use {
event_handling::EventStoring,
order_quoting::{OrderQuoting, Quote, QuoteSearchParameters},
order_validation::{
ValidationError,
convert_signing_scheme_into_quote_signing_scheme,
get_quote_and_check_fee,
ValidationError,
},
},
std::{collections::HashMap, sync::Arc},
Expand Down Expand Up @@ -611,7 +611,7 @@ fn convert_onchain_order_placement(
fee_amount: u256_to_big_decimal(&order_data.fee_amount),
kind: order_kind_into(order_data.kind),
partially_fillable: order_data.partially_fillable,
signature: order_placement.signature.1 .0.clone(),
signature: order_placement.signature.1.0.clone(),
signing_scheme: signing_scheme_into(signing_scheme),
settlement_contract: ByteArray(settlement_contract.0),
sell_token_balance: sell_token_source_into(order_data.sell_token_balance),
Expand All @@ -637,7 +637,7 @@ fn extract_order_data_from_onchain_order_placement_event(
let (signing_scheme, owner) = match order_placement.signature.0 {
0 => (
SigningScheme::Eip1271,
H160::from_slice(&order_placement.signature.1 .0[..20]),
H160::from_slice(&order_placement.signature.1.0[..20]),
),
1 => (SigningScheme::PreSign, order_placement.sender),
// Signatures can only be 0 and 1 by definition in the smart contrac:
Expand All @@ -658,12 +658,12 @@ fn extract_order_data_from_onchain_order_placement_event(
sell_amount: order_placement.order.3,
buy_amount: order_placement.order.4,
valid_to: order_placement.order.5,
app_data: AppDataHash(order_placement.order.6 .0),
app_data: AppDataHash(order_placement.order.6.0),
fee_amount: order_placement.order.7,
kind: OrderKind::from_contract_bytes(order_placement.order.8 .0)?,
kind: OrderKind::from_contract_bytes(order_placement.order.8.0)?,
partially_fillable: order_placement.order.9,
sell_token_balance: SellTokenSource::from_contract_bytes(order_placement.order.10 .0)?,
buy_token_balance: BuyTokenDestination::from_contract_bytes(order_placement.order.11 .0)?,
sell_token_balance: SellTokenSource::from_contract_bytes(order_placement.order.10.0)?,
buy_token_balance: BuyTokenDestination::from_contract_bytes(order_placement.order.11.0)?,
};
let order_uid = order_data.uid(&domain_separator, &owner);
Ok((order_data, owner, signing_scheme, order_uid))
Expand Down Expand Up @@ -700,9 +700,9 @@ mod test {
database::{byte_array::ByteArray, onchain_broadcasted_orders::OnchainOrderPlacement},
ethcontract::{Bytes, EventMetadata, H160, U256},
model::{
DomainSeparator,
order::{BuyTokenDestination, OrderData, OrderKind, SellTokenSource},
signature::SigningScheme,
DomainSeparator,
},
number::conversions::u256_to_big_decimal,
shared::{
Expand Down Expand Up @@ -919,7 +919,7 @@ mod test {
kind: order_kind_into(expected_order_data.kind),
class: OrderClass::Market,
partially_fillable: expected_order_data.partially_fillable,
signature: order_placement.signature.1 .0,
signature: order_placement.signature.1.0,
signing_scheme: signing_scheme_into(SigningScheme::Eip1271),
settlement_contract: ByteArray(settlement_contract.0),
sell_token_balance: sell_token_source_into(expected_order_data.sell_token_balance),
Expand Down Expand Up @@ -1029,7 +1029,7 @@ mod test {
kind: order_kind_into(expected_order_data.kind),
class: OrderClass::Limit,
partially_fillable: expected_order_data.partially_fillable,
signature: order_placement.signature.1 .0,
signature: order_placement.signature.1.0,
signing_scheme: signing_scheme_into(SigningScheme::Eip1271),
settlement_contract: ByteArray(settlement_contract.0),
sell_token_balance: sell_token_source_into(expected_order_data.sell_token_balance),
Expand Down
4 changes: 2 additions & 2 deletions crates/autopilot/src/domain/auction/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use {
super::{eth, Order},
super::{Order, eth},
std::collections::HashMap,
};

Expand Down Expand Up @@ -76,7 +76,7 @@ impl Price {
/// assert_eq!(eth, eth::Ether::from(eth::U256::exp10(15)));
/// ```
pub fn in_eth(self, amount: eth::TokenAmount) -> eth::Ether {
(amount.0 * self.0 .0 / Self::BASE).into()
(amount.0 * self.0.0 / Self::BASE).into()
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/autopilot/src/domain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ pub mod settlement;

pub use {
auction::{
order::{Order, OrderUid},
Auction,
RawAuctionData,
order::{Order, OrderUid},
},
fee::ProtocolFees,
quote::Quote,
Expand Down
Loading

0 comments on commit 97ddf0c

Please sign in to comment.