From 4c0dc41408341bc9514d3e9e1493382deca41336 Mon Sep 17 00:00:00 2001 From: incrypto32 Date: Tue, 19 Nov 2024 15:20:36 +0400 Subject: [PATCH] chain, graph: rename BlockPtrExt to ExtendedBlockPtr --- chain/ethereum/src/adapter.rs | 4 +-- chain/ethereum/src/chain.rs | 6 ++--- chain/ethereum/src/ethereum_adapter.rs | 10 ++++---- graph/src/blockchain/mod.rs | 2 +- graph/src/blockchain/types.rs | 34 +++++++++++++------------- graph/src/components/store/traits.rs | 4 +-- store/postgres/src/chain_store.rs | 11 +++++---- 7 files changed, 36 insertions(+), 35 deletions(-) diff --git a/chain/ethereum/src/adapter.rs b/chain/ethereum/src/adapter.rs index c969f5521d9..1ccdb3d8f2d 100644 --- a/chain/ethereum/src/adapter.rs +++ b/chain/ethereum/src/adapter.rs @@ -1,7 +1,7 @@ use anyhow::Error; use ethabi::{Error as ABIError, Function, ParamType, Token}; -use graph::blockchain::BlockPtrExt; use graph::blockchain::ChainIdentifier; +use graph::blockchain::ExtendedBlockPtr; use graph::components::subgraph::MappingError; use graph::data::store::ethereum::call; use graph::firehose::CallToFilter; @@ -1115,7 +1115,7 @@ pub trait EthereumAdapter: Send + Sync + 'static { _logger: Logger, _chain_store: Arc, _block_numbers: HashSet, - ) -> Box, Error = Error> + Send>; + ) -> Box, Error = Error> + Send>; /// Load Ethereum blocks in bulk, returning results as they come back as a Stream. /// May use the `chain_store` as a cache. diff --git a/chain/ethereum/src/chain.rs b/chain/ethereum/src/chain.rs index c55a3ebaf77..652c51c4d23 100644 --- a/chain/ethereum/src/chain.rs +++ b/chain/ethereum/src/chain.rs @@ -3,8 +3,8 @@ use anyhow::{Context, Error}; use graph::blockchain::client::ChainClient; use graph::blockchain::firehose_block_ingestor::{FirehoseBlockIngestor, Transforms}; use graph::blockchain::{ - BlockIngestor, BlockPtrExt, BlockTime, BlockchainKind, ChainIdentifier, TriggerFilterWrapper, - TriggersAdapterSelector, + BlockIngestor, BlockTime, BlockchainKind, ChainIdentifier, ExtendedBlockPtr, + TriggerFilterWrapper, TriggersAdapterSelector, }; use graph::components::adapter::ChainId; use graph::components::store::{DeploymentCursorTracker, WritableStore}; @@ -631,7 +631,7 @@ pub enum BlockFinality { // If a block may still be reorged, we need to work with more local data. NonFinal(EthereumBlockWithCalls), - Ptr(Arc), + Ptr(Arc), } impl Default for BlockFinality { diff --git a/chain/ethereum/src/ethereum_adapter.rs b/chain/ethereum/src/ethereum_adapter.rs index 905d057f93d..dc672f1b5d9 100644 --- a/chain/ethereum/src/ethereum_adapter.rs +++ b/chain/ethereum/src/ethereum_adapter.rs @@ -1,8 +1,8 @@ use futures03::{future::BoxFuture, stream::FuturesUnordered}; use graph::blockchain::client::ChainClient; use graph::blockchain::BlockHash; -use graph::blockchain::BlockPtrExt; use graph::blockchain::ChainIdentifier; +use graph::blockchain::ExtendedBlockPtr; use graph::components::transaction_receipt::LightTransactionReceipt; use graph::data::store::ethereum::call; @@ -788,7 +788,7 @@ impl EthereumAdapter { &self, logger: Logger, numbers: Vec, - ) -> impl Stream, Error = Error> + Send { + ) -> impl Stream, Error = Error> + Send { let web3 = self.web3.clone(); stream::iter_ok::<_, Error>(numbers.into_iter().map(move |number| { @@ -806,7 +806,7 @@ impl EthereumAdapter { .and_then(move |block| { block .map(|block| { - let ptr = BlockPtrExt::try_from(( + let ptr = ExtendedBlockPtr::try_from(( block.hash, block.number, block.parent_hash, @@ -1706,7 +1706,7 @@ impl EthereumAdapterTrait for EthereumAdapter { logger: Logger, chain_store: Arc, block_numbers: HashSet, - ) -> Box, Error = Error> + Send> { + ) -> Box, Error = Error> + Send> { let blocks_map = chain_store .cheap_clone() .block_ptrs_by_numbers(block_numbers.iter().map(|&b| b.into()).collect::>()) @@ -1717,7 +1717,7 @@ impl EthereumAdapterTrait for EthereumAdapter { }) .unwrap_or_default(); - let mut blocks: Vec> = blocks_map + let mut blocks: Vec> = blocks_map .into_iter() .filter_map(|(_number, values)| { if values.len() == 1 { diff --git a/graph/src/blockchain/mod.rs b/graph/src/blockchain/mod.rs index b3ea849fc0f..ee4d4d19857 100644 --- a/graph/src/blockchain/mod.rs +++ b/graph/src/blockchain/mod.rs @@ -54,7 +54,7 @@ pub use block_stream::{ChainHeadUpdateListener, ChainHeadUpdateStream, TriggersA pub use builder::{BasicBlockchainBuilder, BlockchainBuilder}; pub use empty_node_capabilities::EmptyNodeCapabilities; pub use noop_runtime_adapter::NoopRuntimeAdapter; -pub use types::{BlockHash, BlockPtr, BlockPtrExt, BlockTime, ChainIdentifier}; +pub use types::{BlockHash, BlockPtr, BlockTime, ChainIdentifier, ExtendedBlockPtr}; use self::{ block_stream::{BlockStream, FirehoseCursor}, diff --git a/graph/src/blockchain/types.rs b/graph/src/blockchain/types.rs index 2fa04a6e41c..4429dd87304 100644 --- a/graph/src/blockchain/types.rs +++ b/graph/src/blockchain/types.rs @@ -357,7 +357,7 @@ where #[derive(Clone, PartialEq, Eq, Hash, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct BlockPtrExt { +pub struct ExtendedBlockPtr { pub hash: BlockHash, #[serde(deserialize_with = "deserialize_block_number")] pub number: BlockNumber, @@ -365,7 +365,7 @@ pub struct BlockPtrExt { pub timestamp: U256, } -impl BlockPtrExt { +impl ExtendedBlockPtr { pub fn new( hash: BlockHash, number: BlockNumber, @@ -413,7 +413,7 @@ impl BlockPtrExt { } } -impl fmt::Display for BlockPtrExt { +impl fmt::Display for ExtendedBlockPtr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, @@ -425,7 +425,7 @@ impl fmt::Display for BlockPtrExt { } } -impl fmt::Debug for BlockPtrExt { +impl fmt::Debug for ExtendedBlockPtr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, @@ -437,7 +437,7 @@ impl fmt::Debug for BlockPtrExt { } } -impl slog::Value for BlockPtrExt { +impl slog::Value for ExtendedBlockPtr { fn serialize( &self, record: &slog::Record, @@ -448,7 +448,7 @@ impl slog::Value for BlockPtrExt { } } -impl IntoValue for BlockPtrExt { +impl IntoValue for ExtendedBlockPtr { fn into_value(self) -> r::Value { object! { __typename: "Block", @@ -460,7 +460,7 @@ impl IntoValue for BlockPtrExt { } } -impl TryFrom<(Option, Option, H256, U256)> for BlockPtrExt { +impl TryFrom<(Option, Option, H256, U256)> for ExtendedBlockPtr { type Error = anyhow::Error; fn try_from(tuple: (Option, Option, H256, U256)) -> Result { @@ -474,7 +474,7 @@ impl TryFrom<(Option, Option, H256, U256)> for BlockPtrExt { let block_number = i32::try_from(number).map_err(|_| anyhow!("Block number out of range"))?; - Ok(BlockPtrExt { + Ok(ExtendedBlockPtr { hash: hash.into(), number: block_number, parent_hash: parent_hash.into(), @@ -483,13 +483,13 @@ impl TryFrom<(Option, Option, H256, U256)> for BlockPtrExt { } } -impl TryFrom<(H256, i32, H256, U256)> for BlockPtrExt { +impl TryFrom<(H256, i32, H256, U256)> for ExtendedBlockPtr { type Error = anyhow::Error; fn try_from(tuple: (H256, i32, H256, U256)) -> Result { let (hash, block_number, parent_hash, timestamp) = tuple; - Ok(BlockPtrExt { + Ok(ExtendedBlockPtr { hash: hash.into(), number: block_number, parent_hash: parent_hash.into(), @@ -497,14 +497,14 @@ impl TryFrom<(H256, i32, H256, U256)> for BlockPtrExt { }) } } -impl From for H256 { - fn from(ptr: BlockPtrExt) -> Self { +impl From for H256 { + fn from(ptr: ExtendedBlockPtr) -> Self { ptr.hash_as_h256() } } -impl From for BlockNumber { - fn from(ptr: BlockPtrExt) -> Self { +impl From for BlockNumber { + fn from(ptr: ExtendedBlockPtr) -> Self { ptr.number } } @@ -653,8 +653,8 @@ mod tests { } "#; - // Deserialize the JSON string into a BlockPtrExt - let block_ptr_ext: BlockPtrExt = + // Deserialize the JSON string into a ExtendedBlockPtr + let block_ptr_ext: ExtendedBlockPtr = serde_json::from_str(json_data).expect("Deserialization failed"); // Verify the deserialized values @@ -672,7 +672,7 @@ mod tests { } "#; - let result: Result = serde_json::from_str(invalid_json_data); + let result: Result = serde_json::from_str(invalid_json_data); assert!( result.is_err(), diff --git a/graph/src/components/store/traits.rs b/graph/src/components/store/traits.rs index af43bd1b605..244a831f4a1 100644 --- a/graph/src/components/store/traits.rs +++ b/graph/src/components/store/traits.rs @@ -7,7 +7,7 @@ use web3::types::{Address, H256}; use super::*; use crate::blockchain::block_stream::{EntityWithType, FirehoseCursor}; -use crate::blockchain::{BlockPtrExt, BlockTime, ChainIdentifier}; +use crate::blockchain::{BlockTime, ChainIdentifier, ExtendedBlockPtr}; use crate::components::metrics::stopwatch::StopwatchMetrics; use crate::components::server::index_node::VersionInfo; use crate::components::subgraph::SubgraphVersionSwitchingMode; @@ -500,7 +500,7 @@ pub trait ChainStore: Send + Sync + 'static { async fn block_ptrs_by_numbers( self: Arc, numbers: Vec, - ) -> Result>, Error>; + ) -> Result>, Error>; /// Get the `offset`th ancestor of `block_hash`, where offset=0 means the block matching /// `block_hash` and offset=1 means its parent. If `root` is passed, short-circuit upon finding diff --git a/store/postgres/src/chain_store.rs b/store/postgres/src/chain_store.rs index daf0e70a4d1..097aa799eff 100644 --- a/store/postgres/src/chain_store.rs +++ b/store/postgres/src/chain_store.rs @@ -22,7 +22,7 @@ use std::{ sync::Arc, }; -use graph::blockchain::{Block, BlockHash, BlockPtrExt, ChainIdentifier}; +use graph::blockchain::{Block, BlockHash, ChainIdentifier, ExtendedBlockPtr}; use graph::cheap_clone::CheapClone; use graph::prelude::web3::types::{H256, U256}; use graph::prelude::{ @@ -1958,7 +1958,7 @@ impl ChainStore { } } -fn json_block_to_block_ptr_ext(json_block: &JsonBlock) -> Result { +fn json_block_to_block_ptr_ext(json_block: &JsonBlock) -> Result { let hash = json_block.ptr.hash.clone(); let number = json_block.ptr.number; let parent_hash = json_block.parent_hash.clone(); @@ -1967,8 +1967,9 @@ fn json_block_to_block_ptr_ext(json_block: &JsonBlock) -> Result, numbers: Vec, - ) -> Result>, Error> { + ) -> Result>, Error> { let result = if ENV_VARS.store.disable_block_cache_for_lookup { let values = self.blocks_from_store_by_numbers(numbers).await?;