Skip to content

Cache osToken processed shares#734

Open
evgeny-stakewise wants to merge 16 commits into
v5-releasefrom
cache-positions
Open

Cache osToken processed shares#734
evgeny-stakewise wants to merge 16 commits into
v5-releasefrom
cache-positions

Conversation

@evgeny-stakewise
Copy link
Copy Markdown
Contributor

No description provided.

os_token_positions=os_token_positions,
converter=os_token_converter,
tree_nonce=prev_nonce,
nonce=nonce,
Copy link
Copy Markdown
Contributor Author

@evgeny-stakewise evgeny-stakewise May 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pass the original nonce (not the previous nonce) everywhere, so cache.is_valid(nonce) compares against the same nonce it read from the contract.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm doing 'nonce - 1' right before merkle leaf calculation.

Comment thread src/redemptions/fetch_positions.py
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a processed-shares cache for OsToken redemption flows to reduce repeated on-chain calls and refactors redemption position fetching/processed-shares iteration into a dedicated module.

Changes:

  • Add src/redemptions/fetch_positions.py with IPFS position fetching, batched processed-shares iteration, and a singleton processed-shares cache (with update/validation logic).
  • Refactor redemption tasks and redeemer command to use the new cache/iterators and pass the contract nonce directly (internally using nonce - 1 for leaf hashing/proofs).
  • Add/adjust tests for iterators and cache behavior; add network config for the redeemer “genesis” block; add aioitertools dependency.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/redemptions/tests/test_tasks.py Updates tests to patch the new iterator/cached iterator and adds tests for iterators/cache helpers.
src/redemptions/tests/test_cache.py New unit tests for ProcessedSharesCache.is_valid_on() and update_processed_shares_cache().
src/redemptions/tests/conftest.py Autouse fixture to reset the singleton cache between tests.
src/redemptions/tasks.py Switches cutoff logic to async iteration over cached processed shares; makes block_number required.
src/redemptions/fetch_positions.py New module implementing the cache, cache updater, iterator, and IPFS position fetcher.
src/config/networks.py Adds OS_TOKEN_REDEEMER_GENESIS_BLOCK to network configs for log scanning.
src/common/contracts.py Adds event query helper and a multicall helper for leaf-to-processed-shares.
src/commands/tests/test_internal/test_process_redeemer.py Updates naming (tree_noncenonce) and patches the new cache updater.
src/commands/internal/process_redeemer.py Uses new fetch/cache functions; passes current nonce and computes nonce - 1 internally for proofs.
pyproject.toml Adds aioitertools dependency.
poetry.lock Locks aioitertools dependency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/redemptions/fetch_positions.py
Comment thread src/common/contracts.py
@evgeny-stakewise evgeny-stakewise changed the base branch from v5-release to hard-code-vals-num May 27, 2026 18:01
@evgeny-stakewise evgeny-stakewise changed the base branch from hard-code-vals-num to v5-release May 28, 2026 08:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.

Comment thread src/redemptions/typings.py Outdated
Comment thread src/redemptions/tasks.py
Comment thread pyproject.toml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants