mirror of https://github.com/nucypher/nucypher.git
Deprecate condition_provider_uris in favour of condition_blockchain_endpoints.
parent
57d683ee58
commit
1c333bddaa
|
@ -166,7 +166,7 @@ class Operator(BaseActor):
|
|||
crypto_power: CryptoPower = None,
|
||||
client_password: str = None,
|
||||
operator_address: Optional[ChecksumAddress] = None,
|
||||
condition_provider_uris: Optional[Dict[int, List[str]]] = None,
|
||||
condition_blockchain_endpoints: Optional[Dict[int, List[str]]] = None,
|
||||
publish_finalization: bool = True, # TODO: Remove this
|
||||
*args,
|
||||
**kwargs,
|
||||
|
@ -241,7 +241,7 @@ class Operator(BaseActor):
|
|||
) # used for secure decryption request channel
|
||||
|
||||
self.condition_providers = self.connect_condition_providers(
|
||||
condition_provider_uris
|
||||
condition_blockchain_endpoints
|
||||
)
|
||||
|
||||
def set_provider_public_key(self) -> Union[TxReceipt, None]:
|
||||
|
@ -265,19 +265,22 @@ class Operator(BaseActor):
|
|||
return provider
|
||||
|
||||
def connect_condition_providers(
|
||||
self, condition_provider_uris: Optional[Dict[int, List[str]]] = None
|
||||
self, condition_blockchain_endpoints: Optional[Dict[int, List[str]]] = None
|
||||
) -> DefaultDict[int, Set[HTTPProvider]]:
|
||||
"""Multi-provider support"""
|
||||
|
||||
# If condition_provider_uris is None the node operator
|
||||
# If condition_blockchain_endpoints is None the node operator
|
||||
# did not configure any additional condition providers.
|
||||
condition_provider_uris = condition_provider_uris or dict()
|
||||
condition_blockchain_endpoints = condition_blockchain_endpoints or dict()
|
||||
|
||||
# These are the chains that the Operator will connect to for conditions evaluation (read-only).
|
||||
condition_providers = defaultdict(set)
|
||||
|
||||
# Now, add any additional providers that were passed in.
|
||||
for chain_id, condition_provider_uris in condition_provider_uris.items():
|
||||
for (
|
||||
chain_id,
|
||||
condition_blockchain_endpoints,
|
||||
) in condition_blockchain_endpoints.items():
|
||||
if not self._is_permitted_condition_chain(chain_id):
|
||||
# this is a safety check to prevent the Operator from connecting to
|
||||
# chains that are not supported by ursulas on the network;
|
||||
|
@ -287,7 +290,7 @@ class Operator(BaseActor):
|
|||
)
|
||||
|
||||
providers = set()
|
||||
for uri in condition_provider_uris:
|
||||
for uri in condition_blockchain_endpoints:
|
||||
provider = self._make_condition_provider(uri)
|
||||
providers.add(provider)
|
||||
|
||||
|
|
|
@ -819,7 +819,7 @@ class Ursula(Teacher, Character, Operator):
|
|||
transacting_power: Optional[TransactingPower] = None,
|
||||
eth_endpoint: Optional[str] = None,
|
||||
polygon_endpoint: Optional[str] = None,
|
||||
condition_provider_uris: Optional[Dict[int, List[str]]] = None,
|
||||
condition_blockchain_endpoints: Optional[Dict[int, List[str]]] = None,
|
||||
pre_payment_method: Optional[Union[PaymentMethod, ContractPayment]] = None,
|
||||
# Character
|
||||
abort_on_learning_error: bool = False,
|
||||
|
@ -861,7 +861,7 @@ class Ursula(Teacher, Character, Operator):
|
|||
polygon_endpoint=polygon_endpoint,
|
||||
pre_payment_method=pre_payment_method,
|
||||
client_password=client_password,
|
||||
condition_provider_uris=condition_provider_uris,
|
||||
condition_blockchain_endpoints=condition_blockchain_endpoints,
|
||||
transacting_power=transacting_power,
|
||||
)
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ class UrsulaConfiguration(CharacterConfiguration):
|
|||
keystore_path: Optional[Path] = None,
|
||||
rest_port: Optional[int] = None,
|
||||
certificate: Optional[Certificate] = None,
|
||||
condition_provider_uris: Optional[Dict[str, List[str]]] = None,
|
||||
condition_blockchain_endpoints: Optional[Dict[str, List[str]]] = None,
|
||||
*args,
|
||||
**kwargs,
|
||||
) -> None:
|
||||
|
@ -61,31 +61,37 @@ class UrsulaConfiguration(CharacterConfiguration):
|
|||
|
||||
# json configurations don't allow for integer keyed dictionaries
|
||||
# so convert string chain id to integer
|
||||
self.condition_provider_uris = dict()
|
||||
if condition_provider_uris:
|
||||
for chain, providers in condition_provider_uris.items():
|
||||
self.condition_blockchain_endpoints = dict()
|
||||
if condition_blockchain_endpoints:
|
||||
for chain, blockchain_endpoint in condition_blockchain_endpoints.items():
|
||||
# convert chain from string key (for json) to integer
|
||||
self.condition_provider_uris[int(chain)] = providers
|
||||
self.configure_condition_provider_uris()
|
||||
self.condition_blockchain_endpoints[int(chain)] = blockchain_endpoint
|
||||
self.configure_condition_blockchain_endpoints()
|
||||
|
||||
def configure_condition_provider_uris(self) -> None:
|
||||
def configure_condition_blockchain_endpoints(self) -> None:
|
||||
"""Configure default condition provider URIs for eth and polygon network."""
|
||||
taco_network = NetworksInventory.get_network(self.domain)
|
||||
|
||||
# Polygon
|
||||
polygon_chain_id = taco_network.polygon_chain.id
|
||||
polygon_endpoints = self.condition_provider_uris.get(polygon_chain_id, [])
|
||||
polygon_endpoints = self.condition_blockchain_endpoints.get(
|
||||
polygon_chain_id, []
|
||||
)
|
||||
if not polygon_endpoints:
|
||||
self.condition_provider_uris[polygon_chain_id] = polygon_endpoints
|
||||
self.condition_blockchain_endpoints[polygon_chain_id] = polygon_endpoints
|
||||
|
||||
if self.polygon_endpoint not in polygon_endpoints:
|
||||
polygon_endpoints.append(self.polygon_endpoint)
|
||||
|
||||
# Ethereum
|
||||
staking_chain_id = taco_network.eth_chain.id
|
||||
staking_chain_endpoints = self.condition_provider_uris.get(staking_chain_id, [])
|
||||
staking_chain_endpoints = self.condition_blockchain_endpoints.get(
|
||||
staking_chain_id, []
|
||||
)
|
||||
if not staking_chain_endpoints:
|
||||
self.condition_provider_uris[staking_chain_id] = staking_chain_endpoints
|
||||
self.condition_blockchain_endpoints[
|
||||
staking_chain_id
|
||||
] = staking_chain_endpoints
|
||||
|
||||
if self.eth_endpoint not in staking_chain_endpoints:
|
||||
staking_chain_endpoints.append(self.eth_endpoint)
|
||||
|
@ -113,7 +119,7 @@ class UrsulaConfiguration(CharacterConfiguration):
|
|||
operator_address=self.operator_address,
|
||||
rest_host=self.rest_host,
|
||||
rest_port=self.rest_port,
|
||||
condition_provider_uris=self.condition_provider_uris,
|
||||
condition_blockchain_endpoints=self.condition_blockchain_endpoints,
|
||||
|
||||
# PRE Payments
|
||||
# TODO: Resolve variable prefixing below (uses nested configuration fields?)
|
||||
|
|
|
@ -15,6 +15,10 @@ def __migration(config: Dict) -> Dict:
|
|||
config["polygon_endpoint"] = config["pre_payment_provider"]
|
||||
del config["pre_payment_provider"]
|
||||
|
||||
# condition_provider_uris -> condition_blockchain_endpoints
|
||||
config["condition_blockchain_endpoints"] = config["condition_provider_uris"]
|
||||
del config["condition_provider_uris"]
|
||||
|
||||
return config
|
||||
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ def test_goerli_and_mumbai_as_conditions_providers(lonely_ursula_maker):
|
|||
_ursula_who_tries_to_connect_to_an_invalid_chain = lonely_ursula_maker(
|
||||
quantity=1,
|
||||
domain="useless_domain",
|
||||
condition_provider_uris={
|
||||
condition_blockchain_endpoints={
|
||||
INVALID_CHAIN_ID: "this is a provider URI, but it doesn't matter what we pass here because the chain_id is invalid."
|
||||
},
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue