From d270675296a0b30bd9c61f9e3626ede5c48af1b2 Mon Sep 17 00:00:00 2001 From: Kieran Prasch Date: Tue, 12 Sep 2023 17:49:33 +0200 Subject: [PATCH] Ursula on publishes ferveo public key on-chain when none is present to save gas. --- nucypher/blockchain/eth/actors.py | 17 +++++++++-------- nucypher/blockchain/eth/agents.py | 5 +++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/nucypher/blockchain/eth/actors.py b/nucypher/blockchain/eth/actors.py index 1008339b6..23d5df2b8 100644 --- a/nucypher/blockchain/eth/actors.py +++ b/nucypher/blockchain/eth/actors.py @@ -324,16 +324,17 @@ class Ritualist(BaseActor): condition_provider_uris ) - # TODO: check if the ferveo public key is set on the blockchain - # There is no boolean interface on-chain to determine this. + self.set_provider_public_key() + + def set_provider_public_key(self): # Here we're assuming there is one global key per node. - # onchain_ferveo_public_key = self.coordinator_agent.get_provider_public_key( - # self.staking_provider_address, - # 0 - # ) - self.coordinator_agent.set_provider_public_key( - self.ritual_power.public_key(), transacting_power=self.transacting_power + is_provider_key_set = self.coordinator_agent.is_provider_public_key_set( + self.staking_provider_address, ) + if not is_provider_key_set: + self.coordinator_agent.set_provider_public_key( + self.ritual_power.public_key(), transacting_power=self.transacting_power + ) @staticmethod def _is_permitted_condition_chain(chain_id: int) -> bool: diff --git a/nucypher/blockchain/eth/agents.py b/nucypher/blockchain/eth/agents.py index aca5f579d..7f741b60c 100644 --- a/nucypher/blockchain/eth/agents.py +++ b/nucypher/blockchain/eth/agents.py @@ -794,6 +794,11 @@ class CoordinatorAgent(EthereumContractAgent): ).call() return result + @contract_api(CONTRACT_CALL) + def is_provider_public_key_set(self, staking_provider: ChecksumAddress) -> bool: + result = self.contract.functions.isProviderPublicKeySet(staking_provider).call() + return result + @contract_api(TRANSACTION) def set_provider_public_key( self, public_key: FerveoPublicKey, transacting_power: TransactingPower