Skip to content

Commit

Permalink
feat: use thegraph-core alloy crate
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo Delgado <[email protected]>
  • Loading branch information
LNSD committed Dec 19, 2024
1 parent 44b1851 commit 3ceac86
Show file tree
Hide file tree
Showing 82 changed files with 953 additions and 876 deletions.
257 changes: 155 additions & 102 deletions Cargo.lock

Large diffs are not rendered by default.

25 changes: 12 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ resolver = "2"
opt-level = 3

[workspace.dependencies]
alloy = { version = "=0.5.4", features = [
"kzg",
"signer-mnemonic",
"dyn-abi",
"sol-types",
"signer-local",
"eip712",
"rlp",
"signers",
], default-features = false }
clap = "4.4.3"
lazy_static = "1.4.0"
axum = { version = "0.7.9", default-features = false, features = [
Expand Down Expand Up @@ -62,14 +52,23 @@ uuid = { version = "1.11.0", features = ["v7"] }
tracing = { version = "0.1.40", default-features = false }
bigdecimal = "0.4.3"
build-info = "0.0.39"
tap_core = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "61b47b3", default-features = false }
tap_aggregator = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "61b47b3", default-features = false }
tap_core = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "1c6e29f", default-features = false }
tap_aggregator = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "1c6e29f", default-features = false }
tracing-subscriber = { version = "0.3", features = [
"json",
"env-filter",
"ansi",
], default-features = false }
thegraph-core = { git = "https://github.com/edgeandnode/toolshed", rev = "1663534fc1738e2db1b11cb54b5bb478ee970d40" }
thegraph-core = { version = "0.9.6", features = [
"attestation",
"alloy-eip712",
"alloy-sol-types",
"alloy-rlp",
"alloy-signers",
"alloy-signer-local",
"alloy-signer-mnemonic",
"serde"
] }
thegraph-graphql-http = { version = "0.3.2", features = ["reqwest"] }
graphql_client = { version = "0.14.0", features = ["reqwest-rustls"] }
bip39 = "2.0.0"
Expand Down
1 change: 0 additions & 1 deletion crates/allocation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ edition = "2021"
[dependencies]
indexer-query = { path = "../query" }
serde = { workspace = true, features = ["derive"] }
alloy.workspace = true
thegraph-core.workspace = true
anyhow.workspace = true
6 changes: 4 additions & 2 deletions crates/allocation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

use std::str::FromStr;

