Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache only correct eth_call data #4879

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

SozinM
Copy link
Contributor

@SozinM SozinM commented Sep 19, 2023

This PR closes #4756
It changes caching logic to cache only correct and decodable eth_calls to prevent cache from providing faulty data

});
result.0
}),
.map(move |result| result.0),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like this could take a bit of refactoring, but I'm not sure it's possible to make it more nice looking

@@ -1276,7 +1276,8 @@ impl EthereumAdapterTrait for EthereumAdapter {
"block_hash" => call.block_ptr.hash_hex(),
"block_number" => call.block_ptr.block_number()
);

let cache_logger = logger.clone();
let cache = cache.clone();
Copy link
Contributor Author

@SozinM SozinM Sep 22, 2023

Choose a reason for hiding this comment

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

I would like to move it to inner scope, but I cannot wrap my head on how to correctly clone it in and_then future.

EthereumContractCallError::Revert(format!("failed to decode output: {}", e))
})
});
let _ = graph::spawn_blocking_allow_panic(move || {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I could move it to dedicated and_then future using https://docs.rs/futures-async-combinators/latest/futures_async_combinators/future/fn.and_then.html
But I didn't see it usage in the graph so I'm hesitant to add this

@fordN fordN requested a review from mangas September 26, 2023 15:41
Copy link
Collaborator

@lutter lutter left a comment

Choose a reason for hiding this comment

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

First off, congrats on making it through this code - it's really gnarly and would hugely benefit from asyncifying (though that might be quite a bit of an undertaking)

Before merging this, we need to find a way to not call set_call for calls that are already in the cache as that will have a bad effect on performance.

"error" => e.to_string())
})
});
return result;
Copy link
Collaborator

@lutter lutter Oct 23, 2023

Choose a reason for hiding this comment

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

As I understand it, this will always call set_call, even if we got the result from the cache, i.e., it's not necessary to cache it again. Why don't you just put the spawn_blocking_allow_panic in the existing code in the None branch into an if !result.0.is_empty() { .. } ? That will suppress caching these calls and the error will still be generated later in the and_then

@azf20
Copy link
Contributor

azf20 commented Nov 13, 2023

hey @SozinM, thanks so much for this PR! Did you manage to take a look at David's comments?

@SozinM
Copy link
Contributor Author

SozinM commented Nov 24, 2023

Hi!
Yes, I did saw
I will fix them once I return to work (in dec)

@SozinM
Copy link
Contributor Author

SozinM commented Dec 11, 2023

Hi @lutter , @azf20
It did take some time to come back to this :)
I followed @lutter suggestion and made the check near initial cache thread spawn.

@leoyvens leoyvens added the ops Relevant to Graph Node Ops label Jan 4, 2024
@leoyvens leoyvens merged commit 8c6edc1 into graphprotocol:master Jan 4, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ops Relevant to Graph Node Ops
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Do not cache invalid eth_call results in case node returned invalid results.
4 participants