Skip to content

Commit

Permalink
refactor: move dips to grpc
Browse files Browse the repository at this point in the history
  • Loading branch information
mangas committed Dec 9, 2024
1 parent ed4721d commit dcd4aa8
Show file tree
Hide file tree
Showing 22 changed files with 1,169 additions and 464 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/license_headers_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ jobs:
-ignore '.github/workflows/*.yaml' \
-ignore '.github/*.yaml' \
-ignore 'migrations/*.sql' \
-ignore 'crates/dips/proto/*.proto' \
-ignore 'crates/dips/src/proto/*.rs' \
.
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ jobs:
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@9e326ebed976843c9932b3aa0e021c6f50310eb4 # v0.0.6
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
- name: Install protobuf
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 All @@ -66,6 +69,9 @@ jobs:
DATABASE_URL: postgres://postgres@postgres:5432
SQLX_OFFLINE: true
steps:
- name: Install protobuf
run: |
apt-get update && apt-get install protobuf-compiler -y
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Cache dependencies
uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2.7.5
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"
4 changes: 3 additions & 1 deletion Dockerfile.indexer-service-rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ 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 }
9 changes: 9 additions & 0 deletions crates/dips/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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)");
}
56 changes: 56 additions & 0 deletions crates/dips/proto/dips.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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 dcd4aa8

Please sign in to comment.