use alloy::primitives::U256;
use indexer_query::allocations_query;
use serde::{Deserialize, Deserializer};
use thegraph_core::{Address, DeploymentId};
use thegraph_core::{
alloy::primitives::{Address, U256},
DeploymentId,
};

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Allocation {
Expand Down
1 change: 0 additions & 1 deletion crates/attestation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ edition = "2021"

[dependencies]
indexer-allocation = { path = "../allocation" }
alloy.workspace = true
thegraph-core.workspace = true
anyhow.workspace = true

Expand Down
46 changes: 28 additions & 18 deletions crates/attestation/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
// SPDX-License-Identifier: Apache-2.0

use alloy::{
dyn_abi::Eip712Domain,
signers::{
k256,
local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner},
use indexer_allocation::Allocation;
use thegraph_core::{
alloy::{
primitives::{Address, ChainId},
signers::{
k256,
local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner},
},
sol_types::Eip712Domain,
},
attestation,
attestation::Attestation,
DeploymentId,
};
use thegraph_core::{attestation, Address, Attestation, ChainId, DeploymentId};

use indexer_allocation::Allocation;

pub fn derive_key_pair(
indexer_mnemonic: &str,
Expand Down Expand Up @@ -92,7 +96,7 @@ fn wallet_for_allocation(
// range [0, 100] and checking for a match
for i in 0..100 {
// The allocation was either created at the epoch it intended to or one
// epoch later. So try both both.
// epoch later. So try both.
for created_at_epoch in [allocation.created_at_epoch, allocation.created_at_epoch - 1] {
// The allocation ID is the address of a unique key pair, we just
// need to find the right one by enumerating them all
Expand All @@ -117,14 +121,20 @@ fn wallet_for_allocation(

#[cfg(test)]
mod tests {
use alloy::primitives::U256;
use std::str::FromStr;
use test_log::test;

use indexer_allocation::{Allocation, AllocationStatus, SubgraphDeployment};
use test_assets::DISPUTE_MANAGER_ADDRESS;
use test_log::test;
use thegraph_core::{
alloy::{
primitives::{address, Address, U256},
signers::local::PrivateKeySigner,
},
DeploymentId,
};

use super::*;
use super::{derive_key_pair, AttestationSigner};

const INDEXER_OPERATOR_MNEMONIC: &str = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";

Expand All @@ -142,7 +152,7 @@ mod tests {
)
.unwrap()
.address(),
Address::from_str("0xfa44c72b753a66591f241c7dc04e8178c30e13af").unwrap()
address!("fa44c72b753a66591f241c7dc04e8178c30e13af")
);

assert_eq!(
Expand All @@ -157,7 +167,7 @@ mod tests {
)
.unwrap()
.address(),
Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap()
address!("a171cd12c3dde7eb8fe7717a0bcd06f3ffa65658")
);
}

Expand All @@ -166,7 +176,7 @@ mod tests {
// Note that we use `derive_key_pair` to derive the private key

let allocation = Allocation {
id: Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap(),
id: address!("a171cd12c3dde7eb8fe7717a0bcd06f3ffa65658"),
status: AllocationStatus::Null,
subgraph_deployment: SubgraphDeployment {
id: DeploymentId::from_str(
Expand All @@ -192,7 +202,7 @@ mod tests {
INDEXER_OPERATOR_MNEMONIC,
&allocation,
1,
*DISPUTE_MANAGER_ADDRESS
DISPUTE_MANAGER_ADDRESS
)
.unwrap()
.signer
Expand All @@ -213,7 +223,7 @@ mod tests {

let allocation = Allocation {
// Purposefully wrong address
id: Address::from_str("0xdeadbeefcafebabedeadbeefcafebabedeadbeef").unwrap(),
id: address!("deadbeefcafebabedeadbeefcafebabedeadbeef"),
status: AllocationStatus::Null,
subgraph_deployment: SubgraphDeployment {
id: DeploymentId::from_str(
Expand All @@ -237,7 +247,7 @@ mod tests {
INDEXER_OPERATOR_MNEMONIC,
&allocation,
1,
*DISPUTE_MANAGER_ADDRESS
DISPUTE_MANAGER_ADDRESS
)
.is_err());
}
Expand Down
1 change: 0 additions & 1 deletion crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version = "1.2.2"
edition = "2021"

[dependencies]
alloy.workspace = true
serde.workspace = true
thegraph-core.workspace = true
tracing.workspace = true
Expand Down
47 changes: 21 additions & 26 deletions crates/config/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
// SPDX-License-Identifier: Apache-2.0

use bigdecimal::{BigDecimal, FromPrimitive, ToPrimitive};
use figment::{
providers::{Env, Format, Toml},
Figment,
};
use serde_repr::Deserialize_repr;
use serde_with::DurationSecondsWithFrac;
use std::{
collections::HashMap,
env,
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
path::PathBuf,
str::FromStr,
time::Duration,
};
use tracing::warn;

use alloy::primitives::Address;
use bigdecimal::{BigDecimal, FromPrimitive, ToPrimitive};
use bip39::Mnemonic;
use figment::{
providers::{Env, Format, Toml},
Figment,
};
use regex::Regex;
use serde::Deserialize;
use serde_with::serde_as;
use std::env;
use thegraph_core::DeploymentId;
use serde_repr::Deserialize_repr;
use serde_with::{serde_as, DurationSecondsWithFrac};
use thegraph_core::{alloy::primitives::Address, DeploymentId};
use url::Url;

use crate::NonZeroGRT;
Expand Down Expand Up @@ -57,7 +54,7 @@ impl<'de> Deserialize<'de> for ConfigWrapper {
D: serde::Deserializer<'de>,
{
let config: Config = serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown configuration field: {}", path);
tracing::warn!("Ignoring unknown configuration field: {}", path);
})?;

Ok(ConfigWrapper(config))
Expand Down Expand Up @@ -158,7 +155,7 @@ impl Config {
x if *x <= 1.into() => {
return Err("trigger_value_divisor must be greater than 1".to_string())
}
x if *x > 1.into() && *x < 10.into() => warn!(
x if *x > 1.into() && *x < 10.into() => tracing::warn!(
"It's recommended that trigger_value_divisor \
be a value greater than 10."
),
Expand All @@ -176,7 +173,7 @@ impl Config {
.to_u128()
.unwrap()
{
warn!(
tracing::warn!(
"Trigger value is too low, currently below 0.1 GRT. \
Please modify `max_amount_willing_to_lose_grt` or `trigger_value_divisor`. \
It is best to have a higher trigger value, ideally above 1 GRT. \
Expand All @@ -190,7 +187,7 @@ impl Config {
let usual_grt_price = BigDecimal::from_str("0.0001").unwrap() * ten;
if self.tap.max_amount_willing_to_lose_grt.get_value() < usual_grt_price.to_u128().unwrap()
{
warn!(
tracing::warn!(
"Your `max_amount_willing_to_lose_grt` value is too close to zero. \
This may deny the sender too often or even break the whole system. \
It's recommended it to be a value greater than 100x an usual query price."
Expand All @@ -200,7 +197,7 @@ impl Config {
if self.subgraphs.escrow.config.syncing_interval_secs < Duration::from_secs(10)
|| self.subgraphs.network.config.syncing_interval_secs < Duration::from_secs(10)
{
warn!(
tracing::warn!(
"Your `syncing_interval_secs` value it too low. \
This may overload your graph-node instance, \
a recommended value is about 60 seconds."
Expand All @@ -210,15 +207,15 @@ impl Config {
if self.subgraphs.escrow.config.syncing_interval_secs > Duration::from_secs(600)
|| self.subgraphs.network.config.syncing_interval_secs > Duration::from_secs(600)
{
warn!(
tracing::warn!(
"Your `syncing_interval_secs` value it too high. \
This may cause issues while reacting to updates in the blockchain. \
a recommended value is about 60 seconds."
);
}

if self.tap.rav_request.timestamp_buffer_secs < Duration::from_secs(10) {
warn!(
tracing::warn!(
"Your `tap.rav_request.timestamp_buffer_secs` value it too low. \
You may discart receipts in case of any synchronization issues, \
a recommended value is about 30 seconds."
Expand Down Expand Up @@ -423,15 +420,15 @@ pub struct RavRequestConfig {

#[cfg(test)]
mod tests {
use alloy::primitives::FixedBytes;
use std::{env, fs, path::PathBuf};

use figment::value::Uncased;
use sealed_test::prelude::*;
use std::{env, fs, path::PathBuf, str::FromStr};
use thegraph_core::alloy::primitives::address;
use tracing_test::traced_test;

use crate::{Config, ConfigPrefix};

use super::{DatabaseConfig, SHARED_PREFIX};
use crate::{Config, ConfigPrefix};

#[test]
fn test_minimal_config() {
Expand All @@ -451,9 +448,7 @@ mod tests {
)
.unwrap();
max_config.dips = Some(crate::DipsConfig {
allowed_payers: vec![thegraph_core::Address(
FixedBytes::<20>::from_str("0x3333333333333333333333333333333333333333").unwrap(),
)],
allowed_payers: vec![address!("3333333333333333333333333333333333333333")],
cancellation_time_tolerance: None,
});

Expand Down
4 changes: 1 addition & 3 deletions crates/dips/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
alloy.workspace = true
thiserror.workspace = true
anyhow.workspace = true
alloy-sol-types = "=0.8.15"
alloy-rlp = "0.3.9"
alloy-rlp = "0.3.9"
thegraph-core.workspace = true
35 changes: 20 additions & 15 deletions crates/dips/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
// SPDX-License-Identifier: Apache-2.0

use std::str::FromStr;
use std::time::{Duration, SystemTime, UNIX_EPOCH};

pub use alloy;
pub use alloy_rlp;

use alloy::core::primitives::Address;
use alloy::rlp::{RlpDecodable, RlpEncodable};
use alloy::{primitives::PrimitiveSignature as Signature, signers::SignerSync};
use alloy_rlp::Encodable;
use thegraph_core::alloy_sol_types::{sol, Eip712Domain, SolStruct};
use std::{
str::FromStr,
time::{Duration, SystemTime, UNIX_EPOCH},
};

use alloy_rlp::{Encodable, RlpDecodable, RlpEncodable};
use thegraph_core::alloy::{
primitives::{Address, PrimitiveSignature as Signature},
signers::SignerSync,
sol,
sol_types::{Eip712Domain, SolStruct},
};
use thiserror::Error;

sol! {
Expand Down Expand Up @@ -212,10 +213,14 @@ impl SignedCancellationRequest {
mod test {
use std::time::{Duration, SystemTime, UNIX_EPOCH};

use alloy::primitives::{Address, FixedBytes, U256};
use alloy::signers::local::PrivateKeySigner;
use alloy::sol_types::SolStruct;
use thegraph_core::attestation::eip712_domain;
use thegraph_core::{
alloy::{
primitives::{Address, FixedBytes, U256},
signers::local::PrivateKeySigner,
sol_types::SolStruct,
},
attestation::eip712_domain,
};

use crate::{
AgreementVoucherValidationError, CancellationRequest, CancellationRequestValidationError,
Expand Down
1 change: 0 additions & 1 deletion crates/monitor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ indexer-allocation = { path = "../allocation" }
indexer-attestation = { path = "../attestation" }
indexer-watcher = { path = "../watcher" }
thiserror.workspace = true
alloy.workspace = true
anyhow.workspace = true
reqwest = { workspace = true, features = ["json"] }
tracing.workspace = true
Expand Down
Loading

0 comments on commit 3ceac86

Please sign in to comment.