-
Notifications
You must be signed in to change notification settings - Fork 162
Add disable-balances config flag to driver
#4271
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,22 +25,31 @@ pub struct Metadata { | |
| } | ||
|
|
||
| #[derive(Clone)] | ||
| pub struct Fetcher(Arc<Inner>); | ||
| pub enum Fetcher { | ||
| /// Fetches token metadata and settlement contract balances from the node. | ||
| Rpc(Arc<Inner>), | ||
| /// Returns zero balances without making any RPC calls. | ||
| Disabled, | ||
| } | ||
|
|
||
| impl Fetcher { | ||
| pub fn new(eth: &Ethereum) -> Self { | ||
| let eth = eth.with_metric_label("tokenInfos".into()); | ||
| let block_stream = eth.current_block().clone(); | ||
| let inner = Arc::new(Inner { | ||
| eth, | ||
| cache: RwLock::new(HashMap::new()), | ||
| requests: BoxRequestSharing::labelled("token_info".into()), | ||
| }); | ||
| let block_stream = inner.eth.current_block().clone(); | ||
| tokio::task::spawn( | ||
| update_task(block_stream, Arc::downgrade(&inner)) | ||
| .instrument(tracing::info_span!("token_fetcher")), | ||
| ); | ||
| Self(inner) | ||
| Self::Rpc(inner) | ||
| } | ||
|
|
||
| pub fn disabled() -> Self { | ||
| Self::Disabled | ||
| } | ||
|
|
||
| /// Returns the `Metadata` for the given tokens. Note that the result will | ||
|
|
@@ -50,7 +59,23 @@ impl Fetcher { | |
| &self, | ||
| addresses: &[eth::TokenAddress], | ||
| ) -> HashMap<eth::TokenAddress, Metadata> { | ||
| self.0.get(addresses).await | ||
| match self { | ||
| Self::Rpc(inner) => inner.get(addresses).await, | ||
| Self::Disabled => addresses | ||
| .iter() | ||
| .filter(|address| address.0.0 != BUY_ETH_ADDRESS) | ||
| .map(|address| { | ||
| ( | ||
| *address, | ||
| Metadata { | ||
| decimals: None, | ||
| symbol: None, | ||
| balance: 0.into(), | ||
| }, | ||
| ) | ||
| }) | ||
| .collect(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -120,7 +145,7 @@ async fn update_balances(inner: Arc<Inner>) -> Result<(), blockchain::Error> { | |
| } | ||
|
|
||
| /// Provides metadata of tokens. | ||
| struct Inner { | ||
| pub struct Inner { | ||
|
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.
I like the enum approach as it has some advantages in terms of speed, but it brings more complexities in maintenance; since we're not chasing sub-ms speeds yet, this is unnecessary. One reason it doesn't scale well in terms of maintenance is the burden of handling different branches, for example, in I think the best way to go about this right now is:
|
||
| eth: Ethereum, | ||
| cache: RwLock<HashMap<eth::TokenAddress, Metadata>>, | ||
| requests: BoxRequestSharing<eth::TokenAddress, Option<(eth::TokenAddress, Metadata)>>, | ||
|
|
||
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.
This is applied wholesale to the driver, as the driver is intended to handle different solvers this is a setting that should be handled on a per-solver level.