Skip to content

feat(store): cache account witnesses for tracked accounts - #2476

Open
sofiazcoaga wants to merge 5 commits into
0xMiden:nextfrom
sofiazcoaga:feat/cache-account-witnesses
Open

feat(store): cache account witnesses for tracked accounts#2476
sofiazcoaga wants to merge 5 commits into
0xMiden:nextfrom
sofiazcoaga:feat/cache-account-witnesses

Conversation

@sofiazcoaga

@sofiazcoaga sofiazcoaga commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Problem

Every FPI transaction fetches the foreign account's AccountWitness from the node. N transactions between two syncs cost N GetAccount requests, even against the same account at the same block.

Changes

  1. Client::track_account_witness registers an account whose account witness should be kept fresh. New account_witnesses table, one row per account.
  2. Every sync refreshes them at the new sync height, up to four requests in flight. Each witness is validated against the synced block header's account root before it is stored.
  3. The sync reuses the witnesses it already validated while fetching public account state, so a registered account that changed in that window costs one request, not two.
  4. Building a transaction, a registered foreign account resolves from the store instead of the network: a private one takes the cached witness, a public one the client tracks builds its whole AccountInputs locally. Both fall back to the existing request when there is nothing usable.

The cost moves from once per transaction to once per sync.

Closes #2443

@sofiazcoaga
sofiazcoaga marked this pull request as draft September 1, 2026 13:34
@sofiazcoaga

Copy link
Copy Markdown
Contributor Author

@igamigo the issue mentions "we should also keep account witnesses for watched accounts, which we already request anyway", but I deliberately did not add watched accounts to account witness fetching automatically. Watched accounts are only refetched during sync when they have been modified, so for an unmodified one there is no request to reuse. Automatically tracking their account witnesses would mean an RPC call for every watched account on every sync, so a client watching N accounts for observability would pay N extra requests per sync. I believe this should be a conscious decision. Let me know your thoughts on this.

@sofiazcoaga
sofiazcoaga marked this pull request as ready for review September 1, 2026 21:35
@sofiazcoaga
sofiazcoaga requested review from TomasArrachea, igamigo and juan518munoz and removed request for igamigo and juan518munoz September 3, 2026 13:46
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.

Cache account witnesses

1 participant