Skip to content

Commit 4885cbe

Browse files
committed
chain/ethereum: migrate latest_block_header call to use alloy
1 parent cd85af1 commit 4885cbe

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

chain/ethereum/src/adapter.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ use graph::{
2626
petgraph::{self, graphmap::GraphMap},
2727
};
2828

29+
use graph::blockchain::BlockPtr;
30+
2931
const COMBINED_FILTER_TYPE_URL: &str =
3032
"type.googleapis.com/sf.ethereum.transform.v1.CombinedFilter";
3133

@@ -1083,10 +1085,7 @@ pub trait EthereumAdapter: Send + Sync + 'static {
10831085
async fn latest_block(&self, logger: &Logger) -> Result<LightEthereumBlock, bc::IngestorError>;
10841086

10851087
/// Get the latest block, with only the header and transaction hashes.
1086-
async fn latest_block_header(
1087-
&self,
1088-
logger: &Logger,
1089-
) -> Result<web3::types::Block<H256>, bc::IngestorError>;
1088+
async fn latest_block_header(&self, logger: &Logger) -> Result<BlockPtr, bc::IngestorError>;
10901089

10911090
async fn load_block(
10921091
&self,

chain/ethereum/src/ethereum_adapter.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,26 +1303,27 @@ impl EthereumAdapterTrait for EthereumAdapter {
13031303
Ok(ident)
13041304
}
13051305

1306-
async fn latest_block_header(
1307-
&self,
1308-
logger: &Logger,
1309-
) -> Result<web3::types::Block<H256>, IngestorError> {
1310-
let web3 = self.web3.clone();
1306+
async fn latest_block_header(&self, logger: &Logger) -> Result<BlockPtr, IngestorError> {
1307+
let alloy = self.alloy.clone();
13111308
retry("eth_getBlockByNumber(latest) no txs RPC call", logger)
13121309
.redact_log_urls(true)
13131310
.no_limit()
13141311
.timeout_secs(ENV_VARS.json_rpc_timeout.as_secs())
13151312
.run(move || {
1316-
let web3 = web3.cheap_clone();
1313+
let alloy = alloy.cheap_clone();
13171314
async move {
1318-
let block_opt = web3
1319-
.eth()
1320-
.block(Web3BlockNumber::Latest.into())
1315+
let block_opt = alloy
1316+
.get_block_by_number(alloy::rpc::types::BlockNumberOrTag::Latest)
13211317
.await
13221318
.map_err(|e| anyhow!("could not get latest block from Ethereum: {}", e))?;
13231319

1324-
block_opt
1325-
.ok_or_else(|| anyhow!("no latest block returned from Ethereum").into())
1320+
let block = block_opt
1321+
.ok_or_else(|| anyhow!("no latest block returned from Ethereum"))?;
1322+
1323+
Ok(BlockPtr::from((
1324+
block.header.hash,
1325+
block.header.number as i32,
1326+
)))
13261327
}
13271328
})
13281329
.map_err(move |e| {

chain/ethereum/src/ingestor.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,7 @@ impl PollingBlockIngestor {
206206
logger: &Logger,
207207
eth_adapter: &Arc<EthereumAdapter>,
208208
) -> Result<BlockPtr, IngestorError> {
209-
eth_adapter
210-
.latest_block_header(&logger)
211-
.await
212-
.map(|block| block.into())
209+
eth_adapter.latest_block_header(&logger).await
213210
}
214211

215212
async fn eth_adapter(&self) -> anyhow::Result<Arc<EthereumAdapter>> {

0 commit comments

Comments
 (0)