Skip to content

Commit 1de8ca3

Browse files
Cache default value after failed request in ForkStateReader (#2857)
<!-- Reference any GitHub issues resolved by this PR --> Closes #2849 ## Introduced changes <!-- A brief description of the changes --> Update the logic of `ForkStateReader` - if we receive `StarknetError::ContractNotFound`, we additionaly cache such request. ## Checklist <!-- Make sure all of these are complete --> - [x] Linked relevant issue - [x] Updated relevant documentation - [x] Added relevant tests - [x] Performed self-review of the code - [x] Added changes to `CHANGELOG.md` --------- Co-authored-by: ddoktorski <[email protected]>
1 parent 5306b43 commit 1de8ca3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

crates/cheatnet/src/forking/state.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,14 @@ impl StateReader for ForkStateReader {
134134
Ok(value_sf)
135135
}
136136
Err(ProviderError::Other(boxed)) => other_provider_error(boxed),
137-
Err(ProviderError::StarknetError(StarknetError::ContractNotFound)) => Ok(Default::default()),
137+
Err(ProviderError::StarknetError(StarknetError::ContractNotFound)) => {
138+
self.cache.borrow_mut().cache_get_storage_at(
139+
contract_address,
140+
key,
141+
Felt::default(),
142+
);
143+
Ok(Felt::default())
144+
},
138145
Err(x) => Err(StateReadError(format!(
139146
"Unable to get storage at address: {contract_address:?} and key: {key:?} from fork ({x})"
140147
))),
@@ -159,6 +166,9 @@ impl StateReader for ForkStateReader {
159166
}
160167
Err(ProviderError::Other(boxed)) => other_provider_error(boxed),
161168
Err(ProviderError::StarknetError(StarknetError::ContractNotFound)) => {
169+
self.cache
170+
.borrow_mut()
171+
.cache_get_nonce_at(contract_address, Default::default());
162172
Ok(Default::default())
163173
}
164174
Err(x) => Err(StateReadError(format!(
@@ -184,6 +194,9 @@ impl StateReader for ForkStateReader {
184194
Ok(class_hash)
185195
}
186196
Err(ProviderError::StarknetError(StarknetError::ContractNotFound)) => {
197+
self.cache
198+
.borrow_mut()
199+
.cache_get_class_hash_at(contract_address, Default::default());
187200
Ok(Default::default())
188201
}
189202
Err(ProviderError::Other(boxed)) => other_provider_error(boxed),

0 commit comments

Comments
 (0)