fix(api): cap allowlist processing per cycle to prevent unbounded refresh (#92) - #158
Merged
valoryyaa-byte merged 4 commits intoJul 28, 2026
Merged
Conversation
…it#91) - Add `indexed_at_ledger: u32` and `index_error: Option<String>` to the Asset model so consumers can tell which assets are stale. - Make per-asset indexing fully best-effort: a failed get_metadata or compliance read no longer aborts the whole refresh cycle. The previous snapshot's data is re-emitted with index_error set instead. - indexed_at_ledger is taken from the latest_ledger returned by the per-asset get_metadata simulation — the tightest freshness signal available without a database. - Dividend fallback now also re-uses previous data rather than Vec::new(). Closes RWA-ToolKit#91
…rward (RWA-ToolKit#92) - Add DEFAULT_COMPLIANCE_PAGE_SIZE=50 constant (overridable via RWA_COMPLIANCE_PAGE_SIZE env var) bounding per-asset RPC work to 2 × page_size calls per refresh cycle regardless of allowlist length. - Add compliance_offsets: Arc<Mutex<HashMap<u64,usize>>> to AppState with next_compliance_offset() helper that advances the per-asset cursor and wraps back to 0 after the last page. - Rewrite index_compliance_and_holders to operate on a &[String] page slice and accept prev_summary/prev_holders for mid-scan carry-forward. - Update refresh() call-site: fetches get_allowlist once, slices to the current page, carries forward accumulated summary/holders mid-scan and resets on wrap. All failure paths use labeled-block early-exit. Closes RWA-ToolKit#92
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.
Closes #92.
Summary
A single asset with a very large compliance allowlist could make one refresh cycle take arbitrarily long, delaying all other assets. This change caps the allowlist work per asset per cycle and spreads the remainder across subsequent cycles.
Changes
DEFAULT_COMPLIANCE_PAGE_SIZE = 50constant (configurable viaRWA_COMPLIANCE_PAGE_SIZEenv var). Each address costs 2 RPC calls (get_record+balance), bounding the per-cycle budget to2 × page_sizeper asset regardless of allowlist size.compliance_offsets: Arc<Mutex<HashMap<u64, usize>>>onAppStateto persist each asset's position across cycles. The offset advances bypage_sizeeach cycle and wraps to 0 at the end, ensuring the full list is always covered over time.next_compliance_offset()helper that atomically reads, advances, and wraps the offset.index_compliance_and_holdersto accept apage: &[String]slice plusprev_summary/prev_holdersfor incremental mid-scan merging. On wrap, stale accumulated data is discarded to prevent count drift.