Skip to content

Commit

Permalink
chore: break up the check_redeemed into chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
0xArdi committed Sep 27, 2023
1 parent 1d9e5f0 commit b9c581f
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 20 deletions.
12 changes: 6 additions & 6 deletions packages/packages.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"dev": {
"skill/valory/market_manager_abci/0.1.0": "bafybeidnqerwkljbjgog73qaa5duu5ymsfjs6jsszeupseshx7go3n6afq",
"skill/valory/decision_maker_abci/0.1.0": "bafybeieryuvqcg5ko3mnkpw3j34scedrqgomo2xm42bhweszwgwgtjhi6u",
"skill/valory/trader_abci/0.1.0": "bafybeihxfq6vtr7krfwbmkh4j2ozlzdccl4ladxwwhkqmkaa74koivanu4",
"skill/valory/decision_maker_abci/0.1.0": "bafybeihu4vrh2qyujh3rfguwrvekc76en4lo4rn3u6jsgnmxjbmxngzy2y",
"skill/valory/trader_abci/0.1.0": "bafybeiglomtffddoqdwerxdlujeakrdpcaawqt7v26kl4vpb5on7uskl7u",
"contract/valory/market_maker/0.1.0": "bafybeidaz4dol7qsrwitw5jwasjtvd2vtlxhxizwkzen5kurblwacz4biu",
"agent/valory/trader/0.1.0": "bafybeiehv2cjbusia35yjxqim25jvq4d6tni5kcfckemgkvixzx327p7ui",
"service/valory/trader/0.1.0": "bafybeia5rzebe7z3nfgpfngp44rloro3do3y4wxxuroajftqbuiqojnjly",
"agent/valory/trader/0.1.0": "bafybeiczas2owldbgyavccypfdue725wthmejw3syofellnfiuf7i37oxq",
"service/valory/trader/0.1.0": "bafybeihuhbcocor32ssgne7qxe7zrstuho54oh6gv33mwypcer2q5uktgm",
"contract/valory/erc20/0.1.0": "bafybeid6p64a6tnovatbwybc6ocdd4u7bqkxsb4ks52rvf7ozcxxl6iaf4",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeibkj47cuymq57ccbje6hjtidvpycs6rg2cpshoehi7filrsgokdfi",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeigqaswq3uvitzthww3zdulwbaefaxrn5vrmxwutxco7hq5fztk6ay",
"contract/valory/mech/0.1.0": "bafybeiddc6pgurpyja2k64wzsb3jgcvl254s7rplgt5iooftsyfalqlbfq",
"contract/valory/realitio/0.1.0": "bafybeicdgm2a7evjw6szcpo3uaam5mzd6axtevtzwvejr6uaeymbg437da",
"contract/valory/realitio_proxy/0.1.0": "bafybeibvndq6756qck7forgeavhdbn6ykgqs2ufyg7n5g6qdfpveatxuwy",
"contract/valory/conditional_tokens/0.1.0": "bafybeicxwjdbmjajgr5rsmadtkxxwmcm42r2htef3tvng73uzib4hmb6qa",
"contract/valory/conditional_tokens/0.1.0": "bafybeifb5qvzhzuiqmfb7vowynxyia4jyuov7gjyqgdhyw7yvebu6utsvy",
"contract/valory/agent_registry/0.1.0": "bafybeigpd6wvnbb7fbf6yd77rugepv5hrbb6l3qfodstwgemagtcgne3bm"
},
"third_party": {
Expand Down
8 changes: 4 additions & 4 deletions packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contracts:
- valory/erc20:0.1.0:bafybeid6p64a6tnovatbwybc6ocdd4u7bqkxsb4ks52rvf7ozcxxl6iaf4
- valory/multisend:0.1.0:bafybeieg4tywd5lww2vygvpkilg3hcepa4rmhehjuamyvdf6vazt554v6u
- valory/mech:0.1.0:bafybeiddc6pgurpyja2k64wzsb3jgcvl254s7rplgt5iooftsyfalqlbfq
- valory/conditional_tokens:0.1.0:bafybeicxwjdbmjajgr5rsmadtkxxwmcm42r2htef3tvng73uzib4hmb6qa
- valory/conditional_tokens:0.1.0:bafybeifb5qvzhzuiqmfb7vowynxyia4jyuov7gjyqgdhyw7yvebu6utsvy
- valory/realitio:0.1.0:bafybeicdgm2a7evjw6szcpo3uaam5mzd6axtevtzwvejr6uaeymbg437da
- valory/realitio_proxy:0.1.0:bafybeibvndq6756qck7forgeavhdbn6ykgqs2ufyg7n5g6qdfpveatxuwy
protocols:
Expand All @@ -41,10 +41,10 @@ skills:
- valory/reset_pause_abci:0.1.0:bafybeigeoc363gv3wp2rrmk6p2fdxney33nxd3owtpfugzapgruwe4klyu
- valory/termination_abci:0.1.0:bafybeigqpij2sgrpnilqjljfciixop4fldq5qceixc7534q6af4potdmdm
- valory/transaction_settlement_abci:0.1.0:bafybeia7rzsbea3ch4gcafyp3z6uvqh4npws2xpdwbkkdbrqqpjops7nui
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeibkj47cuymq57ccbje6hjtidvpycs6rg2cpshoehi7filrsgokdfi
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeigqaswq3uvitzthww3zdulwbaefaxrn5vrmxwutxco7hq5fztk6ay
- valory/market_manager_abci:0.1.0:bafybeidnqerwkljbjgog73qaa5duu5ymsfjs6jsszeupseshx7go3n6afq
- valory/decision_maker_abci:0.1.0:bafybeieryuvqcg5ko3mnkpw3j34scedrqgomo2xm42bhweszwgwgtjhi6u
- valory/trader_abci:0.1.0:bafybeihxfq6vtr7krfwbmkh4j2ozlzdccl4ladxwwhkqmkaa74koivanu4
- valory/decision_maker_abci:0.1.0:bafybeihu4vrh2qyujh3rfguwrvekc76en4lo4rn3u6jsgnmxjbmxngzy2y
- valory/trader_abci:0.1.0:bafybeiglomtffddoqdwerxdlujeakrdpcaawqt7v26kl4vpb5on7uskl7u
default_ledger: ethereum
required_ledgers:
- ethereum
Expand Down
12 changes: 9 additions & 3 deletions packages/valory/contracts/conditional_tokens/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def check_redeemed(
condition_ids: List[HexBytes],
index_sets: List[List[int]],
from_block_numbers: Dict[HexBytes, BlockIdentifier],
chunk_size: int = 50_000,
) -> JSONLike:
"""Filter to find out whether a position has already been redeemed."""
earliest_block = DEFAULT_FROM_BLOCK
Expand All @@ -71,18 +72,23 @@ def check_redeemed(
collateral_tokens_checksummed = [
to_checksum(token) for token in collateral_tokens
]
latest_block = ledger_api.api.eth.block_number

payout_filter = contract_instance.events.PayoutRedemption.build_filter()
payout_filter.fromBlock = earliest_block
payout_filter.toBlock = DEFAULT_TO_BLOCK
payout_filter.args.redeemer.match_single(redeemer_checksummed)
payout_filter.args.collateralToken.match_any(*collateral_tokens_checksummed)
payout_filter.args.parentCollectionId.match_any(*parent_collection_ids)
payout_filter.args.conditionId.match_any(*condition_ids)
payout_filter.args.indexSets.match_any(*index_sets)

try:
redeemed = list(payout_filter.deploy(ledger_api.api).get_all_entries())
redeemed = []
for from_block in range(earliest_block, latest_block, chunk_size):
to_block = min(from_block + chunk_size, latest_block)
payout_filter.fromBlock = from_block
payout_filter.toBlock = to_block
redeemed_chunk = list(payout_filter.deploy(ledger_api.api).get_all_entries())
redeemed.extend(redeemed_chunk)
except (Urllib3ReadTimeoutError, RequestsReadTimeoutError):
msg = (
"The RPC timed out! This usually happens if the filtering is too wide. "
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/contracts/conditional_tokens/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: bafybeidhdxio3oq5gqdnxmngumvt3fcd6zyiyrpk5f2k4dwhflbg4e5iky
build/ConditionalTokens.json: bafybeia2ahis7zx2yhhf23kpkcxu56hto6fwg6ptjg5ld46lp4dgz7cz3e
contract.py: bafybeigzs6lox5rebabne5knyxxpz4erdlgveogcebsqa4lxasyis3ichu
contract.py: bafybeifgwflxpbnuwhkaez6mkbwvnryzjyxozaemuz4g4bstfrcfcwdqey
fingerprint_ignore_patterns: []
class_name: ConditionalTokensContract
contract_interface_paths:
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/services/trader/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: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq
fingerprint_ignore_patterns: []
agent: valory/trader:0.1.0:bafybeiehv2cjbusia35yjxqim25jvq4d6tni5kcfckemgkvixzx327p7ui
agent: valory/trader:0.1.0:bafybeiczas2owldbgyavccypfdue725wthmejw3syofellnfiuf7i37oxq
number_of_agents: 4
deployment: {}
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ def _check_already_redeemed(self) -> WaitableConditionType:
)
return result

def _get_redeemed_positions(self) -> Generator:
"""Get the redeemed positions."""

def _clean_redeem_info(self) -> Generator:
"""Clean the redeeming information based on whether any positions have already been redeemed."""
yield from self.wait_for_condition_with_sleep(self._check_already_redeemed)
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/skills/decision_maker_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fingerprint:
behaviours/decision_receive.py: bafybeid54jwjs4lulcl2n2w7taxne3wqgsey6ppaidwr2up6bztyf35ghm
behaviours/decision_request.py: bafybeidlyl2ojmpfs2zkewoacraya2cbampo4ynqbqaocsoq7v2nif3ahi
behaviours/handle_failed_tx.py: bafybeidxpc6u575ymct5tdwutvzov6zqfdoio5irgldn3fw7q3lg36mmxm
behaviours/reedem.py: bafybeigzsx4wyov3ehfvdjmo2d7yimss4p7mbkopkqyr4gryxpa5rpv6ku
behaviours/reedem.py: bafybeifpqinwxep47tpdzlwyrdxknkuzlzahi7t6572ynlkhpf5tf77wku
behaviours/round_behaviour.py: bafybeig4tdktyu6hapoqymnxh2bgpds547st6a44heue657wkctwe4gjvm
behaviours/sampling.py: bafybeiadikynvkaofbko72jc45xthhmmjfmlkpgramormhxwk5u47rnwdu
behaviours/tool_selection.py: bafybeidd7jmauc6edgt7caxylanfdz3ucb2qzsndszlxv7an4lohe2waja
Expand Down Expand Up @@ -49,7 +49,7 @@ contracts:
- valory/erc20:0.1.0:bafybeid6p64a6tnovatbwybc6ocdd4u7bqkxsb4ks52rvf7ozcxxl6iaf4
- valory/multisend:0.1.0:bafybeieg4tywd5lww2vygvpkilg3hcepa4rmhehjuamyvdf6vazt554v6u
- valory/mech:0.1.0:bafybeiddc6pgurpyja2k64wzsb3jgcvl254s7rplgt5iooftsyfalqlbfq
- valory/conditional_tokens:0.1.0:bafybeicxwjdbmjajgr5rsmadtkxxwmcm42r2htef3tvng73uzib4hmb6qa
- valory/conditional_tokens:0.1.0:bafybeifb5qvzhzuiqmfb7vowynxyia4jyuov7gjyqgdhyw7yvebu6utsvy
- valory/realitio:0.1.0:bafybeicdgm2a7evjw6szcpo3uaam5mzd6axtevtzwvejr6uaeymbg437da
- valory/realitio_proxy:0.1.0:bafybeibvndq6756qck7forgeavhdbn6ykgqs2ufyg7n5g6qdfpveatxuwy
- valory/agent_registry:0.1.0:bafybeigpd6wvnbb7fbf6yd77rugepv5hrbb6l3qfodstwgemagtcgne3bm
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/skills/trader_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ skills:
- valory/transaction_settlement_abci:0.1.0:bafybeia7rzsbea3ch4gcafyp3z6uvqh4npws2xpdwbkkdbrqqpjops7nui
- valory/termination_abci:0.1.0:bafybeigqpij2sgrpnilqjljfciixop4fldq5qceixc7534q6af4potdmdm
- valory/market_manager_abci:0.1.0:bafybeidnqerwkljbjgog73qaa5duu5ymsfjs6jsszeupseshx7go3n6afq
- valory/decision_maker_abci:0.1.0:bafybeieryuvqcg5ko3mnkpw3j34scedrqgomo2xm42bhweszwgwgtjhi6u
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeibkj47cuymq57ccbje6hjtidvpycs6rg2cpshoehi7filrsgokdfi
- valory/decision_maker_abci:0.1.0:bafybeihu4vrh2qyujh3rfguwrvekc76en4lo4rn3u6jsgnmxjbmxngzy2y
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeigqaswq3uvitzthww3zdulwbaefaxrn5vrmxwutxco7hq5fztk6ay
behaviours:
main:
args: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contracts: []
protocols: []
skills:
- valory/abstract_round_abci:0.1.0:bafybeih2fyfb6kkf7r45pvdk7pyyebr5xloia4xiqxtb3qsrasnstqmepq
- valory/decision_maker_abci:0.1.0:bafybeieryuvqcg5ko3mnkpw3j34scedrqgomo2xm42bhweszwgwgtjhi6u
- valory/decision_maker_abci:0.1.0:bafybeihu4vrh2qyujh3rfguwrvekc76en4lo4rn3u6jsgnmxjbmxngzy2y
behaviours:
main:
args: {}
Expand Down

0 comments on commit b9c581f

Please sign in to comment.