Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release #413

Merged
merged 5 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
with:
toolchain: stable
components: rustfmt, clippy
profile: minimal
override: true

- name: Cache Cargo build files
uses: Leafwing-Studios/cargo-cache@v1
Expand All @@ -46,7 +48,8 @@ jobs:
- run: cargo clippy -- -D warnings

- name: Unit tests
run: cargo test --lib -- --nocapture
run: cargo test --lib

- name: Integration tests
run: cargo test --test '*'
# the cargo clean is to avoid running out of disk space, hopefully unnecessary in the future
run: cargo clean && cargo test --test '*'
7 changes: 3 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
# Release Process

1. Test the main branch using the [edgeandnode/local-network-environments](https://github.com/edgeandnode/local-network-environments)
1. Test the main branch using the [edgeandnode/local-network](https://github.com/edgeandnode/local-network)
- Make sure that the gateway returns a correct response to a valid query
- Run any other ad-hoc tests that are appropriate for the set of changes made since the last release
2. Open a PR for the new release on [edgeandnode/graph-gateway](https://github.com/edgeandnode/graph-gateway)
- Version the release based on [SemVer](https://semver.org/)
- Note that the data science team relies on the logging format, so any changes to existing log events, spans, or fields require a major version bump
- Version the release based on [SemVer](https://semver.org/). The following trigger a major version bump:
- Breaking changes to the configuration file
- Set the new version in `Cargo.toml`, and run `cargo update`
- Include release notes for changes since the last release. See past releases for format.
- Rebase & Merge the PR
- Create a new release via GitHub
- Include the release notes from the PR
- Tag the commit with the version string, prefixed with a `v`
3. Open a PR on [edgeandnode/graph-infra](https://github.com/edgeandnode/graph-infra)
- Update the staging (and testnet?) gateways to the new version
- Update environment variables and Prometheus filters as necessary
4. Query the staging gateway at `https://gateway.staging.network.thegraph.com`
5. Open a PR on [edgeandnode/graph-infra](https://github.com/edgeandnode/graph-infra)
- Update the mainnet gateway configs, making the same configuration changes as in step 3
5 changes: 2 additions & 3 deletions graph-gateway/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "graph-gateway"
version = "14.0.1"
version = "15.0.0"

[dependencies]
alloy-primitives.workspace = true
Expand All @@ -17,7 +17,6 @@ ethers = { version = "2.0.10", default-features = false, features = ["abigen"] }
eventuals.workspace = true
faster-hex = "0.8.0"
futures = "0.3"
futures-util = "0.3"
graph-subscriptions = { git = "https://github.com/edgeandnode/subscription-payments", rev = "334d18b" }
graphql = { git = "https://github.com/edgeandnode/toolshed", tag = "graphql-v0.1.0" }
hex = "0.4"
Expand All @@ -31,7 +30,7 @@ primitive-types = "0.12.1"
prometheus = { version = "0.13", default-features = false }
prost = "0.12.1"
rand.workspace = true
rdkafka = { version = "0.34", features = ["gssapi", "tracing"] }
rdkafka = { version = "0.36.0", features = ["gssapi", "tracing"] }
reqwest.workspace = true
secp256k1.workspace = true
semver = "1.0"
Expand Down
57 changes: 32 additions & 25 deletions graph-gateway/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use std::ops::Deref;
use std::str::FromStr;
use std::time::Duration;
use std::{collections::BTreeMap, fmt, path::PathBuf};

use alloy_primitives::{Address, U256};
use ethers::signers::coins_bip39::English;
use ethers::signers::MnemonicBuilder;
use graph_subscriptions::subscription_tier::{SubscriptionTier, SubscriptionTiers};
use semver::Version;
use serde::Deserialize;
use serde_with::{serde_as, DisplayFromStr, FromInto};
use toolshed::url::Url;

use indexer_selection::SecretKey;
use prelude::{key_path, USD};
use prelude::USD;

use crate::chains::ethereum;
use crate::poi::ProofOfIndexingInfo;
Expand Down Expand Up @@ -152,34 +151,18 @@ impl From<KafkaConfig> for rdkafka::config::ClientConfig {
#[serde_as]
#[derive(Debug, Deserialize)]
pub struct Scalar {
/// Mnemonic for voucher signing
#[serde_as(as = "DisplayFromStr")]
pub signer_key: SignerKey,
/// Scalar TAP verifier contract chain
pub chain_id: U256,
/// Mnemonic for legacy voucher signing
#[serde_as(as = "Option<DisplayFromStr>")]
pub legacy_signer: Option<Hidden<SecretKey>>,
/// Mnemonic for voucher signing
#[serde_as(as = "DisplayFromStr")]
pub signer: Hidden<SecretKey>,
/// Scalar TAP verifier contract address
pub verifier: Address,
}

pub struct SignerKey(pub SecretKey);

impl fmt::Debug for SignerKey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "SignerKey(..)")
}
}

impl FromStr for SignerKey {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let wallet = MnemonicBuilder::<English>::default()
.phrase(s)
.derivation_path(&key_path("scalar/allocations"))?
.build()?;
Ok(Self(SecretKey::from_slice(&wallet.signer().to_bytes())?))
}
}

#[serde_as]
#[derive(Debug, Deserialize)]
pub struct Subscriptions {
Expand All @@ -206,3 +189,27 @@ pub struct SubscriptionsDomain {
pub chain_id: u64,
pub contract: Address,
}

#[derive(Deserialize)]
#[serde(transparent)]
pub struct Hidden<T>(pub T);

impl<T: fmt::Debug> fmt::Debug for Hidden<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "HIDDEN")
}
}

impl<T: FromStr> FromStr for Hidden<T> {
type Err = T::Err;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(s.parse()?))
}
}

