perf(contracts): introduce shared TransactionCache and apply it to Bridge routing + credit profiles; enforce crowdfunding investment cap - #886
Merged
Conversation
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
|
@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! 🚀 |
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.
Summary
Introduces a reusable intra-transaction caching primitive (
TransactionCache) andwires it into two hot paths — cross-chain route evaluation in
Bridgeandcredit-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
contracts/common/src/cache.rs:TransactionCache<K, V>, a BTreeMap-backedlocal cache scoped to a single message/transaction, avoiding repeated full state
reads for the same key (Local intra-transaction caching abstraction for ink! Multi-read paths #815).
Bridge: maintainroute_cache: Mapping<(FromChain, ToChain, BlockNumber), RouteEstimate>,built on
TransactionCache, so repeated re-routing to hot destination chains isamortized instead of re-resolved (Cache cross-chain route evaluations in Bridge #814).
payment/default state-change events, instead of eagerly on every call (Lazy credit-profile recomputation #817).
max_investment_per_address: u128per campaign and gateinveston it, closing the enforcement TODO atlib.rs:1227(Resolve the crowdfundingTODO: Store max investment per campaign#816).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
TransactionCache(hit/miss/invalidate).Closes #814,
Closes #815,
Closes #816,
Closes #817