Skip to content

refactor: reduce redundant storage reads in record_usage validation#63

Merged
mikewheeleer merged 1 commit into
Agentpay-Org:mainfrom
Baskarayelu:refactor/contracts-30-record-usage-reads
Jun 24, 2026
Merged

refactor: reduce redundant storage reads in record_usage validation#63
mikewheeleer merged 1 commit into
Agentpay-Org:mainfrom
Baskarayelu:refactor/contracts-30-record-usage-reads

Conversation

@Baskarayelu

Copy link
Copy Markdown
Contributor

Summary

Tightens and documents the validation chain in record_usage (contracts/escrow/src/lib.rs). This is a clarity/robustness refactor — the public API and all validation semantics and error precedence are unchanged.

Closes #30

What changed

  • Added a documented comment block at the top of the validation chain spelling out the fixed error precedence:
    Paused(#4) -> ZeroRequests(#2) -> Max(#8) -> Min(#9) -> Registration(#7) -> Disabled(#12) -> Allowlist(#10).
  • Annotated each conditional read so the gating is explicit:
    • ServiceRegistered is only read when RequireServiceRegistration is true (short-circuited via &&).
    • AgentAllowed is only read when AllowlistEnabled is true (short-circuited via &&).
  • Confirmed that the max/min caps are cached in locals (read once, compared once) and that the usage counter is read exactly once. No value is read twice.

Read-count note (honest before/after)

The worst-case storage read count is unchanged — this PR does not remove any read. What it does:

  • Confirms the two conditional reads (ServiceRegistered, AgentAllowed) were already correctly gated behind their controlling flags, so they never execute when those flags are off, and keeps that short-circuit.
  • Documents the read order and gating inline so future edits do not accidentally promote a gated read to an unconditional one or reorder the precedence.
  • The always-on reads (Paused, MaxRequestsPerCall, MinRequestsPerCall, ServiceDisabled) are unavoidable gates and remain; max/min remain cached in locals.

No reductions are claimed beyond confirming and preserving the existing conditional gating and local caching.

Security notes

Tests

test result: ok. 63 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mikewheeleer mikewheeleer merged commit 62c860b into Agentpay-Org:main Jun 24, 2026
1 check passed
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.

Reduce redundant storage reads in record_usage's validation chain

2 participants