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

chore: break up the check_redeemed into chunks #101

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "bafybeiersmwlzih3yhv5nhy7ay6lqe377wn757pugsl457ypoik57aotom",
"skill/valory/trader_abci/0.1.0": "bafybeiajxg7a47vubwyhqj7brrqheoq3ohwqlq3t4uck75r5p45klt43be",
"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": "bafybeihyksse4ohe3x4tshyrlsral6dgptvb6uqvoteu7prlsdggqjk7tm",
"service/valory/trader/0.1.0": "bafybeiemvxyaai7lcfjx5zujfixxfew6vw2xfdpdqzwyyiwnsg6jxu55ny",
"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": "bafybeicwz2jiwwkcufavqc3ttxkaowjcguq7cuaczzlsvonbv2fk373ezu",
"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": "bafybeig26ktayat3m32to3riescg7plsahdylmpf3ubsguiosqixdwjm6m",
"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:bafybeig26ktayat3m32to3riescg7plsahdylmpf3ubsguiosqixdwjm6m
- 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:bafybeicwz2jiwwkcufavqc3ttxkaowjcguq7cuaczzlsvonbv2fk373ezu
- 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:bafybeiersmwlzih3yhv5nhy7ay6lqe377wn757pugsl457ypoik57aotom
- valory/trader_abci:0.1.0:bafybeiajxg7a47vubwyhqj7brrqheoq3ohwqlq3t4uck75r5p45klt43be
default_ledger: ethereum
required_ledgers:
- ethereum
Expand Down
26 changes: 15 additions & 11 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,21 @@ def check_redeemed(
collateral_tokens_checksummed = [
to_checksum(token) for token in collateral_tokens
]

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)

latest_block = ledger_api.api.eth.block_number
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 = contract_instance.events.PayoutRedemption.build_filter()
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)
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: bafybeibex3xrphf7ssmblx3bo6cy3qzv2wk3nxmnv3k6w56yr6cwnkejlq
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:bafybeihyksse4ohe3x4tshyrlsral6dgptvb6uqvoteu7prlsdggqjk7tm
number_of_agents: 4
deployment: {}
---
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/skills/decision_maker_abci/skill.yaml
Original file line number Diff line number Diff line change
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:bafybeig26ktayat3m32to3riescg7plsahdylmpf3ubsguiosqixdwjm6m
- 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:bafybeiersmwlzih3yhv5nhy7ay6lqe377wn757pugsl457ypoik57aotom
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeicwz2jiwwkcufavqc3ttxkaowjcguq7cuaczzlsvonbv2fk373ezu
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:bafybeiersmwlzih3yhv5nhy7ay6lqe377wn757pugsl457ypoik57aotom
behaviours:
main:
args: {}
Expand Down