Skip to content

Commit

Permalink
Merge pull request #39 from derekpierre/use-dkg-dev-15
Browse files Browse the repository at this point in the history
Use `nucypher` `dkg-dev-15`
  • Loading branch information
KPrasch authored Oct 6, 2023
2 parents a09a447 + b954791 commit ed902ac
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 147 deletions.
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ name = "pypi"
python_version = "3"

[packages]
nucypher = {git = "https://github.com/nucypher/nucypher.git", ref = "dkg-dev-14"}
nucypher = {git = "https://github.com/nucypher/nucypher.git", ref = "dkg-dev-15"}
nucypher-core = "==0.12.0" # must be the same as nucypher
flask-cors = "*"

[dev-packages]
nucypher = {git = "https://github.com/nucypher/nucypher.git", editable = true, ref = "dkg-dev-14", extras = ["dev"]} # needed for testerchain, and must be editable
nucypher = {git = "https://github.com/nucypher/nucypher.git", editable = true, ref = "dkg-dev-15", extras = ["dev"]} # needed for testerchain, and must be editable
pytest = "<7" # match with nucypher/nucypher
pytest-cov = "*"
pytest-mock = "*"
Expand Down
6 changes: 3 additions & 3 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions deploy/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ services:
- .:/code
- ~/.local/share/nucypher:/nucypher
command: ["nucypher-porter", "run",
"--eth-provider", "${WEB3_PROVIDER_URI}",
"--network", "${NUCYPHER_NETWORK}",
"--eth-endpoint", "${WEB3_PROVIDER_URI}",
"--domain", "${NUCYPHER_NETWORK}",
"--allow-origins", "${PORTER_CORS_ALLOW_ORIGINS}"] # empty string if env var not defined which translates to CORS not enabled by default
4 changes: 2 additions & 2 deletions deploy/docker/nginx/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ services:
- .:/code
- ~/.local/share/nucypher:/nucypher
command: [ "nucypher-porter", "run",
"--eth-provider", "${WEB3_PROVIDER_URI}",
"--network", "${NUCYPHER_NETWORK}" ]
"--eth-domain", "${WEB3_PROVIDER_URI}",
"--domain", "${NUCYPHER_NETWORK}" ]
environment:
- VIRTUAL_HOST=porter.local
- VIRTUAL_PORT=9155
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ msgspec==0.18.2 ; python_version >= '3.8'
multidict==5.2.0 ; python_version >= '3.6'
mypy-extensions==1.0.0 ; python_version >= '3.5'
nodeenv==1.8.0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6'
git+https://github.com/nucypher/nucypher.git@6ea73db2c4585da8b52c51fac071a0bc07f8f406#egg=nucypher
git+https://github.com/nucypher/nucypher.git@ff383dc663c7100cf2ae6f899ed268213b6c653d#egg=nucypher
nucypher-core==0.12.0
numpy==1.24.4 ; python_version >= '3.8'
packaging==23.1 ; python_version >= '3.7'
Expand Down
125 changes: 77 additions & 48 deletions porter/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import click
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.blockchain.eth.domains import TACoDomain
from nucypher.characters.lawful import Ursula
from nucypher.cli.config import group_general_config
from nucypher.cli.options import (
option_network,
option_eth_provider_uri,
option_teacher_uri,
option_domain,
option_eth_endpoint,
option_min_stake,
option_registry_filepath,
option_min_stake
option_teacher_uri,
)
from nucypher.cli.types import NETWORK_PORT
from nucypher.cli.utils import setup_emitter, get_registry
from nucypher.config.constants import TEMPORARY_DOMAIN
from nucypher.cli.utils import get_registry, setup_emitter

from porter.cli.help import echo_version, echo_config_root_path, echo_logging_root_path
from porter.cli.literature import (
PORTER_CORS_ALLOWED_ORIGINS,
PORTER_RUN_MESSAGE
)
from porter.main import Porter, BANNER
from porter.cli.help import echo_config_root_path, echo_logging_root_path, echo_version
from porter.cli.literature import PORTER_CORS_ALLOWED_ORIGINS, PORTER_RUN_MESSAGE
from porter.main import BANNER, Porter


@click.group()
Expand All @@ -34,53 +30,86 @@ def porter_cli():

@porter_cli.command()
@group_general_config
@option_network(default=NetworksInventory.DEFAULT, validate=True, required=False)
@option_eth_provider_uri(required=False)
@option_domain(default=TACoDomain.DEFAULT_DOMAIN_NAME, validate=True, required=False)
@option_eth_endpoint(required=False)
@option_teacher_uri
@option_registry_filepath
@option_min_stake
@click.option('--http-port', help="Porter HTTP/HTTPS port for JSON endpoint", type=NETWORK_PORT, default=Porter.DEFAULT_PORT)
@click.option('--allow-origins', help="The CORS origin(s) comma-delimited list of strings/regexes for origins to allow - no origins allowed by default", type=click.STRING)
@click.option('--dry-run', '-x', help="Execute normally without actually starting Porter", is_flag=True)
@click.option('--eager', help="Start learning and scraping the network before starting up other services", is_flag=True, default=True)
def run(general_config,
network,
eth_provider_uri,
teacher_uri,
registry_filepath,
min_stake,
http_port,
allow_origins,
dry_run,
eager):
@click.option(
"--http-port",
help="Porter HTTP/HTTPS port for JSON endpoint",
type=NETWORK_PORT,
default=Porter.DEFAULT_PORT,
)
@click.option(
"--allow-origins",
help="The CORS origin(s) comma-delimited list of strings/regexes for origins to allow - no origins allowed by default",
type=click.STRING,
)
@click.option(
"--dry-run",
"-x",
help="Execute normally without actually starting Porter",
is_flag=True,
)
@click.option(
"--eager",
help="Start learning and scraping the domain before starting up other services",
is_flag=True,
default=True,
)
def run(
general_config,
domain,
eth_endpoint,
teacher_uri,
registry_filepath,
min_stake,
http_port,
allow_origins,
dry_run,
eager,
):
"""Start Porter's Web controller."""
emitter = setup_emitter(general_config, banner=BANNER)

