-
Notifications
You must be signed in to change notification settings - Fork 93
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
Make subgraph URL's configurable #2126
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
92de641
to
69a2dae
Compare
69a2dae
to
e759151
Compare
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 parameter should become part of the shared arguments we use to configure all our services. Cf. #1911 for a PR that achieves something very similar.
crates/shared/src/subgraph.rs
Outdated
let graph_api_base = | ||
std::env::var("GRAPH_API_BASE_URL").unwrap_or(DEFAULT_GRAPH_API_BASE_URL.clone()); |
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.
Reading global state such as env variables in core domain components is bad practice (it makes it hard to see holistically which arguments are required for the system as a whole).
Instead we use DI to pass in those configuration values from above and configure them in one place (shared::arguments
)
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.
done. PTAL
e86e8c5
to
10a6266
Compare
eth: &Ethereum, | ||
block_stream: CurrentBlockStream, | ||
block_retriever: Arc<dyn BlockRetrieving>, | ||
config: &infra::liquidity::config::BalancerV2, | ||
) -> Box<dyn LiquidityCollecting> { | ||
let eth = Arc::new(eth.clone()); | ||
let graph_api_base_url = Arc::new(graph_api_base_url.clone()); |
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.
What is the point of using an Arc here, if init_liquidity
doesn't take a shared ref?
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.
otherwise it complains that "borrowed data escapes outside of function".
EDIT : this comment is outdated now
@@ -75,19 +76,22 @@ fn to_interaction( | |||
} | |||
|
|||
pub fn collector( | |||
graph_api_base_url: &Url, |
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 field should probably, like other things that configure the different liquidity sources, be part of the config
struct (otherwise this method will soon have 100 arguments)
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.
done. PTAL
10a6266
to
bfb8186
Compare
crates/driver/src/infra/cli.rs
Outdated
/// The base URL to connect to subgraph clients. | ||
#[clap(long, env, default_value = "https://api.thegraph.com/subgraphs/name/")] | ||
pub graph_api_base_url: Url, |
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.
We should probably not continue requiring the same base url for every use case of the graph and instead pass around the complete url in the univ3 and balancer v2 liquidity section of the config.
Otherwise we are forced to completely move towards self hosting the subgraph on the same base url.
ff7876c
to
01c2996
Compare
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'm not sure @MartinquaXD suggestion of passing in the entire subgraph url (not just the base url) is practical as it would probably require some more involved "default logic" that has to be re-written in the infra repository as well (unless we make it mandatory in which case setting this up for developers to use locally may be a PITA).
If we leave this task to just supply the base URL, I think the right config this value should go on is infra::config::file::LiquidityConfig
so it's only set once.
Can you please also test how a driver config with a custom subgraph URL works locally?
graph_api_base_url: Url::parse(&DEFAULT_GRAPH_API_BASE_URL) | ||
.expect("invalid default Graph API base URL"), |
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.
Shouldn't the url be configurable here as well?
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.
done
|
||
graph_api_base_url: Url, |
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.
Preset pools (which are used in prod) should also be able to configure this value
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 have actually moved the url to the LiquidityConfig so I think that this comment is outdated now.
01c2996
to
605b8a7
Compare
|
||
graph_api_base_url: Url, |
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.
Can we move the four occurrences here (crates/driver/src/infra/config/file/mod.rs) to a single field on the top level LiquidityConfig
object? Since we are not going to configure different base URLs for different liquidity types, this seems the least configuration overhead.
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.
agree that it causes some configuration overhead, so I moved it to LiquidityConfig as suggested
bf0aeb9
to
1b96d7b
Compare
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.
Looking good. I think we should still only define the string "https://api.thegraph.com/subgraphs/name/" once as a constant somewhere in the codebase (and I'd prefer using a type that implements Default over re-implementing it), but otherwise this looks good to me.
@@ -293,6 +293,24 @@ struct LiquidityConfig { | |||
/// Liquidity provided by a Balancer V2 compatible contract. | |||
#[serde(default)] | |||
balancer_v2: Vec<BalancerV2Config>, | |||
|
|||
/// The base URL used to connect to subgraph clients. | |||
graph_api_base_url: Url, |
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.
nit: maybe slightly nice to use Option<Url>
, which implements Default
and then unwrap_or
with out constant when we convert it to the liquidity specific config object.
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.
done
|
||
impl Default for LiquidityConfig { | ||
fn default() -> Self { | ||
let default_url = Url::parse("https://api.thegraph.com/subgraphs/name/") |
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.
let's keep this a constant somewhere
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.
done
1bb18f9
to
646dae3
Compare
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.
Looks okay to me.
Did you run it locally as a sanity check? I think we might not have e2e tests verifying that we can query the graph liquidity.
} | ||
|
||
// impl Default for LiquidityConfig { |
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.
Left over comments.
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.
oh yeah. removed
612ca44
to
58dba87
Compare
I don't know how to run in locally. Are you referring to "Running the Services Locally" section from the README ? |
90ed087
to
5f27fbd
Compare
fb1d437
to
6834e8b
Compare
Description
This PR aims to fix 2105
Changes
The subgraph base url is read from the environment variables.
How to test
All unit tests still pass