Skip to content

Commit

Permalink
refactor: dips grpc (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
mangas authored Jan 2, 2025
1 parent b08b728 commit 1263fb7
Show file tree
Hide file tree
Showing 23 changed files with 1,188 additions and 475 deletions.
1 change: 1 addition & 0 deletions .github/workflows/license_headers_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ jobs:
-ignore '.github/workflows/*.yaml' \
-ignore '.github/*.yaml' \
-ignore 'migrations/*.sql' \
-ignore 'crates/dips/src/proto/*' \
.
8 changes: 8 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ jobs:
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@054db53350805f83040bf3e6e9b8cf5a139aa7c9 # v0.0.7
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
- name: Install protobuf compiler
run: apt-get update && apt-get install protobuf-compiler -y
- name: Install sqlx
run: cargo install sqlx-cli --no-default-features --features postgres
- name: Run the test sqlx migrations
Expand Down Expand Up @@ -78,6 +80,8 @@ jobs:
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@054db53350805f83040bf3e6e9b8cf5a139aa7c9 # v0.0.7
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
- name: Install protobuf compiler
run: apt-get update && apt-get install protobuf-compiler -y
- run: |
rustup component add clippy
# Temporarily allowing dead-code, while denying all other warnings
Expand Down Expand Up @@ -116,6 +120,8 @@ jobs:
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
- name: Install protobuf compiler
run: apt-get update && apt-get install protobuf-compiler -y
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@054db53350805f83040bf3e6e9b8cf5a139aa7c9 # v0.0.7
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
Expand Down Expand Up @@ -166,6 +172,8 @@ jobs:
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
- name: Install protobuf compiler
run: apt-get update && apt-get install protobuf-compiler -y
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@054db53350805f83040bf3e6e9b8cf5a139aa7c9 # v0.0.7
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
Expand Down
81 changes: 79 additions & 2 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ tokio = "1.40"
prometheus = "0.13.3"
anyhow = { version = "1.0.72" }
thiserror = "1.0.49"
async-trait = "0.1.72"
async-trait = "0.1.83"
eventuals = "0.6.7"
base64 = "0.22.1"
reqwest = { version = "0.12", features = [
Expand Down Expand Up @@ -75,3 +75,7 @@ bip39 = "2.0.0"
rstest = "0.23.0"
wiremock = "0.6.1"
typed-builder = "0.20.0"
tonic = { version = "0.12.3", features = ["tls-roots", "gzip"] }
tonic-build = { version = "0.12.3", features = ["prost"] }
prost = "0.13.3"
prost-types = "0.13.3"
5 changes: 4 additions & 1 deletion Dockerfile.indexer-service-rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ COPY . .
# Force SQLx to use the offline mode to statically check the database queries against
# the prepared files in the `.sqlx` directory.
ENV SQLX_OFFLINE=true

RUN apt-get update && apt-get install -y --no-install-recommends \
protobuf-compiler && rm -rf /var/lib/apt/lists/*
RUN cargo build --release --bin indexer-service-rs

########################################################################################

FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
openssl ca-certificates \
openssl ca-certificates protobuf-compiler \
&& rm -rf /var/lib/apt/lists/*
COPY --from=build /root/target/release/indexer-service-rs /usr/local/bin/indexer-service-rs

Expand Down
2 changes: 2 additions & 0 deletions Dockerfile.indexer-tap-agent
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ COPY . .
# Force SQLx to use the offline mode to statically check the database queries against
# the prepared files in the `.sqlx` directory.
ENV SQLX_OFFLINE=true
RUN apt-get update && apt-get install -y --no-install-recommends \
protobuf-compiler && rm -rf /var/lib/apt/lists/*
RUN cargo build --release --bin indexer-tap-agent

########################################################################################
Expand Down
3 changes: 2 additions & 1 deletion crates/config/maximal-config-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,6 @@ max_receipts_per_request = 10000
0x0123456789abcdef0123456789abcdef01234567 = "https://other.example.com/aggregate-receipts"

[dips]
host = "0.0.0.0"
port = "7601"
allowed_payers = ["0x3333333333333333333333333333333333333333"]

23 changes: 19 additions & 4 deletions crates/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,23 @@ pub struct TapConfig {
#[derive(Debug, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
pub struct DipsConfig {
pub host: String,
pub port: String,
pub allowed_payers: Vec<Address>,
pub cancellation_time_tolerance: Option<Duration>,
}

impl Default for DipsConfig {
fn default() -> Self {
DipsConfig {
host: "0.0.0.0".to_string(),
port: "7601".to_string(),
allowed_payers: vec![],
cancellation_time_tolerance: None,
}
}
}

impl TapConfig {
pub fn get_trigger_value(&self) -> u128 {
let grt_wei = self.max_amount_willing_to_lose_grt.get_value();
Expand Down Expand Up @@ -420,11 +433,11 @@ pub struct RavRequestConfig {

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

use figment::value::Uncased;
use sealed_test::prelude::*;
use thegraph_core::alloy::primitives::address;
use thegraph_core::alloy::primitives::{Address, FixedBytes};
use tracing_test::traced_test;

use super::{DatabaseConfig, SHARED_PREFIX};
Expand All @@ -448,8 +461,10 @@ mod tests {
)
.unwrap();
max_config.dips = Some(crate::DipsConfig {
allowed_payers: vec![address!("3333333333333333333333333333333333333333")],
cancellation_time_tolerance: None,
allowed_payers: vec![Address(
FixedBytes::<20>::from_str("0x3333333333333333333333333333333333333333").unwrap(),
)],
..Default::default()
});

let max_config_file: Config = toml::from_str(
Expand Down
10 changes: 10 additions & 0 deletions crates/dips/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ thiserror.workspace = true
anyhow.workspace = true
alloy-rlp = "0.3.10"
thegraph-core.workspace = true
tonic.workspace = true
async-trait.workspace = true
prost.workspace = true
prost-types.workspace = true
uuid.workspace = true
base64.workspace = true
tokio.workspace = true

[build-dependencies]
tonic-build = { workspace = true }
12 changes: 12 additions & 0 deletions crates/dips/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
// SPDX-License-Identifier: Apache-2.0

fn main() {
println!("cargo:rerun-if-changed=proto");
tonic_build::configure()
.out_dir("src/proto")
.include_file("mod.rs")
.protoc_arg("--experimental_allow_proto3_optional")
.compile_protos(&["proto/dips.proto"], &["proto"])
.expect("Failed to compile dips proto(s)");
}
59 changes: 59 additions & 0 deletions crates/dips/proto/dips.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";

package graphprotocol.indexer.dips;

service AgreementService {
rpc CreateAgreement(CreateAgreementRequest) returns (CreateAgreementResponse);
rpc CancelAgreement(CancelAgreementRequest) returns (AgreementCanellationResponse);
rpc GetAgreementById(GetAgreementByIdRequest) returns (GetAgreementByIdResponse);
rpc GetPrice(PriceRequest) returns (PriceResponse);
}

message GetAgreementByIdRequest {

}

message GetAgreementByIdResponse {

}

message CreateAgreementRequest {
string id = 1;
bytes signed_voucher = 2;
}

message CancelAgreementRequest {
string id = 1;
bytes signed_voucher = 2;
}

message CreateAgreementResponse {
string uuid = 1;
}

message AgreementCanellationResponse {
string uuid = 1;
}

message PriceRequest {
ProtocolNetwork protocol = 1;
string chain_id = 2;
}

message PriceResponse {
optional Price price = 1;
}

message Price {
string price_per_block = 1;
string chain_id = 2;
ProtocolNetwork protocol = 3;
}

enum ProtocolNetwork {
UNKNOWN = 0;
EVM = 1;
}
Loading

0 comments on commit 1263fb7

Please sign in to comment.