mirror of https://github.com/nucypher/nucypher.git
Slice in a --lonely ursula flag
parent
5be6363d8c
commit
13254397bc
|
@ -727,7 +727,7 @@ class Ursula(Teacher, Character, Miner):
|
|||
certificate = network_middleware.get_certificate(host=host, port=port)
|
||||
real_host = certificate.subject.get_attributes_for_oid(NameOID.COMMON_NAME)[0].value
|
||||
temp_node_storage = ForgetfulNodeStorage(federated_only=federated_only)
|
||||
certificate_filepath = temp_node_storage.store_host_certificate(certificate=certificate)
|
||||
certificate_filepath = temp_node_storage.store_node_certificate(certificate=certificate)
|
||||
# Load the host as a potential seed node
|
||||
potential_seed_node = cls.from_rest_url(
|
||||
host=real_host,
|
||||
|
@ -740,11 +740,11 @@ class Ursula(Teacher, Character, Miner):
|
|||
|
||||
if checksum_address:
|
||||
# Ensure this is the specific node we expected
|
||||
if not checksum_public_address == potential_seed_node.checksum_public_address:
|
||||
if not checksum_address == potential_seed_node.checksum_public_address:
|
||||
template = "This seed node has a different wallet address: {} (expected {}). Are you sure this is a seednode?"
|
||||
raise potential_seed_node.SuspiciousActivity(
|
||||
template.format(potential_seed_node.checksum_public_address,
|
||||
checksum_public_address))
|
||||
checksum_address))
|
||||
|
||||
# Check the node's stake (optional)
|
||||
if minimum_stake > 0:
|
||||
|
|
|
@ -146,6 +146,7 @@ def status(click_config, config_file):
|
|||
@click.option('--quiet', '-Q', help="Disable logging", is_flag=True)
|
||||
@click.option('--dry-run', '-x', help="Execute normally without actually starting the node", is_flag=True)
|
||||
@click.option('--force', help="Don't ask for confirmation", is_flag=True)
|
||||
@click.option('--lonely', help="Do not connect to seednodes", is_flag=True)
|
||||
@click.option('--network', help="Network Domain Name", type=click.STRING)
|
||||
@click.option('--teacher-uri', help="An Ursula URI to start learning from (seednode)", type=click.STRING)
|
||||
@click.option('--min-stake', help="The minimum stake the teacher must have to be a teacher", type=click.INT, default=0)
|
||||
|
@ -169,6 +170,7 @@ def ursula(click_config,
|
|||
quiet,
|
||||
dry_run,
|
||||
force,
|
||||
lonely,
|
||||
network,
|
||||
teacher_uri,
|
||||
min_stake,
|
||||
|
@ -368,7 +370,8 @@ Delete {}?'''.format(ursula_config.config_root), abort=True)
|
|||
ursula_config.connect_to_blockchain(recompile_contracts=False)
|
||||
ursula_config.connect_to_contracts()
|
||||
except EthereumContractRegistry.NoRegistry:
|
||||
message = "Cannot configure blockchain character: No contract registry found; Did you mean to pass --federated-only?"
|
||||
message = "Cannot configure blockchain character: No contract registry found; " \
|
||||
"Did you mean to pass --federated-only?"
|
||||
raise EthereumContractRegistry.NoRegistry(message)
|
||||
|
||||
click_config.ursula_config = ursula_config # Pass Ursula's config onto staking sub-command
|
||||
|
@ -390,7 +393,7 @@ Delete {}?'''.format(ursula_config.config_root), abort=True)
|
|||
#
|
||||
# Produce - Step 2
|
||||
#
|
||||
ursula = ursula_config(known_nodes=teacher_nodes)
|
||||
ursula = ursula_config(known_nodes=teacher_nodes, lonely=lonely)
|
||||
|
||||
# GO!
|
||||
try:
|
||||
|
|
|
@ -30,6 +30,7 @@ from cryptography import x509
|
|||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives.serialization import Encoding
|
||||
from cryptography.x509 import Certificate, NameOID
|
||||
from eth_utils import is_checksum_address
|
||||
from twisted.logger import Logger
|
||||
from typing import Callable, Tuple, Union, Set, Any
|
||||
|
||||
|
|
|
@ -246,7 +246,8 @@ class Learner:
|
|||
seed_nodes: Tuple[tuple] = None,
|
||||
node_storage=None,
|
||||
save_metadata: bool = False,
|
||||
abort_on_learning_error: bool = False
|
||||
abort_on_learning_error: bool = False,
|
||||
lonely: bool = False,
|
||||
) -> None:
|
||||
|
||||
self.log = Logger("learning-loop") # type: Logger
|
||||
|
@ -263,6 +264,7 @@ class Learner:
|
|||
|
||||
self.__known_nodes = FleetStateTracker()
|
||||
|
||||
self.lonely = lonely
|
||||
self.done_seeding = False
|
||||
|
||||
# Read
|
||||
|
@ -330,13 +332,14 @@ class Learner:
|
|||
__attempt_seednode_learning(seednode_metadata=seednode_metadata)
|
||||
|
||||
if not self.unresponsive_seed_nodes:
|
||||
self.log.info("Finished learning about all seednodes.")
|
||||
if not self.lonely:
|
||||
self.log.info("Finished learning about all seednodes.")
|
||||
self.done_seeding = True
|
||||
|
||||
if read_storages is True:
|
||||
self.read_nodes_from_storage()
|
||||
|
||||
if not self.known_nodes:
|
||||
if not self.known_nodes and not self.lonely:
|
||||
self.log.warn("No seednodes were available after {} attempts".format(retry_attempts))
|
||||
# TODO: Need some actual logic here for situation with no seed nodes (ie, maybe try again much later)
|
||||
|
||||
|
@ -401,18 +404,26 @@ class Learner:
|
|||
return False
|
||||
elif now:
|
||||
self.log.info("Starting Learning Loop NOW.")
|
||||
self.load_seednodes()
|
||||
if not self.lonely:
|
||||
self.load_seednodes()
|
||||
self.learn_from_teacher_node()
|
||||
self.learning_deferred = self._learning_task.start(interval=self._SHORT_LEARNING_DELAY)
|
||||
self.learning_deferred.addErrback(self.handle_learning_errors)
|
||||
return self.learning_deferred
|
||||
else:
|
||||
self.log.info("Starting Learning Loop.")
|
||||
seeder_deferred = deferToThread(self.load_seednodes)
|
||||
|
||||
learning_deferreds = list()
|
||||
if not self.lonely:
|
||||
seeder_deferred = deferToThread(self.load_seednodes)
|
||||
seeder_deferred.addErrback(self.handle_learning_errors)
|
||||
learning_deferreds.append(seeder_deferred)
|
||||
|
||||
learner_deferred = self._learning_task.start(interval=self._SHORT_LEARNING_DELAY, now=now)
|
||||
seeder_deferred.addErrback(self.handle_learning_errors)
|
||||
learner_deferred.addErrback(self.handle_learning_errors)
|
||||
self.learning_deferred = defer.DeferredList([seeder_deferred, learner_deferred])
|
||||
learning_deferreds.append(learner_deferred)
|
||||
|
||||
self.learning_deferred = defer.DeferredList(learning_deferreds)
|
||||
return self.learning_deferred
|
||||
|
||||
def stop_learning_loop(self, reason=None):
|
||||
|
@ -454,7 +465,9 @@ class Learner:
|
|||
# that we have connected to all the seed nodes.
|
||||
if self.unresponsive_seed_nodes:
|
||||
self.log.info("Still have unresponsive seed nodes; trying again to connect.")
|
||||
self.load_seednodes() # Ideally, this is async and singular.
|
||||
|
||||
if not self.lonely:
|
||||
self.load_seednodes() # Ideally, this is async and singular.
|
||||
|
||||
if not self.teacher_nodes:
|
||||
self.select_teacher_nodes()
|
||||
|
|
Loading…
Reference in New Issue