Skip to content

Commit 7dd404d

Browse files
committed
chain: Modernize EthereumAdapter.latest_block_header
1 parent 03d4611 commit 7dd404d

File tree

3 files changed

+25
-31
lines changed

3 files changed

+25
-31
lines changed

chain/ethereum/src/adapter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,10 +1088,10 @@ pub trait EthereumAdapter: Send + Sync + 'static {
10881088
) -> Box<dyn Future<Item = LightEthereumBlock, Error = bc::IngestorError> + Send + Unpin>;
10891089

10901090
/// Get the latest block, with only the header and transaction hashes.
1091-
fn latest_block_header(
1091+
async fn latest_block_header(
10921092
&self,
10931093
logger: &Logger,
1094-
) -> Box<dyn Future<Item = web3::types::Block<H256>, Error = bc::IngestorError> + Send>;
1094+
) -> Result<web3::types::Block<H256>, bc::IngestorError>;
10951095

10961096
fn load_block(
10971097
&self,

chain/ethereum/src/ethereum_adapter.rs

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,39 +1258,34 @@ impl EthereumAdapterTrait for EthereumAdapter {
12581258
Ok(ident)
12591259
}
12601260

1261-
fn latest_block_header(
1261+
async fn latest_block_header(
12621262
&self,
12631263
logger: &Logger,
1264-
) -> Box<dyn Future<Item = web3::types::Block<H256>, Error = IngestorError> + Send> {
1264+
) -> Result<web3::types::Block<H256>, IngestorError> {
12651265
let web3 = self.web3.clone();
1266-
Box::new(
1267-
retry("eth_getBlockByNumber(latest) no txs RPC call", logger)
1268-
.redact_log_urls(true)
1269-
.no_limit()
1270-
.timeout_secs(ENV_VARS.json_rpc_timeout.as_secs())
1271-
.run(move || {
1272-
let web3 = web3.cheap_clone();
1273-
async move {
1274-
let block_opt = web3
1275-
.eth()
1276-
.block(Web3BlockNumber::Latest.into())
1277-
.await
1278-
.map_err(|e| {
1279-
anyhow!("could not get latest block from Ethereum: {}", e)
1280-
})?;
1266+
retry("eth_getBlockByNumber(latest) no txs RPC call", logger)
1267+
.redact_log_urls(true)
1268+
.no_limit()
1269+
.timeout_secs(ENV_VARS.json_rpc_timeout.as_secs())
1270+
.run(move || {
1271+
let web3 = web3.cheap_clone();
1272+
async move {
1273+
let block_opt = web3
1274+
.eth()
1275+
.block(Web3BlockNumber::Latest.into())
1276+
.await
1277+
.map_err(|e| anyhow!("could not get latest block from Ethereum: {}", e))?;
12811278

1282-
block_opt
1283-
.ok_or_else(|| anyhow!("no latest block returned from Ethereum").into())
1284-
}
1285-
})
1286-
.map_err(move |e| {
1287-
e.into_inner().unwrap_or_else(move || {
1288-
anyhow!("Ethereum node took too long to return latest block").into()
1289-
})
1279+
block_opt
1280+
.ok_or_else(|| anyhow!("no latest block returned from Ethereum").into())
1281+
}
1282+
})
1283+
.map_err(move |e| {
1284+
e.into_inner().unwrap_or_else(move || {
1285+
anyhow!("Ethereum node took too long to return latest block").into()
12901286
})
1291-
.boxed()
1292-
.compat(),
1293-
)
1287+
})
1288+
.await
12941289
}
12951290

12961291
fn latest_block(

chain/ethereum/src/ingestor.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ impl PollingBlockIngestor {
210210
) -> Result<BlockPtr, IngestorError> {
211211
eth_adapter
212212
.latest_block_header(&logger)
213-
.compat()
214213
.await
215214
.map(|block| block.into())
216215
}

0 commit comments

Comments
 (0)