Skip to content

Commit 6d6b754

Browse files
committed
chain: Modernize EthereumAdapter.load_block, block_by_hash and by_number
1 parent 20139ab commit 6d6b754

File tree

5 files changed

+60
-71
lines changed

5 files changed

+60
-71
lines changed

chain/ethereum/src/adapter.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,11 +1089,11 @@ pub trait EthereumAdapter: Send + Sync + 'static {
10891089
logger: &Logger,
10901090
) -> Result<web3::types::Block<H256>, bc::IngestorError>;
10911091

1092-
fn load_block(
1092+
async fn load_block(
10931093
&self,
10941094
logger: &Logger,
10951095
block_hash: H256,
1096-
) -> Box<dyn Future<Item = LightEthereumBlock, Error = Error> + Send>;
1096+
) -> Result<LightEthereumBlock, Error>;
10971097

10981098
/// Load Ethereum blocks in bulk, returning results as they come back as a Stream.
10991099
/// May use the `chain_store` as a cache.
@@ -1105,17 +1105,17 @@ pub trait EthereumAdapter: Send + Sync + 'static {
11051105
) -> Result<Vec<Arc<LightEthereumBlock>>, Error>;
11061106

11071107
/// Find a block by its hash.
1108-
fn block_by_hash(
1108+
async fn block_by_hash(
11091109
&self,
11101110
logger: &Logger,
11111111
block_hash: H256,
1112-
) -> Box<dyn Future<Item = Option<LightEthereumBlock>, Error = Error> + Send>;
1112+
) -> Result<Option<LightEthereumBlock>, Error>;
11131113

1114-
fn block_by_number(
1114+
async fn block_by_number(
11151115
&self,
11161116
logger: &Logger,
11171117
block_number: BlockNumber,
1118-
) -> Box<dyn Future<Item = Option<LightEthereumBlock>, Error = Error> + Send>;
1118+
) -> Result<Option<LightEthereumBlock>, Error>;
11191119

