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

feat(agents): improve agent config #171

Merged
merged 20 commits into from
May 20, 2022
Merged

feat(agents): improve agent config #171

merged 20 commits into from
May 20, 2022

Conversation

lattejed
Copy link
Member

@lattejed lattejed commented May 17, 2022

Motivation

Agent config should be improved to speed up deployments. Currently most config changes have to go through a PR->deploy cycle. Configs should be updatable after deployment

  1. Agent config should be simplified with sensible defaults
  2. All necessary settings should be overridable with env vars

Ref #169

[Edit]

Going to cap this PR here since the changes already made allow deploys to be simplified / sped up. Further improvements to agent config can be done later.

Solution

A number of related items need to be done:

  • Add default tx signer config handling
  • Add tests for default tx signer config
  • Add default rpc style config handling
  • Add tests for default rpc style config

PR Checklist

  • Added Tests
  • Updated Documentation
  • Updated CHANGELOG.md for the appropriate package

@lattejed lattejed added enhancement New feature or request configuration labels May 17, 2022
@lattejed lattejed self-assigned this May 17, 2022
Comment on lines +40 to +46
let chain_conf =
ChainConf::from_env(&format!("RPCS_{}", network_upper), Some("RPCS_DEFAULT"))?;

let transaction_signer = SignerConf::from_env(
&format!("TRANSACTIONSIGNERS_{}", network_upper),
Some("TRANSACTIONSIGNERS_DEFAULT"),
)?;
Copy link
Collaborator

@luketchang luketchang May 18, 2022

Choose a reason for hiding this comment

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

Since we currently use the default option no matter what, maybe we can have SignerConf::from_env and ChainConf::from_env look for DEFAULT in env vars rather than passing in arg? As in always look first for DEFAULT, if not there then assume network-specific var

Copy link
Member Author

Choose a reason for hiding this comment

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

I think they should be kept prefix-agnostic. You can call SignerConf::from_env a second time with the default prefix but ChainConf::from_env needs to be able to handle two prefixes (*_CONNECTION_URL has no default). Passing prefix and default prefix separately gives FromEnv implementers the required flexibility.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe you're right about this. Smells to me for some reason but also simplifies.

Copy link
Collaborator

@luketchang luketchang May 18, 2022

Choose a reason for hiding this comment

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

The other option is to separate prefix and network and have network be an optional param. You can first check DEFAULT_{prefix} then check {network}_{prefix} or {prefix}_{network} this way. Think this may be more intuitive than using a hardcoded static default string as param

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I'm going to stick with the original. I think it's ok for an impl to have hardcoded keys (makes little sense to pass everything in) but the interface should indicate that a default is going to be checked. Passing in only network/prefix and then having it pull a default value is too much magic imo. The alternative would be a check_default param or sth similar but I think an Option<&str> is fine.

Copy link
Contributor

@arnaud036 arnaud036 May 19, 2022

Choose a reason for hiding this comment

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

Expected precedence from lowest to highest:

  • TRANSACTIONSIGNERS_DEFAULT
  • TRANSACTIONSIGNERS_RINKEBY


#[test]
#[serial_test::serial]
fn it_builds_from_env_default() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we add a default test case to kathy/src/settings.rs? We've been using kathy settings as place for testing full e2e configuration of agent from env to agent settings block. We'd just need to essentially copy this test except piping in test-signer-default test fixture.

Copy link
Collaborator

Choose a reason for hiding this comment

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

And on that note we need to DRY up agent settings tests... another chore lol

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good. Might have some q's

@lattejed
Copy link
Member Author

FYI, I've set resolver = "2" for the entire workspace since v1 was having trouble with a test-only, non-wasm dependency.

Should not have a negative impact anywhere wrt correctness / security.

Ref https://doc.rust-lang.org/cargo/reference/features.html#feature-resolver-version-2

@lattejed lattejed marked this pull request as ready for review May 19, 2022 10:51
@arnaud036
Copy link
Contributor

Tested in dev with Goerli network and it works as expected.

@lattejed
Copy link
Member Author

Great, thanks @arnaud036

@lattejed lattejed force-pushed the lattejed/agent_config branch from f63297e to 75d5ef6 Compare May 20, 2022 17:28
@lattejed lattejed merged commit 9d125db into main May 20, 2022
@lattejed lattejed mentioned this pull request May 20, 2022
2 tasks
@luketchang luketchang mentioned this pull request May 23, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants