Skip to content

Commit

Permalink
feat: update tap, toolshed and ethers dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannis committed Dec 1, 2023
1 parent d2fad80 commit 5ced9ed
Show file tree
Hide file tree
Showing 25 changed files with 187 additions and 227 deletions.
252 changes: 102 additions & 150 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.1.0"
edition = "2021"

[dependencies]
alloy-primitives = { version = "0.4.2", features = ["serde"] }
alloy-sol-types = "0.4.2"
alloy-primitives = { version = "0.5.2", features = ["serde"] }
alloy-sol-types = "0.5.2"
anyhow = "1.0.75"
arc-swap = "1.6.0"
ethers = "2.0.10"
Expand All @@ -30,12 +30,10 @@ sqlx = { version = "0.7.1", features = [
"time",
] }
tokio = { version = "1.32.0", features = ["full", "macros", "rt"] }
toolshed = { git = "https://github.com/edgeandnode/toolshed", branch = "main", features = [
"graphql",
] }
thegraph = { git = "https://github.com/edgeandnode/toolshed", branch = "main" }
tracing = "0.1.34"
graphql = { git = "https://github.com/edgeandnode/toolshed", branch = "main" }
tap_core = "0.6.0"
graphql-http = { git = "https://github.com/edgeandnode/toolshed", branch = "main" }
tap_core = "0.7.0"

[dev-dependencies]
env_logger = "0.9.0"
Expand Down
2 changes: 1 addition & 1 deletion common/src/allocations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use alloy_primitives::Address;
use ethers_core::types::U256;
use serde::{Deserialize, Deserializer};
use toolshed::thegraph::DeploymentId;
use thegraph::types::DeploymentId;

pub mod monitor;

Expand Down
9 changes: 5 additions & 4 deletions common/src/allocations/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ async fn current_epoch(
}))
.await?;

