@@ -32,17 +32,18 @@ use graph::prelude::{
3232 } ,
3333 rpc:: types:: {
3434 trace:: { filter:: TraceFilter as AlloyTraceFilter , parity:: LocalizedTransactionTrace } ,
35- TransactionInput , TransactionRequest ,
35+ Block as AlloyBlock , TransactionInput , TransactionRequest ,
3636 } ,
3737 transports:: { RpcError , TransportErrorKind } ,
3838 } ,
39- alloy_log_to_web3_log, alloy_transaction_receipt_to_web3_transaction_receipt, b256_to_h256 ,
39+ alloy_log_to_web3_log, alloy_transaction_receipt_to_web3_transaction_receipt,
4040 h160_to_alloy_address, h256_to_b256,
4141 tokio:: try_join,
4242} ;
4343use graph:: slog:: o;
4444use graph:: tokio:: sync:: RwLock ;
4545use graph:: tokio:: time:: timeout;
46+ use graph:: util:: conversions:: alloy_block_to_web3_block;
4647use graph:: {
4748 blockchain:: { block_stream:: BlockWithTriggers , BlockPtr , IngestorError } ,
4849 prelude:: {
@@ -1258,27 +1259,12 @@ impl EthereumAdapterTrait for EthereumAdapter {
12581259 . await
12591260 }
12601261
1261- async fn load_block (
1262- & self ,
1263- logger : & Logger ,
1264- block_hash : H256 ,
1265- ) -> Result < LightEthereumBlock , Error > {
1266- self . block_by_hash ( logger, block_hash)
1267- . await ?
1268- . ok_or_else ( move || {
1269- anyhow ! (
1270- "Ethereum node could not find block with hash {}" ,
1271- block_hash
1272- )
1273- } )
1274- }
1275-
12761262 async fn block_by_hash (
12771263 & self ,
12781264 logger : & Logger ,
1279- block_hash : H256 ,
1280- ) -> Result < Option < LightEthereumBlock > , Error > {
1281- let web3 = self . web3 . clone ( ) ;
1265+ block_hash : B256 ,
1266+ ) -> Result < Option < AlloyBlock > , Error > {
1267+ let alloy = self . alloy . clone ( ) ;
12821268 let logger = logger. clone ( ) ;
12831269 let retry_log_message = format ! (
12841270 "eth_getBlockByHash RPC call for block hash {:?}" ,
@@ -1290,10 +1276,11 @@ impl EthereumAdapterTrait for EthereumAdapter {
12901276 . limit ( ENV_VARS . request_retries )
12911277 . timeout_secs ( ENV_VARS . json_rpc_timeout . as_secs ( ) )
12921278 . run ( move || {
1293- let web3 = web3 . cheap_clone ( ) ;
1279+ let alloy = alloy . cheap_clone ( ) ;
12941280 async move {
1295- web3. eth ( )
1296- . block_with_txs ( BlockId :: Hash ( block_hash) )
1281+ alloy
1282+ . get_block_by_hash ( block_hash)
1283+ . full ( )
12971284 . await
12981285 . map_err ( Error :: from)
12991286 }
@@ -1310,8 +1297,8 @@ impl EthereumAdapterTrait for EthereumAdapter {
13101297 & self ,
13111298 logger : & Logger ,
13121299 block_number : BlockNumber ,
1313- ) -> Result < Option < LightEthereumBlock > , Error > {
1314- let web3 = self . web3 . clone ( ) ;
1300+ ) -> Result < Option < AlloyBlock > , Error > {
1301+ let alloy = self . alloy . clone ( ) ;
13151302 let logger = logger. clone ( ) ;
13161303 let retry_log_message = format ! (
13171304 "eth_getBlockByNumber RPC call for block number {}" ,
@@ -1322,10 +1309,13 @@ impl EthereumAdapterTrait for EthereumAdapter {
13221309 . no_limit ( )
13231310 . timeout_secs ( ENV_VARS . json_rpc_timeout . as_secs ( ) )
13241311 . run ( move || {
1325- let web3 = web3 . cheap_clone ( ) ;
1312+ let alloy = alloy . clone ( ) ;
13261313 async move {
1327- web3. eth ( )
1328- . block_with_txs ( BlockId :: Number ( block_number. into ( ) ) )
1314+ alloy
1315+ . get_block_by_number ( alloy:: rpc:: types:: BlockNumberOrTag :: Number (
1316+ block_number as u64 ,
1317+ ) )
1318+ . full ( )
13291319 . await
13301320 . map_err ( Error :: from)
13311321 }
@@ -1344,50 +1334,42 @@ impl EthereumAdapterTrait for EthereumAdapter {
13441334 async fn load_full_block (
13451335 & self ,
13461336 logger : & Logger ,
1347- block : LightEthereumBlock ,
1337+ block : AlloyBlock ,
13481338 ) -> Result < EthereumBlock , IngestorError > {
13491339 let alloy = self . alloy . clone ( ) ;
13501340 let logger = logger. clone ( ) ;
1351- let block_hash = block. hash . expect ( "block is missing block hash" ) ;
1341+ let block_hash = block. header . hash ;
13521342
13531343 // The early return is necessary for correctness, otherwise we'll
13541344 // request an empty batch which is not valid in JSON-RPC.
13551345 if block. transactions . is_empty ( ) {
13561346 trace ! ( logger, "Block {} contains no transactions" , block_hash) ;
13571347 return Ok ( EthereumBlock {
1358- block : Arc :: new ( block) ,
1348+ block : Arc :: new ( alloy_block_to_web3_block ( block) ) ,
13591349 transaction_receipts : Vec :: new ( ) ,
13601350 } ) ;
13611351 }
1362- let hashes: Vec < _ > = block. transactions . iter ( ) . map ( |txn| txn . hash ) . collect ( ) ;
1352+ let hashes: Vec < _ > = block. transactions . hashes ( ) . collect ( ) ;
13631353
13641354 let supports_block_receipts = self
13651355 . check_block_receipt_support_and_update_cache (
13661356 alloy. clone ( ) ,
1367- h256_to_b256 ( block_hash) ,
1357+ block_hash,
13681358 self . supports_eip_1898 ,
13691359 self . call_only ,
13701360 logger. clone ( ) ,
13711361 )
13721362 . await ;
13731363
1374- let hashes_b256 = hashes. iter ( ) . map ( |hash| h256_to_b256 ( * hash) ) . collect ( ) ;
1375- let block_hash_b256 = h256_to_b256 ( block_hash) ;
1376- fetch_receipts_with_retry (
1377- alloy,
1378- hashes_b256,
1379- block_hash_b256,
1380- logger,
1381- supports_block_receipts,
1382- )
1383- . await
1384- . map ( |transaction_receipts| EthereumBlock {
1385- block : Arc :: new ( block) ,
1386- transaction_receipts : transaction_receipts
1387- . into_iter ( )
1388- . map ( |receipt| alloy_transaction_receipt_to_web3_transaction_receipt ( receipt) )
1389- . collect ( ) ,
1390- } )
1364+ fetch_receipts_with_retry ( alloy, hashes, block_hash, logger, supports_block_receipts)
1365+ . await
1366+ . map ( |transaction_receipts| EthereumBlock {
1367+ block : Arc :: new ( alloy_block_to_web3_block ( block) ) ,
1368+ transaction_receipts : transaction_receipts
1369+ . into_iter ( )
1370+ . map ( |receipt| alloy_transaction_receipt_to_web3_transaction_receipt ( receipt) )
1371+ . collect ( ) ,
1372+ } )
13911373 }
13921374
13931375 async fn get_balance (
@@ -2447,7 +2429,7 @@ fn resolve_transaction_receipt(
24472429 // considers this block to be in the main chain. Nothing we can do from here except
24482430 // give up trying to ingest this block. There is no way to get the transaction
24492431 // receipt from this block.
2450- Err ( IngestorError :: BlockUnavailable ( b256_to_h256 ( block_hash) ) )
2432+ Err ( IngestorError :: BlockUnavailable ( block_hash) )
24512433 } else {
24522434 Ok ( receipt)
24532435 }
0 commit comments