From c96b38767ffb301340870b8eba3f5c53ef7d2695 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Tue, 21 Nov 2023 15:55:36 +0200 Subject: [PATCH] feat: persist batch size --- .../skills/decision_maker_abci/behaviours/reedem.py | 6 ++++-- packages/valory/skills/decision_maker_abci/models.py | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/valory/skills/decision_maker_abci/behaviours/reedem.py b/packages/valory/skills/decision_maker_abci/behaviours/reedem.py index 3ed07989d..1368fb5bb 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/reedem.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/reedem.py @@ -426,7 +426,7 @@ def _check_already_redeemed(self) -> WaitableConditionType: n_retries = 0 from_block = self.redeeming_progress.check_from_block - batch_size = self.params.event_filtering_batch_size + batch_size = self.redeeming_progress.event_filtering_batch_size while from_block < self.redeeming_progress.check_to_block: max_to_block = from_block + batch_size to_block = min(max_to_block, self.redeeming_progress.check_to_block) @@ -449,6 +449,7 @@ def _check_already_redeemed(self) -> WaitableConditionType: n_retries += 1 keep_fraction = (1 - self.params.reduce_factor) ** n_retries batch_size = int(self.params.event_filtering_batch_size * keep_fraction) + self.redeeming_progress.event_filtering_batch_size = batch_size self.context.logger.warning( f"Repeating this call with a decreased batch size of {batch_size}." ) @@ -564,7 +565,7 @@ def get_claim_params(self) -> WaitableConditionType: n_retries = 0 from_block = self.redeeming_progress.claim_from_block - batch_size = self.params.event_filtering_batch_size + batch_size = self.redeeming_progress.event_filtering_batch_size while from_block < self.redeeming_progress.claim_to_block: max_to_block = from_block + batch_size to_block = min(max_to_block, self.redeeming_progress.claim_to_block) @@ -586,6 +587,7 @@ def get_claim_params(self) -> WaitableConditionType: n_retries += 1 keep_fraction = (1 - self.params.reduce_factor) ** n_retries batch_size = int(self.params.event_filtering_batch_size * keep_fraction) + self.redeeming_progress.event_filtering_batch_size = batch_size self.context.logger.warning( f"Repeating this call with a decreased batch size of {batch_size}." ) diff --git a/packages/valory/skills/decision_maker_abci/models.py b/packages/valory/skills/decision_maker_abci/models.py index 8863d600c..35df1bb2e 100644 --- a/packages/valory/skills/decision_maker_abci/models.py +++ b/packages/valory/skills/decision_maker_abci/models.py @@ -81,6 +81,7 @@ class RedeemingProgress: policy: Optional[EGreedyPolicy] = None claimable_amounts: Dict[HexBytes, int] = field(default_factory=lambda: {}) earliest_block_number: int = 0 + event_filtering_batch_size: int = 0 check_started: bool = False check_from_block: BlockIdentifier = "earliest" check_to_block: BlockIdentifier = "latest" @@ -139,6 +140,13 @@ def __init__(self, *args: Any, skill_context: SkillContext, **kwargs: Any) -> No super().__init__(*args, skill_context=skill_context, **kwargs) self.redeeming_progress: RedeemingProgress = RedeemingProgress() + def setup(self) -> None: + """Set up the model.""" + super().setup() + self.redeeming_progress.event_filtering_batch_size = ( + self.context.params.event_filtering_batch_size + ) + def extract_keys_from_template(delimiter: str, template: str) -> Set[str]: """Extract the keys from a string template, given the delimiter."""