Skip to content

Commit 970b78f

Browse files
authored
chain/ethereum: Add more context when logging RPC calls
Also removes the unused `fn uncles` method from `EthereumAdapter` trait
1 parent c51fe36 commit 970b78f

File tree

2 files changed

+35
-76
lines changed

2 files changed

+35
-76
lines changed

chain/ethereum/src/adapter.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::fmt;
1111
use std::marker::Unpin;
1212
use thiserror::Error;
1313
use tiny_keccak::keccak256;
14-
use web3::types::{Address, Block, Log, H256};
14+
use web3::types::{Address, Log, H256};
1515

1616
use graph::prelude::*;
1717
use graph::{
@@ -663,13 +663,6 @@ pub trait EthereumAdapter: Send + Sync + 'static {
663663
block_number: BlockNumber,
664664
) -> Box<dyn Future<Item = Option<H256>, Error = Error> + Send>;
665665

666-
/// Obtain all uncle blocks for a given block hash.
667-
fn uncles(
668-
&self,
669-
logger: &Logger,
670-
block: &LightEthereumBlock,
671-
) -> Box<dyn Future<Item = Vec<Option<Block<H256>>>, Error = Error> + Send>;
672-
673666
/// Call the function of a smart contract.
674667
fn contract_call(
675668
&self,

chain/ethereum/src/ethereum_adapter.rs

Lines changed: 34 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use graph::{
1818
web3::{
1919
self,
2020
types::{
21-
Address, Block, BlockId, BlockNumber as Web3BlockNumber, Bytes, CallRequest,
22-
Filter, FilterBuilder, Log, Transaction, TransactionReceipt, H256,
21+
Address, BlockId, BlockNumber as Web3BlockNumber, Bytes, CallRequest, Filter,
22+
FilterBuilder, Log, Transaction, TransactionReceipt, H256,
2323
},
2424
},
2525
BlockNumber, ChainStore, CheapClone, DynTryFuture, Error, EthereumCallCache, Logger,
@@ -188,8 +188,9 @@ impl EthereumAdapter {
188188
addresses: Vec<H160>,
189189
) -> Result<Vec<Trace>, Error> {
190190
let eth = self.clone();
191-
192-
retry("trace_filter RPC call", &logger)
191+
let retry_log_message =
192+
format!("trace_filter RPC call for block range: [{}..{}]", from, to);
193+
retry(retry_log_message, &logger)
193194
.limit(*REQUEST_RETRIES)
194195
.timeout_secs(*JSON_RPC_TIMEOUT)
195196
.run(move || {
@@ -282,8 +283,8 @@ impl EthereumAdapter {
282283
too_many_logs_fingerprints: &'static [&'static str],
283284
) -> Result<Vec<Log>, TimeoutError<web3::error::Error>> {
284285
let eth_adapter = self.clone();
285-
286-
retry("eth_getLogs RPC call", &logger)
286+
let retry_log_message = format!("eth_getLogs RPC call for block range: [{}..{}]", from, to);
287+
retry(retry_log_message, &logger)
287288
.when(move |res: &Result<_, web3::error::Error>| match res {
288289
Ok(_) => false,
289290
Err(e) => !too_many_logs_fingerprints
@@ -483,8 +484,8 @@ impl EthereumAdapter {
483484
} else {
484485
BlockId::Hash(block_ptr.hash_as_h256())
485486
};
486-
487-
retry("eth_call RPC call", &logger)
487+
let retry_log_message = format!("eth_call RPC call for block {}", block_ptr);
488+
retry(retry_log_message, &logger)
488489
.when(|result| match result {
489490
Ok(_) | Err(EthereumContractCallError::Revert(_)) => false,
490491
Err(_) => true,
@@ -1004,9 +1005,12 @@ impl EthereumAdapterTrait for EthereumAdapter {
10041005
) -> Box<dyn Future<Item = Option<LightEthereumBlock>, Error = Error> + Send> {
10051006
let web3 = self.web3.clone();
10061007
let logger = logger.clone();
1007-
1008+
let retry_log_message = format!(
1009+
"eth_getBlockByHash RPC call for block hash {:?}",
1010+
block_hash
1011+
);
10081012
Box::new(
1009-
retry("eth_getBlockByHash RPC call", &logger)
1013+
retry(retry_log_message, &logger)
10101014
.limit(*REQUEST_RETRIES)
10111015
.timeout_secs(*JSON_RPC_TIMEOUT)
10121016
.run(move || {
@@ -1032,9 +1036,12 @@ impl EthereumAdapterTrait for EthereumAdapter {
10321036
) -> Box<dyn Future<Item = Option<LightEthereumBlock>, Error = Error> + Send> {
10331037
let web3 = self.web3.clone();
10341038
let logger = logger.clone();
1035-
1039+
let retry_log_message = format!(
1040+
"eth_getBlockByNumber RPC call for block number {}",
1041+
block_number
1042+
);
10361043
Box::new(
1037-
retry("eth_getBlockByNumber RPC call", &logger)
1044+
retry(retry_log_message, &logger)
10381045
.no_limit()
10391046
.timeout_secs(*JSON_RPC_TIMEOUT)
10401047
.run(move || {
@@ -1135,9 +1142,12 @@ impl EthereumAdapterTrait for EthereumAdapter {
11351142
block_number: BlockNumber,
11361143
) -> Box<dyn Future<Item = Option<H256>, Error = Error> + Send> {
11371144
let web3 = self.web3.clone();
1138-
1145+
let retry_log_message = format!(
1146+
"eth_getBlockByNumber RPC call for block number {}",
1147+
block_number
1148+
);
11391149
Box::new(
1140-
retry("eth_getBlockByNumber RPC call", &logger)
1150+
retry(retry_log_message, &logger)
11411151
.no_limit()
11421152
.timeout_secs(*JSON_RPC_TIMEOUT)
11431153
.run(move || {
@@ -1163,58 +1173,6 @@ impl EthereumAdapterTrait for EthereumAdapter {
11631173
)
11641174
}
11651175

1166-
fn uncles(
1167-
&self,
1168-
logger: &Logger,
1169-
block: &LightEthereumBlock,
1170-
) -> Box<dyn Future<Item = Vec<Option<Block<H256>>>, Error = Error> + Send> {
1171-
let block_hash = match block.hash {
1172-
Some(hash) => hash,
1173-
None => {
1174-
return Box::new(future::result(Err(anyhow!(
1175-
"could not get uncle for block '{}' because block has null hash",
1176-
block
1177-
.number
1178-
.map(|num| num.to_string())
1179-
.unwrap_or(String::from("null"))
1180-
))))
1181-
}
1182-
};
1183-
let n = block.uncles.len();
1184-
1185-
Box::new(
1186-
futures::stream::futures_ordered((0..n).map(move |index| {
1187-
let web3 = self.web3.clone();
1188-
1189-
retry("eth_getUncleByBlockHashAndIndex RPC call", &logger)
1190-
.no_limit()
1191-
.timeout_secs(60)
1192-
.run(move || {
1193-
Box::pin(web3.eth().uncle(block_hash.clone().into(), index.into()))
1194-
.compat()
1195-
.map_err(move |e| {
1196-
anyhow!(
1197-
"could not get uncle {} for block {:?} ({} uncles): {}",
1198-
index,
1199-
block_hash,
1200-
n,
1201-
e
1202-
)
1203-
})
1204-
.compat()
1205-
})
1206-
.map_err(move |e| {
1207-
e.into_inner().unwrap_or_else(move || {
1208-
anyhow!("Ethereum node took too long to return uncle")
1209-
})
1210-
})
1211-
.boxed()
1212-
.compat()
1213-
}))
1214-
.collect(),
1215-
)
1216-
}
1217-
12181176
fn contract_call(
12191177
&self,
12201178
logger: &Logger,
@@ -1812,7 +1770,11 @@ async fn fetch_transaction_receipts_in_batch_with_retry(
18121770
block_hash: H256,
18131771
logger: Logger,
18141772
) -> Result<Vec<TransactionReceipt>, IngestorError> {
1815-
retry("batch eth_getTransactionReceipt RPC call", &logger)
1773+
let retry_log_message = format!(
1774+
"batch eth_getTransactionReceipt RPC call for block {:?}",
1775+
block_hash
1776+
);
1777+
retry(retry_log_message, &logger)
18161778
.limit(*REQUEST_RETRIES)
18171779
.no_logging()
18181780
.timeout_secs(*JSON_RPC_TIMEOUT)
@@ -1864,7 +1826,11 @@ async fn fetch_transaction_receipt_with_retry(
18641826
logger: Logger,
18651827
) -> Result<TransactionReceipt, IngestorError> {
18661828
let logger = logger.cheap_clone();
1867-
retry("batch eth_getTransactionReceipt RPC call", &logger)
1829+
let retry_log_message = format!(
1830+
"eth_getTransactionReceipt RPC call for transaction {:?}",
1831+
transaction_hash
1832+
);
1833+
retry(retry_log_message, &logger)
18681834
.limit(*REQUEST_RETRIES)
18691835
.no_logging()
18701836
.timeout_secs(*JSON_RPC_TIMEOUT)

0 commit comments

Comments
 (0)