Description
Read-only query functions in contracts/view-facade/src/lib.rs and contracts/escrow-view-facade/src/lib.rs call into contracts/program-escrow/src/lib.rs multiple times per transaction to fetch ProgramData and FeeConfig, each incurring a separate storage read cost. Introducing a per-invocation cache (using a RefCell<HashMap<u64, ProgramData>> or Soroban's temporary storage) to memoize reads within a single call chain would reduce redundant ledger I/O.
Requirements and context
- Add a
QueryCache struct using Soroban temporary storage in contracts/view-facade/src/lib.rs
- Wrap all
ProgramData and FeeConfig reads through QueryCache::get_or_load
- Benchmark before/after instruction counts in
docs/query-cache-benchmark.md
- Must be secure, tested, and documented
- Should be efficient and easy to review
Suggested execution
Fork the repo and create a branch
git checkout -b feature/query-cache-program-balance-fee-config
Implement changes
- Update/Write contract:
contracts/view-facade/src/lib.rs
- Write comprehensive tests:
contracts/view-facade/src/tests/query_cache_tests.rs
- Add documentation:
docs/query-cache-benchmark.md
- Include NatSpec-style doc comments
- Validate security assumptions
Test and commit
- Run tests:
cargo test -p view-facade
- Cover edge cases
- Include test output and security notes
Example commit message
perf: add per-invocation query cache for ProgramData and FeeConfig reads
Guidelines
- Minimum 95 percent test coverage
- Clear documentation
- Timeframe: 96 hours
Description
Read-only query functions in
contracts/view-facade/src/lib.rsandcontracts/escrow-view-facade/src/lib.rscall intocontracts/program-escrow/src/lib.rsmultiple times per transaction to fetchProgramDataandFeeConfig, each incurring a separate storage read cost. Introducing a per-invocation cache (using aRefCell<HashMap<u64, ProgramData>>or Soroban's temporary storage) to memoize reads within a single call chain would reduce redundant ledger I/O.Requirements and context
QueryCachestruct using Soroban temporary storage incontracts/view-facade/src/lib.rsProgramDataandFeeConfigreads throughQueryCache::get_or_loaddocs/query-cache-benchmark.mdSuggested execution
Fork the repo and create a branch
Implement changes
contracts/view-facade/src/lib.rscontracts/view-facade/src/tests/query_cache_tests.rsdocs/query-cache-benchmark.mdTest and commit
cargo test -p view-facadeExample commit message
Guidelines