Skip to content

Commit 0555087

Browse files
committed
Add warning logs on block deserialization failures
1 parent 8e85f3a commit 0555087

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

chain/ethereum/src/chain.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,13 +1036,26 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
10361036
offset: BlockNumber,
10371037
root: Option<BlockHash>,
10381038
) -> Result<Option<BlockFinality>, Error> {
1039+
let ptr_for_log = ptr.clone();
10391040
let block: Option<EthereumBlock> = self
10401041
.chain_store
10411042
.cheap_clone()
10421043
.ancestor_block(ptr, offset, root)
10431044
.await?
1044-
.map(|x| x.0)
1045-
.map(json::from_value)
1045+
.map(|(json_value, block_ptr)| {
1046+
json::from_value(json_value.clone()).map_err(|e| {
1047+
warn!(
1048+
self.logger,
1049+
"Failed to deserialize cached ancestor block {} (offset {} from {}): {}. \
1050+
This may indicate stale cache data from a previous version.",
1051+
block_ptr.hash_hex(),
1052+
offset,
1053+
ptr_for_log.hash_hex(),
1054+
e
1055+
);
1056+
e
1057+
})
1058+
})
10461059
.transpose()?;
10471060
Ok(block.map(|block| {
10481061
BlockFinality::NonFinal(EthereumBlockWithCalls {
@@ -1060,9 +1073,21 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
10601073
let chain_store = self.chain_store.cheap_clone();
10611074
// First try to get the block from the store
10621075
if let Ok(blocks) = chain_store.blocks(vec![block.hash.clone()]).await {
1063-
if let Some(block) = blocks.first() {
1064-
if let Ok(block) = json::from_value::<LightEthereumBlock>(block.clone()) {
1065-
return Ok(block.parent_ptr());
1076+
if let Some(cached_json) = blocks.first() {
1077+
match json::from_value::<LightEthereumBlock>(cached_json.clone()) {
1078+
Ok(block) => {
1079+
return Ok(block.parent_ptr());
1080+
}
1081+
Err(e) => {
1082+
warn!(
1083+
self.logger,
1084+
"Failed to deserialize cached block {}: {}. \
1085+
This may indicate stale cache data from a previous version. \
1086+
Falling back to Firehose.",
1087+
block.hash_hex(),
1088+
e
1089+
);
1090+
}
10661091
}
10671092
}
10681093
}

chain/ethereum/src/ethereum_adapter.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1626,7 +1626,19 @@ impl EthereumAdapterTrait for EthereumAdapter {
16261626
.map_err(|e| error!(&logger, "Error accessing block cache {}", e))
16271627
.unwrap_or_default()
16281628
.into_iter()
1629-
.filter_map(|value| json::from_value(value).ok())
1629+
.filter_map(|value| {
1630+
json::from_value(value.clone())
1631+
.map_err(|e| {
1632+
warn!(
1633+
&logger,
1634+
"Failed to deserialize cached block: {}. \
1635+
This may indicate stale cache data from a previous version. \
1636+
Block will be re-fetched from RPC.",
1637+
e
1638+
);
1639+
})
1640+
.ok()
1641+
})
16301642
.map(|b| Arc::new(LightEthereumBlock::new(b)))
16311643
.collect();
16321644

0 commit comments

Comments
 (0)