Skip to content
Open
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
1 change: 1 addition & 0 deletions crates/configs/src/orderbook/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ mod tests {
max_limit_orders_per_user: 5,
max_gas_per_order: 6_000_000,
same_tokens_policy: SameTokensPolicy::AllowSell,
min_fast_path_exclusivity: Some(Duration::from_secs(30)),
},
ipfs: Some(IpfsConfig {
gateway: "https://gateway.pinata.cloud/ipfs/".parse().unwrap(),
Expand Down
9 changes: 9 additions & 0 deletions crates/configs/src/orderbook/order_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ pub struct OrderValidationConfig {
/// Policy for orders where the buy and sell tokens are equal.
#[serde(default)]
pub same_tokens_policy: SameTokensPolicy,

/// How long a fast-path order is held out of the batch auction for its
/// exclusive settlement (`valid_from = now + this`, unless the user set a
/// later one). Unset disables the fast path: orders requesting it are
/// rejected.
#[serde(with = "humantime_serde", default)]
pub min_fast_path_exclusivity: Option<Duration>,

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.

Why the "minimum"? Can it be held out for longer? I assume it's because the solver can also settle it in the first block after the deadline. While technically correct, I wouldn't carry this detail in the name and just call it fast_path_default_exclusivity.

}

impl Default for OrderValidationConfig {
Expand All @@ -86,6 +93,7 @@ impl Default for OrderValidationConfig {
max_limit_orders_per_user: default_max_limit_orders_per_user(),
max_gas_per_order: default_max_gas_per_order(),
same_tokens_policy: Default::default(),
min_fast_path_exclusivity: None,
}
}
}
Expand Down Expand Up @@ -136,6 +144,7 @@ mod tests {
max_limit_orders_per_user: 5,
max_gas_per_order: 5_000_000,
same_tokens_policy: SameTokensPolicy::AllowSell,
min_fast_path_exclusivity: Some(Duration::from_secs(30)),
};

let serialized = toml::to_string_pretty(&config).unwrap();
Expand Down
12 changes: 6 additions & 6 deletions crates/e2e/tests/e2e/quote_fastpath_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ async fn local_node_fast_path_flags_rejected() {
run_test(fast_path_flags_rejected).await;
}

/// Verifies the orderbook rejects the not-yet-supported `fast_path` quote flag
/// and `enableFastPath` app-data field.
/// Verifies the orderbook rejects the `fast_path` quote flag and
/// `enableFastPath` app-data field when the fast path is not enabled by config.
async fn fast_path_flags_rejected(web3: Web3) {
let mut onchain = OnchainComponents::deploy(web3).await;
let [trader] = onchain.make_accounts(1u64.eth()).await;
Expand Down Expand Up @@ -71,8 +71,8 @@ async fn fast_path_flags_rejected(web3: Web3) {
.unwrap_err();
assert_eq!(err.0, StatusCode::BAD_REQUEST);
assert!(
err.1.contains("enableFastPath"),
"error body should mention enableFastPath, got: {}",
err.1.contains("FastPathDisabled"),
"error body should mention FastPathDisabled, got: {}",
err.1
);

Expand Down Expand Up @@ -107,8 +107,8 @@ async fn fast_path_flags_rejected(web3: Web3) {
.unwrap_err();
assert_eq!(err.0, StatusCode::BAD_REQUEST);
assert!(
err.1.contains("enableFastPath"),
"error body should mention enableFastPath, got: {}",
err.1.contains("FastPathDisabled"),
"error body should mention FastPathDisabled, got: {}",
err.1
);
}
16 changes: 16 additions & 0 deletions crates/orderbook/src/api/post_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ impl IntoResponse for AppDataValidationErrorWrapper {
),
)
.into_response(),
AppDataValidationError::FastPathDisabled => (
StatusCode::BAD_REQUEST,
error(
"FastPathDisabled",
"the fast path is not enabled on this environment.",
),
)
.into_response(),
}
}
}
Expand Down Expand Up @@ -259,6 +267,14 @@ impl IntoResponse for ValidationErrorWrapper {
),
)
.into_response(),
ValidationError::FastPathDisabled => (
StatusCode::BAD_REQUEST,
error(
"FastPathDisabled",
"the fast path is not enabled on this environment.",
),
)
.into_response(),
ValidationError::IncompatibleSigningScheme => (
StatusCode::BAD_REQUEST,
error(
Expand Down
6 changes: 0 additions & 6 deletions crates/orderbook/src/quoter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,6 @@ impl QuoteHandler {
let valid_to = order.valid_to;
self.order_validator.partial_validate(order).await?;

if app_data.inner.protocol.enable_fast_path {
return Err(OrderQuoteError::AppData(AppDataValidationError::Invalid(
anyhow::anyhow!("'enableFastPath' is not yet supported"),
)));
}

// Emit only after validation succeeds so we don't announce requests
// that never reach the estimator (invalid app-data / order data return
// early above). This is best-effort correlation, not a guarantee: if
Expand Down
59 changes: 31 additions & 28 deletions crates/orderbook/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,34 +400,37 @@ pub async fn run(config: Configuration) {
}
});

let order_validator = Arc::new(OrderValidator::new(
native_token.clone(),
Arc::new(order_validation::banned::Users::new(
chainalysis_oracle,
config.banned_users.hermod.clone().map(|hermod| {
order_validation::banned::HermodConfig {
url: hermod.url,
hmac_key: hermod.hmac_key,
api_key: hermod.api_key,
}
}),
config.banned_users.addresses,
config.banned_users.max_cache_size.get().to_u64().unwrap(),
)),
validity_configuration,
config.eip1271_skip_creation_validation,
deny_listed_tokens.clone(),
hooks_contract,
optimal_quoter.clone(),
balance_fetcher,
signature_validator,
validator_simulator,
Arc::new(postgres_write.clone()),
config.order_validation.max_limit_orders_per_user,
app_data_validator.clone(),
config.order_validation.max_gas_per_order,
config.order_validation.same_tokens_policy,
));
let order_validator = Arc::new(
OrderValidator::new(
native_token.clone(),
Arc::new(order_validation::banned::Users::new(
chainalysis_oracle,
config.banned_users.hermod.clone().map(|hermod| {
order_validation::banned::HermodConfig {
url: hermod.url,
hmac_key: hermod.hmac_key,
api_key: hermod.api_key,
}
}),
config.banned_users.addresses,
config.banned_users.max_cache_size.get().to_u64().unwrap(),
)),
validity_configuration,
config.eip1271_skip_creation_validation,
deny_listed_tokens.clone(),
hooks_contract,
optimal_quoter.clone(),
balance_fetcher,
signature_validator,
validator_simulator,
Arc::new(postgres_write.clone()),
config.order_validation.max_limit_orders_per_user,
app_data_validator.clone(),
config.order_validation.max_gas_per_order,
config.order_validation.same_tokens_policy,
)
.with_min_fast_path_exclusivity(config.order_validation.min_fast_path_exclusivity),

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.

Any reason we are using the builder pattern here now, if all other parameters are constructor args? Feels inconsistent.

);
let ipfs = config
.ipfs
.map(|ipfs| {
Expand Down
Loading
Loading