From 6b12617fc1e4025e2c772f6abc9d1ca6eaee800e Mon Sep 17 00:00:00 2001 From: James Campbell Date: Thu, 15 Aug 2024 15:55:53 +0100 Subject: [PATCH 1/3] Prevent variables being overwritten --- scripts/initiate_ritual.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/initiate_ritual.py b/scripts/initiate_ritual.py index 323d327c..7b08678f 100644 --- a/scripts/initiate_ritual.py +++ b/scripts/initiate_ritual.py @@ -105,6 +105,11 @@ def cli( message="Cannot specify --min-version when using --handpicked.", ) + # Get the contracts from the registry + coordinator_contract = registry.get_contract(domain=domain, contract_name="Coordinator") + access_controller_contract = registry.get_contract(domain=domain, contract_name=access_controller) + fee_model_contract = registry.get_contract(domain=domain, contract_name=fee_model) + # Get the staking providers in the ritual cohort if handpicked: providers = sorted(line.lower() for line in handpicked) @@ -115,20 +120,16 @@ def cli( domain=domain, num_nodes=num_nodes, duration=duration, random_seed=random_seed, min_version=min_version ) - # Get the contracts from the registry - coordinator = registry.get_contract(domain=domain, contract_name="Coordinator") - access_controller = registry.get_contract(domain=domain, contract_name=access_controller) - fee_model = registry.get_contract(domain=domain, contract_name=fee_model) # Initiate the ritual transactor = Transactor(account=account) transactor.transact( - coordinator.initiateRitual, - fee_model.address, + coordinator_contract.initiateRitual, + fee_model_contract.address, providers, authority, duration, - access_controller.address, + access_controller_contract.address, ) From d4dac28cb03cca2fb20d11a3e98f509d606757e4 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Thu, 15 Aug 2024 16:44:15 +0100 Subject: [PATCH 2/3] Add duration calculation when using a subscription --- scripts/initiate_ritual.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/scripts/initiate_ritual.py b/scripts/initiate_ritual.py index 7b08678f..8d6d1bcd 100644 --- a/scripts/initiate_ritual.py +++ b/scripts/initiate_ritual.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 import click +from ape import chain from ape.cli import ConnectedProviderCommand, account_option, network_option from deployment import registry @@ -25,7 +26,7 @@ "-t", help="Duration of the ritual in seconds. Must be at least 24h.", type=MinInt(86400), - required=True, + required=False, ) @click.option( "--access-controller", @@ -110,6 +111,23 @@ def cli( access_controller_contract = registry.get_contract(domain=domain, contract_name=access_controller) fee_model_contract = registry.get_contract(domain=domain, contract_name=fee_model) + # if using a subcription, duration needs to be calculated + if fee_model == "BqETHSubscription": + start_of_subscription = fee_model_contract.startOfSubscription() + duration = ( + fee_model_contract.subscriptionPeriodDuration() + + fee_model_contract.yellowPeriodDuration() + + fee_model_contract.redPeriodDuration() + ) + if start_of_subscription > 0: + click.echo( + "Subscription has already started. Subtracting the elapsed time from the duration." + ) + now = chain.blocks.head.timestamp + elapsed = now - start_of_subscription + 100 + duration -= elapsed + + # Get the staking providers in the ritual cohort if handpicked: providers = sorted(line.lower() for line in handpicked) From 2619079d5ec0b8916d856c9b70ee5babbb19ec51 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Fri, 16 Aug 2024 09:14:44 +0100 Subject: [PATCH 3/3] Check that subscription hasn't already ended --- scripts/initiate_ritual.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/initiate_ritual.py b/scripts/initiate_ritual.py index 8d6d1bcd..1908c402 100644 --- a/scripts/initiate_ritual.py +++ b/scripts/initiate_ritual.py @@ -120,10 +120,13 @@ def cli( + fee_model_contract.redPeriodDuration() ) if start_of_subscription > 0: + end_of_subscription = fee_model_contract.getEndOfSubscription() + now = chain.blocks.head.timestamp + if now > end_of_subscription: + raise ValueError("Subscription has already ended.") click.echo( "Subscription has already started. Subtracting the elapsed time from the duration." ) - now = chain.blocks.head.timestamp elapsed = now - start_of_subscription + 100 duration -= elapsed