Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions store/postgres/src/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2839,13 +2839,20 @@ impl EthereumCallCache for ChainStore {
block: BlockPtr,
return_value: call::Retval,
) -> Result<(), Error> {
let call::Retval::Value(return_value) = return_value else {
// We do not want to cache unsuccessful calls as some RPC nodes
// have weird behavior near the chain head. The details are lost
// to time, but we had issues with some RPC clients in the past
// where calls first failed and later succeeded
return Ok(());
let return_value = match return_value {
call::Retval::Value(return_value) if !return_value.is_empty() => return_value,
_ => {
// We do not want to cache unsuccessful calls as some RPC nodes
// have weird behavior near the chain head. The details are lost
// to time, but we had issues with some RPC clients in the past
// where calls first failed and later succeeded
// Also in some cases RPC nodes may return empty ("0x") values
// which in the context of graph-node most likely means an issue
// with the RPC node rather than a successful call.
return Ok(());
}
};

let id = contract_call_id(&call, &block);
let conn = &mut *self.get_conn()?;
conn.transaction(|conn| {
Expand Down
14 changes: 14 additions & 0 deletions store/test-store/tests/postgres/chain_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ fn eth_call_cache() {
.unwrap();
assert_eq!(&new_return_value, ret.as_slice());

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

// Empty return values should not be cached
let return_value: [u8; 0] = [];
store
.set_call(
&logger,
call.cheap_clone(),
BLOCK_FOUR.block_ptr(),
ccr(&return_value),
)
.unwrap();
let ret = store.get_call(&call, BLOCK_FOUR.block_ptr()).unwrap();
assert_eq!(None, ret);

Ok(())
})
}
Expand Down
Loading