-
Notifications
You must be signed in to change notification settings - Fork 186
(fast6) prepare order-notification pipeline in runloop #4861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,15 @@ | ||
| use { | ||
| crate::{domain::OrderUid, infra::order_notify::Listener}, | ||
| std::sync::Arc, | ||
| futures::channel::mpsc, | ||
| }; | ||
|
|
||
| /// "Wakes" up (i.e. notifies) the run-loop to start when a new block or order | ||
| /// appears. | ||
| pub struct RunLoopWaker(pub Arc<tokio::sync::Notify>); | ||
| pub struct RunLoopWaker(pub mpsc::UnboundedSender<OrderUid>); | ||
|
|
||
| #[async_trait::async_trait] | ||
| impl Listener for RunLoopWaker { | ||
| async fn on_new_order(&self, _: OrderUid) { | ||
| self.0.notify_one(); | ||
| async fn on_new_order(&self, order: OrderUid) { | ||
| self.0.unbounded_send(order).unwrap() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ use { | |
| contracts::{GPv2Settlement, WETH9}, | ||
| ethrpc::{Web3, block_stream::block_number_to_block_number_hash}, | ||
| event_indexing::block_retriever::BlockRetriever, | ||
| futures::channel::mpsc, | ||
| http_client::HttpClientFactory, | ||
| model::DomainSeparator, | ||
| num::ToPrimitive, | ||
|
|
@@ -471,9 +472,10 @@ pub async fn run(config: Configuration, shutdown_controller: ShutdownController) | |
| config.banned_users.max_cache_size.get().to_u64().unwrap(), | ||
| )); | ||
|
|
||
| // Wakes the run loop on new orders (via the notifier) and new blocks. | ||
| let wake_runloop = Arc::new(tokio::sync::Notify::new()); | ||
| infra::order_notify::Notifier::new(banned_users.clone(), wake_runloop.clone()) | ||
| // New-order notifications from the DB fan out through this channel to | ||
| // the run loop (which wakes) and, later on, to the fast-path handler. | ||
| let (new_orders_sender, new_orders_receiver) = mpsc::unbounded(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This unbounded makes me nervous, why not running bounded and applying backpressure? |
||
| infra::order_notify::Notifier::new(banned_users.clone(), new_orders_sender) | ||
| .spawn(db_write.pool.clone()); | ||
|
|
||
| let penalty_cap_calculator = match &config.penalty_cap { | ||
|
|
@@ -659,7 +661,7 @@ pub async fn run(config: Configuration, shutdown_controller: ShutdownController) | |
| startup, | ||
| }, | ||
| awaiter, | ||
| wake_runloop, | ||
| new_orders_receiver, | ||
| ); | ||
| run.run_forever(shutdown_controller).await; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
.unwrap()onunbounded_sendis a landmine that contradicts the best-effort contract documented on theListenertrait ("Notifications are best effort ... whatever a listener does must be recoverable at auction cut time").unbounded_sendonly errors when the receiver has been dropped. If the run-loop'sspawn_order_listenertask ever ends (e.g. it panics), the receiver drops and the next order notification panics here. That panic propagates out ofdispatch'sjoin_alland kills the entireNotifiertask — which has no panic recovery, so all order notifications stop permanently, including the unrelatedCachePrewarmerfor banned users.The old
notify_one()could never fail. Consider handling the send error gracefully instead:(the closing
}in the suggestion replaces line 14's}— adjust if you keep the original brace layout)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand why the current unwrap is there, maybe halfway would be an expect with the explanatio