Skip to content

Commit

Permalink
feat: dips grpc
Browse files Browse the repository at this point in the history
  • Loading branch information
mangas committed Dec 9, 2024
1 parent c627756 commit 69cedf3
Show file tree
Hide file tree
Showing 23 changed files with 1,179 additions and 465 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@9e326ebed976843c9932b3aa0e021c6f50310eb4 # v0.0.6
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@9e326ebed976843c9932b3aa0e021c6f50310eb4 # v0.0.6
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@9e326ebed976843c9932b3aa0e021c6f50310eb4 # v0.0.6
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@9e326ebed976843c9932b3aa0e021c6f50310eb4 # v0.0.6
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
Expand Down
77 changes: 77 additions & 0 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 @@ -38,7 +38,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 @@ -78,3 +78,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: 3 additions & 0 deletions crates/config/maximal-config-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,7 @@ max_receipts_per_request = 10000
0x0123456789abcdef0123456789abcdef01234567 = "https://other.example.com/aggregate-receipts"

[dips]
host = "0.0.0.0"
port = "7601"
allowed_payers = ["0x3333333333333333333333333333333333333333"]
expected_payee = "0x0000000000000000000000000000000000000000"
18 changes: 17 additions & 1 deletion crates/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,25 @@ pub struct TapConfig {
#[derive(Debug, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
pub struct DipsConfig {
pub host: String,
pub port: String,
pub expected_payee: Address,
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(),
expected_payee: Address::ZERO,
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 @@ -450,7 +465,8 @@ mod tests {
allowed_payers: vec![thegraph_core::Address(
FixedBytes::<20>::from_str("0x3333333333333333333333333333333333333333").unwrap(),
)],
cancellation_time_tolerance: None,
expected_payee: thegraph_core::Address::ZERO,
..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 @@ -10,3 +10,13 @@ anyhow.workspace = true
alloy-sol-types = "=0.8.13"
alloy-rlp = "0.3.9"
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 69cedf3

Please sign in to comment.