Cache osToken processed shares#734
Open
evgeny-stakewise wants to merge 16 commits into
Open
Conversation
| os_token_positions=os_token_positions, | ||
| converter=os_token_converter, | ||
| tree_nonce=prev_nonce, | ||
| nonce=nonce, |
Contributor
Author
There was a problem hiding this comment.
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.
Contributor
Author
There was a problem hiding this comment.
I'm doing 'nonce - 1' right before merkle leaf calculation.
Contributor
There was a problem hiding this comment.
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.pywith 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 - 1for leaf hashing/proofs). - Add/adjust tests for iterators and cache behavior; add network config for the redeemer “genesis” block; add
aioitertoolsdependency.
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_nonce → nonce) 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.