# HTTP/HTTPS
if not eth_provider_uri:
raise click.BadOptionUsage(option_name='--eth-provider',
message=click.style("--eth-provider is required for decentralized porter.", fg="red"))
if not network:
# should never happen - network defaults to 'mainnet' if not specified
raise click.BadOptionUsage(option_name='--network',
message=click.style("--network is required for decentralized porter.", "red"))
if not eth_endpoint:
raise click.BadOptionUsage(
option_name="--eth-endpoint",
message=click.style(
"--eth-endpoint is required for decentralized porter.", fg="red"
),
)
if not domain:
# should never happen - domain defaults to 'mainnet' if not specified
raise click.BadOptionUsage(
option_name="--domain",
message=click.style(
"--domain is required for decentralized porter.", "red"
),
)

registry = get_registry(network=network, registry_filepath=registry_filepath)
registry = get_registry(domain=domain, registry_filepath=registry_filepath)
teacher = None
if teacher_uri:
teacher = Ursula.from_teacher_uri(teacher_uri=teacher_uri,
min_stake=min_stake,
registry=registry,
provider_uri=eth_provider_uri)
teacher = Ursula.from_teacher_uri(
teacher_uri=teacher_uri,
min_stake=min_stake,
registry=registry,
eth_endpoint=eth_endpoint,
)

PORTER = Porter(domain=network,
known_nodes={teacher} if teacher else None,
registry=registry,
start_learning_now=eager,
eth_provider_uri=eth_provider_uri)
PORTER = Porter(
domain=domain,
known_nodes={teacher} if teacher else None,
registry=registry,
start_learning_now=eager,
eth_endpoint=eth_endpoint,
)

emitter.message(f"Network: {PORTER.domain.capitalize()}", color='green')
emitter.message(f"ETH Provider URI: {eth_provider_uri}", color='green')
emitter.message(f"TACo Domain: {PORTER.domain.capitalize()}", color="green")
emitter.message(f"ETH Endpoint URI: {eth_endpoint}", color="green")

# firm up falsy status (i.e. change specified empty string to None)
allow_origins = allow_origins if allow_origins else None
Expand Down
42 changes: 22 additions & 20 deletions porter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
from flask import Response, request
from nucypher.blockchain.eth.agents import ContractAgency, TACoApplicationAgent
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.blockchain.eth.registry import (
BaseContractRegistry,
InMemoryContractRegistry,
)
from nucypher.blockchain.eth.registry import ContractRegistry
from nucypher.characters.lawful import Ursula
from nucypher.crypto.powers import DecryptingPower
from nucypher.network.decryption import ThresholdDecryptionClient
Expand Down Expand Up @@ -39,7 +36,7 @@
| | | |_| | | | |_( (/ /| |
|_| \___/|_| \___)____)_|
the Pipe for TACo Application network operations
the Pipe for TACo Application operations
"""


Expand Down Expand Up @@ -83,28 +80,33 @@ class CBDDecryptionOutcome(NamedTuple):
]
errors: Dict[ChecksumAddress, str]

def __init__(self,
domain: str = None,
registry: BaseContractRegistry = None,
controller: bool = True,
node_class: object = Ursula,
eth_provider_uri: str = None,
execution_timeout: int = DEFAULT_EXECUTION_TIMEOUT,
*args, **kwargs):
if not eth_provider_uri:
def __init__(
self,
domain: str = None,
registry: ContractRegistry = None,
controller: bool = True,
node_class: object = Ursula,
eth_endpoint: str = None,
execution_timeout: int = DEFAULT_EXECUTION_TIMEOUT,
*args,
**kwargs,
):
if not eth_endpoint:
raise ValueError('ETH Provider URI is required for decentralized Porter.')

if not BlockchainInterfaceFactory.is_interface_initialized(eth_provider_uri=eth_provider_uri):
BlockchainInterfaceFactory.initialize_interface(eth_provider_uri=eth_provider_uri)
if not BlockchainInterfaceFactory.is_interface_initialized(
endpoint=eth_endpoint
):
BlockchainInterfaceFactory.initialize_interface(endpoint=eth_endpoint)

self.eth_provider_uri = eth_provider_uri
self.registry = registry or InMemoryContractRegistry.from_latest_publication(
network=domain
self.eth_endpoint = eth_endpoint
self.registry = registry or ContractRegistry.from_latest_publication(
domain=domain
)
self.application_agent = ContractAgency.get_agent(
TACoApplicationAgent,
registry=self.registry,
provider_uri=self.eth_provider_uri,
blockchain_endpoint=self.eth_endpoint,
)

super().__init__(save_metadata=True, domain=domain, node_class=node_class, *args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ msgpack==1.0.5
msgpack-python==0.5.6
multidict==5.2.0 ; python_version >= '3.6'
mypy-extensions==1.0.0 ; python_version >= '3.5'
git+https://github.com/nucypher/nucypher.git@6ea73db2c4585da8b52c51fac071a0bc07f8f406#egg=nucypher
git+https://github.com/nucypher/nucypher.git@ff383dc663c7100cf2ae6f899ed268213b6c653d#egg=nucypher
nucypher-core==0.12.0
packaging==23.1 ; python_version >= '3.7'
parsimonious==0.9.0
Expand Down
Loading

0 comments on commit ed902ac

Please sign in to comment.