-
-
Notifications
You must be signed in to change notification settings - Fork 108
Description
Overview
During the fix for #2214, we identified an architectural inefficiency where verify_and_store_contract() stores a contract then immediately fetches it back for validation.
Current Flow
// verify_and_store_contract() in runtime.rs
// Line 1076: We HAVE the contract
if let Some(contract) = trying_contract.take() {
// Line 1092: Store it (moves ownership)
self.runtime.contract_store.store_contract(contract)?;
}
// Line 1105: Immediately fetch it back for validation
let result = self.runtime.validate_state(&trying_key, ...)?;The validate_state() call needs the contract bytes to compile a WASM module via prepare_contract_call() → fetch_contract().
The Issue
We have the contract data in hand, give it to the store, then immediately ask the store to give it back. This required adding wait() after cache insert (#2215) because stretto uses eventual consistency and the data wasn't visible yet.
Potential Solutions
-
Pass contract to validate_state directly:
self.runtime.validate_state_with_contract(&trying_key, &contract, ...)?; self.runtime.contract_store.store_contract(contract)?;
-
Have store_contract also compile and cache the WASM module
-
Clone contract code before storing and use directly for compilation
Impact
- Performance: Minimal -
wait()is fast (just flushes buffer) - Correctness: Current fix works correctly
- Code clarity: The round-trip is architecturally awkward
Priority
Low - the current fix is correct and not performance-impacting. This is cleanup for code clarity.
Related
- Fixed in fix: wait for stretto cache insert before validation #2215
- Root cause issue GET request fails to find locally cached contract after different client's PUT #2214
[AI-assisted - Claude]
Metadata
Metadata
Assignees
Labels
Type
Projects
Status