Skip to content

Check banned users on order arrival - #4696

Open
jmg-duarte wants to merge 5 commits into
mainfrom
jmgd/pre-warm-banned
Open

Check banned users on order arrival#4696
jmg-duarte wants to merge 5 commits into
mainfrom
jmgd/pre-warm-banned

Conversation

@jmg-duarte

@jmg-duarte jmg-duarte commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Description

We're doing all the user ban checks when performing auction cutting, however, we can check them eagerly when the autopilot gets notified of new orders; this works because we can extract the owner from the order UID. As such we can check on order arrival leading to the cache being pre-warmed when the auction cutting happens.

Changes

  • New pre-fetch task for banned users, as orders arrive through NOTIFY we send the owner over the pipe
    • Sends are batched to avoid spawning a slew of tasks
  • Order listener now gets access to the pipe to send new orders

How to test

Tested in staging to ensure nothing broke and in prod:

Screenshot 2026-08-03 at 11 26 55

The overall latency was reduced as one can see based on less bucket variance, there are still some spikes as receivers are still searched later on, since the order UID doesn't carry info on them.

Heatmap panel:

sum by (le) (increase(gp_v2_autopilot_auction_update_stage_time_bucket{
  network="mainnet", stage="banned_user_filtering"}[$__rate_interval]))

@jmg-duarte
jmg-duarte marked this pull request as ready for review August 3, 2026 10:34
@jmg-duarte
jmg-duarte requested a review from a team as a code owner August 3, 2026 10:35
@MartinquaXD

Copy link
Copy Markdown
Contributor

Did this also have a measurable latency reduction when building auctions? Fetching banned users happens concurrently with other things so I might have 0 net impact if the other things we do concurrently always take longer than the ban check.

Comment thread crates/autopilot/src/run_loop.rs Outdated
Comment thread crates/autopilot/src/infra/persistence/mod.rs Outdated
Comment thread crates/autopilot/src/infra/persistence/mod.rs Outdated
Comment thread crates/autopilot/src/infra/persistence/mod.rs Outdated
@jmg-duarte

Copy link
Copy Markdown
Contributor Author

Did this also have a measurable latency reduction when building auctions?

This is part of the "update solvable orders" phase, sadly, it didn't have a measurable impact

@MartinquaXD

Copy link
Copy Markdown
Contributor

This is part of the "update solvable orders" phase, sadly, it didn't have a measurable impact

Keep in mind that real world improvements should be the measurement of success - especially for PRs introducing non-trivial changes. In this case I believe there is an argument to be made to add this component now because we already have a few additions to that in mind but without those additions I don't think this PR should be merged.

@jmg-duarte
jmg-duarte force-pushed the jmgd/pre-warm-banned branch from 0741b43 to 8619593 Compare August 3, 2026 14:40
Comment thread crates/autopilot/src/infra/banned.rs Outdated
Comment thread crates/autopilot/src/infra/banned.rs Outdated
tokio::spawn(async move {
while let Some(arrival) = arrivals.next().await {
let owner = match arrival {
Ok(order) => order.owner(),

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.

This currently only looks at the order's owner but not the receiver. For the other 2 use cases (balance cache warming, order fast path) we both need to look up the order. So probably best to already fetch the order from the DB in the new order_notify.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Pushing back against this while we don't actually have the other components in here.
I checked mainnet and in the last hour (at the time of writing), 1.4k orders went in with the owner being the same as the receiver, while only 68 went in with the receiver being different.
I also checked base, 401 owner=receiver, 17 owner!=receiver

Comment thread crates/autopilot/src/run_loop.rs Outdated
@jmg-duarte
jmg-duarte requested a review from MartinquaXD August 5, 2026 10:42

@MartinquaXD MartinquaXD left a comment

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.

neat. 👍

Comment on lines +6 to +7
/// Wakes the run loop so the arriving order makes it into the next auction as
/// soon as possible.

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 comment is not correct. This waker is supposed to help the runloop to only start when a new block or order appears.

boundary::{self, SolvableOrders},
domain::{self, auction::Price},
infra::{self, banned},
infra::{self},

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.

unnecessary change growing the diff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants