Skip to content

Commit 1a16aac

Browse files
committed
chain/ethereum: refactor check_block_receipt_support
1 parent 59e3be3 commit 1a16aac

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

chain/ethereum/src/ethereum_adapter.rs

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,9 @@ impl EthereumAdapter {
107107
) -> Self {
108108
let web3 = Arc::new(Web3::new(transport));
109109

110-
// Check if the chain supports `getBlockReceipts` method.
111-
let supports_block_receipts = web3
112-
.eth()
113-
.block_receipts(BlockId::Number(Web3BlockNumber::Latest))
114-
.await
115-
.is_ok();
110+
// Check if the provider supports `getBlockReceipts` method.
111+
let supports_block_receipts =
112+
Self::check_block_receipt_support(web3.clone(), &provider, &logger).await;
116113

117114
// Use the client version to check if it is ganache. For compatibility with unit tests, be
118115
// are lenient with errors, defaulting to false.
@@ -130,10 +127,36 @@ impl EthereumAdapter {
130127
metrics: provider_metrics,
131128
supports_eip_1898: supports_eip_1898 && !is_ganache,
132129
call_only,
133-
supports_block_receipts,
130+
supports_block_receipts: supports_block_receipts,
134131
}
135132
}
136133

134+
async fn check_block_receipt_support(
135+
web3: Arc<Web3<Transport>>,
136+
provider: &str,
137+
logger: &Logger,
138+
) -> bool {
139+
info!(logger, "Checking if provider supports getBlockReceipts"; "provider" => provider);
140+
141+
// Fetch block receipts from the provider for the latest block.
142+
let block_receipts_result = web3
143+
.eth()
144+
.block_receipts(BlockId::Number(Web3BlockNumber::Latest))
145+
.await;
146+
147+
// Determine if the provider supports block receipts based on the fetched result.
148+
let supports_block_receipts = block_receipts_result
149+
.map(|receipts_option| {
150+
// Ensure the result contains non-empty receipts
151+
receipts_option.map_or(false, |receipts| !receipts.is_empty())
152+
})
153+
.unwrap_or(false); // Default to false if there's an error in fetching receipts.
154+
155+
info!(logger, "Checked if provider supports eth_getBlockReceipts"; "provider" => provider, "supports_block_receipts" => supports_block_receipts);
156+
157+
supports_block_receipts
158+
}
159+
137160
async fn traces(
138161
self,
139162
logger: Logger,
@@ -1287,8 +1310,14 @@ impl EthereumAdapterTrait for EthereumAdapter {
12871310
})));
12881311
}
12891312
let hashes: Vec<_> = block.transactions.iter().map(|txn| txn.hash).collect();
1290-
let receipts_future =
1291-
fetch_receipts_with_retry(web3, hashes, block_hash, logger, true).boxed();
1313+
let receipts_future = fetch_receipts_with_retry(
1314+
web3,
1315+
hashes,
1316+
block_hash,
1317+
logger,
1318+
self.supports_block_receipts,
1319+
)
1320+
.boxed();
12921321

12931322
let block_future =
12941323
futures03::TryFutureExt::map_ok(receipts_future, move |transaction_receipts| {

0 commit comments

Comments
 (0)