-
Notifications
You must be signed in to change notification settings - Fork 11
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
Bqeth testing and usage script #289
Conversation
wip: change of plans was a mistakerino
`ManagedAllowList`
Co-authored-by: Manuel Montenegro <manuel@nucypher.com>
Co-authored-by: David Núñez <david@nucypher.com>
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.
LGTM! 👌
Final params for BqETHSubscription deployment on mainnet
Add mainnet deployment artifacts for BqETH
scripts/bqeth_subscription.py
Outdated
|
||
# Load environment variables | ||
load_dotenv() | ||
PROVIDER_URL = os.environ.get("PROVIDER_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 can be a CLI parameter instead of an env-var. This may alleviate some potential issues when changing providers between mainnet and testnet while testing. Also, if you want to keep the env var functionality, click provides some out-of-the-box functionality for this:
https://click.palletsprojects.com/en/8.1.x/options/#values-from-environment-variables
https://click.palletsprojects.com/en/8.1.x/options/#dynamic-defaults-for-prompts
tx_hash = context.subscription_contract.functions.payForEncryptorSlots(extra_slots).transact( | ||
{"from": context.account.address} | ||
) |
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.
- Does this function also imply the transfer of ERC20 fees to the subscription contract?
- If so - we may need to include ERC20 approval here also?
- Perhaps this is related to how you handle
MAX_NODES
above as a means of "pre-approving" an ERC20 amount?
scripts/bqeth_subscription.py
Outdated
def initiate_ritual(context, num_nodes, duration, random_seed, num_rituals): | ||
"""Initiate a ritual.""" | ||
if NUCYPHER_DOMAIN == "mainnet": | ||
porter_request = f"https://porter.nucypher.community/bucket_sampling?quantity={num_nodes}&random_seed={random_seed}" |
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.
Instead of URL-encoding in a string template, requests does have the ability to accept a dictionary of params
.
scripts/bqeth_subscription.py
Outdated
click.echo(f"Account address that will sign the transaction: {context.account.address}") | ||
click.echo(f"Initiating ritual with {num_nodes} providers for {duration} seconds.") | ||
click.echo(f"Endpoint used: {PROVIDER_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.
These can be combined into a single expression.
scripts/bqeth_subscription.py
Outdated
tx_hash = context.coordinator_contract.functions.initiateRitual( | ||
context.subscription_contract.address, | ||
nodes, | ||
context.account.address, # TODO: parametrize this |
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 the authority address of the ritual. For production use-cases this will not be the same as the initiator so we need to parameterize this.
scripts/bqeth_subscription.py
Outdated
@click.option("--random-seed", help="Random seed integer for sampling.") | ||
@click.option("--num-rituals", default=1, help="Number of rituals to initiate.", type=int) | ||
@setup_context | ||
def initiate_ritual(context, num_nodes, duration, random_seed, num_rituals): |
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 function has a sufficiently different scope than subscription payment/management and will be executed by a different permissioned role. IMO this command can be removed from this PR entirely. In fact, there is already a ritual initiation script in this same directory.
- Use typed syntax instead of named tuple - CHAIN is now derived from domain - domain is a cli argument - dotenv overrides each time the script is used - MAX NODES is removed
def build_constants(domain, provider_url, private_key): | ||
DOMAIN_TO_CHAIN = {"lynx": "80002", "tapir": "80002", "mainnet": "137"} | ||
chain = DOMAIN_TO_CHAIN[domain] | ||
PORTER_ENDPOINT = f"https://porter-{domain}.nucypher.community" |
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.
- Will this work on mainnet given the url is
porter.nucypher.io
(without hyphen)? - Let's use the .io domain instead of the .community domain (community is planed for deprecation)
https://porter.nucypher.io
- Consider using the
PORTER_SAMPLING_ENDPOINTS
constant defined in `deployments/constants.py
|
||
|
||
@cli.command() | ||
@click.option("--num-nodes", default=2, help="Number of nodes to use for the ritual.") |
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.
IMO this can be required without a default since each ritual is intentionally created for a specific purpose.
@click.option("--num-nodes", default=2, help="Number of nodes to use for the ritual.") | |
@click.option("--num-nodes", required=True, help="Number of nodes to use for the ritual.") |
[ | ||
u["checksum_address"] | ||
for u in requests.get( | ||
f"{context.constants['PORTER_ENDPOINT']}/get_ursulas?quantity={num_nodes}" |
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.
Do you still intend to use the bucket sampling endpoint for mainnet - or is this script only meant for testnet now?
nodes = list(sorted( | ||
[ | ||
u["checksum_address"] | ||
for u in requests.get( | ||
f"{context.constants['PORTER_ENDPOINT']}/get_ursulas?quantity={num_nodes}" | ||
).json()["result"]["ursulas"] | ||
] | ||
)) |
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 comprehension has grown beyond readability and will be more maintainable if it's broken up into a few variables instead.
start_of_subscription = context.subscription_contract.functions.startOfSubscription().call() | ||
duration = ( | ||
context.subscription_contract.functions.subscriptionPeriodDuration().call() | ||
+ context.subscription_contract.functions.yellowPeriodDuration().call() | ||
+ context.subscription_contract.functions.redPeriodDuration().call() | ||
) |
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.
Ah - This is very interesting functionality! Just making sure I understand correctly it looks like you are correlating a ritual's duration with the specific temporal rules of a subscription?
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.
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.
|
||
|
||
def build_constants(domain, provider_url, private_key): | ||
DOMAIN_TO_CHAIN = {"lynx": "80002", "tapir": "80002", "mainnet": "137"} |
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.
There are string constants for these domain strings in deployments/constants.py
DOMAIN_TO_CHAIN = {"lynx": "80002", "tapir": "80002", "mainnet": "137"} | |
DOMAIN_TO_CHAIN = {LYNX: "80002", TAPIR: "80002", MAINNET: "137"} |
"ERC20_CONTRACT_ADDRESS": registry[chain][f"{domain.title()}RitualToken"]["address"], | ||
"ERC20_CONTRACT_ABI": registry[chain][f"{domain.title()}RitualToken"]["abi"], |
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.
Is this script intended only for testnets (absolutely fine if it is given the name of the PR is "testing")?
Do you mean this entire PR? This script broke the ice for testnet fee model deployments but I'm in favor of closing this PR as long as you feel that all of the useful bits have been included elsewhere. Also, I want to acknowledge that #299 is based off your initial work here (I made sure to include you as a commit author). That being said (almost) all of the functionality implemented in this PR has been implemented in #299 and #297. The main difference is that this PR has fewer dependencies (#299 heavily depends on eth-ape abstractions). Personally, I do not view that as a major issue. There are a few interesting bits of logic here, particularly with regard to ritual duration calculation that I'd like to understand better so we may possibly include the same changes in #297. (see #289 (comment)) Additional thoughts? |
0dc8055
to
05b960e
Compare
This branch was closed by automation after deleting the epic-subscription branch. I suggest making a new PR into |
Closes https://github.com/orgs/nucypher/projects/55/views/1?pane=issue&itemId=69683595