Skip to content

Commit

Permalink
feat: persist batch size
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamantios committed Nov 21, 2023
1 parent 98fd842 commit c96b387
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}."
)
Expand Down Expand Up @@ -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)
Expand All @@ -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}."
)
Expand Down
8 changes: 8 additions & 0 deletions packages/valory/skills/decision_maker_abci/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit c96b387

Please sign in to comment.