diff --git a/Cargo.toml b/Cargo.toml index cfe09925a4a..f046dcc7a6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ members = [ [workspace.package] version = "0.42.1" -edition = "2021" +edition = "2024" authors = ["The Graph core developers & contributors"] readme = "README.md" homepage = "https://thegraph.com" diff --git a/chain/common/src/lib.rs b/chain/common/src/lib.rs index b8f2ae47eb4..395dd440c84 100644 --- a/chain/common/src/lib.rs +++ b/chain/common/src/lib.rs @@ -2,13 +2,13 @@ use std::collections::HashMap; use std::fmt::Debug; use anyhow::Error; -use protobuf::descriptor::field_descriptor_proto::Label; -use protobuf::descriptor::field_descriptor_proto::Type; +use protobuf::Message; +use protobuf::UnknownValueRef; use protobuf::descriptor::DescriptorProto; use protobuf::descriptor::FieldDescriptorProto; use protobuf::descriptor::OneofDescriptorProto; -use protobuf::Message; -use protobuf::UnknownValueRef; +use protobuf::descriptor::field_descriptor_proto::Label; +use protobuf::descriptor::field_descriptor_proto::Type; use std::convert::From; use std::path::Path; diff --git a/chain/common/tests/test-acme.rs b/chain/common/tests/test-acme.rs index cd0b32b8582..2945fea337e 100644 --- a/chain/common/tests/test-acme.rs +++ b/chain/common/tests/test-acme.rs @@ -7,8 +7,8 @@ fn check_repeated_type_ok() { let types = parse_proto_file(PROTO_FILE).expect("Unable to read proto file!"); let array_types = types - .iter() - .flat_map(|(_, t)| t.fields.iter()) + .values() + .flat_map(|t| t.fields.iter()) .filter(|t| t.is_array) .map(|t| t.type_name.clone()) .collect::>(); diff --git a/chain/ethereum/examples/firehose.rs b/chain/ethereum/examples/firehose.rs index 45199a0ec89..3dd21859653 100644 --- a/chain/ethereum/examples/firehose.rs +++ b/chain/ethereum/examples/firehose.rs @@ -4,7 +4,7 @@ use graph::{ env::env_var, firehose::{self, FirehoseEndpoint, SubgraphLimit}, log::logger, - prelude::{prost, tokio, tonic, MetricsRegistry}, + prelude::{MetricsRegistry, prost, tokio, tonic}, }; use graph_chain_ethereum::codec; use hex::ToHex; diff --git a/chain/ethereum/src/adapter.rs b/chain/ethereum/src/adapter.rs index 5f7fb7d84c0..7a5be3fa0c6 100644 --- a/chain/ethereum/src/adapter.rs +++ b/chain/ethereum/src/adapter.rs @@ -35,7 +35,7 @@ const COMBINED_FILTER_TYPE_URL: &str = use crate::capabilities::NodeCapabilities; use crate::data_source::{BlockHandlerFilter, DataSource}; -use crate::{Chain, Mapping, ENV_VARS}; +use crate::{Chain, ENV_VARS, Mapping}; pub type EventSignature = B256; pub type FunctionSelector = [u8; 4]; @@ -1186,7 +1186,7 @@ pub trait EthereumAdapter: Send + Sync + 'static { #[cfg(test)] mod tests { - use crate::adapter::{FunctionSelector, COMBINED_FILTER_TYPE_URL}; + use crate::adapter::{COMBINED_FILTER_TYPE_URL, FunctionSelector}; use super::{EthereumBlockFilter, LogFilterNode}; use super::{EthereumCallFilter, EthereumLogFilter, TriggerFilter}; @@ -1195,8 +1195,8 @@ mod tests { use graph::blockchain::TriggerFilter as _; use graph::firehose::{CallToFilter, CombinedFilter, LogFilter, MultiLogFilter}; use graph::petgraph::graphmap::GraphMap; - use graph::prelude::alloy::primitives::{Address, Bytes, B256, U256}; use graph::prelude::EthereumCall; + use graph::prelude::alloy::primitives::{Address, B256, Bytes, U256}; use hex::ToHex; use itertools::Itertools; use prost::Message; @@ -1264,9 +1264,11 @@ mod tests { assert_eq!(sig, actual_sig); let filter = LogFilter { - addresses: vec![Address::from_str(hex_addr) - .expect("failed to parse address") - .to_vec()], + addresses: vec![ + Address::from_str(hex_addr) + .expect("failed to parse address") + .to_vec(), + ], event_signatures: vec![fs.to_vec()], }; @@ -1651,8 +1653,8 @@ mod tests { } #[test] - fn extending_ethereum_block_filter_every_block_in_base_and_merge_contract_addresses_and_polling_intervals( - ) { + fn extending_ethereum_block_filter_every_block_in_base_and_merge_contract_addresses_and_polling_intervals() + { let mut base = EthereumBlockFilter { polling_intervals: HashSet::from_iter(vec![(10, 3)]), contract_addresses: HashSet::from_iter(vec![(10, address(2))]), diff --git a/chain/ethereum/src/buffered_call_cache.rs b/chain/ethereum/src/buffered_call_cache.rs index 2ec0bfa40e7..29aa84e90ab 100644 --- a/chain/ethereum/src/buffered_call_cache.rs +++ b/chain/ethereum/src/buffered_call_cache.rs @@ -9,7 +9,7 @@ use graph::{ components::store::EthereumCallCache, data::store::ethereum::call, prelude::{BlockPtr, CachedEthereumCall}, - slog::{error, Logger}, + slog::{Logger, error}, }; /// A wrapper around an Ethereum call cache that buffers call results in diff --git a/chain/ethereum/src/call_helper.rs b/chain/ethereum/src/call_helper.rs index ef0b85fc293..969b8a7e2cc 100644 --- a/chain/ethereum/src/call_helper.rs +++ b/chain/ethereum/src/call_helper.rs @@ -3,8 +3,9 @@ use graph::{ abi, data::store::ethereum::call, prelude::{ + Logger, alloy::transports::{RpcError, TransportErrorKind}, - serde_json, Logger, + serde_json, }, slog::info, }; @@ -93,10 +94,10 @@ pub fn interpret_eth_call_error( Ok(call::Retval::Null) } - if let RpcError::ErrorResp(rpc_error) = &err { - if is_rpc_revert_message(&rpc_error.message) { - return reverted(logger, &rpc_error.message); - } + if let RpcError::ErrorResp(rpc_error) = &err + && is_rpc_revert_message(&rpc_error.message) + { + return reverted(logger, &rpc_error.message); } if let RpcError::ErrorResp(rpc_error) = &err { @@ -106,12 +107,11 @@ pub fn interpret_eth_call_error( .as_ref() .and_then(|d| serde_json::from_str(d.get()).ok()); - if code == PARITY_VM_EXECUTION_ERROR { - if let Some(data) = data { - if is_parity_revert(&data) { - return reverted(logger, &parity_revert_reason(&data)); - } - } + if code == PARITY_VM_EXECUTION_ERROR + && let Some(data) = data + && is_parity_revert(&data) + { + return reverted(logger, &parity_revert_reason(&data)); } } diff --git a/chain/ethereum/src/chain.rs b/chain/ethereum/src/chain.rs index ee7d45ca2a6..0593a6af4b0 100644 --- a/chain/ethereum/src/chain.rs +++ b/chain/ethereum/src/chain.rs @@ -1,5 +1,5 @@ -use anyhow::{anyhow, bail, Result}; use anyhow::{Context, Error}; +use anyhow::{Result, anyhow, bail}; use async_trait::async_trait; use graph::blockchain::client::ChainClient; use graph::blockchain::firehose_block_ingestor::{FirehoseBlockIngestor, Transforms}; @@ -13,26 +13,27 @@ use graph::data::subgraph::UnifiedMappingApiVersion; use graph::firehose::{FirehoseEndpoint, FirehoseEndpoints, ForkStep}; use graph::futures03::TryStreamExt; use graph::prelude::{ - retry, BlockHash, ComponentLoggerConfig, ElasticComponentLoggerConfig, EthereumBlock, + BlockHash, ComponentLoggerConfig, ElasticComponentLoggerConfig, EthereumBlock, EthereumCallCache, LightEthereumBlock, LightEthereumBlockExt, MetricsRegistry, StoreError, + retry, }; use graph::slog::{debug, error, trace, warn}; use graph::{ blockchain::{ + Block, BlockPtr, Blockchain, ChainHeadUpdateListener, IngestorError, + RuntimeAdapter as RuntimeAdapterTrait, TriggerFilter as _, block_stream::{ BlockRefetcher, BlockStreamEvent, BlockWithTriggers, FirehoseError, FirehoseMapper as FirehoseMapperTrait, TriggersAdapter as TriggersAdapterTrait, }, firehose_block_stream::FirehoseBlockStream, - Block, BlockPtr, Blockchain, ChainHeadUpdateListener, IngestorError, - RuntimeAdapter as RuntimeAdapterTrait, TriggerFilter as _, }, cheap_clone::CheapClone, components::store::DeploymentLocator, firehose, prelude::{ - o, serde_json as json, BlockNumber, ChainStore, EthereumBlockWithCalls, Logger, - LoggerFactory, + BlockNumber, ChainStore, EthereumBlockWithCalls, Logger, LoggerFactory, o, + serde_json as json, }, }; use prost::Message; @@ -49,7 +50,9 @@ use crate::ingestor::PollingBlockIngestor; use crate::network::EthereumNetworkAdapters; use crate::polling_block_stream::PollingBlockStream; use crate::runtime::runtime_adapter::eth_call_gas; +use crate::{BufferedCallCache, NodeCapabilities}; use crate::{ + ENV_VARS, SubgraphEthRpcMetrics, TriggerFilter, adapter::EthereumAdapter as _, codec, data_source::{DataSource, UnresolvedDataSource}, @@ -57,9 +60,7 @@ use crate::{ blocks_with_triggers, get_calls, parse_block_triggers, parse_call_triggers, parse_log_triggers, }, - SubgraphEthRpcMetrics, TriggerFilter, ENV_VARS, }; -use crate::{BufferedCallCache, NodeCapabilities}; use crate::{EthereumAdapter, RuntimeAdapter}; use graph::blockchain::block_stream::{ BlockStream, BlockStreamBuilder, BlockStreamError, BlockStreamMapper, FirehoseCursor, @@ -396,10 +397,10 @@ where for _ in 0..offset { match parent_getter(current_ptr.clone()).await? { Some(parent) => { - if let Some(root_hash) = &root { - if parent.hash == *root_hash { - break; - } + if let Some(root_hash) = &root + && parent.hash == *root_hash + { + break; } current_ptr = parent; } @@ -815,8 +816,8 @@ async fn fetch_unique_blocks_from_cache( // Collect blocks and filter out ones with multiple entries let blocks: Vec> = blocks_map - .into_iter() - .filter_map(|(_, values)| { + .into_values() + .filter_map(|values| { if values.len() == 1 { Some(Arc::new(values[0].clone())) } else { @@ -1372,7 +1373,9 @@ impl FirehoseMapperTrait for FirehoseMapper { } StepFinal => { - unreachable!("irreversible step is not handled and should not be requested in the Firehose request") + unreachable!( + "irreversible step is not handled and should not be requested in the Firehose request" + ) } StepUnset => { diff --git a/chain/ethereum/src/codec.rs b/chain/ethereum/src/codec.rs index 8a73ce83136..d809713aefd 100644 --- a/chain/ethereum/src/codec.rs +++ b/chain/ethereum/src/codec.rs @@ -12,15 +12,15 @@ use graph::{ AnyBlock, AnyHeader, AnyRpcHeader, AnyTransactionReceiptBare, AnyTxEnvelope, }, prelude::{ + BlockNumber, Error, EthereumBlock, EthereumBlockWithCalls, EthereumCall, + LightEthereumBlock, alloy::{ self, consensus::{ReceiptWithBloom, TxEnvelope, TxType}, network::AnyReceiptEnvelope, - primitives::{aliases::B2048, Address, Bloom, Bytes, LogData, B256, U256}, + primitives::{Address, B256, Bloom, Bytes, LogData, U256, aliases::B2048}, rpc::types::{self as alloy_rpc_types, AccessList, AccessListItem, Transaction}, }, - BlockNumber, Error, EthereumBlock, EthereumBlockWithCalls, EthereumCall, - LightEthereumBlock, }, }; use std::sync::Arc; @@ -650,7 +650,7 @@ fn transaction_trace_to_alloy_txn_reciept( TransactionTraceStatus::Unknown => { return Err(format_err!( "Transaction trace has UNKNOWN status; datasource is broken" - )) + )); } TransactionTraceStatus::Succeeded => true, TransactionTraceStatus::Failed | TransactionTraceStatus::Reverted => false, diff --git a/chain/ethereum/src/data_source.rs b/chain/ethereum/src/data_source.rs index b2303b6d053..98b63c46fb2 100644 --- a/chain/ethereum/src/data_source.rs +++ b/chain/ethereum/src/data_source.rs @@ -1,5 +1,5 @@ -use anyhow::{anyhow, Error}; -use anyhow::{ensure, Context}; +use anyhow::{Context, ensure}; +use anyhow::{Error, anyhow}; use async_trait::async_trait; use graph::abi; use graph::abi::EventExt; @@ -18,16 +18,16 @@ use graph::data_source::common::{ }; use graph::data_source::{CausalityRegion, MappingTrigger as MappingTriggerType}; use graph::env::ENV_VARS; +use graph::futures03::TryStreamExt; use graph::futures03::future::try_join; use graph::futures03::stream::FuturesOrdered; -use graph::futures03::TryStreamExt; use graph::prelude::alloy::{ consensus::{TxEnvelope, TxLegacy}, network::TransactionResponse, primitives::{Address, B256, U256}, rpc::types::Log, }; -use graph::prelude::{alloy, Link, SubgraphManifestValidationError}; +use graph::prelude::{Link, SubgraphManifestValidationError, alloy}; use graph::slog::{debug, error, o, trace}; use itertools::Itertools; use serde::de::Error as ErrorD; @@ -37,26 +37,26 @@ use std::num::NonZeroU32; use std::str::FromStr; use std::sync::Arc; use std::time::{Duration, Instant}; -use tiny_keccak::{keccak256, Keccak}; +use tiny_keccak::{Keccak, keccak256}; use graph::{ blockchain::{self, Blockchain}, prelude::{ - serde_json, warn, BlockNumber, CheapClone, EthereumCall, LightEthereumBlock, - LightEthereumBlockExt, LinkResolver, Logger, + BlockNumber, CheapClone, EthereumCall, LightEthereumBlock, LightEthereumBlockExt, + LinkResolver, Logger, serde_json, warn, }, }; use graph::data::subgraph::{ - calls_host_fn, DataSourceContext, Source, MIN_SPEC_VERSION, SPEC_VERSION_0_0_8, - SPEC_VERSION_1_2_0, + DataSourceContext, MIN_SPEC_VERSION, SPEC_VERSION_0_0_8, SPEC_VERSION_1_2_0, Source, + calls_host_fn, }; +use crate::NodeCapabilities; use crate::adapter::EthereumAdapter as _; use crate::chain::Chain; use crate::network::EthereumNetworkAdapters; use crate::trigger::{EthereumBlockTriggerType, EthereumTrigger, MappingTrigger}; -use crate::NodeCapabilities; // The recommended kind is `ethereum`, `ethereum/contract` is accepted for backwards compatibility. const ETHEREUM_KINDS: &[&str] = &["ethereum/contract", "ethereum"]; @@ -446,7 +446,7 @@ fn create_dummy_transaction( ) -> Result { use graph::components::ethereum::AnyTxEnvelope; use graph::prelude::alloy::{ - consensus::transaction::Recovered, consensus::Signed, primitives::Signature, + consensus::Signed, consensus::transaction::Recovered, primitives::Signature, rpc::types::Transaction, }; diff --git a/chain/ethereum/src/env.rs b/chain/ethereum/src/env.rs index 027a26b623f..776fcfa7b3f 100644 --- a/chain/ethereum/src/env.rs +++ b/chain/ethereum/src/env.rs @@ -1,6 +1,6 @@ use envconfig::Envconfig; use graph::env::EnvVarBoolean; -use graph::prelude::{envconfig, lazy_static, BlockNumber}; +use graph::prelude::{BlockNumber, envconfig, lazy_static}; use std::fmt; use std::time::Duration; diff --git a/chain/ethereum/src/ethereum_adapter.rs b/chain/ethereum/src/ethereum_adapter.rs index e58055a97a7..2f5ee56dd77 100644 --- a/chain/ethereum/src/ethereum_adapter.rs +++ b/chain/ethereum/src/ethereum_adapter.rs @@ -3,24 +3,24 @@ use futures03::{future::BoxFuture, stream::FuturesUnordered}; use graph::abi; use graph::abi::DynSolValueExt; use graph::abi::FunctionExt; -use graph::blockchain::client::ChainClient; use graph::blockchain::BlockHash; use graph::blockchain::ChainIdentifier; use graph::blockchain::ExtendedBlockPtr; +use graph::blockchain::client::ChainClient; use graph::components::ethereum::*; use graph::components::transaction_receipt::LightTransactionReceipt; use graph::data::store::ethereum::call; use graph::data::store::scalar; -use graph::data::subgraph::UnifiedMappingApiVersion; use graph::data::subgraph::API_VERSION_0_0_7; +use graph::data::subgraph::UnifiedMappingApiVersion; use graph::data_source::common::ContractCall; use graph::derive::CheapClone; -use graph::futures01::stream; use graph::futures01::Future; use graph::futures01::Stream; +use graph::futures01::stream; use graph::futures03::future::try_join_all; use graph::futures03::{ - self, compat::Future01CompatExt, FutureExt, StreamExt, TryFutureExt, TryStreamExt, + self, FutureExt, StreamExt, TryFutureExt, TryStreamExt, compat::Future01CompatExt, }; use graph::prelude::{ alloy::{ @@ -28,15 +28,15 @@ use graph::prelude::{ network::TransactionResponse, primitives::{Address, B256}, providers::{ + Identity, Provider, RootProvider, ext::TraceApi, fillers::{ BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller, }, - Identity, Provider, RootProvider, }, rpc::types::{ - trace::{filter::TraceFilter as AlloyTraceFilter, parity::LocalizedTransactionTrace}, TransactionInput, TransactionRequest, + trace::{filter::TraceFilter as AlloyTraceFilter, parity::LocalizedTransactionTrace}, }, transports::{RpcError, TransportErrorKind}, }, @@ -44,11 +44,12 @@ use graph::prelude::{ }; use graph::slog::o; use graph::{ - blockchain::{block_stream::BlockWithTriggers, BlockPtr, IngestorError}, + blockchain::{BlockPtr, IngestorError, block_stream::BlockWithTriggers}, prelude::{ - anyhow::{self, anyhow, bail, ensure, Context}, - debug, error, hex, info, retry, trace, warn, BlockNumber, ChainStore, CheapClone, - DynTryFuture, Error, EthereumCallCache, Logger, TimeoutError, + BlockNumber, ChainStore, CheapClone, DynTryFuture, Error, EthereumCallCache, Logger, + TimeoutError, + anyhow::{self, Context, anyhow, bail, ensure}, + debug, error, hex, info, retry, trace, warn, }, }; use itertools::Itertools; @@ -61,6 +62,9 @@ use std::time::{Duration, Instant}; use tokio::sync::RwLock; use tokio::time::timeout; +use crate::Chain; +use crate::NodeCapabilities; +use crate::TriggerFilter; use crate::adapter::EthGetLogsFilter; use crate::adapter::EthereumRpcError; use crate::adapter::ProviderStatus; @@ -68,17 +72,14 @@ use crate::call_helper::interpret_eth_call_error; use crate::chain::BlockFinality; use crate::chain::ChainSettings; use crate::trigger::{LogPosition, LogRef}; -use crate::Chain; -use crate::NodeCapabilities; -use crate::TriggerFilter; use crate::{ + ENV_VARS, adapter::{ ContractCallError, EthereumAdapter as EthereumAdapterTrait, EthereumBlockFilter, EthereumCallFilter, EthereumLogFilter, ProviderEthRpcMetrics, SubgraphEthRpcMetrics, }, transport::Transport, trigger::{EthereumBlockTriggerType, EthereumTrigger}, - ENV_VARS, }; type AlloyProvider = FillProvider< @@ -1014,7 +1015,8 @@ impl EthereumAdapter { ) -> Pin< Box< dyn std::future::Future, anyhow::Error>> - + std::marker::Send, + + std::marker::Send + + '_, >, > { // Create a HashMap of block numbers to Vec @@ -1053,15 +1055,13 @@ impl EthereumAdapter { let block_futures = blocks_matching_polling_filter.map(move |ptrs| { ptrs.into_iter() .flat_map(|ptr| { - let triggers = matching_blocks + matching_blocks .get(&ptr.number) // Safe to unwrap since we are iterating over ptrs which was created from // the keys of matching_blocks .unwrap() .iter() - .map(move |trigger| EthereumTrigger::Block(ptr.clone(), trigger.clone())); - - triggers + .map(move |trigger| EthereumTrigger::Block(ptr.clone(), trigger.clone())) }) .collect::>() }); @@ -1126,7 +1126,7 @@ impl EthereumAdapter { logger: Logger, from: BlockNumber, to: BlockNumber, - ) -> Box, Error = Error> + Send> { + ) -> Box, Error = Error> + Send + '_> { // Currently we can't go to the DB for this because there might be duplicate entries for // the same block number. debug!(&logger, "Requesting hashes for blocks [{}, {}]", from, to); @@ -1140,7 +1140,7 @@ impl EthereumAdapter { &self, logger: Logger, blocks: Vec, - ) -> Box, Error = Error> + Send> { + ) -> Box, Error = Error> + Send + '_> { // Currently we can't go to the DB for this because there might be duplicate entries for // the same block number. debug!(&logger, "Requesting hashes for blocks {:?}", blocks); @@ -1587,15 +1587,26 @@ impl EthereumAdapterTrait for EthereumAdapter { fn log_call_error(logger: &ProviderLogger, e: &ContractCallError, call: &ContractCall) { match e { - ContractCallError::AlloyError(e) => error!(logger, + ContractCallError::AlloyError(e) => error!( + logger, "Ethereum node returned an error when calling function \"{}\" of contract \"{}\": {}", - call.function.name, call.contract_name, e), - ContractCallError::Timeout => error!(logger, + call.function.name, + call.contract_name, + e + ), + ContractCallError::Timeout => error!( + logger, "Ethereum node did not respond when calling function \"{}\" of contract \"{}\"", - call.function.name, call.contract_name), - _ => error!(logger, + call.function.name, + call.contract_name + ), + _ => error!( + logger, "Failed to call function \"{}\" of contract \"{}\": {}", - call.function.name, call.contract_name, e), + call.function.name, + call.contract_name, + e + ), } } @@ -2125,7 +2136,7 @@ async fn filter_call_triggers_from_unsuccessful_transactions( // And obtain all Transaction values for the calls in this block. let transactions: Vec<&AnyTransaction> = { match &block.block { - BlockFinality::Final(ref block) => block + BlockFinality::Final(block) => block .transactions() .ok_or_else(|| anyhow!("Block transactions not available"))? .iter() @@ -2696,15 +2707,15 @@ mod tests { use crate::trigger::{EthereumBlockTriggerType, EthereumTrigger}; use super::{ - check_block_receipt_support, parse_block_triggers, EthereumBlock, EthereumBlockFilter, - EthereumBlockWithCalls, + EthereumBlock, EthereumBlockFilter, EthereumBlockWithCalls, check_block_receipt_support, + parse_block_triggers, }; use graph::blockchain::BlockPtr; use graph::components::ethereum::AnyNetworkBare; - use graph::prelude::alloy::primitives::{Address, Bytes, B256}; - use graph::prelude::alloy::providers::mock::Asserter; + use graph::prelude::alloy::primitives::{Address, B256, Bytes}; use graph::prelude::alloy::providers::ProviderBuilder; - use graph::prelude::{create_minimal_block_for_test, EthereumCall, LightEthereumBlock}; + use graph::prelude::alloy::providers::mock::Asserter; + use graph::prelude::{EthereumCall, LightEthereumBlock, create_minimal_block_for_test}; use jsonrpc_core::serde_json::{self, Value}; use std::collections::HashSet; use std::iter::FromIterator; diff --git a/chain/ethereum/src/ingestor.rs b/chain/ethereum/src/ingestor.rs index e2d469a3954..dcbcc42c6f8 100644 --- a/chain/ethereum/src/ingestor.rs +++ b/chain/ethereum/src/ingestor.rs @@ -1,9 +1,9 @@ -use crate::{chain::BlockFinality, ENV_VARS}; +use crate::{ENV_VARS, chain::BlockFinality}; use crate::{EthereumAdapter, EthereumAdapterTrait as _}; use async_trait::async_trait; use futures::future::select_ok; -use graph::blockchain::client::ChainClient; use graph::blockchain::BlockchainKind; +use graph::blockchain::client::ChainClient; use graph::components::network_provider::ChainName; use graph::prelude::alloy::primitives::B256; use graph::slog::o; @@ -12,8 +12,8 @@ use graph::{ blockchain::{BlockHash, BlockIngestor, BlockPtr, IngestorError}, cheap_clone::CheapClone, prelude::{ - debug, error, info, tokio, trace, warn, ChainStore, Error, EthereumBlockWithCalls, LogCode, - Logger, + ChainStore, Error, EthereumBlockWithCalls, LogCode, Logger, debug, error, info, tokio, + trace, warn, }, }; use std::{sync::Arc, time::Duration}; @@ -281,10 +281,10 @@ async fn on_poll_failure( // at the match level. If the current provider responds to eth_blockNumber, the // failure was not caused by provider unavailability — switching cannot help. let current = providers.iter().find(|p| p.provider() == current_name); - if let Some(current) = current { - if current.is_reachable().await { - return; - } + if let Some(current) = current + && current.is_reachable().await + { + return; } // Probe all alternatives in parallel; switch to the first that responds. @@ -378,7 +378,7 @@ mod tests { use graph::components::ethereum::LightEthereumBlock; use graph::data::store::ethereum::call; use graph::data_source::common::ContractCall; - use graph::prelude::alloy::primitives::{Address, Bytes, B256, U256}; + use graph::prelude::alloy::primitives::{Address, B256, Bytes, U256}; use graph::prelude::{BlockNumber, Error, EthereumCallCache, Logger}; use graph::slog::Discard; use std::collections::HashSet; diff --git a/chain/ethereum/src/network.rs b/chain/ethereum/src/network.rs index efd6bc6d317..ad9cd0a83c0 100644 --- a/chain/ethereum/src/network.rs +++ b/chain/ethereum/src/network.rs @@ -15,9 +15,9 @@ use std::sync::Arc; pub use graph::impl_slog_value; use graph::prelude::Error; +use crate::EthereumAdapter; use crate::adapter::EthereumAdapter as _; use crate::capabilities::NodeCapabilities; -use crate::EthereumAdapter; pub const DEFAULT_ADAPTER_ERROR_RETEST_PERCENT: f64 = 0.2; @@ -107,7 +107,7 @@ impl EthereumNetworkAdapters { use std::cmp::Ordering; use graph::components::network_provider::ProviderCheckStrategy; - use graph::slog::{o, Discard, Logger}; + use graph::slog::{Discard, Logger, o}; let chain_id: ChainName = "testing".into(); adapters.sort_by(|a, b| { @@ -118,7 +118,7 @@ impl EthereumNetworkAdapters { let provider = ProviderManager::new( Logger::root(Discard, o!()), - vec![(chain_id.clone(), adapters)].into_iter(), + vec![(chain_id.clone(), adapters)], ProviderCheckStrategy::MarkAsValid, ); @@ -329,14 +329,14 @@ mod tests { endpoint::EndpointMetrics, firehose::SubgraphLimit, prelude::MetricsRegistry, - slog::{o, Discard, Logger}, + slog::{Discard, Logger, o}, url::Url, }; use std::sync::Arc; use crate::{ - chain::ChainSettings, Compression, EthereumAdapter, EthereumAdapterTrait, - ProviderEthRpcMetrics, Transport, + Compression, EthereumAdapter, EthereumAdapterTrait, ProviderEthRpcMetrics, Transport, + chain::ChainSettings, }; use super::{EthereumNetworkAdapter, EthereumNetworkAdapters, NodeCapabilities}; @@ -465,13 +465,15 @@ mod tests { { // Not Found - assert!(adapters - .cheapest_with(&NodeCapabilities { - archive: false, - traces: true, - }) - .await - .is_err()); + assert!( + adapters + .cheapest_with(&NodeCapabilities { + archive: false, + traces: true, + }) + .await + .is_err() + ); // Check cheapest is not call only let adapter = adapters diff --git a/chain/ethereum/src/polling_block_stream.rs b/chain/ethereum/src/polling_block_stream.rs index 55d2aed3df8..339386207f1 100644 --- a/chain/ethereum/src/polling_block_stream.rs +++ b/chain/ethereum/src/polling_block_stream.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Error}; +use anyhow::{Error, anyhow}; use std::cmp; use std::collections::VecDeque; use std::pin::Pin; @@ -7,13 +7,13 @@ use std::task::{Context, Poll}; use std::time::Duration; use graph::blockchain::block_stream::{ - BlockStream, BlockStreamError, BlockStreamEvent, BlockWithTriggers, ChainHeadUpdateStream, - FirehoseCursor, TriggersAdapterWrapper, BUFFERED_BLOCK_STREAM_SIZE, + BUFFERED_BLOCK_STREAM_SIZE, BlockStream, BlockStreamError, BlockStreamEvent, BlockWithTriggers, + ChainHeadUpdateStream, FirehoseCursor, TriggersAdapterWrapper, }; use graph::blockchain::{Block, BlockPtr, TriggerFilterWrapper}; -use graph::futures03::{stream::Stream, Future, FutureExt}; -use graph::prelude::{DeploymentHash, BLOCK_NUMBER_MAX}; -use graph::slog::{info, trace, warn, Logger}; +use graph::futures03::{Future, FutureExt, stream::Stream}; +use graph::prelude::{BLOCK_NUMBER_MAX, DeploymentHash}; +use graph::slog::{Logger, info, trace, warn}; use graph::components::store::BlockNumber; use graph::data::subgraph::UnifiedMappingApiVersion; @@ -182,7 +182,7 @@ impl PollingBlockStreamContext { return Ok(NextBlocks::Done); } ReconciliationStep::Revert(parent_ptr) => { - return Ok(NextBlocks::Revert(parent_ptr)) + return Ok(NextBlocks::Revert(parent_ptr)); } } } @@ -224,10 +224,10 @@ impl PollingBlockStreamContext { // Only continue if the subgraph block ptr is behind the head block ptr. // subgraph_ptr > head_ptr shouldn't happen, but if it does, it's safest to just stop. - if let Some(ptr) = &subgraph_ptr { - if ptr.number >= head_ptr.number { - return Ok(ReconciliationStep::Done); - } + if let Some(ptr) = &subgraph_ptr + && ptr.number >= head_ptr.number + { + return Ok(ReconciliationStep::Done); } // Subgraph ptr is behind head ptr. @@ -569,7 +569,7 @@ impl Stream for PollingBlockStream { } // Yielding blocks from reconciliation process - BlockStreamState::YieldingBlocks(ref mut next_blocks) => { + BlockStreamState::YieldingBlocks(next_blocks) => { match next_blocks.pop_front() { // Yield one block Some(next_block) => { @@ -589,7 +589,7 @@ impl Stream for PollingBlockStream { } // Pausing after an error, before looking for more blocks - BlockStreamState::RetryAfterDelay(ref mut delay) => match delay.as_mut().poll(cx) { + BlockStreamState::RetryAfterDelay(delay) => match delay.as_mut().poll(cx) { Poll::Ready(Ok(..)) | Poll::Ready(Err(_)) => { self.state = BlockStreamState::BeginReconciliation; } diff --git a/chain/ethereum/src/runtime/abi.rs b/chain/ethereum/src/runtime/abi.rs index 8f85866b3d4..4311fed3c48 100644 --- a/chain/ethereum/src/runtime/abi.rs +++ b/chain/ethereum/src/runtime/abi.rs @@ -12,8 +12,8 @@ use graph::prelude::alloy::rpc::types::{Log, TransactionReceipt}; use graph::{ prelude::BigInt, runtime::{ - asc_get, asc_new, asc_new_or_null, gas::GasCounter, AscHeap, AscIndexId, AscPtr, AscType, - DeterministicHostError, FromAscObj, HostExportError, IndexForAscTypeId, ToAscObj, + AscHeap, AscIndexId, AscPtr, AscType, DeterministicHostError, FromAscObj, HostExportError, + IndexForAscTypeId, ToAscObj, asc_get, asc_new, asc_new_or_null, gas::GasCounter, }, }; use graph_runtime_derive::AscType; diff --git a/chain/ethereum/src/runtime/runtime_adapter.rs b/chain/ethereum/src/runtime/runtime_adapter.rs index a5597efcd4d..a5d68a761a7 100644 --- a/chain/ethereum/src/runtime/runtime_adapter.rs +++ b/chain/ethereum/src/runtime/runtime_adapter.rs @@ -2,10 +2,10 @@ use std::{sync::Arc, time::Instant}; use crate::adapter::EthereumRpcError; use crate::{ - capabilities::NodeCapabilities, network::EthereumNetworkAdapters, Chain, ContractCallError, - EthereumAdapter, EthereumAdapterTrait, ENV_VARS, + Chain, ContractCallError, ENV_VARS, EthereumAdapter, EthereumAdapterTrait, + capabilities::NodeCapabilities, network::EthereumNetworkAdapters, }; -use anyhow::{anyhow, Context, Error}; +use anyhow::{Context, Error, anyhow}; use blockchain::HostFn; use graph::abi; use graph::abi::DynSolValueExt; @@ -23,8 +23,8 @@ use graph::{ blockchain::{self, BlockPtr, HostFnCtx}, cheap_clone::CheapClone, futures03::FutureExt, - prelude::{alloy::primitives::Address, EthereumCallCache}, - runtime::{asc_get, asc_new, AscPtr, HostExportError}, + prelude::{EthereumCallCache, alloy::primitives::Address}, + runtime::{AscPtr, HostExportError, asc_get, asc_new}, slog::Logger, }; use graph_runtime_wasm::asc_abi::class::{AscBigInt, AscEnumArray, AscWrapped, EthereumValueKind}; @@ -346,32 +346,34 @@ async fn eth_call( Err(e) => (Err(e), call::Source::Rpc), }; let result = match result { - Ok(res) => Ok(res), + Ok(res) => Ok(res), - // Any error reported by the Ethereum node could be due to the block no longer being on - // the main chain. This is very unespecific but we don't want to risk failing a - // subgraph due to a transient error such as a reorg. - Err(ContractCallError::AlloyError(e)) => Err(HostExportError::PossibleReorg(anyhow::anyhow!( + // Any error reported by the Ethereum node could be due to the block no longer being on + // the main chain. This is very unespecific but we don't want to risk failing a + // subgraph due to a transient error such as a reorg. + Err(ContractCallError::AlloyError(e)) => { + Err(HostExportError::PossibleReorg(anyhow::anyhow!( "Ethereum node returned an error when calling function \"{}\" of contract \"{}\": {}", unresolved_call.function_name, unresolved_call.contract_name, e - ))), - - // Also retry on timeouts. - Err(ContractCallError::Timeout) => Err(HostExportError::PossibleReorg(anyhow::anyhow!( - "Ethereum node did not respond when calling function \"{}\" of contract \"{}\"", - unresolved_call.function_name, - unresolved_call.contract_name, - ))), + ))) + } - Err(e) => Err(HostExportError::Unknown(anyhow::anyhow!( - "Failed to call function \"{}\" of contract \"{}\": {}", - unresolved_call.function_name, - unresolved_call.contract_name, - e - ))), - }; + // Also retry on timeouts. + Err(ContractCallError::Timeout) => Err(HostExportError::PossibleReorg(anyhow::anyhow!( + "Ethereum node did not respond when calling function \"{}\" of contract \"{}\"", + unresolved_call.function_name, + unresolved_call.contract_name, + ))), + + Err(e) => Err(HostExportError::Unknown(anyhow::anyhow!( + "Failed to call function \"{}\" of contract \"{}\": {}", + unresolved_call.function_name, + unresolved_call.contract_name, + e + ))), + }; let elapsed = start_time.elapsed(); diff --git a/chain/ethereum/src/tests.rs b/chain/ethereum/src/tests.rs index 5fa236323a4..a5f0a17bff0 100644 --- a/chain/ethereum/src/tests.rs +++ b/chain/ethereum/src/tests.rs @@ -1,17 +1,17 @@ use std::sync::Arc; use graph::{ - blockchain::{block_stream::BlockWithTriggers, BlockPtr, Trigger}, + blockchain::{BlockPtr, Trigger, block_stream::BlockWithTriggers}, prelude::{ + EthereumCall, LightEthereumBlock, alloy::{ self, - primitives::{Address, Bytes, LogData, B256}, + primitives::{Address, B256, Bytes, LogData}, rpc::types::{Block, Log}, }, rand::{self, Rng}, - EthereumCall, LightEthereumBlock, }, - slog::{self, o, Logger}, + slog::{self, Logger, o}, }; use crate::{ diff --git a/chain/ethereum/src/transport.rs b/chain/ethereum/src/transport.rs index ea5d63bc83b..5b5414c4a5d 100644 --- a/chain/ethereum/src/transport.rs +++ b/chain/ethereum/src/transport.rs @@ -265,12 +265,10 @@ impl Service for PatchingHttp { )); } - if should_patch { - if let Some(patched) = Self::patch_response(&body) { - return serde_json::from_slice(&patched).map_err(|err| { - TransportError::deser_err(err, String::from_utf8_lossy(&patched)) - }); - } + if should_patch && let Some(patched) = Self::patch_response(&body) { + return serde_json::from_slice(&patched).map_err(|err| { + TransportError::deser_err(err, String::from_utf8_lossy(&patched)) + }); } serde_json::from_slice(&body) .map_err(|err| TransportError::deser_err(err, String::from_utf8_lossy(&body))) diff --git a/chain/ethereum/src/trigger.rs b/chain/ethereum/src/trigger.rs index 6a5e1503073..b5d51d9a379 100644 --- a/chain/ethereum/src/trigger.rs +++ b/chain/ethereum/src/trigger.rs @@ -8,19 +8,19 @@ use graph::data::subgraph::API_VERSION_0_0_2; use graph::data::subgraph::API_VERSION_0_0_6; use graph::data::subgraph::API_VERSION_0_0_7; use graph::data_source::common::DeclaredCall; +use graph::prelude::BlockNumber; +use graph::prelude::BlockPtr; +use graph::prelude::LightEthereumBlock; use graph::prelude::alloy::consensus::Transaction as TransactionTrait; use graph::prelude::alloy::network::TransactionResponse; use graph::prelude::alloy::primitives::{Address, B256, U256}; use graph::prelude::alloy::rpc::types::Log; -use graph::prelude::BlockNumber; -use graph::prelude::BlockPtr; -use graph::prelude::LightEthereumBlock; use graph::prelude::{CheapClone, EthereumCall}; -use graph::runtime::asc_new; -use graph::runtime::gas::GasCounter; use graph::runtime::AscHeap; use graph::runtime::AscPtr; use graph::runtime::HostExportError; +use graph::runtime::asc_new; +use graph::runtime::gas::GasCounter; use graph::semver::Version; use graph_runtime_wasm::module::ToAscPtr; use std::{cmp::Ordering, sync::Arc}; diff --git a/chain/near/src/adapter.rs b/chain/near/src/adapter.rs index 8a9de408bad..31c7dca7c97 100644 --- a/chain/near/src/adapter.rs +++ b/chain/near/src/adapter.rs @@ -1,7 +1,7 @@ use std::collections::HashSet; use crate::data_source::PartialAccounts; -use crate::{data_source::DataSource, Chain}; +use crate::{Chain, data_source::DataSource}; use graph::blockchain as bc; use graph::firehose::{BasicReceiptFilter, PrefixSuffixPair}; use graph::itertools::Itertools; @@ -251,7 +251,7 @@ mod test { use std::collections::HashSet; use super::NearBlockFilter; - use crate::adapter::{TriggerFilter, BASIC_RECEIPT_FILTER_TYPE_URL}; + use crate::adapter::{BASIC_RECEIPT_FILTER_TYPE_URL, TriggerFilter}; use graph::{ blockchain::TriggerFilter as _, firehose::{BasicReceiptFilter, PrefixSuffixPair}, diff --git a/chain/near/src/chain.rs b/chain/near/src/chain.rs index 6dae3c3a1f0..5698301b5e8 100644 --- a/chain/near/src/chain.rs +++ b/chain/near/src/chain.rs @@ -14,17 +14,17 @@ use graph::prelude::MetricsRegistry; use graph::{ anyhow::Result, blockchain::{ + BlockHash, BlockPtr, Blockchain, EmptyNodeCapabilities, IngestorError, + RuntimeAdapter as RuntimeAdapterTrait, block_stream::{ BlockStreamEvent, BlockWithTriggers, FirehoseError, FirehoseMapper as FirehoseMapperTrait, TriggersAdapter as TriggersAdapterTrait, }, firehose_block_stream::FirehoseBlockStream, - BlockHash, BlockPtr, Blockchain, EmptyNodeCapabilities, IngestorError, - RuntimeAdapter as RuntimeAdapterTrait, }, components::store::DeploymentLocator, firehose::{self as firehose, ForkStep}, - prelude::{o, BlockNumber, Error, Logger, LoggerFactory}, + prelude::{BlockNumber, Error, Logger, LoggerFactory, o}, }; use prost::Message; use std::collections::BTreeSet; @@ -197,7 +197,9 @@ impl Blockchain for Chain { _logger: &Logger, _cursor: FirehoseCursor, ) -> Result { - unimplemented!("This chain does not support Dynamic Data Sources. is_refetch_block_required always returns false, this shouldn't be called.") + unimplemented!( + "This chain does not support Dynamic Data Sources. is_refetch_block_required always returns false, this shouldn't be called." + ) } async fn chain_head_ptr(&self) -> Result, Error> { @@ -367,7 +369,7 @@ impl BlockStreamMapper for FirehoseMapper { return Err(anyhow::anyhow!( "near mapper is expected to always have a block" )) - .map_err(BlockStreamError::from) + .map_err(BlockStreamError::from); } }; @@ -439,7 +441,9 @@ impl FirehoseMapperTrait for FirehoseMapper { } StepFinal => { - panic!("irreversible step is not handled and should not be requested in the Firehose request") + panic!( + "irreversible step is not handled and should not be requested in the Firehose request" + ) } StepUnset => { @@ -477,23 +481,23 @@ mod test { use std::{collections::HashSet, sync::Arc, vec}; use graph::{ - blockchain::{block_stream::BlockWithTriggers, DataSource as _, TriggersAdapter as _}, + blockchain::{DataSource as _, TriggersAdapter as _, block_stream::BlockWithTriggers}, data::subgraph::LATEST_VERSION, prelude::Link, semver::Version, - slog::{self, o, Logger}, + slog::{self, Logger, o}, }; use crate::{ + Chain, adapter::{NearReceiptFilter, TriggerFilter}, codec::{ - self, execution_outcome, receipt, Block, BlockHeader, DataReceiver, ExecutionOutcome, - ExecutionOutcomeWithId, IndexerExecutionOutcomeWithReceipt, IndexerShard, - ReceiptAction, SuccessValueExecutionStatus, + self, Block, BlockHeader, DataReceiver, ExecutionOutcome, ExecutionOutcomeWithId, + IndexerExecutionOutcomeWithReceipt, IndexerShard, ReceiptAction, + SuccessValueExecutionStatus, execution_outcome, receipt, }, - data_source::{DataSource, Mapping, PartialAccounts, ReceiptHandler, NEAR_KIND}, + data_source::{DataSource, Mapping, NEAR_KIND, PartialAccounts, ReceiptHandler}, trigger::{NearTrigger, ReceiptWithOutcome}, - Chain, }; use super::TriggersAdapter; diff --git a/chain/near/src/codec.rs b/chain/near/src/codec.rs index fca0a4f4c9e..569e8cf5243 100644 --- a/chain/near/src/codec.rs +++ b/chain/near/src/codec.rs @@ -4,7 +4,7 @@ pub mod pbcodec; use graph::{ blockchain::{Block as BlockchainBlock, BlockPtr, BlockTime}, - prelude::{alloy::primitives::B256, hex, BlockNumber}, + prelude::{BlockNumber, alloy::primitives::B256, hex}, }; use std::convert::TryFrom; use std::fmt::LowerHex; diff --git a/chain/near/src/data_source.rs b/chain/near/src/data_source.rs index e64197eeb0d..01484905a58 100644 --- a/chain/near/src/data_source.rs +++ b/chain/near/src/data_source.rs @@ -7,7 +7,7 @@ use graph::components::subgraph::InstanceDSTemplateInfo; use graph::data::subgraph::{DataSourceContext, DeploymentHash}; use graph::prelude::SubgraphManifestValidationError; use graph::{ - anyhow::{anyhow, Error}, + anyhow::{Error, anyhow}, blockchain::{self, Blockchain}, prelude::{BlockNumber, CheapClone, Deserialize, Link, LinkResolver, Logger}, semver, diff --git a/chain/near/src/runtime/abi.rs b/chain/near/src/runtime/abi.rs index 87e224dc4d0..b74d8f5f7ff 100644 --- a/chain/near/src/runtime/abi.rs +++ b/chain/near/src/runtime/abi.rs @@ -3,7 +3,7 @@ use crate::trigger::ReceiptWithOutcome; use async_trait::async_trait; use graph::anyhow::anyhow; use graph::runtime::gas::GasCounter; -use graph::runtime::{asc_new, AscHeap, AscPtr, DeterministicHostError, HostExportError, ToAscObj}; +use graph::runtime::{AscHeap, AscPtr, DeterministicHostError, HostExportError, ToAscObj, asc_new}; use graph_runtime_wasm::asc_abi::class::{Array, AscEnum, EnumPayload, Uint8Array}; pub(crate) use super::generated::*; @@ -517,7 +517,7 @@ impl ToAscObj for codec::MerklePathItem { "Invalid direction value {}", x )) - .into()) + .into()); } }, }) @@ -557,7 +557,7 @@ impl ToAscObj for codec::Signature { "Invalid signature type {}", value, )) - .into()) + .into()); } }, bytes: asc_new(heap, self.bytes.as_slice(), gas).await?, @@ -596,7 +596,7 @@ impl ToAscObj for codec::PublicKey { "Invalid public key type {}", value, )) - .into()) + .into()); } }, bytes: asc_new(heap, self.bytes.as_slice(), gas).await?, diff --git a/chain/near/src/trigger.rs b/chain/near/src/trigger.rs index ab68ab71beb..bf9794d2b20 100644 --- a/chain/near/src/trigger.rs +++ b/chain/near/src/trigger.rs @@ -3,11 +3,11 @@ use graph::blockchain::Block; use graph::blockchain::MappingTriggerTrait; use graph::blockchain::TriggerData; use graph::derive::CheapClone; +use graph::prelude::BlockNumber; use graph::prelude::alloy::primitives::B256; use graph::prelude::hex; -use graph::prelude::BlockNumber; use graph::runtime::HostExportError; -use graph::runtime::{asc_new, gas::GasCounter, AscHeap, AscPtr}; +use graph::runtime::{AscHeap, AscPtr, asc_new, gas::GasCounter}; use graph_runtime_wasm::module::ToAscPtr; use std::{cmp::Ordering, sync::Arc}; @@ -158,8 +158,8 @@ mod tests { anyhow::anyhow, components::metrics::gas::GasMetrics, data::subgraph::API_VERSION_0_0_5, - prelude::{hex, BigInt}, - runtime::{gas::GasCounter, DeterministicHostError, HostExportError}, + prelude::{BigInt, hex}, + runtime::{DeterministicHostError, HostExportError, gas::GasCounter}, util::mem::init_slice, }; diff --git a/core/graphman/src/commands/deployment/info.rs b/core/graphman/src/commands/deployment/info.rs index 55e00e917ca..155a821d715 100644 --- a/core/graphman/src/commands/deployment/info.rs +++ b/core/graphman/src/commands/deployment/info.rs @@ -11,10 +11,10 @@ use graph_store_postgres::ConnectionPool; use graph_store_postgres::Store; use itertools::Itertools; +use crate::GraphmanError; use crate::deployment::Deployment; use crate::deployment::DeploymentSelector; use crate::deployment::DeploymentVersionSelector; -use crate::GraphmanError; #[derive(Clone, Debug)] pub struct DeploymentStatus { diff --git a/core/graphman/src/commands/deployment/pause.rs b/core/graphman/src/commands/deployment/pause.rs index 0257768a03b..e2405b5f68b 100644 --- a/core/graphman/src/commands/deployment/pause.rs +++ b/core/graphman/src/commands/deployment/pause.rs @@ -3,15 +3,15 @@ use std::sync::Arc; use anyhow::anyhow; use graph::components::store::DeploymentLocator; use graph::components::store::StoreEvent; -use graph_store_postgres::command_support::catalog; -use graph_store_postgres::command_support::catalog::Site; use graph_store_postgres::ConnectionPool; use graph_store_postgres::NotificationSender; +use graph_store_postgres::command_support::catalog; +use graph_store_postgres::command_support::catalog::Site; use thiserror::Error; +use crate::GraphmanError; use crate::deployment::DeploymentSelector; use crate::deployment::DeploymentVersionSelector; -use crate::GraphmanError; pub struct ActiveDeployment { locator: DeploymentLocator, diff --git a/core/graphman/src/commands/deployment/reassign.rs b/core/graphman/src/commands/deployment/reassign.rs index b1ead37cd12..f4279946917 100644 --- a/core/graphman/src/commands/deployment/reassign.rs +++ b/core/graphman/src/commands/deployment/reassign.rs @@ -5,15 +5,15 @@ use graph::components::store::DeploymentLocator; use graph::components::store::StoreEvent; use graph::prelude::AssignmentChange; use graph::prelude::NodeId; -use graph_store_postgres::command_support::catalog; -use graph_store_postgres::command_support::catalog::Site; use graph_store_postgres::ConnectionPool; use graph_store_postgres::NotificationSender; +use graph_store_postgres::command_support::catalog; +use graph_store_postgres::command_support::catalog::Site; use thiserror::Error; +use crate::GraphmanError; use crate::deployment::DeploymentSelector; use crate::deployment::DeploymentVersionSelector; -use crate::GraphmanError; pub struct Deployment { locator: DeploymentLocator, @@ -134,7 +134,10 @@ pub async fn reassign_deployment( .map_err(GraphmanError::from)? .len(); if count == 1 { - let warning_msg = format!("This is the only deployment assigned to '{}'. Please make sure that the node ID is spelled correctly.",node.as_str()); + let warning_msg = format!( + "This is the only deployment assigned to '{}'. Please make sure that the node ID is spelled correctly.", + node.as_str() + ); Ok(ReassignResult::CompletedWithWarnings(vec![warning_msg])) } else { Ok(ReassignResult::Ok) diff --git a/core/graphman/src/commands/deployment/resume.rs b/core/graphman/src/commands/deployment/resume.rs index a8f9f4769e7..4fa0162f83e 100644 --- a/core/graphman/src/commands/deployment/resume.rs +++ b/core/graphman/src/commands/deployment/resume.rs @@ -3,15 +3,15 @@ use std::sync::Arc; use anyhow::anyhow; use graph::components::store::DeploymentLocator; use graph::prelude::StoreEvent; -use graph_store_postgres::command_support::catalog; -use graph_store_postgres::command_support::catalog::Site; use graph_store_postgres::ConnectionPool; use graph_store_postgres::NotificationSender; +use graph_store_postgres::command_support::catalog; +use graph_store_postgres::command_support::catalog::Site; use thiserror::Error; +use crate::GraphmanError; use crate::deployment::DeploymentSelector; use crate::deployment::DeploymentVersionSelector; -use crate::GraphmanError; pub struct PausedDeployment { locator: DeploymentLocator, diff --git a/core/graphman/src/commands/deployment/unassign.rs b/core/graphman/src/commands/deployment/unassign.rs index 474358c297e..cef72e947f1 100644 --- a/core/graphman/src/commands/deployment/unassign.rs +++ b/core/graphman/src/commands/deployment/unassign.rs @@ -3,15 +3,15 @@ use std::sync::Arc; use anyhow::anyhow; use graph::components::store::DeploymentLocator; use graph::components::store::StoreEvent; -use graph_store_postgres::command_support::catalog; -use graph_store_postgres::command_support::catalog::Site; use graph_store_postgres::ConnectionPool; use graph_store_postgres::NotificationSender; +use graph_store_postgres::command_support::catalog; +use graph_store_postgres::command_support::catalog::Site; use thiserror::Error; +use crate::GraphmanError; use crate::deployment::DeploymentSelector; use crate::deployment::DeploymentVersionSelector; -use crate::GraphmanError; pub struct AssignedDeployment { locator: DeploymentLocator, diff --git a/core/graphman/src/deployment.rs b/core/graphman/src/deployment.rs index 0a38f175586..6538017edaa 100644 --- a/core/graphman/src/deployment.rs +++ b/core/graphman/src/deployment.rs @@ -1,6 +1,4 @@ use anyhow::anyhow; -use diesel::dsl::sql; -use diesel::sql_types::Text; use diesel::BoolExpressionMethods; use diesel::ExpressionMethods; use diesel::JoinOnDsl; @@ -8,12 +6,14 @@ use diesel::NullableExpressionMethods; use diesel::PgTextExpressionMethods; use diesel::QueryDsl; use diesel::Queryable; +use diesel::dsl::sql; +use diesel::sql_types::Text; use diesel_async::RunQueryDsl; use graph::components::store::DeploymentId; use graph::components::store::DeploymentLocator; use graph::data::subgraph::DeploymentHash; -use graph_store_postgres::command_support::catalog; use graph_store_postgres::AsyncPgConnection; +use graph_store_postgres::command_support::catalog; use itertools::Itertools; use crate::GraphmanError; diff --git a/core/graphman_store/src/lib.rs b/core/graphman_store/src/lib.rs index f986d6484c0..8b1965df7cd 100644 --- a/core/graphman_store/src/lib.rs +++ b/core/graphman_store/src/lib.rs @@ -7,6 +7,9 @@ use anyhow::Result; use async_trait::async_trait; use chrono::DateTime; use chrono::Utc; +use diesel::AsExpression; +use diesel::FromSqlRow; +use diesel::Queryable; use diesel::deserialize::FromSql; use diesel::pg::Pg; use diesel::pg::PgValue; @@ -14,9 +17,6 @@ use diesel::serialize::Output; use diesel::serialize::ToSql; use diesel::sql_types::BigSerial; use diesel::sql_types::Varchar; -use diesel::AsExpression; -use diesel::FromSqlRow; -use diesel::Queryable; use strum::Display; use strum::EnumString; use strum::IntoStaticStr; diff --git a/core/src/amp_subgraph/manager.rs b/core/src/amp_subgraph/manager.rs index ae272830880..61ec421ca17 100644 --- a/core/src/amp_subgraph/manager.rs +++ b/core/src/amp_subgraph/manager.rs @@ -18,7 +18,7 @@ use graph::{ use slog::{debug, error}; use tokio_util::sync::CancellationToken; -use super::{runner, Metrics, Monitor}; +use super::{Metrics, Monitor, runner}; /// Manages Amp subgraph runner futures. /// diff --git a/core/src/amp_subgraph/metrics.rs b/core/src/amp_subgraph/metrics.rs index e54b07c1a6a..7088cf9a48f 100644 --- a/core/src/amp_subgraph/metrics.rs +++ b/core/src/amp_subgraph/metrics.rs @@ -4,7 +4,7 @@ use alloy::primitives::BlockNumber; use graph::{ cheap_clone::CheapClone, components::{ - metrics::{stopwatch::StopwatchMetrics, MetricsRegistry}, + metrics::{MetricsRegistry, stopwatch::StopwatchMetrics}, store::WritableStore, }, prelude::DeploymentHash, diff --git a/core/src/amp_subgraph/monitor.rs b/core/src/amp_subgraph/monitor.rs index 93cf30252a6..314f464c0d1 100644 --- a/core/src/amp_subgraph/monitor.rs +++ b/core/src/amp_subgraph/monitor.rs @@ -7,11 +7,11 @@ //! `subgraph instance` - A background task that executes the subgraph runner future. use std::{ - collections::{hash_map::Entry, HashMap}, + collections::{HashMap, hash_map::Entry}, fmt, sync::{ - atomic::{AtomicU32, Ordering::SeqCst}, Arc, + atomic::{AtomicU32, Ordering::SeqCst}, }, time::Duration, }; @@ -21,7 +21,7 @@ use futures::future::BoxFuture; use graph::{ cheap_clone::CheapClone, components::store::DeploymentLocator, log::factory::LoggerFactory, }; -use slog::{debug, error, info, warn, Logger}; +use slog::{Logger, debug, error, info, warn}; use tokio::{ sync::mpsc::{self, error::SendError}, task::JoinHandle, diff --git a/core/src/amp_subgraph/runner/context.rs b/core/src/amp_subgraph/runner/context.rs index 8ea0bb9e1f1..d8b5b7b638e 100644 --- a/core/src/amp_subgraph/runner/context.rs +++ b/core/src/amp_subgraph/runner/context.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use alloy::primitives::{BlockHash, BlockNumber}; use graph::{ - amp::{log::Logger as _, Codec, Manifest}, + amp::{Codec, Manifest, log::Logger as _}, cheap_clone::CheapClone, components::store::WritableStore, data::subgraph::DeploymentHash, diff --git a/core/src/amp_subgraph/runner/data_processing.rs b/core/src/amp_subgraph/runner/data_processing.rs index b9b2f20aba1..d5bf991d505 100644 --- a/core/src/amp_subgraph/runner/data_processing.rs +++ b/core/src/amp_subgraph/runner/data_processing.rs @@ -6,7 +6,7 @@ use arrow::array::RecordBatch; use chrono::{DateTime, Utc}; use graph::{ amp::{ - codec::{utils::auto_block_timestamp_decoder, DecodeOutput, DecodedEntity, Decoder}, + codec::{DecodeOutput, DecodedEntity, Decoder, utils::auto_block_timestamp_decoder}, stream_aggregator::{RecordBatchGroup, RecordBatchGroups, StreamRecordBatch}, }, blockchain::block_stream::FirehoseCursor, @@ -15,7 +15,7 @@ use graph::{ }; use slog::{debug, trace}; -use super::{data_stream::TablePtr, Compat, Context, Error}; +use super::{Compat, Context, Error, data_stream::TablePtr}; pub(super) async fn process_record_batch_groups( cx: &mut Context, diff --git a/core/src/amp_subgraph/runner/data_stream.rs b/core/src/amp_subgraph/runner/data_stream.rs index 1d7d9a11c4e..693ae9384a7 100644 --- a/core/src/amp_subgraph/runner/data_stream.rs +++ b/core/src/amp_subgraph/runner/data_stream.rs @@ -3,16 +3,16 @@ use std::{collections::HashMap, ops::RangeInclusive, sync::Arc}; use alloy::primitives::BlockNumber; use anyhow::anyhow; use futures::{ - stream::{self, BoxStream}, StreamExt, TryStreamExt, + stream::{self, BoxStream}, }; use graph::{ amp::{ + Client, client::ResponseBatch, error::IsDeterministic, manifest::DataSource, stream_aggregator::{RecordBatchGroups, StreamAggregator}, - Client, }, cheap_clone::CheapClone, prelude::StopwatchMetrics, @@ -152,10 +152,10 @@ where match result { Ok(response) => { if !start_block_checked { - if let Some(((first_block, _), _)) = response.0.first_key_value() { - if *first_block < start_block { - return Err(Error::NonDeterministic(anyhow!("chain reorg"))); - } + if let Some(((first_block, _), _)) = response.0.first_key_value() + && *first_block < start_block + { + return Err(Error::NonDeterministic(anyhow!("chain reorg"))); } start_block_checked = true; diff --git a/core/src/amp_subgraph/runner/latest_blocks.rs b/core/src/amp_subgraph/runner/latest_blocks.rs index cb62f2e3a42..17bdc23dd29 100644 --- a/core/src/amp_subgraph/runner/latest_blocks.rs +++ b/core/src/amp_subgraph/runner/latest_blocks.rs @@ -1,13 +1,13 @@ use alloy::primitives::BlockNumber; use anyhow::anyhow; use arrow::array::RecordBatch; -use futures::{future::try_join_all, stream::BoxStream, StreamExt, TryFutureExt}; +use futures::{StreamExt, TryFutureExt, future::try_join_all, stream::BoxStream}; use graph::amp::{ + Client, client::ResponseBatch, - codec::{utils::block_number_decoder, Decoder}, + codec::{Decoder, utils::block_number_decoder}, error::IsDeterministic, manifest::DataSource, - Client, }; use itertools::Itertools; use slog::debug; @@ -152,7 +152,9 @@ async fn latest_block_changed( where AC: Client, { - let query = format!("SELECT _block_num FROM {dataset}.{table} WHERE _block_num > {latest_block} SETTINGS stream = true"); + let query = format!( + "SELECT _block_num FROM {dataset}.{table} WHERE _block_num > {latest_block} SETTINGS stream = true" + ); let stream = cx.client.query(&cx.logger, query, None); let _record_batch = read_once(stream).await?; diff --git a/core/src/amp_subgraph/runner/mod.rs b/core/src/amp_subgraph/runner/mod.rs index e90b5c257c2..4e0e85294b6 100644 --- a/core/src/amp_subgraph/runner/mod.rs +++ b/core/src/amp_subgraph/runner/mod.rs @@ -119,11 +119,9 @@ where ) .await?; - if deployment_is_failed { - if let Some(block_ptr) = cx.store.block_ptr() { - cx.store.unfail_non_deterministic_error(&block_ptr).await?; - deployment_is_failed = false; - } + if deployment_is_failed && let Some(block_ptr) = cx.store.block_ptr() { + cx.store.unfail_non_deterministic_error(&block_ptr).await?; + deployment_is_failed = false; } } diff --git a/core/src/amp_subgraph/runner/reorg_handler.rs b/core/src/amp_subgraph/runner/reorg_handler.rs index 03130b19625..8f59169304b 100644 --- a/core/src/amp_subgraph/runner/reorg_handler.rs +++ b/core/src/amp_subgraph/runner/reorg_handler.rs @@ -1,10 +1,10 @@ use alloy::primitives::{BlockHash, BlockNumber}; use anyhow::anyhow; -use futures::{future::try_join_all, StreamExt, TryFutureExt}; +use futures::{StreamExt, TryFutureExt, future::try_join_all}; use graph::{ amp::{ - client::{LatestBlockBeforeReorg, RequestMetadata, ResponseBatch, ResumeStreamingQuery}, Client, + client::{LatestBlockBeforeReorg, RequestMetadata, ResponseBatch, ResumeStreamingQuery}, }, blockchain::block_stream::FirehoseCursor, }; diff --git a/core/src/polling_monitor/arweave_service.rs b/core/src/polling_monitor/arweave_service.rs index d0e557905f6..cc42f7af5ea 100644 --- a/core/src/polling_monitor/arweave_service.rs +++ b/core/src/polling_monitor/arweave_service.rs @@ -8,7 +8,7 @@ use graph::{ prelude::CheapClone, }; use std::{sync::Arc, time::Duration}; -use tower::{buffer::Buffer, ServiceBuilder, ServiceExt}; +use tower::{ServiceBuilder, ServiceExt, buffer::Buffer}; pub type ArweaveService = Buffer, Error>>>; diff --git a/core/src/polling_monitor/ipfs_service.rs b/core/src/polling_monitor/ipfs_service.rs index ef061530fd3..6847bb82acd 100644 --- a/core/src/polling_monitor/ipfs_service.rs +++ b/core/src/polling_monitor/ipfs_service.rs @@ -1,13 +1,13 @@ use std::sync::Arc; use std::time::Duration; -use anyhow::anyhow; use anyhow::Error; +use anyhow::anyhow; use bytes::Bytes; use graph::futures03::future::BoxFuture; use graph::ipfs::{ContentPath, IpfsClient, IpfsContext, RetryPolicy}; use graph::{derive::CheapClone, prelude::CheapClone}; -use tower::{buffer::Buffer, ServiceBuilder, ServiceExt}; +use tower::{ServiceBuilder, ServiceExt, buffer::Buffer}; pub type IpfsService = Buffer, Error>>>; @@ -109,10 +109,10 @@ mod test { use graph::ipfs::{IpfsContext, IpfsMetrics, IpfsRpcClient, ServerAddress}; use graph::log::discard; use tower::ServiceExt; - use wiremock::matchers as m; use wiremock::Mock; use wiremock::MockServer; use wiremock::ResponseTemplate; + use wiremock::matchers as m; use super::*; diff --git a/core/src/polling_monitor/mod.rs b/core/src/polling_monitor/mod.rs index fa0b433f4de..f8a24db97d7 100644 --- a/core/src/polling_monitor/mod.rs +++ b/core/src/polling_monitor/mod.rs @@ -14,11 +14,11 @@ use graph::cheap_clone::CheapClone; use graph::env::ENV_VARS; use graph::futures03::future::BoxFuture; use graph::futures03::stream::StreamExt; -use graph::futures03::{stream, Future, FutureExt, TryFutureExt}; +use graph::futures03::{Future, FutureExt, TryFutureExt, stream}; use graph::parking_lot::Mutex; use graph::prelude::tokio; use graph::prometheus::{Counter, Gauge}; -use graph::slog::{debug, Logger}; +use graph::slog::{Logger, debug}; use graph::util::monitored::MonitoredVecDeque as VecDeque; use tokio::sync::{mpsc, watch}; use tower::retry::backoff::{Backoff, ExponentialBackoff, ExponentialBackoffMaker, MakeBackoff}; @@ -28,8 +28,8 @@ use tower::{Service, ServiceExt}; use self::request::RequestId; pub use self::metrics::PollingMonitorMetrics; -pub use arweave_service::{arweave_service, ArweaveService}; -pub use ipfs_service::{ipfs_service, IpfsRequest, IpfsService}; +pub use arweave_service::{ArweaveService, arweave_service}; +pub use ipfs_service::{IpfsRequest, IpfsService, ipfs_service}; const MIN_BACKOFF: Duration = Duration::from_secs(5); @@ -53,7 +53,7 @@ impl Backoffs { } } - fn next_backoff(&mut self, id: ID) -> impl Future { + fn next_backoff(&mut self, id: ID) -> impl Future + Send + use { self.backoffs .entry(id) .or_insert_with(|| self.backoff_maker.make_backoff()) diff --git a/core/src/subgraph/context/instance/mod.rs b/core/src/subgraph/context/instance/mod.rs index e9c311420e6..1f57097ed59 100644 --- a/core/src/subgraph/context/instance/mod.rs +++ b/core/src/subgraph/context/instance/mod.rs @@ -5,8 +5,8 @@ use graph::futures01::sync::mpsc::Sender; use graph::{ blockchain::{Blockchain, TriggerData as _}, data_source::{ - causality_region::CausalityRegionSeq, offchain, CausalityRegion, DataSource, - DataSourceTemplate, TriggerData, + CausalityRegion, DataSource, DataSourceTemplate, TriggerData, + causality_region::CausalityRegionSeq, offchain, }, prelude::*, }; @@ -100,7 +100,7 @@ where ) -> Result>, Error> { let module_bytes = match &data_source.runtime() { None => return Ok(None), - Some(ref module_bytes) => module_bytes.cheap_clone(), + Some(module_bytes) => module_bytes.cheap_clone(), }; let mapping_request_sender = { diff --git a/core/src/subgraph/context/mod.rs b/core/src/subgraph/context/mod.rs index 07af703d7d7..affbc09aa0f 100644 --- a/core/src/subgraph/context/mod.rs +++ b/core/src/subgraph/context/mod.rs @@ -1,7 +1,7 @@ mod instance; use crate::polling_monitor::{ - spawn_monitor, ArweaveService, IpfsRequest, IpfsService, PollingMonitor, PollingMonitorMetrics, + ArweaveService, IpfsRequest, IpfsService, PollingMonitor, PollingMonitorMetrics, spawn_monitor, }; use anyhow::{self, Error}; use bytes::Bytes; @@ -10,9 +10,9 @@ use graph::{ components::{store::DeploymentId, subgraph::HostMetrics}, data::subgraph::SubgraphManifest, data_source::{ + CausalityRegion, DataSource, DataSourceTemplate, causality_region::CausalityRegionSeq, offchain::{self, Base64}, - CausalityRegion, DataSource, DataSourceTemplate, }, derive::CheapClone, ipfs::IpfsContext, @@ -132,12 +132,12 @@ impl> IndexingContext { .map(|ds| (ds.source.clone(), ds.is_processed())); let host = self.instance.add_dynamic_data_source(logger, data_source)?; - if host.is_some() { - if let Some((source, is_processed)) = offchain_fields { - // monitor data source only if it has not yet been processed. - if !is_processed { - self.offchain_monitor.add_source(source); - } + if host.is_some() + && let Some((source, is_processed)) = offchain_fields + { + // monitor data source only if it has not yet been processed. + if !is_processed { + self.offchain_monitor.add_source(source); } } diff --git a/core/src/subgraph/error.rs b/core/src/subgraph/error.rs index 6aad9f7cb3e..00413acb258 100644 --- a/core/src/subgraph/error.rs +++ b/core/src/subgraph/error.rs @@ -1,6 +1,6 @@ use graph::data::subgraph::schema::SubgraphError; use graph::env::ENV_VARS; -use graph::prelude::{anyhow, thiserror, Error, StoreError}; +use graph::prelude::{Error, StoreError, anyhow, thiserror}; pub trait DeterministicError: std::fmt::Debug + std::fmt::Display + Send + Sync + 'static {} diff --git a/core/src/subgraph/inputs.rs b/core/src/subgraph/inputs.rs index 88e89de4ff4..03a8cec29bc 100644 --- a/core/src/subgraph/inputs.rs +++ b/core/src/subgraph/inputs.rs @@ -1,5 +1,5 @@ use graph::{ - blockchain::{block_stream::TriggersAdapterWrapper, Blockchain}, + blockchain::{Blockchain, block_stream::TriggersAdapterWrapper}, components::{ store::{DeploymentLocator, SourceableStore, SubgraphFork, WritableStore}, subgraph::ProofOfIndexingVersion, diff --git a/core/src/subgraph/instance_manager.rs b/core/src/subgraph/instance_manager.rs index 8273b0045cf..ea301ffc723 100644 --- a/core/src/subgraph/instance_manager.rs +++ b/core/src/subgraph/instance_manager.rs @@ -2,10 +2,10 @@ use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; use crate::polling_monitor::{ArweaveService, IpfsService}; +use crate::subgraph::Decoder; use crate::subgraph::context::{IndexingContext, SubgraphKeepAlive}; use crate::subgraph::inputs::IndexingInputs; use crate::subgraph::loader::load_dynamic_data_sources; -use crate::subgraph::Decoder; use std::collections::BTreeSet; use crate::subgraph::runner::SubgraphRunner; @@ -17,18 +17,18 @@ use graph::components::metrics::gas::GasMetrics; use graph::components::metrics::subgraph::DeploymentStatusMetric; use graph::components::store::SourceableStore; use graph::components::subgraph::ProofOfIndexingVersion; -use graph::data::subgraph::{UnresolvedSubgraphManifest, SPEC_VERSION_0_0_6}; +use graph::data::subgraph::{SPEC_VERSION_0_0_6, UnresolvedSubgraphManifest}; use graph::data::value::Word; use graph::data_source::causality_region::CausalityRegionSeq; use graph::env::EnvVars; use graph::prelude::{SubgraphInstanceManager as SubgraphInstanceManagerTrait, *}; use graph::{blockchain::BlockchainMap, components::store::DeploymentLocator}; -use graph_runtime_wasm::module::ToAscPtr; use graph_runtime_wasm::RuntimeHostBuilder; +use graph_runtime_wasm::module::ToAscPtr; use tokio::task; -use super::context::OffchainMonitor; use super::SubgraphTriggerProcessor; +use super::context::OffchainMonitor; use crate::{subgraph::runner::SubgraphRunnerError, subgraph_manifest}; #[derive(Clone)] @@ -278,17 +278,17 @@ impl SubgraphInstanceManager { .with_retries(), ); - if let Some(graft) = &manifest.graft { - if self.subgraph_store.is_deployed(&graft.base).await? { - // Makes sure the raw manifest is cached in the subgraph store - let _raw_manifest = subgraph_manifest::load_raw_subgraph_manifest( - &logger, - &*self.subgraph_store, - &*self.link_resolver, - &graft.base, - ) - .await?; - } + if let Some(graft) = &manifest.graft + && self.subgraph_store.is_deployed(&graft.base).await? + { + // Makes sure the raw manifest is cached in the subgraph store + let _raw_manifest = subgraph_manifest::load_raw_subgraph_manifest( + &logger, + &*self.subgraph_store, + &*self.link_resolver, + &graft.base, + ) + .await?; } info!(logger, "Resolve subgraph files using IPFS"; diff --git a/core/src/subgraph/registrar.rs b/core/src/subgraph/registrar.rs index d718b4131f1..48698d8d3e2 100644 --- a/core/src/subgraph/registrar.rs +++ b/core/src/subgraph/registrar.rs @@ -10,12 +10,12 @@ use graph::components::{ subgraph::Settings, }; use graph::data::{ - subgraph::{schema::DeploymentCreate, Graft}, + subgraph::{Graft, schema::DeploymentCreate}, value::Word, }; -use graph::futures03::{self, future::TryFutureExt, Stream, StreamExt}; +use graph::futures03::{self, Stream, StreamExt, future::TryFutureExt}; use graph::prelude::{CreateSubgraphResult, SubgraphRegistrar as SubgraphRegistrarTrait, *}; -use graph::util::futures::{retry_strategy, RETRY_DEFAULT_LIMIT}; +use graph::util::futures::{RETRY_DEFAULT_LIMIT, retry_strategy}; use tokio_retry::Retry; pub struct SubgraphRegistrar { diff --git a/core/src/subgraph/runner/mod.rs b/core/src/subgraph/runner/mod.rs index 1a6efbc1d6c..5f6170556ca 100644 --- a/core/src/subgraph/runner/mod.rs +++ b/core/src/subgraph/runner/mod.rs @@ -29,19 +29,19 @@ use graph::components::{ use graph::data::store::scalar::Bytes; use graph::data::subgraph::schema::SubgraphError; use graph::data_source::{ - offchain, CausalityRegion, DataSource, DataSourceCreationError, TriggerData, + CausalityRegion, DataSource, DataSourceCreationError, TriggerData, offchain, }; use graph::env::EnvVars; use graph::ext::futures::Cancelable; use graph::futures03::stream::StreamExt; use graph::prelude::{ - anyhow, hex, retry, thiserror, BlockNumber, BlockPtr, BlockState, CancelGuard, CancelHandle, - CancelToken as _, CheapClone as _, EntityCache, EntityModification, Error, - InstanceDSTemplateInfo, LogCode, RunnerMetrics, RuntimeHostBuilder, StopwatchMetrics, - StoreError, StreamExtension, UnfailOutcome, Value, ENV_VARS, + BlockNumber, BlockPtr, BlockState, CancelGuard, CancelHandle, CancelToken as _, + CheapClone as _, ENV_VARS, EntityCache, EntityModification, Error, InstanceDSTemplateInfo, + LogCode, RunnerMetrics, RuntimeHostBuilder, StopwatchMetrics, StoreError, StreamExtension, + UnfailOutcome, Value, anyhow, hex, retry, thiserror, }; use graph::schema::EntityKey; -use graph::slog::{debug, error, info, o, trace, warn, Logger}; +use graph::slog::{Logger, debug, error, info, o, trace, warn}; use graph::util::lfu_cache::EvictStats; use graph::util::{backoff::ExponentialBackoff, lfu_cache::LfuCache}; use std::sync::Arc; @@ -290,16 +290,16 @@ where } // Stop subgraph when we reach maximum endblock. - if let Some(max_end_block) = self.inputs.max_end_block { - if max_end_block <= current_ptr.block_number() { - info!(self.logger, "Stopping subgraph as we reached maximum endBlock"; + if let Some(max_end_block) = self.inputs.max_end_block + && max_end_block <= current_ptr.block_number() + { + info!(self.logger, "Stopping subgraph as we reached maximum endBlock"; "max_end_block" => max_end_block, "current_block" => current_ptr.block_number()); - self.inputs.store.flush().await?; - return Ok(RunnerState::Stopped { - reason: StopReason::MaxEndBlockReached, - }); - } + self.inputs.store.flush().await?; + return Ok(RunnerState::Stopped { + reason: StopReason::MaxEndBlockReached, + }); } } @@ -1312,23 +1312,23 @@ where } } - if let Some(stop_block) = self.inputs.stop_block { - if block_ptr.number >= stop_block { - info!(self.logger, "Stop block reached for subgraph"); - return Ok(Action::Stop); - } + if let Some(stop_block) = self.inputs.stop_block + && block_ptr.number >= stop_block + { + info!(self.logger, "Stop block reached for subgraph"); + return Ok(Action::Stop); } - if let Some(max_end_block) = self.inputs.max_end_block { - if block_ptr.number >= max_end_block { - info!( - self.logger, - "Stopping subgraph as maximum endBlock reached"; - "max_end_block" => max_end_block, - "current_block" => block_ptr.number - ); - return Ok(Action::Stop); - } + if let Some(max_end_block) = self.inputs.max_end_block + && block_ptr.number >= max_end_block + { + info!( + self.logger, + "Stopping subgraph as maximum endBlock reached"; + "max_end_block" => max_end_block, + "current_block" => block_ptr.number + ); + return Ok(Action::Stop); } Ok(action) diff --git a/core/src/subgraph/runner/state.rs b/core/src/subgraph/runner/state.rs index 01ad9648341..d6401842522 100644 --- a/core/src/subgraph/runner/state.rs +++ b/core/src/subgraph/runner/state.rs @@ -3,8 +3,8 @@ //! This module defines the explicit state machine that controls the runner's lifecycle, //! replacing the previous nested loop structure with clear state transitions. -use graph::blockchain::block_stream::{BlockStream, BlockWithTriggers, FirehoseCursor}; use graph::blockchain::Blockchain; +use graph::blockchain::block_stream::{BlockStream, BlockWithTriggers, FirehoseCursor}; use graph::ext::futures::Cancelable; use graph::prelude::BlockPtr; diff --git a/core/src/subgraph_manifest.rs b/core/src/subgraph_manifest.rs index c02497c10c5..ddc01e0bc69 100644 --- a/core/src/subgraph_manifest.rs +++ b/core/src/subgraph_manifest.rs @@ -6,7 +6,7 @@ use graph::{ }, data::subgraph::DeploymentHash, }; -use slog::{debug, Logger}; +use slog::{Logger, debug}; pub(super) async fn load_raw_subgraph_manifest( logger: &Logger, diff --git a/gnd/src/abi.rs b/gnd/src/abi.rs index 49ca4727ee1..0a5fa695cf4 100644 --- a/gnd/src/abi.rs +++ b/gnd/src/abi.rs @@ -3,7 +3,7 @@ //! Handles extraction of bare ABI arrays from various artifact formats //! (raw arrays, Hardhat/Foundry, Truffle). -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; /// Normalize ABI JSON to extract the actual ABI array from various artifact formats. /// @@ -21,19 +21,18 @@ pub fn normalize_abi_json(abi_str: &str) -> Result { } // Case 2: Object with "abi" field (Foundry/Hardhat format) - if let Some(abi) = value.get("abi") { - if abi.is_array() { - return Ok(abi.clone()); - } + if let Some(abi) = value.get("abi") + && abi.is_array() + { + return Ok(abi.clone()); } // Case 3: Object with "compilerOutput.abi" field (Truffle format) - if let Some(compiler_output) = value.get("compilerOutput") { - if let Some(abi) = compiler_output.get("abi") { - if abi.is_array() { - return Ok(abi.clone()); - } - } + if let Some(compiler_output) = value.get("compilerOutput") + && let Some(abi) = compiler_output.get("abi") + && abi.is_array() + { + return Ok(abi.clone()); } Err(anyhow!( @@ -92,9 +91,11 @@ mod tests { let invalid_abi = r#"{"contractName": "MyContract"}"#; let result = normalize_abi_json(invalid_abi); assert!(result.is_err()); - assert!(result - .unwrap_err() - .to_string() - .contains("Invalid ABI format")); + assert!( + result + .unwrap_err() + .to_string() + .contains("Invalid ABI format") + ); } } diff --git a/gnd/src/codegen/abi.rs b/gnd/src/codegen/abi.rs index 292a303260c..9b881fdcbe9 100644 --- a/gnd/src/codegen/abi.rs +++ b/gnd/src/codegen/abi.rs @@ -1375,6 +1375,7 @@ fn indexed_input_type(param_type: &DynSolType) -> DynSolType { #[cfg(test)] mod tests { + use super::*; fn parse_abi(json: &str) -> JsonAbi { @@ -1397,8 +1398,8 @@ mod tests { ]"#; let contract = parse_abi(abi_json); - let gen = AbiCodeGenerator::new(contract, "Token"); - let types = gen.generate_types(); + let generator = AbiCodeGenerator::new(contract, "Token"); + let types = generator.generate_types(); assert!(types.iter().any(|c| c.name == "Transfer")); assert!(types.iter().any(|c| c.name == "Transfer__Params")); @@ -1417,17 +1418,19 @@ mod tests { ]"#; let contract = parse_abi(abi_json); - let gen = AbiCodeGenerator::new(contract, "Token"); - let types = gen.generate_types(); + let generator = AbiCodeGenerator::new(contract, "Token"); + let types = generator.generate_types(); assert!(types.iter().any(|c| c.name == "Token")); let token_class = types.iter().find(|c| c.name == "Token").unwrap(); assert!(token_class.methods.iter().any(|m| m.name == "balanceOf")); - assert!(token_class - .methods - .iter() - .any(|m| m.name == "try_balanceOf")); + assert!( + token_class + .methods + .iter() + .any(|m| m.name == "try_balanceOf") + ); } #[test] @@ -1443,8 +1446,8 @@ mod tests { #[test] fn test_name_sanitization() { - let gen = AbiCodeGenerator::new(JsonAbi::default(), "Test!Contract@Name"); - assert_eq!(gen.name, "Test_Contract_Name"); + let generator = AbiCodeGenerator::new(JsonAbi::default(), "Test!Contract@Name"); + assert_eq!(generator.name, "Test_Contract_Name"); } #[test] @@ -1500,8 +1503,8 @@ mod tests { ]"#; let contract = parse_abi(abi_json); - let gen = AbiCodeGenerator::new(contract, "Token"); - let types = gen.generate_types(); + let generator = AbiCodeGenerator::new(contract, "Token"); + let types = generator.generate_types(); // Get all event class names let event_names: Vec<&str> = types @@ -1555,8 +1558,8 @@ mod tests { ]"#; let contract = parse_abi(abi_json); - let gen = AbiCodeGenerator::new(contract, "Token"); - let types = gen.generate_types(); + let generator = AbiCodeGenerator::new(contract, "Token"); + let types = generator.generate_types(); // Find the Token contract class let token_class = types.iter().find(|c| c.name == "Token").unwrap(); @@ -1612,8 +1615,8 @@ mod tests { ]"#; let contract = parse_abi(abi_json); - let gen = AbiCodeGenerator::new(contract, "TestContract"); - let types = gen.generate_types(); + let generator = AbiCodeGenerator::new(contract, "TestContract"); + let types = generator.generate_types(); // Get class names let class_names: Vec<&str> = types.iter().map(|c| c.name.as_str()).collect(); @@ -1699,8 +1702,8 @@ mod tests { ]"#; let contract = parse_abi(abi_json); - let gen = AbiCodeGenerator::new(contract, "TestContract"); - let types = gen.generate_types(); + let generator = AbiCodeGenerator::new(contract, "TestContract"); + let types = generator.generate_types(); // Get class names let class_names: Vec<&str> = types.iter().map(|c| c.name.as_str()).collect(); @@ -1758,8 +1761,8 @@ mod tests { ]"#; let contract = parse_abi(abi_json); - let gen = AbiCodeGenerator::new(contract, "TestContract"); - let types = gen.generate_types(); + let generator = AbiCodeGenerator::new(contract, "TestContract"); + let types = generator.generate_types(); // Get class names let class_names: Vec<&str> = types.iter().map(|c| c.name.as_str()).collect(); @@ -1803,8 +1806,8 @@ mod tests { ]"#; let contract = parse_abi(abi_json); - let gen = AbiCodeGenerator::new(contract, "TestContract"); - let types = gen.generate_types(); + let generator = AbiCodeGenerator::new(contract, "TestContract"); + let types = generator.generate_types(); // Find the contract class let contract_class = types.iter().find(|c| c.name == "TestContract").unwrap(); @@ -1846,8 +1849,8 @@ mod tests { ]"#; let contract = parse_abi(abi_json); - let gen = AbiCodeGenerator::new(contract, "Token"); - let types = gen.generate_types(); + let generator = AbiCodeGenerator::new(contract, "Token"); + let types = generator.generate_types(); // Find the params class let params_class = types @@ -1924,8 +1927,8 @@ mod tests { ]"#; let contract = parse_abi(abi_json); - let gen = AbiCodeGenerator::new(contract, "TestContract"); - let types = gen.generate_types(); + let generator = AbiCodeGenerator::new(contract, "TestContract"); + let types = generator.generate_types(); // Find the contract class let contract_class = types.iter().find(|c| c.name == "TestContract").unwrap(); diff --git a/gnd/src/codegen/mod.rs b/gnd/src/codegen/mod.rs index 3b300e5eb94..4c8f5fdbd98 100644 --- a/gnd/src/codegen/mod.rs +++ b/gnd/src/codegen/mod.rs @@ -15,6 +15,6 @@ pub use abi::AbiCodeGenerator; pub use schema::SchemaCodeGenerator; pub use template::{Template, TemplateCodeGenerator, TemplateKind}; pub use typescript::{ - ArrayType, Class, ClassMember, Method, ModuleImports, NamedType, NullableType, Param, - StaticMethod, GENERATED_FILE_NOTE, + ArrayType, Class, ClassMember, GENERATED_FILE_NOTE, Method, ModuleImports, NamedType, + NullableType, Param, StaticMethod, }; diff --git a/gnd/src/codegen/schema.rs b/gnd/src/codegen/schema.rs index 97118cfb2a2..a8a276f1ca0 100644 --- a/gnd/src/codegen/schema.rs +++ b/gnd/src/codegen/schema.rs @@ -2,7 +2,7 @@ //! //! Generates AssemblyScript entity classes from GraphQL schemas. -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use graphql_tools::parser::schema::{ Definition, Document, Field, ObjectType, Type, TypeDefinition, }; @@ -210,50 +210,50 @@ impl SchemaCodeGenerator { // First pass: collect entity names and their ID types for def in &document.definitions { - if let Definition::TypeDefinition(TypeDefinition::Object(obj)) = def { - if is_entity_type(obj) { - entity_names.insert(obj.name.clone()); - let id_field = obj.fields.iter().find(|f| f.name == "id"); - let id_kind = id_field - .map(|f| IdFieldKind::from_type_name(&get_base_type_name(&f.field_type))) - .unwrap_or(IdFieldKind::String); - entity_id_kinds.insert(obj.name.clone(), id_kind); - } + if let Definition::TypeDefinition(TypeDefinition::Object(obj)) = def + && is_entity_type(obj) + { + entity_names.insert(obj.name.clone()); + let id_field = obj.fields.iter().find(|f| f.name == "id"); + let id_kind = id_field + .map(|f| IdFieldKind::from_type_name(&get_base_type_name(&f.field_type))) + .unwrap_or(IdFieldKind::String); + entity_id_kinds.insert(obj.name.clone(), id_kind); } } // Second pass: collect entity info for def in &document.definitions { - if let Definition::TypeDefinition(TypeDefinition::Object(obj)) = def { - if is_entity_type(obj) { - let name = obj.name.clone(); - - // Find ID field - let id_field = obj.fields.iter().find(|f| f.name == "id"); - let id_kind = id_field - .map(|f| IdFieldKind::from_type_name(&get_base_type_name(&f.field_type))) - .unwrap_or(IdFieldKind::String); - - // Collect field info - let fields: Vec<_> = obj - .fields - .iter() - .map(|f| FieldInfo { - name: f.name.clone(), - is_derived: is_derived_field(f), - base_type: get_base_type_name(&f.field_type), - is_nullable: is_nullable(&f.field_type), - list_depth: list_depth(&f.field_type), - member_nullable: is_list_member_nullable(&f.field_type), - }) - .collect(); - - entities.push(EntityInfo { - name, - id_kind, - fields, - }); - } + if let Definition::TypeDefinition(TypeDefinition::Object(obj)) = def + && is_entity_type(obj) + { + let name = obj.name.clone(); + + // Find ID field + let id_field = obj.fields.iter().find(|f| f.name == "id"); + let id_kind = id_field + .map(|f| IdFieldKind::from_type_name(&get_base_type_name(&f.field_type))) + .unwrap_or(IdFieldKind::String); + + // Collect field info + let fields: Vec<_> = obj + .fields + .iter() + .map(|f| FieldInfo { + name: f.name.clone(), + is_derived: is_derived_field(f), + base_type: get_base_type_name(&f.field_type), + is_nullable: is_nullable(&f.field_type), + list_depth: list_depth(&f.field_type), + member_nullable: is_list_member_nullable(&f.field_type), + }) + .collect(); + + entities.push(EntityInfo { + name, + id_kind, + fields, + }); } } @@ -713,6 +713,7 @@ enum StoreMethod { #[cfg(test)] mod tests { use super::*; + use graphql_tools::parser::parse_schema; #[test] @@ -726,9 +727,9 @@ mod tests { } "#; let doc = parse_schema::(schema).unwrap(); - let gen = SchemaCodeGenerator::new(&doc).unwrap(); + let generator = SchemaCodeGenerator::new(&doc).unwrap(); - let classes = gen.generate_types(true); + let classes = generator.generate_types(true); assert_eq!(classes.len(), 1); let transfer = &classes[0]; @@ -747,9 +748,9 @@ mod tests { } "#; let doc = parse_schema::(schema).unwrap(); - let gen = SchemaCodeGenerator::new(&doc).unwrap(); + let generator = SchemaCodeGenerator::new(&doc).unwrap(); - let classes = gen.generate_types(true); + let classes = generator.generate_types(true); assert_eq!(classes.len(), 1); // Check that we have methods for nullable and non-nullable fields @@ -802,9 +803,9 @@ mod tests { } "#; let doc = parse_schema::(schema).unwrap(); - let gen = SchemaCodeGenerator::new(&doc).unwrap(); + let generator = SchemaCodeGenerator::new(&doc).unwrap(); - let classes = gen.generate_types(true); + let classes = generator.generate_types(true); assert_eq!(classes.len(), 1); let counter = &classes[0]; @@ -846,9 +847,9 @@ mod tests { } "#; let doc = parse_schema::(schema).unwrap(); - let gen = SchemaCodeGenerator::new(&doc).unwrap(); + let generator = SchemaCodeGenerator::new(&doc).unwrap(); - let classes = gen.generate_types(true); + let classes = generator.generate_types(true); assert_eq!(classes.len(), 1); let event = &classes[0]; @@ -890,9 +891,9 @@ mod tests { } "#; let doc = parse_schema::(schema).unwrap(); - let gen = SchemaCodeGenerator::new(&doc).unwrap(); + let generator = SchemaCodeGenerator::new(&doc).unwrap(); - let classes = gen.generate_types(true); + let classes = generator.generate_types(true); assert_eq!(classes.len(), 1); let user = &classes[0]; @@ -937,11 +938,11 @@ mod tests { } "#; let doc = parse_schema::(schema).unwrap(); - let gen = SchemaCodeGenerator::new(&doc).unwrap(); + let generator = SchemaCodeGenerator::new(&doc).unwrap(); // The Post.author field should be treated as a string (entity ID reference) - assert!(gen.entity_names.contains("User")); - assert!(gen.entity_names.contains("Post")); + assert!(generator.entity_names.contains("User")); + assert!(generator.entity_names.contains("Post")); } #[test] @@ -953,9 +954,9 @@ mod tests { } "#; let doc = parse_schema::(schema).unwrap(); - let gen = SchemaCodeGenerator::new(&doc).unwrap(); + let generator = SchemaCodeGenerator::new(&doc).unwrap(); - let classes = gen.generate_types(true); + let classes = generator.generate_types(true); assert_eq!(classes.len(), 1); let token = &classes[0]; @@ -989,9 +990,9 @@ mod tests { } "#; let doc = parse_schema::(schema).unwrap(); - let gen = SchemaCodeGenerator::new(&doc).unwrap(); + let generator = SchemaCodeGenerator::new(&doc).unwrap(); - let classes = gen.generate_types(true); + let classes = generator.generate_types(true); assert_eq!(classes.len(), 1); let matrix = &classes[0]; @@ -1100,19 +1101,19 @@ mod tests { } "#; let doc = parse_schema::(schema).unwrap(); - let gen = SchemaCodeGenerator::new(&doc).unwrap(); + let generator = SchemaCodeGenerator::new(&doc).unwrap(); // Find the entity - let entity = &gen.entities[0]; + let entity = &generator.entities[0]; // Find each field and check its value type let scalar_field = entity.fields.iter().find(|f| f.name == "scalar").unwrap(); let array_field = entity.fields.iter().find(|f| f.name == "array").unwrap(); let matrix_field = entity.fields.iter().find(|f| f.name == "matrix").unwrap(); - assert_eq!(gen.value_type_from_field(scalar_field), "String"); - assert_eq!(gen.value_type_from_field(array_field), "[String]"); - assert_eq!(gen.value_type_from_field(matrix_field), "[[String]]"); + assert_eq!(generator.value_type_from_field(scalar_field), "String"); + assert_eq!(generator.value_type_from_field(array_field), "[String]"); + assert_eq!(generator.value_type_from_field(matrix_field), "[[String]]"); } #[test] @@ -1129,9 +1130,9 @@ mod tests { } "#; let doc = parse_schema::(schema).unwrap(); - let gen = SchemaCodeGenerator::new(&doc).unwrap(); + let generator = SchemaCodeGenerator::new(&doc).unwrap(); - let classes = gen.generate_types(true); + let classes = generator.generate_types(true); let balance = classes.iter().find(|c| c.name == "Balance").unwrap(); let output = balance.to_string(); @@ -1170,9 +1171,9 @@ mod tests { } "#; let doc = parse_schema::(schema).unwrap(); - let gen = SchemaCodeGenerator::new(&doc).unwrap(); + let generator = SchemaCodeGenerator::new(&doc).unwrap(); - let classes = gen.generate_types(true); + let classes = generator.generate_types(true); let snapshot = classes.iter().find(|c| c.name == "Snapshot").unwrap(); let output = snapshot.to_string(); @@ -1211,9 +1212,9 @@ mod tests { } "#; let doc = parse_schema::(schema).unwrap(); - let gen = SchemaCodeGenerator::new(&doc).unwrap(); + let generator = SchemaCodeGenerator::new(&doc).unwrap(); - let classes = gen.generate_types(true); + let classes = generator.generate_types(true); let token = classes.iter().find(|c| c.name == "Token").unwrap(); let output = token.to_string(); @@ -1244,9 +1245,9 @@ mod tests { } "#; let doc = parse_schema::(schema).unwrap(); - let gen = SchemaCodeGenerator::new(&doc).unwrap(); + let generator = SchemaCodeGenerator::new(&doc).unwrap(); - let classes = gen.generate_types(true); + let classes = generator.generate_types(true); let balance = classes.iter().find(|c| c.name == "Balance").unwrap(); let output = balance.to_string(); @@ -1272,9 +1273,9 @@ mod tests { } "#; let doc = parse_schema::(schema).unwrap(); - let gen = SchemaCodeGenerator::new(&doc).unwrap(); + let generator = SchemaCodeGenerator::new(&doc).unwrap(); - let classes = gen.generate_types(true); + let classes = generator.generate_types(true); let token = classes.iter().find(|c| c.name == "Token").unwrap(); let output = token.to_string(); diff --git a/gnd/src/codegen/template.rs b/gnd/src/codegen/template.rs index d067ea928c2..72a27f9e733 100644 --- a/gnd/src/codegen/template.rs +++ b/gnd/src/codegen/template.rs @@ -159,6 +159,7 @@ impl TemplateCodeGenerator { #[cfg(test)] mod tests { + use super::*; #[test] @@ -185,16 +186,16 @@ mod tests { #[test] fn test_ethereum_template() { let template = Template::new("DynamicToken", TemplateKind::Ethereum); - let gen = TemplateCodeGenerator::new(vec![template]); + let generator = TemplateCodeGenerator::new(vec![template]); - let imports = gen.generate_module_imports(); + let imports = generator.generate_module_imports(); assert_eq!(imports.len(), 1); let import_names: Vec<_> = imports[0].names.iter().collect(); assert!(import_names.contains(&&"DataSourceTemplate".to_string())); assert!(import_names.contains(&&"DataSourceContext".to_string())); assert!(import_names.contains(&&"Address".to_string())); - let types = gen.generate_types(); + let types = generator.generate_types(); assert_eq!(types.len(), 1); let klass = &types[0]; @@ -218,9 +219,9 @@ mod tests { #[test] fn test_file_ipfs_template() { let template = Template::new("TokenMetadata", TemplateKind::FileIpfs); - let gen = TemplateCodeGenerator::new(vec![template]); + let generator = TemplateCodeGenerator::new(vec![template]); - let imports = gen.generate_module_imports(); + let imports = generator.generate_module_imports(); assert_eq!(imports.len(), 1); let import_names: Vec<_> = imports[0].names.iter().collect(); assert!(import_names.contains(&&"DataSourceTemplate".to_string())); @@ -228,7 +229,7 @@ mod tests { // No Address for file templates assert!(!import_names.contains(&&"Address".to_string())); - let types = gen.generate_types(); + let types = generator.generate_types(); assert_eq!(types.len(), 1); let klass = &types[0]; @@ -246,30 +247,30 @@ mod tests { Template::new("DynamicToken", TemplateKind::Ethereum), Template::new("TokenMetadata", TemplateKind::FileIpfs), ]; - let gen = TemplateCodeGenerator::new(templates); + let generator = TemplateCodeGenerator::new(templates); - let imports = gen.generate_module_imports(); + let imports = generator.generate_module_imports(); // Should have Address because of Ethereum template let import_names: Vec<_> = imports[0].names.iter().collect(); assert!(import_names.contains(&&"Address".to_string())); - let types = gen.generate_types(); + let types = generator.generate_types(); assert_eq!(types.len(), 2); } #[test] fn test_empty_templates() { - let gen = TemplateCodeGenerator::new(vec![]); - assert!(gen.generate_module_imports().is_empty()); - assert!(gen.generate_types().is_empty()); + let generator = TemplateCodeGenerator::new(vec![]); + assert!(generator.generate_module_imports().is_empty()); + assert!(generator.generate_types().is_empty()); } #[test] fn test_generated_output() { let template = Template::new("DynamicToken", TemplateKind::Ethereum); - let gen = TemplateCodeGenerator::new(vec![template]); + let generator = TemplateCodeGenerator::new(vec![template]); - let types = gen.generate_types(); + let types = generator.generate_types(); let output = types[0].to_string(); assert!(output.contains("export class DynamicToken extends DataSourceTemplate")); diff --git a/gnd/src/commands/add.rs b/gnd/src/commands/add.rs index 4a6191a6274..280253d5509 100644 --- a/gnd/src/commands/add.rs +++ b/gnd/src/commands/add.rs @@ -6,16 +6,16 @@ use std::fs; use std::path::{Path, PathBuf}; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use clap::Parser; use inflector::Inflector; use serde_json::Value as JsonValue; use crate::config::networks::update_networks_file; use crate::formatter::format_typescript; -use crate::output::{step, Step}; -use crate::scaffold::manifest::{extract_events_from_abi, EventInfo}; +use crate::output::{Step, step}; use crate::scaffold::ScaffoldOptions; +use crate::scaffold::manifest::{EventInfo, extract_events_from_abi}; use crate::services::ContractService; #[derive(Clone, Debug, Parser)] @@ -511,10 +511,12 @@ mod tests { let result = run_add(opt).await; assert!(result.is_err()); - assert!(result - .unwrap_err() - .to_string() - .contains("Invalid contract address")); + assert!( + result + .unwrap_err() + .to_string() + .contains("Invalid contract address") + ); } #[test] diff --git a/gnd/src/commands/build.rs b/gnd/src/commands/build.rs index 2d9c7b36bd7..b33731330aa 100644 --- a/gnd/src/commands/build.rs +++ b/gnd/src/commands/build.rs @@ -8,16 +8,16 @@ use std::collections::HashMap; use std::fs; use std::path::{Path, PathBuf}; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use clap::Parser; use sha1::{Digest, Sha1}; use crate::abi::normalize_abi_json; -use crate::compiler::{compile_mapping, find_graph_ts, AscCompileOptions}; +use crate::compiler::{AscCompileOptions, compile_mapping, find_graph_ts}; use crate::config::{apply_network_config, get_network_config, load_networks_config}; -use crate::manifest::{load_manifest, resolve_path, DataSource, Manifest, Template}; +use crate::manifest::{DataSource, Manifest, Template, load_manifest, resolve_path}; use crate::migrations; -use crate::output::{step, Step}; +use crate::output::{Step, step}; use crate::services::IpfsClient; use crate::validation::{ collect_handler_names, collect_template_handler_names, format_manifest_errors, @@ -496,35 +496,34 @@ fn create_ipfs_manifest( .unwrap_or("schema.graphql"); // Find the hash for this file - if let Some(hash) = uploaded.path_to_ipfs.get(schema_name) { - if let Some(schema) = value.get_mut("schema") { - if let Some(file) = schema.get_mut("file") { - *file = create_ipfs_link(hash); - } - } + if let Some(hash) = uploaded.path_to_ipfs.get(schema_name) + && let Some(schema) = value.get_mut("schema") + && let Some(file) = schema.get_mut("file") + { + *file = create_ipfs_link(hash); } } // Update data source paths - if let Some(data_sources) = value.get_mut("dataSources") { - if let Some(arr) = data_sources.as_sequence_mut() { - for (i, ds_value) in arr.iter_mut().enumerate() { - if i < manifest.data_sources.len() { - let ds = &manifest.data_sources[i]; - update_data_source_ipfs_paths(ds_value, ds, uploaded); - } + if let Some(data_sources) = value.get_mut("dataSources") + && let Some(arr) = data_sources.as_sequence_mut() + { + for (i, ds_value) in arr.iter_mut().enumerate() { + if i < manifest.data_sources.len() { + let ds = &manifest.data_sources[i]; + update_data_source_ipfs_paths(ds_value, ds, uploaded); } } } // Update template paths - if let Some(templates) = value.get_mut("templates") { - if let Some(arr) = templates.as_sequence_mut() { - for (i, template_value) in arr.iter_mut().enumerate() { - if i < manifest.templates.len() { - let template = &manifest.templates[i]; - update_template_ipfs_paths(template_value, template, uploaded); - } + if let Some(templates) = value.get_mut("templates") + && let Some(arr) = templates.as_sequence_mut() + { + for (i, template_value) in arr.iter_mut().enumerate() { + if i < manifest.templates.len() { + let template = &manifest.templates[i]; + update_template_ipfs_paths(template_value, template, uploaded); } } } @@ -558,16 +557,16 @@ fn update_data_source_ipfs_paths( } // Update ABIs - if let Some(abis) = mapping.get_mut("abis") { - if let Some(arr) = abis.as_sequence_mut() { - for (j, abi_value) in arr.iter_mut().enumerate() { - if j < ds.abis.len() { - let abi = &ds.abis[j]; - if let Some(file) = abi_value.get_mut("file") { - let abi_path = format!("{}/{}.json", ds.name, abi.name); - if let Some(hash) = uploaded.path_to_ipfs.get(&abi_path) { - *file = create_ipfs_link(hash); - } + if let Some(abis) = mapping.get_mut("abis") + && let Some(arr) = abis.as_sequence_mut() + { + for (j, abi_value) in arr.iter_mut().enumerate() { + if j < ds.abis.len() { + let abi = &ds.abis[j]; + if let Some(file) = abi_value.get_mut("file") { + let abi_path = format!("{}/{}.json", ds.name, abi.name); + if let Some(hash) = uploaded.path_to_ipfs.get(&abi_path) { + *file = create_ipfs_link(hash); } } } @@ -592,16 +591,16 @@ fn update_template_ipfs_paths( } // Update ABIs - if let Some(abis) = mapping.get_mut("abis") { - if let Some(arr) = abis.as_sequence_mut() { - for (j, abi_value) in arr.iter_mut().enumerate() { - if j < template.abis.len() { - let abi = &template.abis[j]; - if let Some(file) = abi_value.get_mut("file") { - let abi_path = format!("templates/{}/{}.json", template.name, abi.name); - if let Some(hash) = uploaded.path_to_ipfs.get(&abi_path) { - *file = create_ipfs_link(hash); - } + if let Some(abis) = mapping.get_mut("abis") + && let Some(arr) = abis.as_sequence_mut() + { + for (j, abi_value) in arr.iter_mut().enumerate() { + if j < template.abis.len() { + let abi = &template.abis[j]; + if let Some(file) = abi_value.get_mut("file") { + let abi_path = format!("templates/{}/{}.json", template.name, abi.name); + if let Some(hash) = uploaded.path_to_ipfs.get(&abi_path) { + *file = create_ipfs_link(hash); } } } @@ -751,38 +750,37 @@ fn write_output_manifest( let mut value: serde_yaml::Value = serde_yaml::from_str(&manifest_str)?; // Update schema path - if let Some(schema) = value.get_mut("schema") { - if let Some(file) = schema.get_mut("file") { - if let Some(schema_path) = manifest.schema.as_ref() { - let schema_name = Path::new(schema_path) - .file_name() - .and_then(|n| n.to_str()) - .unwrap_or("schema.graphql"); - *file = serde_yaml::Value::String(schema_name.to_string()); - } - } + if let Some(schema) = value.get_mut("schema") + && let Some(file) = schema.get_mut("file") + && let Some(schema_path) = manifest.schema.as_ref() + { + let schema_name = Path::new(schema_path) + .file_name() + .and_then(|n| n.to_str()) + .unwrap_or("schema.graphql"); + *file = serde_yaml::Value::String(schema_name.to_string()); } // Update data source paths - if let Some(data_sources) = value.get_mut("dataSources") { - if let Some(arr) = data_sources.as_sequence_mut() { - for (i, ds) in arr.iter_mut().enumerate() { - if i < manifest.data_sources.len() { - let ds_name = &manifest.data_sources[i].name; - update_data_source_paths(ds, ds_name, output_format); - } + if let Some(data_sources) = value.get_mut("dataSources") + && let Some(arr) = data_sources.as_sequence_mut() + { + for (i, ds) in arr.iter_mut().enumerate() { + if i < manifest.data_sources.len() { + let ds_name = &manifest.data_sources[i].name; + update_data_source_paths(ds, ds_name, output_format); } } } // Update template paths - if let Some(templates) = value.get_mut("templates") { - if let Some(arr) = templates.as_sequence_mut() { - for (i, template) in arr.iter_mut().enumerate() { - if i < manifest.templates.len() { - let template_name = &manifest.templates[i].name; - update_template_paths(template, template_name, output_format); - } + if let Some(templates) = value.get_mut("templates") + && let Some(arr) = templates.as_sequence_mut() + { + for (i, template) in arr.iter_mut().enumerate() { + if i < manifest.templates.len() { + let template_name = &manifest.templates[i].name; + update_template_paths(template, template_name, output_format); } } } @@ -804,19 +802,19 @@ fn update_data_source_paths(ds: &mut serde_yaml::Value, ds_name: &str, output_fo } // Update ABI paths - if let Some(abis) = mapping.get_mut("abis") { - if let Some(arr) = abis.as_sequence_mut() { - for abi in arr.iter_mut() { - // Extract name first to avoid borrow conflicts - let abi_name = abi - .get("name") - .and_then(|n| n.as_str()) - .map(|s| s.to_string()); - if let Some(name) = abi_name { - if let Some(file) = abi.get_mut("file") { - *file = serde_yaml::Value::String(format!("{}/{}.json", ds_name, name)); - } - } + if let Some(abis) = mapping.get_mut("abis") + && let Some(arr) = abis.as_sequence_mut() + { + for abi in arr.iter_mut() { + // Extract name first to avoid borrow conflicts + let abi_name = abi + .get("name") + .and_then(|n| n.as_str()) + .map(|s| s.to_string()); + if let Some(name) = abi_name + && let Some(file) = abi.get_mut("file") + { + *file = serde_yaml::Value::String(format!("{}/{}.json", ds_name, name)); } } } @@ -840,22 +838,22 @@ fn update_template_paths( } // Update ABI paths - if let Some(abis) = mapping.get_mut("abis") { - if let Some(arr) = abis.as_sequence_mut() { - for abi in arr.iter_mut() { - // Extract name first to avoid borrow conflicts - let abi_name = abi - .get("name") - .and_then(|n| n.as_str()) - .map(|s| s.to_string()); - if let Some(name) = abi_name { - if let Some(file) = abi.get_mut("file") { - *file = serde_yaml::Value::String(format!( - "templates/{}/{}.json", - template_name, name - )); - } - } + if let Some(abis) = mapping.get_mut("abis") + && let Some(arr) = abis.as_sequence_mut() + { + for abi in arr.iter_mut() { + // Extract name first to avoid borrow conflicts + let abi_name = abi + .get("name") + .and_then(|n| n.as_str()) + .map(|s| s.to_string()); + if let Some(name) = abi_name + && let Some(file) = abi.get_mut("file") + { + *file = serde_yaml::Value::String(format!( + "templates/{}/{}.json", + template_name, name + )); } } } diff --git a/gnd/src/commands/codegen.rs b/gnd/src/commands/codegen.rs index fafa88d2b43..deb0feb0ca5 100644 --- a/gnd/src/commands/codegen.rs +++ b/gnd/src/commands/codegen.rs @@ -9,7 +9,7 @@ use std::fs; use std::path::{Path, PathBuf}; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use clap::Parser; use graph::abi::JsonAbi; use graphql_tools::parser::schema as gql; @@ -17,13 +17,13 @@ use semver::Version; use crate::abi::normalize_abi_json; use crate::codegen::{ - AbiCodeGenerator, Class, ModuleImports, SchemaCodeGenerator, Template as CodegenTemplate, - TemplateCodeGenerator, TemplateKind, GENERATED_FILE_NOTE, + AbiCodeGenerator, Class, GENERATED_FILE_NOTE, ModuleImports, SchemaCodeGenerator, + Template as CodegenTemplate, TemplateCodeGenerator, TemplateKind, }; use crate::formatter::try_format_typescript; -use crate::manifest::{load_manifest, resolve_path, DataSource, Manifest, Template}; +use crate::manifest::{DataSource, Manifest, Template, load_manifest, resolve_path}; use crate::migrations; -use crate::output::{step, Step}; +use crate::output::{Step, step}; use crate::services::IpfsClient; use crate::validation::{ format_manifest_errors, format_schema_errors, validate_manifest_files, validate_schema, @@ -209,7 +209,7 @@ fn generate_schema_types( step(Step::Generate, "Generate types for GraphQL schema"); let generator = match SchemaCodeGenerator::new(&ast) { - Ok(gen) => gen, + Ok(generator) => generator, Err(e) => { // Schema validation failed - skip schema.ts generation but don't fail eprintln!("Warning: {}", e); @@ -277,13 +277,13 @@ fn preprocess_abi_json(abi_str: &str) -> Result { fn add_default_event_param_names(params: &mut serde_json::Value) { if let Some(params_arr) = params.as_array_mut() { for (index, param) in params_arr.iter_mut().enumerate() { - if let Some(obj) = param.as_object_mut() { - if !obj.contains_key("name") { - obj.insert( - "name".to_string(), - serde_json::Value::String(format!("param{}", index)), - ); - } + if let Some(obj) = param.as_object_mut() + && !obj.contains_key("name") + { + obj.insert( + "name".to_string(), + serde_json::Value::String(format!("param{}", index)), + ); } } } @@ -407,7 +407,7 @@ async fn generate_subgraph_source_types( // Generate entity types WITHOUT store methods (false = no store methods) let generator = match SchemaCodeGenerator::new(&ast) { - Ok(gen) => gen, + Ok(generator) => generator, Err(e) => { eprintln!( "Warning: Failed to create schema generator for subgraph {} ({}): {}", diff --git a/gnd/src/commands/deploy.rs b/gnd/src/commands/deploy.rs index 7c305c72d11..7f975511f46 100644 --- a/gnd/src/commands/deploy.rs +++ b/gnd/src/commands/deploy.rs @@ -5,13 +5,13 @@ use std::path::PathBuf; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use clap::Parser; use url::Url; use crate::commands::auth::get_deploy_key; -use crate::commands::build::{run_build, BuildOpt}; -use crate::output::{step, Step}; +use crate::commands::build::{BuildOpt, run_build}; +use crate::output::{Step, step}; use crate::services::GraphNodeClient; /// Default IPFS URL used by The Graph diff --git a/gnd/src/commands/dev.rs b/gnd/src/commands/dev.rs index f7ce6f1a01a..044cefa877e 100644 --- a/gnd/src/commands/dev.rs +++ b/gnd/src/commands/dev.rs @@ -6,7 +6,7 @@ use graph::{ components::link_resolver::FileLinkResolver, env::EnvVars, prelude::{CheapClone, DeploymentHash, LinkResolver, SubgraphName}, - slog::{error, info, Logger}, + slog::{Logger, error, info}, }; use graph_core::polling_monitor::ipfs_service; use graph_node::{launcher, opt::Opt}; diff --git a/gnd/src/commands/init.rs b/gnd/src/commands/init.rs index 1bf20aa070c..629297616d0 100644 --- a/gnd/src/commands/init.rs +++ b/gnd/src/commands/init.rs @@ -13,20 +13,20 @@ use std::fs; use std::io::{self, IsTerminal}; use std::path::{Path, PathBuf}; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use clap::{Parser, ValueEnum}; use graphql_tools::parser::schema as gql; -use crate::commands::add::{run_add, AddOpt}; -use crate::commands::codegen::{run_codegen, CodegenOpt}; +use crate::commands::add::{AddOpt, run_add}; +use crate::commands::codegen::{CodegenOpt, run_codegen}; use crate::config::networks::update_networks_file; -use crate::output::{step, with_spinner, Step}; +use crate::output::{Step, step, with_spinner}; use crate::prompt::{ - get_subgraph_basename, prompt_add_another_contract, prompt_contract_address, - prompt_contract_name, prompt_directory_with_confirm, prompt_start_block, - prompt_subgraph_slug_with_confirm, resolve_directory_collision, InitForm, SourceType, + InitForm, SourceType, get_subgraph_basename, prompt_add_another_contract, + prompt_contract_address, prompt_contract_name, prompt_directory_with_confirm, + prompt_start_block, prompt_subgraph_slug_with_confirm, resolve_directory_collision, }; -use crate::scaffold::{generate_scaffold, init_git, install_dependencies, ScaffoldOptions}; +use crate::scaffold::{ScaffoldOptions, generate_scaffold, init_git, install_dependencies}; use crate::services::{ContractInfo, ContractService, IpfsClient, NetworksRegistry}; /// Available protocols for subgraph development. @@ -385,10 +385,10 @@ async fn init_from_contract(opt: &InitOpt, prefetched: Option) -> } // Install dependencies unless skipped - if !opt.skip_install { - if let Err(e) = install_dependencies(&directory) { - eprintln!("Warning: {}", e); - } + if !opt.skip_install + && let Err(e) = install_dependencies(&directory) + { + eprintln!("Warning: {}", e); } // Run codegen to generate types (requires dependencies to be installed) @@ -573,10 +573,10 @@ fn init_from_example(opt: &InitOpt) -> Result<()> { } // Install dependencies unless skipped - if !opt.skip_install { - if let Err(e) = install_dependencies(&directory) { - eprintln!("Warning: {}", e); - } + if !opt.skip_install + && let Err(e) = install_dependencies(&directory) + { + eprintln!("Warning: {}", e); } // Run codegen unless install was skipped (codegen requires dependencies) @@ -869,7 +869,9 @@ fn print_next_steps(subgraph_name: &str, directory: &Path) { println!(); println!(" 3. Run `yarn deploy` to deploy the subgraph."); println!(); - println!("Make sure to visit the documentation on https://thegraph.com/docs/ for further information."); + println!( + "Make sure to visit the documentation on https://thegraph.com/docs/ for further information." + ); } /// Initialize a subgraph from an existing deployed subgraph. @@ -908,15 +910,15 @@ async fn init_from_subgraph(opt: &InitOpt) -> Result<()> { serde_yaml::from_str(&manifest_yaml).context("Failed to parse subgraph manifest YAML")?; // Validate network matches - if let Some(manifest_network) = extract_network(&manifest) { - if manifest_network != network { - return Err(anyhow!( - "Network mismatch: The source subgraph is indexing '{}', but you specified '{}'.\n\ + if let Some(manifest_network) = extract_network(&manifest) + && manifest_network != network + { + return Err(anyhow!( + "Network mismatch: The source subgraph is indexing '{}', but you specified '{}'.\n\ When composing subgraphs, they must index the same network.", - manifest_network, - network - )); - } + manifest_network, + network + )); } // Get start block from manifest if not provided @@ -999,10 +1001,10 @@ async fn init_from_subgraph(opt: &InitOpt) -> Result<()> { } // Install dependencies unless skipped - if !opt.skip_install { - if let Err(e) = install_dependencies(&directory) { - eprintln!("Warning: {}", e); - } + if !opt.skip_install + && let Err(e) = install_dependencies(&directory) + { + eprintln!("Warning: {}", e); } step( @@ -1097,10 +1099,10 @@ fn is_immutable_entity(obj: &gql::ObjectType) -> bool { for directive in &obj.directives { if directive.name == "entity" { for (name, value) in &directive.arguments { - if name == "immutable" { - if let gql::Value::Boolean(true) = value { - return true; - } + if name == "immutable" + && let gql::Value::Boolean(true) = value + { + return true; } } } @@ -1422,10 +1424,10 @@ mod tests { let ast = gql::parse_schema::(schema).unwrap(); for def in ast.definitions { - if let gql::Definition::TypeDefinition(gql::TypeDefinition::Object(obj)) = def { - if obj.name == "Transfer" { - assert!(is_immutable_entity(&obj)); - } + if let gql::Definition::TypeDefinition(gql::TypeDefinition::Object(obj)) = def + && obj.name == "Transfer" + { + assert!(is_immutable_entity(&obj)); } } @@ -1438,10 +1440,10 @@ mod tests { let ast = gql::parse_schema::(schema).unwrap(); for def in ast.definitions { - if let gql::Definition::TypeDefinition(gql::TypeDefinition::Object(obj)) = def { - if obj.name == "Account" { - assert!(!is_immutable_entity(&obj)); - } + if let gql::Definition::TypeDefinition(gql::TypeDefinition::Object(obj)) = def + && obj.name == "Account" + { + assert!(!is_immutable_entity(&obj)); } } } diff --git a/gnd/src/commands/mod.rs b/gnd/src/commands/mod.rs index 4220fb6202f..5867cc8d584 100644 --- a/gnd/src/commands/mod.rs +++ b/gnd/src/commands/mod.rs @@ -11,15 +11,15 @@ mod publish; mod remove; mod test; -pub use add::{run_add, AddOpt}; -pub use auth::{get_deploy_key, run_auth, AuthOpt}; -pub use build::{run_build, BuildOpt}; -pub use clean::{run_clean, CleanOpt}; -pub use codegen::{run_codegen, CodegenOpt}; -pub use create::{run_create, CreateOpt}; -pub use deploy::{run_deploy, DeployOpt}; -pub use dev::{run_dev, DevOpt}; -pub use init::{run_init, InitOpt}; -pub use publish::{run_publish, PublishOpt}; -pub use remove::{run_remove, RemoveOpt}; -pub use test::{run_test, TestOpt}; +pub use add::{AddOpt, run_add}; +pub use auth::{AuthOpt, get_deploy_key, run_auth}; +pub use build::{BuildOpt, run_build}; +pub use clean::{CleanOpt, run_clean}; +pub use codegen::{CodegenOpt, run_codegen}; +pub use create::{CreateOpt, run_create}; +pub use deploy::{DeployOpt, run_deploy}; +pub use dev::{DevOpt, run_dev}; +pub use init::{InitOpt, run_init}; +pub use publish::{PublishOpt, run_publish}; +pub use remove::{RemoveOpt, run_remove}; +pub use test::{TestOpt, run_test}; diff --git a/gnd/src/commands/publish.rs b/gnd/src/commands/publish.rs index e55b5ffc0b6..e07a57de999 100644 --- a/gnd/src/commands/publish.rs +++ b/gnd/src/commands/publish.rs @@ -5,12 +5,12 @@ use std::path::PathBuf; -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use clap::Parser; use inquire::Confirm; -use crate::commands::build::{run_build, BuildOpt}; -use crate::output::{step, Step}; +use crate::commands::build::{BuildOpt, run_build}; +use crate::output::{Step, step}; /// Default IPFS URL for The Graph's hosted IPFS node. const DEFAULT_IPFS_URL: &str = "https://api.thegraph.com/ipfs/api/v0"; diff --git a/gnd/src/commands/test/assertion.rs b/gnd/src/commands/test/assertion.rs index 8bb6f9ee302..9d6455c69bb 100644 --- a/gnd/src/commands/test/assertion.rs +++ b/gnd/src/commands/test/assertion.rs @@ -2,9 +2,9 @@ use super::runner::TestContext; use super::schema::{Assertion, AssertionFailure, AssertionOutcome, TestResult}; -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use graph::data::query::{Query, QueryResults, QueryTarget}; -use graph::prelude::{q, ApiVersion, GraphQlRunner as GraphQlRunnerTrait}; +use graph::prelude::{ApiVersion, GraphQlRunner as GraphQlRunnerTrait, q}; pub(super) async fn run_assertions( ctx: &TestContext, @@ -136,11 +136,11 @@ fn json_similarity(a: &serde_json::Value, b: &serde_json::Value) -> usize { (serde_json::Value::Object(a_obj), serde_json::Value::Object(b_obj)) => { let mut score = 0; for (k, v) in a_obj { - if let Some(bv) = b_obj.get(k) { - if json_equal(v, bv) { - // `id` match is a strong signal for entity identity. - score += if k == "id" { 100 } else { 1 }; - } + if let Some(bv) = b_obj.get(k) + && json_equal(v, bv) + { + // `id` match is a strong signal for entity identity. + score += if k == "id" { 100 } else { 1 }; } } score diff --git a/gnd/src/commands/test/eth_calls.rs b/gnd/src/commands/test/eth_calls.rs index 4b9dbddfaf8..5f9152037a1 100644 --- a/gnd/src/commands/test/eth_calls.rs +++ b/gnd/src/commands/test/eth_calls.rs @@ -1,7 +1,7 @@ //! ABI encoding helpers for mock Ethereum call data. use super::trigger::json_to_sol_value; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use graph::abi::FunctionExt as GraphFunctionExt; use graph::prelude::alloy::dyn_abi::{DynSolType, FunctionExt as AlloyFunctionExt}; use graph::prelude::alloy::json_abi::Function; diff --git a/gnd/src/commands/test/matchstick.rs b/gnd/src/commands/test/matchstick.rs index ee2409a0ef8..08657366650 100644 --- a/gnd/src/commands/test/matchstick.rs +++ b/gnd/src/commands/test/matchstick.rs @@ -4,12 +4,12 @@ //! This is the legacy path for projects that haven't migrated to the new //! JSON-based test format yet. -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use serde::{Deserialize, Serialize}; use std::path::{Path, PathBuf}; use std::time::{SystemTime, UNIX_EPOCH}; -use crate::output::{step, Step}; +use crate::output::{Step, step}; use super::TestOpt; diff --git a/gnd/src/commands/test/mock_chain.rs b/gnd/src/commands/test/mock_chain.rs index 8978284eb63..c3a1a69f01f 100644 --- a/gnd/src/commands/test/mock_chain.rs +++ b/gnd/src/commands/test/mock_chain.rs @@ -1,8 +1,8 @@ //! Block pointer utilities for mock chains. use graph::blockchain::block_stream::BlockWithTriggers; -use graph::prelude::alloy::primitives::B256; use graph::prelude::BlockPtr; +use graph::prelude::alloy::primitives::B256; use graph_chain_ethereum::Chain; /// Last block pointer — used as the indexer's stop target. diff --git a/gnd/src/commands/test/mock_runtime.rs b/gnd/src/commands/test/mock_runtime.rs index 150662faa74..d18e93fd3c0 100644 --- a/gnd/src/commands/test/mock_runtime.rs +++ b/gnd/src/commands/test/mock_runtime.rs @@ -8,9 +8,9 @@ use graph::data_source; use graph::futures03::FutureExt; use graph::prelude::EthereumCallCache; use graph::runtime::HostExportError; +use graph_chain_ethereum::Chain; use graph_chain_ethereum::chain::{EthereumRuntimeAdapterBuilder, RuntimeAdapterBuilder}; use graph_chain_ethereum::network::EthereumNetworkAdapters; -use graph_chain_ethereum::Chain; use std::sync::Arc; const WRAPPED_HOST_FNS: &[&str] = &["ethereum.call", "ethereum.getBalance", "ethereum.hasCode"]; diff --git a/gnd/src/commands/test/mod.rs b/gnd/src/commands/test/mod.rs index a2f0d413495..7352ae73e48 100644 --- a/gnd/src/commands/test/mod.rs +++ b/gnd/src/commands/test/mod.rs @@ -42,12 +42,12 @@ mod runner; mod schema; mod trigger; -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use clap::Parser; use console::style; use std::path::PathBuf; -use crate::output::{step, Step}; +use crate::output::{Step, step}; const DEFAULT_TEST_DIR: &str = "tests"; diff --git a/gnd/src/commands/test/output.rs b/gnd/src/commands/test/output.rs index e02b90f9179..8746574b511 100644 --- a/gnd/src/commands/test/output.rs +++ b/gnd/src/commands/test/output.rs @@ -5,7 +5,7 @@ use similar::{ChangeTag, TextDiff}; use super::assertion::align_for_diff; use super::schema::{AssertionFailure, AssertionOutcome, TestResult}; -use crate::output::{step, Step}; +use crate::output::{Step, step}; pub fn print_test_start(path: &std::path::Path) { step(Step::Load, &format!("Running {}", path.display())); diff --git a/gnd/src/commands/test/runner.rs b/gnd/src/commands/test/runner.rs index 3d0955b63b7..20e4c18791f 100644 --- a/gnd/src/commands/test/runner.rs +++ b/gnd/src/commands/test/runner.rs @@ -10,6 +10,7 @@ //! 5. Waits for all blocks to be processed (or a fatal error) //! 6. Runs GraphQL assertions against the indexed entity state +use super::TestOpt; use super::assertion::run_assertions; use super::block_stream::StaticStreamBuilder; use super::mock_arweave::MockArweaveResolver; @@ -20,9 +21,8 @@ use super::mock_transport::MockTransport; use super::noop::{NoopAdapterSelector, StaticBlockRefetcher}; use super::schema::{TestFile, TestResult}; use super::trigger::build_blocks_with_triggers; -use super::TestOpt; -use crate::manifest::{load_manifest, Manifest}; -use anyhow::{anyhow, ensure, Context, Result}; +use crate::manifest::{Manifest, load_manifest}; +use anyhow::{Context, Result, anyhow, ensure}; use graph::amp::FlightClient; use graph::blockchain::block_stream::BlockWithTriggers; use graph::blockchain::{BlockPtr, BlockchainMap, ChainIdentifier}; @@ -44,11 +44,11 @@ use graph::prelude::{ DeploymentHash, LoggerFactory, NodeId, SubgraphCountMetric, SubgraphName, SubgraphRegistrar, SubgraphStore as SubgraphStoreTrait, SubgraphVersionSwitchingMode, }; -use graph::slog::{info, o, Logger}; +use graph::slog::{Logger, info, o}; use graph_chain_ethereum::network::{EthereumNetworkAdapter, EthereumNetworkAdapters}; use graph_chain_ethereum::{ - chain::ChainSettings, Chain, EthereumAdapter, NodeCapabilities, ProviderEthRpcMetrics, - Transport, + Chain, EthereumAdapter, NodeCapabilities, ProviderEthRpcMetrics, Transport, + chain::ChainSettings, }; use graph_core::polling_monitor::{arweave_service, ipfs_service}; use graph_graphql::prelude::GraphQlRunner; diff --git a/gnd/src/commands/test/trigger.rs b/gnd/src/commands/test/trigger.rs index 8af4272a071..297e6a064ff 100644 --- a/gnd/src/commands/test/trigger.rs +++ b/gnd/src/commands/test/trigger.rs @@ -7,19 +7,19 @@ //! - data = ABI-encoded `value` (non-indexed) use super::schema::{LogEvent, TestFile}; -use anyhow::{anyhow, ensure, Context, Result}; +use anyhow::{Context, Result, anyhow, ensure}; use graph::blockchain::block_stream::BlockWithTriggers; use graph::components::ethereum::AnyTransactionReceiptBare; use graph::prelude::alloy::consensus::{Eip658Value, Receipt, ReceiptWithBloom}; use graph::prelude::alloy::dyn_abi::{DynSolType, DynSolValue}; use graph::prelude::alloy::json_abi::Event; use graph::prelude::alloy::network::AnyReceiptEnvelope; -use graph::prelude::alloy::primitives::{keccak256, Address, Bloom, Bytes, B256, I256, U256}; +use graph::prelude::alloy::primitives::{Address, B256, Bloom, Bytes, I256, U256, keccak256}; use graph::prelude::alloy::rpc::types::{Log, TransactionReceipt}; use graph::prelude::{BlockPtr, LightEthereumBlock}; +use graph_chain_ethereum::Chain; use graph_chain_ethereum::chain::BlockFinality; use graph_chain_ethereum::trigger::{EthereumBlockTriggerType, EthereumTrigger, LogRef}; -use graph_chain_ethereum::Chain; use std::collections::HashMap; use std::sync::Arc; @@ -293,11 +293,7 @@ pub fn json_to_sol_value(sol_type: &DynSolType, value: &serde_json::Value) -> Re None => (s_abs, 10), }; let abs = U256::from_str_radix(digits, radix).context("Invalid int")?; - if is_neg { - !abs + U256::from(1) - } else { - abs - } + if is_neg { !abs + U256::from(1) } else { abs } } serde_json::Value::Number(n) => { if let Some(i) = n.as_i64() { @@ -470,10 +466,10 @@ fn create_block_with_triggers( // Collect unique transaction hashes from log triggers. let mut tx_hashes: HashSet = HashSet::new(); for trigger in &triggers { - if let EthereumTrigger::Log(LogRef::FullLog(log, _)) = trigger { - if let Some(tx_hash) = log.transaction_hash { - tx_hashes.insert(tx_hash); - } + if let EthereumTrigger::Log(LogRef::FullLog(log, _)) = trigger + && let Some(tx_hash) = log.transaction_hash + { + tx_hashes.insert(tx_hash); } } diff --git a/gnd/src/compiler/asc.rs b/gnd/src/compiler/asc.rs index 6c06218f27a..821adba699c 100644 --- a/gnd/src/compiler/asc.rs +++ b/gnd/src/compiler/asc.rs @@ -6,7 +6,7 @@ use std::path::{Path, PathBuf}; use std::process::Command; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; /// Options for compiling an AssemblyScript file. #[derive(Debug, Clone)] diff --git a/gnd/src/compiler/mod.rs b/gnd/src/compiler/mod.rs index 6b5bcf9b1f4..0c80a4aec89 100644 --- a/gnd/src/compiler/mod.rs +++ b/gnd/src/compiler/mod.rs @@ -5,4 +5,4 @@ mod asc; -pub use asc::{compile_mapping, find_asc_binary, find_graph_ts, AscCompileOptions}; +pub use asc::{AscCompileOptions, compile_mapping, find_asc_binary, find_graph_ts}; diff --git a/gnd/src/config/mod.rs b/gnd/src/config/mod.rs index 6a95a7043e8..38b57baf6b4 100644 --- a/gnd/src/config/mod.rs +++ b/gnd/src/config/mod.rs @@ -8,6 +8,6 @@ pub mod networks; pub use networks::{ - apply_network_config, get_network_config, init_networks_config, load_networks_config, - update_networks_file, DataSourceNetworkConfig, NetworkConfig, NetworksConfig, + DataSourceNetworkConfig, NetworkConfig, NetworksConfig, apply_network_config, + get_network_config, init_networks_config, load_networks_config, update_networks_file, }; diff --git a/gnd/src/config/networks.rs b/gnd/src/config/networks.rs index 48abc2c6f9a..667d72745aa 100644 --- a/gnd/src/config/networks.rs +++ b/gnd/src/config/networks.rs @@ -8,7 +8,7 @@ use std::collections::HashMap; use std::fs; use std::path::Path; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use serde::{Deserialize, Serialize}; /// Network-specific configuration for a data source. @@ -85,24 +85,24 @@ pub fn apply_network_config( network_config: &NetworkConfig, ) -> Result<()> { // Update data sources - if let Some(data_sources) = manifest.get_mut("dataSources") { - if let Some(arr) = data_sources.as_sequence_mut() { - for ds in arr.iter_mut() { - update_data_source(ds, network, network_config)?; - } + if let Some(data_sources) = manifest.get_mut("dataSources") + && let Some(arr) = data_sources.as_sequence_mut() + { + for ds in arr.iter_mut() { + update_data_source(ds, network, network_config)?; } } // Update templates to use the same network - if let Some(templates) = manifest.get_mut("templates") { - if let Some(arr) = templates.as_sequence_mut() { - for template in arr.iter_mut() { - if let Some(mapping) = template.as_mapping_mut() { - mapping.insert( - serde_yaml::Value::String("network".to_string()), - serde_yaml::Value::String(network.to_string()), - ); - } + if let Some(templates) = manifest.get_mut("templates") + && let Some(arr) = templates.as_sequence_mut() + { + for template in arr.iter_mut() { + if let Some(mapping) = template.as_mapping_mut() { + mapping.insert( + serde_yaml::Value::String("network".to_string()), + serde_yaml::Value::String(network.to_string()), + ); } } } diff --git a/gnd/src/formatter.rs b/gnd/src/formatter.rs index 0c85f1589a7..58947e15519 100644 --- a/gnd/src/formatter.rs +++ b/gnd/src/formatter.rs @@ -6,7 +6,7 @@ use std::io::Write; use std::process::{Command, Stdio}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; /// Format TypeScript/AssemblyScript code using Prettier. /// diff --git a/gnd/src/main.rs b/gnd/src/main.rs index d4c90f72ba3..fc7369528b7 100644 --- a/gnd/src/main.rs +++ b/gnd/src/main.rs @@ -2,16 +2,16 @@ use std::io; use anyhow::Result; use clap::{CommandFactory, Parser, Subcommand, ValueEnum}; -use clap_complete::{generate, Shell}; +use clap_complete::{Shell, generate}; use git_testament::{git_testament, render_testament}; use graph::log::logger; use lazy_static::lazy_static; use tokio_util::sync::CancellationToken; use gnd::commands::{ - run_add, run_auth, run_build, run_clean, run_codegen, run_create, run_deploy, run_dev, - run_init, run_publish, run_remove, run_test, AddOpt, AuthOpt, BuildOpt, CleanOpt, CodegenOpt, - CreateOpt, DeployOpt, DevOpt, InitOpt, PublishOpt, RemoveOpt, TestOpt, + AddOpt, AuthOpt, BuildOpt, CleanOpt, CodegenOpt, CreateOpt, DeployOpt, DevOpt, InitOpt, + PublishOpt, RemoveOpt, TestOpt, run_add, run_auth, run_build, run_clean, run_codegen, + run_create, run_deploy, run_dev, run_init, run_publish, run_remove, run_test, }; git_testament!(TESTAMENT); @@ -155,8 +155,10 @@ fn generate_completions(completions_opt: CompletionsOpt) -> Result<()> { #[tokio::main] async fn main() -> Result<()> { - std::env::set_var("ETHEREUM_REORG_THRESHOLD", "10"); - std::env::set_var("GRAPH_NODE_DISABLE_DEPLOYMENT_HASH_VALIDATION", "true"); + unsafe { + std::env::set_var("ETHEREUM_REORG_THRESHOLD", "10"); + std::env::set_var("GRAPH_NODE_DISABLE_DEPLOYMENT_HASH_VALIDATION", "true"); + } env_logger::init(); let cli = Cli::parse(); diff --git a/gnd/src/manifest.rs b/gnd/src/manifest.rs index 947eff5fd12..0221070edfe 100644 --- a/gnd/src/manifest.rs +++ b/gnd/src/manifest.rs @@ -17,7 +17,7 @@ use graph::prelude::DeploymentHash; use graph_chain_ethereum::{BlockHandlerFilter, Chain}; use semver::Version; -use crate::output::{step, Step}; +use crate::output::{Step, step}; /// Type alias for the graph-node unresolved manifest parameterized on Ethereum. type GraphManifest = UnresolvedSubgraphManifest; diff --git a/gnd/src/migrations/api_version.rs b/gnd/src/migrations/api_version.rs index 64ed1670ae4..f660d54ca5e 100644 --- a/gnd/src/migrations/api_version.rs +++ b/gnd/src/migrations/api_version.rs @@ -6,8 +6,8 @@ use anyhow::Result; use super::{ - load_manifest, manifest_has_api_version, replace_in_file, versions, Migration, MigrationCheck, - MigrationContext, + Migration, MigrationCheck, MigrationContext, load_manifest, manifest_has_api_version, + replace_in_file, versions, }; /// Helper to create an API version migration check. diff --git a/gnd/src/migrations/mod.rs b/gnd/src/migrations/mod.rs index cf1e6be8317..0fa888e80e6 100644 --- a/gnd/src/migrations/mod.rs +++ b/gnd/src/migrations/mod.rs @@ -18,7 +18,7 @@ use std::path::Path; use anyhow::Result; use regex::Regex; -use crate::output::{step, Step}; +use crate::output::{Step, step}; pub use versions::get_graph_ts_version; @@ -139,10 +139,9 @@ fn manifest_has_api_version(manifest: &serde_json::Value, version: &str) -> bool .get("mapping") .and_then(|m| m.get("apiVersion")) .and_then(|v| v.as_str()) + && api_version == version { - if api_version == version { - return true; - } + return true; } } } @@ -154,10 +153,9 @@ fn manifest_has_api_version(manifest: &serde_json::Value, version: &str) -> bool .get("mapping") .and_then(|m| m.get("apiVersion")) .and_then(|v| v.as_str()) + && api_version == version { - if api_version == version { - return true; - } + return true; } } } diff --git a/gnd/src/migrations/spec_version.rs b/gnd/src/migrations/spec_version.rs index a1b6ecd573d..ffdb6f13ce7 100644 --- a/gnd/src/migrations/spec_version.rs +++ b/gnd/src/migrations/spec_version.rs @@ -4,7 +4,7 @@ use anyhow::Result; -use super::{load_manifest, replace_in_file, Migration, MigrationCheck, MigrationContext}; +use super::{Migration, MigrationCheck, MigrationContext, load_manifest, replace_in_file}; /// Migration: specVersion 0.0.1 -> 0.0.2 /// diff --git a/gnd/src/migrations/versions.rs b/gnd/src/migrations/versions.rs index f33703b95ad..f0cd6a3e221 100644 --- a/gnd/src/migrations/versions.rs +++ b/gnd/src/migrations/versions.rs @@ -5,7 +5,7 @@ use std::path::Path; -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use semver::Version; /// Get the installed graph-ts version by searching node_modules. diff --git a/gnd/src/output/mod.rs b/gnd/src/output/mod.rs index 9b7ea7b118f..e0cf8a356f5 100644 --- a/gnd/src/output/mod.rs +++ b/gnd/src/output/mod.rs @@ -1,6 +1,6 @@ mod spinner; -pub use spinner::{step as spinner_step, with_spinner, Spinner, SpinnerResult}; +pub use spinner::{Spinner, SpinnerResult, step as spinner_step, with_spinner}; use console::style; diff --git a/gnd/src/output/spinner.rs b/gnd/src/output/spinner.rs index 01405fc9a16..24822e294d3 100644 --- a/gnd/src/output/spinner.rs +++ b/gnd/src/output/spinner.rs @@ -28,7 +28,7 @@ use std::fmt::Display; use std::time::Duration; -use console::{style, Term}; +use console::{Term, style}; use indicatif::{ProgressBar, ProgressStyle}; /// The checkmark symbol used for successful steps (matches TS CLI) diff --git a/gnd/src/prompt.rs b/gnd/src/prompt.rs index 608af7327dd..aa27b04a3d3 100644 --- a/gnd/src/prompt.rs +++ b/gnd/src/prompt.rs @@ -6,11 +6,11 @@ use std::path::Path; use anyhow::Result; -use console::{style, Term}; +use console::{Term, style}; use inquire::validator::Validation; use inquire::{Autocomplete, Confirm, CustomUserError, Select, Text}; -use crate::output::{step, Step}; +use crate::output::{Step, step}; use crate::services::{ContractInfo, ContractService, Network, NetworksRegistry}; /// Format a network for display. @@ -608,12 +608,12 @@ fn prompt_network_interactive(registry: &NetworksRegistry) -> Result { // Extract network ID from the selection // Format is "Full Name (id)" - if let Some(start) = input.rfind('(') { - if let Some(end) = input.rfind(')') { - let id = &input[start + 1..end]; - if registry.get_network(id).is_some() { - return Ok(id.to_string()); - } + if let Some(start) = input.rfind('(') + && let Some(end) = input.rfind(')') + { + let id = &input[start + 1..end]; + if registry.get_network(id).is_some() { + return Ok(id.to_string()); } } diff --git a/gnd/src/scaffold/mapping.rs b/gnd/src/scaffold/mapping.rs index aed72e33466..9034cf4ec2c 100644 --- a/gnd/src/scaffold/mapping.rs +++ b/gnd/src/scaffold/mapping.rs @@ -1,7 +1,7 @@ //! Mapping (AssemblyScript) generation for scaffold. -use super::manifest::{extract_events_from_abi, EventInfo}; use super::ScaffoldOptions; +use super::manifest::{EventInfo, extract_events_from_abi}; /// Generate the mapping.ts content. pub fn generate_mapping(options: &ScaffoldOptions) -> String { @@ -276,10 +276,10 @@ fn extract_callable_functions(options: &ScaffoldOptions) -> String { .unwrap_or(""); // Only include view and pure functions (callable from mappings) - if state == "view" || state == "pure" { - if let Some(name) = item.get("name").and_then(|n| n.as_str()) { - functions.push(format!("\n // - contract.{}(...)", name)); - } + if (state == "view" || state == "pure") + && let Some(name) = item.get("name").and_then(|n| n.as_str()) + { + functions.push(format!("\n // - contract.{}(...)", name)); } } } diff --git a/gnd/src/scaffold/mod.rs b/gnd/src/scaffold/mod.rs index 57345458408..2a9e7f18d39 100644 --- a/gnd/src/scaffold/mod.rs +++ b/gnd/src/scaffold/mod.rs @@ -7,7 +7,7 @@ pub mod manifest; mod mapping; mod schema; -pub use manifest::{extract_events_from_abi, generate_manifest, EventInfo, EventInput}; +pub use manifest::{EventInfo, EventInput, extract_events_from_abi, generate_manifest}; pub use mapping::generate_mapping; pub use schema::generate_schema; @@ -15,12 +15,12 @@ use std::fs; use std::path::Path; use std::process::{Command, Stdio}; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use inflector::Inflector; use serde_json::Value as JsonValue; use crate::formatter::format_typescript; -use crate::output::{step, with_spinner, Step}; +use crate::output::{Step, step, with_spinner}; /// Options for scaffold generation. #[derive(Debug, Clone)] diff --git a/gnd/src/scaffold/schema.rs b/gnd/src/scaffold/schema.rs index 35079e9dde3..b7141f66f3d 100644 --- a/gnd/src/scaffold/schema.rs +++ b/gnd/src/scaffold/schema.rs @@ -1,7 +1,7 @@ //! Schema (schema.graphql) generation for scaffold. -use super::manifest::{extract_events_from_abi, EventInput}; use super::ScaffoldOptions; +use super::manifest::{EventInput, extract_events_from_abi}; /// Generate the schema.graphql content. pub fn generate_schema(options: &ScaffoldOptions) -> String { diff --git a/gnd/src/services/contract.rs b/gnd/src/services/contract.rs index d237577ad6c..d6dea4376c2 100644 --- a/gnd/src/services/contract.rs +++ b/gnd/src/services/contract.rs @@ -6,7 +6,7 @@ use std::env; use std::time::Duration; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use reqwest::Client; use serde::Deserialize; use serde_json::Value as JsonValue; @@ -220,15 +220,15 @@ impl ContractService { match self.fetch_from_etherscan(&api_url).await { Ok(response) => { - if response.status == "1" { - if let Some(result) = response.result { - // The result is a JSON string containing the ABI - if let Some(abi_str) = result.as_str() { - return serde_json::from_str(abi_str) - .context("Failed to parse ABI JSON"); - } - return Ok(result); + if response.status == "1" + && let Some(result) = response.result + { + // The result is a JSON string containing the ABI + if let Some(abi_str) = result.as_str() { + return serde_json::from_str(abi_str) + .context("Failed to parse ABI JSON"); } + return Ok(result); } last_error = Some(anyhow!( "{} - {}", @@ -273,16 +273,13 @@ impl ContractService { if response.status().is_success() { match response.json::().await { Ok(data) => { - if data.status == "1" { - if let Some(results) = data.result { - if let Some(first) = results.first() { - if let Some(name) = &first.contract_name { - if !name.is_empty() { - return Ok(name.clone()); - } - } - } - } + if data.status == "1" + && let Some(results) = data.result + && let Some(first) = results.first() + && let Some(name) = &first.contract_name + && !name.is_empty() + { + return Ok(name.clone()); } last_error = Some(anyhow!("Contract name is empty")); } @@ -330,24 +327,21 @@ impl ContractService { if response.status().is_success() { match response.json::().await { Ok(data) => { - if data.status == "1" { - if let Some(results) = data.result { - if let Some(first) = results.first() { - // Try direct block number first - if let Some(block) = &first.block_number { - if let Ok(num) = block.parse::() { - return Ok(num); - } - } - // Fall back to fetching transaction - if let Some(tx_hash) = &first.tx_hash { - if let Ok(block) = - self.get_block_from_tx(network_id, tx_hash).await - { - return Ok(block); - } - } - } + if data.status == "1" + && let Some(results) = data.result + && let Some(first) = results.first() + { + // Try direct block number first + if let Some(block) = &first.block_number + && let Ok(num) = block.parse::() + { + return Ok(num); + } + // Fall back to fetching transaction + if let Some(tx_hash) = &first.tx_hash + && let Ok(block) = self.get_block_from_tx(network_id, tx_hash).await + { + return Ok(block); } } last_error = Some(anyhow!("No contract creation info found")); @@ -570,13 +564,13 @@ impl ContractService { if response.status().is_success() { match response.json::().await { Ok(data) => { - if let Some(result) = data.result { - if let Some(block_hex) = result.block_number { - // Parse hex block number - let block_str = block_hex.trim_start_matches("0x"); - if let Ok(block) = u64::from_str_radix(block_str, 16) { - return Ok(block); - } + if let Some(result) = data.result + && let Some(block_hex) = result.block_number + { + // Parse hex block number + let block_str = block_hex.trim_start_matches("0x"); + if let Ok(block) = u64::from_str_radix(block_str, 16) { + return Ok(block); } } last_error = Some(anyhow!("No block number in transaction")); diff --git a/gnd/src/services/graph_node.rs b/gnd/src/services/graph_node.rs index 61facbf897e..9d3faa07d2b 100644 --- a/gnd/src/services/graph_node.rs +++ b/gnd/src/services/graph_node.rs @@ -3,7 +3,7 @@ //! This client is used by the `create`, `remove`, and `deploy` commands to //! interact with a Graph Node instance. -use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION, USER_AGENT}; +use reqwest::header::{AUTHORIZATION, HeaderMap, HeaderValue, USER_AGENT}; use serde::{Deserialize, Serialize}; use thiserror::Error; use url::Url; @@ -48,7 +48,7 @@ impl GraphNodeClient { other => { return Err(GraphNodeError::UnsupportedProtocol { protocol: other.to_string(), - }) + }); } } diff --git a/gnd/src/services/ipfs.rs b/gnd/src/services/ipfs.rs index 42f9dedd347..54070dbac2b 100644 --- a/gnd/src/services/ipfs.rs +++ b/gnd/src/services/ipfs.rs @@ -7,7 +7,7 @@ use std::collections::HashMap; use std::path::Path; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use reqwest::multipart::{Form, Part}; use serde::Deserialize; use url::Url; diff --git a/gnd/src/services/mod.rs b/gnd/src/services/mod.rs index c9bf2c10b4b..27fa4942c99 100644 --- a/gnd/src/services/mod.rs +++ b/gnd/src/services/mod.rs @@ -3,8 +3,8 @@ mod graph_node; mod ipfs; pub use contract::{ - get_fallback_etherscan_url, ContractInfo, ContractService, Network, NetworksRegistry, - SourcifyResult, + ContractInfo, ContractService, Network, NetworksRegistry, SourcifyResult, + get_fallback_etherscan_url, }; pub use graph_node::{DeployResult, GraphNodeClient, GraphNodeError}; -pub use ipfs::{read_file, IpfsClient}; +pub use ipfs::{IpfsClient, read_file}; diff --git a/gnd/src/shared/mod.rs b/gnd/src/shared/mod.rs index f2a243f57b6..4421dbd4645 100644 --- a/gnd/src/shared/mod.rs +++ b/gnd/src/shared/mod.rs @@ -5,4 +5,4 @@ pub mod sanitize; -pub use sanitize::{capitalize, handle_reserved_word, RESERVED_WORDS}; +pub use sanitize::{RESERVED_WORDS, capitalize, handle_reserved_word}; diff --git a/gnd/src/validation/mod.rs b/gnd/src/validation/mod.rs index b64c9f41398..8991df4fba5 100644 --- a/gnd/src/validation/mod.rs +++ b/gnd/src/validation/mod.rs @@ -9,9 +9,9 @@ use std::path::Path; use anyhow::{Context, Result}; use graph::abi::{Event, Function, JsonAbi}; +use graph::data::subgraph::SubgraphManifestValidationError; use graph::data::subgraph::api_version::{LATEST_VERSION, MIN_SPEC_VERSION}; use graph::data::subgraph::manifest_validation; -use graph::data::subgraph::SubgraphManifestValidationError; use graph::prelude::DeploymentHash; use graph::schema::{InputSchema, SchemaValidationError}; use semver::Version; @@ -307,10 +307,10 @@ pub(crate) fn validate_manifest( .collect(); // Only validate networks if there are data sources - if !manifest.data_sources.is_empty() { - if let Err(e) = manifest_validation::validate_single_network(&networks) { - errors.push(e.into()); - } + if !manifest.data_sources.is_empty() + && let Err(e) = manifest_validation::validate_single_network(&networks) + { + errors.push(e.into()); } // Collect API versions from data sources and templates @@ -492,26 +492,26 @@ fn validate_source_abi_references(manifest: &Manifest) -> Vec CacheWeight for MapMeasure { unsafe impl GlobalAlloc for Counter { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - let ret = System.alloc(layout); + let ret = unsafe { System.alloc(layout) }; if !ret.is_null() { ALLOCATED.fetch_add(layout.size(), SeqCst); } @@ -174,7 +174,7 @@ unsafe impl GlobalAlloc for Counter { } unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { - System.dealloc(ptr, layout); + unsafe { System.dealloc(ptr, layout) }; ALLOCATED.fetch_sub(layout.size(), SeqCst); } } @@ -240,11 +240,7 @@ impl Template for BigInt { let f = match rng { Some(rng) => { let mag = rng.random_range(1..100); - if rng.random_bool(0.5) { - mag - } else { - -mag - } + if rng.random_bool(0.5) { mag } else { -mag } } None => 1, }; @@ -261,11 +257,7 @@ impl Template for BigDecimal { let f = match rng.as_deref_mut() { Some(rng) => { let mag = rng.random_range(1i32..100); - if rng.random_bool(0.5) { - mag - } else { - -mag - } + if rng.random_bool(0.5) { mag } else { -mag } } None => 1, }; @@ -564,11 +556,7 @@ struct Opt { } fn maybe_rng<'a>(opt: &'a Opt, rng: &'a mut SmallRng) -> Option<&'a mut SmallRng> { - if opt.seed == Some(0) { - None - } else { - Some(rng) - } + if opt.seed == Some(0) { None } else { Some(rng) } } fn stress(opt: &Opt) { diff --git a/graph/examples/validate.rs b/graph/examples/validate.rs index b94c00b999d..87888ef155b 100644 --- a/graph/examples/validate.rs +++ b/graph/examples/validate.rs @@ -29,12 +29,12 @@ /// ``` use clap::Parser; -use graph::data::graphql::ext::DirectiveFinder; use graph::data::graphql::DirectiveExt; use graph::data::graphql::DocumentExt; +use graph::data::graphql::ext::DirectiveFinder; use graph::data::subgraph::SPEC_VERSION_1_1_0; -use graph::prelude::s; use graph::prelude::DeploymentHash; +use graph::prelude::s; use graph::schema::InputSchema; use serde::Deserialize; use std::alloc::GlobalAlloc; @@ -50,7 +50,7 @@ use std::sync::atomic::AtomicBool; use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; use std::time::{Duration, Instant}; -use graph::anyhow::{anyhow, bail, Result}; +use graph::anyhow::{Result, anyhow, bail}; // Install an allocator that tracks allocation sizes @@ -60,7 +60,7 @@ struct Counter; unsafe impl GlobalAlloc for Counter { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - let ret = System.alloc(layout); + let ret = unsafe { System.alloc(layout) }; if !ret.is_null() { ALLOCATED.fetch_add(layout.size(), SeqCst); } @@ -68,7 +68,7 @@ unsafe impl GlobalAlloc for Counter { } unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { - System.dealloc(ptr, layout); + unsafe { System.dealloc(ptr, layout) }; ALLOCATED.fetch_sub(layout.size(), SeqCst); } } @@ -278,7 +278,9 @@ impl Runner for Sizer { pub fn main() { // Allow fulltext search in schemas - std::env::set_var("GRAPH_ALLOW_NON_DETERMINISTIC_FULLTEXT_SEARCH", "true"); + unsafe { + std::env::set_var("GRAPH_ALLOW_NON_DETERMINISTIC_FULLTEXT_SEARCH", "true"); + } let opt = Opts::parse(); diff --git a/graph/src/abi/event_ext.rs b/graph/src/abi/event_ext.rs index 383252a379f..9083f44b931 100644 --- a/graph/src/abi/event_ext.rs +++ b/graph/src/abi/event_ext.rs @@ -2,8 +2,8 @@ use std::collections::VecDeque; use alloy::json_abi::Event; use alloy::rpc::types::Log; -use anyhow::anyhow; use anyhow::Result; +use anyhow::anyhow; use crate::abi::{DynSolParam, DynSolValue}; diff --git a/graph/src/abi/function_ext.rs b/graph/src/abi/function_ext.rs index 52696beac23..ab17e0d9b55 100644 --- a/graph/src/abi/function_ext.rs +++ b/graph/src/abi/function_ext.rs @@ -5,8 +5,8 @@ use alloy::dyn_abi::DynSolValue; use alloy::dyn_abi::Specifier; use alloy::json_abi::Function; use alloy::json_abi::Param; -use anyhow::anyhow; use anyhow::Result; +use anyhow::anyhow; use itertools::Itertools; use crate::abi::DynSolValueExt; diff --git a/graph/src/abi/value_ext.rs b/graph/src/abi/value_ext.rs index cb0f220e036..cf0d36006af 100644 --- a/graph/src/abi/value_ext.rs +++ b/graph/src/abi/value_ext.rs @@ -1,7 +1,7 @@ use alloy::dyn_abi::DynSolType; use alloy::dyn_abi::DynSolValue; -use anyhow::anyhow; use anyhow::Result; +use anyhow::anyhow; use itertools::Itertools; pub trait DynSolValueExt { @@ -258,16 +258,26 @@ mod tests { assert!(!Array(vec![Bool(true)]).type_check(&T::Array(Box::new(T::String)))); assert!(!Array(vec![Bool(true)]).type_check(&T::FixedArray(Box::new(T::Bool), 1))); - assert!(!FixedArray(vec![String("".to_owned())]) - .type_check(&T::FixedArray(Box::new(T::Bool), 1))); - assert!(!FixedArray(vec![Bool(true), Bool(false)]) - .type_check(&T::FixedArray(Box::new(T::Bool), 1))); - assert!(FixedArray(vec![Bool(true), Bool(false)]) - .type_check(&T::FixedArray(Box::new(T::Bool), 2))); - assert!(!FixedArray(vec![Bool(true), Bool(false)]) - .type_check(&T::FixedArray(Box::new(T::Bool), 3))); - assert!(!FixedArray(vec![Bool(true), Bool(false)]) - .type_check(&T::Tuple(vec![T::Bool, T::Bool]))); + assert!( + !FixedArray(vec![String("".to_owned())]) + .type_check(&T::FixedArray(Box::new(T::Bool), 1)) + ); + assert!( + !FixedArray(vec![Bool(true), Bool(false)]) + .type_check(&T::FixedArray(Box::new(T::Bool), 1)) + ); + assert!( + FixedArray(vec![Bool(true), Bool(false)]) + .type_check(&T::FixedArray(Box::new(T::Bool), 2)) + ); + assert!( + !FixedArray(vec![Bool(true), Bool(false)]) + .type_check(&T::FixedArray(Box::new(T::Bool), 3)) + ); + assert!( + !FixedArray(vec![Bool(true), Bool(false)]) + .type_check(&T::Tuple(vec![T::Bool, T::Bool])) + ); assert!(!Tuple(vec![Bool(true), Bool(false)]).type_check(&T::Tuple(vec![T::Bool]))); assert!(Tuple(vec![Bool(true), Bool(false)]).type_check(&T::Tuple(vec![T::Bool, T::Bool]))); diff --git a/graph/src/amp/client/flight_client.rs b/graph/src/amp/client/flight_client.rs index 87dd747f0c8..bda2c783fd9 100644 --- a/graph/src/amp/client/flight_client.rs +++ b/graph/src/amp/client/flight_client.rs @@ -9,10 +9,10 @@ use arrow_flight::{ }; use async_stream::try_stream; use bytes::Bytes; -use futures03::{future::BoxFuture, stream::BoxStream, StreamExt}; +use futures03::{StreamExt, future::BoxFuture, stream::BoxStream}; use http::Uri; use serde::{Deserialize, Serialize}; -use slog::{debug, trace, Logger}; +use slog::{Logger, debug, trace}; use thiserror::Error; use tonic::transport::{Channel, ClientTlsConfig, Endpoint}; @@ -22,7 +22,7 @@ use crate::{ Client, LatestBlockBeforeReorg, RequestMetadata, ResponseBatch, ResumeStreamingQuery, }, error, - log::{one_line, Logger as _}, + log::{Logger as _, one_line}, }, prelude::CheapClone, }; diff --git a/graph/src/amp/codec/array_decoder.rs b/graph/src/amp/codec/array_decoder.rs index f7a480f38d0..3c261554ff3 100644 --- a/graph/src/amp/codec/array_decoder.rs +++ b/graph/src/amp/codec/array_decoder.rs @@ -1,15 +1,15 @@ use std::{fmt::Display, sync::LazyLock}; use alloy::primitives::B256; -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use arrow::{ array::{ - timezone::Tz, Array, ArrayAccessor, BinaryArray, BinaryViewArray, BooleanArray, - Decimal128Array, Decimal256Array, FixedSizeBinaryArray, Float16Array, Float32Array, - Float64Array, Int16Array, Int32Array, Int64Array, Int8Array, LargeBinaryArray, - LargeStringArray, PrimitiveArray, StringArray, StringViewArray, TimestampMicrosecondArray, - TimestampMillisecondArray, TimestampNanosecondArray, TimestampSecondArray, UInt16Array, - UInt32Array, UInt64Array, UInt8Array, + Array, ArrayAccessor, BinaryArray, BinaryViewArray, BooleanArray, Decimal128Array, + Decimal256Array, FixedSizeBinaryArray, Float16Array, Float32Array, Float64Array, Int8Array, + Int16Array, Int32Array, Int64Array, LargeBinaryArray, LargeStringArray, PrimitiveArray, + StringArray, StringViewArray, TimestampMicrosecondArray, TimestampMillisecondArray, + TimestampNanosecondArray, TimestampSecondArray, UInt8Array, UInt16Array, UInt32Array, + UInt64Array, timezone::Tz, }, datatypes::ArrowTemporalType, }; diff --git a/graph/src/amp/codec/mod.rs b/graph/src/amp/codec/mod.rs index b642d0377c9..f259ae528d8 100644 --- a/graph/src/amp/codec/mod.rs +++ b/graph/src/amp/codec/mod.rs @@ -15,7 +15,7 @@ use std::{ sync::Arc, }; -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{Context, Result, anyhow, bail}; use arrow::array::{Array, RecordBatch}; use self::{list_decoder::ListDecoder, mapping_decoder::MappingDecoder, name_cache::NameCache}; @@ -244,7 +244,7 @@ impl Codec { mod tests { use std::sync::LazyLock; - use arrow::array::{BinaryArray, BooleanArray, Int64Array, Int8Array}; + use arrow::array::{BinaryArray, BooleanArray, Int8Array, Int64Array}; use arrow::datatypes::{DataType, Field, Schema}; use crate::data::subgraph::DeploymentHash; diff --git a/graph/src/amp/codec/test_fixtures.rs b/graph/src/amp/codec/test_fixtures.rs index a8a6882ff88..2a438b18137 100644 --- a/graph/src/amp/codec/test_fixtures.rs +++ b/graph/src/amp/codec/test_fixtures.rs @@ -4,14 +4,14 @@ use arrow::{ array::{ BinaryArray, BinaryViewArray, BooleanArray, BooleanBuilder, Decimal128Builder, Decimal256Builder, FixedSizeBinaryArray, FixedSizeListBuilder, Float16Array, Float32Array, - Float64Array, Int16Array, Int32Array, Int64Array, Int8Array, LargeBinaryArray, + Float64Array, Int8Array, Int16Array, Int32Array, Int64Array, LargeBinaryArray, LargeListBuilder, LargeListViewBuilder, LargeStringArray, ListBuilder, ListViewBuilder, RecordBatch, StringArray, StringViewArray, TimestampMicrosecondArray, - TimestampMillisecondArray, TimestampNanosecondArray, TimestampSecondArray, UInt16Array, - UInt32Array, UInt64Array, UInt8Array, + TimestampMillisecondArray, TimestampNanosecondArray, TimestampSecondArray, UInt8Array, + UInt16Array, UInt32Array, UInt64Array, }, datatypes::{ - i256, DataType, Field, Schema, TimeUnit, DECIMAL128_MAX_PRECISION, DECIMAL256_MAX_PRECISION, + DECIMAL128_MAX_PRECISION, DECIMAL256_MAX_PRECISION, DataType, Field, Schema, TimeUnit, i256, }, }; use chrono::{TimeZone, Utc}; diff --git a/graph/src/amp/codec/utils.rs b/graph/src/amp/codec/utils.rs index 9811f661f7b..78e8857fa6a 100644 --- a/graph/src/amp/codec/utils.rs +++ b/graph/src/amp/codec/utils.rs @@ -1,5 +1,5 @@ use alloy::primitives::{BlockHash, BlockNumber}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use arrow::array::{ Array, FixedSizeBinaryArray, RecordBatch, TimestampNanosecondArray, UInt64Array, }; diff --git a/graph/src/amp/codec/value_decoder.rs b/graph/src/amp/codec/value_decoder.rs index c6e4e7162a2..72073c31887 100644 --- a/graph/src/amp/codec/value_decoder.rs +++ b/graph/src/amp/codec/value_decoder.rs @@ -1,13 +1,13 @@ -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use arrow::{ array::{ Array, BinaryArray, BinaryViewArray, BooleanArray, Decimal128Array, Decimal256Array, FixedSizeBinaryArray, FixedSizeListArray, Float16Array, Float32Array, Float64Array, - Int16Array, Int32Array, Int64Array, Int8Array, LargeBinaryArray, LargeListArray, + Int8Array, Int16Array, Int32Array, Int64Array, LargeBinaryArray, LargeListArray, LargeListViewArray, LargeStringArray, ListArray, ListViewArray, StringArray, StringViewArray, TimestampMicrosecondArray, TimestampMillisecondArray, - TimestampNanosecondArray, TimestampSecondArray, UInt16Array, UInt32Array, UInt64Array, - UInt8Array, + TimestampNanosecondArray, TimestampSecondArray, UInt8Array, UInt16Array, UInt32Array, + UInt64Array, }, datatypes::{DataType, TimeUnit}, }; @@ -15,8 +15,8 @@ use chrono::{DateTime, Utc}; use super::{ArrayDecoder, Decoder, ListDecoder, MappingDecoder}; use crate::data::store::{ - scalar::{BigDecimal, BigInt, Bytes, Timestamp}, Value, ValueType, + scalar::{BigDecimal, BigInt, Bytes, Timestamp}, }; /// Returns a decoder that converts an Arrow array into subgraph store values. diff --git a/graph/src/amp/manifest/data_source/raw.rs b/graph/src/amp/manifest/data_source/raw.rs index 3369eebc54d..91d792293be 100644 --- a/graph/src/amp/manifest/data_source/raw.rs +++ b/graph/src/amp/manifest/data_source/raw.rs @@ -11,7 +11,7 @@ use itertools::Itertools; use lazy_regex::regex_is_match; use semver::Version; use serde::Deserialize; -use slog::{debug, error, Logger}; +use slog::{Logger, debug, error}; use thiserror::Error; use super::{Abi, DataSource, Source, Table, Transformer}; @@ -698,9 +698,9 @@ impl IsDeterministic for Error { fn validate_ident(s: &str) -> Result<(), Error> { if !regex_is_match!("^[a-zA-Z_][a-zA-Z0-9_-]{0,100}$", s) { - return Err(Error::InvalidValue( - anyhow!("invalid identifier '{s}': must start with a letter or an underscore, and contain only letters, numbers, hyphens, and underscores") - )); + return Err(Error::InvalidValue(anyhow!( + "invalid identifier '{s}': must start with a letter or an underscore, and contain only letters, numbers, hyphens, and underscores" + ))); } Ok(()) } diff --git a/graph/src/amp/manifest/mod.rs b/graph/src/amp/manifest/mod.rs index 028d567332c..520f2ebcee5 100644 --- a/graph/src/amp/manifest/mod.rs +++ b/graph/src/amp/manifest/mod.rs @@ -2,7 +2,7 @@ pub mod data_source; use std::sync::Arc; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use itertools::Itertools; use semver::Version; use slog::Logger; diff --git a/graph/src/amp/mod.rs b/graph/src/amp/mod.rs index 9541d450626..21f3e064c58 100644 --- a/graph/src/amp/mod.rs +++ b/graph/src/amp/mod.rs @@ -11,7 +11,7 @@ pub mod sql; pub mod stream_aggregator; pub use self::{ - client::{flight_client::FlightClient, Client}, + client::{Client, flight_client::FlightClient}, codec::Codec, manifest::Manifest, }; diff --git a/graph/src/amp/schema/generator/entity.rs b/graph/src/amp/schema/generator/entity.rs index e3204abc623..5655df21a48 100644 --- a/graph/src/amp/schema/generator/entity.rs +++ b/graph/src/amp/schema/generator/entity.rs @@ -1,6 +1,6 @@ use std::fmt; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use inflector::Inflector; use crate::data::store::ValueType; diff --git a/graph/src/amp/sql/query_builder/block_range_query.rs b/graph/src/amp/sql/query_builder/block_range_query.rs index 496c4a9fbd1..2c22336d379 100644 --- a/graph/src/amp/sql/query_builder/block_range_query.rs +++ b/graph/src/amp/sql/query_builder/block_range_query.rs @@ -6,7 +6,7 @@ use std::{ use alloy::primitives::BlockNumber; use sqlparser_latest::ast::{self, VisitMut, VisitorMut}; -use super::{extract_tables, parse_query, TableReference}; +use super::{TableReference, extract_tables, parse_query}; /// Limits the query execution to the specified block range. /// diff --git a/graph/src/amp/sql/query_builder/event_signature_resolver.rs b/graph/src/amp/sql/query_builder/event_signature_resolver.rs index ac37068ea3d..27a1bdcf2bd 100644 --- a/graph/src/amp/sql/query_builder/event_signature_resolver.rs +++ b/graph/src/amp/sql/query_builder/event_signature_resolver.rs @@ -1,7 +1,7 @@ use std::ops::ControlFlow; use alloy::json_abi::JsonAbi; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use sqlparser_latest::ast::{self, visit_expressions_mut}; static FUNCTION_NAME: &str = "sg_event_signature"; @@ -43,7 +43,9 @@ fn visit_expr(expr: &mut ast::Expr, abis: &[(&str, &JsonAbi)]) -> Result<()> { } let Some((contract_name, event_name)) = get_args(function) else { - bail!("invalid function call: expected `{FUNCTION_NAME}('CONTRACT_NAME', 'EVENT_NAME')`, found: `{function}`"); + bail!( + "invalid function call: expected `{FUNCTION_NAME}('CONTRACT_NAME', 'EVENT_NAME')`, found: `{function}`" + ); }; let Some(event) = get_event(abis, contract_name, event_name) else { diff --git a/graph/src/amp/sql/query_builder/mod.rs b/graph/src/amp/sql/query_builder/mod.rs index 5f5458ec092..c71c6ef5baf 100644 --- a/graph/src/amp/sql/query_builder/mod.rs +++ b/graph/src/amp/sql/query_builder/mod.rs @@ -12,7 +12,7 @@ use alloy::{ json_abi::JsonAbi, primitives::{Address, BlockNumber}, }; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use itertools::Itertools; use sqlparser_latest::ast; @@ -22,7 +22,7 @@ use self::{ event_signature_resolver::resolve_event_signatures, parser::parse_query, source_address_resolver::resolve_source_address, - table_extractor::{extract_tables, TableReference}, + table_extractor::{TableReference, extract_tables}, table_validator::validate_tables, }; diff --git a/graph/src/amp/sql/query_builder/parser.rs b/graph/src/amp/sql/query_builder/parser.rs index 2e40b0e53a3..9b25e8431f6 100644 --- a/graph/src/amp/sql/query_builder/parser.rs +++ b/graph/src/amp/sql/query_builder/parser.rs @@ -1,6 +1,6 @@ use std::ops::ControlFlow; -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{Context, Result, anyhow, bail}; use itertools::Itertools; use sqlparser_latest::{ ast::{self, Visit, Visitor}, diff --git a/graph/src/amp/sql/query_builder/source_address_resolver.rs b/graph/src/amp/sql/query_builder/source_address_resolver.rs index 579e0873bb6..e0d908deb24 100644 --- a/graph/src/amp/sql/query_builder/source_address_resolver.rs +++ b/graph/src/amp/sql/query_builder/source_address_resolver.rs @@ -1,7 +1,7 @@ use std::ops::ControlFlow; use alloy::primitives::Address; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use sqlparser_latest::ast::{self, visit_expressions_mut}; static FUNCTION_NAME: &str = "sg_source_address"; diff --git a/graph/src/amp/sql/query_builder/table_validator.rs b/graph/src/amp/sql/query_builder/table_validator.rs index 25bf2c8da30..43e7fa9c128 100644 --- a/graph/src/amp/sql/query_builder/table_validator.rs +++ b/graph/src/amp/sql/query_builder/table_validator.rs @@ -1,9 +1,9 @@ use std::collections::BTreeSet; -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use sqlparser_latest::ast; -use super::{extract_tables, TableReference}; +use super::{TableReference, extract_tables}; /// Validates that SQL query references only allowed dataset and tables. /// diff --git a/graph/src/amp/stream_aggregator/mod.rs b/graph/src/amp/stream_aggregator/mod.rs index 990d721ec8f..df990fa20d6 100644 --- a/graph/src/amp/stream_aggregator/mod.rs +++ b/graph/src/amp/stream_aggregator/mod.rs @@ -7,10 +7,10 @@ use std::{ task::{self, Poll}, }; -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use arrow::array::RecordBatch; -use futures03::{stream::BoxStream, Stream, StreamExt, TryStreamExt}; -use slog::{debug, info, Logger}; +use futures03::{Stream, StreamExt, TryStreamExt, stream::BoxStream}; +use slog::{Logger, debug, info}; use self::record_batch::Buffer; use crate::{ @@ -195,16 +195,15 @@ impl StreamAggregator { } } - if made_progress { - if let Some(completed_groups) = + if made_progress + && let Some(completed_groups) = self.buffer.completed_groups().map_err(Error::Aggregation)? - { - debug!(self.logger, "Sending completed record batch groups"; - "num_completed_groups" => completed_groups.len() - ); + { + debug!(self.logger, "Sending completed record batch groups"; + "num_completed_groups" => completed_groups.len() + ); - return Poll::Ready(Some(Ok(completed_groups))); - } + return Poll::Ready(Some(Ok(completed_groups))); } if self.is_finalized { diff --git a/graph/src/amp/stream_aggregator/record_batch/aggregator.rs b/graph/src/amp/stream_aggregator/record_batch/aggregator.rs index f2c9cff13e0..acce58ebdeb 100644 --- a/graph/src/amp/stream_aggregator/record_batch/aggregator.rs +++ b/graph/src/amp/stream_aggregator/record_batch/aggregator.rs @@ -1,10 +1,10 @@ use std::{ - collections::{btree_map::Entry, BTreeMap, HashSet}, + collections::{BTreeMap, HashSet, btree_map::Entry}, sync::{Arc, Weak}, }; use alloy::primitives::{BlockHash, BlockNumber}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use arrow::array::RecordBatch; use super::{Decoder, GroupData}; @@ -146,11 +146,11 @@ impl Aggregator { let incomplete_groups = self.buffer.split_off(max_block_ptr); let mut completed_groups = std::mem::replace(&mut self.buffer, incomplete_groups); - if let Some((block_ptr, _)) = self.buffer.first_key_value() { - if block_ptr == max_block_ptr { - let (block_ptr, group_data) = self.buffer.pop_first().unwrap(); - completed_groups.insert(block_ptr, group_data); - } + if let Some((block_ptr, _)) = self.buffer.first_key_value() + && block_ptr == max_block_ptr + { + let (block_ptr, group_data) = self.buffer.pop_first().unwrap(); + completed_groups.insert(block_ptr, group_data); } if completed_groups.is_empty() { diff --git a/graph/src/amp/stream_aggregator/record_batch/buffer.rs b/graph/src/amp/stream_aggregator/record_batch/buffer.rs index cc59390f3b5..476da79f0fc 100644 --- a/graph/src/amp/stream_aggregator/record_batch/buffer.rs +++ b/graph/src/amp/stream_aggregator/record_batch/buffer.rs @@ -1,7 +1,7 @@ -use std::collections::{btree_map::Entry, BTreeMap}; +use std::collections::{BTreeMap, btree_map::Entry}; use alloy::primitives::{BlockHash, BlockNumber}; -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use arrow::array::RecordBatch; use super::{Aggregator, RecordBatchGroup, RecordBatchGroups, StreamRecordBatch}; @@ -190,7 +190,8 @@ impl Buffer { } Entry::Occupied(entry) => { if *entry.get() != max_completed_block_hash { - bail!("aggregated data is corrupted: stream {} produced block hash '0x{}' for block {}, but a previous stream set the block hash to '0x{}'", + bail!( + "aggregated data is corrupted: stream {} produced block hash '0x{}' for block {}, but a previous stream set the block hash to '0x{}'", stream_index, hex::encode(max_completed_block_hash), max_completed_block_number, diff --git a/graph/src/amp/stream_aggregator/record_batch/decoder.rs b/graph/src/amp/stream_aggregator/record_batch/decoder.rs index a2c5cf92daf..14e5410910a 100644 --- a/graph/src/amp/stream_aggregator/record_batch/decoder.rs +++ b/graph/src/amp/stream_aggregator/record_batch/decoder.rs @@ -1,5 +1,5 @@ use alloy::primitives::{BlockHash, BlockNumber}; -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use arrow::array::RecordBatch; use crate::amp::codec::{ diff --git a/graph/src/blockchain/block_stream.rs b/graph/src/blockchain/block_stream.rs index c076619bbf9..8098cfea664 100644 --- a/graph/src/blockchain/block_stream.rs +++ b/graph/src/blockchain/block_stream.rs @@ -1,5 +1,5 @@ use crate::blockchain::SubgraphFilter; -use crate::data_source::{subgraph, CausalityRegion}; +use crate::data_source::{CausalityRegion, subgraph}; use anyhow::Error; use async_stream::stream; use async_trait::async_trait; @@ -66,7 +66,7 @@ impl BufferedBlockStream { return Err(anyhow!( "buffered blockstream channel is closed, stopping. Err: {}", err - )) + )); } } } diff --git a/graph/src/blockchain/firehose_block_ingestor.rs b/graph/src/blockchain/firehose_block_ingestor.rs index 774785fa2f5..1a0ff0f2c06 100644 --- a/graph/src/blockchain/firehose_block_ingestor.rs +++ b/graph/src/blockchain/firehose_block_ingestor.rs @@ -3,8 +3,8 @@ use std::{marker::PhantomData, sync::Arc, time::Duration}; use crate::{ blockchain::Block as BlockchainBlock, components::store::ChainHeadStore, - firehose::{self, decode_firehose_block, HeaderOnly}, - prelude::{error, info, Logger}, + firehose::{self, HeaderOnly, decode_firehose_block}, + prelude::{Logger, error, info}, util::backoff::ExponentialBackoff, }; use anyhow::{Context, Error}; @@ -15,7 +15,7 @@ use prost_types::Any; use slog::{o, trace}; use tonic::Streaming; -use super::{client::ChainClient, BlockIngestor, Blockchain, BlockchainKind}; +use super::{BlockIngestor, Blockchain, BlockchainKind, client::ChainClient}; use crate::components::network_provider::ChainName; const TRANSFORM_ETHEREUM_HEADER_ONLY: &str = diff --git a/graph/src/blockchain/firehose_block_stream.rs b/graph/src/blockchain/firehose_block_stream.rs index 90e985ff44d..9ad0f2aa6e5 100644 --- a/graph/src/blockchain/firehose_block_stream.rs +++ b/graph/src/blockchain/firehose_block_stream.rs @@ -1,10 +1,10 @@ +use super::Blockchain; use super::block_stream::{ - BlockStream, BlockStreamError, BlockStreamEvent, FirehoseMapper, FIREHOSE_BUFFER_STREAM_SIZE, + BlockStream, BlockStreamError, BlockStreamEvent, FIREHOSE_BUFFER_STREAM_SIZE, FirehoseMapper, }; use super::client::ChainClient; -use super::Blockchain; -use crate::blockchain::block_stream::FirehoseCursor; use crate::blockchain::TriggerFilter; +use crate::blockchain::block_stream::FirehoseCursor; use crate::prelude::*; use crate::util::backoff::ExponentialBackoff; use crate::{firehose, firehose::FirehoseEndpoint}; @@ -360,7 +360,10 @@ async fn process_firehose_response>( .context("Mapping block to BlockStreamEvent failed")?; if *check_subgraph_continuity { - info!(logger, "Firehose started from a subgraph pointer without an existing cursor, ensuring chain continuity"); + info!( + logger, + "Firehose started from a subgraph pointer without an existing cursor, ensuring chain continuity" + ); if let BlockStreamEvent::ProcessBlock(ref block, _) = event { let previous_block_ptr = block.parent_ptr(); @@ -380,7 +383,10 @@ async fn process_firehose_response>( .context("Could not fetch final block to revert to")?; if revert_to.number < manifest_start_block_num { - warn!(&logger, "We would return before subgraph manifest's start block, limiting rewind to manifest's start block"); + warn!( + &logger, + "We would return before subgraph manifest's start block, limiting rewind to manifest's start block" + ); // We must revert up to parent's of manifest start block to ensure we delete everything "including" the start // block that was processed. @@ -445,10 +451,10 @@ fn must_check_subgraph_continuity( #[cfg(test)] mod tests { use crate::blockchain::{ - block_stream::FirehoseCursor, firehose_block_stream::must_check_subgraph_continuity, - BlockPtr, + BlockPtr, block_stream::FirehoseCursor, + firehose_block_stream::must_check_subgraph_continuity, }; - use slog::{o, Logger}; + use slog::{Logger, o}; #[test] fn check_continuity() { diff --git a/graph/src/blockchain/mock.rs b/graph/src/blockchain/mock.rs index 79ca098849e..a87e3da1fc3 100644 --- a/graph/src/blockchain/mock.rs +++ b/graph/src/blockchain/mock.rs @@ -13,8 +13,8 @@ use crate::{ data::subgraph::{DeploymentHash, UnifiedMappingApiVersion}, data_source, prelude::{ - transaction_receipt::LightTransactionReceipt, BlockHash, ChainStore, - DataSourceTemplateInfo, StoreError, + BlockHash, ChainStore, DataSourceTemplateInfo, StoreError, + transaction_receipt::LightTransactionReceipt, }, }; use alloy::primitives::{B256, U256}; @@ -29,17 +29,17 @@ use std::{ }; use super::{ - block_stream::{self, BlockStream, FirehoseCursor}, - client::ChainClient, BlockIngestor, BlockTime, ChainIdentifier, EmptyNodeCapabilities, ExtendedBlockPtr, HostFn, IngestorError, MappingTriggerTrait, NoopDecoderHook, Trigger, TriggerFilterWrapper, TriggerWithHandler, + block_stream::{self, BlockStream, FirehoseCursor}, + client::ChainClient, }; use super::{ - block_stream::BlockWithTriggers, Block, BlockPtr, Blockchain, BlockchainKind, DataSource, - DataSourceTemplate, RuntimeAdapter, TriggerData, TriggerFilter, TriggersAdapter, - UnresolvedDataSource, UnresolvedDataSourceTemplate, + Block, BlockPtr, Blockchain, BlockchainKind, DataSource, DataSourceTemplate, RuntimeAdapter, + TriggerData, TriggerFilter, TriggersAdapter, UnresolvedDataSource, + UnresolvedDataSourceTemplate, block_stream::BlockWithTriggers, }; #[derive(Debug)] diff --git a/graph/src/blockchain/mod.rs b/graph/src/blockchain/mod.rs index f65fcea2e5b..df942d19910 100644 --- a/graph/src/blockchain/mod.rs +++ b/graph/src/blockchain/mod.rs @@ -22,17 +22,17 @@ use crate::{ subgraph::{HostMetrics, InstanceDSTemplateInfo, MappingError}, trigger_processor::RunnableTriggers, }, - data::subgraph::{UnifiedMappingApiVersion, MIN_SPEC_VERSION}, - data_source::{self, subgraph, DataSourceTemplateInfo}, + data::subgraph::{MIN_SPEC_VERSION, UnifiedMappingApiVersion}, + data_source::{self, DataSourceTemplateInfo, subgraph}, prelude::{DataSourceContext, DeploymentHash}, - runtime::{gas::GasCounter, AscHeap, HostExportError}, + runtime::{AscHeap, HostExportError, gas::GasCounter}, }; use crate::{ components::store::BlockNumber, - prelude::{thiserror::Error, LinkResolver}, + prelude::{LinkResolver, thiserror::Error}, }; use alloy::primitives::B256; -use anyhow::{anyhow, Context, Error}; +use anyhow::{Context, Error, anyhow}; use async_trait::async_trait; use futures03::future::BoxFuture; use graph_derive::CheapClone; diff --git a/graph/src/blockchain/types.rs b/graph/src/blockchain/types.rs index f3f3fff58f1..dc88bd91841 100644 --- a/graph/src/blockchain/types.rs +++ b/graph/src/blockchain/types.rs @@ -19,8 +19,8 @@ use crate::data::graphql::IntoValue; use crate::data::store::scalar::Timestamp; use crate::derive::CheapClone; use crate::object; -use crate::prelude::{r, Value}; -use crate::util::stable_hash_glue::{impl_stable_hash, AsBytes}; +use crate::prelude::{Value, r}; +use crate::util::stable_hash_glue::{AsBytes, impl_stable_hash}; /// A simple marker for byte arrays that are really block hashes #[derive(Clone, Default, PartialEq, Eq, Hash, FromSqlRow, AsExpression)] diff --git a/graph/src/components/ethereum/json_patch.rs b/graph/src/components/ethereum/json_patch.rs index 8e2daff4684..13859c8f4a7 100644 --- a/graph/src/components/ethereum/json_patch.rs +++ b/graph/src/components/ethereum/json_patch.rs @@ -10,11 +10,11 @@ use serde_json::Value; pub fn patch_type_field(obj: &mut Value) -> bool { - if let Value::Object(map) = obj { - if !map.contains_key("type") { - map.insert("type".to_string(), Value::String("0x0".to_string())); - return true; - } + if let Value::Object(map) = obj + && !map.contains_key("type") + { + map.insert("type".to_string(), Value::String("0x0".to_string())); + return true; } false } diff --git a/graph/src/components/ethereum/types.rs b/graph/src/components/ethereum/types.rs index b44385dbafa..104f6dbe036 100644 --- a/graph/src/components/ethereum/types.rs +++ b/graph/src/components/ethereum/types.rs @@ -3,10 +3,10 @@ use alloy::{ AnyHeader, AnyReceiptEnvelope, AnyRpcHeader, AnyTxEnvelope, ReceiptResponse, TransactionResponse, }, - primitives::{Address, Bytes, B256, U256}, + primitives::{Address, B256, Bytes, U256}, rpc::types::{ - trace::parity::{Action, LocalizedTransactionTrace, TraceOutput}, Block, Header, Log, Transaction, TransactionReceipt, + trace::parity::{Action, LocalizedTransactionTrace, TraceOutput}, }, }; use serde::{Deserialize, Serialize}; diff --git a/graph/src/components/link_resolver/arweave.rs b/graph/src/components/link_resolver/arweave.rs index 266558a6466..e42263c9fe1 100644 --- a/graph/src/components/link_resolver/arweave.rs +++ b/graph/src/components/link_resolver/arweave.rs @@ -4,7 +4,7 @@ use async_trait::async_trait; use futures03::prelude::Stream; use reqwest::Client; use serde_json::Value; -use slog::{debug, Logger}; +use slog::{Logger, debug}; use thiserror::Error; use crate::data_source::offchain::Base64; @@ -106,7 +106,7 @@ impl ArweaveResolver for ArweaveClient { match (&limit, rsp.content_length()) { (_, None) => return Err(ArweaveClientError::UnableToCheckFileSize), (FileSizeLimit::MaxBytes(max), Some(cl)) if cl > *max => { - return Err(ArweaveClientError::FileTooLarge { got: cl, max: *max }) + return Err(ArweaveClientError::FileTooLarge { got: cl, max: *max }); } _ => {} }; diff --git a/graph/src/components/link_resolver/ipfs.rs b/graph/src/components/link_resolver/ipfs.rs index f71a73ea5bb..c1b866c9994 100644 --- a/graph/src/components/link_resolver/ipfs.rs +++ b/graph/src/components/link_resolver/ipfs.rs @@ -12,11 +12,11 @@ use serde_json::Value; use crate::derive::CheapClone; use crate::env::EnvVars; -use crate::futures01::stream::poll_fn; -use crate::futures01::stream::Stream; -use crate::futures01::try_ready; use crate::futures01::Async; use crate::futures01::Poll; +use crate::futures01::stream::Stream; +use crate::futures01::stream::poll_fn; +use crate::futures01::try_ready; use crate::ipfs::{ContentPath, IpfsClient, IpfsContext, RetryPolicy}; use crate::prelude::*; diff --git a/graph/src/components/metrics/block_state.rs b/graph/src/components/metrics/block_state.rs index 7aac48278b9..93c9f9a8302 100644 --- a/graph/src/components/metrics/block_state.rs +++ b/graph/src/components/metrics/block_state.rs @@ -1,10 +1,10 @@ use std::collections::HashMap; -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use futures03::future::join_all; -use object_store::{gcp::GoogleCloudStorageBuilder, path::Path, ObjectStoreExt as _}; +use object_store::{ObjectStoreExt as _, gcp::GoogleCloudStorageBuilder, path::Path}; use serde::Serialize; -use slog::{error, info, Logger}; +use slog::{Logger, error, info}; use url::Url; use crate::{ diff --git a/graph/src/components/metrics/mod.rs b/graph/src/components/metrics/mod.rs index ea5cf5d9ea5..f028c8aa515 100644 --- a/graph/src/components/metrics/mod.rs +++ b/graph/src/components/metrics/mod.rs @@ -1,7 +1,7 @@ pub use prometheus::core::Collector; pub use prometheus::{ - labels, Counter, CounterVec, Error as PrometheusError, Gauge, GaugeVec, Histogram, - HistogramOpts, HistogramVec, Opts, Registry, + Counter, CounterVec, Error as PrometheusError, Gauge, GaugeVec, Histogram, HistogramOpts, + HistogramVec, Opts, Registry, labels, }; pub mod registry; diff --git a/graph/src/components/metrics/registry.rs b/graph/src/components/metrics/registry.rs index 4777ea6f62f..5efb6564ef7 100644 --- a/graph/src/components/metrics/registry.rs +++ b/graph/src/components/metrics/registry.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use crate::parking_lot::RwLock; -use prometheus::{labels, Histogram, IntCounterVec}; +use prometheus::{Histogram, IntCounterVec, labels}; use prometheus::{IntCounter, IntGauge}; use slog::debug; @@ -13,7 +13,7 @@ use crate::prometheus::{ Counter, CounterVec, Error as PrometheusError, Gauge, GaugeVec, HistogramOpts, HistogramVec, Opts, Registry, }; -use crate::slog::{self, error, o, Logger}; +use crate::slog::{self, Logger, error, o}; pub struct MetricsRegistry { logger: Logger, diff --git a/graph/src/components/metrics/stopwatch.rs b/graph/src/components/metrics/stopwatch.rs index f9eb5ff78dc..ce6ddfd0ff8 100644 --- a/graph/src/components/metrics/stopwatch.rs +++ b/graph/src/components/metrics/stopwatch.rs @@ -1,4 +1,4 @@ -use std::sync::{atomic::AtomicBool, atomic::Ordering, Mutex}; +use std::sync::{Mutex, atomic::AtomicBool, atomic::Ordering}; use std::time::Instant; use crate::derive::CheapClone; diff --git a/graph/src/components/metrics/subgraph.rs b/graph/src/components/metrics/subgraph.rs index abcf2810e6a..e45e7bd33a5 100644 --- a/graph/src/components/metrics/subgraph.rs +++ b/graph/src/components/metrics/subgraph.rs @@ -6,8 +6,8 @@ use indoc::indoc; use prometheus::Counter; use prometheus::IntGauge; -use super::stopwatch::StopwatchMetrics; use super::MetricsRegistry; +use super::stopwatch::StopwatchMetrics; use crate::blockchain::block_stream::BlockStreamMetrics; use crate::components::store::DeploymentLocator; use crate::prelude::{Gauge, Histogram, HostMetrics}; diff --git a/graph/src/components/network_provider/chain_identifier_validator.rs b/graph/src/components/network_provider/chain_identifier_validator.rs index c275e4e31bc..8eabe44edc7 100644 --- a/graph/src/components/network_provider/chain_identifier_validator.rs +++ b/graph/src/components/network_provider/chain_identifier_validator.rs @@ -35,14 +35,18 @@ pub enum ChainIdentifierValidationError { #[error("identifier not set for chain '{0}'")] IdentifierNotSet(ChainName), - #[error("net version mismatch on chain '{chain_name}'; expected '{store_net_version}', found '{chain_net_version}'")] + #[error( + "net version mismatch on chain '{chain_name}'; expected '{store_net_version}', found '{chain_net_version}'" + )] NetVersionMismatch { chain_name: ChainName, store_net_version: String, chain_net_version: String, }, - #[error("genesis block hash mismatch on chain '{chain_name}'; expected '{store_genesis_block_hash}', found '{chain_genesis_block_hash}'")] + #[error( + "genesis block hash mismatch on chain '{chain_name}'; expected '{store_genesis_block_hash}', found '{chain_genesis_block_hash}'" + )] GenesisBlockHashMismatch { chain_name: ChainName, store_genesis_block_hash: BlockHash, diff --git a/graph/src/components/network_provider/extended_blocks_check.rs b/graph/src/components/network_provider/extended_blocks_check.rs index f4d412795bc..a7ef879990d 100644 --- a/graph/src/components/network_provider/extended_blocks_check.rs +++ b/graph/src/components/network_provider/extended_blocks_check.rs @@ -2,9 +2,9 @@ use std::collections::HashSet; use std::time::Instant; use async_trait::async_trait; +use slog::Logger; use slog::error; use slog::warn; -use slog::Logger; use crate::components::network_provider::ChainName; use crate::components::network_provider::NetworkDetails; @@ -82,8 +82,8 @@ impl ProviderCheck for ExtendedBlocksCheck { mod tests { use std::sync::Mutex; - use anyhow::anyhow; use anyhow::Result; + use anyhow::anyhow; use super::*; use crate::blockchain::ChainIdentifier; @@ -102,11 +102,12 @@ mod tests { impl Drop for TestAdapter { fn drop(&mut self) { - assert!(self - .provides_extended_blocks_calls - .lock() - .unwrap() - .is_empty()); + assert!( + self.provides_extended_blocks_calls + .lock() + .unwrap() + .is_empty() + ); } } diff --git a/graph/src/components/network_provider/genesis_hash_check.rs b/graph/src/components/network_provider/genesis_hash_check.rs index b92d4602315..50b895913c6 100644 --- a/graph/src/components/network_provider/genesis_hash_check.rs +++ b/graph/src/components/network_provider/genesis_hash_check.rs @@ -2,11 +2,10 @@ use std::sync::Arc; use std::time::Instant; use async_trait::async_trait; +use slog::Logger; use slog::error; use slog::warn; -use slog::Logger; -use crate::components::network_provider::chain_id_validator; use crate::components::network_provider::ChainIdentifierValidationError; use crate::components::network_provider::ChainIdentifierValidator; use crate::components::network_provider::ChainName; @@ -14,6 +13,7 @@ use crate::components::network_provider::NetworkDetails; use crate::components::network_provider::ProviderCheck; use crate::components::network_provider::ProviderCheckStatus; use crate::components::network_provider::ProviderName; +use crate::components::network_provider::chain_id_validator; use crate::components::store::ChainIdStore; /// Requires providers to have the same network version and genesis hash as one @@ -155,8 +155,8 @@ mod tests { use std::sync::Arc; use std::sync::Mutex; - use anyhow::anyhow; use anyhow::Result; + use anyhow::anyhow; use super::*; use crate::blockchain::ChainIdentifier; diff --git a/graph/src/components/network_provider/mod.rs b/graph/src/components/network_provider/mod.rs index 3677ed6447f..e6b239360c5 100644 --- a/graph/src/components/network_provider/mod.rs +++ b/graph/src/components/network_provider/mod.rs @@ -5,9 +5,9 @@ mod network_details; mod provider_check; mod provider_manager; -pub use self::chain_identifier_validator::chain_id_validator; pub use self::chain_identifier_validator::ChainIdentifierValidationError; pub use self::chain_identifier_validator::ChainIdentifierValidator; +pub use self::chain_identifier_validator::chain_id_validator; pub use self::extended_blocks_check::ExtendedBlocksCheck; pub use self::genesis_hash_check::GenesisHashCheck; pub use self::network_details::NetworkDetails; diff --git a/graph/src/components/network_provider/provider_manager.rs b/graph/src/components/network_provider/provider_manager.rs index 3c1a6e3196a..c94f71563ec 100644 --- a/graph/src/components/network_provider/provider_manager.rs +++ b/graph/src/components/network_provider/provider_manager.rs @@ -5,9 +5,9 @@ use std::time::Duration; use derive_more::Debug; use itertools::Itertools; +use slog::Logger; use slog::info; use slog::warn; -use slog::Logger; use thiserror::Error; use tokio::sync::RwLock; diff --git a/graph/src/components/server/query.rs b/graph/src/components/server/query.rs index 4a9fe1557c2..d20a7dcb6c0 100644 --- a/graph/src/components/server/query.rs +++ b/graph/src/components/server/query.rs @@ -1,6 +1,6 @@ use http_body_util::Full; -use hyper::body::Bytes; use hyper::Response; +use hyper::body::Bytes; use crate::data::query::QueryError; use std::error::Error; diff --git a/graph/src/components/server/server.rs b/graph/src/components/server/server.rs index b746848c86b..e17e4d5897a 100644 --- a/graph/src/components/server/server.rs +++ b/graph/src/components/server/server.rs @@ -1,10 +1,10 @@ use std::future::Future; use std::net::SocketAddr; -use std::sync::atomic::AtomicBool; use std::sync::Arc; +use std::sync::atomic::AtomicBool; -use hyper::body::Incoming; use hyper::Request; +use hyper::body::Incoming; use tokio::net::TcpListener; use tokio::task::JoinHandle; diff --git a/graph/src/components/store/entity_cache.rs b/graph/src/components/store/entity_cache.rs index 4750779701c..afbc900ac0a 100644 --- a/graph/src/components/store/entity_cache.rs +++ b/graph/src/components/store/entity_cache.rs @@ -2,14 +2,14 @@ use anyhow::{anyhow, bail}; use std::borrow::Borrow; use std::collections::HashMap; use std::fmt::{self, Debug}; -use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::Arc; +use std::sync::atomic::{AtomicU32, Ordering}; use crate::cheap_clone::CheapClone; use crate::components::store::write::EntityModification; use crate::components::store::{self as s, Entity, EntityOperation}; use crate::data::store::{EntityValidationError, Id, IdType, IntoEntityIterator}; -use crate::prelude::{CacheWeight, StopwatchMetrics, ENV_VARS}; +use crate::prelude::{CacheWeight, ENV_VARS, StopwatchMetrics}; use crate::schema::{EntityKey, InputSchema}; use crate::util::intern::Error as InternError; use crate::util::lfu_cache::{EvictStats, LfuCache}; @@ -354,23 +354,23 @@ impl EntityCache { // - Check if there's an update for the same entity in handler_updates and apply it. // - Add the entity to entity_map. for (key, op) in self.updates.iter() { - if !entity_map.contains_key(key) { - if let Some(entity) = matches_query(op, &query, key)? { - if let Some(handler_op) = self.handler_updates.get(key).cloned() { - // If there's a corresponding update in handler_updates, apply it to the entity - // and insert the updated entity into entity_map - let mut entity = Some(entity); - entity = handler_op - .apply_to(&entity) - .map_err(|e| key.unknown_attribute(e))?; - - if let Some(updated_entity) = entity { - entity_map.insert(key.clone(), updated_entity); - } - } else { - // If there isn't a corresponding update in handler_updates or the update doesn't match the query, just insert the entity from self.updates - entity_map.insert(key.clone(), entity); + if !entity_map.contains_key(key) + && let Some(entity) = matches_query(op, &query, key)? + { + if let Some(handler_op) = self.handler_updates.get(key).cloned() { + // If there's a corresponding update in handler_updates, apply it to the entity + // and insert the updated entity into entity_map + let mut entity = Some(entity); + entity = handler_op + .apply_to(&entity) + .map_err(|e| key.unknown_attribute(e))?; + + if let Some(updated_entity) = entity { + entity_map.insert(key.clone(), updated_entity); } + } else { + // If there isn't a corresponding update in handler_updates or the update doesn't match the query, just insert the entity from self.updates + entity_map.insert(key.clone(), entity); } } } @@ -381,10 +381,11 @@ impl EntityCache { // - Match the query. // If these conditions are met, add the entity to entity_map. for (key, handler_op) in self.handler_updates.iter() { - if !entity_map.contains_key(key) && !self.updates.contains_key(key) { - if let Some(entity) = matches_query(handler_op, &query, key)? { - entity_map.insert(key.clone(), entity); - } + if !entity_map.contains_key(key) + && !self.updates.contains_key(key) + && let Some(entity) = matches_query(handler_op, &query, key)? + { + entity_map.insert(key.clone(), entity); } } diff --git a/graph/src/components/store/err.rs b/graph/src/components/store/err.rs index 995f0c67648..9e94342cb34 100644 --- a/graph/src/components/store/err.rs +++ b/graph/src/components/store/err.rs @@ -2,7 +2,7 @@ use super::{BlockNumber, DeploymentSchemaVersion}; use crate::prelude::DeploymentHash; use crate::prelude::QueryExecutionError; -use anyhow::{anyhow, Error}; +use anyhow::{Error, anyhow}; use diesel::result::Error as DieselError; use thiserror::Error; use tokio::task::JoinError; diff --git a/graph/src/components/store/mod.rs b/graph/src/components/store/mod.rs index 4c5b96c589d..d9a4e120dff 100644 --- a/graph/src/components/store/mod.rs +++ b/graph/src/components/store/mod.rs @@ -27,8 +27,8 @@ use std::collections::btree_map::Entry; use std::collections::{BTreeMap, BTreeSet, HashSet}; use std::fmt; use std::fmt::Display; -use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; +use std::sync::atomic::{AtomicUsize, Ordering}; use std::time::Duration; use async_trait::async_trait; @@ -43,8 +43,8 @@ use crate::data_source::CausalityRegion; use crate::derive::CheapClone; use crate::env::ENV_VARS; use crate::internal_error; -use crate::prelude::{s, Attribute, DeploymentHash, ValueType}; -use crate::schema::{ast as sast, EntityKey, EntityType, InputSchema}; +use crate::prelude::{Attribute, DeploymentHash, ValueType, s}; +use crate::schema::{EntityKey, EntityType, InputSchema, ast as sast}; use crate::util::stats::AtomicMovingStats; #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -521,26 +521,26 @@ impl EntityQuery { // If there is one window, with one id, in a direct relation to the // entities, we can simplify the query by changing the filter and // getting rid of the window - if let EntityCollection::Window(windows) = &self.collection { - if windows.len() == 1 { - let window = windows.first().expect("we just checked"); - if window.ids.len() == 1 { - let id = window.ids.first().expect("we just checked").to_value(); - if let EntityLink::Direct(attribute, _) = &window.link { - let filter = match attribute { - WindowAttribute::Scalar(name) => { - EntityFilter::Equal(name.clone(), id.into()) - } - WindowAttribute::List(name) => { - EntityFilter::Contains(name.clone(), Value::from(vec![id])) - } - }; - self.filter = Some(filter.and_maybe(self.filter)); - self.collection = EntityCollection::All(vec![( - window.child_type.clone(), - window.column_names.clone(), - )]); - } + if let EntityCollection::Window(windows) = &self.collection + && windows.len() == 1 + { + let window = windows.first().expect("we just checked"); + if window.ids.len() == 1 { + let id = window.ids.first().expect("we just checked").to_value(); + if let EntityLink::Direct(attribute, _) = &window.link { + let filter = match attribute { + WindowAttribute::Scalar(name) => { + EntityFilter::Equal(name.clone(), id.into()) + } + WindowAttribute::List(name) => { + EntityFilter::Contains(name.clone(), Value::from(vec![id])) + } + }; + self.filter = Some(filter.and_maybe(self.filter)); + self.collection = EntityCollection::All(vec![( + window.child_type.clone(), + window.column_names.clone(), + )]); } } } diff --git a/graph/src/components/store/traits.rs b/graph/src/components/store/traits.rs index bb4397432ff..cc5aa9cc433 100644 --- a/graph/src/components/store/traits.rs +++ b/graph/src/components/store/traits.rs @@ -17,11 +17,11 @@ use crate::components::versions::ApiVersion; use crate::data::query::Trace; use crate::data::store::ethereum::call; use crate::data::store::{QueryObject, SqlQueryObject}; -use crate::data::subgraph::{status, DeploymentFeatures}; +use crate::data::subgraph::{DeploymentFeatures, status}; use crate::data::{query::QueryTarget, subgraph::schema::*}; use crate::prelude::{ - alloy::primitives::{Address, B256}, DeploymentState, NodeId, QueryExecutionError, SubgraphName, + alloy::primitives::{Address, B256}, }; use crate::schema::{ApiSchema, InputSchema}; @@ -142,7 +142,7 @@ pub trait SubgraphStore: Send + Sync + 'static { /// Returns assignments that are not paused async fn active_assignments(&self, node: &NodeId) - -> Result, StoreError>; + -> Result, StoreError>; /// Return `true` if a subgraph `name` exists, regardless of whether the /// subgraph has any deployments attached to it @@ -582,7 +582,7 @@ pub trait ChainStore: ChainHeadStore { /// column. More efficient than `blocks` when only the parent pointer is /// needed. async fn block_parent_ptr(self: Arc, hash: &BlockHash) - -> Result, Error>; + -> Result, Error>; /// Returns the blocks present in the store for the given block numbers. async fn block_ptrs_by_numbers( @@ -740,7 +740,7 @@ pub trait QueryStore: Send + Sync { async fn block_ptr(&self) -> Result, StoreError>; async fn block_number(&self, block_hash: &BlockHash) - -> Result, StoreError>; + -> Result, StoreError>; async fn block_numbers( &self, diff --git a/graph/src/components/store/write.rs b/graph/src/components/store/write.rs index 0f8ba70251e..1a29714e51e 100644 --- a/graph/src/components/store/write.rs +++ b/graph/src/components/store/write.rs @@ -7,7 +7,7 @@ use std::{ use slog::Logger; use crate::{ - blockchain::{block_stream::FirehoseCursor, BlockPtr, BlockTime}, + blockchain::{BlockPtr, BlockTime, block_stream::FirehoseCursor}, cheap_clone::CheapClone, components::subgraph::Entity, data::{store::Id, subgraph::schema::SubgraphError}, @@ -202,7 +202,7 @@ impl EntityModification { "can not clamp block range for removal of {:?} to {}", self, block - )) + )); } } Ok(()) @@ -415,16 +415,16 @@ impl RowGroup { pub fn last_op(&self, key: &EntityKey, at: BlockNumber) -> Option> { // If we have `key` in `last_mod`, use that and return the // corresponding op. If not, fall through to a more expensive search - if let Some(&idx) = self.last_mod.get(&key.entity_id) { - if let Some(op) = self.rows.get(idx).and_then(|emod| { + if let Some(&idx) = self.last_mod.get(&key.entity_id) + && let Some(op) = self.rows.get(idx).and_then(|emod| { if emod.block() <= at { Some(emod.as_entity_op(at)) } else { None } - }) { - return Some(op); - } + }) + { + return Some(op); } // We are looking for the change at a block `at` that is before the // change we remember in `last_mod`, and therefore have to scan @@ -491,9 +491,12 @@ impl RowGroup { if self.entity_type.skip_duplicates() { return Ok(()); } - return Err(StoreError::Input( - format!("entity {} is immutable; inserting it at block {} is not possible as it was already inserted at block {}", - row.key(), row.block(), prev.block()))); + return Err(StoreError::Input(format!( + "entity {} is immutable; inserting it at block {} is not possible as it was already inserted at block {}", + row.key(), + row.block(), + prev.block() + ))); } _ => { /* nothing to check */ } } @@ -548,7 +551,7 @@ impl RowGroup { "impossible combination of entity operations: {:?} and then {:?}", prev_row, row - )) + )); } (Remove { .. }, Remove { .. }) => { // Ignore the new row, since prev_row is already a @@ -835,7 +838,11 @@ impl Batch { fn append_inner(&mut self, mut batch: Batch) -> Result<(), StoreError> { if batch.block_ptr.number <= self.block_ptr.number { - return Err(internal_error!("Batches must go forward. Can't append a batch with block pointer {} to one with block pointer {}", batch.block_ptr, self.block_ptr)); + return Err(internal_error!( + "Batches must go forward. Can't append a batch with block pointer {} to one with block pointer {}", + batch.block_ptr, + self.block_ptr + )); } self.block_ptr = batch.block_ptr; @@ -1048,7 +1055,7 @@ mod test { use crate::{ components::store::{ - write::EntityModification, write::EntityOp, BlockNumber, EntityType, StoreError, + BlockNumber, EntityType, StoreError, write::EntityModification, write::EntityOp, }, data::{store::Id, value::Word}, entity, diff --git a/graph/src/components/subgraph/proof_of_indexing/event.rs b/graph/src/components/subgraph/proof_of_indexing/event.rs index 4fc2e90c171..227a7a6c561 100644 --- a/graph/src/components/subgraph/proof_of_indexing/event.rs +++ b/graph/src/components/subgraph/proof_of_indexing/event.rs @@ -60,8 +60,8 @@ pub enum ProofOfIndexingEvent<'a> { impl stable_hash_legacy::StableHash for ProofOfIndexingEvent<'_> { fn stable_hash(&self, mut sequence_number: H::Seq, state: &mut H) { - use stable_hash_legacy::prelude::*; use ProofOfIndexingEvent::*; + use stable_hash_legacy::prelude::*; let str: &'static str = self.into(); str.stable_hash(sequence_number.next_child(), state); diff --git a/graph/src/components/subgraph/proof_of_indexing/mod.rs b/graph/src/components/subgraph/proof_of_indexing/mod.rs index 78bbaf6255f..dea6ffa6279 100644 --- a/graph/src/components/subgraph/proof_of_indexing/mod.rs +++ b/graph/src/components/subgraph/proof_of_indexing/mod.rs @@ -81,7 +81,7 @@ impl SharedProofOfIndexing { #[cfg(test)] mod tests { use super::*; - use crate::util::stable_hash_glue::{impl_stable_hash, AsBytes}; + use crate::util::stable_hash_glue::{AsBytes, impl_stable_hash}; use crate::{ data::store::Id, prelude::{BlockPtr, DeploymentHash, Value}, @@ -91,7 +91,7 @@ mod tests { use maplit::hashmap; use online::ProofOfIndexingFinisher; use reference::*; - use slog::{o, Discard, Logger}; + use slog::{Discard, Logger, o}; use stable_hash::{fast_stable_hash, utils::check_for_child_errors}; use stable_hash_legacy::crypto::SetHasher; use stable_hash_legacy::utils::stable_hash as stable_hash_legacy; diff --git a/graph/src/components/subgraph/proof_of_indexing/online.rs b/graph/src/components/subgraph/proof_of_indexing/online.rs index f9bd8b5f18d..00b8aa56080 100644 --- a/graph/src/components/subgraph/proof_of_indexing/online.rs +++ b/graph/src/components/subgraph/proof_of_indexing/online.rs @@ -6,12 +6,12 @@ use super::{ProofOfIndexingEvent, ProofOfIndexingVersion}; use crate::{ blockchain::BlockPtr, data::store::Id, - prelude::{debug, BlockNumber, DeploymentHash, Logger, ENV_VARS}, + prelude::{BlockNumber, DeploymentHash, ENV_VARS, Logger, debug}, util::stable_hash_glue::AsBytes, }; use alloy::primitives::Address; use sha2::{Digest, Sha256}; -use stable_hash::{fast::FastStableHasher, FieldAddress, StableHash, StableHasher}; +use stable_hash::{FieldAddress, StableHash, StableHasher, fast::FastStableHasher}; use stable_hash_legacy::crypto::{Blake3SeqNo, SetHasher}; use stable_hash_legacy::prelude::{ StableHash as StableHashLegacy, StableHasher as StableHasherLegacy, *, diff --git a/graph/src/components/subgraph/settings.rs b/graph/src/components/subgraph/settings.rs index f1ad9459b37..3e4db56c9ed 100644 --- a/graph/src/components/subgraph/settings.rs +++ b/graph/src/components/subgraph/settings.rs @@ -3,7 +3,7 @@ use std::fs::read_to_string; use crate::{ anyhow, - prelude::{regex::Regex, SubgraphName}, + prelude::{SubgraphName, regex::Regex}, }; use serde::{Deserialize, Serialize}; diff --git a/graph/src/data/graphql/ext.rs b/graph/src/data/graphql/ext.rs index e9f3828e169..4177da59eae 100644 --- a/graph/src/data/graphql/ext.rs +++ b/graph/src/data/graphql/ext.rs @@ -6,7 +6,7 @@ use crate::prelude::s::{ self, Definition, Directive, Document, EnumType, Field, InterfaceType, ObjectType, Type, TypeDefinition, Value, }; -use crate::prelude::{ValueType, ENV_VARS}; +use crate::prelude::{ENV_VARS, ValueType}; use crate::schema::{META_FIELD_TYPE, SCHEMA_TYPE_NAME}; use std::collections::{BTreeMap, HashMap}; diff --git a/graph/src/data/graphql/load_manager.rs b/graph/src/data/graphql/load_manager.rs index e1053360e18..79655e25629 100644 --- a/graph/src/data/graphql/load_manager.rs +++ b/graph/src/data/graphql/load_manager.rs @@ -14,7 +14,7 @@ use crate::components::store::{DeploymentId, PoolWaitStats}; use crate::data::graphql::shape_hash::shape_hash; use crate::data::query::{CacheStatus, QueryExecutionError}; use crate::prelude::q; -use crate::prelude::{debug, info, o, warn, Logger, ENV_VARS}; +use crate::prelude::{ENV_VARS, Logger, debug, info, o, warn}; use crate::util::stats::MovingStats; const SHARD_LABEL: [&str; 1] = ["shard"]; @@ -417,24 +417,25 @@ impl LoadManager { let total_effort = total_effort.as_millis() as f64; // When this variable is not set, we never jail any queries. - if let Some(jail_threshold) = ENV_VARS.load_jail_threshold { - if known_query && query_effort / total_effort > jail_threshold { - // Any single query that causes at least JAIL_THRESHOLD of the - // effort in an overload situation gets killed - warn!(self.logger, "Jailing query"; + if let Some(jail_threshold) = ENV_VARS.load_jail_threshold + && known_query + && query_effort / total_effort > jail_threshold + { + // Any single query that causes at least JAIL_THRESHOLD of the + // effort in an overload situation gets killed + warn!(self.logger, "Jailing query"; "query" => query, "sgd" => format!("sgd{}", qref.id), "wait_ms" => wait_ms.as_millis(), "query_effort_ms" => query_effort, "total_effort_ms" => total_effort, "ratio" => format!("{:.4}", query_effort/total_effort)); - self.jailed_queries.write().insert(qref); - return if ENV_VARS.load_simulate { - Proceed - } else { - TooExpensive - }; - } + self.jailed_queries.write().insert(qref); + return if ENV_VARS.load_simulate { + Proceed + } else { + TooExpensive + }; } // Kill random queries in case we have no queries, or not enough queries diff --git a/graph/src/data/graphql/mod.rs b/graph/src/data/graphql/mod.rs index 1bb2c691411..fe6b6d8707d 100644 --- a/graph/src/data/graphql/mod.rs +++ b/graph/src/data/graphql/mod.rs @@ -30,4 +30,4 @@ pub use object_or_interface::ObjectOrInterface; pub mod object_macro; pub use crate::object; -pub use object_macro::{object_value, IntoValue}; +pub use object_macro::{IntoValue, object_value}; diff --git a/graph/src/data/graphql/values.rs b/graph/src/data/graphql/values.rs index b4923d6ce26..6e493675e48 100644 --- a/graph/src/data/graphql/values.rs +++ b/graph/src/data/graphql/values.rs @@ -1,12 +1,12 @@ use alloy::primitives::Address; -use anyhow::{anyhow, Error}; +use anyhow::{Error, anyhow}; use std::collections::HashMap; use std::convert::TryFrom; use std::str::FromStr; use crate::blockchain::BlockHash; use crate::data::value::Object; -use crate::prelude::{r, BigInt}; +use crate::prelude::{BigInt, r}; pub trait TryFromValue: Sized { fn try_from_value(value: &r::Value) -> Result; diff --git a/graph/src/data/query/error.rs b/graph/src/data/query/error.rs index ac01da52df7..aa6f84b2591 100644 --- a/graph/src/data/query/error.rs +++ b/graph/src/data/query/error.rs @@ -191,7 +191,11 @@ impl fmt::Display for QueryExecutionError { write!(f, "Failed to get entities from store: {}", e) } OrderByNotSupportedError(entity, field) => { - write!(f, "Ordering by `{}` is not supported for type `{}`", field, entity) + write!( + f, + "Ordering by `{}` is not supported for type `{}`", + field, entity + ) } OrderByNotSupportedForType(field_type) => { write!(f, "Ordering by `{}` fields is not supported", field_type) @@ -200,7 +204,11 @@ impl fmt::Display for QueryExecutionError { write!(f, "Filter not supported by value `{}`: `{}`", value, filter) } ChildFilterNestingNotSupportedError(value, filter) => { - write!(f, "Child filter nesting not supported by value `{}`: `{}`", value, filter) + write!( + f, + "Child filter nesting not supported by value `{}`: `{}`", + value, filter + ) } UnknownField(_, t, s) => { write!(f, "Type `{}` has no field `{}`", t, s) @@ -210,12 +218,20 @@ impl fmt::Display for QueryExecutionError { write!(f, "Failed to get subgraph ID from type: `{}`", s) } RangeArgumentsError(arg, max, actual) => { - write!(f, "The `{}` argument must be between 0 and {}, but is {}", arg, max, actual) + write!( + f, + "The `{}` argument must be between 0 and {}, but is {}", + arg, max, actual + ) } InvalidFilterError => write!(f, "Filter must by an object"), InvalidOrFilterStructure(fields, example) => { - write!(f, "Cannot mix column filters with 'or' operator at the same level. Found column filter(s) {} alongside 'or' operator.\n\n{}", - fields.join(", "), example) + write!( + f, + "Cannot mix column filters with 'or' operator at the same level. Found column filter(s) {} alongside 'or' operator.\n\n{}", + fields.join(", "), + example + ) } EntityFieldError(e, a) => { write!(f, "Entity `{}` has no attribute `{}`", e, a) @@ -234,7 +250,11 @@ impl fmt::Display for QueryExecutionError { write!(f, "Failed to decode `{}` value: `{}`", t, e) } AttributeTypeError(value, ty) => { - write!(f, "Query contains value with invalid type `{}`: `{}`", ty, value) + write!( + f, + "Query contains value with invalid type `{}`: `{}`", + ty, value + ) } EntityParseError(s) => { write!(f, "Broken entity found in store: {}", s) @@ -247,38 +267,78 @@ impl fmt::Display for QueryExecutionError { write!(f, "Selection set for type `{}` is empty", entity_type) } AmbiguousDerivedFromResult(_, field, target_type, target_field) => { - write!(f, "Ambiguous result for derived field `{}`: \ + write!( + f, + "Ambiguous result for derived field `{}`: \ Multiple `{}` entities refer back via `{}`", - field, target_type, target_field) + field, target_type, target_field + ) } Unimplemented(feature) => { write!(f, "Feature `{}` is not yet implemented", feature) } EnumCoercionError(_, field, value, enum_type, values) => { - write!(f, "Failed to coerce value `{}` of field `{}` to enum type `{}`. Possible values are: {}", value, field, enum_type, values.join(", ")) + write!( + f, + "Failed to coerce value `{}` of field `{}` to enum type `{}`. Possible values are: {}", + value, + field, + enum_type, + values.join(", ") + ) } ScalarCoercionError(_, field, value, scalar_type) => { - write!(f, "Failed to coerce value `{}` of field `{}` to scalar type `{}`", value, field, scalar_type) + write!( + f, + "Failed to coerce value `{}` of field `{}` to scalar type `{}`", + value, field, scalar_type + ) } TooComplex(complexity, max_complexity) => { - write!(f, "query potentially returns `{}` entities or more and thereby exceeds \ + write!( + f, + "query potentially returns `{}` entities or more and thereby exceeds \ the limit of `{}` entities. Possible solutions are reducing the depth \ of the query, querying fewer relationships or using `first` to \ - return smaller collections", complexity, max_complexity) + return smaller collections", + complexity, max_complexity + ) } - TooDeep(max_depth) => write!(f, "query has a depth that exceeds the limit of `{}`", max_depth), - CyclicalFragment(name) =>write!(f, "query has fragment cycle including `{}`", name), + TooDeep(max_depth) => write!( + f, + "query has a depth that exceeds the limit of `{}`", + max_depth + ), + CyclicalFragment(name) => write!(f, "query has fragment cycle including `{}`", name), UndefinedFragment(frag_name) => write!(f, "fragment `{}` is not defined", frag_name), Panic(msg) => write!(f, "panic processing query: {}", msg), - FulltextQueryRequiresFilter => write!(f, "fulltext search queries can only use EntityFilter::Equal"), - FulltextQueryInvalidSyntax(msg) => write!(f, "Invalid fulltext search query syntax. Error: {}. Hint: Search terms with spaces need to be enclosed in single quotes", msg), + FulltextQueryRequiresFilter => write!( + f, + "fulltext search queries can only use EntityFilter::Equal" + ), + FulltextQueryInvalidSyntax(msg) => write!( + f, + "Invalid fulltext search query syntax. Error: {}. Hint: Search terms with spaces need to be enclosed in single quotes", + msg + ), TooExpensive => write!(f, "query is too expensive"), - Throttled => write!(f, "service is overloaded and can not run the query right now. Please try again in a few minutes"), + Throttled => write!( + f, + "service is overloaded and can not run the query right now. Please try again in a few minutes" + ), DeploymentReverted => write!(f, "the chain was reorganized while executing the query"), - SubgraphManifestResolveError(e) => write!(f, "failed to resolve subgraph manifest: {}", e), + SubgraphManifestResolveError(e) => { + write!(f, "failed to resolve subgraph manifest: {}", e) + } InvalidSubgraphManifest => write!(f, "invalid subgraph manifest file"), - ResultTooBig(actual, limit) => write!(f, "the result size of {} is larger than the allowed limit of {}", actual, limit), - DeploymentNotFound(id_or_name) => write!(f, "deployment `{}` does not exist", id_or_name), + ResultTooBig(actual, limit) => write!( + f, + "the result size of {} is larger than the allowed limit of {}", + actual, limit + ), + DeploymentNotFound(id_or_name) => { + write!(f, "deployment `{}` does not exist", id_or_name) + } IdMissing => write!(f, "entity is missing an `id` attribute"), IdNotString => write!(f, "entity `id` attribute is not a string"), InternalError(msg) => write!(f, "internal error: {}", msg), diff --git a/graph/src/data/query/query.rs b/graph/src/data/query/query.rs index cb35f6ccca0..ab069852374 100644 --- a/graph/src/data/query/query.rs +++ b/graph/src/data/query/query.rs @@ -8,7 +8,7 @@ use std::sync::Arc; use crate::{ data::graphql::shape_hash::shape_hash, - prelude::{q, r, ApiVersion, DeploymentHash, SubgraphName, ENV_VARS}, + prelude::{ApiVersion, DeploymentHash, ENV_VARS, SubgraphName, q, r}, }; fn deserialize_number<'de, D>(deserializer: D) -> Result diff --git a/graph/src/data/query/result.rs b/graph/src/data/query/result.rs index 787c1b2524c..5694bf3fcd9 100644 --- a/graph/src/data/query/result.rs +++ b/graph/src/data/query/result.rs @@ -4,15 +4,15 @@ use crate::cheap_clone::CheapClone; use crate::components::server::query::ServerResponse; use crate::data::value::Object; use crate::derive::CacheWeight; -use crate::prelude::{r, BlockHash, BlockNumber, CacheWeight, DeploymentHash}; +use crate::prelude::{BlockHash, BlockNumber, CacheWeight, DeploymentHash, r}; use http_body_util::Full; +use hyper::Response; use hyper::header::{ ACCESS_CONTROL_ALLOW_HEADERS, ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_ALLOW_ORIGIN, CONTENT_TYPE, }; -use hyper::Response; -use serde::ser::*; use serde::Serialize; +use serde::ser::*; use std::convert::TryFrom; use std::sync::Arc; use std::time::Instant; diff --git a/graph/src/data/query/trace.rs b/graph/src/data/query/trace.rs index c6682274100..369c36a5435 100644 --- a/graph/src/data/query/trace.rs +++ b/graph/src/data/query/trace.rs @@ -1,11 +1,11 @@ use std::{sync::Arc, time::Duration}; -use serde::{ser::SerializeMap, Serialize}; +use serde::{Serialize, ser::SerializeMap}; use crate::{ components::store::{BlockNumber, QueryPermit}, derive::CacheWeight, - prelude::{lazy_static, CheapClone}, + prelude::{CheapClone, lazy_static}, }; use super::{CacheStatus, QueryExecutionError}; diff --git a/graph/src/data/store/ethereum.rs b/graph/src/data/store/ethereum.rs index 469b4b14551..29f4544c71c 100644 --- a/graph/src/data/store/ethereum.rs +++ b/graph/src/data/store/ethereum.rs @@ -1,7 +1,7 @@ use super::scalar; use crate::derive::CheapClone; use crate::prelude::*; -use alloy::primitives::{aliases::B2048, Address, Bytes, B256, B64, U64}; +use alloy::primitives::{Address, B64, B256, Bytes, U64, aliases::B2048}; impl From
for Value { fn from(address: Address) -> Value { diff --git a/graph/src/data/store/id.rs b/graph/src/data/store/id.rs index 222a11fefdf..8391da53b76 100644 --- a/graph/src/data/store/id.rs +++ b/graph/src/data/store/id.rs @@ -1,11 +1,11 @@ //! Types and helpers to deal with entity IDs which support a subset of the //! types that more general values support -use anyhow::{anyhow, Context, Error}; +use anyhow::{Context, Error, anyhow}; use diesel::{ + QueryResult, pg::Pg, query_builder::AstPass, sql_types::{BigInt, Binary, Text}, - QueryResult, }; use stable_hash::{StableHash, StableHasher}; use std::convert::TryFrom; @@ -27,7 +27,7 @@ use crate::{ runtime::gas::{Gas, GasSizeOf}, }; -use super::{scalar, Value, ValueType, ID}; +use super::{ID, Value, ValueType, scalar}; /// The types that can be used for the `id` of an entity #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] diff --git a/graph/src/data/store/mod.rs b/graph/src/data/store/mod.rs index 589f894bf96..006f44d65ae 100644 --- a/graph/src/data/store/mod.rs +++ b/graph/src/data/store/mod.rs @@ -1,11 +1,11 @@ use crate::{ derive::CacheWeight, - prelude::{lazy_static, q, r, s, CacheWeight, QueryExecutionError}, + prelude::{CacheWeight, QueryExecutionError, lazy_static, q, r, s}, runtime::gas::{Gas, GasSizeOf}, - schema::{input::VID_FIELD, EntityKey}, + schema::{EntityKey, input::VID_FIELD}, util::intern::{self, AtomPool, Error as InternError, NullValue, Object}, }; -use anyhow::{anyhow, Error}; +use anyhow::{Error, anyhow}; use itertools::Itertools; use serde::de; use serde::{Deserialize, Serialize}; @@ -228,8 +228,8 @@ impl stable_hash_legacy::StableHash for Value { mut sequence_number: H::Seq, state: &mut H, ) { - use stable_hash_legacy::prelude::*; use Value::*; + use stable_hash_legacy::prelude::*; // This is the default, so write nothing. if self == &Null { @@ -525,10 +525,10 @@ impl fmt::Display for Value { Value::BigDecimal(d) => d.to_string(), Value::Bool(b) => b.to_string(), Value::Null => "null".to_string(), - Value::List(ref values) => + Value::List(values) => format!("[{}]", values.iter().map(ToString::to_string).join(", ")), - Value::Bytes(ref bytes) => bytes.to_string(), - Value::BigInt(ref number) => number.to_string(), + Value::Bytes(bytes) => bytes.to_string(), + Value::BigInt(number) => number.to_string(), } ) } @@ -833,7 +833,9 @@ pub enum EntityValidationErrorInner { #[error("Entity {entity}[{id}]: unknown entity type `{entity}`")] UnknownEntityType { entity: String, id: String }, - #[error("Entity {entity}[{entity_id}]: field `{field}` is of type {expected_type}, but the value `{value}` contains a {actual_type} at index {index}")] + #[error( + "Entity {entity}[{entity_id}]: field `{field}` is of type {expected_type}, but the value `{value}` contains a {actual_type} at index {index}" + )] MismatchedElementTypeInList { entity: String, entity_id: String, @@ -844,7 +846,9 @@ pub enum EntityValidationErrorInner { index: usize, }, - #[error("Entity {entity}[{entity_id}]: the value `{value}` for field `{field}` must have type {expected_type} but has type {actual_type}")] + #[error( + "Entity {entity}[{entity_id}]: the value `{value}` for field `{field}` must have type {expected_type} but has type {actual_type}" + )] InvalidFieldType { entity: String, entity_id: String, @@ -968,7 +972,7 @@ impl Entity { pub fn sorted_ref(&self) -> Vec<(&str, &Value)> { let mut v: Vec<_> = self.0.iter().filter(|(k, _)| !k.eq(&VID_FIELD)).collect(); - v.sort_by(|(k1, _), (k2, _)| k1.cmp(k2)); + v.sort_by_key(|(k1, _)| *k1); v } @@ -1208,7 +1212,9 @@ fn value_bytes() { assert_eq!( from_query, Value::Bytes(scalar::Bytes::from( - &[143, 73, 76, 102, 175, 193, 211, 248, 172, 27, 69, 223, 33, 240, 42, 70][..] + &[ + 143, 73, 76, 102, 175, 193, 211, 248, 172, 27, 69, 223, 33, 240, 42, 70 + ][..] )) ); assert_eq!(r::Value::from(from_query), graphql_value); diff --git a/graph/src/data/store/scalar/bigdecimal.rs b/graph/src/data/store/scalar/bigdecimal.rs index baba57a2d4e..3d038682471 100644 --- a/graph/src/data/store/scalar/bigdecimal.rs +++ b/graph/src/data/store/scalar/bigdecimal.rs @@ -304,7 +304,7 @@ mod pg { ref digits, } => (Sign::Minus, weight, scale, digits), PgNumeric::NaN => { - return Err(Box::from("NaN is not (yet) supported in BigDecimal")) + return Err(Box::from("NaN is not (yet) supported in BigDecimal")); } }; @@ -604,8 +604,8 @@ mod pg { #[cfg(test)] mod test { use super::{ - super::test::{crypto_stable_hash, same_stable_hash}, super::Bytes, + super::test::{crypto_stable_hash, same_stable_hash}, BigDecimal, BigInt, OldBigDecimal, }; use std::str::FromStr; diff --git a/graph/src/data/store/scalar/bigint.rs b/graph/src/data/store/scalar/bigint.rs index 0b6ae34e025..3b31a3a623d 100644 --- a/graph/src/data/store/scalar/bigint.rs +++ b/graph/src/data/store/scalar/bigint.rs @@ -1,11 +1,11 @@ use anyhow::bail; use num_bigint; use serde::{self, Deserialize, Serialize}; -use stable_hash::utils::AsInt; use stable_hash::StableHash; +use stable_hash::utils::AsInt; use thiserror::Error; -use crate::prelude::alloy::primitives::{U128, U256, U64}; +use crate::prelude::alloy::primitives::{U64, U128, U256}; use std::convert::{TryFrom, TryInto}; use std::fmt; use std::ops::{Add, BitAnd, BitOr, Div, Mul, Rem, Shl, Shr, Sub}; diff --git a/graph/src/data/store/scalar/bytes.rs b/graph/src/data/store/scalar/bytes.rs index 0df3aa3bdae..62a50d3cb49 100644 --- a/graph/src/data/store/scalar/bytes.rs +++ b/graph/src/data/store/scalar/bytes.rs @@ -11,7 +11,7 @@ use std::str::FromStr; use crate::blockchain::BlockHash; use crate::derive::CacheWeight; -use crate::util::stable_hash_glue::{impl_stable_hash, AsBytes}; +use crate::util::stable_hash_glue::{AsBytes, impl_stable_hash}; /// A byte array that's serialized as a hex string prefixed by `0x`. #[derive(Clone, CacheWeight, PartialEq, Eq, PartialOrd, Ord)] diff --git a/graph/src/data/store/sql.rs b/graph/src/data/store/sql.rs index aa78e01a182..7124927ee74 100644 --- a/graph/src/data/store/sql.rs +++ b/graph/src/data/store/sql.rs @@ -5,7 +5,7 @@ use diesel::sql_types::{Binary, Bool, Int8, Integer, Text, Timestamptz}; use std::str::FromStr; -use super::{scalar, Value}; +use super::{Value, scalar}; impl ToSql for Value { fn to_sql(&self, out: &mut Output) -> serialize::Result { diff --git a/graph/src/data/subgraph/api_version.rs b/graph/src/data/subgraph/api_version.rs index eb7eb461f33..6cdc7a6bcc5 100644 --- a/graph/src/data/subgraph/api_version.rs +++ b/graph/src/data/subgraph/api_version.rs @@ -92,8 +92,8 @@ impl UnifiedMappingApiVersion { pub(super) fn try_from_versions( versions: impl Iterator, ) -> Result { - use super::manifest_validation::validate_api_versions; use super::SubgraphManifestValidationError; + use super::manifest_validation::validate_api_versions; let versions_vec: Vec = versions.collect(); diff --git a/graph/src/data/subgraph/mod.rs b/graph/src/data/subgraph/mod.rs index 46154155319..5717f7ad273 100644 --- a/graph/src/data/subgraph/mod.rs +++ b/graph/src/data/subgraph/mod.rs @@ -15,7 +15,7 @@ pub mod status; pub use features::{SubgraphFeature, SubgraphFeatureValidationError}; use crate::{cheap_clone::CheapClone, components::store::BLOCK_NUMBER_MAX, object}; -use anyhow::{anyhow, Context, Error}; +use anyhow::{Context, Error, anyhow}; use futures03::future::try_join_all; use itertools::Itertools; use semver::Version; @@ -46,16 +46,16 @@ use crate::{ subgraph::features::validate_subgraph_features, }, data_source::{ - offchain::OFFCHAIN_KINDS, DataSource, DataSourceTemplate, UnresolvedDataSource, - UnresolvedDataSourceTemplate, + DataSource, DataSourceTemplate, UnresolvedDataSource, UnresolvedDataSourceTemplate, + offchain::OFFCHAIN_KINDS, }, derive::CacheWeight, ensure, - prelude::{r, Value, ENV_VARS}, + prelude::{ENV_VARS, Value, r}, schema::{InputSchema, SchemaValidationError}, }; -use crate::prelude::{impl_slog_value, BlockNumber, Deserialize, Serialize}; +use crate::prelude::{BlockNumber, Deserialize, Serialize, impl_slog_value}; use std::fmt; use std::ops::Deref; @@ -580,10 +580,15 @@ impl Graft { // The graft point must be at least `reorg_threshold` blocks // behind the subgraph head so that a reorg can not affect the // data that we copy for grafting - (Some(ptr), true) if self.block + ENV_VARS.reorg_threshold() > ptr.number => Err(GraftBaseInvalid(format!( - "failed to graft onto `{}` at block {} since it's only at block {} which is within the reorg threshold of {} blocks", - self.base, self.block, ptr.number, ENV_VARS.reorg_threshold() - ))), + (Some(ptr), true) if self.block + ENV_VARS.reorg_threshold() > ptr.number => { + Err(GraftBaseInvalid(format!( + "failed to graft onto `{}` at block {} since it's only at block {} which is within the reorg threshold of {} blocks", + self.base, + self.block, + ptr.number, + ENV_VARS.reorg_threshold() + ))) + } // If the base deployment is failed *and* the `graft.block` is not // less than the `base.block`, the graft shouldn't be permitted. // @@ -591,7 +596,9 @@ impl Graft { // to `base.block - 1` or less. (Some(ptr), false) if self.block >= ptr.number => Err(GraftBaseInvalid(format!( "failed to graft onto `{}` at block {} since it's not healthy. You can graft it starting at block {} backwards", - self.base, self.block, ptr.number - 1 + self.base, + self.block, + ptr.number - 1 ))), (Some(_), _) => Ok(()), } @@ -872,19 +879,18 @@ impl UnvalidatedSubgraphManifest { errors.push(e); } - if let Some(graft) = &self.0.graft { - if validate_graft_base { - if let Err(graft_err) = graft.validate(store).await { - errors.push(graft_err); - } - } + if let Some(graft) = &self.0.graft + && validate_graft_base + && let Err(graft_err) = graft.validate(store).await + { + errors.push(graft_err); } // Validate subgraph feature usage and declaration. - if self.0.spec_version >= SPEC_VERSION_0_0_4 { - if let Err(feature_validation_error) = validate_subgraph_features(&self.0) { - errors.push(feature_validation_error.into()) - } + if self.0.spec_version >= SPEC_VERSION_0_0_4 + && let Err(feature_validation_error) = validate_subgraph_features(&self.0) + { + errors.push(feature_validation_error.into()) } // Validate subgraph datasource constraints diff --git a/graph/src/data/subgraph/schema.rs b/graph/src/data/subgraph/schema.rs index 75922d810f2..c65dfad88e2 100644 --- a/graph/src/data/subgraph/schema.rs +++ b/graph/src/data/subgraph/schema.rs @@ -1,10 +1,10 @@ //! Entity types that contain the graph-node state. -use anyhow::{anyhow, bail, Error}; +use anyhow::{Error, anyhow, bail}; use chrono::{DateTime, Utc}; use hex; -use rand::rngs::OsRng; use rand::TryRngCore as _; +use rand::rngs::OsRng; use std::collections::BTreeSet; use std::str::FromStr; use std::{fmt, fmt::Display}; diff --git a/graph/src/data/subgraph/status.rs b/graph/src/data/subgraph/status.rs index 5d78311249d..86c45fc193f 100644 --- a/graph/src/data/subgraph/status.rs +++ b/graph/src/data/subgraph/status.rs @@ -3,8 +3,8 @@ use super::schema::{SubgraphError, SubgraphHealth}; use crate::blockchain::BlockHash; use crate::components::store::{BlockNumber, DeploymentId}; -use crate::data::graphql::{object, IntoValue}; -use crate::prelude::{r, BlockPtr, Value}; +use crate::data::graphql::{IntoValue, object}; +use crate::prelude::{BlockPtr, Value, r}; pub enum Filter { /// Get all versions for the named subgraph diff --git a/graph/src/data/value.rs b/graph/src/data/value.rs index 7abf8fec47e..6dce081aa7b 100644 --- a/graph/src/data/value.rs +++ b/graph/src/data/value.rs @@ -4,8 +4,8 @@ use crate::runtime::gas::{Gas, GasSizeOf, SaturatingInto}; use diesel::pg::Pg; use diesel::serialize::{self, Output, ToSql}; use diesel::sql_types::Text; -use serde::ser::{SerializeMap, SerializeSeq, Serializer}; use serde::Serialize; +use serde::ser::{SerializeMap, SerializeSeq, Serializer}; use std::collections::BTreeMap; use std::convert::TryFrom; use std::iter::FromIterator; diff --git a/graph/src/data_source/common.rs b/graph/src/data_source/common.rs index bc9b27b5bd6..c02a7577dd3 100644 --- a/graph/src/data_source/common.rs +++ b/graph/src/data_source/common.rs @@ -12,13 +12,13 @@ use crate::{ }; use alloy::primitives::{Address, U256}; use alloy::rpc::types::Log; -use anyhow::{anyhow, Context, Error}; +use anyhow::{Context, Error, anyhow}; use graph_derive::CheapClone; use lazy_static::lazy_static; use num_bigint::Sign; use regex::Regex; -use serde::de; use serde::Deserialize; +use serde::de; use serde_json; use slog::Logger; use std::collections::HashMap; @@ -55,12 +55,11 @@ fn normalize_abi_json(json_bytes: &[u8]) -> Result, anyhow::Error> { for (index, item) in array.iter_mut().enumerate() { if let Some(obj) = item.as_object_mut() { - if let Some(state_mutability) = obj.get_mut("stateMutability") { - if let Some(s) = state_mutability.as_str() { - if s == "undefined" { - *state_mutability = serde_json::Value::String("nonpayable".to_string()); - } - } + if let Some(state_mutability) = obj.get_mut("stateMutability") + && let Some(s) = state_mutability.as_str() + && s == "undefined" + { + *state_mutability = serde_json::Value::String("nonpayable".to_string()); } let item_type = obj.get("type").and_then(|t| t.as_str()); @@ -183,43 +182,37 @@ impl AbiJson { for item in abi_array { // Only process events - if item.get("type").and_then(|t| t.as_str()) == Some("event") { - if let Some(item_event_name) = item.get("name").and_then(|n| n.as_str()) { - if item_event_name == event_name { - // Found the event, now look for the parameter - if let Some(inputs) = item.get("inputs").and_then(|i| i.as_array()) { - for input in inputs { - if let Some(input_param_name) = - input.get("name").and_then(|n| n.as_str()) - { - if input_param_name == param_name { - // Found the parameter, check if it's a struct - if let Some(param_type) = - input.get("type").and_then(|t| t.as_str()) - { - if param_type == "tuple" { - if let Some(components) = input.get("components") { - // Parse the ParamType from the JSON (simplified for now) - let param_type = abi::DynSolType::Tuple(vec![]); - return StructFieldInfo::from_components( - param_name.to_string(), - param_type, - components, - ) - .map(Some); - } - } - } - // Parameter found but not a struct - return Ok(None); - } - } + if item.get("type").and_then(|t| t.as_str()) == Some("event") + && let Some(item_event_name) = item.get("name").and_then(|n| n.as_str()) + && item_event_name == event_name + { + // Found the event, now look for the parameter + if let Some(inputs) = item.get("inputs").and_then(|i| i.as_array()) { + for input in inputs { + if let Some(input_param_name) = input.get("name").and_then(|n| n.as_str()) + && input_param_name == param_name + { + // Found the parameter, check if it's a struct + if let Some(param_type) = input.get("type").and_then(|t| t.as_str()) + && param_type == "tuple" + && let Some(components) = input.get("components") + { + // Parse the ParamType from the JSON (simplified for now) + let param_type = abi::DynSolType::Tuple(vec![]); + return StructFieldInfo::from_components( + param_name.to_string(), + param_type, + components, + ) + .map(Some); } + // Parameter found but not a struct + return Ok(None); } - // Event found but parameter not found - return Ok(None); } } + // Event found but parameter not found + return Ok(None); } } @@ -249,45 +242,35 @@ impl AbiJson { for item in abi_array { // Only process events - if item.get("type").and_then(|t| t.as_str()) == Some("event") { - if let Some(item_event_name) = item.get("name").and_then(|n| n.as_str()) { - if item_event_name == event_name { - // Found the event, now look for the parameter - if let Some(inputs) = item.get("inputs").and_then(|i| i.as_array()) { - for input in inputs { - if let Some(input_param_name) = - input.get("name").and_then(|n| n.as_str()) - { - if input_param_name == param_name { - // Found the parameter, check if it's a struct - if let Some(param_type) = - input.get("type").and_then(|t| t.as_str()) - { - if param_type == "tuple" { - if let Some(components) = input.get("components") { - // If no nested path, this is the end - if nested_path.is_empty() { - return Ok(Some(vec![])); - } - // Recursively resolve the nested path - return Self::resolve_field_path( - components, - nested_path, - ) - .map(Some); - } - } - } - // Parameter found but not a struct - return Ok(None); - } + if item.get("type").and_then(|t| t.as_str()) == Some("event") + && let Some(item_event_name) = item.get("name").and_then(|n| n.as_str()) + && item_event_name == event_name + { + // Found the event, now look for the parameter + if let Some(inputs) = item.get("inputs").and_then(|i| i.as_array()) { + for input in inputs { + if let Some(input_param_name) = input.get("name").and_then(|n| n.as_str()) + && input_param_name == param_name + { + // Found the parameter, check if it's a struct + if let Some(param_type) = input.get("type").and_then(|t| t.as_str()) + && param_type == "tuple" + && let Some(components) = input.get("components") + { + // If no nested path, this is the end + if nested_path.is_empty() { + return Ok(Some(vec![])); } + // Recursively resolve the nested path + return Self::resolve_field_path(components, nested_path).map(Some); } + // Parameter found but not a struct + return Ok(None); } - // Event found but parameter not found - return Ok(None); } } + // Event found but parameter not found + return Ok(None); } } @@ -361,40 +344,37 @@ impl AbiJson { // It's a field name - find it in the current level for (index, component) in components_array.iter().enumerate() { - if let Some(component_name) = component.get("name").and_then(|n| n.as_str()) { - if component_name == field_accessor { - // Found the field - if remaining_path.is_empty() { - // This is the final field, return its index - return Ok(vec![index]); - } else { - // We need to go deeper - check if this component is a tuple - if let Some(component_type) = component.get("type").and_then(|t| t.as_str()) - { - if component_type == "tuple" { - if let Some(nested_components) = component.get("components") { - // Recursively resolve the remaining path - let mut result = vec![index]; - let nested_result = Self::resolve_field_path( - nested_components, - remaining_path, - )?; - result.extend(nested_result); - return Ok(result); - } else { - return Err(anyhow!( - "Tuple field '{}' has no components", - field_accessor - )); - } + if let Some(component_name) = component.get("name").and_then(|n| n.as_str()) + && component_name == field_accessor + { + // Found the field + if remaining_path.is_empty() { + // This is the final field, return its index + return Ok(vec![index]); + } else { + // We need to go deeper - check if this component is a tuple + if let Some(component_type) = component.get("type").and_then(|t| t.as_str()) { + if component_type == "tuple" { + if let Some(nested_components) = component.get("components") { + // Recursively resolve the remaining path + let mut result = vec![index]; + let nested_result = + Self::resolve_field_path(nested_components, remaining_path)?; + result.extend(nested_result); + return Ok(result); } else { return Err(anyhow!( - "Field '{}' is not a struct (type: {}), cannot access nested field '{}'", - field_accessor, - component_type, - remaining_path[0] + "Tuple field '{}' has no components", + field_accessor )); } + } else { + return Err(anyhow!( + "Field '{}' is not a struct (type: {}), cannot access nested field '{}'", + field_accessor, + component_type, + remaining_path[0] + )); } } } @@ -557,9 +537,9 @@ impl CallDecl { }, CallArg::Subgraph(_) => { return Err(anyhow!( - "In declarative call '{}': Subgraph params are not supported for event handlers", - self.label - )) + "In declarative call '{}': Subgraph params are not supported for event handlers", + self.label + )); } }; Ok(address) @@ -874,7 +854,9 @@ impl CallDecl { _ => { return Err(anyhow!( "In declarative call '{}': cannot access field on non-struct/tuple at access step {} (field path: {:?})", - call_label, index, field_accesses + call_label, + index, + field_accesses )); } } @@ -1187,10 +1169,10 @@ impl CallArg { spec_version: &semver::Version, ) -> Result { // Handle hex addresses first - if ADDR_RE.is_match(s) { - if let Ok(parsed_address) = Address::from_str(s) { - return Ok(CallArg::HexAddress(parsed_address)); - } + if ADDR_RE.is_match(s) + && let Ok(parsed_address) = Address::from_str(s) + { + return Ok(CallArg::HexAddress(parsed_address)); } // Context validation @@ -1235,11 +1217,11 @@ impl CallArg { // Validate spec version before allowing any struct field access if spec_version < &SPEC_VERSION_1_4_0 { return Err(anyhow!( - "Struct field access 'event.params.{}.*' in declarative calls is only supported for specVersion >= 1.4.0, current version is {}. Event: '{}'", - param, - spec_version, - event_signature.unwrap_or("unknown") - )); + "Struct field access 'event.params.{}.*' in declarative calls is only supported for specVersion >= 1.4.0, current version is {}. Event: '{}'", + param, + spec_version, + event_signature.unwrap_or("unknown") + )); } // Resolve field path - supports both numeric and named fields @@ -2401,8 +2383,6 @@ mod tests { } ]"#; - let abi_json_helper = AbiJson::new(ABI_JSON.as_bytes()).unwrap(); - - abi_json_helper + AbiJson::new(ABI_JSON.as_bytes()).unwrap() } } diff --git a/graph/src/data_source/mod.rs b/graph/src/data_source/mod.rs index cd34ca62857..016903ab55f 100644 --- a/graph/src/data_source/mod.rs +++ b/graph/src/data_source/mod.rs @@ -25,9 +25,9 @@ use crate::{ prelude::{CheapClone as _, DataSourceContext}, schema::{EntityType, InputSchema}, }; -use anyhow::{anyhow, Context, Error}; +use anyhow::{Context, Error, anyhow}; use semver::Version; -use serde::{de::IntoDeserializer as _, Deserialize, Deserializer}; +use serde::{Deserialize, Deserializer, de::IntoDeserializer as _}; use slog::{Logger, SendSyncRefUnwindSafeKV}; use std::{ collections::{BTreeMap, HashSet}, diff --git a/graph/src/data_source/offchain.rs b/graph/src/data_source/offchain.rs index 35e62a3cdcc..b21b52a6e3a 100644 --- a/graph/src/data_source/offchain.rs +++ b/graph/src/data_source/offchain.rs @@ -16,16 +16,16 @@ use crate::{ prelude::{DataSourceContext, Link}, schema::{EntityType, InputSchema}, }; -use anyhow::{anyhow, Context, Error}; +use anyhow::{Context, Error, anyhow}; use itertools::Itertools; use lazy_static::lazy_static; use serde::Deserialize; -use slog::{info, warn, Logger}; +use slog::{Logger, info, warn}; use std::{ collections::HashMap, fmt, str::FromStr, - sync::{atomic::AtomicI32, Arc}, + sync::{Arc, atomic::AtomicI32}, }; use super::{CausalityRegion, DataSourceCreationError, DataSourceTemplateInfo, TriggerWithHandler}; @@ -326,8 +326,8 @@ impl Source { /// the `source` of the data source is equal the `source` of the `TriggerData`. pub fn address(&self) -> Option> { match self { - Source::Ipfs(ref path) => Some(path.to_string().as_bytes().to_vec()), - Source::Arweave(ref base64) => Some(base64.as_bytes().to_vec()), + Source::Ipfs(path) => Some(path.to_string().as_bytes().to_vec()), + Source::Arweave(base64) => Some(base64.as_bytes().to_vec()), } } } @@ -335,8 +335,8 @@ impl Source { impl From for Bytes { fn from(val: Source) -> Self { match val { - Source::Ipfs(ref path) => Bytes::from(path.to_string().as_bytes().to_vec()), - Source::Arweave(ref base64) => Bytes::from(base64.as_bytes()), + Source::Ipfs(path) => Bytes::from(path.to_string().as_bytes().to_vec()), + Source::Arweave(base64) => Bytes::from(base64.as_bytes()), } } } diff --git a/graph/src/data_source/subgraph.rs b/graph/src/data_source/subgraph.rs index 454f20ec29e..e7b6319b942 100644 --- a/graph/src/data_source/subgraph.rs +++ b/graph/src/data_source/subgraph.rs @@ -1,13 +1,13 @@ use crate::{ - blockchain::{block_stream::EntitySourceOperation, Block, Blockchain}, + blockchain::{Block, Blockchain, block_stream::EntitySourceOperation}, components::{ link_resolver::{LinkResolver, LinkResolverContext}, store::BlockNumber, }, data::{ subgraph::{ - calls_host_fn, SubgraphManifest, UnresolvedSubgraphManifest, LATEST_VERSION, - SPEC_VERSION_1_3_0, + LATEST_VERSION, SPEC_VERSION_1_3_0, SubgraphManifest, UnresolvedSubgraphManifest, + calls_host_fn, }, value::Word, }, @@ -16,17 +16,17 @@ use crate::{ prelude::{CheapClone, DataSourceContext, DeploymentHash, Link}, schema::TypeKind, }; -use anyhow::{anyhow, Context, Error, Result}; -use futures03::{stream::FuturesOrdered, TryStreamExt}; +use anyhow::{Context, Error, Result, anyhow}; +use futures03::{TryStreamExt, stream::FuturesOrdered}; use serde::Deserialize; -use slog::{info, Logger}; +use slog::{Logger, info}; use std::{fmt, sync::Arc}; use super::{ + DataSourceTemplateInfo, TriggerWithHandler, common::{ AbiJson, CallDecls, FindMappingABI, MappingABI, UnresolvedCallDecls, UnresolvedMappingABI, }, - DataSourceTemplateInfo, TriggerWithHandler, }; use crate::amp; diff --git a/graph/src/data_source/tests.rs b/graph/src/data_source/tests.rs index 500c8cdb403..93818f5bb8f 100644 --- a/graph/src/data_source/tests.rs +++ b/graph/src/data_source/tests.rs @@ -51,10 +51,12 @@ fn data_source_helpers() { let offchain = new_datasource(); let offchain_ds = DataSource::::Offchain(offchain.clone()); assert!(offchain_ds.causality_region() == offchain.causality_region); - assert!(offchain_ds - .as_offchain() - .unwrap() - .is_duplicate_of(&offchain)); + assert!( + offchain_ds + .as_offchain() + .unwrap() + .is_duplicate_of(&offchain) + ); let onchain = DataSource::::Onchain(MockDataSource { api_version: Version::new(1, 0, 0), diff --git a/graph/src/endpoint.rs b/graph/src/endpoint.rs index 1b563fb52f0..a62dc07f2ba 100644 --- a/graph/src/endpoint.rs +++ b/graph/src/endpoint.rs @@ -1,13 +1,13 @@ use std::{ collections::HashMap, sync::{ - atomic::{AtomicU64, Ordering}, Arc, + atomic::{AtomicU64, Ordering}, }, }; use prometheus::IntCounterVec; -use slog::{warn, Logger}; +use slog::{Logger, warn}; use crate::components::network_provider::ProviderName; use crate::{components::metrics::MetricsRegistry, data::value::Word}; @@ -100,7 +100,7 @@ impl EndpointMetrics { /// This should only be used for testing. pub fn mock() -> Self { - use slog::{o, Discard}; + use slog::{Discard, o}; let providers: &[&str] = &[]; Self::new( Logger::root(Discard, o!()), @@ -169,7 +169,7 @@ impl EndpointMetrics { mod test { use std::sync::Arc; - use slog::{o, Discard, Logger}; + use slog::{Discard, Logger, o}; use crate::{ components::metrics::MetricsRegistry, diff --git a/graph/src/env/graphql.rs b/graph/src/env/graphql.rs index 4f1f9896488..f4563155493 100644 --- a/graph/src/env/graphql.rs +++ b/graph/src/env/graphql.rs @@ -139,8 +139,8 @@ impl From for EnvVarsGraphQl { max_first: x.max_first, max_skip: x.max_skip.0, allow_deployment_change: x.allow_deployment_change.0, - warn_result_size: x.warn_result_size.0 .0, - error_result_size: x.error_result_size.0 .0, + warn_result_size: x.warn_result_size.0.0, + error_result_size: x.error_result_size.0.0, disable_bool_filters: x.disable_bool_filters.0, disable_child_sorting: x.disable_child_sorting.0, query_trace_token: x.query_trace_token, diff --git a/graph/src/env/mappings.rs b/graph/src/env/mappings.rs index c56bea2bac4..83ebef18962 100644 --- a/graph/src/env/mappings.rs +++ b/graph/src/env/mappings.rs @@ -149,7 +149,7 @@ impl TryFrom for EnvVarsMapping { max_api_version: x.max_api_version, timeout: x.mapping_handler_timeout_in_secs.map(Duration::from_secs), - max_stack_size: x.runtime_max_stack_size.0 .0, + max_stack_size: x.runtime_max_stack_size.0.0, max_ipfs_cache_file_size: x.max_ipfs_cache_file_size.0, max_ipfs_cache_size: x.max_ipfs_cache_size, diff --git a/graph/src/env/mod.rs b/graph/src/env/mod.rs index 536a383e0da..23abf67d813 100644 --- a/graph/src/env/mod.rs +++ b/graph/src/env/mod.rs @@ -322,7 +322,7 @@ impl EnvVars { lock_contention_log_threshold: Duration::from_millis( inner.lock_contention_log_threshold_in_ms, ), - max_gas_per_handler: inner.max_gas_per_handler.0 .0, + max_gas_per_handler: inner.max_gas_per_handler.0.0, log_query_timing: inner .log_query_timing .split(',') diff --git a/graph/src/env/store.rs b/graph/src/env/store.rs index e36e60c8b84..92c5564d17f 100644 --- a/graph/src/env/store.rs +++ b/graph/src/env/store.rs @@ -254,12 +254,12 @@ impl TryFrom for EnvVarsStore { x.connection_unavailable_retry_in_secs, ), }; - if let Some(timeout) = vars.batch_timeout { - if timeout < 2 * vars.batch_target_duration { - bail!( - "GRAPH_STORE_BATCH_TIMEOUT must be greater than 2*GRAPH_STORE_BATCH_TARGET_DURATION" - ); - } + if let Some(timeout) = vars.batch_timeout + && timeout < 2 * vars.batch_target_duration + { + bail!( + "GRAPH_STORE_BATCH_TIMEOUT must be greater than 2*GRAPH_STORE_BATCH_TARGET_DURATION" + ); } if vars.batch_workers < 1 { bail!("GRAPH_STORE_BATCH_WORKERS must be at least 1"); diff --git a/graph/src/ext/futures.rs b/graph/src/ext/futures.rs index 7c5eb0fc96e..b9453ff31da 100644 --- a/graph/src/ext/futures.rs +++ b/graph/src/ext/futures.rs @@ -2,7 +2,7 @@ use crate::blockchain::block_stream::BlockStreamError; use crate::prelude::tokio::macros::support::Poll; use crate::prelude::{Pin, StoreError}; use futures03::channel::oneshot; -use futures03::{future::Fuse, Future, FutureExt, Stream}; +use futures03::{Future, FutureExt, Stream, future::Fuse}; use std::fmt::{Debug, Display}; use std::sync::{Arc, Mutex, Weak}; use std::task::Context; diff --git a/graph/src/firehose/endpoint_info/info_response.rs b/graph/src/firehose/endpoint_info/info_response.rs index 56f431452c4..a51ae7610c5 100644 --- a/graph/src/firehose/endpoint_info/info_response.rs +++ b/graph/src/firehose/endpoint_info/info_response.rs @@ -1,6 +1,6 @@ -use anyhow::anyhow; use anyhow::Context; use anyhow::Result; +use anyhow::anyhow; use crate::blockchain::BlockHash; use crate::blockchain::BlockPtr; @@ -78,9 +78,9 @@ fn parse_block_hash( s: String, encoding: codec::info_response::BlockIdEncoding, ) -> Result { + use base64::Engine; use base64::engine::general_purpose::STANDARD; use base64::engine::general_purpose::URL_SAFE; - use base64::Engine; use codec::info_response::BlockIdEncoding::*; let block_hash = match encoding { diff --git a/graph/src/firehose/endpoints.rs b/graph/src/firehose/endpoints.rs index 537b5bf9bcd..02e4c24b116 100644 --- a/graph/src/firehose/endpoints.rs +++ b/graph/src/firehose/endpoints.rs @@ -2,29 +2,29 @@ use crate::firehose::fetch_client::FetchClient; use crate::firehose::interceptors::AuthInterceptor; use crate::{ blockchain::{ - block_stream::FirehoseCursor, Block as BlockchainBlock, BlockPtr, ChainIdentifier, + Block as BlockchainBlock, BlockPtr, ChainIdentifier, block_stream::FirehoseCursor, }, cheap_clone::CheapClone, components::store::BlockNumber, endpoint::{ConnectionType, EndpointMetrics, RequestLabels}, env::ENV_VARS, firehose::decode_firehose_block, - prelude::{anyhow, debug, DeploymentHash}, + prelude::{DeploymentHash, anyhow, debug}, }; use anyhow::Context; use async_trait::async_trait; use futures03::{StreamExt, TryStreamExt}; use http::uri::{Scheme, Uri}; use itertools::Itertools; -use slog::{error, info, trace, Logger}; +use slog::{Logger, error, info, trace}; use std::{collections::HashMap, fmt::Display, ops::ControlFlow, sync::Arc, time::Duration}; use tokio::sync::OnceCell; use tonic::codegen::InterceptedService; use tonic::{ + Request, codegen::CompressionEncoding, metadata::{Ascii, MetadataKey, MetadataValue}, transport::{Channel, ClientTlsConfig}, - Request, }; use super::{codec as firehose, interceptors::MetricsInterceptor, stream_client::StreamClient}; @@ -736,7 +736,7 @@ impl FirehoseEndpoints { mod test { use std::{mem, sync::Arc}; - use slog::{o, Discard, Logger}; + use slog::{Discard, Logger, o}; use super::*; use crate::components::metrics::MetricsRegistry; diff --git a/graph/src/ipfs/cache.rs b/graph/src/ipfs/cache.rs index 41c69a0fc7d..ab9daf6f784 100644 --- a/graph/src/ipfs/cache.rs +++ b/graph/src/ipfs/cache.rs @@ -9,12 +9,12 @@ use async_trait::async_trait; use bytes::Bytes; use graph_derive::CheapClone; use lru_time_cache::LruCache; -use object_store::{local::LocalFileSystem, path::Path, ObjectStore, ObjectStoreExt as _}; +use object_store::{ObjectStore, ObjectStoreExt as _, local::LocalFileSystem, path::Path}; use redis::{ - aio::{ConnectionManager, ConnectionManagerConfig}, AsyncCommands as _, RedisResult, Value, + aio::{ConnectionManager, ConnectionManagerConfig}, }; -use slog::{debug, info, warn, Logger}; +use slog::{Logger, debug, info, warn}; use tokio::sync::Mutex as AsyncMutex; use crate::{env::ENV_VARS, prelude::CheapClone}; diff --git a/graph/src/ipfs/client.rs b/graph/src/ipfs/client.rs index 908a46c338e..fd8ac996985 100644 --- a/graph/src/ipfs/client.rs +++ b/graph/src/ipfs/client.rs @@ -5,9 +5,9 @@ use std::time::{Duration, Instant}; use async_trait::async_trait; use bytes::Bytes; use bytes::BytesMut; -use futures03::stream::BoxStream; use futures03::StreamExt; use futures03::TryStreamExt; +use futures03::stream::BoxStream; use slog::Logger; use crate::cheap_clone::CheapClone as _; diff --git a/graph/src/ipfs/content_path.rs b/graph/src/ipfs/content_path.rs index 39c8b95d29e..54fd569e5e4 100644 --- a/graph/src/ipfs/content_path.rs +++ b/graph/src/ipfs/content_path.rs @@ -172,9 +172,10 @@ mod tests { fn fails_on_an_invalid_cid() { let err = ContentPath::new("not_a_cid").unwrap_err(); - assert!(err - .to_string() - .starts_with("'not_a_cid' is not a valid IPFS content path: invalid CID: ")); + assert!( + err.to_string() + .starts_with("'not_a_cid' is not a valid IPFS content path: invalid CID: ") + ); } #[test] @@ -217,9 +218,11 @@ mod tests { fn fails_on_an_invalid_cid_followed_by_a_path() { let err = ContentPath::new("not_a_cid/readme.md").unwrap_err(); - assert!(err - .to_string() - .starts_with("'not_a_cid/readme.md' is not a valid IPFS content path: invalid CID: ")); + assert!( + err.to_string().starts_with( + "'not_a_cid/readme.md' is not a valid IPFS content path: invalid CID: " + ) + ); } #[test] diff --git a/graph/src/ipfs/gateway_client.rs b/graph/src/ipfs/gateway_client.rs index 91a9126e4f1..ff2a8a431cc 100644 --- a/graph/src/ipfs/gateway_client.rs +++ b/graph/src/ipfs/gateway_client.rs @@ -5,7 +5,7 @@ use async_trait::async_trait; use derive_more::Debug; use http::header::ACCEPT; use http::header::CACHE_CONTROL; -use reqwest::{redirect::Policy as RedirectPolicy, StatusCode}; +use reqwest::{StatusCode, redirect::Policy as RedirectPolicy}; use slog::Logger; use crate::env::ENV_VARS; @@ -162,11 +162,11 @@ mod tests { use bytes::BytesMut; use futures03::TryStreamExt; - use wiremock::matchers as m; use wiremock::Mock; use wiremock::MockBuilder; use wiremock::MockServer; use wiremock::ResponseTemplate; + use wiremock::matchers as m; use super::*; use crate::data::subgraph::DeploymentHash; @@ -551,7 +551,7 @@ mod tests { #[crate::test] async fn operation_names_include_cid_for_debugging() { - use slog::{o, Drain, Logger, Record}; + use slog::{Drain, Logger, Record, o}; use std::sync::{Arc, Mutex}; // Custom drain to capture log messages diff --git a/graph/src/ipfs/mod.rs b/graph/src/ipfs/mod.rs index d8231d2074c..1bbcc459be3 100644 --- a/graph/src/ipfs/mod.rs +++ b/graph/src/ipfs/mod.rs @@ -5,8 +5,8 @@ use cache::CachingClient; use futures03::future::BoxFuture; use futures03::stream::FuturesUnordered; use futures03::stream::StreamExt; -use slog::info; use slog::Logger; +use slog::info; use crate::components::metrics::MetricsRegistry; use crate::util::security::SafeDisplay; diff --git a/graph/src/ipfs/pool.rs b/graph/src/ipfs/pool.rs index bf8943036c1..d78ac0c9483 100644 --- a/graph/src/ipfs/pool.rs +++ b/graph/src/ipfs/pool.rs @@ -68,11 +68,11 @@ mod tests { use bytes::BytesMut; use futures03::TryStreamExt; use http::StatusCode; - use wiremock::matchers as m; use wiremock::Mock; use wiremock::MockBuilder; use wiremock::MockServer; use wiremock::ResponseTemplate; + use wiremock::matchers as m; use super::*; use crate::ipfs::{ContentPath, IpfsContext, IpfsGatewayClient, IpfsMetrics, RetryPolicy}; diff --git a/graph/src/ipfs/retry_policy.rs b/graph/src/ipfs/retry_policy.rs index 783f506d568..2b7d63f1657 100644 --- a/graph/src/ipfs/retry_policy.rs +++ b/graph/src/ipfs/retry_policy.rs @@ -2,8 +2,8 @@ use slog::Logger; use crate::ipfs::error::IpfsError; use crate::prelude::*; -use crate::util::futures::retry; use crate::util::futures::RetryConfig; +use crate::util::futures::retry; /// Describes retry behavior when IPFS requests fail. #[derive(Clone, Copy, Debug)] @@ -42,9 +42,9 @@ impl RetryPolicy { #[cfg(test)] mod tests { + use std::sync::Arc; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; - use std::sync::Arc; use std::time::Duration; use super::*; diff --git a/graph/src/ipfs/rpc_client.rs b/graph/src/ipfs/rpc_client.rs index 1838036c6ec..8dc1a7b9445 100644 --- a/graph/src/ipfs/rpc_client.rs +++ b/graph/src/ipfs/rpc_client.rs @@ -140,11 +140,11 @@ mod tests { use bytes::BytesMut; use futures03::TryStreamExt; - use wiremock::matchers as m; use wiremock::Mock; use wiremock::MockBuilder; use wiremock::MockServer; use wiremock::ResponseTemplate; + use wiremock::matchers as m; use super::*; use crate::ipfs::{ContentPath, IpfsContext, IpfsMetrics}; diff --git a/graph/src/ipfs/server_address.rs b/graph/src/ipfs/server_address.rs index 46890e4e083..a6a7cfe759a 100644 --- a/graph/src/ipfs/server_address.rs +++ b/graph/src/ipfs/server_address.rs @@ -1,8 +1,8 @@ use std::sync::Arc; use anyhow::anyhow; -use http::uri::Scheme; use http::Uri; +use http::uri::Scheme; use crate::derive::CheapClone; use crate::ipfs::IpfsError; diff --git a/graph/src/lib.rs b/graph/src/lib.rs index 83a8a4a9112..5b6ede158db 100644 --- a/graph/src/lib.rs +++ b/graph/src/lib.rs @@ -52,8 +52,8 @@ pub use futures03; pub use graph_derive as derive; pub use graph_derive::test; pub use http; -pub use http0; pub use http_body_util; +pub use http0; pub use hyper; pub use hyper_util; pub use itertools; @@ -77,7 +77,7 @@ pub use url; pub mod prelude { pub use ::anyhow; pub use alloy; - pub use anyhow::{anyhow, Context as _, Error}; + pub use anyhow::{Context as _, Error, anyhow}; pub use chrono; pub use diesel; pub use envconfig; @@ -92,7 +92,7 @@ pub mod prelude { pub use serde_json; pub use serde_regex; pub use serde_yaml; - pub use slog::{self, crit, debug, error, info, o, trace, warn, Logger}; + pub use slog::{self, Logger, crit, debug, error, info, o, trace, warn}; pub use std::convert::TryFrom; pub use std::fmt::Debug; pub use std::iter::FromIterator; @@ -119,17 +119,17 @@ pub mod prelude { IpfsResolver, JsonStreamValue, JsonValueStream, LinkResolver, }; pub use crate::components::metrics::{ - stopwatch::StopwatchMetrics, subgraph::*, Collector, Counter, CounterVec, Gauge, GaugeVec, - Histogram, HistogramOpts, HistogramVec, MetricsRegistry, Opts, PrometheusError, Registry, + Collector, Counter, CounterVec, Gauge, GaugeVec, Histogram, HistogramOpts, HistogramVec, + MetricsRegistry, Opts, PrometheusError, Registry, stopwatch::StopwatchMetrics, subgraph::*, }; pub use crate::components::store::{ - write::EntityModification, AssignmentChange, AssignmentOperation, AttributeNames, - BlockNumber, CachedEthereumCall, ChainStore, Child, ChildMultiplicity, EntityCache, - EntityCollection, EntityFilter, EntityLink, EntityOperation, EntityOrder, - EntityOrderByChild, EntityOrderByChildInfo, EntityQuery, EntityRange, EntityWindow, - EthereumCallCache, ParentLink, PartialBlockPtr, PoolWaitStats, QueryStore, - QueryStoreManager, SeqGenerator, StaleCallCacheResult, StoreError, StoreEvent, - StoreEventStreamBox, SubgraphStore, UnfailOutcome, WindowAttribute, BLOCK_NUMBER_MAX, + AssignmentChange, AssignmentOperation, AttributeNames, BLOCK_NUMBER_MAX, BlockNumber, + CachedEthereumCall, ChainStore, Child, ChildMultiplicity, EntityCache, EntityCollection, + EntityFilter, EntityLink, EntityOperation, EntityOrder, EntityOrderByChild, + EntityOrderByChildInfo, EntityQuery, EntityRange, EntityWindow, EthereumCallCache, + ParentLink, PartialBlockPtr, PoolWaitStats, QueryStore, QueryStoreManager, SeqGenerator, + StaleCallCacheResult, StoreError, StoreEvent, StoreEventStreamBox, SubgraphStore, + UnfailOutcome, WindowAttribute, write::EntityModification, }; pub use crate::components::subgraph::{ BlockState, BlockStateCheckpoint, HostMetrics, InstanceDSTemplateInfo, RuntimeHost, @@ -138,12 +138,12 @@ pub mod prelude { }; pub use crate::components::trigger_processor::TriggerProcessor; pub use crate::components::versions::{ApiVersion, FeatureFlag}; - pub use crate::components::{transaction_receipt, EventConsumer, EventProducer}; + pub use crate::components::{EventConsumer, EventProducer, transaction_receipt}; pub use crate::env::ENV_VARS; pub use crate::cheap_clone::CheapClone; pub use crate::data::graphql::{ - shape_hash::shape_hash, SerializableValue, TryFromValue, ValueMap, + SerializableValue, TryFromValue, ValueMap, shape_hash::shape_hash, }; pub use crate::data::query::{ Query, QueryError, QueryExecutionError, QueryResult, QueryTarget, QueryVariables, @@ -164,13 +164,13 @@ pub mod prelude { }; pub use crate::impl_slog_value; pub use crate::log::codes::LogCode; - pub use crate::log::elastic::{elastic_logger, ElasticDrainConfig, ElasticLoggingConfig}; + pub use crate::log::elastic::{ElasticDrainConfig, ElasticLoggingConfig, elastic_logger}; pub use crate::log::factory::{ ComponentLoggerConfig, ElasticComponentLoggerConfig, LoggerFactory, }; pub use crate::log::split::split_logger; pub use crate::util::cache_weight::CacheWeight; - pub use crate::util::futures::{retry, TimeoutError}; + pub use crate::util::futures::{TimeoutError, retry}; pub use crate::util::stats::{AtomicMovingStats, MovingStats}; pub use crate::util::test_utils::*; diff --git a/graph/src/log/elastic.rs b/graph/src/log/elastic.rs index eb285d3d6e6..141cdfdcecd 100644 --- a/graph/src/log/elastic.rs +++ b/graph/src/log/elastic.rs @@ -11,8 +11,8 @@ use http::header::CONTENT_TYPE; use prometheus::Counter; use reqwest; use reqwest::Client; -use serde::ser::Serializer as SerdeSerializer; use serde::Serialize; +use serde::ser::Serializer as SerdeSerializer; use serde_json::json; use slog::*; use slog_async; diff --git a/graph/src/runtime/asc_heap.rs b/graph/src/runtime/asc_heap.rs index 1301ea017f5..ecccf546ba3 100644 --- a/graph/src/runtime/asc_heap.rs +++ b/graph/src/runtime/asc_heap.rs @@ -4,8 +4,8 @@ use async_trait::async_trait; use semver::Version; use super::{ - gas::GasCounter, AscIndexId, AscPtr, AscType, DeterministicHostError, HostExportError, - IndexForAscTypeId, + AscIndexId, AscPtr, AscType, DeterministicHostError, HostExportError, IndexForAscTypeId, + gas::GasCounter, }; // A 128 limit is plenty for any subgraph, while the `fn recursion_limit` test ensures it is not diff --git a/graph/src/runtime/asc_ptr.rs b/graph/src/runtime/asc_ptr.rs index 3325d4b7f02..8e25971590b 100644 --- a/graph/src/runtime/asc_ptr.rs +++ b/graph/src/runtime/asc_ptr.rs @@ -1,7 +1,7 @@ use crate::data::subgraph::API_VERSION_0_0_4; use super::gas::GasCounter; -use super::{padding_to_16, DeterministicHostError, HostExportError}; +use super::{DeterministicHostError, HostExportError, padding_to_16}; use super::{AscHeap, AscIndexId, AscType, IndexForAscTypeId}; use semver::Version; diff --git a/graph/src/runtime/gas/combinators.rs b/graph/src/runtime/gas/combinators.rs index a6bc37954db..152f317bab0 100644 --- a/graph/src/runtime/gas/combinators.rs +++ b/graph/src/runtime/gas/combinators.rs @@ -83,10 +83,10 @@ where #[inline] fn const_gas_size_of() -> Option { - if let Some(t0) = T0::const_gas_size_of() { - if let Some(t1) = T1::const_gas_size_of() { - return Some(C::combine(t0, t1)); - } + if let Some(t0) = T0::const_gas_size_of() + && let Some(t1) = T1::const_gas_size_of() + { + return Some(C::combine(t0, t1)); } None } @@ -109,12 +109,11 @@ where #[inline] // Const propagation to the rescue. I hope. fn const_gas_size_of() -> Option { - if let Some(t0) = T0::const_gas_size_of() { - if let Some(t1) = T1::const_gas_size_of() { - if let Some(t2) = T2::const_gas_size_of() { - return Some(C::combine(C::combine(t0, t1), t2)); - } - } + if let Some(t0) = T0::const_gas_size_of() + && let Some(t1) = T1::const_gas_size_of() + && let Some(t2) = T2::const_gas_size_of() + { + return Some(C::combine(C::combine(t0, t1), t2)); } None } diff --git a/graph/src/runtime/gas/mod.rs b/graph/src/runtime/gas/mod.rs index 4758833e8ea..ab666c9095b 100644 --- a/graph/src/runtime/gas/mod.rs +++ b/graph/src/runtime/gas/mod.rs @@ -12,8 +12,8 @@ pub use costs::DEFAULT_BASE_COST; pub use costs::*; pub use saturating::*; -use std::sync::atomic::{AtomicU64, Ordering::SeqCst}; use std::sync::Arc; +use std::sync::atomic::{AtomicU64, Ordering::SeqCst}; use std::{fmt, fmt::Display}; pub struct GasOp { @@ -100,11 +100,11 @@ impl GasCounter { amount += costs::HOST_EXPORT_GAS; // If gas metrics are enabled, track the gas used - if ENV_VARS.enable_dips_metrics { - if let Some(method) = method { - self.metrics.track_gas(method, amount.0); - self.metrics.track_operations(method, 1); - } + if ENV_VARS.enable_dips_metrics + && let Some(method) = method + { + self.metrics.track_gas(method, amount.0); + self.metrics.track_operations(method, 1); } let old = self diff --git a/graph/src/runtime/gas/size_of.rs b/graph/src/runtime/gas/size_of.rs index 651df429099..05369d94847 100644 --- a/graph/src/runtime/gas/size_of.rs +++ b/graph/src/runtime/gas/size_of.rs @@ -2,7 +2,7 @@ use crate::{ components::store::LoadRelatedRequest, - data::store::{scalar::Bytes, Value}, + data::store::{Value, scalar::Bytes}, schema::{EntityKey, EntityType}, }; diff --git a/graph/src/runtime/mod.rs b/graph/src/runtime/mod.rs index c91a5548b08..34a8a316020 100644 --- a/graph/src/runtime/mod.rs +++ b/graph/src/runtime/mod.rs @@ -9,7 +9,7 @@ mod asc_heap; mod asc_ptr; pub use asc_heap::{ - asc_get, asc_new, asc_new_or_missing, asc_new_or_null, AscHeap, FromAscObj, ToAscObj, + AscHeap, FromAscObj, ToAscObj, asc_get, asc_new, asc_new_or_missing, asc_new_or_null, }; pub use asc_ptr::AscPtr; diff --git a/graph/src/schema/api.rs b/graph/src/schema/api.rs index 4ebbbdc23c4..9159d1495db 100644 --- a/graph/src/schema/api.rs +++ b/graph/src/schema/api.rs @@ -10,13 +10,13 @@ use crate::cheap_clone::CheapClone; use crate::data::graphql::{ObjectOrInterface, ObjectTypeExt, TypeExt}; use crate::data::store::IdType; use crate::env::ENV_VARS; -use crate::schema::{ast, META_FIELD_NAME, META_FIELD_TYPE, SCHEMA_TYPE_NAME}; +use crate::schema::{META_FIELD_NAME, META_FIELD_TYPE, SCHEMA_TYPE_NAME, ast}; use crate::data::graphql::ext::{ - camel_cased_names, DefinitionExt, DirectiveExt, DocumentExt, ValueExt, + DefinitionExt, DirectiveExt, DocumentExt, ValueExt, camel_cased_names, }; use crate::derive::CheapClone; -use crate::prelude::{q, r, s, DeploymentHash}; +use crate::prelude::{DeploymentHash, q, r, s}; use super::{Aggregation, Field, InputSchema, Schema, TypeKind}; @@ -817,10 +817,10 @@ fn field_filter_input_values( extend_with_child_filter_input_value(field, type_name, &mut input_values); input_values } - s::TypeDefinition::Scalar(ref t) => { + s::TypeDefinition::Scalar(t) => { field_scalar_filter_input_values(&schema.document, field, ops.for_type(t)) } - s::TypeDefinition::Enum(ref t) => { + s::TypeDefinition::Enum(t) => { field_enum_filter_input_values(&schema.document, field, t) } _ => vec![], @@ -1016,8 +1016,8 @@ fn field_list_filter_input_values( (Some(named_type), Some(name.clone())) } } - s::TypeDefinition::Scalar(ref t) => (Some(s::Type::NamedType(t.name.clone())), None), - s::TypeDefinition::Enum(ref t) => (Some(s::Type::NamedType(t.name.clone())), None), + s::TypeDefinition::Scalar(t) => (Some(s::Type::NamedType(t.name.clone())), None), + s::TypeDefinition::Enum(t) => (Some(s::Type::NamedType(t.name.clone())), None), s::TypeDefinition::InputObject(_) | s::TypeDefinition::Union(_) => (None, None), }; @@ -1307,10 +1307,10 @@ fn meta_field() -> s::Field { mod tests { use crate::{ data::{ - graphql::{ext::FieldExt, ObjectTypeExt, TypeExt as _}, + graphql::{ObjectTypeExt, TypeExt as _, ext::FieldExt}, subgraph::LATEST_VERSION, }, - prelude::{s, DeploymentHash}, + prelude::{DeploymentHash, s}, schema::{InputSchema, SCHEMA_TYPE_NAME}, }; use lazy_static::lazy_static; @@ -2044,7 +2044,7 @@ mod tests { .expect("Query type is missing in derived API schema"); let singular_field = match query_type { - s::TypeDefinition::Object(ref t) => ast::get_field(t, "node"), + s::TypeDefinition::Object(t) => ast::get_field(t, "node"), _ => None, } .expect("\"node\" field is missing on Query type"); @@ -2068,7 +2068,7 @@ mod tests { ); let plural_field = match query_type { - s::TypeDefinition::Object(ref t) => ast::get_field(t, "nodes"), + s::TypeDefinition::Object(t) => ast::get_field(t, "nodes"), _ => None, } .expect("\"nodes\" field is missing on Query type"); diff --git a/graph/src/schema/ast.rs b/graph/src/schema/ast.rs index 60395cb88e0..fc9b97430c0 100644 --- a/graph/src/schema/ast.rs +++ b/graph/src/schema/ast.rs @@ -7,7 +7,7 @@ use crate::data::graphql::ext::DirectiveFinder; use crate::data::graphql::{DirectiveExt, DocumentExt, ObjectOrInterface}; use crate::derive::CheapClone; use crate::prelude::anyhow::anyhow; -use crate::prelude::{s, Error, ValueType}; +use crate::prelude::{Error, ValueType, s}; use super::AsEntityTypeName; @@ -211,7 +211,7 @@ pub fn get_field<'a>( /// Returns the value type for a GraphQL field type. pub fn get_field_value_type(field_type: &s::Type) -> Result { match field_type { - s::Type::NamedType(ref name) => ValueType::from_str(name), + s::Type::NamedType(name) => ValueType::from_str(name), s::Type::NonNullType(inner) => get_field_value_type(inner), s::Type::ListType(_) => Err(anyhow!("Only scalar values are supported in this context")), } diff --git a/graph/src/schema/input/mod.rs b/graph/src/schema/input/mod.rs index ef241ff831f..905a46dbea5 100644 --- a/graph/src/schema/input/mod.rs +++ b/graph/src/schema/input/mod.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use std::sync::Arc; use std::time::Duration; -use anyhow::{anyhow, Error}; +use anyhow::{Error, anyhow}; use semver::Version; use store::Entity; @@ -15,13 +15,13 @@ use crate::components::store::LoadRelatedRequest; use crate::data::graphql::ext::DirectiveFinder; use crate::data::graphql::{DirectiveExt, DocumentExt, ObjectTypeExt, TypeExt, ValueExt}; use crate::data::store::{ - self, EntityValidationError, IdType, IntoEntityIterator, TryIntoEntityIterator, ValueType, ID, + self, EntityValidationError, ID, IdType, IntoEntityIterator, TryIntoEntityIterator, ValueType, }; use crate::data::subgraph::SPEC_VERSION_1_3_0; use crate::data::value::Word; use crate::derive::CheapClone; use crate::prelude::q::Value; -use crate::prelude::{s, DeploymentHash}; +use crate::prelude::{DeploymentHash, s}; use crate::schema::api::api_schema; use crate::util::intern::{Atom, AtomPool}; @@ -1265,7 +1265,7 @@ impl InputSchema { obj_type.interfaces().map(|intf| { let atom = self.inner.pool.lookup(intf).unwrap(); match self.type_info(atom).unwrap() { - TypeInfo::Interface(ref intf_type) => intf_type, + TypeInfo::Interface(intf_type) => intf_type, _ => unreachable!("expected `{intf}` to refer to an interface"), } }) @@ -1745,17 +1745,17 @@ mod validations { use crate::{ data::{ graphql::{ - ext::{DirectiveFinder, FieldExt}, DirectiveExt, DocumentExt, ObjectTypeExt, TypeExt, ValueExt, + ext::{DirectiveFinder, FieldExt}, }, - store::{IdType, ValueType, ID}, + store::{ID, IdType, ValueType}, subgraph::SPEC_VERSION_1_1_0, }, prelude::s, schema::{ - input::{kw, sqlexpr, AggregateFn, AggregationInterval}, - FulltextAlgorithm, FulltextLanguage, Schema as BaseSchema, SchemaValidationError, - SchemaValidationError as Err, Strings, SCHEMA_TYPE_NAME, + FulltextAlgorithm, FulltextLanguage, SCHEMA_TYPE_NAME, Schema as BaseSchema, + SchemaValidationError, SchemaValidationError as Err, Strings, + input::{AggregateFn, AggregationInterval, kw, sqlexpr}, }, }; @@ -1975,7 +1975,7 @@ mod validations { .find(|typ| typ.name[..].eq(entity)) { None => { - return vec![SchemaValidationError::FulltextIncludedEntityNotFound] + return vec![SchemaValidationError::FulltextIncludedEntityNotFound]; } Some(t) => t, }; @@ -2304,7 +2304,7 @@ mod validations { object_type, &field.name, "the @derivedFrom `field` argument must be a string", - )) + )); } }; @@ -2362,11 +2362,11 @@ mod validations { let valid_types = valid_types.join(", "); let msg = format!( - "field `{tf}` on type `{tt}` must have one of the following types: {valid_types}", - tf = target_field.name, - tt = target_type_name, - valid_types = valid_types, - ); + "field `{tf}` on type `{tt}` must have one of the following types: {valid_types}", + tf = target_field.name, + tt = target_type_name, + valid_types = valid_types, + ); return Err(invalid(object_type, &field.name, &msg)); } } @@ -3215,8 +3215,8 @@ mod tests { data::store::ID, prelude::DeploymentHash, schema::{ - input::{POI_DIGEST, POI_OBJECT}, EntityType, + input::{POI_DIGEST, POI_OBJECT}, }, }; diff --git a/graph/src/schema/input/sqlexpr.rs b/graph/src/schema/input/sqlexpr.rs index e32c3373dce..36e250ad15b 100644 --- a/graph/src/schema/input/sqlexpr.rs +++ b/graph/src/schema/input/sqlexpr.rs @@ -236,7 +236,7 @@ impl<'a> VisitExpr<'a> { match pargs { p::FunctionArguments::None => { /* nothing to do */ } p::FunctionArguments::Subquery(_) => { - return self.illegal_function(format!("call to {name} uses a subquery argument")) + return self.illegal_function(format!("call to {name} uses a subquery argument")); } p::FunctionArguments::List(pargs) => { let p::FunctionArgumentList { diff --git a/graph/src/schema/mod.rs b/graph/src/schema/mod.rs index 52a440fc04f..0bcbefb53f3 100644 --- a/graph/src/schema/mod.rs +++ b/graph/src/schema/mod.rs @@ -22,17 +22,17 @@ mod entity_type; mod fulltext; pub(crate) mod input; -pub use api::{is_introspection_field, APISchemaError, INTROSPECTION_QUERY_TYPE}; +pub use api::{APISchemaError, INTROSPECTION_QUERY_TYPE, is_introspection_field}; pub use api::{ApiSchema, ErrorPolicy}; pub use entity_key::EntityKey; pub use entity_type::{AsEntityTypeName, EntityType}; pub use fulltext::{FulltextAlgorithm, FulltextConfig, FulltextDefinition, FulltextLanguage}; -pub use input::sqlexpr::{ExprVisitor, VisitExpr}; pub(crate) use input::POI_OBJECT; +pub use input::sqlexpr::{ExprVisitor, VisitExpr}; pub use input::{ - kw, Aggregate, AggregateFn, Aggregation, AggregationInterval, AggregationMapping, Field, - InputSchema, InterfaceType, ObjectOrInterface, ObjectType, TypeKind, + Aggregate, AggregateFn, Aggregation, AggregationInterval, AggregationMapping, Field, + InputSchema, InterfaceType, ObjectOrInterface, ObjectType, TypeKind, kw, }; pub const SCHEMA_TYPE_NAME: &str = "_Schema_"; @@ -72,7 +72,9 @@ pub enum SchemaValidationError { the following fields: {2}" )] InterfaceFieldsMissing(String, String, Strings), // (type, interface, missing_fields) - #[error("Implementors of interface `{0}` use different id types `{1}`. They must all use the same type")] + #[error( + "Implementors of interface `{0}` use different id types `{1}`. They must all use the same type" + )] InterfaceImplementorsMixId(String, String), #[error("Field `{1}` in type `{0}` has invalid @derivedFrom: {2}")] InvalidDerivedFrom(String, String, String), // (type, field, reason) @@ -90,7 +92,9 @@ pub enum SchemaValidationError { FulltextNameUndefined, #[error("Fulltext directive name overlaps with type: {0}")] FulltextNameConflict(String), - #[error("Fulltext directive name overlaps with an existing entity field or a top-level query field: {0}")] + #[error( + "Fulltext directive name overlaps with an existing entity field or a top-level query field: {0}" + )] FulltextNameCollision(String), #[error("Fulltext language is undefined")] FulltextLanguageUndefined, @@ -122,9 +126,13 @@ pub enum SchemaValidationError { IllegalIdType(String), #[error("Timeseries {0} is missing a `timestamp` field")] TimestampFieldMissing(String), - #[error("Aggregation {0}, field{1}: aggregates must use a numeric type, one of Int, Int8, BigInt, and BigDecimal")] + #[error( + "Aggregation {0}, field{1}: aggregates must use a numeric type, one of Int, Int8, BigInt, and BigDecimal" + )] NonNumericAggregate(String, String), - #[error("Aggregation '{0}', field '{1}': first/last aggregates must use a numeric, byte array, string or a reference type")] + #[error( + "Aggregation '{0}', field '{1}': first/last aggregates must use a numeric, byte array, string or a reference type" + )] InvalidFirstLastAggregate(String, String), #[error("Aggregation {0} is missing the `source` argument")] AggregationMissingSource(String), @@ -148,7 +156,9 @@ pub enum SchemaValidationError { AggregationDerivedField(String, String), #[error("Timeseries {0} is marked as mutable, it must be immutable")] MutableTimeseries(String), - #[error("Entity type `{0}` has skipDuplicates: true but is not immutable; skipDuplicates requires immutable: true")] + #[error( + "Entity type `{0}` has skipDuplicates: true but is not immutable; skipDuplicates requires immutable: true" + )] SkipDuplicatesRequiresImmutable(String), #[error("Timeseries {0} is missing a `timestamp` field")] TimeseriesMissingTimestamp(String), @@ -168,7 +178,9 @@ pub enum SchemaValidationError { AggregationInvalidFn(String, String, String), #[error("Field {1} in aggregation {0} is missing the `fn` argument")] AggregationMissingFn(String, String), - #[error("Field {1} in aggregation {0} is missing the `arg` argument since the function {2} requires it")] + #[error( + "Field {1} in aggregation {0} is missing the `arg` argument since the function {2} requires it" + )] AggregationMissingArg(String, String, String), #[error( "Field {1} in aggregation {0} has `arg` {2} but the source type does not have such a field" @@ -180,11 +192,17 @@ pub enum SchemaValidationError { AggregationNonMatchingArg(String, String, String, String, String), #[error("Field {1} in aggregation {0} has arg `{3}` but that is not a numeric field in {2}")] AggregationNonNumericArg(String, String, String, String), - #[error("Field {1} in aggregation {0} has an invalid value for `cumulative`. It needs to be a boolean")] + #[error( + "Field {1} in aggregation {0} has an invalid value for `cumulative`. It needs to be a boolean" + )] AggregationInvalidCumulative(String, String), - #[error("Aggregations are not supported with spec version {0}; please migrate the subgraph to the latest version")] + #[error( + "Aggregations are not supported with spec version {0}; please migrate the subgraph to the latest version" + )] AggregationsNotSupported(Version), - #[error("Using Int8 as the type for the `id` field is not supported with spec version {0}; please migrate the subgraph to the latest version")] + #[error( + "Using Int8 as the type for the `id` field is not supported with spec version {0}; please migrate the subgraph to the latest version" + )] IdTypeInt8NotSupported(Version), #[error("{0}")] ExprNotSupported(String), @@ -309,7 +327,7 @@ impl Schema { arguments: vec![subgraph_id_argument], }; - if let s::Definition::TypeDefinition(ref mut type_definition) = definition { + if let s::Definition::TypeDefinition(type_definition) = definition { let (name, directives) = match type_definition { s::TypeDefinition::Object(object_type) => { (&object_type.name, &mut object_type.directives) diff --git a/graph/src/util/cache_weight.rs b/graph/src/util/cache_weight.rs index b560906fdc0..d09d8de1e63 100644 --- a/graph/src/util/cache_weight.rs +++ b/graph/src/util/cache_weight.rs @@ -2,7 +2,7 @@ use chrono::{DateTime, TimeZone}; use crate::{ data::value::Word, - prelude::{q, BigDecimal, BigInt, Value}, + prelude::{BigDecimal, BigInt, Value, q}, schema::EntityType, }; use std::{ diff --git a/graph/src/util/futures.rs b/graph/src/util/futures.rs index 01d775bfc6b..593fa4149d0 100644 --- a/graph/src/util/futures.rs +++ b/graph/src/util/futures.rs @@ -2,14 +2,14 @@ use crate::ext::futures::FutureExtension; use futures03::{Future, FutureExt, TryFutureExt}; use lazy_static::lazy_static; use regex::Regex; -use slog::{debug, trace, warn, Logger}; +use slog::{Logger, debug, trace, warn}; use std::fmt::Debug; use std::marker::PhantomData; use std::sync::Arc; use std::time::Duration; use thiserror::Error; -use tokio_retry::strategy::{jitter, ExponentialBackoff}; use tokio_retry::Retry; +use tokio_retry::strategy::{ExponentialBackoff, jitter}; // Use different limits for test and production code to speed up tests #[cfg(debug_assertions)] diff --git a/graph/src/util/herd_cache.rs b/graph/src/util/herd_cache.rs index a469b2d9ac2..88f32ffb861 100644 --- a/graph/src/util/herd_cache.rs +++ b/graph/src/util/herd_cache.rs @@ -1,5 +1,5 @@ -use std::collections::hash_map::Entry; use std::collections::HashMap; +use std::collections::hash_map::Entry; use std::future::Future; use std::pin::Pin; use std::sync::Arc; diff --git a/graph/src/util/intern.rs b/graph/src/util/intern.rs index 884e4cb7e3d..655d71da9e7 100644 --- a/graph/src/util/intern.rs +++ b/graph/src/util/intern.rs @@ -114,10 +114,10 @@ impl AtomPool { /// Get the atom for `word`. Return `None` if the word is not in this /// pool or any of its ancestors. pub fn lookup(&self, word: &str) -> Option { - if let Some(base) = &self.base { - if let Some(atom) = base.lookup(word) { - return Some(atom); - } + if let Some(base) = &self.base + && let Some(atom) = base.lookup(word) + { + return Some(atom); } self.words.get(word).cloned() @@ -510,9 +510,7 @@ impl PartialEq for Object { } } -impl Eq for Object { - fn assert_receiver_is_total_eq(&self) {} -} +impl Eq for Object {} impl Serialize for Object { fn serialize(&self, serializer: S) -> Result diff --git a/graph/src/util/jobs.rs b/graph/src/util/jobs.rs index 438ff72004c..bd5d10b854d 100644 --- a/graph/src/util/jobs.rs +++ b/graph/src/util/jobs.rs @@ -3,9 +3,9 @@ //! to be done on a tight deadline, solely for work that needs to be done //! at reasonably long intervals (like a few hours) -use slog::{debug, info, o, trace, warn, Logger}; -use std::sync::atomic::{AtomicBool, Ordering}; +use slog::{Logger, debug, info, o, trace, warn}; use std::sync::Arc; +use std::sync::atomic::{AtomicBool, Ordering}; use std::time::{Duration, Instant}; use async_trait::async_trait; diff --git a/graph/src/util/mem.rs b/graph/src/util/mem.rs index b98b7d5ed87..02982c962d2 100644 --- a/graph/src/util/mem.rs +++ b/graph/src/util/mem.rs @@ -1,4 +1,4 @@ -use std::mem::{transmute, MaybeUninit}; +use std::mem::{MaybeUninit, transmute}; /// Temporarily needed until MaybeUninit::write_slice is stabilized. pub fn init_slice<'a, T>(src: &[T], dst: &'a mut [MaybeUninit]) -> &'a mut [T] diff --git a/graph/src/util/timed_rw_lock.rs b/graph/src/util/timed_rw_lock.rs index e8ff394be44..17befde8636 100644 --- a/graph/src/util/timed_rw_lock.rs +++ b/graph/src/util/timed_rw_lock.rs @@ -1,5 +1,5 @@ use parking_lot::{Mutex, RwLock}; -use slog::{warn, Logger}; +use slog::{Logger, warn}; use std::time::{Duration, Instant}; use crate::prelude::ENV_VARS; diff --git a/graph/tests/subgraph_datasource_tests.rs b/graph/tests/subgraph_datasource_tests.rs index 366c7bc8d26..9dba0767065 100644 --- a/graph/tests/subgraph_datasource_tests.rs +++ b/graph/tests/subgraph_datasource_tests.rs @@ -2,12 +2,12 @@ use std::{collections::BTreeMap, ops::Range, sync::Arc}; use graph::{ blockchain::{ + Block, SubgraphFilter, Trigger, block_stream::{ EntityOperationKind, EntitySourceOperation, SubgraphTriggerScanRange, TriggersAdapterWrapper, }, mock::MockTriggersAdapter, - Block, SubgraphFilter, Trigger, }, components::store::SourceableStore, data_source::CausalityRegion, diff --git a/graphql/src/execution/ast.rs b/graphql/src/execution/ast.rs index 4f6012dc4ea..cc9eeae5083 100644 --- a/graphql/src/execution/ast.rs +++ b/graphql/src/execution/ast.rs @@ -4,8 +4,8 @@ use graph::{ components::store::{AggregationCurrent, AttributeNames, ChildMultiplicity, EntityOrder}, data::{graphql::ObjectOrInterface, store::ID}, env::ENV_VARS, - prelude::{anyhow, q, r, s, QueryExecutionError, ValueMap}, - schema::{ast::ObjectType, kw, AggregationInterval, ApiSchema, EntityType}, + prelude::{QueryExecutionError, ValueMap, anyhow, q, r, s}, + schema::{AggregationInterval, ApiSchema, EntityType, ast::ObjectType, kw}, }; /// A selection set is a table that maps object types to the fields that diff --git a/graphql/src/execution/cache.rs b/graphql/src/execution/cache.rs index 099fba25f23..de4387ace46 100644 --- a/graphql/src/execution/cache.rs +++ b/graphql/src/execution/cache.rs @@ -1,6 +1,6 @@ -use graph::prelude::{debug, BlockPtr, CheapClone, Logger, QueryResult}; -use std::sync::atomic::{AtomicU64, Ordering}; +use graph::prelude::{BlockPtr, CheapClone, Logger, QueryResult, debug}; use std::sync::Arc; +use std::sync::atomic::{AtomicU64, Ordering}; use std::{collections::HashMap, time::Duration}; use std::{collections::VecDeque, time::Instant}; @@ -107,10 +107,10 @@ impl QueryBlockCache { // - There are none yet, this is the first query being cached, or // - `block_ptr` is of higher or equal number than the most recent block in the cache. // Otherwise this is a historical query that does not belong in the block cache. - if let Some(highest) = cache.iter().next() { - if highest.block.number > block_ptr.number { - return false; - } + if let Some(highest) = cache.iter().next() + && highest.block.number > block_ptr.number + { + return false; }; if cache.len() == self.max_blocks { @@ -164,10 +164,10 @@ impl QueryBlockCache { .map(|(_, c)| c) { // Iterate from the most recent block looking for a block that matches. - if let Some(cache_by_block) = cache.iter().find(|c| &c.block == block_ptr) { - if let Some(response) = cache_by_block.get(key) { - return Some(response.cheap_clone()); - } + if let Some(cache_by_block) = cache.iter().find(|c| &c.block == block_ptr) + && let Some(response) = cache_by_block.get(key) + { + return Some(response.cheap_clone()); } } None diff --git a/graphql/src/execution/execution.rs b/graphql/src/execution/execution.rs index 48477d3eb5f..fa17a47009e 100644 --- a/graphql/src/execution/execution.rs +++ b/graphql/src/execution/execution.rs @@ -7,8 +7,8 @@ use graph::{ value::{Object, Word}, }, futures03::future::TryFutureExt, - prelude::{s, CheapClone}, - schema::{is_introspection_field, INTROSPECTION_QUERY_TYPE, META_FIELD_NAME}, + prelude::{CheapClone, s}, + schema::{INTROSPECTION_QUERY_TYPE, META_FIELD_NAME, is_introspection_field}, util::{herd_cache::HerdCache, lfu_cache::EvictStats, timed_rw_lock::TimedMutex}, }; use lazy_static::lazy_static; @@ -39,11 +39,7 @@ lazy_static! { // We will not add entries to the cache that exceed this weight. static ref MAX_ENTRY_WEIGHT: usize = { - if ENV_VARS.graphql.query_cache_max_entry_ratio == 0 { - usize::MAX - } else { - *MAX_WEIGHT / ENV_VARS.graphql.query_cache_max_entry_ratio - } + MAX_WEIGHT.checked_div(ENV_VARS.graphql.query_cache_max_entry_ratio).unwrap_or(usize::MAX) }; // Sharded query results cache for recent blocks by network. @@ -168,8 +164,8 @@ fn log_lfu_evict_stats( ) { let total_shards = ENV_VARS.graphql.query_lfu_cache_shards as usize; - if total_shards > 0 { - if let Some(EvictStats { + if total_shards > 0 + && let Some(EvictStats { new_weight, evicted_weight, new_count, @@ -179,27 +175,26 @@ fn log_lfu_evict_stats( accesses, hits, }) = evict_stats + { { - { - let shard = (cache_key[0] as usize) % total_shards; - let network = network.to_string(); - let logger = logger.clone(); - - graph::spawn(async move { - debug!(logger, "Evicted LFU cache"; - "shard" => shard, - "network" => network, - "entries" => new_count, - "entries_evicted" => evicted_count, - "weight" => new_weight, - "weight_evicted" => evicted_weight, - "stale_update" => stale_update, - "hit_rate" => format!("{:.0}%", hits as f64 / accesses as f64 * 100.0), - "accesses" => accesses, - "evict_time_ms" => evict_time.as_millis() - ) - }); - } + let shard = (cache_key[0] as usize) % total_shards; + let network = network.to_string(); + let logger = logger.clone(); + + graph::spawn(async move { + debug!(logger, "Evicted LFU cache"; + "shard" => shard, + "network" => network, + "entries" => new_count, + "entries_evicted" => evicted_count, + "weight" => new_weight, + "weight_evicted" => evicted_weight, + "stale_update" => stale_update, + "hit_rate" => format!("{:.0}%", hits as f64 / accesses as f64 * 100.0), + "accesses" => accesses, + "evict_time_ms" => evict_time.as_millis() + ) + }); } } } @@ -336,34 +331,34 @@ pub(crate) async fn execute_root_selection_set( } }; - if should_check_cache { - if let (Some(block_ptr), Some(network)) = (block_ptr.as_ref(), &ctx.query.network) { - // JSONB and metadata queries use `BLOCK_NUMBER_MAX`. Ignore this case for two reasons: - // - Metadata queries are not cacheable. - // - Caching `BLOCK_NUMBER_MAX` would make this cache think all other blocks are old. - if block_ptr.number != BLOCK_NUMBER_MAX { - // Calculate the hash outside of the lock - let cache_key = cache_key(&ctx, &selection_set, block_ptr); - let shard = (cache_key[0] as usize) % QUERY_BLOCK_CACHE.len(); - - // Check if the response is cached, first in the recent blocks cache, - // and then in the LfuCache for historical queries - // The blocks are used to delimit how long locks need to be held - { - let cache = QUERY_BLOCK_CACHE[shard].lock(&ctx.logger); - if let Some(result) = cache.get(network, block_ptr, &cache_key) { - ctx.cache_status.store(CacheStatus::Hit); - return result; - } - } - if let Some(mut cache) = lfu_cache(&ctx.logger, &cache_key) { - if let Some(weighted) = cache.get(&cache_key) { - ctx.cache_status.store(CacheStatus::Hit); - return weighted.result.cheap_clone(); - } + if should_check_cache + && let (Some(block_ptr), Some(network)) = (block_ptr.as_ref(), &ctx.query.network) + { + // JSONB and metadata queries use `BLOCK_NUMBER_MAX`. Ignore this case for two reasons: + // - Metadata queries are not cacheable. + // - Caching `BLOCK_NUMBER_MAX` would make this cache think all other blocks are old. + if block_ptr.number != BLOCK_NUMBER_MAX { + // Calculate the hash outside of the lock + let cache_key = cache_key(&ctx, &selection_set, block_ptr); + let shard = (cache_key[0] as usize) % QUERY_BLOCK_CACHE.len(); + + // Check if the response is cached, first in the recent blocks cache, + // and then in the LfuCache for historical queries + // The blocks are used to delimit how long locks need to be held + { + let cache = QUERY_BLOCK_CACHE[shard].lock(&ctx.logger); + if let Some(result) = cache.get(network, block_ptr, &cache_key) { + ctx.cache_status.store(CacheStatus::Hit); + return result; } - key = Some(cache_key); } + if let Some(mut cache) = lfu_cache(&ctx.logger, &cache_key) + && let Some(weighted) = cache.get(&cache_key) + { + ctx.cache_status.store(CacheStatus::Hit); + return weighted.result.cheap_clone(); + } + key = Some(cache_key); } } @@ -614,7 +609,7 @@ async fn resolve_field_value( .await } - s::Type::NamedType(ref name) => { + s::Type::NamedType(name) => { resolve_field_value_for_named_type( ctx, object_type, @@ -702,7 +697,7 @@ async fn resolve_field_value_for_list_type( .await } - s::Type::NamedType(ref type_name) => { + s::Type::NamedType(type_name) => { let named_type = ctx .query .schema diff --git a/graphql/src/execution/mod.rs b/graphql/src/execution/mod.rs index 9cd5db531df..d51bf6f5a75 100644 --- a/graphql/src/execution/mod.rs +++ b/graphql/src/execution/mod.rs @@ -9,7 +9,7 @@ mod resolver; /// Our representation of a query AST pub mod ast; -use stable_hash_legacy::{crypto::SetHasher, StableHasher}; +use stable_hash_legacy::{StableHasher, crypto::SetHasher}; pub use self::execution::*; pub use self::query::Query; diff --git a/graphql/src/execution/query.rs b/graphql/src/execution/query.rs index 1eb377acafb..c12d68d7fa9 100644 --- a/graphql/src/execution/query.rs +++ b/graphql/src/execution/query.rs @@ -3,7 +3,7 @@ use graph::data::graphql::DocumentExt as _; use graph::data::value::{Object, Word}; use graph::schema::ApiSchema; use graphql_tools::validation::rules::*; -use graphql_tools::validation::validate::{validate, ValidationPlan}; +use graphql_tools::validation::validate::{ValidationPlan, validate}; use lazy_static::lazy_static; use std::collections::{BTreeMap, HashMap, HashSet}; use std::hash::{Hash, Hasher}; @@ -12,15 +12,15 @@ use std::sync::Arc; use std::time::Instant; use std::{collections::hash_map::DefaultHasher, convert::TryFrom}; -use graph::data::graphql::{ext::TypeExt, ObjectOrInterface}; +use graph::data::graphql::{ObjectOrInterface, ext::TypeExt}; use graph::data::query::{Query as GraphDataQuery, QueryVariables}; use graph::data::query::{QueryExecutionError, Trace}; use graph::prelude::{ - info, o, q, r, s, warn, BlockNumber, CheapClone, DeploymentHash, EntityRange, GraphQLMetrics, - Logger, TryFromValue, ENV_VARS, + BlockNumber, CheapClone, DeploymentHash, ENV_VARS, EntityRange, GraphQLMetrics, Logger, + TryFromValue, info, o, q, r, s, warn, }; -use graph::schema::ast::{self as sast}; use graph::schema::ErrorPolicy; +use graph::schema::ast::{self as sast}; use crate::execution::ast as a; use crate::execution::get_field; @@ -224,12 +224,12 @@ impl Query { q::OperationDefinition::Subscription(_) => { return Err(vec![QueryExecutionError::NotSupported( "Subscriptions are not supported".to_owned(), - )]) + )]); } q::OperationDefinition::Mutation(_) => { return Err(vec![QueryExecutionError::NotSupported( "Mutations are not supported".to_owned(), - )]) + )]); } }; @@ -468,13 +468,13 @@ impl<'s> RawQuery<'s> { max_depth: u8, ) -> Result> { let complexity = self.complexity(max_depth).map_err(|e| vec![e])?; - if let Some(max_complexity) = max_complexity { - if complexity > max_complexity { - return Err(vec![QueryExecutionError::TooComplex( - complexity, - max_complexity, - )]); - } + if let Some(max_complexity) = max_complexity + && complexity > max_complexity + { + return Err(vec![QueryExecutionError::TooComplex( + complexity, + max_complexity, + )]); } Ok(complexity) } diff --git a/graphql/src/execution/resolver.rs b/graphql/src/execution/resolver.rs index 6568b7538f8..7e0609e98d4 100644 --- a/graphql/src/execution/resolver.rs +++ b/graphql/src/execution/resolver.rs @@ -4,14 +4,14 @@ use async_trait::async_trait; use graph::components::store::QueryPermit; use graph::data::query::{CacheStatus, Trace}; -use graph::prelude::{s, Error, QueryExecutionError}; +use graph::prelude::{Error, QueryExecutionError, s}; use graph::schema::ApiSchema; use graph::{ data::graphql::ObjectOrInterface, - prelude::{r, QueryResult}, + prelude::{QueryResult, r}, }; -use crate::execution::{ast as a, ExecutionContext}; +use crate::execution::{ExecutionContext, ast as a}; use super::Query; diff --git a/graphql/src/introspection/resolver.rs b/graphql/src/introspection/resolver.rs index 5ce1385abbd..39ead572448 100644 --- a/graphql/src/introspection/resolver.rs +++ b/graphql/src/introspection/resolver.rs @@ -4,12 +4,12 @@ use graph::data::graphql::ext::{FieldExt, TypeDefinitionExt}; use graph::data::query::Trace; use std::collections::BTreeMap; -use graph::data::graphql::{object, DocumentExt, ObjectOrInterface}; +use graph::data::graphql::{DocumentExt, ObjectOrInterface, object}; use graph::prelude::*; use crate::execution::ast as a; use crate::prelude::*; -use graph::schema::{ast as sast, Schema}; +use graph::schema::{Schema, ast as sast}; type TypeObjectsMap = BTreeMap; @@ -34,8 +34,8 @@ fn type_object(schema: &Schema, type_objects: &mut TypeObjectsMap, t: &s::Type) match t { // We store the name of the named type here to be able to resolve it dynamically later s::Type::NamedType(s) => r::Value::String(s.clone()), - s::Type::ListType(ref inner) => list_type_object(schema, type_objects, inner), - s::Type::NonNullType(ref inner) => non_null_type_object(schema, type_objects, inner), + s::Type::ListType(inner) => list_type_object(schema, type_objects, inner), + s::Type::NonNullType(inner) => non_null_type_object(schema, type_objects, inner), } } @@ -391,7 +391,7 @@ impl Resolver for IntrospectionResolver { type_names .iter() .filter_map(|type_name| match type_name { - r::Value::String(ref type_name) => Some(type_name), + r::Value::String(type_name) => Some(type_name), _ => None, }) .filter_map(|type_name| self.type_objects.get(type_name).cloned()) diff --git a/graphql/src/lib.rs b/graphql/src/lib.rs index 03626eb907e..9869d0a5344 100644 --- a/graphql/src/lib.rs +++ b/graphql/src/lib.rs @@ -21,9 +21,9 @@ mod metrics; /// Prelude that exports the most important traits and types. pub mod prelude { - pub use super::execution::{ast as a, ExecutionContext, Query, Resolver}; + pub use super::execution::{ExecutionContext, Query, Resolver, ast as a}; pub use super::introspection::IntrospectionResolver; - pub use super::query::{execute_query, ext::BlockConstraint, QueryExecutionOptions}; + pub use super::query::{QueryExecutionOptions, execute_query, ext::BlockConstraint}; pub use super::store::StoreResolver; pub use super::values::MaybeCoercible; diff --git a/graphql/src/query/ext.rs b/graphql/src/query/ext.rs index 4abca7a4b6c..c57c35c5392 100644 --- a/graphql/src/query/ext.rs +++ b/graphql/src/query/ext.rs @@ -7,7 +7,7 @@ use std::collections::{BTreeMap, HashMap}; use anyhow::anyhow; use graph::data::query::QueryExecutionError; -use graph::prelude::{q, r, BlockNumber, Error}; +use graph::prelude::{BlockNumber, Error, q, r}; pub trait ValueExt: Sized { fn as_object(&self) -> &BTreeMap; diff --git a/graphql/src/runner.rs b/graphql/src/runner.rs index 293dcaa111b..9d6d1fb1017 100644 --- a/graphql/src/runner.rs +++ b/graphql/src/runner.rs @@ -9,11 +9,11 @@ use crate::query::execute_query; use graph::data::query::{CacheStatus, SqlQueryReq}; use graph::data::store::SqlQueryObject; use graph::futures03::future; +use graph::prelude::{ApiVersion, MetricsRegistry}; use graph::prelude::{ - o, CheapClone, DeploymentState, GraphQLMetrics as GraphQLMetricsTrait, - GraphQlRunner as GraphQlRunnerTrait, Logger, Query, QueryExecutionError, ENV_VARS, + CheapClone, DeploymentState, ENV_VARS, GraphQLMetrics as GraphQLMetricsTrait, + GraphQlRunner as GraphQlRunnerTrait, Logger, Query, QueryExecutionError, o, }; -use graph::prelude::{ApiVersion, MetricsRegistry}; use graph::{data::graphql::load_manager::LoadManager, prelude::QueryStoreManager}; use graph::{ data::query::{LatestBlockInfo, QueryResults, QueryTarget}, diff --git a/graphql/src/store/prefetch.rs b/graphql/src/store/prefetch.rs index c23a475a08a..e9a04c8c97b 100644 --- a/graphql/src/store/prefetch.rs +++ b/graphql/src/store/prefetch.rs @@ -9,7 +9,7 @@ use graph::data::store::IdList; use graph::data::store::IdType; use graph::data::store::QueryObject; use graph::data::value::{Object, Word}; -use graph::prelude::{r, CacheWeight, CheapClone}; +use graph::prelude::{CacheWeight, CheapClone, r}; use graph::schema::AggregationInterval; use graph::schema::Field; use graph::slog::warn; @@ -20,15 +20,16 @@ use std::time::Instant; use graph::data::graphql::TypeExt; use graph::prelude::{ - AttributeNames, ChildMultiplicity, EntityCollection, EntityFilter, EntityLink, EntityOrder, - EntityWindow, ParentLink, QueryExecutionError, Value as StoreValue, WindowAttribute, ENV_VARS, + AttributeNames, ChildMultiplicity, ENV_VARS, EntityCollection, EntityFilter, EntityLink, + EntityOrder, EntityWindow, ParentLink, QueryExecutionError, Value as StoreValue, + WindowAttribute, }; use graph::schema::{EntityType, InputSchema, ObjectOrInterface}; use crate::execution::ast as a; use crate::metrics::GraphQLMetrics; -use crate::store::query::build_query; use crate::store::StoreResolver; +use crate::store::query::build_query; pub const ARG_ID: &str = "id"; @@ -597,11 +598,11 @@ impl<'a> Loader<'a> { // Process all field groups in order for (object_type, fields) in selection_set.interior_fields() { - if let Some(deadline) = self.ctx.deadline { - if deadline < Instant::now() { - errors.push(QueryExecutionError::Timeout); - break; - } + if let Some(deadline) = self.ctx.deadline + && deadline < Instant::now() + { + errors.push(QueryExecutionError::Timeout); + break; } // Filter out parents that do not match the type condition. diff --git a/graphql/src/store/query.rs b/graphql/src/store/query.rs index 855b83b409a..f893663b258 100644 --- a/graphql/src/store/query.rs +++ b/graphql/src/store/query.rs @@ -10,7 +10,7 @@ use graph::data::query::QueryExecutionError; use graph::data::store::{Attribute, Value, ValueType}; use graph::data::value::Object; use graph::data::value::Value as DataValue; -use graph::prelude::{r, TryFromValue, ENV_VARS}; +use graph::prelude::{ENV_VARS, TryFromValue, r}; use graph::schema::ast::{self as sast, FilterOp}; use graph::schema::kw; use graph::schema::{EntityType, InputSchema, ObjectOrInterface}; @@ -258,9 +258,7 @@ fn build_filter_from_object( let filter_list = column_filters.join(", "); let example = format!( "Instead of:\nwhere: {{ {}, or: [...] }}\n\nUse:\nwhere: {{ or: [{{ {}, ... }}, {{ {}, ... }}] }}", - filter_list, - filter_list, - filter_list + filter_list, filter_list, filter_list ); return Err(QueryExecutionError::InvalidOrFilterStructure( column_filters, @@ -695,10 +693,9 @@ mod tests { data::value::Object, prelude::lazy_static, prelude::{ - r, + AttributeNames, BLOCK_NUMBER_MAX, DeploymentHash, EntityCollection, EntityFilter, + EntityOrder, EntityRange, Value, ValueType, r, s::{self, Directive, Field, InputValue, ObjectType, Type, Value as SchemaValue}, - AttributeNames, DeploymentHash, EntityCollection, EntityFilter, EntityOrder, - EntityRange, Value, ValueType, BLOCK_NUMBER_MAX, }, schema::{EntityType, InputSchema}, }; @@ -1218,7 +1215,9 @@ mod tests { assert!(example.contains("Instead of:")); assert!(example.contains("where: { 'name_gt', or: [...] }")); assert!(example.contains("Use:")); - assert!(example.contains("where: { or: [{ 'name_gt', ... }, { 'name_gt', ... }] }")); + assert!( + example.contains("where: { or: [{ 'name_gt', ... }, { 'name_gt', ... }] }") + ); } _ => panic!("Expected InvalidOrFilterStructure error, got: {}", error), } @@ -1247,7 +1246,9 @@ mod tests { assert!(error_msg.contains("Instead of:")); assert!(error_msg.contains("Use:")); assert!(error_msg.contains("where: { 'age_gt', 'name', or: [...] }")); - assert!(error_msg - .contains("where: { or: [{ 'age_gt', 'name', ... }, { 'age_gt', 'name', ... }] }")); + assert!( + error_msg + .contains("where: { or: [{ 'age_gt', 'name', ... }, { 'age_gt', 'name', ... }] }") + ); } } diff --git a/graphql/src/store/resolver.rs b/graphql/src/store/resolver.rs index 779a9766fe7..6f9548e7037 100644 --- a/graphql/src/store/resolver.rs +++ b/graphql/src/store/resolver.rs @@ -5,20 +5,20 @@ use async_trait::async_trait; use graph::components::graphql::GraphQLMetrics as _; use graph::components::store::QueryPermit; use graph::data::graphql::load_manager::LoadManager; -use graph::data::graphql::{object, ObjectOrInterface}; +use graph::data::graphql::{ObjectOrInterface, object}; use graph::data::query::{CacheStatus, QueryResults, Trace}; use graph::data::store::ID; use graph::data::value::{Object, Word}; use graph::derive::CheapClone; use graph::prelude::alloy::primitives::B256; use graph::prelude::*; +use graph::schema::{BLOCK_FIELD_TYPE, ErrorPolicy}; use graph::schema::{ - ast as sast, INTROSPECTION_SCHEMA_FIELD_NAME, INTROSPECTION_TYPE_FIELD_NAME, META_FIELD_NAME, - META_FIELD_TYPE, + INTROSPECTION_SCHEMA_FIELD_NAME, INTROSPECTION_TYPE_FIELD_NAME, META_FIELD_NAME, + META_FIELD_TYPE, ast as sast, }; -use graph::schema::{ErrorPolicy, BLOCK_FIELD_TYPE}; -use crate::execution::{ast as a, Query}; +use crate::execution::{Query, ast as a}; use crate::metrics::GraphQLMetrics; use crate::prelude::{ExecutionContext, Resolver}; use crate::query::ext::BlockConstraint; @@ -329,8 +329,11 @@ impl Resolver for StoreResolver { let child1_id = child_id(&children[1]); QueryExecutionError::InternalError(format!( "expected only one child for {}.{} but got {}. One child has id {}, another has id {}", - object_type.name(), field.name, - children.len(), child0_id, child1_id + object_type.name(), + field.name, + children.len(), + child0_id, + child1_id )) } }; diff --git a/graphql/src/values/coercion.rs b/graphql/src/values/coercion.rs index 9d85059b33c..bd0bacbf677 100644 --- a/graphql/src/values/coercion.rs +++ b/graphql/src/values/coercion.rs @@ -1,6 +1,6 @@ use graph::data::store::scalar::Timestamp; use graph::prelude::s::{EnumType, InputValue, ScalarType, Type, TypeDefinition}; -use graph::prelude::{q, r, QueryExecutionError}; +use graph::prelude::{QueryExecutionError, q, r}; use graph::schema; use std::collections::BTreeMap; use std::convert::TryFrom; diff --git a/node/src/bin/manager.rs b/node/src/bin/manager.rs index a3e8216410c..42f86730b8e 100644 --- a/node/src/bin/manager.rs +++ b/node/src/bin/manager.rs @@ -8,12 +8,13 @@ use graph::components::network_provider::ChainName; use graph::endpoint::EndpointMetrics; use graph::env::ENV_VARS; use graph::log::logger_with_levels; -use graph::prelude::{BlockNumber, MetricsRegistry, BLOCK_NUMBER_MAX}; +use graph::prelude::{BLOCK_NUMBER_MAX, BlockNumber, MetricsRegistry}; use graph::{data::graphql::load_manager::LoadManager, prelude::chrono, prometheus::Registry}; use graph::{ prelude::{ - anyhow::{self, anyhow, Context as AnyhowContextTrait}, - info, tokio, Logger, NodeId, + Logger, NodeId, + anyhow::{self, Context as AnyhowContextTrait, anyhow}, + info, tokio, }, url::Url, }; @@ -24,11 +25,11 @@ use graph_node::manager::color::Terminal; use graph_node::manager::commands; use graph_node::network_setup::Networks; use graph_node::{ - manager::deployment::DeploymentSearch, store_builder::StoreBuilder, MetricsContext, + MetricsContext, manager::deployment::DeploymentSearch, store_builder::StoreBuilder, }; use graph_store_postgres::{ - BlockStore, ChainStore, ConnectionPool, NotificationSender, PoolCoordinator, Shard, Store, - SubgraphStore, SubscriptionManager, PRIMARY_SHARD, + BlockStore, ChainStore, ConnectionPool, NotificationSender, PRIMARY_SHARD, PoolCoordinator, + Shard, Store, SubgraphStore, SubscriptionManager, }; use itertools::Itertools; use lazy_static::lazy_static; @@ -1133,7 +1134,9 @@ impl Context { #[tokio::main] async fn main() -> anyhow::Result<()> { // Disable load management for graphman commands - env::set_var("GRAPH_LOAD_THRESHOLD", "0"); + unsafe { + env::set_var("GRAPH_LOAD_THRESHOLD", "0"); + } let opt = Opt::parse(); @@ -1499,8 +1502,8 @@ async fn main() -> anyhow::Result<()> { } CheckBlocks { method, chain_name } => { - use commands::check_blocks::{by_hash, by_number, by_range}; use CheckBlockMethod::*; + use commands::check_blocks::{by_hash, by_number, by_range}; let logger = ctx.logger.clone(); let (chain_store, ethereum_adapter) = ctx.chain_store_and_adapter(&chain_name).await?; @@ -1563,7 +1566,9 @@ async fn main() -> anyhow::Result<()> { } if !remove_entire_cache && from.is_none() && to.is_none() { - bail!("you must specify either --from and --to or --remove-entire-cache"); + bail!( + "you must specify either --from and --to or --remove-entire-cache" + ); } let (from, to) = if remove_entire_cache { (0, BLOCK_NUMBER_MAX) diff --git a/node/src/chain.rs b/node/src/chain.rs index 2e52d966311..824cbf5faeb 100644 --- a/node/src/chain.rs +++ b/node/src/chain.rs @@ -2,13 +2,13 @@ use crate::config::{ChainSettings as ConfigChainSettings, Config, ProviderDetail use crate::network_setup::{ AdapterConfiguration, EthAdapterConfig, FirehoseAdapterConfig, Networks, }; +use ethereum::ProviderEthRpcMetrics; use ethereum::chain::ChainSettings; use ethereum::chain::{ EthereumAdapterSelector, EthereumBlockRefetcher, EthereumRuntimeAdapterBuilder, EthereumStreamBuilder, }; use ethereum::network::EthereumNetworkAdapter; -use ethereum::ProviderEthRpcMetrics; use graph::anyhow::bail; use graph::blockchain::client::ChainClient; use graph::blockchain::{BlockchainKind, BlockchainMap, ChainIdentifier}; @@ -16,14 +16,14 @@ use graph::cheap_clone::CheapClone; use graph::components::network_provider::ChainName; use graph::components::store::BlockStore as _; use graph::endpoint::EndpointMetrics; -use graph::env::{EnvVars, ENV_VARS}; +use graph::env::{ENV_VARS, EnvVars}; use graph::firehose::FirehoseEndpoint; use graph::futures03::future::try_join_all; use graph::itertools::Itertools; use graph::log::factory::LoggerFactory; -use graph::prelude::anyhow; use graph::prelude::MetricsRegistry; -use graph::slog::{debug, info, o, warn, Logger}; +use graph::prelude::anyhow; +use graph::slog::{Logger, debug, info, o, warn}; use graph::url::Url; use graph_chain_ethereum::{self as ethereum, Transport}; use graph_store_postgres::{BlockStore, ChainHeadUpdateListener}; @@ -356,7 +356,12 @@ pub async fn networks_as_chains( { Ok(Ok(ident)) => ident, err => { - warn!(&logger, "unable to fetch genesis for {}. Err: {:?}.falling back to the default value", chain_id, err); + warn!( + &logger, + "unable to fetch genesis for {}. Err: {:?}.falling back to the default value", + chain_id, + err + ); ChainIdentifier::default() } }; diff --git a/node/src/config.rs b/node/src/config.rs index 1da6ce6cd05..1b932b247e5 100644 --- a/node/src/config.rs +++ b/node/src/config.rs @@ -6,22 +6,23 @@ use graph::{ store::BLOCK_CACHE_SIZE, }, env::ENV_VARS, - firehose::{SubgraphLimit, SUBGRAPHS_PER_CONN}, + firehose::{SUBGRAPHS_PER_CONN, SubgraphLimit}, itertools::Itertools, prelude::{ - anyhow::{anyhow, bail, Context, Result}, + BLOCK_NUMBER_MAX, Logger, NodeId, StoreError, + anyhow::{Context, Result, anyhow, bail}, info, regex::Regex, serde::{ - de::{self, value, SeqAccess, Visitor}, Deserialize, Deserializer, + de::{self, SeqAccess, Visitor, value}, }, - serde_json, serde_regex, toml, Logger, NodeId, StoreError, BLOCK_NUMBER_MAX, + serde_json, serde_regex, toml, }, }; use graph_chain_ethereum as ethereum; use graph_chain_ethereum::{Compression, NodeCapabilities}; -use graph_store_postgres::{DeploymentPlacer, Shard as ShardName, PRIMARY_SHARD}; +use graph_store_postgres::{DeploymentPlacer, PRIMARY_SHARD, Shard as ShardName}; use graph::http::{HeaderMap, Uri}; use serde::Serialize; @@ -517,19 +518,19 @@ impl ChainSection { } // Check that an explicit amp alias doesn't collide with // another chain's own name (which would be ambiguous). - if chain.amp.is_some() { - if let Some(other) = self.chains.get(effective) { - // Only a collision if the other chain doesn't also - // set the same amp alias (which is covered by the - // duplicate check above). - if other.amp.as_deref() != Some(effective) { - return Err(anyhow!( - "AMP alias `{}` on chain `{}` collides with chain `{}`", - effective, - chain_name, - effective, - )); - } + if chain.amp.is_some() + && let Some(other) = self.chains.get(effective) + { + // Only a collision if the other chain doesn't also + // set the same amp alias (which is covered by the + // duplicate check above). + if other.amp.as_deref() != Some(effective) { + return Err(anyhow!( + "AMP alias `{}` on chain `{}` collides with chain `{}`", + effective, + chain_name, + effective, + )); } } amp_names.insert(effective.to_string(), chain_name.clone()); @@ -1134,7 +1135,9 @@ impl<'de> Deserialize<'de> for Provider { || features.is_some() || headers.is_some() { - return Err(serde::de::Error::custom("when `details` field is provided, deprecated `url`, `transport`, `features` and `headers` cannot be specified")); + return Err(serde::de::Error::custom( + "when `details` field is provided, deprecated `url`, `transport`, `features` and `headers` cannot be specified", + )); } if let ProviderDetails::Firehose(ref mut firehose) = v { @@ -1324,10 +1327,10 @@ impl Predicate { } pub fn matches(&self, name: &str, network: &str) -> bool { - if let Some(n) = &self.network { - if !n.matches(network) { - return false; - } + if let Some(n) = &self.network + && !n.matches(network) + { + return false; } match self.name.find(name) { @@ -1507,11 +1510,11 @@ mod tests { use std::time::Duration; use crate::config::{ - default_block_batch_size, default_block_ingestor_max_concurrent_json_rpc_calls, - default_block_ptr_batch_size, default_genesis_block_number, default_get_logs_max_contracts, - default_json_rpc_timeout, default_max_block_range_size, default_max_event_only_range, - default_polling_interval, default_request_retries, default_target_triggers_per_block_range, - ChainSection, Web3Rule, + ChainSection, Web3Rule, default_block_batch_size, + default_block_ingestor_max_concurrent_json_rpc_calls, default_block_ptr_batch_size, + default_genesis_block_number, default_get_logs_max_contracts, default_json_rpc_timeout, + default_max_block_range_size, default_max_event_only_range, default_polling_interval, + default_request_retries, default_target_triggers_per_block_range, }; use super::{ @@ -1522,7 +1525,7 @@ mod tests { use graph::firehose::SubgraphLimit; use graph::http::{HeaderMap, HeaderValue}; use graph::prelude::regex::Regex; - use graph::prelude::{toml, NodeId}; + use graph::prelude::{NodeId, toml}; use graph_chain_ethereum::Compression; use std::collections::BTreeSet; use std::fs::read_to_string; @@ -1886,9 +1889,11 @@ mod tests { assert!(actual.is_err(), "{:?}", actual); if let Err(error) = actual { - assert!(error - .to_string() - .starts_with("supported firehose endpoint filters are:")) + assert!( + error + .to_string() + .starts_with("supported firehose endpoint filters are:") + ) } } diff --git a/node/src/helpers.rs b/node/src/helpers.rs index 7b2e81335f8..2cef6c70eb7 100644 --- a/node/src/helpers.rs +++ b/node/src/helpers.rs @@ -4,7 +4,7 @@ use anyhow::Result; use graph::prelude::{ BlockPtr, DeploymentHash, NodeId, SubgraphRegistrarError, SubgraphStore as SubgraphStoreTrait, }; -use graph::slog::{error, info, Logger}; +use graph::slog::{Logger, error, info}; use graph::{ components::store::DeploymentLocator, prelude::{SubgraphName, SubgraphRegistrar}, diff --git a/node/src/launcher.rs b/node/src/launcher.rs index 85127f0d474..fba98e0bbf2 100644 --- a/node/src/launcher.rs +++ b/node/src/launcher.rs @@ -20,15 +20,15 @@ use graph::{ blockchain::{Blockchain, BlockchainKind, BlockchainMap}, components::network_provider::AmpChainNames, }; -use graph_core::polling_monitor::{arweave_service, ArweaveService, IpfsService}; +use graph_core::polling_monitor::{ArweaveService, IpfsService, arweave_service}; use graph_graphql::prelude::GraphQlRunner; use graph_server_http::GraphQLServer as GraphQLQueryServer; use graph_server_index_node::IndexNodeServer; use graph_server_json_rpc::JsonRpcServer; use graph_server_metrics::PrometheusMetricsServer; use graph_store_postgres::{ - register_jobs as register_store_jobs, ChainHeadUpdateListener, ConnectionPool, - NotificationSender, Store, SubgraphStore, SubscriptionManager, + ChainHeadUpdateListener, ConnectionPool, NotificationSender, Store, SubgraphStore, + SubscriptionManager, register_jobs as register_store_jobs, }; use graphman_server::GraphmanServer; use graphman_server::GraphmanServerConfig; @@ -692,25 +692,28 @@ fn spawn_contention_checker(logger: Logger) { } panic!("ping sender dropped"); }); - std::thread::spawn(move || loop { - std::thread::sleep(Duration::from_secs(1)); - let (pong_send, pong_receive) = std::sync::mpsc::sync_channel(1); - if graph::futures03::executor::block_on(ping_send.clone().send(pong_send)).is_err() { - debug!(logger, "Shutting down contention checker thread"); - break; - } - let mut timeout = Duration::from_millis(10); - while pong_receive.recv_timeout(timeout) == Err(std::sync::mpsc::RecvTimeoutError::Timeout) - { - debug!(logger, "Possible contention in tokio threadpool"; + std::thread::spawn(move || { + loop { + std::thread::sleep(Duration::from_secs(1)); + let (pong_send, pong_receive) = std::sync::mpsc::sync_channel(1); + if graph::futures03::executor::block_on(ping_send.clone().send(pong_send)).is_err() { + debug!(logger, "Shutting down contention checker thread"); + break; + } + let mut timeout = Duration::from_millis(10); + while pong_receive.recv_timeout(timeout) + == Err(std::sync::mpsc::RecvTimeoutError::Timeout) + { + debug!(logger, "Possible contention in tokio threadpool"; "timeout_ms" => timeout.as_millis(), "code" => LogCode::TokioContention); - if timeout < ENV_VARS.kill_if_unresponsive_timeout { - timeout *= 10; - } else if ENV_VARS.kill_if_unresponsive { - // The node is unresponsive, kill it in hopes it will be restarted. - crit!(logger, "Node is unresponsive, killing process"); - std::process::abort() + if timeout < ENV_VARS.kill_if_unresponsive_timeout { + timeout *= 10; + } else if ENV_VARS.kill_if_unresponsive { + // The node is unresponsive, kill it in hopes it will be restarted. + crit!(logger, "Node is unresponsive, killing process"); + std::process::abort() + } } } }); diff --git a/node/src/manager/commands/assign.rs b/node/src/manager/commands/assign.rs index c5f451281be..3787145fb29 100644 --- a/node/src/manager/commands/assign.rs +++ b/node/src/manager/commands/assign.rs @@ -1,6 +1,6 @@ use graph::components::store::DeploymentLocator; -use graph::prelude::{anyhow::anyhow, Error, NodeId, StoreEvent}; -use graph_store_postgres::{command_support::catalog, ConnectionPool, NotificationSender}; +use graph::prelude::{Error, NodeId, StoreEvent, anyhow::anyhow}; +use graph_store_postgres::{ConnectionPool, NotificationSender, command_support::catalog}; use std::time::Duration; use tokio; diff --git a/node/src/manager/commands/chain.rs b/node/src/manager/commands/chain.rs index 3943861fe56..2f344bdeb7b 100644 --- a/node/src/manager/commands/chain.rs +++ b/node/src/manager/commands/chain.rs @@ -19,18 +19,18 @@ use graph::{ components::store::BlockStore as _, components::store::ChainHeadStore as _, prelude::anyhow::Error, }; -use graph_chain_ethereum::chain::BlockFinality; use graph_chain_ethereum::EthereumAdapter; use graph_chain_ethereum::EthereumAdapterTrait as _; -use graph_store_postgres::add_chain; -use graph_store_postgres::find_chain; -use graph_store_postgres::update_chain_name; +use graph_chain_ethereum::chain::BlockFinality; use graph_store_postgres::BlockStore; use graph_store_postgres::ChainStore; use graph_store_postgres::PoolCoordinator; use graph_store_postgres::ScopedFutureExt; use graph_store_postgres::Shard; -use graph_store_postgres::{command_support::catalog::block_store, ConnectionPool}; +use graph_store_postgres::add_chain; +use graph_store_postgres::find_chain; +use graph_store_postgres::update_chain_name; +use graph_store_postgres::{ConnectionPool, command_support::catalog::block_store}; use crate::network_setup::Networks; diff --git a/node/src/manager/commands/check_blocks.rs b/node/src/manager/commands/check_blocks.rs index dc6b2e0aee1..d7014bd4b1c 100644 --- a/node/src/manager/commands/check_blocks.rs +++ b/node/src/manager/commands/check_blocks.rs @@ -8,7 +8,7 @@ use graph::{ }, prelude::{ alloy::primitives::B256, - anyhow::{self, anyhow, Context}, + anyhow::{self, Context, anyhow}, }, slog::Logger, }; @@ -165,7 +165,7 @@ mod steps { serde_json::{self, Value}, }, }; - use json_structural_diff::{colorize as diff_to_string, JsonDiff}; + use json_structural_diff::{JsonDiff, colorize as diff_to_string}; /// Queries the [`ChainStore`] about the block hash for the given block number. /// diff --git a/node/src/manager/commands/config.rs b/node/src/manager/commands/config.rs index 08633ae586d..35ee9ed573a 100644 --- a/node/src/manager/commands/config.rs +++ b/node/src/manager/commands/config.rs @@ -2,14 +2,14 @@ use std::{collections::BTreeMap, sync::Arc}; use graph::components::network_provider::ChainName; use graph::{ - anyhow::{bail, Context}, + anyhow::{Context, bail}, components::subgraph::{Setting, Settings}, endpoint::EndpointMetrics, env::EnvVars, itertools::Itertools, prelude::{ - anyhow::{anyhow, Error}, MetricsRegistry, NodeId, SubgraphName, + anyhow::{Error, anyhow}, }, slog::Logger, }; diff --git a/node/src/manager/commands/copy.rs b/node/src/manager/commands/copy.rs index 0d43f74f61d..9d158dcd231 100644 --- a/node/src/manager/commands/copy.rs +++ b/node/src/manager/commands/copy.rs @@ -6,19 +6,20 @@ use graph::{ components::store::{BlockStore as _, DeploymentId, DeploymentLocator}, data::query::QueryTarget, prelude::{ - anyhow::{anyhow, bail, Error}, - chrono::{DateTime, Duration, SecondsFormat, Utc}, BlockPtr, ChainStore, DeploymentHash, NodeId, QueryStoreManager, + anyhow::{Error, anyhow, bail}, + chrono::{DateTime, Duration, SecondsFormat, Utc}, }, }; +use graph_store_postgres::{ConnectionPool, Shard, Store, SubgraphStore}; use graph_store_postgres::{ + PRIMARY_SHARD, command_support::{ + OnSync, catalog::{self, copy_state, copy_table_state}, - on_sync, OnSync, + on_sync, }, - PRIMARY_SHARD, }; -use graph_store_postgres::{ConnectionPool, Shard, Store, SubgraphStore}; use crate::manager::display::List; use crate::manager::{deployment::DeploymentSearch, fmt}; @@ -120,7 +121,8 @@ async fn create_inner( .ok_or_else(|| anyhow!("subgraph {} has not indexed any blocks yet and can not be used as the source of a copy", src))?; if src_ptr.number <= block_offset { - bail!("subgraph {} has only indexed up to block {}, but we need at least block {} before we can copy from it", + bail!( + "subgraph {} has only indexed up to block {}, but we need at least block {} before we can copy from it", src, src_ptr.number, block_offset diff --git a/node/src/manager/commands/create.rs b/node/src/manager/commands/create.rs index db75e28d5c1..8ab34a0d487 100644 --- a/node/src/manager/commands/create.rs +++ b/node/src/manager/commands/create.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use graph::prelude::{anyhow, Error, SubgraphName, SubgraphStore as _}; +use graph::prelude::{Error, SubgraphName, SubgraphStore as _, anyhow}; use graph_store_postgres::SubgraphStore; pub async fn run(store: Arc, name: String) -> Result<(), Error> { diff --git a/node/src/manager/commands/database.rs b/node/src/manager/commands/database.rs index 56df0a73f27..69c7ad932af 100644 --- a/node/src/manager/commands/database.rs +++ b/node/src/manager/commands/database.rs @@ -16,15 +16,15 @@ pub async fn remap( }; let servers = coord.servers(); - if let Some(src) = &src { - if !servers.iter().any(|srv| srv.shard.as_str() == src) { - return Err(anyhow!("unknown source shard {src}")); - } + if let Some(src) = &src + && !servers.iter().any(|srv| srv.shard.as_str() == src) + { + return Err(anyhow!("unknown source shard {src}")); } - if let Some(dst) = &dst { - if !pools.iter().any(|pool| pool.shard.as_str() == dst) { - return Err(anyhow!("unknown destination shard {dst}")); - } + if let Some(dst) = &dst + && !pools.iter().any(|pool| pool.shard.as_str() == dst) + { + return Err(anyhow!("unknown destination shard {dst}")); } let servers = servers.iter().filter(|srv| match &src { diff --git a/node/src/manager/commands/deploy.rs b/node/src/manager/commands/deploy.rs index 15ddc6b1049..603d09b63ca 100644 --- a/node/src/manager/commands/deploy.rs +++ b/node/src/manager/commands/deploy.rs @@ -1,10 +1,10 @@ use std::sync::Arc; use graph::prelude::{ - anyhow::{anyhow, bail, Result}, - reqwest, - serde_json::{json, Value}, SubgraphName, SubgraphStore, + anyhow::{Result, anyhow, bail}, + reqwest, + serde_json::{Value, json}, }; use crate::manager::deployment::DeploymentSearch; diff --git a/node/src/manager/commands/deployment/info.rs b/node/src/manager/commands/deployment/info.rs index 08e8f1c517d..14151664bda 100644 --- a/node/src/manager/commands/deployment/info.rs +++ b/node/src/manager/commands/deployment/info.rs @@ -3,13 +3,13 @@ use std::collections::HashMap; use std::io; use std::sync::Arc; -use anyhow::bail; use anyhow::Result; +use anyhow::bail; use graph_store_postgres::ConnectionPool; use graph_store_postgres::Store; +use graphman::commands::deployment::info::DeploymentStatus; use graphman::commands::deployment::info::load_deployment_statuses; use graphman::commands::deployment::info::load_deployments; -use graphman::commands::deployment::info::DeploymentStatus; use graphman::deployment::Deployment; use graphman::deployment::DeploymentSelector; use graphman::deployment::DeploymentVersionSelector; diff --git a/node/src/manager/commands/deployment/pause.rs b/node/src/manager/commands/deployment/pause.rs index 2b91680a0f3..2dd913df300 100644 --- a/node/src/manager/commands/deployment/pause.rs +++ b/node/src/manager/commands/deployment/pause.rs @@ -4,7 +4,7 @@ use anyhow::Result; use graph_store_postgres::ConnectionPool; use graph_store_postgres::NotificationSender; use graphman::commands::deployment::pause::{ - load_active_deployment, pause_active_deployment, PauseDeploymentError, + PauseDeploymentError, load_active_deployment, pause_active_deployment, }; use graphman::deployment::DeploymentSelector; diff --git a/node/src/manager/commands/deployment/reassign.rs b/node/src/manager/commands/deployment/reassign.rs index da8341422c4..abd35f42700 100644 --- a/node/src/manager/commands/deployment/reassign.rs +++ b/node/src/manager/commands/deployment/reassign.rs @@ -5,7 +5,7 @@ use graph::prelude::NodeId; use graph_store_postgres::ConnectionPool; use graph_store_postgres::NotificationSender; use graphman::commands::deployment::reassign::{ - load_deployment, reassign_deployment, ReassignResult, + ReassignResult, load_deployment, reassign_deployment, }; use graphman::deployment::DeploymentSelector; diff --git a/node/src/manager/commands/index.rs b/node/src/manager/commands/index.rs index 6a5370895e5..0dc876eb66a 100644 --- a/node/src/manager/commands/index.rs +++ b/node/src/manager/commands/index.rs @@ -1,12 +1,12 @@ -use crate::manager::{color::Terminal, deployment::DeploymentSearch, CmdResult}; +use crate::manager::{CmdResult, color::Terminal, deployment::DeploymentSearch}; use graph::{ components::store::DeploymentLocator, itertools::Itertools, - prelude::{anyhow, StoreError}, + prelude::{StoreError, anyhow}, }; use graph_store_postgres::{ - command_support::index::{CreateIndex, Method}, ConnectionPool, SubgraphStore, + command_support::index::{CreateIndex, Method}, }; use std::io::Write as _; use std::{collections::HashSet, sync::Arc}; diff --git a/node/src/manager/commands/listen.rs b/node/src/manager/commands/listen.rs index 0f61f8a5b2e..2b65fde8006 100644 --- a/node/src/manager/commands/listen.rs +++ b/node/src/manager/commands/listen.rs @@ -1,11 +1,11 @@ use std::io::Write; use std::sync::Arc; -use graph::futures03::{future, StreamExt}; +use graph::futures03::{StreamExt, future}; use graph::{ components::store::SubscriptionManager as _, - prelude::{serde_json, Error}, + prelude::{Error, serde_json}, }; use graph_store_postgres::SubscriptionManager; diff --git a/node/src/manager/commands/provider_checks.rs b/node/src/manager/commands/provider_checks.rs index 12f2e98e00b..5154756c8f3 100644 --- a/node/src/manager/commands/provider_checks.rs +++ b/node/src/manager/commands/provider_checks.rs @@ -1,7 +1,6 @@ use std::sync::Arc; use std::time::Duration; -use graph::components::network_provider::chain_id_validator; use graph::components::network_provider::ChainIdentifierValidator; use graph::components::network_provider::ChainName; use graph::components::network_provider::ExtendedBlocksCheck; @@ -9,9 +8,10 @@ use graph::components::network_provider::GenesisHashCheck; use graph::components::network_provider::NetworkDetails; use graph::components::network_provider::ProviderCheck; use graph::components::network_provider::ProviderCheckStatus; -use graph::prelude::tokio; +use graph::components::network_provider::chain_id_validator; use graph::prelude::CheapClone; use graph::prelude::Logger; +use graph::prelude::tokio; use graph_store_postgres::BlockStore; use itertools::Itertools; diff --git a/node/src/manager/commands/prune.rs b/node/src/manager/commands/prune.rs index 5078ab37d02..82f4387dd4d 100644 --- a/node/src/manager/commands/prune.rs +++ b/node/src/manager/commands/prune.rs @@ -12,11 +12,11 @@ use graph::{ use graph::{ components::store::{PruneReporter, StatusStore}, data::subgraph::status, - prelude::{anyhow, BlockNumber}, + prelude::{BlockNumber, anyhow}, }; use graph_store_postgres::{ - command_support::{Phase, PruneTableState}, ConnectionPool, Store, + command_support::{Phase, PruneTableState}, }; use termcolor::Color; @@ -194,7 +194,9 @@ async fn check_args( .ok_or_else(|| anyhow!("deployment {} does not index any chain", deployment))?; let latest_block = status.latest_block.map(|ptr| ptr.number()).unwrap_or(0); if latest_block <= history { - return Err(anyhow!("deployment {deployment} has only indexed up to block {latest_block} and we can't preserve {history} blocks of history")); + return Err(anyhow!( + "deployment {deployment} has only indexed up to block {latest_block} and we can't preserve {history} blocks of history" + )); } Ok(Args { history, @@ -426,7 +428,8 @@ pub async fn status( let batch_size = batch_size.map_or_null(|b| b.to_string()); let duration = started_at.map_or_null(|s| fmt::duration(s, &finished_at)); let phase = phase.as_str(); - writeln!(term, + writeln!( + term, "{table_name:<30} | {:<15} {complete:>6} | {rows:>8} | {batch_size:>11} | {duration:>8}", format!("{strategy}/{phase}") )?; diff --git a/node/src/manager/commands/query.rs b/node/src/manager/commands/query.rs index 04400bfb923..57937200839 100644 --- a/node/src/manager/commands/query.rs +++ b/node/src/manager/commands/query.rs @@ -9,8 +9,9 @@ use graph::prelude::{q, r}; use graph::{ data::query::QueryTarget, prelude::{ + DeploymentHash, GraphQlRunner as _, Query, QueryVariables, SubgraphName, anyhow::{self, anyhow}, - serde_json, DeploymentHash, GraphQlRunner as _, Query, QueryVariables, SubgraphName, + serde_json, }, }; use graph_graphql::prelude::GraphQlRunner; diff --git a/node/src/manager/commands/remove.rs b/node/src/manager/commands/remove.rs index bcf9417569a..44a5e888f46 100644 --- a/node/src/manager/commands/remove.rs +++ b/node/src/manager/commands/remove.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use graph::prelude::{anyhow, Error, SubgraphName, SubgraphStore as _}; +use graph::prelude::{Error, SubgraphName, SubgraphStore as _, anyhow}; use graph_store_postgres::SubgraphStore; pub async fn run(store: Arc, name: &str) -> Result<(), Error> { diff --git a/node/src/manager/commands/rewind.rs b/node/src/manager/commands/rewind.rs index 03a75692c27..55628c2de3c 100644 --- a/node/src/manager/commands/rewind.rs +++ b/node/src/manager/commands/rewind.rs @@ -8,7 +8,7 @@ use crate::manager::deployment::DeploymentSearch; use graph::anyhow::bail; use graph::components::store::{BlockStore as _, ChainStore as _, DeploymentLocator}; use graph::env::ENV_VARS; -use graph::prelude::{anyhow, BlockNumber, BlockPtr}; +use graph::prelude::{BlockNumber, BlockPtr, anyhow}; use graph_store_postgres::command_support::catalog::{self as store_catalog}; use graph_store_postgres::{BlockStore, NotificationSender}; use graph_store_postgres::{ConnectionPool, Store}; diff --git a/node/src/manager/commands/run.rs b/node/src/manager/commands/run.rs index 2c23eb5151d..bbe9e1faf18 100644 --- a/node/src/manager/commands/run.rs +++ b/node/src/manager/commands/run.rs @@ -2,11 +2,11 @@ use std::collections::HashMap; use std::sync::Arc; use std::time::Duration; +use crate::MetricsContext; use crate::config::Config; use crate::manager::PanicSubscriptionManager; use crate::network_setup::Networks; use crate::store_builder::StoreBuilder; -use crate::MetricsContext; use graph::amp; use graph::anyhow::bail; use graph::cheap_clone::CheapClone; @@ -17,11 +17,11 @@ use graph::components::subgraph::{Settings, SubgraphInstanceManager as _}; use graph::endpoint::EndpointMetrics; use graph::env::EnvVars; use graph::prelude::{ - anyhow, tokio, BlockNumber, DeploymentHash, IpfsResolver, LoggerFactory, NodeId, + BlockNumber, DeploymentHash, ENV_VARS, IpfsResolver, LoggerFactory, NodeId, SubgraphCountMetric, SubgraphName, SubgraphRegistrar, SubgraphStore, - SubgraphVersionSwitchingMode, ENV_VARS, + SubgraphVersionSwitchingMode, anyhow, tokio, }; -use graph::slog::{debug, info, Logger}; +use graph::slog::{Logger, debug, info}; use graph_core::polling_monitor::{arweave_service, ipfs_service}; use tokio_util::sync::CancellationToken; diff --git a/node/src/manager/commands/stats.rs b/node/src/manager/commands/stats.rs index 34405b05e9b..bbb219bf11c 100644 --- a/node/src/manager/commands/stats.rs +++ b/node/src/manager/commands/stats.rs @@ -6,15 +6,15 @@ use crate::manager::deployment::DeploymentSearch; use crate::manager::fmt; use graph::components::store::DeploymentLocator; use graph::components::store::VersionStats; -use graph::prelude::anyhow; use graph::prelude::CheapClone as _; -use graph_store_postgres::command_support::catalog as store_catalog; -use graph_store_postgres::command_support::catalog::Site; +use graph::prelude::anyhow; use graph_store_postgres::AsyncPgConnection; use graph_store_postgres::ConnectionPool; +use graph_store_postgres::PRIMARY_SHARD; use graph_store_postgres::Shard; use graph_store_postgres::SubgraphStore; -use graph_store_postgres::PRIMARY_SHARD; +use graph_store_postgres::command_support::catalog as store_catalog; +use graph_store_postgres::command_support::catalog::Site; async fn site_and_conn( pools: HashMap, diff --git a/node/src/manager/commands/unused_deployments.rs b/node/src/manager/commands/unused_deployments.rs index 5690a7485af..c14f7662d7a 100644 --- a/node/src/manager/commands/unused_deployments.rs +++ b/node/src/manager/commands/unused_deployments.rs @@ -1,7 +1,7 @@ use std::{sync::Arc, time::Instant}; use graph::prelude::{anyhow::Error, chrono}; -use graph_store_postgres::{unused, SubgraphStore, UnusedDeployment}; +use graph_store_postgres::{SubgraphStore, UnusedDeployment, unused}; use crate::manager::{deployment::DeploymentSearch, display::List}; diff --git a/node/src/manager/deployment.rs b/node/src/manager/deployment.rs index eb5b575eb4e..4dd31fbbec0 100644 --- a/node/src/manager/deployment.rs +++ b/node/src/manager/deployment.rs @@ -12,7 +12,7 @@ use diesel_async::RunQueryDsl; use graph::components::store::DeploymentId; use graph::{ components::store::DeploymentLocator, - prelude::{anyhow, lazy_static, regex::Regex, DeploymentHash}, + prelude::{DeploymentHash, anyhow, lazy_static, regex::Regex}, }; use graph_store_postgres::command_support::catalog as store_catalog; use graph_store_postgres::unused; diff --git a/node/src/manager/fmt.rs b/node/src/manager/fmt.rs index 45807fecbf7..e476bb876dd 100644 --- a/node/src/manager/fmt.rs +++ b/node/src/manager/fmt.rs @@ -76,8 +76,8 @@ pub fn abbreviate(name: &str, size: usize) -> String { let last = name.len() - fragment; let mut name = name.to_string(); name.replace_range(fragment..last, ".."); - let table = name.trim().to_string(); - table + + name.trim().to_string() } else { name.to_string() } diff --git a/node/src/manager/mod.rs b/node/src/manager/mod.rs index d95e5fbadc1..7c3ae84793d 100644 --- a/node/src/manager/mod.rs +++ b/node/src/manager/mod.rs @@ -1,6 +1,6 @@ use graph::{ components::store::SubscriptionManager, - prelude::{anyhow, StoreEventStreamBox}, + prelude::{StoreEventStreamBox, anyhow}, }; pub mod catalog; diff --git a/node/src/network_setup.rs b/node/src/network_setup.rs index 2191aaea0d9..e1630786345 100644 --- a/node/src/network_setup.rs +++ b/node/src/network_setup.rs @@ -1,7 +1,7 @@ use ethereum::{ + BlockIngestor, chain::ChainSettings, network::{EthereumNetworkAdapter, EthereumNetworkAdapters}, - BlockIngestor, }; use graph::components::network_provider::ChainName; use graph::components::network_provider::NetworkDetails; @@ -20,10 +20,11 @@ use graph::{ itertools::Itertools, log::factory::LoggerFactory, prelude::{ - anyhow::{anyhow, Result}, - info, Logger, + Logger, + anyhow::{Result, anyhow}, + info, }, - slog::{o, warn, Discard}, + slog::{Discard, o, warn}, }; use graph_chain_ethereum as ethereum; use graph_store_postgres::{BlockStore, ChainHeadUpdateListener}; @@ -31,8 +32,8 @@ use graph_store_postgres::{BlockStore, ChainHeadUpdateListener}; use std::{any::Any, cmp::Ordering, sync::Arc}; use crate::chain::{ - create_ethereum_networks, create_firehose_networks, networks_as_chains, AnyChainFilter, - ChainFilter, OneChainFilter, + AnyChainFilter, ChainFilter, OneChainFilter, create_ethereum_networks, + create_firehose_networks, networks_as_chains, }; #[derive(Debug, Clone)] @@ -129,13 +130,13 @@ impl Networks { Ok(ident) => return Ok(ident), Err(err) => { warn!( - logger, - "unable to get chain identification from {} provider {} for chain {}, err: {}", - provider_type, - adapter.provider_name(), - chain_id, - err.to_string(), - ); + logger, + "unable to get chain identification from {} provider {} for chain {}, err: {}", + provider_type, + adapter.provider_name(), + chain_id, + err.to_string(), + ); } } } @@ -181,7 +182,7 @@ impl Networks { endpoint_metrics.cheap_clone(), chain_filter, ); - let adapters: Vec<_> = eth.into_iter().chain(firehose.into_iter()).collect(); + let adapters: Vec<_> = eth.into_iter().chain(firehose).collect(); Ok(Networks::new(&logger, adapters, provider_checks)) } @@ -260,7 +261,7 @@ impl Networks { ) .collect_vec(); - let s = Self { + Self { adapters: adapters2, rpc_provider_manager: ProviderManager::new( logger.clone(), @@ -272,9 +273,7 @@ impl Networks { firehose_adapters, ProviderCheckStrategy::RequireAll(provider_checks), ), - }; - - s + } } pub async fn block_ingestors( diff --git a/node/src/store_builder.rs b/node/src/store_builder.rs index 24132881f3b..fb3737e5b89 100644 --- a/node/src/store_builder.rs +++ b/node/src/store_builder.rs @@ -2,18 +2,18 @@ use std::iter::FromIterator; use std::{collections::HashMap, sync::Arc}; use graph::components::store::BLOCK_CACHE_SIZE; -use graph::prelude::{o, MetricsRegistry, NodeId}; +use graph::prelude::{MetricsRegistry, NodeId, o}; use graph::slog::warn; use graph::url::Url; use graph::{ - prelude::{info, CheapClone, Logger}, + prelude::{CheapClone, Logger, info}, util::security::SafeDisplay, }; use graph_store_postgres::{ BlockStore as DieselBlockStore, ChainHeadUpdateListener as PostgresChainHeadUpdateListener, - ChainStoreMetrics, ConnectionPool, ForeignServer, NotificationSender, PoolCoordinator, - PoolRole, Shard as ShardName, Store as DieselStore, SubgraphStore, SubscriptionManager, - PRIMARY_SHARD, + ChainStoreMetrics, ConnectionPool, ForeignServer, NotificationSender, PRIMARY_SHARD, + PoolCoordinator, PoolRole, Shard as ShardName, Store as DieselStore, SubgraphStore, + SubscriptionManager, }; use crate::config::{Config, Shard}; diff --git a/runtime/test/src/test.rs b/runtime/test/src/test.rs index 3afe845d46e..985dc26ea8f 100644 --- a/runtime/test/src/test.rs +++ b/runtime/test/src/test.rs @@ -2,7 +2,7 @@ use async_trait::async_trait; use graph::blockchain::BlockTime; use graph::components::metrics::gas::GasMetrics; use graph::components::store::*; -use graph::data::store::{scalar, Id, IdType}; +use graph::data::store::{Id, IdType, scalar}; use graph::data::subgraph::*; use graph::data::value::Word; use graph::futures03::future::BoxFuture; @@ -16,7 +16,7 @@ use graph::{entity, prelude::*}; use graph_chain_ethereum::DataSource; use graph_runtime_wasm::asc_abi::class::{Array, AscBigInt, AscEntity, AscString, Uint8Array}; use graph_runtime_wasm::{ - host_exports, ExperimentalFeatures, MappingContext, ValidModule, WasmInstance, + ExperimentalFeatures, MappingContext, ValidModule, WasmInstance, host_exports, }; use semver::Version; use std::collections::{BTreeMap, HashMap}; @@ -994,10 +994,12 @@ async fn test_ens_name_by_hash(api_version: Version) { let data: String = module.asc_get(converted).unwrap(); assert_eq!(data, name); - assert!(module - .invoke_export1::<_, _, AscString>("nameByHash", "impossible keccak hash") - .await - .is_null()); + assert!( + module + .invoke_export1::<_, _, AscString>("nameByHash", "impossible keccak hash") + .await + .is_null() + ); } #[graph::test] @@ -1130,10 +1132,12 @@ fn test_detect_contract_calls(api_version: Version) { &wasm_file_path("abi_store_value.wasm", api_version.clone()), api_version.clone(), ); - assert!(!data_source_without_calls - .mapping - .requires_archive() - .unwrap()); + assert!( + !data_source_without_calls + .mapping + .requires_archive() + .unwrap() + ); let data_source_with_calls = mock_data_source( &wasm_file_path("contract_calls.wasm", api_version.clone()), @@ -1250,30 +1254,38 @@ async fn test_boolean() { // non-zero values are true for x in (-10i32..10).filter(|&x| x != 0) { - assert!(module - .invoke_export1_val_void("testReceiveTrue", x) - .await - .is_ok(),); + assert!( + module + .invoke_export1_val_void("testReceiveTrue", x) + .await + .is_ok(), + ); } // zero is not true - assert!(module - .invoke_export1_val_void("testReceiveTrue", 0i32) - .await - .is_err()); + assert!( + module + .invoke_export1_val_void("testReceiveTrue", 0i32) + .await + .is_err() + ); // zero is false - assert!(module - .invoke_export1_val_void("testReceiveFalse", 0i32) - .await - .is_ok()); + assert!( + module + .invoke_export1_val_void("testReceiveFalse", 0i32) + .await + .is_ok() + ); // non-zero values are not false for x in (-10i32..10).filter(|&x| x != 0) { - assert!(module - .invoke_export1_val_void("testReceiveFalse", x) - .await - .is_err()); + assert!( + module + .invoke_export1_val_void("testReceiveFalse", x) + .await + .is_err() + ); } } @@ -1566,7 +1578,10 @@ async fn test_store_set_invalid_fields() { .err() .unwrap(); - err_says(err, "Attempted to set undefined fields [test3] for the entity type `User`. Make sure those fields are defined in the schema."); + err_says( + err, + "Attempted to set undefined fields [test3] for the entity type `User`. Make sure those fields are defined in the schema.", + ); // For apiVersion below 0.0.8, we should not error out let mut host2 = Host::new( diff --git a/runtime/test/src/test_padding.rs b/runtime/test/src/test_padding.rs index 93e1a642724..89cab5b7231 100644 --- a/runtime/test/src/test_padding.rs +++ b/runtime/test/src/test_padding.rs @@ -7,7 +7,7 @@ const WASM_FILE_NAME: &str = "test_padding.wasm"; //for tests, to run in parallel, sub graph name has be unique fn rnd_sub_graph_name(size: usize) -> String { - use rand::{distr::Alphanumeric, Rng}; + use rand::{Rng, distr::Alphanumeric}; rand::rng() .sample_iter(&Alphanumeric) .take(size) @@ -62,8 +62,8 @@ pub mod data { use async_trait::async_trait; use graph::runtime::HostExportError; pub use graph::runtime::{ - asc_new, gas::GasCounter, AscHeap, AscIndexId, AscPtr, AscType, AscValue, - DeterministicHostError, IndexForAscTypeId, ToAscObj, + AscHeap, AscIndexId, AscPtr, AscType, AscValue, DeterministicHostError, IndexForAscTypeId, + ToAscObj, asc_new, gas::GasCounter, }; use graph_runtime_wasm::asc_abi::class::AscString; diff --git a/runtime/wasm/src/asc_abi/class.rs b/runtime/wasm/src/asc_abi/class.rs index 8d0f54049dc..ac3256661b2 100644 --- a/runtime/wasm/src/asc_abi/class.rs +++ b/runtime/wasm/src/asc_abi/class.rs @@ -8,8 +8,8 @@ use graph::{ subgraph::API_VERSION_0_0_4, }, runtime::{ - gas::GasCounter, AscHeap, AscIndexId, AscType, AscValue, HostExportError, - IndexForAscTypeId, ToAscObj, + AscHeap, AscIndexId, AscType, AscValue, HostExportError, IndexForAscTypeId, ToAscObj, + gas::GasCounter, }, }; use graph::{prelude::serde_json, runtime::DeterministicHostError}; diff --git a/runtime/wasm/src/asc_abi/v0_0_5.rs b/runtime/wasm/src/asc_abi/v0_0_5.rs index 3c769845b2b..c09ce7a167f 100644 --- a/runtime/wasm/src/asc_abi/v0_0_5.rs +++ b/runtime/wasm/src/asc_abi/v0_0_5.rs @@ -7,7 +7,7 @@ use semver::Version; use graph::runtime::gas::GasCounter; use graph::runtime::{ - AscHeap, AscPtr, AscType, AscValue, DeterministicHostError, HostExportError, HEADER_SIZE, + AscHeap, AscPtr, AscType, AscValue, DeterministicHostError, HEADER_SIZE, HostExportError, }; use crate::asc_abi::class; diff --git a/runtime/wasm/src/host_exports.rs b/runtime/wasm/src/host_exports.rs index ab45777c428..f65ae397be5 100644 --- a/runtime/wasm/src/host_exports.rs +++ b/runtime/wasm/src/host_exports.rs @@ -24,7 +24,7 @@ use graph::data_source::{CausalityRegion, DataSource, EntityTypeAccess}; use graph::ensure; use graph::prelude::serde_json; use graph::prelude::{slog::b, slog::record_static, *}; -use graph::runtime::gas::{self, complexity, Gas, GasCounter}; +use graph::runtime::gas::{self, Gas, GasCounter, complexity}; pub use graph::runtime::{DeterministicHostError, HostExportError}; use crate::module::WasmInstance; @@ -179,8 +179,8 @@ impl HostExports { if has_invalid_fields { let mut invalid_fields: Vec = data - .iter() - .filter_map(|(field_name, _)| { + .keys() + .filter_map(|field_name| { if !state .entity_cache .schema @@ -1299,7 +1299,7 @@ pub mod test_support { components::{store::GetScope, subgraph::SharedProofOfIndexing}, data::value::Word, prelude::{BlockState, Entity, StopwatchMetrics, Value}, - runtime::{gas::GasCounter, HostExportError}, + runtime::{HostExportError, gas::GasCounter}, slog::Logger, }; @@ -1371,7 +1371,9 @@ fn bytes_to_string_is_lossy() { "Downcoin WETH-USDT", bytes_to_string( &graph::log::logger(true), - vec![68, 111, 119, 110, 99, 111, 105, 110, 32, 87, 69, 84, 72, 45, 85, 83, 68, 84], + vec![ + 68, 111, 119, 110, 99, 111, 105, 110, 32, 87, 69, 84, 72, 45, 85, 83, 68, 84 + ], ) ); diff --git a/runtime/wasm/src/mapping.rs b/runtime/wasm/src/mapping.rs index 68e7ea249f2..3c98bc8081d 100644 --- a/runtime/wasm/src/mapping.rs +++ b/runtime/wasm/src/mapping.rs @@ -9,13 +9,13 @@ use graph::futures01::{Future as _, Stream as _}; use graph::futures03::channel::oneshot::Sender; use graph::parking_lot::RwLock; use graph::prelude::*; -use graph::runtime::gas::Gas; use graph::runtime::IndexForAscTypeId; +use graph::runtime::gas::Gas; use parity_wasm::elements::ExportEntry; use std::collections::{BTreeMap, HashMap}; use std::panic::AssertUnwindSafe; -use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; +use std::sync::atomic::{AtomicUsize, Ordering}; use std::{panic, thread}; /// Spawn a wasm module in its own thread. diff --git a/runtime/wasm/src/module/context.rs b/runtime/wasm/src/module/context.rs index 68639e463b3..3f32d235378 100644 --- a/runtime/wasm/src/module/context.rs +++ b/runtime/wasm/src/module/context.rs @@ -13,21 +13,21 @@ use anyhow::Error; use graph::components::store::{GetScope, SeqGenerator}; use never::Never; -use crate::asc_abi::class::*; use crate::HostExports; +use crate::asc_abi::class::*; use graph::data::store; +use crate::ExperimentalFeatures; use crate::asc_abi::class::AscEntity; use crate::asc_abi::class::AscString; use crate::mapping::MappingContext; use crate::mapping::ValidModule; -use crate::ExperimentalFeatures; use graph::prelude::*; use graph::runtime::AscPtr; -use graph::runtime::{asc_new, gas::GasCounter, DeterministicHostError, HostExportError}; +use graph::runtime::{DeterministicHostError, HostExportError, asc_new, gas::GasCounter}; -use super::asc_get; use super::AscHeapCtx; +use super::asc_get; pub(crate) struct WasmInstanceContext<'a> { inner: StoreContextMut<'a, WasmInstanceData>, diff --git a/runtime/wasm/src/module/instance.rs b/runtime/wasm/src/module/instance.rs index a4bf1f34d81..02cfc5eb8d1 100644 --- a/runtime/wasm/src/module/instance.rs +++ b/runtime/wasm/src/module/instance.rs @@ -2,8 +2,8 @@ use std::collections::BTreeMap; use std::time::Instant; use anyhow::Error; -use graph::futures03::future::BoxFuture; use graph::futures03::FutureExt as _; +use graph::futures03::future::BoxFuture; use graph::slog::SendSyncRefUnwindSafeKV; use semver::Version; @@ -15,21 +15,20 @@ use graph::data::subgraph::schema::SubgraphError; use graph::data_source::{MappingTrigger, TriggerWithHandler}; use graph::prelude::*; use graph::runtime::{ - asc_new, + HostExportError, asc_new, gas::{Gas, GasCounter, SaturatingInto}, - HostExportError, }; use graph::{components::subgraph::MappingError, runtime::AscPtr}; use super::IntoWasmRet; use super::{IntoTrap, WasmInstanceContext}; +use crate::ExperimentalFeatures; use crate::error::DeterminismLevel; use crate::mapping::MappingContext; use crate::mapping::ValidModule; use crate::module::WasmInstanceData; -use crate::ExperimentalFeatures; -use super::{is_trap_deterministic, AscHeapCtx, ToAscPtr}; +use super::{AscHeapCtx, ToAscPtr, is_trap_deterministic}; /// Handle to a WASM instance, which is terminated if and only if this is dropped. pub struct WasmInstance { @@ -43,11 +42,11 @@ pub struct WasmInstance { #[cfg(debug_assertions)] mod impl_for_tests { use graph::runtime::{ - asc_new, AscIndexId, AscPtr, AscType, DeterministicHostError, FromAscObj, HostExportError, - ToAscObj, + AscIndexId, AscPtr, AscType, DeterministicHostError, FromAscObj, HostExportError, ToAscObj, + asc_new, }; - use crate::module::{asc_get, WasmInstanceContext}; + use crate::module::{WasmInstanceContext, asc_get}; impl super::WasmInstance { pub fn asc_get(&mut self, asc_ptr: AscPtr

) -> Result diff --git a/runtime/wasm/src/module/mod.rs b/runtime/wasm/src/module/mod.rs index fddfe4b8c01..5c84155836f 100644 --- a/runtime/wasm/src/module/mod.rs +++ b/runtime/wasm/src/module/mod.rs @@ -1,8 +1,8 @@ use std::convert::TryFrom; use std::mem::MaybeUninit; -use anyhow::anyhow; use anyhow::Error; +use anyhow::anyhow; use async_trait::async_trait; use graph::blockchain::Blockchain; use graph::data_source::subgraph; @@ -13,14 +13,13 @@ use wasmtime::AsContext; use wasmtime::AsContextMut; use wasmtime::Memory; -use graph::data_source::{offchain, MappingTrigger, TriggerWithHandler}; +use graph::data_source::{MappingTrigger, TriggerWithHandler, offchain}; use graph::prelude::*; use graph::runtime::AscPtr; use graph::runtime::{ - asc_new, - gas::{Gas, GasCounter}, AscHeap, AscIndexId, AscType, DeterministicHostError, FromAscObj, HostExportError, - IndexForAscTypeId, + IndexForAscTypeId, asc_new, + gas::{Gas, GasCounter}, }; pub use into_wasm_ret::IntoWasmRet; diff --git a/runtime/wasm/src/to_from/external.rs b/runtime/wasm/src/to_from/external.rs index 1ae4e6426fe..39e23cf00d9 100644 --- a/runtime/wasm/src/to_from/external.rs +++ b/runtime/wasm/src/to_from/external.rs @@ -5,10 +5,10 @@ use graph::data::store::scalar::Timestamp; use graph::data::value::Word; use graph::prelude::alloy::primitives::{Address, B256}; use graph::prelude::{BigDecimal, BigInt}; -use graph::runtime::gas::GasCounter; use graph::runtime::AscHeap; +use graph::runtime::gas::GasCounter; use graph::runtime::{ - asc_get, asc_new, AscIndexId, AscPtr, AscType, AscValue, HostExportError, ToAscObj, + AscIndexId, AscPtr, AscType, AscValue, HostExportError, ToAscObj, asc_get, asc_new, }; use graph::{data::store, runtime::DeterministicHostError}; use graph::{ diff --git a/runtime/wasm/src/to_from/mod.rs b/runtime/wasm/src/to_from/mod.rs index d3dc07c9afe..5318aac2fd2 100644 --- a/runtime/wasm/src/to_from/mod.rs +++ b/runtime/wasm/src/to_from/mod.rs @@ -9,8 +9,8 @@ use std::iter::FromIterator; use graph::{ data::value::Word, runtime::{ - asc_get, asc_new, gas::GasCounter, AscHeap, AscIndexId, AscPtr, AscType, AscValue, - DeterministicHostError, FromAscObj, HostExportError, ToAscObj, + AscHeap, AscIndexId, AscPtr, AscType, AscValue, DeterministicHostError, FromAscObj, + HostExportError, ToAscObj, asc_get, asc_new, gas::GasCounter, }, }; @@ -207,11 +207,11 @@ where } impl< - K: AscType + AscIndexId, - V: AscType + AscIndexId, - T: FromAscObj + Hash + Eq, - U: FromAscObj, - > FromAscObj> for HashMap + K: AscType + AscIndexId, + V: AscType + AscIndexId, + T: FromAscObj + Hash + Eq, + U: FromAscObj, +> FromAscObj> for HashMap where Array>>: AscIndexId, AscTypedMapEntry: AscIndexId, diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 4caf2a671f8..529ab8268aa 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,9 @@ [toolchain] -channel = "stable" +# Pinned to 1.94.0 because Rust 1.95.0 has a compiler regression where +# the `core` crate hits a recursion limit resolving NonZero niche types +# ("queries overflow the depth limit!" in niche_types.rs). See +# https://github.com/rust-lang/rust/issues/152942 for details. Switch +# back to "stable" once a fixed release (1.95.1+ or 1.96.0) is available. +channel = "1.94.0" profile = "default" components = [ "rustfmt" ] diff --git a/server/graphman/src/entities/deployment_selector.rs b/server/graphman/src/entities/deployment_selector.rs index 97d8ec72b23..f77ab9ee766 100644 --- a/server/graphman/src/entities/deployment_selector.rs +++ b/server/graphman/src/entities/deployment_selector.rs @@ -1,5 +1,5 @@ -use anyhow::anyhow; use anyhow::Result; +use anyhow::anyhow; use async_graphql::InputObject; /// Available criteria for selecting one or more deployments. diff --git a/server/graphman/src/handlers/graphql.rs b/server/graphman/src/handlers/graphql.rs index 4eeb88303cf..8390942f018 100644 --- a/server/graphman/src/handlers/graphql.rs +++ b/server/graphman/src/handlers/graphql.rs @@ -1,7 +1,7 @@ use std::sync::Arc; -use async_graphql::http::playground_source; use async_graphql::http::GraphQLPlaygroundConfig; +use async_graphql::http::playground_source; use async_graphql_axum::GraphQLRequest; use async_graphql_axum::GraphQLResponse; use axum::extract::Extension; diff --git a/server/graphman/src/resolvers/deployment_mutation/create.rs b/server/graphman/src/resolvers/deployment_mutation/create.rs index 52e30bc6504..9c9bd09542e 100644 --- a/server/graphman/src/resolvers/deployment_mutation/create.rs +++ b/server/graphman/src/resolvers/deployment_mutation/create.rs @@ -20,7 +20,7 @@ pub async fn run(ctx: &GraphmanContext, name: &String) -> Result<()> { return Err(GraphmanError::Store(anyhow!( "Subgraph name must contain only a-z, A-Z, 0-9, '-' and '_'" )) - .into()) + .into()); } }; diff --git a/server/graphman/src/resolvers/deployment_mutation/pause.rs b/server/graphman/src/resolvers/deployment_mutation/pause.rs index 71327e62f7e..386747f1af5 100644 --- a/server/graphman/src/resolvers/deployment_mutation/pause.rs +++ b/server/graphman/src/resolvers/deployment_mutation/pause.rs @@ -1,6 +1,6 @@ use async_graphql::Result; use graphman::commands::deployment::pause::{ - load_active_deployment, pause_active_deployment, PauseDeploymentError, + PauseDeploymentError, load_active_deployment, pause_active_deployment, }; use graphman::deployment::DeploymentSelector; diff --git a/server/graphman/src/resolvers/deployment_mutation/reassign.rs b/server/graphman/src/resolvers/deployment_mutation/reassign.rs index 00d32bc0a7b..ee24719c328 100644 --- a/server/graphman/src/resolvers/deployment_mutation/reassign.rs +++ b/server/graphman/src/resolvers/deployment_mutation/reassign.rs @@ -1,9 +1,9 @@ use anyhow::Ok; use async_graphql::Result; use graph::prelude::NodeId; +use graphman::commands::deployment::reassign::ReassignResult; use graphman::commands::deployment::reassign::load_deployment; use graphman::commands::deployment::reassign::reassign_deployment; -use graphman::commands::deployment::reassign::ReassignResult; use graphman::deployment::DeploymentSelector; use crate::resolvers::context::GraphmanContext; diff --git a/server/graphman/src/resolvers/deployment_mutation/remove.rs b/server/graphman/src/resolvers/deployment_mutation/remove.rs index c7997b6885f..b310281d52c 100644 --- a/server/graphman/src/resolvers/deployment_mutation/remove.rs +++ b/server/graphman/src/resolvers/deployment_mutation/remove.rs @@ -20,7 +20,7 @@ pub async fn run(ctx: &GraphmanContext, name: &String) -> Result<()> { return Err(GraphmanError::Store(anyhow!( "Subgraph name must contain only a-z, A-Z, 0-9, '-' and '_'" )) - .into()) + .into()); } }; diff --git a/server/graphman/src/resolvers/deployment_mutation/restart.rs b/server/graphman/src/resolvers/deployment_mutation/restart.rs index 3f92b9403e7..477ee7fb261 100644 --- a/server/graphman/src/resolvers/deployment_mutation/restart.rs +++ b/server/graphman/src/resolvers/deployment_mutation/restart.rs @@ -3,8 +3,8 @@ use std::time::Duration; use async_graphql::Result; use graph_store_postgres::graphman::GraphmanStore; -use graphman::deployment::DeploymentSelector; use graphman::GraphmanExecutionTracker; +use graphman::deployment::DeploymentSelector; use graphman_store::CommandKind; use graphman_store::GraphmanStore as _; diff --git a/server/graphman/src/server.rs b/server/graphman/src/server.rs index a969433cdea..a3a4456606b 100644 --- a/server/graphman/src/server.rs +++ b/server/graphman/src/server.rs @@ -3,28 +3,28 @@ use std::sync::Arc; use async_graphql::EmptySubscription; use async_graphql::Schema; +use axum::Router; use axum::extract::Extension; use axum::http::Method; use axum::routing::get; -use axum::Router; use graph::log::factory::LoggerFactory; use graph::prelude::ComponentLoggerConfig; use graph::prelude::ElasticComponentLoggerConfig; -use graph_store_postgres::graphman::GraphmanStore; use graph_store_postgres::ConnectionPool; use graph_store_postgres::NotificationSender; use graph_store_postgres::Store; -use slog::{info, Logger}; +use graph_store_postgres::graphman::GraphmanStore; +use slog::{Logger, info}; use tokio::sync::Notify; use tower_http::cors::{Any, CorsLayer}; +use crate::GraphmanServerError; use crate::auth::AuthToken; +use crate::handlers::AppState; use crate::handlers::graphql_playground_handler; use crate::handlers::graphql_request_handler; -use crate::handlers::AppState; use crate::resolvers::MutationRoot; use crate::resolvers::QueryRoot; -use crate::GraphmanServerError; #[derive(Clone)] pub struct GraphmanServer { diff --git a/server/graphman/tests/auth.rs b/server/graphman/tests/auth.rs index f60670c33dc..a5729ef9e66 100644 --- a/server/graphman/tests/auth.rs +++ b/server/graphman/tests/auth.rs @@ -2,10 +2,10 @@ pub mod util; use serde_json::json; -use self::util::client::send_graphql_request; -use self::util::client::send_request; use self::util::client::BASE_URL; use self::util::client::CLIENT; +use self::util::client::send_graphql_request; +use self::util::client::send_request; use self::util::run_test; use self::util::server::INVALID_TOKEN; use self::util::server::VALID_TOKEN; diff --git a/server/graphman/tests/deployment_mutation.rs b/server/graphman/tests/deployment_mutation.rs index fd2020ee740..6742b064f20 100644 --- a/server/graphman/tests/deployment_mutation.rs +++ b/server/graphman/tests/deployment_mutation.rs @@ -6,8 +6,8 @@ use graph::components::store::SubgraphStore; use graph::prelude::DeploymentHash; use serde::Deserialize; use serde_json::json; -use test_store::create_test_subgraph; use test_store::SUBGRAPH_STORE; +use test_store::create_test_subgraph; use tokio::time::sleep; use self::util::client::send_graphql_request; diff --git a/server/graphman/tests/deployment_query.rs b/server/graphman/tests/deployment_query.rs index 9d11cfc018f..52006b91b38 100644 --- a/server/graphman/tests/deployment_query.rs +++ b/server/graphman/tests/deployment_query.rs @@ -5,10 +5,10 @@ use graph::data::subgraph::DeploymentHash; use graph::prelude::QueryTarget; use serde_json::json; -use test_store::store::create_test_subgraph; -use test_store::store::NETWORK_NAME; use test_store::STORE; use test_store::SUBGRAPH_STORE; +use test_store::store::NETWORK_NAME; +use test_store::store::create_test_subgraph; use self::util::client::send_graphql_request; use self::util::run_test; diff --git a/server/graphman/tests/util/mod.rs b/server/graphman/tests/util/mod.rs index 7fe6893fcd6..b4409d2d500 100644 --- a/server/graphman/tests/util/mod.rs +++ b/server/graphman/tests/util/mod.rs @@ -6,8 +6,8 @@ use std::sync::Mutex; use graph::TEST_RUNTIME; use lazy_static::lazy_static; -use test_store::store::remove_subgraphs; use test_store::store::PRIMARY_POOL; +use test_store::store::remove_subgraphs; lazy_static! { // Used to make sure tests will run sequentially. diff --git a/server/http/src/server.rs b/server/http/src/server.rs index f5868cff5b8..8aad5eb0d18 100644 --- a/server/http/src/server.rs +++ b/server/http/src/server.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use graph::anyhow; use graph::cheap_clone::CheapClone; -use graph::components::server::server::{start, ServerHandle}; +use graph::components::server::server::{ServerHandle, start}; use graph::log::factory::{ComponentLoggerConfig, ElasticComponentLoggerConfig}; use graph::slog::info; diff --git a/server/http/src/service.rs b/server/http/src/service.rs index 6eee41ce59a..2a17abf29ca 100644 --- a/server/http/src/service.rs +++ b/server/http/src/service.rs @@ -19,15 +19,15 @@ use graph::hyper::header::{ ACCESS_CONTROL_ALLOW_HEADERS, ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_ALLOW_ORIGIN, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, }; -use graph::hyper::{body::Body, header::HeaderValue}; use graph::hyper::{Method, Request, Response, StatusCode}; -use graph::prelude::serde_json; -use graph::prelude::serde_json::json; +use graph::hyper::{body::Body, header::HeaderValue}; use graph::prelude::CacheWeight as _; use graph::prelude::QueryError; +use graph::prelude::serde_json; +use graph::prelude::serde_json::json; use graph::semver::VersionReq; -use graph::slog::error; use graph::slog::Logger; +use graph::slog::error; use graph::url::form_urlencoded; use graph::{components::server::query::ServerError, data::query::QueryTarget}; @@ -104,10 +104,10 @@ where if let Some(query) = request.uri().query() { let potential_version_requirement = query.split('&').find_map(|pair| { - if pair.starts_with("api-version=") { - if let Some(version_requirement) = pair.split('=').nth(1) { - return Some(version_requirement); - } + if pair.starts_with("api-version=") + && let Some(version_requirement) = pair.split('=').nth(1) + { + return Some(version_requirement); } None }); @@ -298,12 +298,11 @@ where } fn has_request_body(&self, req: &Request) -> bool { - if let Some(length) = req.headers().get(CONTENT_LENGTH) { - if let Ok(length) = length.to_str() { - if let Ok(length) = length.parse::() { - return length > 0; - } - } + if let Some(length) = req.headers().get(CONTENT_LENGTH) + && let Ok(length) = length.to_str() + && let Ok(length) = length.parse::() + { + return length > 0; } false } diff --git a/server/http/src/test_utils.rs b/server/http/src/test_utils.rs index 3ad4586c8fc..114b729e385 100644 --- a/server/http/src/test_utils.rs +++ b/server/http/src/test_utils.rs @@ -1,5 +1,5 @@ use graph::http_body_util::{BodyExt, Full}; -use graph::hyper::{body::Bytes, header::ACCESS_CONTROL_ALLOW_ORIGIN, Response, StatusCode}; +use graph::hyper::{Response, StatusCode, body::Bytes, header::ACCESS_CONTROL_ALLOW_ORIGIN}; use graph::prelude::serde_json; /// Asserts that the response is a successful GraphQL response; returns its `"data"` field. diff --git a/server/http/tests/server.rs b/server/http/tests/server.rs index 812dd25ef63..74e7cd13c0e 100644 --- a/server/http/tests/server.rs +++ b/server/http/tests/server.rs @@ -197,7 +197,10 @@ mod test { let errors = assert_error_response(response, StatusCode::BAD_REQUEST, false).await; let message = errors[0].as_str().expect("Error message is not a string"); - assert_eq!(message, "{\"error\":\"GraphQL server error (client error): The \\\"query\\\" field is missing in request data\"}"); + assert_eq!( + message, + "{\"error\":\"GraphQL server error (client error): The \\\"query\\\" field is missing in request data\"}" + ); } #[graph::test] diff --git a/server/index-node/src/explorer.rs b/server/index-node/src/explorer.rs index 8bcd39d7f8b..728fc228129 100644 --- a/server/index-node/src/explorer.rs +++ b/server/index-node/src/explorer.rs @@ -18,7 +18,7 @@ use graph::{ }, data::subgraph::status, object, - prelude::{serde_json, warn, Logger, ENV_VARS}, + prelude::{ENV_VARS, Logger, serde_json, warn}, util::timed_cache::TimedCache, }; diff --git a/server/index-node/src/resolver.rs b/server/index-node/src/resolver.rs index 4c43c4d8ec1..5d23483265e 100644 --- a/server/index-node/src/resolver.rs +++ b/server/index-node/src/resolver.rs @@ -6,18 +6,18 @@ use graph::data::store::Id; use graph::prelude::alloy::primitives::Address; use graph::schema::EntityType; -use git_testament::{git_testament, CommitKind}; +use git_testament::{CommitKind, git_testament}; use graph::amp; use graph::blockchain::{Blockchain, BlockchainKind, BlockchainMap}; use graph::components::link_resolver::LinkResolverContext; use graph::components::store::{BlockPtrForNumber, BlockStore, QueryPermit, Store}; use graph::components::versions::VERSIONS; -use graph::data::graphql::{object, IntoValue, ObjectOrInterface, ValueMap}; -use graph::data::subgraph::{status, DeploymentFeatures}; +use graph::data::graphql::{IntoValue, ObjectOrInterface, ValueMap, object}; +use graph::data::subgraph::{DeploymentFeatures, status}; use graph::data::value::Object; use graph::futures03::TryFutureExt; use graph::prelude::*; -use graph_graphql::prelude::{a, ExecutionContext, Resolver}; +use graph_graphql::prelude::{ExecutionContext, Resolver, a}; use crate::auth::PoiProtection; diff --git a/server/index-node/src/server.rs b/server/index-node/src/server.rs index 00b62c09ca2..e59e3407c4d 100644 --- a/server/index-node/src/server.rs +++ b/server/index-node/src/server.rs @@ -3,7 +3,7 @@ use graph::{ blockchain::BlockchainMap, cheap_clone::CheapClone, components::{ - server::server::{start, ServerHandle}, + server::server::{ServerHandle, start}, store::Store, }, prelude::*, diff --git a/server/index-node/src/service.rs b/server/index-node/src/service.rs index 09ddfd29038..359da3883f4 100644 --- a/server/index-node/src/service.rs +++ b/server/index-node/src/service.rs @@ -13,14 +13,14 @@ use graph::hyper::header::{ self, ACCESS_CONTROL_ALLOW_HEADERS, ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_ALLOW_ORIGIN, CONTENT_TYPE, LOCATION, }; -use graph::hyper::{body::Body, Method, Request, Response, StatusCode}; +use graph::hyper::{Method, Request, Response, StatusCode, body::Body}; use graph::amp; use graph::components::{server::query::ServerError, store::Store}; use graph::data::query::{Query, QueryError, QueryResult, QueryResults}; use graph::prelude::{q, serde_json}; -use graph::slog::{debug, error, Logger}; -use graph_graphql::prelude::{execute_query, Query as PreparedQuery, QueryExecutionOptions}; +use graph::slog::{Logger, debug, error}; +use graph_graphql::prelude::{Query as PreparedQuery, QueryExecutionOptions, execute_query}; use crate::auth::bearer_token; diff --git a/server/json-rpc/src/handlers.rs b/server/json-rpc/src/handlers.rs index eda2ed67154..442347cfdb5 100644 --- a/server/json-rpc/src/handlers.rs +++ b/server/json-rpc/src/handlers.rs @@ -8,16 +8,16 @@ use std::fmt::Debug; use std::net::SocketAddr; use std::sync::Arc; +use axum::Json; use axum::extract::{ConnectInfo, State}; use axum::http::{HeaderMap, StatusCode}; use axum::response::IntoResponse; -use axum::Json; use graph::prelude::{ - DeploymentHash, NodeId, SubgraphName, SubgraphRegistrar, SubgraphRegistrarError, ENV_VARS, + DeploymentHash, ENV_VARS, NodeId, SubgraphName, SubgraphRegistrar, SubgraphRegistrarError, }; use serde::Deserialize; use serde_json::{self, Value as JsonValue}; -use slog::{error, info, Logger}; +use slog::{Logger, error, info}; use crate::jsonrpc::{JsonRpcError, JsonRpcId, JsonRpcRequest, JsonRpcResponse}; diff --git a/server/json-rpc/src/server.rs b/server/json-rpc/src/server.rs index 0495d186b1a..5fe5905ba70 100644 --- a/server/json-rpc/src/server.rs +++ b/server/json-rpc/src/server.rs @@ -6,14 +6,14 @@ use std::net::{Ipv4Addr, SocketAddr}; use std::sync::Arc; -use axum::routing::post; use axum::Router; +use axum::routing::post; use graph::prelude::{NodeId, SubgraphRegistrar}; -use slog::{info, Logger}; +use slog::{Logger, info}; use thiserror::Error; use tokio::sync::Notify; -use crate::handlers::{jsonrpc_handler, AppState}; +use crate::handlers::{AppState, jsonrpc_handler}; /// Errors that can occur when starting the JSON-RPC server. #[derive(Debug, Error)] diff --git a/server/metrics/src/lib.rs b/server/metrics/src/lib.rs index 7526bf7dc6c..d2fb2e747fe 100644 --- a/server/metrics/src/lib.rs +++ b/server/metrics/src/lib.rs @@ -1,9 +1,9 @@ use std::sync::Arc; -use graph::components::server::server::{start, ServerHandle}; +use graph::components::server::server::{ServerHandle, start}; use graph::http_body_util::Full; -use graph::hyper::header::{ACCESS_CONTROL_ALLOW_ORIGIN, CONTENT_TYPE}; use graph::hyper::Response; +use graph::hyper::header::{ACCESS_CONTROL_ALLOW_ORIGIN, CONTENT_TYPE}; use graph::prelude::*; use graph::prometheus::{Encoder, Registry, TextEncoder}; diff --git a/store/postgres/examples/layout.rs b/store/postgres/examples/layout.rs index cab97889cba..e009e61e111 100644 --- a/store/postgres/examples/layout.rs +++ b/store/postgres/examples/layout.rs @@ -1,7 +1,7 @@ extern crate clap; extern crate graph_store_postgres; -use clap::{arg, Command}; +use clap::{Command, arg}; use graph::schema::InputSchema; use std::collections::BTreeSet; use std::process::exit; diff --git a/store/postgres/src/advisory_lock.rs b/store/postgres/src/advisory_lock.rs index 6b0fc671ffa..6e9b9fbf0ac 100644 --- a/store/postgres/src/advisory_lock.rs +++ b/store/postgres/src/advisory_lock.rs @@ -17,9 +17,9 @@ use diesel::sql_types::Bool; use diesel_async::RunQueryDsl; use graph::prelude::StoreError; +use crate::AsyncPgConnection; use crate::command_support::catalog::Site; use crate::primary::DeploymentId; -use crate::AsyncPgConnection; /// A locking scope for a particular deployment. We use different scopes for /// different purposes, and in each scope we use an advisory lock for each diff --git a/store/postgres/src/block_range.rs b/store/postgres/src/block_range.rs index 4383ab80d7e..d6877957dea 100644 --- a/store/postgres/src/block_range.rs +++ b/store/postgres/src/block_range.rs @@ -8,7 +8,7 @@ use diesel::sql_types::{Integer, Range}; use graph::env::ENV_VARS; use std::ops::{Bound, RangeBounds, RangeFrom}; -use graph::prelude::{lazy_static, BlockNumber, BlockPtr, BLOCK_NUMBER_MAX}; +use graph::prelude::{BLOCK_NUMBER_MAX, BlockNumber, BlockPtr, lazy_static}; use crate::relational::{SqlName, Table}; diff --git a/store/postgres/src/block_store.rs b/store/postgres/src/block_store.rs index 87ecc5358db..0ae4b05597a 100644 --- a/store/postgres/src/block_store.rs +++ b/store/postgres/src/block_store.rs @@ -4,13 +4,13 @@ use graph::{components::store::BLOCK_CACHE_SIZE, parking_lot::RwLock}; use anyhow::anyhow; use async_trait::async_trait; -use diesel::{sql_query, ExpressionMethods as _, QueryDsl}; -use diesel_async::{scoped_futures::ScopedFutureExt, RunQueryDsl}; +use diesel::{ExpressionMethods as _, QueryDsl, sql_query}; +use diesel_async::{RunQueryDsl, scoped_futures::ScopedFutureExt}; use graph::{ blockchain::ChainIdentifier, components::store::{BlockStore as BlockStoreTrait, QueryPermit}, derive::CheapClone, - prelude::{error, info, warn, BlockNumber, BlockPtr, Logger, ENV_VARS}, + prelude::{BlockNumber, BlockPtr, ENV_VARS, Logger, error, info, warn}, slog::o, }; use graph::{ @@ -21,11 +21,11 @@ use graph::{internal_error, prelude::CheapClone}; use graph::{prelude::StoreError, util::timed_cache::TimedCache}; use crate::{ + AsyncPgConnection, ChainStore, NotificationSender, PRIMARY_SHARD, Shard, chain_head_listener::ChainHeadUpdateSender, chain_store::{ChainStoreMetrics, Storage}, pool::ConnectionPool, primary::Mirror as PrimaryMirror, - AsyncPgConnection, ChainStore, NotificationSender, Shard, PRIMARY_SHARD, }; use self::primary::Chain; @@ -40,7 +40,7 @@ const SUPPORTED_DB_VERSION: i64 = 3; pub mod primary { use std::convert::TryFrom; - use diesel::{delete, insert_into, update, ExpressionMethods, OptionalExtension, QueryDsl}; + use diesel::{ExpressionMethods, OptionalExtension, QueryDsl, delete, insert_into, update}; use diesel_async::RunQueryDsl; use graph::{ blockchain::{BlockHash, ChainIdentifier}, @@ -48,7 +48,7 @@ pub mod primary { prelude::StoreError, }; - use crate::{chain_store::Storage, AsyncPgConnection}; + use crate::{AsyncPgConnection, chain_store::Storage}; use crate::{ConnectionPool, Shard}; table! { diff --git a/store/postgres/src/catalog.rs b/store/postgres/src/catalog.rs index 83bc7528900..809899c148e 100644 --- a/store/postgres/src/catalog.rs +++ b/store/postgres/src/catalog.rs @@ -1,11 +1,11 @@ use diesel::select; use diesel::sql_query; use diesel::sql_types::{Bool, Integer}; -use diesel::{insert_into, OptionalExtension}; use diesel::{ - sql_types::{Array, BigInt, Double, Nullable, Text}, ExpressionMethods, QueryDsl, + sql_types::{Array, BigInt, Double, Nullable, Text}, }; +use diesel::{OptionalExtension, insert_into}; use diesel_async::{RunQueryDsl, SimpleAsyncConnection}; use graph::components::store::VersionStats; use graph::prelude::BlockNumber; @@ -20,14 +20,14 @@ use std::time::Duration; use graph::prelude::anyhow::anyhow; use graph::{ data::subgraph::schema::POI_TABLE, - prelude::{lazy_static, StoreError, BLOCK_NUMBER_MAX}, + prelude::{BLOCK_NUMBER_MAX, StoreError, lazy_static}, }; use crate::AsyncPgConnection; use crate::{ block_range::BLOCK_RANGE_COLUMN, pool::ForeignServer, - primary::{Namespace, Site, NAMESPACE_PUBLIC}, + primary::{NAMESPACE_PUBLIC, Namespace, Site}, relational::SqlName, }; diff --git a/store/postgres/src/chain_head_listener.rs b/store/postgres/src/chain_head_listener.rs index 035e10f377a..2502fd7a631 100644 --- a/store/postgres/src/chain_head_listener.rs +++ b/store/postgres/src/chain_head_listener.rs @@ -1,7 +1,7 @@ use graph::futures03::{self, FutureExt}; use graph::{ blockchain::ChainHeadUpdateStream, - prelude::{tokio, MetricsRegistry, StoreError}, + prelude::{MetricsRegistry, StoreError, tokio}, prometheus::{CounterVec, GaugeVec}, util::timed_rw_lock::TimedRwLock, }; @@ -11,15 +11,15 @@ use std::sync::Arc; use lazy_static::lazy_static; use crate::{ + NotificationSender, notification_listener::{JsonNotification, NotificationListener, SafeChannelName}, pool::ConnectionPool, - NotificationSender, }; use graph::blockchain::ChainHeadUpdateListener as ChainHeadUpdateListenerTrait; use graph::prelude::serde::{Deserialize, Serialize}; use graph::prelude::serde_json::{self, json}; use graph::prelude::tokio::sync::{mpsc::Receiver, watch}; -use graph::prelude::{crit, debug, o, CheapClone, Logger, ENV_VARS}; +use graph::prelude::{CheapClone, ENV_VARS, Logger, crit, debug, o}; lazy_static! { pub static ref CHANNEL_NAME: SafeChannelName = diff --git a/store/postgres/src/chain_store.rs b/store/postgres/src/chain_store.rs index e1d9bea2538..3fe39462a98 100644 --- a/store/postgres/src/chain_store.rs +++ b/store/postgres/src/chain_store.rs @@ -1,18 +1,18 @@ use anyhow::anyhow; use async_trait::async_trait; use diesel::sql_types::Text; -use diesel::{insert_into, update, ExpressionMethods, OptionalExtension, QueryDsl}; +use diesel::{ExpressionMethods, OptionalExtension, QueryDsl, insert_into, update}; use diesel_async::AsyncConnection; -use diesel_async::{scoped_futures::ScopedFutureExt, RunQueryDsl}; +use diesel_async::{RunQueryDsl, scoped_futures::ScopedFutureExt}; use graph::components::store::ChainHeadStore; use graph::data::store::ethereum::call; use graph::env::ENV_VARS; use graph::parking_lot::RwLock; -use graph::prelude::alloy::primitives::B256; use graph::prelude::MetricsRegistry; +use graph::prelude::alloy::primitives::B256; use graph::prometheus::{CounterVec, GaugeVec}; -use graph::slog::{info, o, Logger}; +use graph::slog::{Logger, info, o}; use graph::stable_hash::crypto_stable_hash; use graph::util::herd_cache::HerdCache; @@ -31,15 +31,15 @@ use graph::blockchain::{Block, BlockHash, ChainIdentifier, ExtendedBlockPtr}; use graph::cheap_clone::CheapClone; use graph::components::ethereum::CachedBlock; use graph::prelude::{ - serde_json as json, transaction_receipt::LightTransactionReceipt, BlockNumber, BlockPtr, - CachedEthereumCall, ChainStore as ChainStoreTrait, Error, EthereumCallCache, - StaleCallCacheResult, StoreError, + BlockNumber, BlockPtr, CachedEthereumCall, ChainStore as ChainStoreTrait, Error, + EthereumCallCache, StaleCallCacheResult, StoreError, serde_json as json, + transaction_receipt::LightTransactionReceipt, }; use graph::{ensure, internal_error}; use self::recent_blocks_cache::RecentBlocksCache; -use crate::vid_batcher::AdaptiveBatchSize; use crate::AsyncPgConnection; +use crate::vid_batcher::AdaptiveBatchSize; use crate::{chain_head_listener::ChainHeadUpdateSender, pool::ConnectionPool}; /// Our own internal notion of a block @@ -127,13 +127,13 @@ pub use data::Storage; /// Encapuslate access to the blocks table for a chain. mod data { use crate::diesel::dsl::IntervalDsl; - use crate::{catalog, AsyncPgConnection}; + use crate::{AsyncPgConnection, catalog}; use diesel::dsl::sql; use diesel::insert_into; use diesel::sql_types::{Array, Binary, Bool, Nullable, Text}; use diesel::{ - delete, sql_query, BoolExpressionMethods, ExpressionMethods, JoinOnDsl, - NullableExpressionMethods, OptionalExtension, QueryDsl, + BoolExpressionMethods, ExpressionMethods, JoinOnDsl, NullableExpressionMethods, + OptionalExtension, QueryDsl, delete, sql_query, }; use diesel::{ deserialize::FromSql, @@ -151,8 +151,8 @@ mod data { use graph::prelude::alloy::primitives::{Address, B256}; use graph::prelude::transaction_receipt::LightTransactionReceipt; use graph::prelude::{ - info, serde_json as json, BlockNumber, BlockPtr, CachedEthereumCall, Error, Logger, - StoreError, + BlockNumber, BlockPtr, CachedEthereumCall, Error, Logger, StoreError, info, + serde_json as json, }; use std::collections::HashMap; @@ -2235,11 +2235,11 @@ impl ChainHeadPtrCache { return None; } let guard = self.entry.read(); - if let Some((value, expires)) = guard.as_ref() { - if Instant::now() < *expires { - self.metrics.record_chain_head_ptr_cache_hit(&self.chain); - return Some(value.clone()); - } + if let Some((value, expires)) = guard.as_ref() + && Instant::now() < *expires + { + self.metrics.record_chain_head_ptr_cache_hit(&self.chain); + return Some(value.clone()); } self.metrics.record_chain_head_ptr_cache_miss(&self.chain); None @@ -2273,39 +2273,39 @@ impl ChainHeadPtrCache { // Only update estimate if we have a previous value and block number advanced // (skip reorgs where new block number <= old) - if let Some(old_ptr) = old_value.as_ref() { - if new_value.number > old_ptr.number { - let mut last_change = self.last_change.write(); - let delta_ms = now.duration_since(*last_change).as_millis() as u64; - *last_change = now; - - let blocks_advanced = (new_value.number - old_ptr.number) as u64; - - // Increment observation count - let obs = AtomicU64::fetch_add(&self.observations, 1, Ordering::Relaxed); - - // Ignore unreasonable deltas (> 60s) - if delta_ms > 0 && delta_ms < 60_000 { - let per_block_ms = delta_ms / blocks_advanced; - let new_estimate = if obs == 0 { - // First observation - use as initial estimate - per_block_ms - } else { - // EWMA: new = 0.8 * old + 0.2 * observed - let old_estimate = - AtomicU64::load(&self.estimated_block_time_ms, Ordering::Relaxed); - (old_estimate * 4 + per_block_ms) / 5 - }; - AtomicU64::store( - &self.estimated_block_time_ms, - new_estimate, - Ordering::Relaxed, - ); + if let Some(old_ptr) = old_value.as_ref() + && new_value.number > old_ptr.number + { + let mut last_change = self.last_change.write(); + let delta_ms = now.duration_since(*last_change).as_millis() as u64; + *last_change = now; + + let blocks_advanced = (new_value.number - old_ptr.number) as u64; + + // Increment observation count + let obs = AtomicU64::fetch_add(&self.observations, 1, Ordering::Relaxed); + + // Ignore unreasonable deltas (> 60s) + if delta_ms > 0 && delta_ms < 60_000 { + let per_block_ms = delta_ms / blocks_advanced; + let new_estimate = if obs == 0 { + // First observation - use as initial estimate + per_block_ms + } else { + // EWMA: new = 0.8 * old + 0.2 * observed + let old_estimate = + AtomicU64::load(&self.estimated_block_time_ms, Ordering::Relaxed); + (old_estimate * 4 + per_block_ms) / 5 + }; + AtomicU64::store( + &self.estimated_block_time_ms, + new_estimate, + Ordering::Relaxed, + ); - // Update metric gauge - self.metrics - .set_chain_head_ptr_block_time(&self.chain, new_estimate); - } + // Update metric gauge + self.metrics + .set_chain_head_ptr_block_time(&self.chain, new_estimate); } } diff --git a/store/postgres/src/copy.rs b/store/postgres/src/copy.rs index 54c1a03a896..22c37bf2498 100644 --- a/store/postgres/src/copy.rs +++ b/store/postgres/src/copy.rs @@ -16,30 +16,30 @@ use std::{ future::Future, pin::Pin, sync::{ - atomic::{AtomicBool, AtomicI64, Ordering}, Arc, Mutex, + atomic::{AtomicBool, AtomicI64, Ordering}, }, time::{Duration, Instant}, }; use diesel::{ - dsl::sql, insert_into, select, sql_query, update, ExpressionMethods, OptionalExtension, - QueryDsl, + ExpressionMethods, OptionalExtension, QueryDsl, dsl::sql, insert_into, select, sql_query, + update, }; use diesel_async::{ - scoped_futures::{ScopedBoxFuture, ScopedFutureExt}, AsyncConnection, + scoped_futures::{ScopedBoxFuture, ScopedFutureExt}, }; use diesel_async::{RunQueryDsl, SimpleAsyncConnection}; use graph::{ futures03::{ - future::{select_all, BoxFuture}, FutureExt as _, + future::{BoxFuture, select_all}, }, internal_error, prelude::{ - info, lazy_static, o, warn, BlockNumber, BlockPtr, CheapClone, Logger, StoreError, ENV_VARS, + BlockNumber, BlockPtr, CheapClone, ENV_VARS, Logger, StoreError, info, lazy_static, o, warn, }, schema::EntityType, slog::error, @@ -47,13 +47,12 @@ use graph::{ use itertools::Itertools; use crate::{ - advisory_lock, catalog, deployment, + AsyncPgConnection, ConnectionPool, advisory_lock, catalog, deployment, dynds::DataSourcesTable, primary::{DeploymentId, Primary, Site}, - relational::{index::IndexList, Layout, Table}, + relational::{Layout, Table, index::IndexList}, relational_queries as rq, vid_batcher::{VidBatcher, VidRange}, - AsyncPgConnection, ConnectionPool, }; const LOG_INTERVAL: Duration = Duration::from_secs(3 * 60); @@ -151,7 +150,8 @@ impl CopyState { src.site.deployment, dst.site.deployment, stored_target_block, - target_block)); + target_block + )); } if src_id != src.site.id { return Err(internal_error!( diff --git a/store/postgres/src/deployment.rs b/store/postgres/src/deployment.rs index 15e64321a99..1a7faeed62e 100644 --- a/store/postgres/src/deployment.rs +++ b/store/postgres/src/deployment.rs @@ -1,7 +1,7 @@ //! Utilities for dealing with deployment metadata. Any connection passed //! into these methods must be for the shard that holds the actual //! deployment data and metadata -use crate::{advisory_lock, detail::GraphNodeVersion, primary::DeploymentId, AsyncPgConnection}; +use crate::{AsyncPgConnection, advisory_lock, detail::GraphNodeVersion, primary::DeploymentId}; use diesel::{ dsl::{count, delete, insert_into, now, select, sql, update}, sql_types::{Bool, Integer}, @@ -18,7 +18,7 @@ use graph::{ data::subgraph::schema::SubgraphError, env::ENV_VARS, schema::EntityType, - slog::{debug, Logger}, + slog::{Logger, debug}, }; use graph::{components::store::StoreResult, semver::Version}; use graph::{ @@ -26,7 +26,7 @@ use graph::{ util::backoff::ExponentialBackoff, }; use graph::{ - prelude::{anyhow, hex, BlockNumber, BlockPtr, DeploymentHash, DeploymentState, StoreError}, + prelude::{BlockNumber, BlockPtr, DeploymentHash, DeploymentState, StoreError, anyhow, hex}, schema::InputSchema, }; use stable_hash_legacy::crypto::SetHasher; @@ -55,8 +55,8 @@ impl SubgraphHealth { impl From for graph::data::subgraph::schema::SubgraphHealth { fn from(health: SubgraphHealth) -> Self { - use graph::data::subgraph::schema::SubgraphHealth as H; use SubgraphHealth as Db; + use graph::data::subgraph::schema::SubgraphHealth as H; match health { Db::Failed => H::Failed, @@ -478,13 +478,13 @@ pub async fn transact_block( // `where` clause of the `update` statement, but that caused Postgres to use bitmap scans instead // of a simple primary key lookup. So a separate query it is. let block_ptr = block_ptr(conn, site).await?; - if let Some(block_ptr_from) = block_ptr { - if block_ptr_from.number >= ptr.number { - return Err(StoreError::DuplicateBlockProcessing( - site.deployment.clone(), - ptr.number, - )); - } + if let Some(block_ptr_from) = block_ptr + && block_ptr_from.number >= ptr.number + { + return Err(StoreError::DuplicateBlockProcessing( + site.deployment.clone(), + ptr.number, + )); } reset_reorg_count(conn, site).await?; @@ -579,13 +579,12 @@ pub async fn get_subgraph_firehose_cursor( ) -> Result, StoreError> { use head as h; - let res = h::table + h::table .filter(h::id.eq(site.id)) .select(h::firehose_cursor) .first::>(conn) .await - .map_err(StoreError::from); - res + .map_err(StoreError::from) } pub async fn revert_block_ptr( diff --git a/store/postgres/src/deployment_store.rs b/store/postgres/src/deployment_store.rs index 4d8df5c3a28..22cff2d4f34 100644 --- a/store/postgres/src/deployment_store.rs +++ b/store/postgres/src/deployment_store.rs @@ -5,8 +5,8 @@ use diesel_async::{AsyncConnection as _, RunQueryDsl, SimpleAsyncConnection}; use tokio::task::JoinHandle; use graph::anyhow::Context; -use graph::blockchain::block_stream::{EntitySourceOperation, FirehoseCursor}; use graph::blockchain::BlockTime; +use graph::blockchain::block_stream::{EntitySourceOperation, FirehoseCursor}; use graph::components::store::write::RowGroup; use graph::components::store::{ Batch, DeploymentLocator, DerivedEntityQuery, DumpReporter, PrunePhase, PruneReporter, @@ -17,7 +17,7 @@ use graph::components::versions::VERSIONS; use graph::data::graphql::IntoValue; use graph::data::query::Trace; use graph::data::store::{IdList, SqlQueryObject}; -use graph::data::subgraph::{status, SPEC_VERSION_0_0_6}; +use graph::data::subgraph::{SPEC_VERSION_0_0_6, status}; use graph::data_source::CausalityRegion; use graph::derive::CheapClone; use graph::futures03::FutureExt; @@ -33,7 +33,7 @@ use std::ops::Bound; use std::ops::{Deref, Range}; use std::path::{Path, PathBuf}; use std::str::FromStr; -use std::sync::{atomic::AtomicUsize, Arc, Mutex}; +use std::sync::{Arc, Mutex, atomic::AtomicUsize}; use std::time::{Duration, Instant}; use graph::components::store::EntityCollection; @@ -41,9 +41,9 @@ use graph::components::subgraph::{ProofOfIndexingFinisher, ProofOfIndexingVersio use graph::data::subgraph::schema::{DeploymentCreate, SubgraphError}; use graph::internal_error; use graph::prelude::{ - anyhow, debug, info, o, warn, AttributeNames, BlockNumber, BlockPtr, CheapClone, - DeploymentHash, DeploymentState, Entity, EntityQuery, Error, Logger, QueryExecutionError, - StopwatchMetrics, StoreError, UnfailOutcome, Value, ENV_VARS, + AttributeNames, BlockNumber, BlockPtr, CheapClone, DeploymentHash, DeploymentState, ENV_VARS, + Entity, EntityQuery, Error, Logger, QueryExecutionError, StopwatchMetrics, StoreError, + UnfailOutcome, Value, anyhow, debug, info, o, warn, }; use graph::schema::{ApiSchema, EntityKey, EntityType, InputSchema}; @@ -53,10 +53,10 @@ use crate::detail::ErrorDetail; use crate::dynds::DataSourcesTable; use crate::primary::{DeploymentId, Primary}; use crate::relational::index::{CreateIndex, IndexList, Method}; -use crate::relational::{self, Layout, LayoutCache, SqlName, Table, STATEMENT_TIMEOUT}; +use crate::relational::{self, Layout, LayoutCache, STATEMENT_TIMEOUT, SqlName, Table}; use crate::relational_queries::{FromEntityData, JSONData}; -use crate::{advisory_lock, catalog, retry, AsyncPgConnection}; -use crate::{detail, ConnectionPool}; +use crate::{AsyncPgConnection, advisory_lock, catalog, retry}; +use crate::{ConnectionPool, detail}; use crate::{dynds, primary::Site}; /// When connected to read replicas, this allows choosing which DB server to use for an operation. @@ -1476,24 +1476,27 @@ impl DeploymentStore { // Confidence check on revert to ensure we go backward only if block_ptr_to.number >= deployment_head.number { - panic!("revert_block_operations must revert only backward, you are trying to revert forward going from subgraph block {} to new block {}", deployment_head, block_ptr_to); + panic!( + "revert_block_operations must revert only backward, you are trying to revert forward going from subgraph block {} to new block {}", + deployment_head, block_ptr_to + ); } // Don't revert past a graft point let info = self .subgraph_info_with_conn(&mut conn, site.cheap_clone()) .await?; - if let Some(graft_block) = info.graft_block { - if graft_block > block_ptr_to.number { - return Err(internal_error!( - "Can not revert subgraph `{}` to block {} as it was \ + if let Some(graft_block) = info.graft_block + && graft_block > block_ptr_to.number + { + return Err(internal_error!( + "Can not revert subgraph `{}` to block {} as it was \ grafted at block {} and reverting past a graft point \ is not possible", - site.deployment.clone(), - block_ptr_to.number, - graft_block - )); - } + site.deployment.clone(), + block_ptr_to.number, + graft_block + )); } self.rewind_or_truncate_with_conn(&mut conn, site, block_ptr_to, firehose_cursor, false) diff --git a/store/postgres/src/detail.rs b/store/postgres/src/detail.rs index 9e1827fcddb..b59a53cdca4 100644 --- a/store/postgres/src/detail.rs +++ b/store/postgres/src/detail.rs @@ -14,11 +14,11 @@ use git_testament::{git_testament, git_testament_macros}; use graph::blockchain::BlockHash; use graph::data::store::scalar::ToPrimitive; use graph::data::subgraph::schema::{SubgraphError, SubgraphManifestEntity}; -use graph::prelude::alloy::primitives::B256; use graph::prelude::BlockNumber; +use graph::prelude::alloy::primitives::B256; use graph::prelude::{ - chrono::{DateTime, Utc}, BlockPtr, DeploymentHash, StoreError, SubgraphDeploymentEntity, + chrono::{DateTime, Utc}, }; use graph::schema::InputSchema; use graph::{data::subgraph::status, internal_error}; @@ -27,12 +27,12 @@ use std::collections::HashMap; use std::convert::TryFrom; use std::{ops::Bound, sync::Arc}; +use crate::AsyncPgConnection; use crate::deployment::{ - deployment as subgraph_deployment, graph_node_versions, head as subgraph_head, subgraph_error, - subgraph_manifest, SubgraphHealth as HealthType, + SubgraphHealth as HealthType, deployment as subgraph_deployment, graph_node_versions, + head as subgraph_head, subgraph_error, subgraph_manifest, }; use crate::primary::{DeploymentId, Site}; -use crate::AsyncPgConnection; git_testament_macros!(version); git_testament!(TESTAMENT); diff --git a/store/postgres/src/dynds/mod.rs b/store/postgres/src/dynds/mod.rs index a1155c96678..e53474ae280 100644 --- a/store/postgres/src/dynds/mod.rs +++ b/store/postgres/src/dynds/mod.rs @@ -3,9 +3,9 @@ pub(crate) mod shared; pub(crate) use private::DataSourcesTable; -use crate::{primary::Site, AsyncPgConnection}; +use crate::{AsyncPgConnection, primary::Site}; use graph::{ - components::store::{write, StoredDynamicDataSource}, + components::store::{StoredDynamicDataSource, write}, data_source::CausalityRegion, internal_error, prelude::{BlockNumber, StoreError}, diff --git a/store/postgres/src/dynds/private.rs b/store/postgres/src/dynds/private.rs index 6a247f824e5..714e1741245 100644 --- a/store/postgres/src/dynds/private.rs +++ b/store/postgres/src/dynds/private.rs @@ -1,25 +1,25 @@ use std::{collections::HashMap, ops::Bound}; use diesel::{ - pg::{sql_types, Pg}, + ExpressionMethods, OptionalExtension, QueryDsl, QueryResult, + pg::{Pg, sql_types}, query_builder::{AstPass, QueryFragment, QueryId}, sql_query, sql_types::{BigInt, Binary, Bool, Integer, Jsonb, Nullable, Text}, - ExpressionMethods, OptionalExtension, QueryDsl, QueryResult, }; use diesel_async::RunQueryDsl; use graph::{ - anyhow::{anyhow, Context}, - components::store::{write, StoredDynamicDataSource}, + anyhow::{Context, anyhow}, + components::store::{StoredDynamicDataSource, write}, data_source::CausalityRegion, internal_error, - prelude::{serde_json, BlockNumber, StoreError}, + prelude::{BlockNumber, StoreError, serde_json}, }; use crate::parquet::convert::DataSourceRestoreRow; -use crate::{primary::Namespace, relational_queries::POSTGRES_MAX_PARAMETERS, AsyncPgConnection}; +use crate::{AsyncPgConnection, primary::Namespace, relational_queries::POSTGRES_MAX_PARAMETERS}; type DynTable = diesel_dynamic_schema::Table; type DynColumn = diesel_dynamic_schema::Column; @@ -181,10 +181,10 @@ impl DataSourcesTable { // Offchain data sources have a unique causality region assigned from a sequence in the // database, while onchain data sources always have causality region 0. let query = format!( - "insert into {}(block_range, manifest_idx, param, context, causality_region, done_at) \ + "insert into {}(block_range, manifest_idx, param, context, causality_region, done_at) \ values (int4range($1, null), $2, $3, $4, $5, $6)", - self.qname - ); + self.qname + ); let query = sql_query(query) .bind::, _>(creation_block) @@ -311,10 +311,10 @@ impl DataSourcesTable { if count > 1 { return Err(internal_error!( - "expected to remove at most one offchain data source but would remove {}, causality region: {}", - count, - ds.causality_region - )); + "expected to remove at most one offchain data source but would remove {}, causality region: {}", + count, + ds.causality_region + )); } } } diff --git a/store/postgres/src/dynds/shared.rs b/store/postgres/src/dynds/shared.rs index 3562e4584f2..d5e86332115 100644 --- a/store/postgres/src/dynds/shared.rs +++ b/store/postgres/src/dynds/shared.rs @@ -11,16 +11,16 @@ use diesel::{ use diesel_async::RunQueryDsl; use graph::{ - components::store::{write, StoredDynamicDataSource}, + components::store::{StoredDynamicDataSource, write}, data::store::scalar::ToPrimitive, data_source::CausalityRegion, internal_error, - prelude::{serde_json, BigDecimal, BlockNumber, DeploymentHash, StoreError}, + prelude::{BigDecimal, BlockNumber, DeploymentHash, StoreError, serde_json}, }; -use crate::primary::Site; use crate::AsyncPgConnection; use crate::ForeignServer; +use crate::primary::Site; table! { subgraphs.dynamic_ethereum_contract_data_source (vid) { @@ -67,9 +67,10 @@ pub(super) async fn load( if address.len() != 20 { return Err(internal_error!( "Data source address `0x{:?}` for dynamic data source {} should be 20 bytes long but is {} bytes long", - address, vid, - address.len() - )); + address, + vid, + address.len() + )); } let manifest_idx = manifest_idx_and_name diff --git a/store/postgres/src/fork.rs b/store/postgres/src/fork.rs index c8602e0a519..07241577a53 100644 --- a/store/postgres/src/fork.rs +++ b/store/postgres/src/fork.rs @@ -9,8 +9,8 @@ use graph::{ components::store::SubgraphFork as SubgraphForkTrait, internal_error, prelude::{ - anyhow, info, r::Value as RValue, reqwest, serde_json, DeploymentHash, Entity, Logger, - Serialize, StoreError, Value, ValueType, + DeploymentHash, Entity, Logger, Serialize, StoreError, Value, ValueType, anyhow, info, + r::Value as RValue, reqwest, serde_json, }, schema::Field, url::Url, @@ -228,7 +228,7 @@ mod tests { use graph::{ data::store::scalar, - prelude::{s::Type, DeploymentHash}, + prelude::{DeploymentHash, s::Type}, slog::{self, o}, }; diff --git a/store/postgres/src/jobs.rs b/store/postgres/src/jobs.rs index 2d95ef9b2f0..7a90fcdd811 100644 --- a/store/postgres/src/jobs.rs +++ b/store/postgres/src/jobs.rs @@ -7,12 +7,12 @@ use async_trait::async_trait; use diesel::{sql_query, sql_types::Double}; use diesel_async::RunQueryDsl; -use graph::prelude::{error, Logger, MetricsRegistry, StoreError, ENV_VARS}; +use graph::prelude::{ENV_VARS, Logger, MetricsRegistry, StoreError, error}; use graph::prometheus::Gauge; use graph::util::jobs::{Job, Runner}; use crate::ConnectionPool; -use crate::{unused, Store, SubgraphStore}; +use crate::{Store, SubgraphStore, unused}; pub fn register( runner: &mut Runner, diff --git a/store/postgres/src/lib.rs b/store/postgres/src/lib.rs index 44b53a7130d..a8e3e902428 100644 --- a/store/postgres/src/lib.rs +++ b/store/postgres/src/lib.rs @@ -47,7 +47,7 @@ pub mod layout_for_tests { pub use crate::block_store::FAKE_NETWORK_SHARED; pub use crate::catalog::set_account_like; pub use crate::primary::{ - make_dummy_site, Connection, Mirror, Namespace, EVENT_TAP, EVENT_TAP_ENABLED, + Connection, EVENT_TAP, EVENT_TAP_ENABLED, Mirror, Namespace, make_dummy_site, }; pub use crate::relational::*; pub mod writable { @@ -55,8 +55,8 @@ pub mod layout_for_tests { } } -pub use self::block_store::primary::{add_chain, find_chain, update_chain_name}; pub use self::block_store::BlockStore; +pub use self::block_store::primary::{add_chain, find_chain, update_chain_name}; pub use self::chain_head_listener::ChainHeadUpdateListener; pub use self::chain_store::{ChainStore, ChainStoreMetrics, Storage}; pub use self::detail::DeploymentDetail; @@ -65,28 +65,28 @@ pub use self::notification_listener::NotificationSender; pub use self::pool::{ AsyncPgConnection, ConnectionPool, ForeignServer, PoolCoordinator, PoolRole, ScopedFutureExt, }; -pub use self::primary::{db_version, RestoreMode, UnusedDeployment}; +pub use self::primary::{RestoreMode, UnusedDeployment, db_version}; pub use self::store::Store; pub use self::store_events::SubscriptionManager; -pub use self::subgraph_store::{unused, DeploymentPlacer, Shard, SubgraphStore, PRIMARY_SHARD}; +pub use self::subgraph_store::{DeploymentPlacer, PRIMARY_SHARD, Shard, SubgraphStore, unused}; /// This module is only meant to support command line tooling. It must not /// be used in 'normal' graph-node code pub mod command_support { pub mod catalog { pub use crate::block_store::primary as block_store; - pub use crate::catalog::{account_like, Catalog}; + pub use crate::catalog::{Catalog, account_like}; pub use crate::copy::{copy_state, copy_table_state}; + pub use crate::primary::{Connection, Mirror}; pub use crate::primary::{ - active_copies, deployment_schemas, ens_names, subgraph, subgraph_deployment_assignment, - subgraph_version, Site, + Site, active_copies, deployment_schemas, ens_names, subgraph, + subgraph_deployment_assignment, subgraph_version, }; - pub use crate::primary::{Connection, Mirror}; } pub mod index { pub use crate::relational::index::{CreateIndex, Method}; } - pub use crate::deployment::{on_sync, OnSync}; + pub use crate::deployment::{OnSync, on_sync}; pub use crate::primary::Namespace; pub use crate::relational::prune::{Phase, PruneState, PruneTableState, Viewer}; pub use crate::relational::{Catalog, Column, ColumnType, Layout, SqlName}; diff --git a/store/postgres/src/notification_listener.rs b/store/postgres/src/notification_listener.rs index 7f0e5eb51ba..c72bf4f309d 100644 --- a/store/postgres/src/notification_listener.rs +++ b/store/postgres/src/notification_listener.rs @@ -5,14 +5,14 @@ use graph::util::backoff::ExponentialBackoff; use lazy_static::lazy_static; use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode}; use postgres::Notification; -use postgres::{fallible_iterator::FallibleIterator, Client}; +use postgres::{Client, fallible_iterator::FallibleIterator}; use postgres_openssl::MakeTlsConnector; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Barrier}; use std::thread; use std::time::{Duration, Instant}; -use tokio::sync::mpsc::{channel, Receiver}; use tokio::sync::Mutex; +use tokio::sync::mpsc::{Receiver, channel}; use graph::prelude::serde_json; use graph::prelude::*; @@ -453,17 +453,17 @@ impl NotificationSender { // If we can't get the lock, another thread in this process is // already checking, and we can just skip checking - if let Ok(mut last_check) = LAST_CLEANUP_CHECK.try_lock() { - if last_check.elapsed() > ENV_VARS.store.large_notification_cleanup_interval { - diesel::sql_query(format!( - "delete from large_notifications + if let Ok(mut last_check) = LAST_CLEANUP_CHECK.try_lock() + && last_check.elapsed() > ENV_VARS.store.large_notification_cleanup_interval + { + diesel::sql_query(format!( + "delete from large_notifications where created_at < current_timestamp - interval '{}s'", - ENV_VARS.store.large_notification_cleanup_interval.as_secs(), - )) - .execute(conn) - .await?; - *last_check = Instant::now(); - } + ENV_VARS.store.large_notification_cleanup_interval.as_secs(), + )) + .execute(conn) + .await?; + *last_check = Instant::now(); } } self.sent_counter diff --git a/store/postgres/src/parquet/convert.rs b/store/postgres/src/parquet/convert.rs index 441700c09cb..b0959e8ef6a 100644 --- a/store/postgres/src/parquet/convert.rs +++ b/store/postgres/src/parquet/convert.rs @@ -11,8 +11,8 @@ use arrow::array::{ use arrow::datatypes::{DataType, Schema}; use graph::components::store::StoreError; -use graph::data::store::scalar; use graph::data::store::Value; +use graph::data::store::scalar; use graph::data::value::Word; use graph::prelude::BlockNumber; @@ -593,7 +593,7 @@ mod tests { use std::sync::Arc; use super::*; - use crate::layout_for_tests::{make_dummy_site, Catalog, Layout, Namespace}; + use crate::layout_for_tests::{Catalog, Layout, Namespace, make_dummy_site}; use crate::parquet::schema::arrow_schema; fn make_row(values: Vec) -> OidRow { diff --git a/store/postgres/src/parquet/schema.rs b/store/postgres/src/parquet/schema.rs index fd6b1d216a8..f5c06643be0 100644 --- a/store/postgres/src/parquet/schema.rs +++ b/store/postgres/src/parquet/schema.rs @@ -95,7 +95,7 @@ mod tests { use graph::prelude::DeploymentHash; use graph::schema::InputSchema; - use crate::layout_for_tests::{make_dummy_site, Catalog, Layout, Namespace}; + use crate::layout_for_tests::{Catalog, Layout, Namespace, make_dummy_site}; use super::*; @@ -188,10 +188,12 @@ mod tests { .data_type(), &DataType::Int32 ); - assert!(!schema - .field_with_name("block_range_start") - .unwrap() - .is_nullable()); + assert!( + !schema + .field_with_name("block_range_start") + .unwrap() + .is_nullable() + ); assert_eq!( schema @@ -200,10 +202,12 @@ mod tests { .data_type(), &DataType::Int32 ); - assert!(schema - .field_with_name("block_range_end") - .unwrap() - .is_nullable()); + assert!( + schema + .field_with_name("block_range_end") + .unwrap() + .is_nullable() + ); assert_eq!( schema @@ -333,22 +337,30 @@ mod tests { // Check nullability assert!(!schema.field_with_name("vid").unwrap().is_nullable()); - assert!(!schema - .field_with_name("block_range_start") - .unwrap() - .is_nullable()); - assert!(schema - .field_with_name("block_range_end") - .unwrap() - .is_nullable()); - assert!(!schema - .field_with_name("causality_region") - .unwrap() - .is_nullable()); - assert!(!schema - .field_with_name("manifest_idx") - .unwrap() - .is_nullable()); + assert!( + !schema + .field_with_name("block_range_start") + .unwrap() + .is_nullable() + ); + assert!( + schema + .field_with_name("block_range_end") + .unwrap() + .is_nullable() + ); + assert!( + !schema + .field_with_name("causality_region") + .unwrap() + .is_nullable() + ); + assert!( + !schema + .field_with_name("manifest_idx") + .unwrap() + .is_nullable() + ); assert!(schema.field_with_name("parent").unwrap().is_nullable()); assert!(schema.field_with_name("id").unwrap().is_nullable()); assert!(schema.field_with_name("param").unwrap().is_nullable()); @@ -389,10 +401,12 @@ mod tests { .data_type(), &DataType::Int32 ); - assert!(!schema - .field_with_name("block_range_end") - .unwrap() - .is_nullable()); + assert!( + !schema + .field_with_name("block_range_end") + .unwrap() + .is_nullable() + ); } #[test] diff --git a/store/postgres/src/pool/coordinator.rs b/store/postgres/src/pool/coordinator.rs index d0a7088ec47..cf733deb3f3 100644 --- a/store/postgres/src/pool/coordinator.rs +++ b/store/postgres/src/pool/coordinator.rs @@ -1,16 +1,16 @@ use graph::cheap_clone::CheapClone; -use graph::futures03::future::join_all; use graph::futures03::FutureExt as _; +use graph::futures03::future::join_all; use graph::internal_error; use graph::prelude::MetricsRegistry; -use graph::prelude::{crit, debug, error, info, o, StoreError}; +use graph::prelude::{StoreError, crit, debug, error, info, o}; use graph::slog::Logger; use std::collections::HashMap; use std::sync::{Arc, Mutex}; use crate::advisory_lock::with_migration_lock; -use crate::{Shard, PRIMARY_SHARD}; +use crate::{PRIMARY_SHARD, Shard}; use super::{ConnectionPool, ForeignServer, MigrationCount, PoolInner, PoolRole, PoolState}; diff --git a/store/postgres/src/pool/foreign_server.rs b/store/postgres/src/pool/foreign_server.rs index 78cd83116db..c2883eb929b 100644 --- a/store/postgres/src/pool/foreign_server.rs +++ b/store/postgres/src/pool/foreign_server.rs @@ -1,8 +1,8 @@ use diesel_async::SimpleAsyncConnection; use graph::{ prelude::{ + ENV_VARS, StoreError, anyhow::{self, anyhow, bail}, - StoreError, ENV_VARS, }, util::security::SafeDisplay, }; @@ -12,8 +12,8 @@ use std::fmt::Write; use postgres::config::{Config, Host}; use crate::primary::NAMESPACE_PUBLIC; -use crate::{catalog, AsyncPgConnection}; -use crate::{Shard, PRIMARY_SHARD}; +use crate::{AsyncPgConnection, catalog}; +use crate::{PRIMARY_SHARD, Shard}; use super::{PRIMARY_PUBLIC, PRIMARY_TABLES, SHARDED_TABLES}; diff --git a/store/postgres/src/pool/manager.rs b/store/postgres/src/pool/manager.rs index dbbcb288b83..5ff0198a36e 100644 --- a/store/postgres/src/pool/manager.rs +++ b/store/postgres/src/pool/manager.rs @@ -9,20 +9,20 @@ use diesel::IntoSql; use diesel_async::pooled_connection::{PoolError as DieselPoolError, PoolableConnection}; use diesel_async::{AsyncConnection, RunQueryDsl}; use graph::env::ENV_VARS; -use graph::prelude::error; use graph::prelude::AtomicMovingStats; use graph::prelude::Counter; use graph::prelude::Gauge; use graph::prelude::MetricsRegistry; use graph::prelude::PoolWaitStats; -use graph::slog::info; +use graph::prelude::error; use graph::slog::Logger; +use graph::slog::info; use std::collections::HashMap; +use std::sync::Arc; use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; -use std::sync::Arc; use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH}; use crate::pool::AsyncPool; diff --git a/store/postgres/src/pool/mod.rs b/store/postgres/src/pool/mod.rs index 9d881ca7ebd..e71740f9d6a 100644 --- a/store/postgres/src/pool/mod.rs +++ b/store/postgres/src/pool/mod.rs @@ -1,5 +1,5 @@ -use deadpool::managed::{PoolError, Timeouts}; use deadpool::Runtime; +use deadpool::managed::{PoolError, Timeouts}; use diesel::sql_query; use diesel_async::async_connection_wrapper::AsyncConnectionWrapper; use diesel_async::{AsyncConnection as _, RunQueryDsl, SimpleAsyncConnection}; @@ -11,10 +11,10 @@ use graph::derive::CheapClone; use graph::internal_error; use graph::prelude::tokio::time::Instant; use graph::prelude::{ - anyhow::anyhow, crit, debug, error, info, o, AtomicMovingStats, Gauge, Logger, PoolWaitStats, - StoreError, ENV_VARS, + AtomicMovingStats, ENV_VARS, Gauge, Logger, PoolWaitStats, StoreError, anyhow::anyhow, crit, + debug, error, info, o, }; -use graph::prelude::{tokio, MetricsRegistry}; +use graph::prelude::{MetricsRegistry, tokio}; use graph::slog::warn; use graph::util::timed_rw_lock::TimedMutex; use tokio::sync::OwnedSemaphorePermit; @@ -29,7 +29,7 @@ use std::time::Duration; use crate::catalog; use crate::pool::manager::{ConnectionManager, WaitMeter}; use crate::primary::{self, Mirror, Namespace}; -use crate::{Shard, PRIMARY_SHARD}; +use crate::{PRIMARY_SHARD, Shard}; mod coordinator; mod foreign_server; @@ -816,7 +816,11 @@ impl PoolInner { crit!(logger, "{}: {}", MSG, msg); panic!("{}: {}", MSG, msg); } else { - warn!(logger, "{}.\nPlease check the graph-node documentation for how to set up the database locale", msg); + warn!( + logger, + "{}.\nPlease check the graph-node documentation for how to set up the database locale", + msg + ); } }; Ok(()) diff --git a/store/postgres/src/primary.rs b/store/postgres/src/primary.rs index a63fc3f98b6..2e4e61b9af0 100644 --- a/store/postgres/src/primary.rs +++ b/store/postgres/src/primary.rs @@ -2,11 +2,11 @@ //! shard. Anything in this module can only be used with a database connection //! for the primary shard. use crate::{ + AsyncPgConnection, ConnectionPool, ForeignServer, NotificationSender, block_range::UNVERSIONED_RANGE, detail::DeploymentDetail, - pool::{PermittedConnection, PRIMARY_PUBLIC}, - subgraph_store::{unused, Shard, PRIMARY_SHARD}, - AsyncPgConnection, ConnectionPool, ForeignServer, NotificationSender, + pool::{PRIMARY_PUBLIC, PermittedConnection}, + subgraph_store::{PRIMARY_SHARD, Shard, unused}, }; use diesel::dsl::{delete, insert_into, sql, update}; use diesel::prelude::{ @@ -22,23 +22,23 @@ use diesel::{ sql_types::{Array, BigInt, Bool, Integer, Text}, }; use diesel_async::{ - scoped_futures::{ScopedBoxFuture, ScopedFutureExt}, RunQueryDsl, SimpleAsyncConnection as _, TransactionManager, + scoped_futures::{ScopedBoxFuture, ScopedFutureExt}, }; use graph::{ components::store::DeploymentLocator, data::{ store::scalar::ToPrimitive, - subgraph::{status, DeploymentFeatures}, + subgraph::{DeploymentFeatures, status}, }, derive::CheapClone, - futures03::{future::BoxFuture, FutureExt}, + futures03::{FutureExt, future::BoxFuture}, internal_error, prelude::{ - anyhow, + AssignmentChange, DeploymentHash, NodeId, StoreError, SubgraphName, + SubgraphVersionSwitchingMode, anyhow, chrono::{DateTime, Utc}, - serde_json, AssignmentChange, DeploymentHash, NodeId, StoreError, SubgraphName, - SubgraphVersionSwitchingMode, + serde_json, }, }; use graph::{ @@ -1006,10 +1006,10 @@ impl Connection { where F: AsyncFn(&DeploymentHash) -> Result, { + use SubgraphVersionSwitchingMode::*; use subgraph as s; use subgraph_deployment_assignment as a; use subgraph_version as v; - use SubgraphVersionSwitchingMode::*; let created_at = SystemTime::now() .duration_since(UNIX_EPOCH) diff --git a/store/postgres/src/relational.rs b/store/postgres/src/relational.rs index f5f9ab9c6dd..0665a64da74 100644 --- a/store/postgres/src/relational.rs +++ b/store/postgres/src/relational.rs @@ -26,12 +26,12 @@ use diesel::deserialize::FromSql; use diesel::pg::Pg; use diesel::serialize::{Output, ToSql}; use diesel::sql_types::Text; -use diesel::{debug_query, sql_query, OptionalExtension, QueryDsl, QueryResult}; +use diesel::{OptionalExtension, QueryDsl, QueryResult, debug_query, sql_query}; use diesel_async::scoped_futures::ScopedFutureExt; use diesel_async::{AsyncConnection, RunQueryDsl, SimpleAsyncConnection}; -use graph::blockchain::block_stream::{EntityOperationKind, EntitySourceOperation}; use graph::blockchain::BlockTime; +use graph::blockchain::block_stream::{EntityOperationKind, EntitySourceOperation}; use graph::cheap_clone::CheapClone; use graph::components::store::write::{RowGroup, WriteChunk}; use graph::data::graphql::TypeExt as _; @@ -39,7 +39,7 @@ use graph::data::query::Trace; use graph::data::value::Word; use graph::data_source::CausalityRegion; use graph::internal_error; -use graph::prelude::{q, EntityQuery, StopwatchMetrics, ENV_VARS}; +use graph::prelude::{ENV_VARS, EntityQuery, StopwatchMetrics, q}; use graph::schema::{ AggregationInterval, EntityKey, EntityType, Field, FulltextConfig, FulltextDefinition, InputSchema, @@ -71,17 +71,17 @@ use crate::{ }, }; use graph::components::store::{AttributeNames, DerivedEntityQuery}; -use graph::data::store::{IdList, IdType, BYTES_SCALAR}; +use graph::data::store::{BYTES_SCALAR, IdList, IdType}; use graph::data::subgraph::schema::POI_TABLE; use graph::prelude::{ - anyhow, info, BlockNumber, DeploymentHash, Entity, EntityOperation, Logger, - QueryExecutionError, StoreError, ValueType, + BlockNumber, DeploymentHash, Entity, EntityOperation, Logger, QueryExecutionError, StoreError, + ValueType, anyhow, info, }; -use crate::block_range::{BoundSide, BLOCK_COLUMN, BLOCK_RANGE_COLUMN, CAUSALITY_REGION_COLUMN}; -pub use crate::catalog::Catalog; use crate::ForeignServer; -use crate::{catalog, deployment, AsyncPgConnection}; +use crate::block_range::{BLOCK_COLUMN, BLOCK_RANGE_COLUMN, BoundSide, CAUSALITY_REGION_COLUMN}; +pub use crate::catalog::Catalog; +use crate::{AsyncPgConnection, catalog, deployment}; use self::rollup::Rollup; @@ -656,7 +656,7 @@ impl Layout { // sort the elements in each blocks bucket by vid for vec in entities.values_mut() { - vec.sort_by(|a, b| a.vid.cmp(&b.vid)); + vec.sort_by_key(|a| a.vid); } Ok(entities) @@ -1039,7 +1039,8 @@ impl Layout { } return Err(internal_error!( "entities of type `{}` can not be deleted since they are immutable. Entity ids are [{}]", - table.object, group.ids().join(", ") + table.object, + group.ids().join(", ") )); } diff --git a/store/postgres/src/relational/ddl.rs b/store/postgres/src/relational/ddl.rs index cdb162978b6..317349f9edd 100644 --- a/store/postgres/src/relational/ddl.rs +++ b/store/postgres/src/relational/ddl.rs @@ -10,11 +10,11 @@ use graph::{ use crate::block_range::CAUSALITY_REGION_COLUMN; use crate::relational::{ - ColumnType, BLOCK_COLUMN, BLOCK_RANGE_COLUMN, BYTE_ARRAY_PREFIX_SIZE, STRING_PREFIX_SIZE, + BLOCK_COLUMN, BLOCK_RANGE_COLUMN, BYTE_ARRAY_PREFIX_SIZE, ColumnType, STRING_PREFIX_SIZE, VID_COLUMN, }; -use super::{index::IndexList, Catalog, Column, Layout, SqlName, Table}; +use super::{Catalog, Column, Layout, SqlName, Table, index::IndexList}; // In debug builds (for testing etc.) unconditionally create exclusion constraints, in release // builds for production, skip them @@ -194,12 +194,15 @@ impl Table { // // We also index `vid` as that correlates with the order in which // entities are stored. - write!(out,"create index brin_{table_name}\n \ + write!( + out, + "create index brin_{table_name}\n \ on {qname}\n \ using brin(lower(block_range) {int4}, coalesce(upper(block_range), {block_max}) {int4}, vid {int8});\n", table_name = self.name, qname = self.qualified_name, - block_max = BLOCK_NUMBER_MAX)?; + block_max = BLOCK_NUMBER_MAX + )?; // Add a BTree index that helps with the `RevertClampQuery` by making // it faster to find entity versions that have been modified @@ -343,13 +346,12 @@ impl Table { && [ColumnType::BigDecimal, ColumnType::BigInt, ColumnType::Int] .contains(&col.column_type)) }; - let columns = self - .columns + + self.columns .iter() .filter(not_enum_list) .filter(not_immutable_pk) - .filter(not_numeric_list); - columns + .filter(not_numeric_list) } /// If `self` is an aggregation and has cumulative aggregates, create an diff --git a/store/postgres/src/relational/ddl_tests.rs b/store/postgres/src/relational/ddl_tests.rs index 901b4daa1e5..d090a149d03 100644 --- a/store/postgres/src/relational/ddl_tests.rs +++ b/store/postgres/src/relational/ddl_tests.rs @@ -93,7 +93,7 @@ fn test_manual_index_creation_ddl() { vec!["id".to_string()], BTREE, "create index concurrently if not exists manual_book_id on {namespace}.book using btree (\"id\")", - None + None, ); assert_generated_sql( @@ -102,7 +102,7 @@ fn test_manual_index_creation_ddl() { vec!["content".to_string()], BTREE, "create index concurrently if not exists manual_book_content on {namespace}.book using btree (substring(\"content\", 1, 64))", - None + None, ); assert_generated_sql( @@ -111,7 +111,7 @@ fn test_manual_index_creation_ddl() { vec!["title".to_string()], BTREE, "create index concurrently if not exists manual_book_title on {namespace}.book using btree (left(\"title\", 256))", - None + None, ); assert_generated_sql( @@ -120,7 +120,7 @@ fn test_manual_index_creation_ddl() { vec!["page_count".to_string()], BTREE, "create index concurrently if not exists manual_book_page_count on {namespace}.book using btree (\"page_count\")", - None + None, ); assert_generated_sql( @@ -129,7 +129,7 @@ fn test_manual_index_creation_ddl() { vec!["page_count".to_string(), "title".to_string()], BTREE, "create index concurrently if not exists manual_book_page_count_title on {namespace}.book using btree (\"page_count\", left(\"title\", 256))", - None + None, ); assert_generated_sql( @@ -138,7 +138,7 @@ fn test_manual_index_creation_ddl() { vec!["content".to_string(), "block_range".to_string()], // Explicitly including 'block_range' GIST, "create index concurrently if not exists manual_book_content_block_range on {namespace}.book using gist (substring(\"content\", 1, 64), block_range)", - None + None, ); assert_generated_sql( @@ -147,7 +147,7 @@ fn test_manual_index_creation_ddl() { vec!["page_count".to_string()], BTREE, "create index concurrently if not exists manual_book_page_count_12345 on sgd0815.book using btree (\"page_count\") where coalesce(upper(block_range), 2147483647) > 12345", - Some(12345) + Some(12345), ); } diff --git a/store/postgres/src/relational/dsl.rs b/store/postgres/src/relational/dsl.rs index 06cbd60025c..9d53bc1a66c 100644 --- a/store/postgres/src/relational/dsl.rs +++ b/store/postgres/src/relational/dsl.rs @@ -6,7 +6,7 @@ use std::marker::PhantomData; use diesel::backend::Backend; use diesel::dsl::sql; -use diesel::expression::{expression_types, is_aggregate, TypedExpressionType, ValidGrouping}; +use diesel::expression::{TypedExpressionType, ValidGrouping, expression_types, is_aggregate}; use diesel::pg::Pg; use diesel::query_builder::{ AsQuery, AstPass, BoxedSelectStatement, FromClause, Query, QueryFragment, QueryId, @@ -21,17 +21,17 @@ use diesel::sql_types::{ }; use diesel::{AppearsOnTable, Expression, QueryDsl, QueryResult, SelectableExpression}; use diesel_dynamic_schema::DynamicSelectClause; -use graph::components::store::{AttributeNames, BlockNumber, StoreError, BLOCK_NUMBER_MAX}; -use graph::data::store::{Id, IdType, ID, VID}; +use graph::components::store::{AttributeNames, BLOCK_NUMBER_MAX, BlockNumber, StoreError}; +use graph::data::store::{ID, Id, IdType, VID}; use graph::data_source::CausalityRegion; -use graph::prelude::{lazy_static, ENV_VARS}; +use graph::prelude::{ENV_VARS, lazy_static}; use crate::relational::ColumnType; use crate::relational_queries::PARENT_ID; -use super::value::FromOidRow; use super::Column as RelColumn; use super::SqlName; +use super::value::FromOidRow; use super::{BLOCK_COLUMN, BLOCK_RANGE_COLUMN, CAUSALITY_REGION_COLUMN}; const TYPENAME: &str = "__typename"; diff --git a/store/postgres/src/relational/dump.rs b/store/postgres/src/relational/dump.rs index f2f679579e3..1a5c70f4cd8 100644 --- a/store/postgres/src/relational/dump.rs +++ b/store/postgres/src/relational/dump.rs @@ -3,11 +3,11 @@ use std::io::Write; use std::path::{Path, PathBuf}; use std::{collections::HashMap, fs}; +use diesel::QueryDsl; use diesel::dsl::sql; use diesel::sql_types::{ Array, BigInt, Binary, Bool, Integer, Nullable, Numeric, Text, Timestamptz, Untyped, }; -use diesel::QueryDsl; use diesel_async::RunQueryDsl; use diesel_dynamic_schema::DynamicSelectClause; @@ -16,6 +16,7 @@ use graph::data::subgraph::schema::{SubgraphError, SubgraphHealth, SubgraphManif use graph::prelude::{DeploymentHash, StoreError, SubgraphDeploymentEntity}; use serde::{Deserialize, Serialize}; +use crate::AsyncPgConnection; use crate::catalog; use crate::detail::deployment_entity; use crate::parquet::convert::rows_to_record_batch; @@ -26,7 +27,6 @@ use crate::relational::index::IndexList; use crate::relational::value::OidRow; use crate::relational::{ColumnType, SqlName, Table as RelTable}; use crate::vid_batcher::{VidBatcher, VidRange}; -use crate::AsyncPgConnection; use super::Layout; @@ -654,22 +654,22 @@ async fn dump_entity_table( if effective_range.is_empty() { // No new rows, but for incremental mutable tables we still // need to check for clamps - if let (Some(prev_info), Some(prev_head)) = (prev, prev_head_block_number) { - if !table.immutable { - let clamp_index = prev_info.clamps.len(); - if let Some(clamp_info) = dump_clamp( - conn, - table, - dir, - prev_info.max_vid, - prev_head, - clamp_index, - reporter, - ) - .await? - { - clamps.push(clamp_info); - } + if let (Some(prev_info), Some(prev_head)) = (prev, prev_head_block_number) + && !table.immutable + { + let clamp_index = prev_info.clamps.len(); + if let Some(clamp_info) = dump_clamp( + conn, + table, + dir, + prev_info.max_vid, + prev_head, + clamp_index, + reporter, + ) + .await? + { + clamps.push(clamp_info); } } @@ -733,22 +733,22 @@ async fn dump_entity_table( } // For incremental mutable tables, dump clamps - if let (Some(prev_info), Some(prev_head)) = (prev, prev_head_block_number) { - if !table.immutable { - let clamp_index = prev_info.clamps.len(); - if let Some(clamp_info) = dump_clamp( - conn, - table, - dir, - prev_info.max_vid, - prev_head, - clamp_index, - reporter, - ) - .await? - { - clamps.push(clamp_info); - } + if let (Some(prev_info), Some(prev_head)) = (prev, prev_head_block_number) + && !table.immutable + { + let clamp_index = prev_info.clamps.len(); + if let Some(clamp_info) = dump_clamp( + conn, + table, + dir, + prev_info.max_vid, + prev_head, + clamp_index, + reporter, + ) + .await? + { + clamps.push(clamp_info); } } @@ -1070,14 +1070,13 @@ impl Layout { if let (Some(prev_head), Some(curr_head)) = ( prev_head_block_number, metadata.head_block.as_ref().map(|b| b.number), - ) { - if curr_head <= prev_head { - return Err(StoreError::InternalError(format!( - "incremental dump refused: current head block ({}) <= previous head block ({}); \ + ) && curr_head <= prev_head + { + return Err(StoreError::InternalError(format!( + "incremental dump refused: current head block ({}) <= previous head block ({}); \ possible reorg — delete the dump directory and re-dump", - curr_head, prev_head - ))); - } + curr_head, prev_head + ))); } write_file(dir.join("schema.graphql"), &schema)?; diff --git a/store/postgres/src/relational/index.rs b/store/postgres/src/relational/index.rs index 5cfb8f024e8..6dc43a684fb 100644 --- a/store/postgres/src/relational/index.rs +++ b/store/postgres/src/relational/index.rs @@ -1,5 +1,5 @@ //! Parse Postgres index definition into a form that is meaningful for us. -use anyhow::{anyhow, Error}; +use anyhow::{Error, anyhow}; use std::collections::HashMap; use std::fmt::{Display, Write}; use std::sync::Arc; @@ -10,9 +10,8 @@ use diesel_async::RunQueryDsl; use graph::components::store::StoreError; use graph::itertools::Itertools; use graph::prelude::{ - lazy_static, + BlockNumber, lazy_static, regex::{Captures, Regex}, - BlockNumber, }; use crate::block_range::{BLOCK_COLUMN, BLOCK_RANGE_COLUMN}; @@ -20,7 +19,7 @@ use crate::command_support::catalog::Site; use crate::deployment_store::DeploymentStore; use crate::primary::Namespace; use crate::relational::{BYTE_ARRAY_PREFIX_SIZE, STRING_PREFIX_SIZE}; -use crate::{catalog, AsyncPgConnection}; +use crate::{AsyncPgConnection, catalog}; use super::{Layout, Table, VID_COLUMN}; @@ -725,7 +724,9 @@ impl CreateIndex { let if_not_exists = if if_not_exists { "if not exists " } else { "" }; let columns = columns.iter().map(|c| c.to_sql()).join(", "); - let mut sql = format!("create {unique}index {concurrent}{if_not_exists}{name} on {nsp}.{table} using {method} ({columns})"); + let mut sql = format!( + "create {unique}index {concurrent}{if_not_exists}{name} on {nsp}.{table} using {method} ({columns})" + ); if let Some(with) = with { write!(sql, " with ({with})")?; } @@ -796,13 +797,11 @@ impl IndexList { // that are not to be postponed we want to create during initial creation of // the copied subgraph && postponed == ci.to_postpone() - { - if let Ok(sql) = ci + && let Ok(sql) = ci .with_nsp(namespace.to_string())? .to_sql(concurrent, if_not_exists) - { - arr.push((ci.name(), sql)) - } + { + arr.push((ci.name(), sql)) } } } @@ -871,7 +870,7 @@ mod tests { use graph::prelude::{BlockNumber, DeploymentHash}; use graph::schema::InputSchema; - use crate::layout_for_tests::{make_dummy_site, Namespace}; + use crate::layout_for_tests::{Namespace, make_dummy_site}; use crate::relational::Catalog; use super::*; diff --git a/store/postgres/src/relational/prune.rs b/store/postgres/src/relational/prune.rs index d7747fef5e9..f25b364b0d8 100644 --- a/store/postgres/src/relational/prune.rs +++ b/store/postgres/src/relational/prune.rs @@ -5,29 +5,28 @@ use diesel::{ sql_types::{BigInt, Integer}, }; use diesel_async::{ - scoped_futures::{ScopedBoxFuture, ScopedFutureExt}, AsyncConnection, RunQueryDsl, SimpleAsyncConnection, + scoped_futures::{ScopedBoxFuture, ScopedFutureExt}, }; use graph::{ components::store::{PrunePhase, PruneReporter, PruneRequest, PruningStrategy, VersionStats}, - prelude::{BlockNumber, CancelableError, CheapClone, StoreError, BLOCK_NUMBER_MAX}, + prelude::{BLOCK_NUMBER_MAX, BlockNumber, CancelableError, CheapClone, StoreError}, schema::InputSchema, - slog::{warn, Logger}, + slog::{Logger, warn}, }; use itertools::Itertools; use crate::{ - catalog, + AsyncPgConnection, catalog, copy::BATCH_STATEMENT_TIMEOUT, deployment, relational::{Table, VID_COLUMN}, vid_batcher::{VidBatcher, VidRange}, - AsyncPgConnection, }; use super::{ - index::{load_indexes_from_table, CreateIndex, IndexList}, Catalog, Layout, Namespace, + index::{CreateIndex, IndexList, load_indexes_from_table}, }; pub use status::{Phase, PruneState, PruneTableState, Viewer}; @@ -580,16 +579,17 @@ mod status { use chrono::{DateTime, Utc}; use diesel::{ + AsChangeset, ExpressionMethods as _, OptionalExtension, QueryDsl as _, deserialize::FromSql, dsl::insert_into, pg::{Pg, PgValue}, query_builder::QueryFragment, serialize::{Output, ToSql}, sql_types::Text, - table, update, AsChangeset, ExpressionMethods as _, OptionalExtension, QueryDsl as _, + table, update, }; use diesel_async::RunQueryDsl as _; - use diesel_async::{scoped_futures::ScopedFutureExt, AsyncConnection}; + use diesel_async::{AsyncConnection, scoped_futures::ScopedFutureExt}; use graph::{ components::store::{PruneRequest, PruningStrategy, StoreResult}, env::ENV_VARS, @@ -597,9 +597,9 @@ mod status { }; use crate::{ + AsyncPgConnection, ConnectionPool, relational::{Layout, Table}, vid_batcher::{VidBatcher, VidRange}, - AsyncPgConnection, ConnectionPool, }; table! { diff --git a/store/postgres/src/relational/query_tests.rs b/store/postgres/src/relational/query_tests.rs index 63ccb5e2ea0..3b4582c5b5b 100644 --- a/store/postgres/src/relational/query_tests.rs +++ b/store/postgres/src/relational/query_tests.rs @@ -5,13 +5,13 @@ use graph::{ components::store::write::RowGroup, data_source::CausalityRegion, entity, - prelude::{r, serde_json as json, DeploymentHash, EntityFilter}, + prelude::{DeploymentHash, EntityFilter, r, serde_json as json}, schema::InputSchema, }; use crate::{ block_range::BoundSide, - layout_for_tests::{make_dummy_site, Namespace}, + layout_for_tests::{Namespace, make_dummy_site}, relational::{Catalog, ColumnType, Layout}, relational_queries::{FindRangeQuery, FromColumnValue, InsertQuery}, }; diff --git a/store/postgres/src/relational/restore.rs b/store/postgres/src/relational/restore.rs index a4f7eff61da..9860da0fd3b 100644 --- a/store/postgres/src/relational/restore.rs +++ b/store/postgres/src/relational/restore.rs @@ -20,6 +20,7 @@ use graph::prelude::{BlockPtr as GraphBlockPtr, StoreError}; use graph::schema::{EntityType, InputSchema}; use graph::semver::Version; +use crate::AsyncPgConnection; use crate::catalog; use crate::deployment::create_deployment; use crate::dynds::DataSourcesTable; @@ -32,7 +33,6 @@ use crate::relational::dump::{Metadata, TableInfo}; use crate::relational::{Layout, Table, VID_COLUMN}; use crate::relational_queries::InsertQuery; use crate::vid_batcher::VidRange; -use crate::AsyncPgConnection; const DATA_SOURCES_TABLE: &str = "data_sources$"; @@ -428,17 +428,17 @@ pub async fn finalize( } // 2. Reset data_sources$ vid sequence if present - if let Some(ds_info) = metadata.tables.get(DATA_SOURCES_TABLE) { - if ds_info.max_vid >= 0 { - let qualified = format!("\"{nsp}\".\"{DATA_SOURCES_TABLE}\""); - let query = format!( - "SELECT setval(pg_get_serial_sequence('{qualified}', 'vid'), {})", - ds_info.max_vid - ); - conn.batch_execute(&query).await.map_err(|e| { - StoreError::InternalError(format!("reset data_sources$ vid seq: {e}")) - })?; - } + if let Some(ds_info) = metadata.tables.get(DATA_SOURCES_TABLE) + && ds_info.max_vid >= 0 + { + let qualified = format!("\"{nsp}\".\"{DATA_SOURCES_TABLE}\""); + let query = format!( + "SELECT setval(pg_get_serial_sequence('{qualified}', 'vid'), {})", + ds_info.max_vid + ); + conn.batch_execute(&query) + .await + .map_err(|e| StoreError::InternalError(format!("reset data_sources$ vid seq: {e}")))?; } // 3. Update earliest_block_number (may differ from start_block after diff --git a/store/postgres/src/relational/rollup.rs b/store/postgres/src/relational/rollup.rs index c96652e7bf9..e622c6ab119 100644 --- a/store/postgres/src/relational/rollup.rs +++ b/store/postgres/src/relational/rollup.rs @@ -73,8 +73,8 @@ use graph::sqlparser::ast as p; use graph::sqlparser::parser::ParserError; use itertools::Itertools; -use crate::relational::Table; use crate::AsyncPgConnection; +use crate::relational::Table; use super::{Column, SqlName}; @@ -739,8 +739,8 @@ mod tests { use itertools::Itertools as _; use crate::{ - layout_for_tests::{make_dummy_site, Namespace}, - relational::{rollup::Rollup, Catalog, Layout}, + layout_for_tests::{Namespace, make_dummy_site}, + relational::{Catalog, Layout, rollup::Rollup}, }; // Check that the two strings are the same after replacing runs of diff --git a/store/postgres/src/relational/value.rs b/store/postgres/src/relational/value.rs index 6e4764b14c0..1217afd6195 100644 --- a/store/postgres/src/relational/value.rs +++ b/store/postgres/src/relational/value.rs @@ -11,8 +11,8 @@ use graph::{ components::store::StoreError, data::{ store::{ - scalar::{BigDecimal, Bytes, Timestamp}, Entity, QueryObject, + scalar::{BigDecimal, Bytes, Timestamp}, }, value::{Object, Word}, }, @@ -153,7 +153,7 @@ impl FromOidValue for r::Value { O::Int4Range(..) => { return Err(StoreError::InternalError( "int4range can not be converted to r::Value".to_string(), - )) + )); } O::Null => Self::Null, }; @@ -210,7 +210,7 @@ impl FromOidValue for graph::prelude::Value { O::Int4Range(..) => { return Err(StoreError::InternalError( "int4range can not be converted to Value".to_string(), - )) + )); } O::Null => Self::Null, }; diff --git a/store/postgres/src/relational_queries.rs b/store/postgres/src/relational_queries.rs index eee8b6073f1..46655c21c71 100644 --- a/store/postgres/src/relational_queries.rs +++ b/store/postgres/src/relational_queries.rs @@ -5,13 +5,13 @@ //! //! Code in this module works very hard to minimize the number of allocations //! that it performs +use diesel::QuerySource as _; use diesel::pg::Pg; use diesel::query_builder::{AstPass, Query, QueryFragment, QueryId}; use diesel::query_dsl::RunQueryDsl; use diesel::result::{Error as DieselError, QueryResult}; use diesel::sql_types::Untyped; use diesel::sql_types::{Array, BigInt, Binary, Bool, Int8, Integer, Jsonb, Text, Timestamptz}; -use diesel::QuerySource as _; use graph::components::store::write::{EntityWrite, RowGroup, WriteChunk}; use graph::components::store::{Child as StoreChild, DerivedEntityQuery}; @@ -21,9 +21,9 @@ use graph::data::store::{IdList, IdRef, QueryObject}; use graph::data::value::{Object, Word}; use graph::data_source::CausalityRegion; use graph::prelude::{ - anyhow, r, serde_json, BlockNumber, ChildMultiplicity, Entity, EntityCollection, EntityFilter, - EntityLink, EntityOrder, EntityOrderByChild, EntityOrderByChildInfo, EntityRange, EntityWindow, - ParentLink, QueryExecutionError, StoreError, Value, ENV_VARS, + BlockNumber, ChildMultiplicity, ENV_VARS, Entity, EntityCollection, EntityFilter, EntityLink, + EntityOrder, EntityOrderByChild, EntityOrderByChildInfo, EntityRange, EntityWindow, ParentLink, + QueryExecutionError, StoreError, Value, anyhow, r, serde_json, }; use graph::schema::{EntityType, FulltextAlgorithm, FulltextConfig, InputSchema}; use graph::{ @@ -44,13 +44,14 @@ use crate::block_range::{BoundSide, EntityBlockRange}; use crate::parquet::convert::RestoreRow; use crate::relational::dsl::AtBlock; use crate::relational::{ - dsl, rollup::Rollup, Column, ColumnType, Layout, SqlName, Table, BYTE_ARRAY_PREFIX_SIZE, - PRIMARY_KEY_COLUMN, STRING_PREFIX_SIZE, VID_COLUMN, + BYTE_ARRAY_PREFIX_SIZE, Column, ColumnType, Layout, PRIMARY_KEY_COLUMN, STRING_PREFIX_SIZE, + SqlName, Table, VID_COLUMN, dsl, rollup::Rollup, }; use crate::{ block_range::{ - BlockRangeColumn, BlockRangeLowerBoundClause, BlockRangeUpperBoundClause, BlockRangeValue, - BLOCK_COLUMN, BLOCK_RANGE_COLUMN, BLOCK_RANGE_CURRENT, CAUSALITY_REGION_COLUMN, + BLOCK_COLUMN, BLOCK_RANGE_COLUMN, BLOCK_RANGE_CURRENT, BlockRangeColumn, + BlockRangeLowerBoundClause, BlockRangeUpperBoundClause, BlockRangeValue, + CAUSALITY_REGION_COLUMN, }, primary::Site, }; @@ -631,7 +632,7 @@ impl<'a> SqlValue<'a> { let value = match value { String(s) => match column_type { - ColumnType::String|ColumnType::Enum(_)|ColumnType::TSVector(_) => S::Text(s), + ColumnType::String | ColumnType::Enum(_) | ColumnType::TSVector(_) => S::Text(s), ColumnType::Int8 => S::Int8(s.parse::().map_err(|e| { internal_error!("failed to convert `{}` to an Int8: {}", s, e.to_string()) })?), @@ -646,35 +647,26 @@ impl<'a> SqlValue<'a> { }, Int(i) => S::Int(*i), Value::Int8(i) => S::Int8(*i), - BigDecimal(d) => { - S::Numeric(d.to_string()) - } + BigDecimal(d) => S::Numeric(d.to_string()), Timestamp(ts) => S::Timestamp(*ts), Bool(b) => S::Bool(*b), - List(values) => { - match column_type { - ColumnType::BigDecimal | ColumnType::BigInt => { - let text_values: Vec<_> = values.iter().map(|v| v.to_string()).collect(); - S::Numerics(text_values) - }, - ColumnType::Boolean|ColumnType::Bytes| - ColumnType::Int| - ColumnType::Int8| - ColumnType::String| - ColumnType::Timestamp| - ColumnType::Enum(_)| - ColumnType::TSVector(_) => { - S::List(values) - } + List(values) => match column_type { + ColumnType::BigDecimal | ColumnType::BigInt => { + let text_values: Vec<_> = values.iter().map(|v| v.to_string()).collect(); + S::Numerics(text_values) } - } - Null => { - S::Null - } + ColumnType::Boolean + | ColumnType::Bytes + | ColumnType::Int + | ColumnType::Int8 + | ColumnType::String + | ColumnType::Timestamp + | ColumnType::Enum(_) + | ColumnType::TSVector(_) => S::List(values), + }, + Null => S::Null, Bytes(b) => S::Bytes(b), - BigInt(i) => { - S::Numeric(i.to_string()) - } + BigInt(i) => S::Numeric(i.to_string()), }; Ok(value) } @@ -765,7 +757,7 @@ impl<'a> QueryFragment for QueryValue<'a> { use SqlValue as S; match &self.value { S::Text(s) => push_string(s, column_type, &mut out), - S::String(ref s) => push_string(s, column_type, &mut out), + S::String(s) => push_string(s, column_type, &mut out), S::Int(i) => out.push_bind_param::(i), S::Int8(i) => out.push_bind_param::(i), S::Timestamp(i) => out.push_bind_param::(&i.0), @@ -2432,11 +2424,11 @@ impl<'a> InsertQuery<'a> { for column in table.columns.iter() { if !column.is_nullable() && !row.entity.contains_key(&column.field) { return Err(StoreError::QueryExecutionError(format!( - "can not insert entity {}[{}] since value for non-nullable attribute {} is missing. \ + "can not insert entity {}[{}] since value for non-nullable attribute {} is missing. \ To fix this, mark the attribute as nullable in the GraphQL schema or change the \ mapping code to always set this attribute.", - table.object, row.id, column.field - ))); + table.object, row.id, column.field + ))); } } } diff --git a/store/postgres/src/retry.rs b/store/postgres/src/retry.rs index 2b6f3f73d75..d0dea82aca9 100644 --- a/store/postgres/src/retry.rs +++ b/store/postgres/src/retry.rs @@ -4,7 +4,7 @@ use std::time::Duration; use graph::{ prelude::StoreError, - slog::{warn, Logger}, + slog::{Logger, warn}, util::backoff::ExponentialBackoff, }; diff --git a/store/postgres/src/sql/mod.rs b/store/postgres/src/sql/mod.rs index f08f89ae711..938db9de13d 100644 --- a/store/postgres/src/sql/mod.rs +++ b/store/postgres/src/sql/mod.rs @@ -12,7 +12,7 @@ mod test { use crate::{ catalog::Catalog, - primary::{make_dummy_site, Namespace}, + primary::{Namespace, make_dummy_site}, relational::Layout, }; diff --git a/store/postgres/src/sql/parser.rs b/store/postgres/src/sql/parser.rs index e263a54deb2..d800cdab248 100644 --- a/store/postgres/src/sql/parser.rs +++ b/store/postgres/src/sql/parser.rs @@ -1,6 +1,6 @@ use super::{constants::SQL_DIALECT, validation::Validator}; use crate::relational::Layout; -use anyhow::{anyhow, Ok, Result}; +use anyhow::{Ok, Result, anyhow}; use graph::{env::ENV_VARS, prelude::BlockNumber}; use std::sync::Arc; @@ -36,7 +36,7 @@ mod test { use std::sync::Arc; use crate::sql::{parser::SQL_DIALECT, test::make_layout}; - use graph::prelude::{lazy_static, serde_yaml, BLOCK_NUMBER_MAX}; + use graph::prelude::{BLOCK_NUMBER_MAX, lazy_static, serde_yaml}; use serde::{Deserialize, Serialize}; use pretty_assertions::assert_eq; diff --git a/store/postgres/src/sql/validation.rs b/store/postgres/src/sql/validation.rs index 295e3460f6c..28a57d04c34 100644 --- a/store/postgres/src/sql/validation.rs +++ b/store/postgres/src/sql/validation.rs @@ -246,7 +246,7 @@ impl VisitorMut for Validator<'_> { SetExpr::Table(_) => { /* permitted */ } SetExpr::Values(_) => { /* permitted */ } SetExpr::Insert(_) | SetExpr::Update(_) | SetExpr::Delete(_) | SetExpr::Merge(_) => { - return ControlFlow::Break(Error::NotSelectQuery) + return ControlFlow::Break(Error::NotSelectQuery); } } diff --git a/store/postgres/src/store.rs b/store/postgres/src/store.rs index 4adec80ab5b..2ddc926539a 100644 --- a/store/postgres/src/store.rs +++ b/store/postgres/src/store.rs @@ -12,12 +12,12 @@ use graph::{ data::subgraph::status, internal_error, prelude::{ - alloy::primitives::Address, BlockNumber, BlockPtr, CheapClone, DeploymentHash, - PartialBlockPtr, QueryExecutionError, StoreError, + BlockNumber, BlockPtr, CheapClone, DeploymentHash, PartialBlockPtr, QueryExecutionError, + StoreError, alloy::primitives::Address, }, }; -use crate::{block_store::BlockStore, query_store::QueryStore, SubgraphStore}; +use crate::{SubgraphStore, block_store::BlockStore, query_store::QueryStore}; /// The overall store of the system, consisting of a [`SubgraphStore`] and a /// [`BlockStore`], each of which multiplex across multiple database shards. diff --git a/store/postgres/src/store_events.rs b/store/postgres/src/store_events.rs index 572c3a339a3..6ed19314649 100644 --- a/store/postgres/src/store_events.rs +++ b/store/postgres/src/store_events.rs @@ -1,12 +1,12 @@ use graph::futures01::Stream; +use graph::futures03::TryStreamExt; use graph::futures03::compat::Stream01CompatExt; use graph::futures03::stream::StreamExt; -use graph::futures03::TryStreamExt; -use std::sync::{atomic::Ordering, Arc}; +use std::sync::{Arc, atomic::Ordering}; use graph::parking_lot::RwLock; use std::{collections::HashMap, sync::atomic::AtomicUsize}; -use tokio::sync::mpsc::{channel, Sender}; +use tokio::sync::mpsc::{Sender, channel}; use tokio_stream::wrappers::ReceiverStream; use crate::notification_listener::{NotificationListener, SafeChannelName}; diff --git a/store/postgres/src/subgraph_store.rs b/store/postgres/src/subgraph_store.rs index 3561999567e..5110dd7732e 100644 --- a/store/postgres/src/subgraph_store.rs +++ b/store/postgres/src/subgraph_store.rs @@ -9,7 +9,7 @@ use diesel_async::scoped_futures::ScopedFutureExt; use std::fmt; use std::{ collections::{BTreeMap, HashMap}, - sync::{atomic::AtomicU8, Arc, Mutex}, + sync::{Arc, Mutex, atomic::AtomicU8}, }; use std::{iter::FromIterator, time::Duration}; @@ -26,14 +26,14 @@ use graph::{ data::{ query::QueryTarget, store::DEFAULT_NODE_ID, - subgraph::{schema::DeploymentCreate, status, DeploymentFeatures}, + subgraph::{DeploymentFeatures, schema::DeploymentCreate, status}, }, internal_error, prelude::{ - anyhow, lazy_static, o, ApiVersion, BlockNumber, BlockPtr, ChainStore, DeploymentHash, - EntityOperation, Logger, MetricsRegistry, NodeId, PartialBlockPtr, StoreError, StoreEvent, - SubgraphDeploymentEntity, SubgraphName, SubgraphStore as SubgraphStoreTrait, - SubgraphVersionSwitchingMode, + ApiVersion, BlockNumber, BlockPtr, ChainStore, DeploymentHash, EntityOperation, Logger, + MetricsRegistry, NodeId, PartialBlockPtr, StoreError, StoreEvent, SubgraphDeploymentEntity, + SubgraphName, SubgraphStore as SubgraphStoreTrait, SubgraphVersionSwitchingMode, anyhow, + lazy_static, o, }, schema::{ApiSchema, InputSchema}, url::Url, @@ -42,25 +42,24 @@ use graph::{ use graph::{derive::CheapClone, futures03::future::join_all, prelude::alloy::primitives::Address}; use crate::{ + ConnectionPool, NotificationSender, catalog::Catalog, deployment::{OnSync, SubgraphHealth}, primary::{ self, DeploymentId, Mirror as PrimaryMirror, Primary, RestoreAction, RestoreMode, Site, }, relational::{ - self, + self, Layout, index::{IndexList, Method}, - Layout, }, writable::{SourceableStore, WritableStore}, - ConnectionPool, NotificationSender, }; use crate::{ deployment_store::{DeploymentStore, ReplicaId}, detail::DeploymentDetail, primary::UnusedDeployment, }; -use crate::{fork, relational::index::CreateIndex, relational::SqlName}; +use crate::{fork, relational::SqlName, relational::index::CreateIndex}; /// The name of a database shard; valid names must match `[a-z0-9_]+` #[derive(Clone, Debug, Eq, PartialEq, Hash, AsExpression, FromSqlRow)] @@ -132,7 +131,7 @@ impl ToSql for Shard { /// shards. pub trait DeploymentPlacer { fn place(&self, name: &str, network: &str) - -> Result, Vec)>, String>; + -> Result, Vec)>, String>; } /// Tools for managing unused deployments diff --git a/store/postgres/src/vid_batcher.rs b/store/postgres/src/vid_batcher.rs index 7ea633058f8..1275608e364 100644 --- a/store/postgres/src/vid_batcher.rs +++ b/store/postgres/src/vid_batcher.rs @@ -12,10 +12,9 @@ use graph::{ }; use crate::{ - catalog, + AsyncPgConnection, catalog, primary::Namespace, relational::{Table, VID_COLUMN}, - AsyncPgConnection, }; /// The initial batch size for tables that do not have an array column diff --git a/store/postgres/src/writable.rs b/store/postgres/src/writable.rs index 680a217c8be..a322b4b91dd 100644 --- a/store/postgres/src/writable.rs +++ b/store/postgres/src/writable.rs @@ -1,7 +1,7 @@ use std::collections::BTreeSet; use std::ops::{Deref, Range}; -use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Mutex; +use std::sync::atomic::{AtomicBool, Ordering}; use graph::parking_lot::RwLock; use std::time::Instant; @@ -9,27 +9,27 @@ use std::{collections::BTreeMap, sync::Arc}; use async_trait::async_trait; use diesel_async::scoped_futures::ScopedFutureExt; -use graph::blockchain::block_stream::{EntitySourceOperation, FirehoseCursor}; use graph::blockchain::BlockTime; +use graph::blockchain::block_stream::{EntitySourceOperation, FirehoseCursor}; use graph::components::store::{Batch, DeploymentCursorTracker, DerivedEntityQuery, ReadStore}; use graph::data::store::IdList; use graph::data::subgraph::schema; use graph::data_source::CausalityRegion; use graph::internal_error; use graph::prelude::{ - BlockNumber, CacheWeight, Entity, MetricsRegistry, SubgraphDeploymentEntity, - SubgraphStore as _, BLOCK_NUMBER_MAX, + BLOCK_NUMBER_MAX, BlockNumber, CacheWeight, Entity, MetricsRegistry, SubgraphDeploymentEntity, + SubgraphStore as _, }; use graph::schema::{EntityKey, EntityType, InputSchema}; use graph::slog::{debug, info, warn}; use graph::util::bounded_queue::BoundedQueue; use graph::{ cheap_clone::CheapClone, - components::store::{self, write::EntityOp, WritableStore as WritableStoreTrait}, + components::store::{self, WritableStore as WritableStoreTrait, write::EntityOp}, data::subgraph::schema::SubgraphError, prelude::{ - BlockPtr, DeploymentHash, EntityModification, Logger, StopwatchMetrics, StoreError, - StoreEvent, UnfailOutcome, ENV_VARS, + BlockPtr, DeploymentHash, ENV_VARS, EntityModification, Logger, StopwatchMetrics, + StoreError, StoreEvent, UnfailOutcome, }, slog::error, }; @@ -41,8 +41,8 @@ use tokio::task::JoinHandle; use crate::deployment_store::DeploymentStore; use crate::primary::DeploymentId; use crate::relational::index::IndexList; -use crate::{primary, primary::Site, relational::Layout, SubgraphStore}; -use crate::{retry, NotificationSender}; +use crate::{NotificationSender, retry}; +use crate::{SubgraphStore, primary, primary::Site, relational::Layout}; /// A wrapper around `SubgraphStore` that only exposes functions that are /// safe to call from `WritableStore`, i.e., functions that either do not @@ -464,18 +464,17 @@ impl SyncStore { // Handle on_sync actions. They only apply to copies (not // grafts) so we make sure that the source, if it exists, has // the same hash as `self.site` - if let Some(src) = self.writable.source_of_copy(&self.site).await? { - if let Some(src) = self.maybe_find_site(src).await? { - if src.deployment == self.site.deployment { - let on_sync = self.writable.on_sync(&self.site).await?; - if on_sync.activate() { - let mut pconn = self.store.primary_conn().await?; - pconn.activate(&self.site.as_ref().into()).await?; - } - if on_sync.replace() { - self.unassign_subgraph(&src).await?; - } - } + if let Some(src) = self.writable.source_of_copy(&self.site).await? + && let Some(src) = self.maybe_find_site(src).await? + && src.deployment == self.site.deployment + { + let on_sync = self.writable.on_sync(&self.site).await?; + if on_sync.activate() { + let mut pconn = self.store.primary_conn().await?; + pconn.activate(&self.site.as_ref().into()).await?; + } + if on_sync.replace() { + self.unassign_subgraph(&src).await?; } } @@ -1820,14 +1819,14 @@ impl WritableStoreTrait for WritableStore { self.writer.start_batching(); } - if let Some(block_ptr) = self.block_ptr.lock().unwrap().as_ref() { - if block_ptr_to.number <= block_ptr.number { - return Err(internal_error!( - "transact_block_operations called for block {} but its head is already at {}", - block_ptr_to, - block_ptr - )); - } + if let Some(block_ptr) = self.block_ptr.lock().unwrap().as_ref() + && block_ptr_to.number <= block_ptr.number + { + return Err(internal_error!( + "transact_block_operations called for block {} but its head is already at {}", + block_ptr_to, + block_ptr + )); } let batch = Batch::new( diff --git a/store/test-store/src/block_store.rs b/store/test-store/src/block_store.rs index c0ca494688c..70459d6b39b 100644 --- a/store/test-store/src/block_store.rs +++ b/store/test-store/src/block_store.rs @@ -1,16 +1,16 @@ use std::{convert::TryFrom, str::FromStr, sync::Arc}; use graph::blockchain::{BlockTime, ChainIdentifier}; +use graph::prelude::LightEthereumBlock; use graph::prelude::alloy::consensus::Header as ConsensusHeader; -use graph::prelude::alloy::primitives::{Bloom, B256, U256}; +use graph::prelude::alloy::primitives::{B256, Bloom, U256}; use graph::prelude::alloy::rpc::types::{Block, Header}; -use graph::prelude::LightEthereumBlock; use lazy_static::lazy_static; use graph::components::store::BlockStore; use graph::{ blockchain::Block as BlockchainBlock, - prelude::{serde_json, BlockHash, BlockNumber, BlockPtr, EthereumBlock}, + prelude::{BlockHash, BlockNumber, BlockPtr, EthereumBlock, serde_json}, }; use graph_chain_ethereum::codec::{Block as FirehoseBlock, BlockHeader}; use prost_types::Timestamp; @@ -181,7 +181,7 @@ impl BlockchainBlock for FakeBlock { // can never be null and therefore impossible to test without manipulating the JSON blob directly. if let serde_json::Value::Object(ref mut map) = value { map.entry("block").and_modify(|ref mut block| { - if let serde_json::Value::Object(ref mut block) = block { + if let serde_json::Value::Object(block) = block { block.remove_entry("timestamp"); } }); diff --git a/store/test-store/src/store.rs b/store/test-store/src/store.rs index b90d244bbcc..106ab2b0cfe 100644 --- a/store/test-store/src/store.rs +++ b/store/test-store/src/store.rs @@ -1,13 +1,13 @@ use diesel; -use graph::blockchain::mock::MockDataSource; use graph::blockchain::BlockTime; use graph::blockchain::ChainIdentifier; +use graph::blockchain::mock::MockDataSource; use graph::components::store::{BlockStore, SeqGenerator}; use graph::data::graphql::load_manager::LoadManager; use graph::data::query::QueryResults; use graph::data::query::QueryTarget; -use graph::data::subgraph::schema::{DeploymentCreate, SubgraphError}; use graph::data::subgraph::SubgraphFeature; +use graph::data::subgraph::schema::{DeploymentCreate, SubgraphError}; use graph::data_source::DataSource; use graph::log; use graph::prelude::alloy::primitives::B256; @@ -21,16 +21,16 @@ use graph::{ data::subgraph::status, prelude::NodeId, }; use graph_graphql::prelude::{ - execute_query, Query as PreparedQuery, QueryExecutionOptions, StoreResolver, + Query as PreparedQuery, QueryExecutionOptions, StoreResolver, execute_query, }; use graph_graphql::test_support::GraphQLMetrics; use graph_node::config::{Config, Opt}; use graph_node::store_builder::StoreBuilder; use graph_store_postgres::AsyncPgConnection; use graph_store_postgres::{ - layout_for_tests::FAKE_NETWORK_SHARED, BlockStore as DieselBlockStore, ConnectionPool, - DeploymentPlacer, Shard, SubgraphStore as DieselSubgraphStore, SubscriptionManager, - PRIMARY_SHARD, + BlockStore as DieselBlockStore, ConnectionPool, DeploymentPlacer, PRIMARY_SHARD, Shard, + SubgraphStore as DieselSubgraphStore, SubscriptionManager, + layout_for_tests::FAKE_NETWORK_SHARED, }; use hex_literal::hex; use lazy_static::lazy_static; @@ -419,8 +419,8 @@ pub async fn revert_block(store: &Arc, deployment: &DeploymentLocator, pt } pub async fn insert_ens_name(hash: &str, name: &str) { - use diesel::insert_into; use diesel::ExpressionMethods; + use diesel::insert_into; use diesel_async::RunQueryDsl; use graph_store_postgres::command_support::catalog::ens_names; @@ -626,13 +626,17 @@ fn build_store() -> (Arc, ConnectionPool, Config, Arc { - assert_eq!(message, "Field \"name\" must not have a selection since type \"String!\" has no subfields."); + assert_eq!( + message, + "Field \"name\" must not have a selection since type \"String!\" has no subfields." + ); } r => panic!("unexpexted query error: {:?}", r), }; @@ -2196,7 +2198,10 @@ fn leaf_selection_mismatch() { _pos, message, )) => { - assert_eq!(message, "Field \"mainBand\" of type \"Band\" must have a selection of subfields. Did you mean \"mainBand { ... }\"?"); + assert_eq!( + message, + "Field \"mainBand\" of type \"Band\" must have a selection of subfields. Did you mean \"mainBand { ... }\"?" + ); } r => panic!("unexpexted query error: {:?}", r), }; diff --git a/store/test-store/tests/graphql/sql.rs b/store/test-store/tests/graphql/sql.rs index ba0b1613879..27802ef469b 100644 --- a/store/test-store/tests/graphql/sql.rs +++ b/store/test-store/tests/graphql/sql.rs @@ -4,15 +4,15 @@ use graph::components::store::QueryStoreManager; use graph::data::query::QueryTarget; use graph::data::store::SqlQueryObject; -use graph::prelude::{r, QueryExecutionError}; +use graph::prelude::{QueryExecutionError, r}; use std::collections::BTreeSet; -use test_store::{run_test_sequentially, STORE}; +use test_store::{STORE, run_test_sequentially}; #[cfg(debug_assertions)] use graph::env::ENV_VARS; // Import test setup from query.rs module -use super::query::{setup, IdType}; +use super::query::{IdType, setup}; /// Synchronous wrapper for SQL query execution fn run_sql_query(sql: &str, test: F) @@ -52,12 +52,11 @@ fn sql_can_query_simple_select() { assert_eq!(results.len(), 5, "Should return 5 musicians"); // Check first musician - if let Some(first) = results.first() { - if let r::Value::Object(ref obj) = first.0 { - if let Some(r::Value::String(name)) = obj.get("name") { - assert_eq!(name, "John", "First musician should be John"); - } - } + if let Some(first) = results.first() + && let r::Value::Object(ref obj) = first.0 + && let Some(r::Value::String(name)) = obj.get("name") + { + assert_eq!(name, "John", "First musician should be John"); } }); } @@ -70,12 +69,11 @@ fn sql_can_query_with_where_clause() { let results = result.expect("SQL query should succeed"); assert_eq!(results.len(), 1, "Should return 1 musician named John"); - if let Some(first) = results.first() { - if let r::Value::Object(ref obj) = first.0 { - if let Some(r::Value::String(name)) = obj.get("name") { - assert_eq!(name, "John", "Should return John"); - } - } + if let Some(first) = results.first() + && let r::Value::Object(ref obj) = first.0 + && let Some(r::Value::String(name)) = obj.get("name") + { + assert_eq!(name, "John", "Should return John"); } }); } @@ -88,16 +86,15 @@ fn sql_can_query_with_aggregation() { let results = result.expect("SQL query should succeed"); assert_eq!(results.len(), 1, "Should return 1 row with count"); - if let Some(first) = results.first() { - if let r::Value::Object(ref obj) = first.0 { - if let Some(total) = obj.get("total") { - // The count should be a number (could be various forms) - match total { - r::Value::Int(n) => assert_eq!(*n, 5), - r::Value::String(s) => assert_eq!(s, "5"), - _ => panic!("Total should be a number: {:?}", total), - } - } + if let Some(first) = results.first() + && let r::Value::Object(ref obj) = first.0 + && let Some(total) = obj.get("total") + { + // The count should be a number (could be various forms) + match total { + r::Value::Int(n) => assert_eq!(*n, 5), + r::Value::String(s) => assert_eq!(s, "5"), + _ => panic!("Total should be a number: {:?}", total), } } }); @@ -112,13 +109,12 @@ fn sql_can_query_with_limit_offset() { assert_eq!(results.len(), 2, "Should return 2 musicians with offset"); // Should skip first musician (order may vary by id type) - if let Some(first) = results.first() { - if let r::Value::Object(ref obj) = first.0 { - if let Some(r::Value::String(name)) = obj.get("name") { - // Just check we got a valid musician name - assert!(["John", "Lisa", "Tom", "Valerie", "Paul"].contains(&name.as_str())); - } - } + if let Some(first) = results.first() + && let r::Value::Object(ref obj) = first.0 + && let Some(r::Value::String(name)) = obj.get("name") + { + // Just check we got a valid musician name + assert!(["John", "Lisa", "Tom", "Valerie", "Paul"].contains(&name.as_str())); } }); } @@ -253,13 +249,13 @@ fn sql_can_query_with_case_expression() { ); // Check that popularity field exists in first result - if let Some(first) = results.first() { - if let r::Value::Object(ref obj) = first.0 { - assert!( - obj.get("popularity").is_some(), - "Should have popularity field" - ); - } + if let Some(first) = results.first() + && let r::Value::Object(ref obj) = first.0 + { + assert!( + obj.get("popularity").is_some(), + "Should have popularity field" + ); } }); } @@ -279,11 +275,11 @@ fn sql_can_query_with_subquery() { let results = result.expect("SQL query with CTE should succeed"); assert_eq!(results.len(), 1, "Should return one count result"); - if let Some(first) = results.first() { - if let r::Value::Object(ref obj) = first.0 { - let count = obj.get("active_count"); - assert!(count.is_some(), "Should have active_count field"); - } + if let Some(first) = results.first() + && let r::Value::Object(ref obj) = first.0 + { + let count = obj.get("active_count"); + assert!(count.is_some(), "Should have active_count field"); } }); } diff --git a/store/test-store/tests/postgres/aggregation.rs b/store/test-store/tests/postgres/aggregation.rs index c2cb619d63f..f005a15b73d 100644 --- a/store/test-store/tests/postgres/aggregation.rs +++ b/store/test-store/tests/postgres/aggregation.rs @@ -3,7 +3,7 @@ use std::fmt::Write; use std::{future::Future, sync::Arc}; use graph::{ - blockchain::{block_stream::FirehoseCursor, BlockPtr, BlockTime}, + blockchain::{BlockPtr, BlockTime, block_stream::FirehoseCursor}, components::{ metrics::stopwatch::StopwatchMetrics, store::{ @@ -15,8 +15,8 @@ use graph::{ }, data::{ store::{ - scalar::{BigDecimal, Bytes, Timestamp}, Entity, Id, IdList, Value, + scalar::{BigDecimal, Bytes, Timestamp}, }, subgraph::DeploymentHash, }, @@ -26,8 +26,8 @@ use graph::{ }; use graph_store_postgres::Store as DieselStore; use test_store::{ - create_test_subgraph, remove_subgraphs, run_test_sequentially, BLOCKS, LOGGER, - METRICS_REGISTRY, STOPWATCH, + BLOCKS, LOGGER, METRICS_REGISTRY, STOPWATCH, create_test_subgraph, remove_subgraphs, + run_test_sequentially, }; const SCHEMA: &str = r#" diff --git a/store/test-store/tests/postgres/chain_head.rs b/store/test-store/tests/postgres/chain_head.rs index 941fe6f9773..d72641b29b6 100644 --- a/store/test-store/tests/postgres/chain_head.rs +++ b/store/test-store/tests/postgres/chain_head.rs @@ -13,20 +13,20 @@ use std::sync::Arc; use graph::cheap_clone::CheapClone; use graph::prelude::alloy; -use graph::prelude::{anyhow::anyhow, anyhow::Error}; use graph::prelude::{BlockNumber, QueryStoreManager, QueryTarget}; +use graph::prelude::{anyhow::Error, anyhow::anyhow}; use graph::{components::store::BlockStore as _, prelude::DeploymentHash}; use graph::{ components::store::ChainHeadStore as _, components::store::ChainStore as _, prelude::EthereumCallCache as _, }; use graph_store_postgres::Store as DieselStore; -use graph_store_postgres::{layout_for_tests::FAKE_NETWORK_SHARED, ChainStore as DieselChainStore}; +use graph_store_postgres::{ChainStore as DieselChainStore, layout_for_tests::FAKE_NETWORK_SHARED}; use test_store::block_store::{ - FakeBlock, FakeBlockList, BLOCK_FIVE, BLOCK_FIVE_AFTER_SKIP, BLOCK_FOUR, - BLOCK_FOUR_SKIPPED_2_AND_3, BLOCK_ONE, BLOCK_ONE_NO_PARENT, BLOCK_ONE_SIBLING, BLOCK_THREE, - BLOCK_THREE_NO_PARENT, BLOCK_TWO, BLOCK_TWO_NO_PARENT, GENESIS_BLOCK, NO_PARENT, + BLOCK_FIVE, BLOCK_FIVE_AFTER_SKIP, BLOCK_FOUR, BLOCK_FOUR_SKIPPED_2_AND_3, BLOCK_ONE, + BLOCK_ONE_NO_PARENT, BLOCK_ONE_SIBLING, BLOCK_THREE, BLOCK_THREE_NO_PARENT, BLOCK_TWO, + BLOCK_TWO_NO_PARENT, FakeBlock, FakeBlockList, GENESIS_BLOCK, NO_PARENT, }; use test_store::*; diff --git a/store/test-store/tests/postgres/graft.rs b/store/test-store/tests/postgres/graft.rs index dc7c759ef64..6536fc3e06c 100644 --- a/store/test-store/tests/postgres/graft.rs +++ b/store/test-store/tests/postgres/graft.rs @@ -9,7 +9,7 @@ use graph::components::store::{ DeploymentLocator, EntityOrder, EntityQuery, PruneReporter, PruneRequest, PruningStrategy, VersionStats, }; -use graph::data::store::{scalar, Id}; +use graph::data::store::{Id, scalar}; use graph::data::subgraph::schema::*; use graph::data::subgraph::*; use graph::semver::Version; diff --git a/store/test-store/tests/postgres/relational.rs b/store/test-store/tests/postgres/relational.rs index 57cac35cc2b..9a50f1ee63e 100644 --- a/store/test-store/tests/postgres/relational.rs +++ b/store/test-store/tests/postgres/relational.rs @@ -5,15 +5,15 @@ use graph::data::store::scalar; use graph::entity; use graph::prelude::alloy::primitives::B256; use graph::prelude::{ - o, slog, DeploymentHash, Entity, EntityCollection, EntityFilter, EntityOrder, EntityQuery, - Logger, StopwatchMetrics, Value, ValueType, BLOCK_NUMBER_MAX, + BLOCK_NUMBER_MAX, DeploymentHash, Entity, EntityCollection, EntityFilter, EntityOrder, + EntityQuery, Logger, StopwatchMetrics, Value, ValueType, o, slog, }; use graph::prelude::{BlockNumber, MetricsRegistry}; use graph::schema::{EntityKey, EntityType, InputSchema}; -use graph_store_postgres::layout_for_tests::set_account_like; +use graph_store_postgres::AsyncPgConnection; use graph_store_postgres::layout_for_tests::LayoutCache; use graph_store_postgres::layout_for_tests::SqlName; -use graph_store_postgres::AsyncPgConnection; +use graph_store_postgres::layout_for_tests::set_account_like; use hex_literal::hex; use lazy_static::lazy_static; use std::collections::BTreeSet; @@ -773,13 +773,11 @@ async fn serialize_bigdecimal() { // Update with overwrite let mut entity = SCALAR_ENTITY.clone(); - let mut vid = 1i64; - for d in &["50", "50.00", "5000", "0.5000", "0.050", "0.5", "0.05"] { + for (vid, d) in (1i64..).zip(&["50", "50.00", "5000", "0.5000", "0.050", "0.5", "0.05"]) { let d = BigDecimal::from_str(d).unwrap(); entity.set("bigDecimal", d).unwrap(); entity.set("vid", vid).unwrap(); - vid += 1; let key = SCALAR_TYPE.key(entity.id()); let entity_type = layout.input_schema.entity_type("Scalar").unwrap(); diff --git a/store/test-store/tests/postgres/relational_bytes.rs b/store/test-store/tests/postgres/relational_bytes.rs index 2c4ac5f27c7..5ab5bb042c9 100644 --- a/store/test-store/tests/postgres/relational_bytes.rs +++ b/store/test-store/tests/postgres/relational_bytes.rs @@ -15,12 +15,11 @@ use std::collections::BTreeSet; use std::str::FromStr; use std::{collections::BTreeMap, sync::Arc}; -use graph::data::store::scalar::{BigDecimal, BigInt}; use graph::data::store::IdList; +use graph::data::store::scalar::{BigDecimal, BigInt}; use graph::prelude::{ - o, slog, AttributeNames, ChildMultiplicity, DeploymentHash, Entity, EntityCollection, - EntityLink, EntityWindow, Logger, ParentLink, StopwatchMetrics, WindowAttribute, - BLOCK_NUMBER_MAX, + AttributeNames, BLOCK_NUMBER_MAX, ChildMultiplicity, DeploymentHash, Entity, EntityCollection, + EntityLink, EntityWindow, Logger, ParentLink, StopwatchMetrics, WindowAttribute, o, slog, }; use graph_store_postgres::{ layout_for_tests::make_dummy_site, diff --git a/store/test-store/tests/postgres/store.rs b/store/test-store/tests/postgres/store.rs index f85a9e89e2d..f6365d292b3 100644 --- a/store/test-store/tests/postgres/store.rs +++ b/store/test-store/tests/postgres/store.rs @@ -1,5 +1,5 @@ -use graph::blockchain::block_stream::FirehoseCursor; use graph::blockchain::BlockTime; +use graph::blockchain::block_stream::FirehoseCursor; use graph::data::graphql::ext::TypeDefinitionExt; use graph::data::subgraph::schema::DeploymentCreate; use graph::data_source::common::MappingABI; diff --git a/store/test-store/tests/postgres/subgraph.rs b/store/test-store/tests/postgres/subgraph.rs index 23b60ecc52c..e4679753e1e 100644 --- a/store/test-store/tests/postgres/subgraph.rs +++ b/store/test-store/tests/postgres/subgraph.rs @@ -6,8 +6,8 @@ use graph::{ data::{ query::QueryTarget, subgraph::{ - schema::{DeploymentCreate, SubgraphError, SubgraphHealth}, DeploymentFeatures, SubgraphFeature, + schema::{DeploymentCreate, SubgraphError, SubgraphHealth}, }, }, prelude::{ @@ -18,8 +18,8 @@ use graph::{ schema::InputSchema, semver::Version, }; -use graph_store_postgres::layout_for_tests::Connection as Primary; use graph_store_postgres::SubgraphStore; +use graph_store_postgres::layout_for_tests::Connection as Primary; use std::{collections::HashSet, marker::PhantomData, sync::Arc}; use test_store::*; @@ -483,9 +483,9 @@ fn status() { .await .unwrap(); let infos = store - .status(status::Filter::Deployments(vec![deployment - .hash - .to_string()])) + .status(status::Filter::Deployments(vec![ + deployment.hash.to_string(), + ])) .await .unwrap(); assert_eq!(1, infos.len()); diff --git a/store/test-store/tests/postgres/writable.rs b/store/test-store/tests/postgres/writable.rs index 2ac4eddd5ce..7c17e8f201f 100644 --- a/store/test-store/tests/postgres/writable.rs +++ b/store/test-store/tests/postgres/writable.rs @@ -442,8 +442,10 @@ fn read_immutable_only_range_test() { #[test] fn read_range_pool_created_test() { run_test(|store, writable, sourceable, deployment| async move { - let result_entities = ["(1, [EntitySourceOperation { entity_op: Create, entity_type: EntityType(PoolCreated), entity: Entity { blockNumber: BigInt(12369621), blockTimestamp: BigInt(1620243254), fee: Int(500), id: Bytes(0xff80818283848586), logIndex: BigInt(0), pool: Bytes(0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8), tickSpacing: Int(10), token0: Bytes(0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), token1: Bytes(0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2), transactionFrom: Bytes(0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), transactionGasPrice: BigInt(100000000000), transactionHash: Bytes(0x12340000000000000000000000000000000000000000000000000000000000000000000000000000), vid: Int8(1) }, vid: 1 }])", - "(2, [EntitySourceOperation { entity_op: Create, entity_type: EntityType(PoolCreated), entity: Entity { blockNumber: BigInt(12369622), blockTimestamp: BigInt(1620243255), fee: Int(3000), id: Bytes(0xff90919293949596), logIndex: BigInt(1), pool: Bytes(0x4585fe77225b41b697c938b018e2ac67ac5a20c0), tickSpacing: Int(60), token0: Bytes(0x2260fac5e5542a773aa44fbcfedf7c193bc2c599), token1: Bytes(0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2), transactionFrom: Bytes(0x2260fac5e5542a773aa44fbcfedf7c193bc2c599), transactionGasPrice: BigInt(100000000000), transactionHash: Bytes(0x12340000000000000000000000000000000000000000000000000000000000000000000000000001), vid: Int8(2) }, vid: 2 }])"]; + let result_entities = [ + "(1, [EntitySourceOperation { entity_op: Create, entity_type: EntityType(PoolCreated), entity: Entity { blockNumber: BigInt(12369621), blockTimestamp: BigInt(1620243254), fee: Int(500), id: Bytes(0xff80818283848586), logIndex: BigInt(0), pool: Bytes(0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8), tickSpacing: Int(10), token0: Bytes(0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), token1: Bytes(0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2), transactionFrom: Bytes(0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48), transactionGasPrice: BigInt(100000000000), transactionHash: Bytes(0x12340000000000000000000000000000000000000000000000000000000000000000000000000000), vid: Int8(1) }, vid: 1 }])", + "(2, [EntitySourceOperation { entity_op: Create, entity_type: EntityType(PoolCreated), entity: Entity { blockNumber: BigInt(12369622), blockTimestamp: BigInt(1620243255), fee: Int(3000), id: Bytes(0xff90919293949596), logIndex: BigInt(1), pool: Bytes(0x4585fe77225b41b697c938b018e2ac67ac5a20c0), tickSpacing: Int(60), token0: Bytes(0x2260fac5e5542a773aa44fbcfedf7c193bc2c599), token1: Bytes(0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2), transactionFrom: Bytes(0x2260fac5e5542a773aa44fbcfedf7c193bc2c599), transactionGasPrice: BigInt(100000000000), transactionHash: Bytes(0x12340000000000000000000000000000000000000000000000000000000000000000000000000001), vid: Int8(2) }, vid: 2 }])", + ]; // Rest of the test remains the same let subgraph_store = store.subgraph_store(); diff --git a/tests/src/contract.rs b/tests/src/contract.rs index d7a67ceffa9..82fc89fec87 100644 --- a/tests/src/contract.rs +++ b/tests/src/contract.rs @@ -5,7 +5,7 @@ use graph::prelude::{ json_abi::JsonAbi, network::{Ethereum, TransactionBuilder}, primitives::{Address, Bytes, U256}, - providers::{ext::AnvilApi, Provider, ProviderBuilder, WalletProvider}, + providers::{Provider, ProviderBuilder, WalletProvider, ext::AnvilApi}, rpc::types::{Block, TransactionReceipt, TransactionRequest}, signers::local::PrivateKeySigner, }, @@ -13,7 +13,7 @@ use graph::prelude::{ serde_json::{self, Value}, }; -use crate::{error, helpers::TestFile, status, CONFIG}; +use crate::{CONFIG, error, helpers::TestFile, status}; // `FROM` and `FROM_KEY` are the address and private key of the first // account that anvil prints on startup diff --git a/tests/src/fixture/ethereum.rs b/tests/src/fixture/ethereum.rs index 40bf54467cc..63a37d668bb 100644 --- a/tests/src/fixture/ethereum.rs +++ b/tests/src/fixture/ethereum.rs @@ -3,8 +3,8 @@ use std::sync::{Arc, Mutex}; use std::time::Duration; use super::{ - test_ptr, CommonChainConfig, MutexBlockStreamBuilder, NoopAdapterSelector, - NoopRuntimeAdapterBuilder, StaticBlockRefetcher, StaticStreamBuilder, Stores, TestChain, + CommonChainConfig, MutexBlockStreamBuilder, NoopAdapterSelector, NoopRuntimeAdapterBuilder, + StaticBlockRefetcher, StaticStreamBuilder, Stores, TestChain, test_ptr, }; use graph::abi; use graph::blockchain::block_stream::BlockWithTriggers; @@ -16,17 +16,17 @@ use graph::data_source::subgraph; use graph::prelude::alloy::primitives::{Address, B256, U256}; use graph::prelude::alloy::rpc::types::BlockTransactions; use graph::prelude::{ - create_dummy_transaction, create_minimal_block_for_test, tiny_keccak, DeploymentHash, Entity, - LightEthereumBlock, ENV_VARS, + DeploymentHash, ENV_VARS, Entity, LightEthereumBlock, create_dummy_transaction, + create_minimal_block_for_test, tiny_keccak, }; use graph::schema::EntityType; use graph_chain_ethereum::network::EthereumNetworkAdapters; use graph_chain_ethereum::trigger::LogRef; +use graph_chain_ethereum::{Chain, chain::ChainSettings}; use graph_chain_ethereum::{ chain::BlockFinality, trigger::{EthereumBlockTriggerType, EthereumTrigger}, }; -use graph_chain_ethereum::{chain::ChainSettings, Chain}; pub async fn chain( test_name: &str, diff --git a/tests/src/fixture/mod.rs b/tests/src/fixture/mod.rs index 19b459f2a6c..7577cd7e8fe 100644 --- a/tests/src/fixture/mod.rs +++ b/tests/src/fixture/mod.rs @@ -36,21 +36,21 @@ use graph::env::EnvVars; use graph::firehose::{FirehoseEndpoint, FirehoseEndpoints, SubgraphLimit}; use graph::futures03::{Stream, StreamExt}; use graph::http_body_util::Full; -use graph::hyper::body::Bytes; use graph::hyper::Request; +use graph::hyper::body::Bytes; use graph::ipfs::{IpfsClient, IpfsMetrics}; use graph::prelude::alloy::primitives::B256; use graph::prelude::alloy::primitives::U256; use graph::prelude::serde_json::{self, json}; use graph::prelude::{ - lazy_static, q, r, ApiVersion, BigInt, BlockNumber, DeploymentHash, GraphQlRunner as _, - IpfsResolver, LinkResolver, LoggerFactory, NodeId, QueryError, SubgraphCountMetric, - SubgraphName, SubgraphRegistrar, SubgraphStore as _, SubgraphVersionSwitchingMode, - TriggerProcessor, + ApiVersion, BigInt, BlockNumber, DeploymentHash, GraphQlRunner as _, IpfsResolver, + LinkResolver, LoggerFactory, NodeId, QueryError, SubgraphCountMetric, SubgraphName, + SubgraphRegistrar, SubgraphStore as _, SubgraphVersionSwitchingMode, TriggerProcessor, + lazy_static, q, r, }; +use graph_chain_ethereum::Chain; use graph_chain_ethereum::chain::RuntimeAdapterBuilder; use graph_chain_ethereum::network::EthereumNetworkAdapters; -use graph_chain_ethereum::Chain; use graph_core::polling_monitor::{arweave_service, ipfs_service}; use graph_node::config::Opt; use graph_node::manager::PanicSubscriptionManager; @@ -59,7 +59,7 @@ use graph_runtime_wasm::RuntimeHostBuilder; use graph_server_index_node::IndexNodeService; use graph_store_postgres::{ChainHeadUpdateListener, ChainStore, Store, SubgraphStore}; use serde::Deserialize; -use slog::{crit, debug, info, o, Discard, Logger}; +use slog::{Discard, Logger, crit, debug, info, o}; use std::env::VarError; use std::pin::Pin; use std::sync::Arc; diff --git a/tests/src/helpers.rs b/tests/src/helpers.rs index fb06a583923..50403d46eea 100644 --- a/tests/src/helpers.rs +++ b/tests/src/helpers.rs @@ -4,9 +4,9 @@ use std::path::PathBuf; use std::process::Command; use crate::output::OutputConfig; -use anyhow::{bail, Context}; +use anyhow::{Context, bail}; use graph::itertools::Itertools; -use graph::prelude::serde_json::{json, Value}; +use graph::prelude::serde_json::{Value, json}; use graph::prelude::{reqwest, serde_json}; /// Parses stdout bytes into a prefixed String diff --git a/tests/src/lib.rs b/tests/src/lib.rs index 33c6246c8b4..860f6da714d 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -8,5 +8,5 @@ pub mod output; pub mod recipe; pub mod subgraph; -pub use config::{Config, DbConfig, EthConfig, CONFIG}; +pub use config::{CONFIG, Config, DbConfig, EthConfig}; pub use output::OutputConfig; diff --git a/tests/src/output.rs b/tests/src/output.rs index a1cb960ded2..fece1947528 100644 --- a/tests/src/output.rs +++ b/tests/src/output.rs @@ -4,7 +4,7 @@ //! to `tests/runner-tests.log` while progress messages appear on the console. //! In CI (detected via `GITHUB_ACTIONS` env var), all output goes to the console. -use slog::{o, Drain, Logger}; +use slog::{Drain, Logger, o}; use std::fs::File; use std::io::{self, Write}; use std::path::PathBuf; diff --git a/tests/src/recipe.rs b/tests/src/recipe.rs index d0e0b2fe242..d1d424ad190 100644 --- a/tests/src/recipe.rs +++ b/tests/src/recipe.rs @@ -1,5 +1,5 @@ use crate::{ - fixture::{stores, Stores, TestInfo}, + fixture::{Stores, TestInfo, stores}, helpers::run_cmd, }; use graph::prelude::{DeploymentHash, SubgraphName}; diff --git a/tests/src/subgraph.rs b/tests/src/subgraph.rs index 67513f49ca0..43c970fbd40 100644 --- a/tests/src/subgraph.rs +++ b/tests/src/subgraph.rs @@ -12,9 +12,9 @@ use serde_yaml; use tokio::{process::Command, time::sleep}; use crate::{ - contract::Contract, - helpers::{graphql_query, graphql_query_with_vars, run_checked, TestFile}, CONFIG, + contract::Contract, + helpers::{TestFile, graphql_query, graphql_query_with_vars, run_checked}, }; #[derive(Clone, Debug)] @@ -155,10 +155,10 @@ impl Subgraph { pub async fn wait_ready(name: &str) -> anyhow::Result { let start = Instant::now(); while start.elapsed() <= CONFIG.timeout { - if let Some(subgraph) = Self::status(name).await? { - if subgraph.synced || !subgraph.healthy { - return Ok(subgraph); - } + if let Some(subgraph) = Self::status(name).await? + && (subgraph.synced || !subgraph.healthy) + { + return Ok(subgraph); } sleep(Duration::from_millis(2000)).await; } diff --git a/tests/tests/file_link_resolver.rs b/tests/tests/file_link_resolver.rs index 0213c209457..0fdab778a3b 100644 --- a/tests/tests/file_link_resolver.rs +++ b/tests/tests/file_link_resolver.rs @@ -10,7 +10,9 @@ use graph_tests::{ #[graph::test] async fn file_link_resolver() -> anyhow::Result<()> { - std::env::set_var("GRAPH_NODE_DISABLE_DEPLOYMENT_HASH_VALIDATION", "true"); + unsafe { + std::env::set_var("GRAPH_NODE_DISABLE_DEPLOYMENT_HASH_VALIDATION", "true"); + } let RunnerTestRecipe { stores, test_info } = RunnerTestRecipe::new_with_file_link_resolver( "file_link_resolver", "file-link-resolver", diff --git a/tests/tests/gnd_cli_tests.rs b/tests/tests/gnd_cli_tests.rs index 43676cbed11..1bbeb88cbc8 100644 --- a/tests/tests/gnd_cli_tests.rs +++ b/tests/tests/gnd_cli_tests.rs @@ -29,12 +29,12 @@ use std::path::PathBuf; use anyhow::anyhow; use graph::futures03::StreamExt; use graph_tests::contract::Contract; -use graph_tests::{error, status, CONFIG}; +use graph_tests::{CONFIG, error, status}; mod integration_tests; use integration_tests::{ - stop_graph_node, test_block_handlers, test_int8, test_value_roundtrip, TestCase, TestResult, + TestCase, TestResult, stop_graph_node, test_block_handlers, test_int8, test_value_roundtrip, }; /// Get the path to the gnd binary diff --git a/tests/tests/gnd_tests.rs b/tests/tests/gnd_tests.rs index 0ed1ac5ec8a..f1dbde81a53 100644 --- a/tests/tests/gnd_tests.rs +++ b/tests/tests/gnd_tests.rs @@ -3,13 +3,13 @@ use graph::futures03::StreamExt; use graph_tests::config::set_dev_mode; use graph_tests::contract::Contract; use graph_tests::subgraph::Subgraph; -use graph_tests::{error, status, CONFIG}; +use graph_tests::{CONFIG, error, status}; mod integration_tests; use integration_tests::{ - stop_graph_node, subgraph_data_sources, test_block_handlers, - test_multiple_subgraph_datasources, TestCase, TestResult, + TestCase, TestResult, stop_graph_node, subgraph_data_sources, test_block_handlers, + test_multiple_subgraph_datasources, }; /// The main test entrypoint. diff --git a/tests/tests/integration_tests.rs b/tests/tests/integration_tests.rs index ee1f0f201dc..12f5837f96e 100644 --- a/tests/tests/integration_tests.rs +++ b/tests/tests/integration_tests.rs @@ -14,7 +14,7 @@ use std::future::Future; use std::pin::Pin; use std::time::{Duration, Instant}; -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{Context, Result, anyhow, bail}; use graph::components::subgraph::{ ProofOfIndexing, ProofOfIndexingEvent, ProofOfIndexingFinisher, ProofOfIndexingVersion, }; @@ -22,13 +22,13 @@ use graph::data::store::Id; use graph::entity; use graph::futures03::StreamExt; use graph::itertools::Itertools; -use graph::prelude::serde_json::{json, Value}; -use graph::prelude::{alloy::primitives::Address, hex, BlockPtr, DeploymentHash}; +use graph::prelude::serde_json::{Value, json}; +use graph::prelude::{BlockPtr, DeploymentHash, alloy::primitives::Address, hex}; use graph::schema::InputSchema; -use graph::slog::{o, Discard, Logger}; +use graph::slog::{Discard, Logger, o}; use graph_tests::contract::Contract; use graph_tests::subgraph::Subgraph; -use graph_tests::{error, status, CONFIG}; +use graph_tests::{CONFIG, error, status}; use tokio::process::Child; use tokio::task::JoinError; use tokio::time::sleep; @@ -1200,9 +1200,9 @@ async fn test_declared_calls_basic(ctx: TestContext) -> anyhow::Result<()> { ); let Some(act_value) = call_result["value"].as_str() else { panic!( - "Expected call result with label '{}' to have a string 'value' field, but got: {:?}", - label, call_result["value"] - ); + "Expected call result with label '{}' to have a string 'value' field, but got: {:?}", + label, call_result["value"] + ); }; assert_eq!( exp_value, act_value, diff --git a/tests/tests/runner_tests.rs b/tests/tests/runner_tests.rs index a215d270a5d..743f5714df3 100644 --- a/tests/tests/runner_tests.rs +++ b/tests/tests/runner_tests.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; use std::marker::PhantomData; use std::str::FromStr; -use std::sync::atomic::{self, AtomicBool}; use std::sync::Arc; +use std::sync::atomic::{self, AtomicBool}; use std::time::Duration; use assert_json_diff::assert_json_eq; @@ -17,7 +17,7 @@ use graph::env::{EnvVars, TEST_WITH_NO_REORG}; use graph::ipfs::test_utils::add_files_to_local_ipfs_node_for_testing; use graph::object; use graph::prelude::alloy::primitives::{Address, B256, U256}; -use graph::prelude::{hex, CheapClone, SubgraphName, SubgraphStore}; +use graph::prelude::{CheapClone, SubgraphName, SubgraphStore, hex}; use graph_tests::fixture::ethereum::{ chain, empty_block, generate_empty_blocks_for_range, genesis, push_test_command, push_test_log, push_test_polling_trigger, @@ -25,18 +25,18 @@ use graph_tests::fixture::ethereum::{ use graph::blockchain::Trigger; use graph::prelude::alloy::rpc::types::BlockTransactions; -use graph::prelude::{create_dummy_transaction, create_minimal_block_for_test, LightEthereumBlock}; +use graph::prelude::{LightEthereumBlock, create_dummy_transaction, create_minimal_block_for_test}; use graph_chain_ethereum::{ chain::BlockFinality, trigger::{EthereumBlockTriggerType, EthereumTrigger}, }; use graph_tests::fixture::{ - self, test_ptr, test_ptr_reorged, MockAdapterSelector, NoopAdapterSelector, - StaticArweaveResolver, TestChainTrait, TestContext, TestInfo, + self, MockAdapterSelector, NoopAdapterSelector, StaticArweaveResolver, TestChainTrait, + TestContext, TestInfo, test_ptr, test_ptr_reorged, }; -use graph_tests::recipe::{build_subgraph_with_pnpm_cmd_and_arg, RunnerTestRecipe}; -use slog::{o, Discard, Logger}; +use graph_tests::recipe::{RunnerTestRecipe, build_subgraph_with_pnpm_cmd_and_arg}; +use slog::{Discard, Logger, o}; fn assert_eq_ignore_backtrace(err: &SubgraphError, expected: &SubgraphError) { let equal = {