11201120
/// Load full information for the specified `block` (in particular, transaction receipts).
11211121
fn load_full_block(

chain/ethereum/src/ethereum_adapter.rs

Lines changed: 54 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,92 +1314,87 @@ impl EthereumAdapterTrait for EthereumAdapter {
13141314
.await
13151315
}
13161316

1317-
fn load_block(
1317+
async fn load_block(
13181318
&self,
13191319
logger: &Logger,
13201320
block_hash: H256,
1321-
) -> Box<dyn Future<Item = LightEthereumBlock, Error = Error> + Send> {
1322-
Box::new(
1323-
self.block_by_hash(logger, block_hash)
1324-
.and_then(move |block_opt| {
1325-
block_opt.ok_or_else(move || {
1326-
anyhow!(
1327-
"Ethereum node could not find block with hash {}",
1328-
block_hash
1329-
)
1330-
})
1331-
}),
1332-
)
1321+
) -> Result<LightEthereumBlock, Error> {
1322+
self.block_by_hash(logger, block_hash)
1323+
.await?
1324+
.ok_or_else(move || {
1325+
anyhow!(
1326+
"Ethereum node could not find block with hash {}",
1327+
block_hash
1328+
)
1329+
})
13331330
}
13341331

1335-
fn block_by_hash(
1332+
async fn block_by_hash(
13361333
&self,
13371334
logger: &Logger,
13381335
block_hash: H256,
1339-
) -> Box<dyn Future<Item = Option<LightEthereumBlock>, Error = Error> + Send> {
1336+
) -> Result<Option<LightEthereumBlock>, Error> {
13401337
let web3 = self.web3.clone();
13411338
let logger = logger.clone();
13421339
let retry_log_message = format!(
13431340
"eth_getBlockByHash RPC call for block hash {:?}",
13441341
block_hash
13451342
);
1346-
Box::new(
1347-
retry(retry_log_message, &logger)
1348-
.redact_log_urls(true)
1349-
.limit(ENV_VARS.request_retries)
1350-
.timeout_secs(ENV_VARS.json_rpc_timeout.as_secs())
1351-
.run(move || {
1352-
Box::pin(web3.eth().block_with_txs(BlockId::Hash(block_hash)))
1353-
.compat()
1354-
.from_err()
1355-
.compat()
1356-
})
1357-
.map_err(move |e| {
1358-
e.into_inner().unwrap_or_else(move || {
1359-
anyhow!("Ethereum node took too long to return block {}", block_hash)
1360-
})
1343+
1344+
retry(retry_log_message, &logger)
1345+
.redact_log_urls(true)
1346+
.limit(ENV_VARS.request_retries)
1347+
.timeout_secs(ENV_VARS.json_rpc_timeout.as_secs())
1348+
.run(move || {
1349+
let web3 = web3.cheap_clone();
1350+
async move {
1351+
web3.eth()
1352+
.block_with_txs(BlockId::Hash(block_hash))
1353+
.await
1354+
.map_err(Error::from)
1355+
}
1356+
})
1357+
.map_err(move |e| {
1358+
e.into_inner().unwrap_or_else(move || {
1359+
anyhow!("Ethereum node took too long to return block {}", block_hash)
13611360
})
1362-
.boxed()
1363-
.compat(),
1364-
)
1361+
})
1362+
.await
13651363
}
13661364

1367-
fn block_by_number(
1365+
async fn block_by_number(
13681366
&self,
13691367
logger: &Logger,
13701368
block_number: BlockNumber,
1371-
) -> Box<dyn Future<Item = Option<LightEthereumBlock>, Error = Error> + Send> {
1369+
) -> Result<Option<LightEthereumBlock>, Error> {
13721370
let web3 = self.web3.clone();
13731371
let logger = logger.clone();
13741372
let retry_log_message = format!(
13751373
"eth_getBlockByNumber RPC call for block number {}",
13761374
block_number
13771375
);
1378-
Box::new(
1379-
retry(retry_log_message, &logger)
1380-
.redact_log_urls(true)
1381-
.no_limit()
1382-
.timeout_secs(ENV_VARS.json_rpc_timeout.as_secs())
1383-
.run(move || {
1384-
let web3 = web3.cheap_clone();
1385-
async move {
1386-
web3.eth()
1387-
.block_with_txs(BlockId::Number(block_number.into()))
1388-
.await
1389-
.map_err(Error::from)
1390-
}
1391-
})
1392-
.map_err(move |e| {
1393-
e.into_inner().unwrap_or_else(move || {
1394-
anyhow!(
1395-
"Ethereum node took too long to return block {}",
1396-
block_number
1397-
)
1398-
})
1376+
retry(retry_log_message, &logger)
1377+
.redact_log_urls(true)
1378+
.no_limit()
1379+
.timeout_secs(ENV_VARS.json_rpc_timeout.as_secs())
1380+
.run(move || {
1381+
let web3 = web3.cheap_clone();
1382+
async move {
1383+
web3.eth()
1384+
.block_with_txs(BlockId::Number(block_number.into()))
1385+
.await
1386+
.map_err(Error::from)
1387+
}
1388+
})
1389+
.map_err(move |e| {
1390+
e.into_inner().unwrap_or_else(move || {
1391+
anyhow!(
1392+
"Ethereum node took too long to return block {}",
1393+
block_number
1394+
)
13991395
})
1400-
.boxed()
1401-
.compat(),
1402-
)
1396+
})
1397+
.await
14031398
}
14041399

14051400
fn load_full_block(

chain/ethereum/src/ingestor.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::{EthereumAdapter, EthereumAdapterTrait as _};
33
use graph::blockchain::client::ChainClient;
44
use graph::blockchain::BlockchainKind;
55
use graph::components::network_provider::ChainName;
6-
use graph::futures03::compat::Future01CompatExt as _;
76
use graph::slog::o;
87
use graph::util::backoff::ExponentialBackoff;
98
use graph::{
@@ -175,7 +174,6 @@ impl PollingBlockIngestor {
175174
// Get the fully populated block
176175
let block = eth_adapter
177176
.block_by_hash(logger, block_hash)
178-
.compat()
179177
.await?
180178
.ok_or(IngestorError::BlockUnavailable(block_hash))?;
181179
let ethereum_block = eth_adapter.load_full_block(&logger, block).await?;

node/src/manager/commands/chain.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use graph::cheap_clone::CheapClone;
1010
use graph::components::network_provider::ChainIdentifierStore;
1111
use graph::components::network_provider::ChainName;
1212
use graph::components::store::StoreError;
13-
use graph::futures03::compat::Future01CompatExt as _;
1413
use graph::prelude::BlockNumber;
1514
use graph::prelude::ChainStore as _;
1615
use graph::prelude::LightEthereumBlockExt;
@@ -273,7 +272,6 @@ pub async fn ingest(
273272
) -> Result<(), Error> {
274273
let Some(block) = ethereum_adapter
275274
.block_by_number(logger, number)
276-
.compat()
277275
.await
278276
.map_err(|e| anyhow!("error getting block number {number}: {}", e))?
279277
else {

node/src/manager/commands/check_blocks.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ async fn handle_multiple_block_hashes(
153153
mod steps {
154154
use super::*;
155155

156-
use graph::futures03::compat::Future01CompatExt;
157156
use graph::{
158157
anyhow::bail,
159158
prelude::serde_json::{self, Value},
@@ -204,7 +203,6 @@ mod steps {
204203
) -> anyhow::Result<Value> {
205204
let provider_block = ethereum_adapter
206205
.block_by_hash(logger, *block_hash)
207-
.compat()
208206
.await
209207
.with_context(|| format!("failed to fetch block {block_hash}"))?
210208
.ok_or_else(|| anyhow!("JRPC provider found no block with hash {block_hash:?}"))?;

0 commit comments

Comments
 (0)