Skip to content

feat: cache last discovered signature to avoid re-fetching transactions#156

Draft
lpahlavi wants to merge 2 commits intolpahlavi/defi-2780-exponential-backoff-pollingfrom
lpahlavi/defi-2780-cache-fetched-slot
Draft

feat: cache last discovered signature to avoid re-fetching transactions#156
lpahlavi wants to merge 2 commits intolpahlavi/defi-2780-exponential-backoff-pollingfrom
lpahlavi/defi-2780-cache-fetched-slot

Conversation

@lpahlavi
Copy link
Copy Markdown
Contributor

@lpahlavi lpahlavi commented Apr 20, 2026

Summary

  • Adds last_discovered_signature: Option<Signature> to AutomaticDepositCacheEntry, storing the most recent transaction signature seen for each monitored address
  • Passes this signature as the until parameter to subsequent getSignaturesForAddress calls, so only transactions newer than the last seen one are returned
  • Moves the CBOR codecs from state/event/cbor to utils/cbor to make them reusable across the codebase
  • Extends the signature codec with an option sub-module for Option<Signature> encoding
  • Adds round-trip property tests for Option<Signature> CBOR encoding

Depends on #157.

Test plan

  • cargo test --locked --workspace --exclude cksol-int-tests passes
  • None and Some(signature) round-trip correctly via the CBOR option codec
  • getSignaturesForAddress calls receive the correct until parameter after the first poll

🤖 Generated with Claude Code

@lpahlavi lpahlavi force-pushed the lpahlavi/defi-2780-poll-deposit-addresses branch 2 times, most recently from 6c2a4f6 to 524f299 Compare April 20, 2026 15:05
lpahlavi added a commit that referenced this pull request Apr 21, 2026
Replace the separate PollEntry/POLL_SCHEDULE map with a single
AutomaticDepositCache struct per account, mirroring the cache design
from #156. The cache stores next_poll_at (Option<u64>, None when
monitoring has stopped) and checks_done, and is retained after
monitoring stops so future PRs can add fields without losing state.

The cache map moves to storage/mod.rs alongside the event log, with
read/write_automatic_deposit_cache accessors. Poll scheduling logic
stays in deposit/automatic/mod.rs using the cache.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Base automatically changed from lpahlavi/defi-2780-poll-deposit-addresses to main April 21, 2026 12:22
Copilot AI review requested due to automatic review settings April 22, 2026 09:04
@lpahlavi lpahlavi force-pushed the lpahlavi/defi-2780-cache-fetched-slot branch from a3c5d73 to 151d64c Compare April 22, 2026 09:04
@lpahlavi lpahlavi changed the title feat: cache deposit signatures and enforce quota per account feat: cache last discovered signature to avoid re-fetching transactions Apr 22, 2026
@lpahlavi lpahlavi changed the base branch from main to lpahlavi/defi-2780-exponential-backoff-polling April 22, 2026 09:05
@lpahlavi lpahlavi force-pushed the lpahlavi/defi-2780-cache-fetched-slot branch from 151d64c to e4e947f Compare April 22, 2026 09:14
…actions

Store the most recent `getSignaturesForAddress` result in the deposit
cache and pass it as the `until` parameter on subsequent calls, so that
only new transactions are returned.

Also moves the CBOR codecs from `state/event/cbor` to `utils/cbor`
(making them reusable), extends the signature codec with an `option`
variant, adds round-trip tests for `Option<Signature>` encoding, and
adds `update_index` to `StableSortKeyMap` for rescheduling existing
entries.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lpahlavi lpahlavi force-pushed the lpahlavi/defi-2780-cache-fetched-slot branch from 3915d07 to c419aa4 Compare April 22, 2026 09:22
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

With a fixed limit, a single call may not return all transactions in the
range (e.g., B at slot 101 is missed when the batch fills up with D and C).

Add `page_cursor` to `AutomaticDepositCacheEntry`:
- New scan (page_cursor = None): call with before=None, until=last_discovered.
  Record first() as the new last_discovered; set page_cursor=last() if full.
- Continuing (page_cursor = Some): call with before=cursor, until=None.
  No lower bound is needed since the call budget limits scan depth.
  Clear page_cursor when the batch is smaller than the limit.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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