From 55f28b4e611741e70e8ac92b83ceb48537bcfe12 Mon Sep 17 00:00:00 2001 From: derekpierre Date: Tue, 17 Oct 2023 12:12:53 -0400 Subject: [PATCH 1/5] Add CLI command to list rituals for a specific TACo domain. There is the option to also include inactive ritual information as well. --- nucypher/cli/commands/taco.py | 82 ++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/nucypher/cli/commands/taco.py b/nucypher/cli/commands/taco.py index b1c9dbf62..baef7c783 100644 --- a/nucypher/cli/commands/taco.py +++ b/nucypher/cli/commands/taco.py @@ -1,10 +1,13 @@ from pathlib import Path import click +import maya +from tabulate import tabulate from web3 import Web3 from nucypher.blockchain.eth.agents import ( ContractAgency, + CoordinatorAgent, TACoApplicationAgent, ) from nucypher.blockchain.eth.constants import ( @@ -106,6 +109,16 @@ option_to_block = click.option( type=click.INT, ) +option_ritual_ids = click.option( + "--ritual-id", + "-r", + "ritual_ids", + help="ID of a ritual", + multiple=True, + type=click.INT, + default=[], +) + @click.group() def taco(): @@ -116,7 +129,7 @@ def taco(): @group_registry_options @group_general_config def application_info(general_config, registry_options): - """Overall information for the TACo Application.""" + """Overall information about the TACo Application.""" emitter, registry, blockchain_endpoint = registry_options.setup( general_config=general_config ) @@ -129,7 +142,7 @@ def application_info(general_config, registry_options): @group_registry_options @group_general_config def active_providers(general_config, registry_options): - """List of active stakers for the TACo Application""" + """List of active stakers for the TACo Domain.""" emitter, registry, blockchain_endpoint = registry_options.setup( general_config=general_config ) @@ -148,6 +161,71 @@ def active_providers(general_config, registry_options): emitter.echo(f"\t{provider} ..... {Web3.from_wei(staked, 'ether'):,}") +@taco.command() +@option_ritual_ids +@click.option( + "--include-inactive", + "-i", + "include_inactive", + help="Include all known rituals including failed/expired ones", + is_flag=True, +) +@group_registry_options +@group_general_config +def rituals(ritual_ids, include_inactive, registry_options, general_config): + """Information about rituals on the TACo domain.""" + if ritual_ids and not include_inactive: + # provided ritual ids may/may not be active + include_inactive = True + + emitter, registry, blockchain_endpoint = registry_options.setup( + general_config=general_config + ) + coordinator_agent = ContractAgency.get_agent( + CoordinatorAgent, registry=registry, blockchain_endpoint=blockchain_endpoint + ) + + headers = ["ID", "Expiry", "Threshold", "Participants"] + if include_inactive: + headers += ["Status", "Active"] + + now = maya.now() + rows = list() + ritual_id_list = ( + ritual_ids if ritual_ids else range(coordinator_agent.number_of_rituals()) + ) + for ritual_id in ritual_id_list: + ritual = coordinator_agent.get_ritual(ritual_id) + + ritual_status = coordinator_agent.get_ritual_status(ritual_id=ritual_id) + ritual_expiry = maya.MayaDT(epoch=ritual.end_timestamp) + is_ritual_active = all( + [ + ritual_status == CoordinatorAgent.Ritual.Status.FINALIZED, + ritual_expiry > now, + ] + ) + if not include_inactive and not is_ritual_active: + continue + + row = [ + ritual_id, + ritual_expiry.rfc3339(), + f"{ritual.threshold}/{ritual.dkg_size}", + "\n".join([p.provider for p in ritual.participants]), + ] + + if include_inactive: + row.append(str(ritual_status)) + row.append("✓" if is_ritual_active else "x") + + rows.append(row) + + emitter.echo( + tabulate(rows, headers=headers, showindex=False, tablefmt="fancy_grid") + ) + + @taco.command() @group_registry_options @group_general_config From 187a9c8783a4981f31d4055e29a01ecc43f133c1 Mon Sep 17 00:00:00 2001 From: derekpierre Date: Tue, 17 Oct 2023 12:26:48 -0400 Subject: [PATCH 2/5] Include Authority and AccessController entries in table output. --- nucypher/cli/commands/taco.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/nucypher/cli/commands/taco.py b/nucypher/cli/commands/taco.py index baef7c783..53d5ea44f 100644 --- a/nucypher/cli/commands/taco.py +++ b/nucypher/cli/commands/taco.py @@ -15,6 +15,7 @@ from nucypher.blockchain.eth.constants import ( TACO_CONTRACT_NAMES, ) from nucypher.blockchain.eth.domains import TACoDomain +from nucypher.blockchain.eth.utils import truncate_checksum_address from nucypher.cli.config import group_general_config from nucypher.cli.options import ( group_options, @@ -185,7 +186,14 @@ def rituals(ritual_ids, include_inactive, registry_options, general_config): CoordinatorAgent, registry=registry, blockchain_endpoint=blockchain_endpoint ) - headers = ["ID", "Expiry", "Threshold", "Participants"] + headers = [ + "ID", + "Authority", + "AccessController", + "Threshold", + "Participants", + "Expiry", + ] if include_inactive: headers += ["Status", "Active"] @@ -210,9 +218,13 @@ def rituals(ritual_ids, include_inactive, registry_options, general_config): row = [ ritual_id, - ritual_expiry.rfc3339(), + truncate_checksum_address(ritual.authority), + truncate_checksum_address(ritual.access_controller), f"{ritual.threshold}/{ritual.dkg_size}", - "\n".join([p.provider for p in ritual.participants]), + "\n".join( + [truncate_checksum_address(p.provider) for p in ritual.participants] + ), + ritual_expiry.rfc3339(), ] if include_inactive: From 9d8f05013015f663c3906965114ddd51695298e9 Mon Sep 17 00:00:00 2001 From: derekpierre Date: Tue, 17 Oct 2023 12:32:22 -0400 Subject: [PATCH 3/5] Always include "State", "Active" columns. --- nucypher/cli/commands/taco.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/nucypher/cli/commands/taco.py b/nucypher/cli/commands/taco.py index 53d5ea44f..638ee18fb 100644 --- a/nucypher/cli/commands/taco.py +++ b/nucypher/cli/commands/taco.py @@ -175,10 +175,6 @@ def active_providers(general_config, registry_options): @group_general_config def rituals(ritual_ids, include_inactive, registry_options, general_config): """Information about rituals on the TACo domain.""" - if ritual_ids and not include_inactive: - # provided ritual ids may/may not be active - include_inactive = True - emitter, registry, blockchain_endpoint = registry_options.setup( general_config=general_config ) @@ -193,9 +189,9 @@ def rituals(ritual_ids, include_inactive, registry_options, general_config): "Threshold", "Participants", "Expiry", + "State", + "Active", ] - if include_inactive: - headers += ["Status", "Active"] now = maya.now() rows = list() @@ -225,12 +221,10 @@ def rituals(ritual_ids, include_inactive, registry_options, general_config): [truncate_checksum_address(p.provider) for p in ritual.participants] ), ritual_expiry.rfc3339(), + ritual_status, + "✓" if is_ritual_active else "x", ] - if include_inactive: - row.append(str(ritual_status)) - row.append("✓" if is_ritual_active else "x") - rows.append(row) emitter.echo( From 7f31a740e2a2b1f87fa860fbd6bba47780e7f8c5 Mon Sep 17 00:00:00 2001 From: derekpierre Date: Tue, 17 Oct 2023 12:36:08 -0400 Subject: [PATCH 4/5] Add newsfragment for #3290. --- newsfragments/3290.misc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/3290.misc.rst diff --git a/newsfragments/3290.misc.rst b/newsfragments/3290.misc.rst new file mode 100644 index 000000000..62e09e335 --- /dev/null +++ b/newsfragments/3290.misc.rst @@ -0,0 +1 @@ +Add ``nucypher taco rituals`` CLI command to list ritual information for a TACo domain. From 500dc6ac3506e0bf6417c6318c65696926248771 Mon Sep 17 00:00:00 2001 From: derekpierre Date: Tue, 17 Oct 2023 12:42:56 -0400 Subject: [PATCH 5/5] Update show_inactive value to True if specific ritual ids are queried. --- nucypher/cli/commands/taco.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/nucypher/cli/commands/taco.py b/nucypher/cli/commands/taco.py index 638ee18fb..2f6a4dff3 100644 --- a/nucypher/cli/commands/taco.py +++ b/nucypher/cli/commands/taco.py @@ -165,16 +165,20 @@ def active_providers(general_config, registry_options): @taco.command() @option_ritual_ids @click.option( - "--include-inactive", + "--show-inactive", "-i", - "include_inactive", - help="Include all known rituals including failed/expired ones", + "show_inactive", + help="Include failed/expired rituals", is_flag=True, ) @group_registry_options @group_general_config -def rituals(ritual_ids, include_inactive, registry_options, general_config): +def rituals(ritual_ids, show_inactive, registry_options, general_config): """Information about rituals on the TACo domain.""" + if not show_inactive and ritual_ids: + # provided ritual ids may/may not be active + show_inactive = True + emitter, registry, blockchain_endpoint = registry_options.setup( general_config=general_config ) @@ -209,7 +213,7 @@ def rituals(ritual_ids, include_inactive, registry_options, general_config): ritual_expiry > now, ] ) - if not include_inactive and not is_ritual_active: + if not show_inactive and not is_ritual_active: continue row = [