Skip to content

perf(contracts): introduce shared TransactionCache and apply it to Bridge routing + credit profiles; enforce crowdfunding investment cap - #886

Merged
nanaf6203-bit merged 1 commit into
MettaChain:mainfrom
gloriaelishahabu:main
Jul 29, 2026
Merged

perf(contracts): introduce shared TransactionCache and apply it to Bridge routing + credit profiles; enforce crowdfunding investment cap#886
nanaf6203-bit merged 1 commit into
MettaChain:mainfrom
gloriaelishahabu:main

Conversation

@gloriaelishahabu

@gloriaelishahabu gloriaelishahabu commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Introduces a reusable intra-transaction caching primitive (TransactionCache) and
wires it into two hot paths — cross-chain route evaluation in Bridge and
credit-profile recomputation — eliminating redundant state reads/recomputes within
a single call. Also closes an outstanding TODO in the crowdfunding contract by
enforcing a per-address max investment cap.

Changes

Why

Three of these are performance issues (redundant state reads/recomputation on
hot paths); the fourth (#816) is a compliance/security gap where investment caps
were documented but never enforced. Bundled here for cross-comparison purposes.

Testing

  • Unit tests for TransactionCache (hit/miss/invalidate).
  • Bridge route_cache: repeated route resolution within one tx hits cache.
  • Credit profile: recompute only fires on relevant events, not every read.
  • Crowdfunding: invest() reverts once max_investment_per_address is exceeded.

Closes #814,
Closes #815,
Closes #816,
Closes #817

Refs MettaChain#815

feat(bridge): cache cross-chain route evaluations via route_cache

Backed by common::TransactionCache; amortizes repeated gas/route
resolution for hot destination chains.

Refs MettaChain#814

perf(credit): lazily recompute credit profile on state-change events

Replaces eager per-call recomputation with cached profile,
invalidated only on payment/default events.

Refs MettaChain#817

fix(crowdfunding): enforce max_investment_per_address per campaign

Adds max_investment_per_address: u128 and gates invest() on it,
resolving the TODO at lib.rs:1227.

Refs MettaChain#816
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@gloriaelishahabu Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@nanaf6203-bit nanaf6203-bit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nanaf6203-bit
nanaf6203-bit merged commit 0db08a4 into MettaChain:main Jul 29, 2026
2 checks 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

2 participants