if let Some(errors) = response.errors {
if !response.errors.is_empty() {
warn!(
"Errors encountered identifying current epoch for network {}: {}",
graph_network_id,
errors
response
.errors
.into_iter()
.map(|e| e.message)
.collect::<Vec<_>>()
Expand Down Expand Up @@ -147,11 +148,11 @@ pub fn indexer_allocations(
.map_err(|e| e.to_string())?;

// If there are any GraphQL errors returned, we'll log them for debugging
if let Some(errors) = response.errors {
if !response.errors.is_empty() {
warn!(
"Errors encountered fetching active or recently closed allocations for indexer {:?}: {}",
indexer_address,
errors.into_iter().map(|e| e.message).collect::<Vec<_>>().join(", ")
response.errors.into_iter().map(|e| e.message).collect::<Vec<_>>().join(", ")
);
}

Expand Down
5 changes: 3 additions & 2 deletions common/src/attestations/dispute_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ pub fn dispute_manager(
.await
.map_err(|e| e.to_string())?;

if let Some(errors) = response.errors {
if !response.errors.is_empty() {
warn!(
"Errors encountered querying the dispute manager for network {}: {}",
graph_network_id,
errors
response
.errors
.into_iter()
.map(|e| e.message)
.collect::<Vec<_>>()
Expand Down
3 changes: 1 addition & 2 deletions common/src/attestations/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use alloy_sol_types::Eip712Domain;
use ethers::signers::coins_bip39::English;
use ethers::signers::{MnemonicBuilder, Signer, Wallet};
use ethers_core::k256::ecdsa::SigningKey;
use toolshed::thegraph::attestation::{self, Attestation};
use toolshed::thegraph::DeploymentId;
use thegraph::types::{attestation, Attestation, DeploymentId};

use crate::prelude::Allocation;

Expand Down
5 changes: 3 additions & 2 deletions common/src/escrow_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ pub fn escrow_accounts(
.map_err(|e| e.to_string())?;

// If there are any GraphQL errors returned, we'll log them for debugging
if let Some(errors) = response.errors {
if !response.errors.is_empty() {
error!(
"Errors encountered fetching escrow accounts for indexer {:?}: {}",
indexer_address,
errors
response
.errors
.into_iter()
.map(|e| e.message)
.collect::<Vec<_>>()
Expand Down
16 changes: 8 additions & 8 deletions common/src/subgraph_client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

use anyhow::anyhow;
use eventuals::Eventual;
use graphql::http::Response;
use graphql_http::http::response::ResponseBody;
use reqwest::{header, Url};
use serde::de::Deserialize;
use serde_json::Value;
use toolshed::thegraph::DeploymentId;
use thegraph::types::DeploymentId;
use tracing::warn;

use super::monitor::{monitor_deployment_status, DeploymentStatus};
Expand Down Expand Up @@ -62,7 +62,7 @@ impl DeploymentClient {
pub async fn query<T: for<'de> Deserialize<'de>>(
&self,
body: &Value,
) -> Result<Response<T>, anyhow::Error> {
) -> Result<ResponseBody<T>, anyhow::Error> {
if let Some(ref status) = self.status {
let deployment_status = status.value().await.expect("reading deployment status");

Expand All @@ -83,7 +83,7 @@ impl DeploymentClient {
.send()
.await
.and_then(|response| response.error_for_status())?
.json::<Response<T>>()
.json::<ResponseBody<T>>()
.await?)
}
}
Expand All @@ -109,7 +109,7 @@ impl SubgraphClient {
pub async fn query<T: for<'de> Deserialize<'de>>(
&self,
body: &Value,
) -> Result<Response<T>, anyhow::Error> {
) -> Result<ResponseBody<T>, anyhow::Error> {
// Try the local client first; if that fails, log the error and move on
// to the remote client
if let Some(ref local_client) = self.local_client {
Expand Down Expand Up @@ -273,7 +273,7 @@ mod test {
);

// Query the subgraph
let response: Response<Value> = client
let response: ResponseBody<Value> = client
.query(&json!({ "query": "{ user(id: 1} { name } }"}))
.await
.unwrap();
Expand Down Expand Up @@ -352,7 +352,7 @@ mod test {
);

// Query the subgraph
let response: Response<Value> = client
let response: ResponseBody<Value> = client
.query(&json!({ "query": "{ user(id: 1} { name } }"}))
.await
.unwrap();
Expand Down Expand Up @@ -431,7 +431,7 @@ mod test {
);

// Query the subgraph
let response: Response<Value> = client
let response: ResponseBody<Value> = client
.query(&json!({ "query": "{ user(id: 1} { name } }"}))
.await
.unwrap();
Expand Down
13 changes: 7 additions & 6 deletions common/src/subgraph_client/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
use std::time::Duration;

use eventuals::{timer, Eventual, EventualExt};
use graphql::http::Response;
use graphql_http::http::response::ResponseBody;
use reqwest::{header, Url};
use serde::Deserialize;
use serde_json::{json, Value};
use thegraph::types::DeploymentId;
use tokio::time::sleep;
use toolshed::thegraph::DeploymentId;
use tracing::warn;

#[derive(Deserialize)]
Expand All @@ -27,15 +27,15 @@ pub struct DeploymentStatus {
async fn query<T: for<'de> Deserialize<'de>>(
url: Url,
body: &Value,
) -> Result<Response<T>, reqwest::Error> {
) -> Result<ResponseBody<T>, reqwest::Error> {
reqwest::Client::new()
.post(url)
.json(body)
.header(header::CONTENT_TYPE, "application/json")
.send()
.await
.and_then(|response| response.error_for_status())?
.json::<Response<T>>()
.json::<ResponseBody<T>>()
.await
}

Expand Down Expand Up @@ -68,11 +68,12 @@ pub fn monitor_deployment_status(
format!("Failed to query status of deployment `{deployment}`: {e}")
})?;

if let Some(errors) = response.errors {
if !response.errors.is_empty() {
warn!(
"Errors encountered querying the deployment status for `{}`: {}",
deployment,
errors
response
.errors
.into_iter()
.map(|e| e.message)
.collect::<Vec<_>>()
Expand Down
2 changes: 1 addition & 1 deletion common/src/test_vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{collections::HashMap, str::FromStr};
use alloy_primitives::Address;
use ethers_core::types::U256;
use lazy_static::lazy_static;
use toolshed::thegraph::DeploymentId;
use thegraph::types::DeploymentId;

use crate::prelude::{Allocation, AllocationStatus, SubgraphDeployment};

Expand Down
26 changes: 18 additions & 8 deletions service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "service"
version = "0.1.0"
edition = "2021"
description="Could not find crate on crates.io and could not import with git and path at the same time, so copied a version directly at https://github.com/graphprotocol/indexer/blob/972658b3ce8c512ad7b4dc575d29cd9d5377e3fe/packages/indexer-native/native"
description = "Could not find crate on crates.io and could not import with git and path at the same time, so copied a version directly at https://github.com/graphprotocol/indexer/blob/972658b3ce8c512ad7b4dc575d29cd9d5377e3fe/packages/indexer-native/native"
license = "Apache-2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -25,7 +25,11 @@ serde_json = "1"
axum = "0.5"
hyper = "0.14.27"
tower = { version = "0.4", features = ["util", "timeout", "limit"] }
tower-http = { version = "0.4.0", features = ["add-extension", "trace", "cors"] }
tower-http = { version = "0.4.0", features = [
"add-extension",
"trace",
"cors",
] }
toml = "0.7.4"
once_cell = "1.17"
async-graphql = "4.0.16"
Expand All @@ -42,13 +46,19 @@ autometrics = { version = "0.3.3", features = ["prometheus-exporter"] }
clap = { version = "4.3.1", features = ["derive", "env"] }
prometheus = "0.13.3"
hex = "0.4.3"
tap_core = "0.6.0"
tap_core = "0.7.0"
ethereum-types = "0.14.1"
sqlx = { version = "0.7.1", features = ["postgres", "runtime-tokio", "bigdecimal", "rust_decimal", "time"] }
alloy-primitives = { version = "0.4.2", features = ["serde"] }
alloy-sol-types = "0.4.2"
sqlx = { version = "0.7.1", features = [
"postgres",
"runtime-tokio",
"bigdecimal",
"rust_decimal",
"time",
] }
alloy-primitives = { version = "0.5.2", features = ["serde"] }
alloy-sol-types = "0.5.2"
lazy_static = "1.4.0"
toolshed = { git = "https://github.com/edgeandnode/toolshed", branch = "main", features = ["graphql"] }
thegraph = { git = "https://github.com/edgeandnode/toolshed", branch = "main" }

[dev-dependencies]
faux = "0.1.10"
Expand All @@ -65,4 +75,4 @@ wiremock = "0.5.19"
version = "1"
default-features = false
# Disable features which are enabled by default
features = ["precommit-hook", "run-cargo-fmt", "run-cargo-clippy"]
features = ["precommit-hook", "run-cargo-fmt", "run-cargo-clippy"]
13 changes: 1 addition & 12 deletions service/src/common/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,7 @@
use ethers::signers::{
coins_bip39::English, LocalWallet, MnemonicBuilder, Signer, Wallet, WalletError,
};
use ethers_core::{k256::ecdsa::SigningKey, utils::hex};
use sha3::{Digest, Keccak256};

/// A normalized address in checksum format.
pub type Address = String;

/// Converts an address to checksum format and returns a typed instance.
pub fn to_address(s: impl AsRef<str>) -> Address {
let address = s.as_ref().to_ascii_lowercase();
let hash = &Keccak256::digest(address);
hex::encode(hash)
}
use ethers_core::k256::ecdsa::SigningKey;

/// Build Wallet from Private key or Mnemonic
pub fn build_wallet(value: &str) -> Result<Wallet<SigningKey>, WalletError> {
Expand Down
2 changes: 1 addition & 1 deletion service/src/common/indexer_management/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{collections::HashSet, str::FromStr};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use sqlx::PgPool;
use toolshed::thegraph::{DeploymentId, DeploymentIdError};
use thegraph::types::{DeploymentId, DeploymentIdError};

/// Internal cost model representation as stored in the database.
///
Expand Down
2 changes: 1 addition & 1 deletion service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use clap::{command, Args, Parser, ValueEnum};

use alloy_primitives::Address;
use serde::{Deserialize, Serialize};
use toolshed::thegraph::DeploymentId;
use thegraph::types::DeploymentId;

use crate::util::init_tracing;

Expand Down
2 changes: 1 addition & 1 deletion service/src/graph_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use anyhow::anyhow;
use reqwest::{header, Client, Url};
use std::sync::Arc;
use toolshed::thegraph::DeploymentId;
use thegraph::types::DeploymentId;

use crate::query_processor::{QueryError, UnattestedQueryResult};

Expand Down
3 changes: 1 addition & 2 deletions service/src/query_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use indexer_common::tap_manager::TapManager;
use log::error;
use serde::{Deserialize, Serialize};
use tap_core::tap_manager::SignedReceipt;
use toolshed::thegraph::attestation::Attestation;
use toolshed::thegraph::DeploymentId;
use thegraph::types::{attestation::Attestation, DeploymentId};

use indexer_common::indexer_errors::{IndexerError, IndexerErrorCause, IndexerErrorCode};
use indexer_common::prelude::AttestationSigner;
Expand Down
2 changes: 1 addition & 1 deletion service/src/server/routes/cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use async_graphql_axum::{GraphQLRequest, GraphQLResponse};
use axum::extract::Extension;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use toolshed::thegraph::DeploymentId;
use thegraph::types::DeploymentId;

use crate::{
common::indexer_management::{self, CostModel},
Expand Down
6 changes: 2 additions & 4 deletions service/src/server/routes/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ pub async fn network_queries(
match server.network_subgraph.query::<Value>(&body).await {
Ok(result) => Json(json!({
"data": result.data,
"errors": result.errors.map(|errors| {
errors
"errors": result.errors
.into_iter()
.map(|e| json!({ "message": e.message }))
.collect::<Vec<_>>()
}),
.collect::<Vec<_>>(),
}))
.into_response(),
Err(e) => bad_request_response(&e.to_string()),
Expand Down
2 changes: 1 addition & 1 deletion service/src/server/routes/subgraphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use axum::{
Json,
};
use std::str::FromStr;
use toolshed::thegraph::DeploymentId;
use thegraph::types::DeploymentId;
use tracing::trace;

use crate::{
Expand Down
Loading

0 comments on commit 5ced9ed

Please sign in to comment.