Skip to content

fix(tip403): cache policy id counter#515

Open
mattsse wants to merge 1 commit into
mainfrom
mattsse/cache-tip403-policy-counter
Open

fix(tip403): cache policy id counter#515
mattsse wants to merge 1 commit into
mainfrom
mattsse/cache-tip403-policy-counter

Conversation

@mattsse

@mattsse mattsse commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Seed the TIP-403 policyIdCounter into PolicyCache during node startup.
  • Store the cached counter as Option<u64> so an unseeded cache remains explicitly unknown.
  • On policyIdCounter() cache miss, fetch the authoritative value from L1 at last_l1_block, cache it, and return it.
  • Keep policy record observations separate from counter updates so cached policy IDs do not become a lower-bound counter substitute.
  • Prevent delayed seed/RPC results from regressing a newer cached counter.
  • Serve subsequent PolicyCheck::policy_id_counter() calls from local cache state.

Root Cause

The previous implementation derived policyIdCounter() from max(cached policy id) + 1, but the policy cache can be missing policies that exist on L1. That makes the derived value only a lower bound. Keeping the authoritative value in the cache fixes the undercount without putting an L1 RPC call on every zone precompile invocation.

Impact

Contracts calling the zone TIP-403 proxy get a locally served counter after startup seeding or the first cache-miss fallback. If the counter is genuinely unknown, the proxy fetches it once from L1 and stores it for future calls instead of fabricating 2 or performing network IO every time.

@mattsse mattsse requested a review from 0xKitsune as a code owner June 24, 2026 11:03
@mattsse mattsse force-pushed the mattsse/cache-tip403-policy-counter branch 5 times, most recently from 93b735e to 5ef8730 Compare June 24, 2026 11:53
@mattsse mattsse force-pushed the mattsse/cache-tip403-policy-counter branch from 5ef8730 to c5d4d04 Compare June 24, 2026 11:55
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.

1 participant