Skip to content

Cache common derived state (program balance, fee config) across query_* function chains #1382

Description

@Jagadeeshftw

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

Metadata

Metadata

Assignees

Labels

Smart-ContractSoroban/Rust smart contract workStellar WaveIssues in the Stellar wave programenhancementNew feature or improvementgas-optimizationGas / storage optimization

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions