Skip to content
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

Optional Chain ID in Baseline Solver Configuration #1207

Merged
merged 2 commits into from
Feb 14, 2023
Merged

Conversation

nlordell
Copy link
Contributor

@vkgnosis pointed out in #1202 that the chain ID parameter being mandatory is not practical for local deployments or when testing out on new chains.

In fact, the baseline solver only needs to know the WETH address, so this PR changes the configuration semantics to require either:

  • specifying a chain-id to use the canonical WETH contract for that chain.
  • specify a custom weth address to use that instead, at which point the ChainId is no longer needed

Test Plan

Adjusted test loading the example TOML configuration.

@nlordell nlordell requested a review from a team as a code owner February 14, 2023 09:25
@nlordell nlordell changed the title Optional Chain ID Optional Chain ID in Baseline Solver Configuration Feb 14, 2023
Comment on lines 13 to 14
#[serde(flatten)]
pub contracts: ContractsConfig,
Copy link
Contributor

@vkgnosis vkgnosis Feb 14, 2023

Choose a reason for hiding this comment

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

Now we're mixing deny_unknown_fields and flatten which you mentioned before doesn't work. deny_unknown_fields has already been pretty helpful for me, but this is a small config file so doesn't really matter. More generally, I think not using flatten is nice because it makes the structure of the config file more obvious from the code. I like keeping a one-to-one correspondence of rust field to config field. With complicated serde instructions it tends to get harder to figure out how the serialized file is going to look. Again, this file is small so not super important, so up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now we're mixing deny_unknown_fields and flatten which you mentioned before doesn't work

It doesn't work well. deny_unknown_fields and flatten together have a whole bunch of prickly issues:

  • If you flatten a struct that also has deny_unknown_fields, then this won't work (the inner struct will see a whole bunch of fields from the parent and deny them).
  • If you deny_unknown_fields on untagged enums, then this also doesn't work

However, in this particular case of deny_unknown_fields, flatten and rename on an enum with only single values, it does. I tested it out locally, but you can also see an example of this in the playground.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, I changed it to use a manual match (chain_id, weth). The reasoning is:

  • As you mentioned complicated serde instructions make things harder to figure out, also the whole complex interaction between deny_unknown_fields, flatten and rename_all is not obvious (for example, if you don't use the rename_all, then serialization will not work as expected)
  • You get nicer panic error messages

@@ -1,4 +1,5 @@
chain-id = "1"
weth = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
# Alternatively, you can manually specify a WETH contract address:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Could you make the comment refer to the chain-id parameter? This makes the dependency more explicit and less error prone if somebody where to insert a new argument between chain-id and weth.

@nlordell nlordell enabled auto-merge (squash) February 14, 2023 10:22
@nlordell nlordell merged commit 38ac5f0 into main Feb 14, 2023
@nlordell nlordell deleted the optional-chain-id branch February 14, 2023 10:26
@github-actions github-actions bot locked and limited conversation to collaborators Feb 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants