fix(tip403): resolve policyIdCounter from L1 instead of cache#508
Open
CrytoInsight wants to merge 1 commit into
Open
fix(tip403): resolve policyIdCounter from L1 instead of cache#508CrytoInsight wants to merge 1 commit into
CrytoInsight wants to merge 1 commit into
Conversation
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.
fix(tip403): resolve policyIdCounter from L1 instead of cache
Description
The TIP-403 proxy precompile is meant to be a faithful in-zone mirror of the L1
registry: when a contract running inside the zone calls a read method, the proxy
answers with what L1 would say. Almost every read honors that contract — on a
cache miss it falls back to an L1 RPC call.
policyIdCounter()was theexception.
Instead of asking L1,
PolicyProvider::policy_id_counterderived its answerfrom the cache, returning
max(observed policy id) + 1. The problem is that thecache only contains policies the zone has actually seen events for. Any policy
that was created before the subscriber came online, or that no tracked token
ever referenced, simply isn't there. So the highest cached id is only a lower
bound on the real counter, and the proxy could confidently hand back a value
below L1's authoritative
policyIdCounter— a silent disagreement with L1 thatnothing else in the proxy exhibits.
The fix brings this read in line with the rest of the proxy. It now queries the
registry's
policyIdCounter()on L1, pinned tolast_l1_blockso the answer isdeterministic and identical across nodes (the same anchoring the other reads
already use). The cache-derived lower bound survives only as a fallback for when
the RPC itself fails. Mechanically it follows the existing
policy_exists_syncshape:
block_in_place+block_onaround the call.I added two tests next to the provider: one feeds a mocked L1 response and
checks the authoritative value is returned; the other leaves the mock empty so
the RPC errors, and checks we fall back to the cache-derived bound. Both pass,
alongside clean clippy and fmt runs.