impl<T> Deref for Hidden<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.0
}
}
20 changes: 14 additions & 6 deletions graph-gateway/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ use graph_gateway::{
use indexer_selection::{actor::Update, BlockStatus, Indexing};
use prelude::buffer_queue::QueueWriter;
use prelude::{buffer_queue, double_buffer};
use secp256k1::SecretKey;

// Moving the `exchange_rate` module to `lib.rs` makes the doctests to fail during the compilation
// step. This module is only used here, so let's keep it here for now.
Expand Down Expand Up @@ -111,7 +112,6 @@ async fn main() {
})
.collect::<HashMap<String, BlockCache>>();
let block_caches: &'static HashMap<String, BlockCache> = Box::leak(Box::new(block_caches));
let signer_key = config.scalar.signer_key.0;

let http_client = reqwest::Client::builder()
.timeout(Duration::from_secs(20))
Expand Down Expand Up @@ -190,12 +190,20 @@ async fn main() {
.collect();
Ptr::new(legacy_indexers)
});
let legacy_signer: &'static SecretKey = Box::leak(Box::new(
config
.scalar
.legacy_signer
.map(|s| s.0)
.unwrap_or(config.scalar.signer.0),
));
let receipt_signer: &'static ReceiptSigner = Box::leak(Box::new(
ReceiptSigner::new(
signer_key,
legacy_indexers,
config.scalar.signer.0,
config.scalar.chain_id,
config.scalar.verifier,
legacy_signer,
legacy_indexers,
)
.await,
));
Expand Down Expand Up @@ -358,17 +366,17 @@ async fn main() {
.route("/ready", routing::get(|| async { "Ready" }))
.route(
"/collect-receipts",
routing::post(vouchers::handle_collect_receipts).with_state(signer_key),
routing::post(vouchers::handle_collect_receipts).with_state(legacy_signer),
)
.route(
"/partial-voucher",
routing::post(vouchers::handle_partial_voucher)
.with_state(signer_key)
.with_state(legacy_signer)
.layer(DefaultBodyLimit::max(3_000_000)),
)
.route(
"/voucher",
routing::post(vouchers::handle_voucher).with_state(signer_key),
routing::post(vouchers::handle_voucher).with_state(legacy_signer),
)
// Temporary route. Will be replaced by gateway metadata (GSP).
.route(
Expand Down
17 changes: 9 additions & 8 deletions graph-gateway/src/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ use indexer_selection::{Indexing, SecretKey};
use prelude::GRT;

pub struct ReceiptSigner {
// TODO: When legacy (non-TAP) Scalar is removed, this should contain the only owned reference
// to the SignerKey. This will resolve https://github.com/edgeandnode/graph-gateway/issues/13.
signer_key: SecretKey,
signer: SecretKey,
domain: Eip712Domain,
allocations: RwLock<HashMap<Indexing, Address>>,
legacy_signer: &'static SecretKey,
legacy_indexers: Eventual<Ptr<HashSet<Address>>>,
legacy_pools: RwLock<HashMap<Indexing, Arc<Mutex<ReceiptPool>>>>,
}
Expand Down Expand Up @@ -50,14 +49,15 @@ impl ScalarReceipt {

impl ReceiptSigner {
pub async fn new(
signer_key: SecretKey,
legacy_indexers: Eventual<Ptr<HashSet<Address>>>,
signer: SecretKey,
chain_id: U256,
verifier: Address,
legacy_signer: &'static SecretKey,
legacy_indexers: Eventual<Ptr<HashSet<Address>>>,
) -> Self {
let _ = legacy_indexers.value().await;
Self {
signer_key,
signer,
domain: Eip712Domain {
name: Some("Scalar TAP".into()),
version: Some("1".into()),
Expand All @@ -66,6 +66,7 @@ impl ReceiptSigner {
salt: None,
},
allocations: RwLock::default(),
legacy_signer,
legacy_indexers,
legacy_pools: RwLock::default(),
}
Expand Down Expand Up @@ -101,7 +102,7 @@ impl ReceiptSigner {
value: fee.shift::<0>().as_u256().as_u128(),
};
let wallet =
Wallet::from_bytes(self.signer_key.as_ref()).expect("failed to prepare receipt wallet");
Wallet::from_bytes(self.signer.as_ref()).expect("failed to prepare receipt wallet");
let signed = EIP712SignedMessage::new(&self.domain, receipt, &wallet)
.await
.expect("failed to sign receipt");
Expand Down Expand Up @@ -143,7 +144,7 @@ impl ReceiptSigner {
}
// add allocation, if not already present
if !legacy_pool.contains_allocation(allocation) {
legacy_pool.add_allocation(self.signer_key, *allocation.0);
legacy_pool.add_allocation(*self.legacy_signer, *allocation.0);
}
}

Expand Down
2 changes: 1 addition & 1 deletion graph-gateway/src/topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;
use alloy_primitives::Address;
use anyhow::anyhow;
use eventuals::{Eventual, EventualExt, Ptr};
use futures_util::future::join_all;
use futures::future::join_all;
use itertools::Itertools;
use prelude::GRT;
use serde::Deserialize;
Expand Down
12 changes: 6 additions & 6 deletions graph-gateway/src/vouchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ lazy_static! {
}

pub async fn handle_collect_receipts(
State(signer): State<SecretKey>,
State(signer): State<&'static SecretKey>,
payload: Bytes,
) -> Result<JsonResponse, (StatusCode, String)> {
let _timer = METRICS.collect_receipts.duration.start_timer();
match process_oneshot_voucher(&signer, &payload) {
match process_oneshot_voucher(signer, &payload) {
Ok(response) => {
METRICS.collect_receipts.ok.inc();
Ok(response)
Expand Down Expand Up @@ -65,11 +65,11 @@ fn process_oneshot_voucher(signer: &SecretKey, payload: &Bytes) -> Result<JsonRe
}

pub async fn handle_partial_voucher(
State(signer): State<SecretKey>,
State(signer): State<&'static SecretKey>,
payload: Bytes,
) -> Result<JsonResponse, (StatusCode, String)> {
let _timer = METRICS.partial_voucher.duration.start_timer();
match process_partial_voucher(&signer, &payload) {
match process_partial_voucher(signer, &payload) {
Ok(response) => {
METRICS.partial_voucher.ok.inc();
Ok(response)
Expand Down Expand Up @@ -112,11 +112,11 @@ fn process_partial_voucher(signer: &SecretKey, payload: &Bytes) -> Result<JsonRe
}

pub async fn handle_voucher(
State(signer): State<SecretKey>,
State(signer): State<&'static SecretKey>,
payload: Bytes,
) -> Result<JsonResponse, (StatusCode, String)> {
let _timer = METRICS.voucher.duration.start_timer();
match process_voucher(&signer, &payload) {
match process_voucher(signer, &payload) {
Ok(response) => {
METRICS.voucher.ok.inc();
Ok(response)
Expand Down
8 changes: 0 additions & 8 deletions prelude/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ pub fn sip24_hash(value: &impl Hash) -> u64 {
hasher.finish()
}

/// Encode the given name into a valid BIP-32 key chain path.
pub fn key_path(name: &str) -> String {
std::iter::once("m".to_string())
.chain(name.bytes().map(|b| b.to_string()))
.collect::<Vec<String>>()
.join("/")
}

/// Decimal Parts-Per-Million with 6 fractional digits
pub type PPM = UDecimal<6>;
/// Decimal USD with 18 fractional digits
Expand Down
Loading