@@ -65,8 +65,6 @@ use graph::blockchain::block_stream::{
6565 BlockStream , BlockStreamBuilder , BlockStreamError , BlockStreamMapper , FirehoseCursor ,
6666 TriggersAdapterWrapper ,
6767} ;
68- use graph:: components:: ethereum:: EthereumJsonBlock ;
69-
7068/// Celo Mainnet: 42220, Testnet Alfajores: 44787, Testnet Baklava: 62320
7169const CELO_CHAIN_IDS : [ u64 ; 3 ] = [ 42220 , 44787 , 62320 ] ;
7270
@@ -1076,52 +1074,25 @@ 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 ( ) {
1097- trace ! (
1098- self . logger,
1099- "Cached block #{} {} is legacy light format. Falling back to Firehose/RPC." ,
1100- ptr. number,
1101- ptr. hash_hex( ) ,
1102- ) ;
1103- 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- }
1080+ Some ( ( cached_block, ptr) ) => {
1081+ match cached_block. into_full_block ( ) {
1082+ Some ( block) => {
1083+ return Ok ( Some ( BlockFinality :: NonFinal ( EthereumBlockWithCalls {
1084+ ethereum_block : block,
1085+ calls : None ,
1086+ } ) ) ) ;
1087+ }
1088+ None => {
1089+ trace ! (
1090+ self . logger,
1091+ "Cached block #{} {} is light (no receipts). Falling back to Firehose/RPC." ,
1092+ ptr. number,
1093+ ptr. hash_hex( ) ,
1094+ ) ;
1095+ ptr
11251096 }
11261097 }
11271098 }
@@ -1179,35 +1150,10 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
11791150 let block = match self . chain_client . as_ref ( ) {
11801151 ChainClient :: Firehose ( endpoints) => {
11811152 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.
1153+ // First try to get the block from the store (typed cache)
11841154 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- }
1155+ if let Some ( cached_block) = blocks. into_iter ( ) . next ( ) {
1156+ return Ok ( cached_block. light_block ( ) . parent_ptr ( ) ) ;
12111157 }
12121158 }
12131159
0 commit comments