Prevent nucypher ursula init from executing by looking up operator address in the Coordinator contract.

pull/3533/head
KPrasch 2024-07-31 23:21:51 +07:00
parent f85cf10b82
commit e65d9a9c73
No known key found for this signature in database
3 changed files with 77 additions and 11 deletions

View File

@ -590,7 +590,9 @@ class CharacterConfiguration(BaseConfiguration):
def generate(
cls, password: str, key_material: Optional[bytes] = None, *args, **kwargs
):
"""Shortcut: Hook-up a new initial installation and configuration."""
"""
Generates local directories, private keys, and initial configuration for a new node.
"""
node_config = cls(dev_mode=False, *args, **kwargs)
node_config.initialize(key_material=key_material, password=password)
node_config.keystore.unlock(password)
@ -787,7 +789,7 @@ class CharacterConfiguration(BaseConfiguration):
power_ups.append(power_up)
return power_ups
def initialize(self, password: str, key_material: Optional[bytes] = None) -> str:
def initialize(self, password: str, key_material: Optional[bytes] = None) -> Path:
"""Initialize a new configuration and write installation files to disk."""
# Development

View File

@ -5,13 +5,22 @@ from typing import Dict, List, Optional
from cryptography.x509 import Certificate
from eth_utils import is_checksum_address
from nucypher.blockchain.eth.agents import (
ContractAgency,
CoordinatorAgent,
TACoChildApplicationAgent,
)
from nucypher.blockchain.eth.constants import NULL_ADDRESS
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.config.base import CharacterConfiguration
from nucypher.config.constants import (
NUCYPHER_ENVVAR_ALICE_ETH_PASSWORD,
NUCYPHER_ENVVAR_BOB_ETH_PASSWORD,
NUCYPHER_ENVVAR_OPERATOR_ETH_PASSWORD,
)
from nucypher.utilities.emitters import StdoutEmitter
from nucypher.utilities.networking import LOOPBACK_ADDRESS
from nucypher.utilities.warnings import render_lost_seed_phrase_message
class UrsulaConfiguration(CharacterConfiguration):
@ -67,6 +76,50 @@ class UrsulaConfiguration(CharacterConfiguration):
self.condition_blockchain_endpoints[int(chain)] = blockchain_endpoint
self.configure_condition_blockchain_endpoints()
def initialize(self, *args, **kwargs) -> Path:
"""
Check if the coordinator public key is set and prevent the creation of a new node if it is.
"""
emitter = StdoutEmitter()
emitter.echo("Checking operator account status...")
BlockchainInterfaceFactory.get_or_create_interface(
endpoint=self.polygon_endpoint
)
coordinator_agent = ContractAgency.get_agent(
CoordinatorAgent,
blockchain_endpoint=self.polygon_endpoint,
registry=self.registry,
)
application_agent = ContractAgency.get_agent(
TACoChildApplicationAgent,
blockchain_endpoint=self.polygon_endpoint,
registry=self.registry,
)
staking_provider_address = application_agent.staking_provider_from_operator(
self.operator_address
)
if staking_provider_address != NULL_ADDRESS:
if coordinator_agent.is_provider_public_key_set(staking_provider_address):
message = (
f"Operator {self.operator_address} has already published a public key.\n"
f"It is not permitted to create a new node with this operator address."
f"{render_lost_seed_phrase_message()}"
)
self.log.critical(message)
raise self.ConfigurationError(message)
else:
emitter.echo(
"NOTE: Your operator is not bonded to a staking provider. \n"
"Bond the operator to a staking provider on the threshold dashboard.",
color="cyan",
)
return super().initialize(*args, **kwargs)
def configure_condition_blockchain_endpoints(self) -> None:
"""Configure default condition provider URIs for eth and polygon network."""
# Polygon

View File

@ -1,3 +1,22 @@
from nucypher.config.constants import DEFAULT_CONFIG_ROOT
def render_lost_seed_phrase_message():
message = f"""
To relocate your node to a new host copy the configuration directory ({DEFAULT_CONFIG_ROOT}) to the new host.
If you do not have a backup of the original keystore or have lost your password, you will need to recover your
node using the recovery phrase assigned during the initial setup by running:
nucypher ursula recover
If you have lost your recovery phrase: Open a support ticket in the Threshold Discord server (#taco).
Disclose the loss immediately to minimize penalties. Your stake may be slashed, but the punishment will be significantly
reduced if a key material handover is completed quickly, ensuring the node's service is not disrupted.
"""
return message
def render_ferveo_key_mismatch_warning(local_key, onchain_key):
message = f"""
@ -8,15 +27,7 @@ This is a critical error. Without the original private keys, your node cannot se
IMPORTANT: Running `nucypher ursula init` will generate new private keys, which is not the correct procedure
for relocating or restoring a TACo node.
To relocate your node to a new host copy the keystore directory (~/.local/share/nucypher) to the new host.
If you do not have a backup of the original keystore or have lost your password, you will need to recover your
node using the recovery phrase assigned during the initial setup by running:
nucypher ursula recover
If you have lost your recovery phrase: Open a support ticket in the Threshold Discord server (#taco).
Disclose the loss immediately to minimize penalties. Your stake may be slashed, but the punishment will be significantly
reduced if a key material handover is completed quickly, ensuring the node's service is not disrupted.
{render_lost_seed_phrase_message()}
"""
return message