Skip to content

Commit

Permalink
Merge pull request #181 from valory-xyz/feat/split-window
Browse files Browse the repository at this point in the history
feat: split large block ranges
  • Loading branch information
Adamantios authored Feb 27, 2024
2 parents f795135 + 43a83b9 commit 0fce73e
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 29 deletions.
14 changes: 7 additions & 7 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
"custom/nickcom007/prediction_request_sme/0.1.0": "bafybeicswze7sobpdtpypcgt75b4wvxs3eex5sznswnopxwunyzki6ew5a",
"protocol/valory/acn_data_share/0.1.0": "bafybeih5ydonnvrwvy2ygfqgfabkr47s4yw3uqxztmwyfprulwfsoe7ipq",
"protocol/valory/websocket_client/0.1.0": "bafybeih43mnztdv3v2hetr2k3gezg7d3yj4ur7cxdvcyaqhg65e52s5sf4",
"contract/valory/agent_mech/0.1.0": "bafybeigidwivuynzbtakkzsnnxxls54qaycw2oef4yth5lmtmwotmrf6qq",
"contract/valory/agent_mech/0.1.0": "bafybeicbhvrlug56qvwlh6b4y35xg6fytvtahhaae7xm7jssecbie576mu",
"contract/valory/agent_registry/0.1.0": "bafybeiargayav6yiztdnwzejoejstcx4idssch2h4f5arlgtzj3tgsgfmu",
"contract/valory/hash_checkpoint/0.1.0": "bafybeianr3zy3bb464jwlwwxtk2daeeh4cefy7ihw5bfn7zrn7vjs3fyga",
"connection/valory/websocket_client/0.1.0": "bafybeiflmystocxaqblhpzqlcop2vkhsknpzjx2jomohomaxamwskeokzm",
"skill/valory/contract_subscription/0.1.0": "bafybeicyugrkx5glat4p4ezwf6i7oduh26eycfie6ftd4uxrknztzl3ik4",
"skill/valory/mech_abci/0.1.0": "bafybeiahkev6ur4otoeuprgedck3pk6ob4q44lyvdkvz733ftu54zicw3i",
"skill/valory/task_submission_abci/0.1.0": "bafybeifaqewhshy4xrm7nejtmwgm6wwm6k4ps2xn4v2kckpwqsr7wblslm",
"skill/valory/task_execution/0.1.0": "bafybeienkm3nxcyqllpnndsacaq27nhgwgs4v5vyynvqkyv5uc6aojatji",
"skill/valory/mech_abci/0.1.0": "bafybeiagit2v4swvgwsulrqpr75qgkxhzjjkyc7yevqkggb3jblcjymytq",
"skill/valory/task_submission_abci/0.1.0": "bafybeib6yijhh5ss7mufpjghjwobxjynuaz2mf52jo54dtpyer4ovowei4",
"skill/valory/task_execution/0.1.0": "bafybeih3emwjdqorctgizmxj7r53uiyfzpkvlchdmxfm5oyxvyxpxnd4km",
"skill/valory/websocket_client/0.1.0": "bafybeidwntmkk4b2ixq5454ycbkknclqx7a6vpn7aqpm2nw3duszqrxvta",
"skill/valory/subscription_abci/0.1.0": "bafybeidtoiyzlenxawjkyogwbfjgui2a22srdo6zbajubgg6awgha5hm4m",
"agent/valory/mech/0.1.0": "bafybeigileaik3lno5mb3je2tfsmep33eq43qfxtp4razjfo7mzaxzqfxa",
"service/valory/mech/0.1.0": "bafybeianvggwocwrat6w6zirab44nwpptigb6aw533zawmqxgjg6eslkdm"
"skill/valory/subscription_abci/0.1.0": "bafybeiclwa2u24nv4yzke6s24qxz2uxc6tpniyjxzprlb7oinkiijdhlgy",
"agent/valory/mech/0.1.0": "bafybeicajxejujc42cqojtzkltpdelkeya53qwjdruxx3d77xn5m66b3um",
"service/valory/mech/0.1.0": "bafybeif2pihcwqrm4ecyoc4r3yukt2bincx2b3ktsf7mg3givi2otei5eq"
},
"third_party": {
"protocol/valory/default/1.0.0": "bafybeifqcqy5hfbnd7fjv4mqdjrtujh2vx3p2xhe33y67zoxa6ph7wdpaq",
Expand Down
10 changes: 5 additions & 5 deletions packages/valory/agents/mech/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ connections:
- valory/p2p_libp2p_client:0.1.0:bafybeid3xg5k2ol5adflqloy75ibgljmol6xsvzvezebsg7oudxeeolz7e
- valory/websocket_client:0.1.0:bafybeiflmystocxaqblhpzqlcop2vkhsknpzjx2jomohomaxamwskeokzm
contracts:
- valory/agent_mech:0.1.0:bafybeigidwivuynzbtakkzsnnxxls54qaycw2oef4yth5lmtmwotmrf6qq
- valory/agent_mech:0.1.0:bafybeicbhvrlug56qvwlh6b4y35xg6fytvtahhaae7xm7jssecbie576mu
- valory/agent_registry:0.1.0:bafybeiargayav6yiztdnwzejoejstcx4idssch2h4f5arlgtzj3tgsgfmu
- valory/gnosis_safe:0.1.0:bafybeictjc7saviboxbsdcey3trvokrgo7uoh76mcrxecxhlvcrp47aqg4
- valory/gnosis_safe_proxy_factory:0.1.0:bafybeie6ynnoavvk2fpbn426nlp32sxrj7pz5esgebtlezy4tmx5gjretm
Expand All @@ -38,12 +38,12 @@ skills:
- valory/abstract_abci:0.1.0:bafybeihljirk3d4rgvmx2nmz3p2mp27iwh2o5euce5gccwjwrpawyjzuaq
- valory/abstract_round_abci:0.1.0:bafybeigjrepaqpb3m7zunmt4hryos4vto4yyj3u6iyofdb2fotwho3bqvm
- valory/contract_subscription:0.1.0:bafybeicyugrkx5glat4p4ezwf6i7oduh26eycfie6ftd4uxrknztzl3ik4
- valory/mech_abci:0.1.0:bafybeiahkev6ur4otoeuprgedck3pk6ob4q44lyvdkvz733ftu54zicw3i
- valory/mech_abci:0.1.0:bafybeiagit2v4swvgwsulrqpr75qgkxhzjjkyc7yevqkggb3jblcjymytq
- valory/registration_abci:0.1.0:bafybeif3ln6eg53ebrfe6uicjew4uqp2ynyrcxkw5wi4jm3ixqv3ykte4a
- valory/reset_pause_abci:0.1.0:bafybeicm7onl72rfnn33pbvzwjpkl5gafeieyobfcnyresxz7kunjwmqea
- valory/subscription_abci:0.1.0:bafybeidtoiyzlenxawjkyogwbfjgui2a22srdo6zbajubgg6awgha5hm4m
- valory/task_execution:0.1.0:bafybeienkm3nxcyqllpnndsacaq27nhgwgs4v5vyynvqkyv5uc6aojatji
- valory/task_submission_abci:0.1.0:bafybeifaqewhshy4xrm7nejtmwgm6wwm6k4ps2xn4v2kckpwqsr7wblslm
- valory/subscription_abci:0.1.0:bafybeiclwa2u24nv4yzke6s24qxz2uxc6tpniyjxzprlb7oinkiijdhlgy
- valory/task_execution:0.1.0:bafybeih3emwjdqorctgizmxj7r53uiyfzpkvlchdmxfm5oyxvyxpxnd4km
- valory/task_submission_abci:0.1.0:bafybeib6yijhh5ss7mufpjghjwobxjynuaz2mf52jo54dtpyer4ovowei4
- valory/termination_abci:0.1.0:bafybeie6h7j4hyhgj2wte64n3xyudxq4pgqcqjmslxi5tff4mb6vce2tay
- valory/transaction_settlement_abci:0.1.0:bafybeid57tozt5f3kgzmu22nbr3c3oy4p7bi2bu66rqsgnlylq6xgh2ixe
- valory/websocket_client:0.1.0:bafybeidwntmkk4b2ixq5454ycbkknclqx7a6vpn7aqpm2nw3duszqrxvta
Expand Down
29 changes: 19 additions & 10 deletions packages/valory/contracts/agent_mech/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,27 @@ def get_undelivered_reqs(
contract_address: str,
from_block: BlockIdentifier = "earliest",
to_block: BlockIdentifier = "latest",
max_block_window: int = 1000,
**kwargs: Any,
) -> JSONLike:
"""Get the requests that are not delivered."""
requests: List[Dict[str, Any]] = cls.get_request_events(
ledger_api, contract_address, from_block, to_block
)["data"]
delivers: List[Dict[str, Any]] = cls.get_deliver_events(
ledger_api, contract_address, from_block, to_block
)["data"]
if from_block == "earliest":
from_block = 0

current_block = ledger_api.api.eth.block_number
requests, delivers = [], []
for from_block_batch in range(int(from_block), current_block, max_block_window):
to_block_batch = (from_block_batch + max_block_window) - 1
if to_block_batch >= current_block:
to_block_batch = "latest"
requests_batch: List[Dict[str, Any]] = cls.get_request_events(
ledger_api, contract_address, from_block_batch, to_block_batch
)["data"]
delivers_batch: List[Dict[str, Any]] = cls.get_deliver_events(
ledger_api, contract_address, from_block_batch, to_block_batch
)["data"]
requests.extend(requests_batch)
delivers.extend(delivers_batch)
pending_tasks: List[Dict[str, Any]] = []
for request in requests:
if request["requestId"] not in [
Expand All @@ -366,13 +378,10 @@ def get_multiple_undelivered_reqs(
**kwargs: Any,
) -> JSONLike:
"""Get the requests that are not delivered."""
current_block = ledger_api.api.eth.block_number
if from_block != "earliest" and current_block - from_block > max_block_window:
from_block = current_block - max_block_window
pending_tasks: List[Dict[str, Any]] = []
for contract_address in contract_addresses:
pending_tasks_batch = cls.get_undelivered_reqs(
ledger_api, contract_address, from_block
ledger_api, contract_address, from_block, max_block_window
).get("data")
pending_tasks.extend(pending_tasks_batch)
return {"data": pending_tasks}
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/contracts/agent_mech/contract.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ aea_version: '>=1.0.0, <2.0.0'
fingerprint:
__init__.py: bafybeigpq5lxfj2aza6ok3fjuywtdafelkbvoqwaits7regfbgu4oynmku
build/AgentMech.json: bafybeifw3whznwg6i6sa6cicivsfmqchfwfdodxwaqzepd3h6otq5qpktq
contract.py: bafybeiawilbhsix4ui3whuoyk6sgundbbpeatbidv4krp2c45cpayhfu7m
contract.py: bafybeifb3d7uzgjkffk4j2hgc6beeesoa5e527pme6v45lofliljxtibt4
fingerprint_ignore_patterns: []
class_name: AgentMechContract
contract_interface_paths:
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:bafybeigileaik3lno5mb3je2tfsmep33eq43qfxtp4razjfo7mzaxzqfxa
agent: valory/mech:0.1.0:bafybeicajxejujc42cqojtzkltpdelkeya53qwjdruxx3d77xn5m66b3um
number_of_agents: 4
deployment:
agent:
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/skills/mech_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ skills:
- valory/abstract_round_abci:0.1.0:bafybeigjrepaqpb3m7zunmt4hryos4vto4yyj3u6iyofdb2fotwho3bqvm
- valory/registration_abci:0.1.0:bafybeif3ln6eg53ebrfe6uicjew4uqp2ynyrcxkw5wi4jm3ixqv3ykte4a
- valory/reset_pause_abci:0.1.0:bafybeicm7onl72rfnn33pbvzwjpkl5gafeieyobfcnyresxz7kunjwmqea
- valory/task_submission_abci:0.1.0:bafybeifaqewhshy4xrm7nejtmwgm6wwm6k4ps2xn4v2kckpwqsr7wblslm
- valory/task_submission_abci:0.1.0:bafybeib6yijhh5ss7mufpjghjwobxjynuaz2mf52jo54dtpyer4ovowei4
- valory/termination_abci:0.1.0:bafybeie6h7j4hyhgj2wte64n3xyudxq4pgqcqjmslxi5tff4mb6vce2tay
- valory/transaction_settlement_abci:0.1.0:bafybeid57tozt5f3kgzmu22nbr3c3oy4p7bi2bu66rqsgnlylq6xgh2ixe
- valory/subscription_abci:0.1.0:bafybeidtoiyzlenxawjkyogwbfjgui2a22srdo6zbajubgg6awgha5hm4m
- valory/subscription_abci:0.1.0:bafybeiclwa2u24nv4yzke6s24qxz2uxc6tpniyjxzprlb7oinkiijdhlgy
behaviours:
main:
args: {}
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/skills/subscription_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fingerprint:
fingerprint_ignore_patterns: []
connections: []
contracts:
- valory/agent_mech:0.1.0:bafybeigidwivuynzbtakkzsnnxxls54qaycw2oef4yth5lmtmwotmrf6qq
- valory/agent_mech:0.1.0:bafybeicbhvrlug56qvwlh6b4y35xg6fytvtahhaae7xm7jssecbie576mu
- valory/gnosis_safe:0.1.0:bafybeictjc7saviboxbsdcey3trvokrgo7uoh76mcrxecxhlvcrp47aqg4
- valory/multisend:0.1.0:bafybeig5byt5urg2d2bsecufxe5ql7f4mezg3mekfleeh32nmuusx66p4y
protocols:
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/skills/task_execution/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ connections:
- valory/ipfs:0.1.0:bafybeiflaxrnepfn4hcnq5pieuc7ki7d422y3iqb54lv4tpgs7oywnuhhq
- valory/p2p_libp2p_client:0.1.0:bafybeid3xg5k2ol5adflqloy75ibgljmol6xsvzvezebsg7oudxeeolz7e
contracts:
- valory/agent_mech:0.1.0:bafybeigidwivuynzbtakkzsnnxxls54qaycw2oef4yth5lmtmwotmrf6qq
- valory/agent_mech:0.1.0:bafybeicbhvrlug56qvwlh6b4y35xg6fytvtahhaae7xm7jssecbie576mu
protocols:
- valory/acn_data_share:0.1.0:bafybeih5ydonnvrwvy2ygfqgfabkr47s4yw3uqxztmwyfprulwfsoe7ipq
- valory/contract_api:1.0.0:bafybeidgu7o5llh26xp3u3ebq3yluull5lupiyeu6iooi2xyymdrgnzq5i
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/skills/task_submission_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fingerprint:
fingerprint_ignore_patterns: []
connections: []
contracts:
- valory/agent_mech:0.1.0:bafybeigidwivuynzbtakkzsnnxxls54qaycw2oef4yth5lmtmwotmrf6qq
- valory/agent_mech:0.1.0:bafybeicbhvrlug56qvwlh6b4y35xg6fytvtahhaae7xm7jssecbie576mu
- valory/agent_registry:0.1.0:bafybeiargayav6yiztdnwzejoejstcx4idssch2h4f5arlgtzj3tgsgfmu
- valory/gnosis_safe:0.1.0:bafybeictjc7saviboxbsdcey3trvokrgo7uoh76mcrxecxhlvcrp47aqg4
- valory/multisend:0.1.0:bafybeig5byt5urg2d2bsecufxe5ql7f4mezg3mekfleeh32nmuusx66p4y
Expand Down

0 comments on commit 0fce73e

Please sign in to comment.