Skip to content

Commit

Permalink
Merge pull request #259 from KahanMajmudar/bugfix/mech-revert
Browse files Browse the repository at this point in the history
WIP: only remove tasks if the previous tx was successful
  • Loading branch information
0xArdi authored Oct 21, 2024
2 parents aec184f + 7a75478 commit 81337df
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 16 deletions.
8 changes: 4 additions & 4 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
"contract/valory/mech_marketplace/0.1.0": "bafybeich3a3oh5w4u533w6y7ideojudqp2m5gxta7pqmsfiaohdhuw7yz4",
"connection/valory/websocket_client/0.1.0": "bafybeic4ag3gqc7kd3k2o3pucddj2odck5yrfbgmwh5veqny7zao5qayli",
"skill/valory/contract_subscription/0.1.0": "bafybeiefuemlp75obgpxrp6iuleb3hn6vcviwh5oetk5djbuprf4xsmgjy",
"skill/valory/mech_abci/0.1.0": "bafybeid2xjhf74q6ifjzdk4hhbkoyg2srnpb6336idqpmpdireaab7my5q",
"skill/valory/task_submission_abci/0.1.0": "bafybeibicofaxge45plccso7schwjpdu5tffyzwp43qd2gahy53lizrf3y",
"skill/valory/mech_abci/0.1.0": "bafybeiajz42vtyvmm3bjmft7d6y3dodped2kh7h75zgqocym76twvpyejq",
"skill/valory/task_submission_abci/0.1.0": "bafybeigoda6koeghcboflmz5e6r7yluk7fanpjso64b4am3w2szo2a65w4",
"skill/valory/task_execution/0.1.0": "bafybeif7jsxbue6l7fhn5ahf7jbks5td6me55b42dy7k6s3j72zvu2p7ie",
"skill/valory/websocket_client/0.1.0": "bafybeif7rrvsu6z4evqkhblxj3u6wwv2eqou576hgkyoehxuj7cntw7o2m",
"skill/valory/subscription_abci/0.1.0": "bafybeicnum426c4te77enoalhmthqirrhvswvyunvanjbljlhs2cob6zsa",
"agent/valory/mech/0.1.0": "bafybeihept2bauaohfdpu42lyz23lqnlztopiqechl2towjijgg64n3toa",
"service/valory/mech/0.1.0": "bafybeib3hvrzcew57u4vmqehu52ydm2g375wuow2lpink3fdtxrpkghr2a"
"agent/valory/mech/0.1.0": "bafybeib4wzpyfopo7curjyp5jvt35clri7mmpzyzbtmv5246bjxrkieelu",
"service/valory/mech/0.1.0": "bafybeic7uew3lt2kiely3a5jvizir5pcbnuuwzr6rmj75yydseiz744wqu"
},
"third_party": {
"protocol/valory/default/1.0.0": "bafybeifqcqy5hfbnd7fjv4mqdjrtujh2vx3p2xhe33y67zoxa6ph7wdpaq",
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/agents/mech/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ skills:
- valory/abstract_abci:0.1.0:bafybeihat4giyc4bz6zopvahcj4iw53356pbtwfn7p4d5yflwly2qhahum
- valory/abstract_round_abci:0.1.0:bafybeih3enhagoql7kzpeyzzu2scpkif6y3ubakpralfnwxcvxexdyvy5i
- valory/contract_subscription:0.1.0:bafybeiefuemlp75obgpxrp6iuleb3hn6vcviwh5oetk5djbuprf4xsmgjy
- valory/mech_abci:0.1.0:bafybeid2xjhf74q6ifjzdk4hhbkoyg2srnpb6336idqpmpdireaab7my5q
- valory/mech_abci:0.1.0:bafybeiajz42vtyvmm3bjmft7d6y3dodped2kh7h75zgqocym76twvpyejq
- valory/registration_abci:0.1.0:bafybeiek7zcsxbucjwzgqfftafhfrocvc7q4yxllh2q44jeemsjxg3rcfm
- valory/reset_pause_abci:0.1.0:bafybeidw4mbx3os3hmv7ley7b3g3gja7ydpitr7mxbjpwzxin2mzyt5yam
- valory/subscription_abci:0.1.0:bafybeicnum426c4te77enoalhmthqirrhvswvyunvanjbljlhs2cob6zsa
- valory/task_execution:0.1.0:bafybeif7jsxbue6l7fhn5ahf7jbks5td6me55b42dy7k6s3j72zvu2p7ie
- valory/task_submission_abci:0.1.0:bafybeibicofaxge45plccso7schwjpdu5tffyzwp43qd2gahy53lizrf3y
- valory/task_submission_abci:0.1.0:bafybeigoda6koeghcboflmz5e6r7yluk7fanpjso64b4am3w2szo2a65w4
- valory/termination_abci:0.1.0:bafybeihq6qtbwt6i53ayqym63vhjexkcppy26gguzhhjqywfmiuqghvv44
- valory/transaction_settlement_abci:0.1.0:bafybeigtzlk4uakmd54rxnznorcrstsr52kta474lgrnvx5ovr546vj7sq
- valory/websocket_client:0.1.0:bafybeif7rrvsu6z4evqkhblxj3u6wwv2eqou576hgkyoehxuj7cntw7o2m
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/services/mech/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeif7ia4jdlazy6745ke2k2x5yoqlwsgwr6sbztbgqtwvs3ndm2p7ba
fingerprint_ignore_patterns: []
agent: valory/mech:0.1.0:bafybeihept2bauaohfdpu42lyz23lqnlztopiqechl2towjijgg64n3toa
agent: valory/mech:0.1.0:bafybeib4wzpyfopo7curjyp5jvt35clri7mmpzyzbtmv5246bjxrkieelu
number_of_agents: 4
deployment:
agent:
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/skills/mech_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ skills:
- valory/abstract_round_abci:0.1.0:bafybeih3enhagoql7kzpeyzzu2scpkif6y3ubakpralfnwxcvxexdyvy5i
- valory/registration_abci:0.1.0:bafybeiek7zcsxbucjwzgqfftafhfrocvc7q4yxllh2q44jeemsjxg3rcfm
- valory/reset_pause_abci:0.1.0:bafybeidw4mbx3os3hmv7ley7b3g3gja7ydpitr7mxbjpwzxin2mzyt5yam
- valory/task_submission_abci:0.1.0:bafybeibicofaxge45plccso7schwjpdu5tffyzwp43qd2gahy53lizrf3y
- valory/task_submission_abci:0.1.0:bafybeigoda6koeghcboflmz5e6r7yluk7fanpjso64b4am3w2szo2a65w4
- valory/termination_abci:0.1.0:bafybeihq6qtbwt6i53ayqym63vhjexkcppy26gguzhhjqywfmiuqghvv44
- valory/transaction_settlement_abci:0.1.0:bafybeigtzlk4uakmd54rxnznorcrstsr52kta474lgrnvx5ovr546vj7sq
- valory/subscription_abci:0.1.0:bafybeicnum426c4te77enoalhmthqirrhvswvyunvanjbljlhs2cob6zsa
Expand Down
34 changes: 28 additions & 6 deletions packages/valory/skills/task_submission_abci/behaviours.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def async_act(self) -> Generator: # pylint: disable=R0914,R0915
with self.context.benchmark_tool.measure(self.behaviour_id).local():
# clean up the queue based on the outcome of the previous period
self.handle_submitted_tasks()

# sync new tasks
payload_content = yield from self.get_payload_content()
sender = self.context.agent_address
Expand Down Expand Up @@ -188,12 +189,33 @@ def get_done_tasks(self, timeout: float) -> Generator[None, None, List[Dict]]:

def handle_submitted_tasks(self) -> None:
"""Handle tasks that have been already submitted before (in a prev. period)."""
submitted_tasks = cast(List[Dict[str, Any]], self.synchronized_data.done_tasks)
self.context.logger.info(
f"Tasks {submitted_tasks} has already been submitted. "
f"Removing them from the list of tasks to be processed."
)
self.remove_tasks(submitted_tasks)
status = self.check_last_tx_status()
self.context.logger.info(f"Last tx status is: {status}")
if status:
submitted_tasks = cast(
List[Dict[str, Any]], self.synchronized_data.done_tasks
)
self.context.logger.info(
f"Tasks {submitted_tasks} has already been submitted. "
f"Removing them from the list of tasks to be processed."
)
self.remove_tasks(submitted_tasks)

def check_last_tx_status(self) -> bool:
"""Check if the tx in the last round was successful or not"""
# Try to fetch the final tx hash from the sync db
# If the value exists and is not None, we return True, else False
# ref: https://github.com/valory-xyz/open-autonomy/blob/main/packages/valory/skills/transaction_settlement_abci/rounds.py#L432-L434
try:
final_tx_hash = self.synchronized_data.final_tx_hash
except Exception as e:
self.context.logger.error(e)
return False
else:
if final_tx_hash is not None:
return True
else:
return False


class DeliverBehaviour(TaskExecutionBaseBehaviour, ABC):
Expand Down
5 changes: 5 additions & 0 deletions packages/valory/skills/task_submission_abci/rounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def done_tasks(self) -> List[Dict[str, Any]]:
"""Done tasks."""
return cast(List[Dict[str, Any]], self.db.get("done_tasks", []))

@property
def final_tx_hash(self) -> str:
"""Get the verified tx hash."""
return cast(str, self.db.get_strict("final_tx_hash"))


class TaskPoolingRound(CollectionRound):
"""TaskPoolingRound"""
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/skills/task_submission_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ license: Apache-2.0
aea_version: '>=1.0.0, <2.0.0'
fingerprint:
__init__.py: bafybeiholqak7ltw6bbmn2c5tn3j7xgzkdlfzp3kcskiqsvmxoih6m4muq
behaviours.py: bafybeihib2i2jcpv6e36ftgktchw4eij7sevavk2n4qyxe5gqiv6dx2lt4
behaviours.py: bafybeigdv2gcesycwjwoy62igcbhsr3cgszfzleb5fhl4lwmq7g57skntm
dialogues.py: bafybeibmac3m5u5h6ucoyjr4dazay72dyga656wvjl6z6saapluvjo54ne
fsm_specification.yaml: bafybeidtmsmpunr3t77pshd3k2s6dd6hlvhze6inu3gj7xyvlg4wi3tnuu
handlers.py: bafybeibe5n7my2vd2wlwo73sbma65epjqc7kxgtittewlylcmvnmoxtxzq
models.py: bafybeifkca4krpykazv4tar4nfgaefwplpcia34zrdlvkiijf5anrxzcmu
payloads.py: bafybeia2yorri2u5rwh6vukb6iwdrbn53ygsuuhthns2txptvjipyb6f4e
rounds.py: bafybeiazzauhh5ddr6fkqckv7tiu7nek6k7deoaihwyspeywlrq46uemou
rounds.py: bafybeicqimk23sc7itxwcu372lyerwnqly4v7tv2pcl4krd53gdizdv6ae
tasks.py: bafybeicu5t5cvfhbndgpxbbtmp4vbmtyb6fba6vsnlewftvuderxp5lwcy
fingerprint_ignore_patterns: []
connections: []
Expand Down

0 comments on commit 81337df

Please sign in to comment.