Skip to content

Commit

Permalink
fix: rpc timeout issue
Browse files Browse the repository at this point in the history
Only search up to a specific number of days in the past (`redeem_margin_days`) for redeeming positions.

This is done to avoid a known timeout limitation of getblock's Gnosis RPCs.

Positions for older markets will have to be manually redeemed.
  • Loading branch information
Adamantios committed Sep 7, 2023
1 parent 618ac27 commit 26a1405
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ models:
realitio_address: ${str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57}
redeeming_batch_size: ${int:5}
slippage: ${float:0.01}
redeem_margin_days: ${int:15}
---
public_id: valory/p2p_libp2p_client:0.1.0
type: connection
Expand Down
2 changes: 2 additions & 0 deletions packages/valory/contracts/conditional_tokens/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def check_redeemed(
f"Did the creation happen too long in the past?\n"
f"The market with condition id {earliest_condition_id!r} "
f"is the oldest one and the block filtering was set based on it."
"If the issue persists, try to decrease the value of `redeem_margin_days` "
f"in the agent's configuration, based on the date corresponding to the block number {earliest_block}."
)
return dict(error=msg)

Expand Down
4 changes: 4 additions & 0 deletions packages/valory/services/trader/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type: skill
realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57}
redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:5}
slippage: ${SLIPPAGE:float:0.01}
redeem_margin_days: ${REDEEM_MARGIN_DAYS:int:15}
benchmark_tool: &id005
args:
log_dir: ${LOG_DIR:str:/benchmarks}
Expand Down Expand Up @@ -166,6 +167,7 @@ type: skill
realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57}
redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:5}
slippage: ${SLIPPAGE:float:0.01}
redeem_margin_days: ${REDEEM_MARGIN_DAYS:int:15}
benchmark_tool: *id005
2:
models:
Expand Down Expand Up @@ -227,6 +229,7 @@ type: skill
realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57}
redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:5}
slippage: ${SLIPPAGE:float:0.01}
redeem_margin_days: ${REDEEM_MARGIN_DAYS:int:15}
benchmark_tool: *id005
3:
models:
Expand Down Expand Up @@ -288,6 +291,7 @@ type: skill
realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57}
redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:5}
slippage: ${SLIPPAGE:float:0.01}
redeem_margin_days: ${REDEEM_MARGIN_DAYS:int:15}
benchmark_tool: *id005
---
public_id: valory/ledger:0.19.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
creator: "${creator}",
fpmm_: {
answerFinalizedTimestamp_not: null,
creationTimestamp_gt: "${from_timestamp}",
isPendingArbitration: false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
from packages.valory.skills.market_manager_abci.rounds import SynchronizedData


DAY_UNIX = 24 * 60 * 60


def to_content(query: str) -> bytes:
"""Convert the given query string to payload content, i.e., add it under a `queries` key and convert it to bytes."""
finalized_query = {"query": query}
Expand Down Expand Up @@ -184,7 +187,9 @@ def _fetch_redeem_info(self) -> Generator[None, None, Optional[list]]:
self._fetch_status = FetchStatus.IN_PROGRESS

safe = self.synchronized_data.safe_contract_address
query = trades.substitute(creator=safe.lower())
redeem_margin = self.params.redeem_margin_days * DAY_UNIX
from_timestamp = self.synced_time - redeem_margin
query = trades.substitute(creator=safe.lower(), from_timestamp=from_timestamp)

# workaround because we cannot have multiple response keys for a single `ApiSpec`
res_key_backup = self.current_subgraph.response_info.response_key
Expand Down
35 changes: 35 additions & 0 deletions packages/valory/skills/market_manager_abci/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
BenchmarkTool = BaseBenchmarkTool


GNOSIS_RPC_TIMEOUT_DAYS = 25


class SharedState(BaseSharedState):
"""Keep the current shared state of the skill."""

Expand Down Expand Up @@ -72,8 +75,40 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
self.languages: List[str] = self._ensure("languages", kwargs, List[str])
self.average_block_time: int = self._ensure("average_block_time", kwargs, int)
self.abt_error_mult: int = self._ensure("abt_error_mult", kwargs, int)
self._redeem_margin_days: int = 0
self.redeem_margin_days = self._ensure("redeem_margin_days", kwargs, int)
super().__init__(*args, **kwargs)

@property
def redeem_margin_days(self) -> int:
"""Get the margin in days of the redeeming information."""
return self._redeem_margin_days

@redeem_margin_days.setter
def redeem_margin_days(self, redeem_margin_days: int) -> None:
"""Get the margin in days of the redeeming information."""
value_enforcement = (
f"The value needs to be in the exclusive range (0, {GNOSIS_RPC_TIMEOUT_DAYS}) "
f"and manual redeeming has to be performed for markets older than {GNOSIS_RPC_TIMEOUT_DAYS - 1} days."
)

if redeem_margin_days <= 0:
raise ValueError(
"The margin in days for the redeeming information (`redeem_margin_days`) "
f"cannot be set to {redeem_margin_days} <= 0. {value_enforcement}"
)
if redeem_margin_days >= GNOSIS_RPC_TIMEOUT_DAYS:
raise ValueError(
"Due to a constraint of the Gnosis RPCs, it is not possible to configure the redeeming "
f"information's time window to exceed {GNOSIS_RPC_TIMEOUT_DAYS - 1} days "
f"(currently {redeem_margin_days=}). To clarify, these RPCs experience timeouts "
"when attempting to filter for historical on-chain events. "
"Practical testing of the service has revealed that timeouts consistently occur for blocks "
f"approximately {GNOSIS_RPC_TIMEOUT_DAYS} days old. {value_enforcement}"
)

self._redeem_margin_days = redeem_margin_days

@property
def creators_iterator(self) -> Iterator[Tuple[str, List[str]]]:
"""Return an iterator of market per creators."""
Expand Down
1 change: 1 addition & 0 deletions packages/valory/skills/market_manager_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ models:
- en_US
average_block_time: 5
abt_error_mult: 5
redeem_margin_days: 15
class_name: MarketManagerParams
network_subgraph:
args:
Expand Down
1 change: 1 addition & 0 deletions packages/valory/skills/trader_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ models:
realitio_address: '0x79e32aE03fb27B07C89c0c568F80287C01ca2E57'
redeeming_batch_size: 5
slippage: 0.01
redeem_margin_days: 15
class_name: TraderParams
network_subgraph:
args:
Expand Down

0 comments on commit 26a1405

Please sign in to comment.