From 3bbc951ea5325e865d3f767e8503f7db2ec75eaf Mon Sep 17 00:00:00 2001 From: Kieran Prasch Date: Mon, 30 Oct 2023 17:33:40 +0100 Subject: [PATCH] respond to RFCs in PR #3315 --- nucypher/blockchain/eth/actors.py | 11 ++++------- nucypher/characters/base.py | 20 +++++++++++-------- nucypher/characters/lawful.py | 13 +----------- nucypher/config/base.py | 11 ++++++----- nucypher/network/nodes.py | 33 +++++++++++++++++-------------- 5 files changed, 41 insertions(+), 47 deletions(-) diff --git a/nucypher/blockchain/eth/actors.py b/nucypher/blockchain/eth/actors.py index fccfaadc2..4c7aaed8c 100644 --- a/nucypher/blockchain/eth/actors.py +++ b/nucypher/blockchain/eth/actors.py @@ -1,8 +1,9 @@ +import time from collections import defaultdict +from decimal import Decimal +from typing import DefaultDict, Dict, List, Optional, Set, Tuple, Union import maya -import time -from decimal import Decimal from eth_typing import ChecksumAddress from hexbytes import HexBytes from nucypher_core import ( @@ -22,12 +23,10 @@ from nucypher_core.ferveo import ( Transcript, Validator, ) -from typing import DefaultDict, Dict, List, Optional, Set, Tuple, Union from web3 import HTTPProvider, Web3 from web3.types import TxReceipt from nucypher.acumen.nicknames import Nickname -from nucypher.blockchain.eth import domains from nucypher.blockchain.eth.agents import ( ContractAgency, CoordinatorAgent, @@ -39,9 +38,7 @@ from nucypher.blockchain.eth.constants import NULL_ADDRESS from nucypher.blockchain.eth.decorators import validate_checksum_address from nucypher.blockchain.eth.domains import TACoDomain from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory -from nucypher.blockchain.eth.registry import ( - ContractRegistry, -) +from nucypher.blockchain.eth.registry import ContractRegistry from nucypher.blockchain.eth.signers import Signer from nucypher.blockchain.eth.trackers import dkg from nucypher.blockchain.eth.trackers.bonding import OperatorBondedTracker diff --git a/nucypher/characters/base.py b/nucypher/characters/base.py index 766f04a0f..0f9699326 100644 --- a/nucypher/characters/base.py +++ b/nucypher/characters/base.py @@ -1,8 +1,9 @@ +from pathlib import Path +from typing import ClassVar, Dict, List, Optional, Union + from constant_sorrow.constants import NO_NICKNAME, NO_SIGNING_POWER, STRANGER from eth_utils import to_canonical_address from nucypher_core.umbral import PublicKey -from pathlib import Path -from typing import ClassVar, Dict, List, Optional, Union from nucypher.acumen.nicknames import Nickname from nucypher.blockchain.eth import domains @@ -78,7 +79,6 @@ class Character(Learner): represented by zero Characters or by more than one Character. """ - self.domain = domains.get_domain(str(domain)) # @@ -128,11 +128,15 @@ class Character(Learner): ) # Learner - Learner.__init__(self, - network_middleware=self.network_middleware, - node_class=known_node_class, - include_self_in_the_state=include_self_in_the_state, - *args, **kwargs) + Learner.__init__( + self, + domain=self.domain, + network_middleware=self.network_middleware, + node_class=known_node_class, + include_self_in_the_state=include_self_in_the_state, + *args, + **kwargs, + ) self.checksum_address = checksum_address diff --git a/nucypher/characters/lawful.py b/nucypher/characters/lawful.py index fac7db44b..7f81bb47c 100644 --- a/nucypher/characters/lawful.py +++ b/nucypher/characters/lawful.py @@ -106,7 +106,7 @@ from nucypher.crypto.utils import keccak_digest from nucypher.network.decryption import ThresholdDecryptionClient from nucypher.network.exceptions import NodeSeemsToBeDown from nucypher.network.middleware import RestMiddleware -from nucypher.network.nodes import TEACHER_NODES, NodeSprout, Teacher +from nucypher.network.nodes import NodeSprout, Teacher from nucypher.network.protocols import parse_node_uri from nucypher.network.retrieval import PRERetrievalClient from nucypher.network.server import ProxyRESTServer, make_rest_app @@ -1177,17 +1177,6 @@ class Ursula(Teacher, Character, Operator): seed_uri = f"{seednode_metadata.checksum_address}@{seednode_metadata.rest_host}:{seednode_metadata.rest_port}" return cls.from_seed_and_stake_info(seed_uri=seed_uri, *args, **kwargs) - @classmethod - def seednode_for_domain(cls, domain: str, eth_endpoint: str) -> "Ursula": - """Returns a default seednode ursula for a given network.""" - try: - url = TEACHER_NODES[domain][0] - except KeyError: - raise ValueError(f'"{domain}" is not a known domain.') - except IndexError: - raise ValueError(f'No default seednodes available for "{domain}".') - ursula = cls.from_seed_and_stake_info(seed_uri=url, eth_endpoint=eth_endpoint) - return ursula @classmethod def from_teacher_uri( diff --git a/nucypher/config/base.py b/nucypher/config/base.py index 88f2ae25e..97e591eb7 100644 --- a/nucypher/config/base.py +++ b/nucypher/config/base.py @@ -1,6 +1,11 @@ import json import re from abc import ABC, abstractmethod +from decimal import Decimal +from pathlib import Path +from tempfile import TemporaryDirectory +from typing import Callable, List, Optional, Union + from constant_sorrow.constants import ( DEVELOPMENT_CONFIGURATION, LIVE_CONFIGURATION, @@ -9,11 +14,7 @@ from constant_sorrow.constants import ( UNINITIALIZED_CONFIGURATION, UNKNOWN_VERSION, ) -from decimal import Decimal from eth_utils.address import is_checksum_address -from pathlib import Path -from tempfile import TemporaryDirectory -from typing import Callable, List, Optional, Union from nucypher.blockchain.eth import domains from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory @@ -832,7 +833,7 @@ class CharacterConfiguration(BaseConfiguration): if pre_payment_class.ONCHAIN: # on-chain payment strategies require a blockchain connection pre_payment_strategy = pre_payment_class( - domain=str(self.domain), + domain=self.domain, blockchain_endpoint=self.polygon_endpoint, registry=self.registry, ) diff --git a/nucypher/network/nodes.py b/nucypher/network/nodes.py index 15b2422e8..477f0aba1 100644 --- a/nucypher/network/nodes.py +++ b/nucypher/network/nodes.py @@ -29,6 +29,7 @@ from nucypher.acumen.perception import FleetSensor from nucypher.blockchain.eth import domains from nucypher.blockchain.eth.agents import ContractAgency, TACoApplicationAgent from nucypher.blockchain.eth.constants import NULL_ADDRESS +from nucypher.blockchain.eth.domains import TACoDomain from nucypher.blockchain.eth.registry import ContractRegistry from nucypher.config.constants import SeednodeMetadata from nucypher.config.storages import ForgetfulNodeStorage @@ -250,22 +251,24 @@ class Learner: it does not have the proper attributes for learning or verification. """ - def __init__(self, - node_class: object = None, - network_middleware: RestMiddleware = None, - start_learning_now: bool = False, - learn_on_same_thread: bool = False, - known_nodes: tuple = None, - seed_nodes: Tuple[tuple] = None, - node_storage=None, - save_metadata: bool = False, - abort_on_learning_error: bool = False, - lonely: bool = False, - verify_node_bonding: bool = True, - include_self_in_the_state: bool = False, - ) -> None: - + def __init__( + self, + domain: TACoDomain, + node_class: object = None, + network_middleware: RestMiddleware = None, + start_learning_now: bool = False, + learn_on_same_thread: bool = False, + known_nodes: tuple = None, + seed_nodes: Tuple[tuple] = None, + node_storage=None, + save_metadata: bool = False, + abort_on_learning_error: bool = False, + lonely: bool = False, + verify_node_bonding: bool = True, + include_self_in_the_state: bool = False, + ) -> None: self.log = Logger("learning-loop") # type: Logger + self.domain = domain self.learning_deferred = Deferred() default_middleware = self.__DEFAULT_MIDDLEWARE_CLASS(