Skip to content

Commit

Permalink
Cache default value after failed request in ForkStateReader (#2857)
Browse files Browse the repository at this point in the history
<!-- 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 <45050160+ddoktorski@users.noreply.github.com>
  • Loading branch information
franciszekjob and ddoktorski authored Jan 20, 2025
1 parent 5306b43 commit 1de8ca3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/cheatnet/src/forking/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ impl StateReader for ForkStateReader {
Ok(value_sf)
}
Err(ProviderError::Other(boxed)) => other_provider_error(boxed),
Err(ProviderError::StarknetError(StarknetError::ContractNotFound)) => Ok(Default::default()),
Err(ProviderError::StarknetError(StarknetError::ContractNotFound)) => {
self.cache.borrow_mut().cache_get_storage_at(
contract_address,
key,
Felt::default(),
);
Ok(Felt::default())
},
Err(x) => Err(StateReadError(format!(
"Unable to get storage at address: {contract_address:?} and key: {key:?} from fork ({x})"
))),
Expand All @@ -159,6 +166,9 @@ impl StateReader for ForkStateReader {
}
Err(ProviderError::Other(boxed)) => other_provider_error(boxed),
Err(ProviderError::StarknetError(StarknetError::ContractNotFound)) => {
self.cache
.borrow_mut()
.cache_get_nonce_at(contract_address, Default::default());
Ok(Default::default())
}
Err(x) => Err(StateReadError(format!(
Expand All @@ -184,6 +194,9 @@ impl StateReader for ForkStateReader {
Ok(class_hash)
}
Err(ProviderError::StarknetError(StarknetError::ContractNotFound)) => {
self.cache
.borrow_mut()
.cache_get_class_hash_at(contract_address, Default::default());
Ok(Default::default())
}
Err(ProviderError::Other(boxed)) => other_provider_error(boxed),
Expand Down

0 comments on commit 1de8ca3

Please sign in to comment.