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

per-container payment config #556

Merged
merged 17 commits into from
Nov 3, 2021
Merged

Conversation

johny-b
Copy link
Contributor

@johny-b johny-b commented Oct 27, 2021

Resolves #554

VISIBLE CHANGES:

  1. Every node in goth-config.yml has optional key "payments" with a payment config name. Allowed names are now "erc20", "zksync" and "polygon". If "payments" is not specified, default value "zksync" will be used.
  2. All nodes initialize only a single payment driver (up to now, both zksync and erc20 were initialized). This shouldn't be hard to change if we want it one day.

INTERNAL CHANGES:

  1. All payment-related configuration is in a single place, there are no defaults anywhere outside of goth/payment_config.py. This required some additional args here and there.
  2. I removed PaymentDriver enum - I think it's not really useful after the change in previous point. I'm not 100% sure about this, but if we want it back than why not also PaymentNetwork enum?
  3. There was some cleanup of env variables - now only those necessary should be set (at least regarding payments).

NOTE: The only thing I checked (outside of the goth repo) is that:

  • test_run_blender (in yapapi) works with this version
  • after adding payments: erc20 in goth-config.yml in yapapi tests we need --payment-driver erc20 --payment-network mainnet in test_run_blender
  • if only one provider has payments: erc20, blender uses only this provider

And as far as I understand, this is what we wanted.

Recommended reading start: goth/payment_config.py.
Also, commits are messy, there's no use in reading them one by one.

@johny-b johny-b requested a review from kmazurek October 28, 2021 15:50
@johny-b johny-b marked this pull request as ready for review October 28, 2021 15:50
@johny-b johny-b changed the title Johny b/multiple payment networks per-container payment config Oct 29, 2021
@@ -292,6 +298,10 @@ def load_yaml(
name = node["name"]
type_name = node["type"]
use_proxy = node.get("use-proxy", False)

payment_config_name = node.get("payments", DEFAULT_PAYMENT_CONFIG_NAME)
Copy link
Contributor

Choose a reason for hiding this comment

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

I find the name payments ambiguous in this context. How about payment_platform or payment_config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

def payment_fund(
self: CommandRunner, payment_driver: PaymentDriver = DEFAULT_PAYMENT_DRIVER
) -> None:
def payment_fund(self: CommandRunner, payment_driver: str) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps instead of taking a payment_driver string argument this should accept a PaymentConfig object? I think this would be slightly easier to use from the API's end user's perspective.

"""Run `<cmd> payment fund` with optional extra args."""
args = make_args("payment", "fund", driver=payment_driver.name)
args = make_args("payment", "fund", driver=payment_driver)
self.run_command(*args)

def payment_init(
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, maybe let's use a PaymentConfig object here? In this case we could use it instead of payment_driver and network parameters.

@@ -110,15 +104,15 @@ def payment_init(

def payment_status(
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, if we decide to use PaymentConfig in these calls, let's change this one as well for consistency.

@@ -50,6 +51,7 @@ def __init__(
self,
name: str,
probe_type: Type["Probe"],
payment_config: PaymentConfig,
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is a public field, please add its type definition to the class (like for other fields in this class).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@johny-b
Copy link
Contributor Author

johny-b commented Nov 2, 2021

@zakaprov

I left goth/runner/cli/yagna_payment_cmd.py without changes, because

  1. I don't think logic behind "how to use this PaymentConfig thing" should be placed in goth/runner/cli
  2. One could consider using goth/runner/cli without knowing anything about PaymentConfig

IOW, I'd rather not entangle those two parts of goth in any way.

But I'm not super-sure about this, so if you insist, I'll change that : )

@johny-b johny-b requested a review from kmazurek November 2, 2021 16:25
Copy link
Contributor

@kmazurek kmazurek left a comment

Choose a reason for hiding this comment

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

Left one last nitpick comment, the rest looks good!

@@ -292,6 +299,12 @@ def load_yaml(
name = node["name"]
type_name = node["type"]
use_proxy = node.get("use-proxy", False)

payment_config_name = node.get(
"payment_config", DEFAULT_PAYMENT_CONFIG_NAME
Copy link
Contributor

Choose a reason for hiding this comment

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

Apologies for the confusion, but I think for the sake of consistency with other goth-config.yml fields the name of the field itself should be payment-config (hyphen instead of underscore).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good find. I should have thought about it.
cbb2254

@johny-b johny-b merged commit 7882c57 into master Nov 3, 2021
@shadeofblue shadeofblue deleted the johny-b/multiple-payment-networks branch January 19, 2022 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support choosing yagna payment platform through goth-config.yml
2 participants