Skip to content

Commit

Permalink
chain, graph: rename BlockPtrExt to ExtendedBlockPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
incrypto32 committed Dec 10, 2024
1 parent ae66751 commit 3bd36f6
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 35 deletions.
4 changes: 2 additions & 2 deletions chain/ethereum/src/adapter.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -1115,7 +1115,7 @@ pub trait EthereumAdapter: Send + Sync + 'static {
_logger: Logger,
_chain_store: Arc<dyn ChainStore>,
_block_numbers: HashSet<BlockNumber>,
) -> Box<dyn Stream<Item = Arc<BlockPtrExt>, Error = Error> + Send>;
) -> Box<dyn Stream<Item = Arc<ExtendedBlockPtr>, 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.
Expand Down
6 changes: 3 additions & 3 deletions chain/ethereum/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, SourceableStore};
Expand Down Expand Up @@ -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<BlockPtrExt>),
Ptr(Arc<ExtendedBlockPtr>),
}

impl Default for BlockFinality {
Expand Down
10 changes: 5 additions & 5 deletions chain/ethereum/src/ethereum_adapter.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -788,7 +788,7 @@ impl EthereumAdapter {
&self,
logger: Logger,
numbers: Vec<BlockNumber>,
) -> impl Stream<Item = Arc<BlockPtrExt>, Error = Error> + Send {
) -> impl Stream<Item = Arc<ExtendedBlockPtr>, Error = Error> + Send {
let web3 = self.web3.clone();

stream::iter_ok::<_, Error>(numbers.into_iter().map(move |number| {
Expand All @@ -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,
Expand Down Expand Up @@ -1706,7 +1706,7 @@ impl EthereumAdapterTrait for EthereumAdapter {
logger: Logger,
chain_store: Arc<dyn ChainStore>,
block_numbers: HashSet<BlockNumber>,
) -> Box<dyn Stream<Item = Arc<BlockPtrExt>, Error = Error> + Send> {
) -> Box<dyn Stream<Item = Arc<ExtendedBlockPtr>, Error = Error> + Send> {
let blocks_map = chain_store
.cheap_clone()
.block_ptrs_by_numbers(block_numbers.iter().map(|&b| b.into()).collect::<Vec<_>>())
Expand All @@ -1717,7 +1717,7 @@ impl EthereumAdapterTrait for EthereumAdapter {
})
.unwrap_or_default();

let mut blocks: Vec<Arc<BlockPtrExt>> = blocks_map
let mut blocks: Vec<Arc<ExtendedBlockPtr>> = blocks_map
.into_iter()
.filter_map(|(_number, values)| {
if values.len() == 1 {
Expand Down
2 changes: 1 addition & 1 deletion graph/src/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
34 changes: 17 additions & 17 deletions graph/src/blockchain/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,15 @@ 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,
pub parent_hash: BlockHash,
pub timestamp: U256,
}

impl BlockPtrExt {
impl ExtendedBlockPtr {
pub fn new(
hash: BlockHash,
number: BlockNumber,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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",
Expand All @@ -460,7 +460,7 @@ impl IntoValue for BlockPtrExt {
}
}

impl TryFrom<(Option<H256>, Option<U64>, H256, U256)> for BlockPtrExt {
impl TryFrom<(Option<H256>, Option<U64>, H256, U256)> for ExtendedBlockPtr {
type Error = anyhow::Error;

fn try_from(tuple: (Option<H256>, Option<U64>, H256, U256)) -> Result<Self, Self::Error> {
Expand All @@ -474,7 +474,7 @@ impl TryFrom<(Option<H256>, Option<U64>, 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(),
Expand All @@ -483,28 +483,28 @@ impl TryFrom<(Option<H256>, Option<U64>, 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<Self, Self::Error> {
let (hash, block_number, parent_hash, timestamp) = tuple;

Ok(BlockPtrExt {
Ok(ExtendedBlockPtr {
hash: hash.into(),
number: block_number,
parent_hash: parent_hash.into(),
timestamp,
})
}
}
impl From<BlockPtrExt> for H256 {
fn from(ptr: BlockPtrExt) -> Self {
impl From<ExtendedBlockPtr> for H256 {
fn from(ptr: ExtendedBlockPtr) -> Self {
ptr.hash_as_h256()
}
}

impl From<BlockPtrExt> for BlockNumber {
fn from(ptr: BlockPtrExt) -> Self {
impl From<ExtendedBlockPtr> for BlockNumber {
fn from(ptr: ExtendedBlockPtr) -> Self {
ptr.number
}
}
Expand Down Expand Up @@ -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
Expand All @@ -672,7 +672,7 @@ mod tests {
}
"#;

let result: Result<BlockPtrExt, _> = serde_json::from_str(invalid_json_data);
let result: Result<ExtendedBlockPtr, _> = serde_json::from_str(invalid_json_data);

assert!(
result.is_err(),
Expand Down
4 changes: 2 additions & 2 deletions graph/src/components/store/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -526,7 +526,7 @@ pub trait ChainStore: Send + Sync + 'static {
async fn block_ptrs_by_numbers(
self: Arc<Self>,
numbers: Vec<BlockNumber>,
) -> Result<BTreeMap<BlockNumber, Vec<BlockPtrExt>>, Error>;
) -> Result<BTreeMap<BlockNumber, Vec<ExtendedBlockPtr>>, 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
Expand Down
11 changes: 6 additions & 5 deletions store/postgres/src/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -1958,7 +1958,7 @@ impl ChainStore {
}
}

fn json_block_to_block_ptr_ext(json_block: &JsonBlock) -> Result<BlockPtrExt, Error> {
fn json_block_to_block_ptr_ext(json_block: &JsonBlock) -> Result<ExtendedBlockPtr, Error> {
let hash = json_block.ptr.hash.clone();
let number = json_block.ptr.number;
let parent_hash = json_block.parent_hash.clone();
Expand All @@ -1967,8 +1967,9 @@ fn json_block_to_block_ptr_ext(json_block: &JsonBlock) -> Result<BlockPtrExt, Er
.timestamp()
.ok_or_else(|| anyhow!("Timestamp is missing"))?;

let ptr = BlockPtrExt::try_from((hash.as_h256(), number, parent_hash.as_h256(), timestamp))
.map_err(|e| anyhow!("Failed to convert to BlockPtrExt: {}", e))?;
let ptr =
ExtendedBlockPtr::try_from((hash.as_h256(), number, parent_hash.as_h256(), timestamp))
.map_err(|e| anyhow!("Failed to convert to ExtendedBlockPtr: {}", e))?;

Ok(ptr)
}
Expand Down Expand Up @@ -2168,7 +2169,7 @@ impl ChainStoreTrait for ChainStore {
async fn block_ptrs_by_numbers(
self: Arc<Self>,
numbers: Vec<BlockNumber>,
) -> Result<BTreeMap<BlockNumber, Vec<BlockPtrExt>>, Error> {
) -> Result<BTreeMap<BlockNumber, Vec<ExtendedBlockPtr>>, Error> {
let result = if ENV_VARS.store.disable_block_cache_for_lookup {
let values = self.blocks_from_store_by_numbers(numbers).await?;

Expand Down

0 comments on commit 3bd36f6

Please sign in to comment.