@@ -46,7 +46,6 @@ use crate::codec::HeaderOnlyBlock;
4646use crate :: data_source:: DataSourceTemplate ;
4747use crate :: data_source:: UnresolvedDataSourceTemplate ;
4848use crate :: ingestor:: PollingBlockIngestor ;
49- use crate :: json_block:: EthereumJsonBlock ;
5049use crate :: network:: EthereumNetworkAdapters ;
5150use crate :: polling_block_stream:: PollingBlockStream ;
5251use crate :: runtime:: runtime_adapter:: eth_call_gas;
@@ -66,7 +65,6 @@ use graph::blockchain::block_stream::{
6665 BlockStream , BlockStreamBuilder , BlockStreamError , BlockStreamMapper , FirehoseCursor ,
6766 TriggersAdapterWrapper ,
6867} ;
69-
7068/// Celo Mainnet: 42220, Testnet Alfajores: 44787, Testnet Baklava: 62320
7169const CELO_CHAIN_IDS : [ u64 ; 3 ] = [ 42220 , 44787 , 62320 ] ;
7270
@@ -1076,55 +1074,26 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
10761074 . ancestor_block ( ptr. clone ( ) , offset, root. clone ( ) )
10771075 . await ?;
10781076
1079- // First check if we have the ancestor in cache and can deserialize it.
1080- // The cached JSON can be in one of three formats:
1081- // 1. Full RPC format: {"block": {...}, "transaction_receipts": [...]}
1082- // 2. Shallow/header-only: {"timestamp": "...", "data": null} - only timestamp, no block data
1083- // 3. Legacy direct: block fields at root level {hash, number, transactions, ...}
1084- // We need full format with receipts for ancestor_block (used for trigger processing).
1077+ // Use full blocks (with receipts) directly from cache.
1078+ // Light blocks (no receipts) need to be fetched from Firehose/RPC.
10851079 let block_ptr = match cached {
1086- Some ( ( json, ptr) ) => {
1087- let json_block = EthereumJsonBlock :: new ( json) ;
1088- if json_block. is_shallow ( ) {
1089- trace ! (
1090- self . logger,
1091- "Cached block #{} {} is shallow (header-only). Falling back to Firehose/RPC." ,
1092- ptr. number,
1093- ptr. hash_hex( ) ,
1094- ) ;
1095- ptr
1096- } else if json_block. is_legacy_format ( ) {
1080+ Some ( ( cached_block, ptr) ) => match cached_block. into_full_block ( ) {
1081+ Some ( block) => {
1082+ return Ok ( Some ( BlockFinality :: NonFinal ( EthereumBlockWithCalls {
1083+ ethereum_block : block,
1084+ calls : None ,
1085+ } ) ) ) ;
1086+ }
1087+ None => {
10971088 trace ! (
10981089 self . logger,
1099- "Cached block #{} {} is legacy light format . Falling back to Firehose/RPC." ,
1090+ "Cached block #{} {} is light (no receipts) . Falling back to Firehose/RPC." ,
11001091 ptr. number,
11011092 ptr. hash_hex( ) ,
11021093 ) ;
11031094 ptr
1104- } else {
1105- match json_block. into_full_block ( ) {
1106- Ok ( block) => {
1107- return Ok ( Some ( BlockFinality :: NonFinal ( EthereumBlockWithCalls {
1108- ethereum_block : block,
1109- calls : None ,
1110- } ) ) ) ;
1111- }
1112- Err ( e) => {
1113- warn ! (
1114- self . logger,
1115- "Failed to deserialize cached ancestor block #{} {} (offset {} from #{}): {}. \
1116- Falling back to Firehose/RPC.",
1117- ptr. number,
1118- ptr. hash_hex( ) ,
1119- offset,
1120- ptr_for_log. number,
1121- e
1122- ) ;
1123- ptr
1124- }
1125- }
11261095 }
1127- }
1096+ } ,
11281097 None => {
11291098 // Cache miss - fall back to walking the chain via parent_ptr() calls.
11301099 // This provides resilience when the block cache is empty (e.g., after truncation).
@@ -1179,35 +1148,10 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
11791148 let block = match self . chain_client . as_ref ( ) {
11801149 ChainClient :: Firehose ( endpoints) => {
11811150 let chain_store = self . chain_store . cheap_clone ( ) ;
1182- // First try to get the block from the store
1183- // See ancestor_block() for documentation of the 3 cached JSON formats.
1151+ // First try to get the block from the store (typed cache)
11841152 if let Ok ( blocks) = chain_store. blocks ( vec ! [ block. hash. clone( ) ] ) . await {
1185- if let Some ( cached_json) = blocks. into_iter ( ) . next ( ) {
1186- let json_block = EthereumJsonBlock :: new ( cached_json) ;
1187- if json_block. is_shallow ( ) {
1188- trace ! (
1189- self . logger,
1190- "Cached block #{} {} is shallow. Falling back to Firehose." ,
1191- block. number,
1192- block. hash_hex( ) ,
1193- ) ;
1194- } else {
1195- match json_block. into_light_block ( ) {
1196- Ok ( light_block) => {
1197- return Ok ( light_block. parent_ptr ( ) ) ;
1198- }
1199- Err ( e) => {
1200- warn ! (
1201- self . logger,
1202- "Failed to deserialize cached block #{} {}: {}. \
1203- Falling back to Firehose.",
1204- block. number,
1205- block. hash_hex( ) ,
1206- e
1207- ) ;
1208- }
1209- }
1210- }
1153+ if let Some ( cached_block) = blocks. into_iter ( ) . next ( ) {
1154+ return Ok ( cached_block. light_block ( ) . parent_ptr ( ) ) ;
12111155 }
12121156 }
12131157
0 commit comments