Skip to content

Commit f1f403c

Browse files
store: Do not cache calls that return 0x
Signed-off-by: Maksim Dimitrov <[email protected]>
1 parent a675c22 commit f1f403c

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

store/postgres/src/chain_store.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2839,13 +2839,20 @@ impl EthereumCallCache for ChainStore {
28392839
block: BlockPtr,
28402840
return_value: call::Retval,
28412841
) -> Result<(), Error> {
2842-
let call::Retval::Value(return_value) = return_value else {
2843-
// We do not want to cache unsuccessful calls as some RPC nodes
2844-
// have weird behavior near the chain head. The details are lost
2845-
// to time, but we had issues with some RPC clients in the past
2846-
// where calls first failed and later succeeded
2847-
return Ok(());
2842+
let return_value = match return_value {
2843+
call::Retval::Value(return_value) if !return_value.is_empty() => return_value,
2844+
_ => {
2845+
// We do not want to cache unsuccessful calls as some RPC nodes
2846+
// have weird behavior near the chain head. The details are lost
2847+
// to time, but we had issues with some RPC clients in the past
2848+
// where calls first failed and later succeeded
2849+
// Also in some cases RPC nodes may return empty ("0x") values
2850+
// which in the context of graph-node most likely means an issue
2851+
// with the RPC node rather than a successful call.
2852+
return Ok(());
2853+
}
28482854
};
2855+
28492856
let id = contract_call_id(&call, &block);
28502857
let conn = &mut *self.get_conn()?;
28512858
conn.transaction(|conn| {

store/test-store/tests/postgres/chain_head.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ fn eth_call_cache() {
475475
.unwrap();
476476
assert_eq!(&new_return_value, ret.as_slice());
477477

478+
// Reverted calls should not be cached
478479
store
479480
.set_call(
480481
&logger,
@@ -486,6 +487,19 @@ fn eth_call_cache() {
486487
let ret = store.get_call(&call, BLOCK_THREE.block_ptr()).unwrap();
487488
assert_eq!(None, ret);
488489

490+
// Empty return values should not be cached
491+
let return_value: [u8; 0] = [];
492+
store
493+
.set_call(
494+
&logger,
495+
call.cheap_clone(),
496+
BLOCK_FOUR.block_ptr(),
497+
ccr(&return_value),
498+
)
499+
.unwrap();
500+
let ret = store.get_call(&call, BLOCK_FOUR.block_ptr()).unwrap();
501+
assert_eq!(None, ret);
502+
489503
Ok(())
490504
})
491505
}

0 commit comments

Comments
 (0)