Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/perform work #105

Merged
merged 28 commits into from
Sep 5, 2022
Merged

Fix/perform work #105

merged 28 commits into from
Sep 5, 2022

Conversation

Karrenbelt
Copy link
Contributor

perform work round / behaviour. Still need to revisit performatives, #98 , which is up next.

Comment on lines 132 to 136
def build_safe_raw_tx(
self,
tx_params: Dict[str, Any],
) -> Generator[None, None, Optional[str]]:
"""Build safe raw tx hash"""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still need to finish the bonding / activation and work transaction preparation. This is related to performatives and will also affect the tests, so next PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


address = self.synchronized_data.safe_contract_address
contract_api_response = yield from self.get_contract_api_response(
performative=ContractApiMessage.Performative.GET_STATE, # type: ignore
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. this should be GET_RAW_TRANSACTION, but it affects all transaction producing behaviours hence addressing separately

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def process_payload(self, payload: BaseTxPayload) -> None:
"""Process payload."""
raise NotImplementedError
_ = (Event.INSUFFICIENT_FUNDS,)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually unnecessary I think, can be caught via error performative

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can prepare tx and submit to tx settlement, which will handle insufficient funds

if rpc_status == RPCResponseStatus.INSUFFICIENT_FUNDS:
# blacklist self.

Comment on lines 132 to 135
def build_safe_raw_tx(
self,
tx_params: Dict[str, Any],
) -> Generator[None, None, Optional[str]]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it is worth opening an issue on open-autonomy to extract a skill for this since it is also being done in the price estimation skill?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps, I don't understand it well enough. Why not as part of the tx settlement skill?

Comment on lines -409 to -447
def _get_raw_work_transaction_hash(self) -> Generator[None, None, Optional[str]]:

job_contract_api_response = yield from self.get_contract_api_response(
performative=ContractApiMessage.Performative.GET_RAW_TRANSACTION, # type: ignore
contract_id=str(Keep3rTestJobContract.contract_id),
contract_callable="work",
contract_address=self.synchronized_data.current_job,
sender_address=self.context.agent_address,
)

if (
job_contract_api_response.performative
!= ContractApiMessage.Performative.RAW_TRANSACTION
): # pragma: nocover
self.context.logger.warning("get raw work transaction unsuccessful!")
return None

tx_params = job_contract_api_response.raw_transaction.body
safe_contract_address = self.synchronized_data.safe_contract_address

safe_contract_api_msg = yield from self.get_contract_api_response(
performative=ContractApiMessage.Performative.GET_RAW_TRANSACTION, # type: ignore
contract_address=safe_contract_address,
contract_id=str(GnosisSafeContract.contract_id),
contract_callable="get_raw_safe_transaction_hash",
to_address=tx_params["to_address"],
value=tx_params["ether_value"],
data=tx_params["data"],
safe_tx_gas=tx_params["safe_tx_gas"],
)
if (
safe_contract_api_msg.performative
!= ContractApiMessage.Performative.RAW_TRANSACTION
): # pragma: nocover
self.context.logger.warning("Get work transaction hash unsuccessful!")
return None
tx_hash = cast(str, job_contract_api_response.raw_transaction.body.pop("hash"))

return tx_hash
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved here

def build_work_raw_tx(
self, job_address: str, address: str
) -> Generator[None, None, Optional[RawTx]]:
"""Build raw work transaction for a job contract"""
contract_api_response = yield from self.get_contract_api_response(
performative=ContractApiMessage.Performative.GET_RAW_TRANSACTION,
contract_id=str(Keep3rTestJobContract.contract_id),
contract_callable="build_work_tx",
contract_address=job_address,
address=address,
)
if (
contract_api_response.performative
!= ContractApiMessage.Performative.RAW_TRANSACTION
):
self.context.logger.error(
f"Failed build_work_raw_tx: {contract_api_response}"
)
return None
log_msg = f"`build_work_tx` contract api response on {contract_api_response}"
self.context.logger.info(f"{log_msg}: {contract_api_response}")
return cast(RawTx, contract_api_response.raw_transaction.body.get("data"))
def build_safe_raw_tx(
self,
tx_params: RawTx,
) -> Generator[None, None, Optional[str]]:
"""Build safe raw tx hash"""
contract_api_response = yield from self.get_contract_api_response(
performative=ContractApiMessage.Performative.GET_RAW_TRANSACTION,
contract_address=self.synchronized_data.safe_contract_address,
contract_id=str(GnosisSafeContract.contract_id),
contract_callable="get_raw_safe_transaction_hash",
to_address=tx_params["to"],
value=tx_params["value"],
data=tx_params["data"],
safe_tx_gas=tx_params["gas"],
)
if (
contract_api_response.performative
!= ContractApiMessage.Performative.RAW_TRANSACTION
):
self.context.logger.warning("build_safe_raw_tx unsuccessful!")
return None
return cast(str, contract_api_response.raw_transaction.body.pop("tx_hash"))

@@ -129,6 +129,31 @@ def has_sufficient_funds(self, address: str) -> Generator[None, None, bool]:
self.context.logger.info(f"balance: {balance / 10 ** 18} ETH")
return balance >= cast(int, self.context.params.insufficient_funds_threshold)

def build_safe_raw_tx(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this being called anywhere in async_act...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7bc5e3f

@DavidMinarsch DavidMinarsch merged commit 900dddf into feat/await_top_up Sep 5, 2022
@DavidMinarsch DavidMinarsch deleted the fix/perform_work branch September 5, 2022 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants