Skip to content

Commit e307bc3

Browse files
committed
fix: updated proto and added domains
1 parent 7e0ed8c commit e307bc3

File tree

9 files changed

+377
-98
lines changed

9 files changed

+377
-98
lines changed

crates/dips/proto/gateway.proto

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ service DipsService {
1212
rpc CancelAgreement(CancelAgreementRequest) returns (CancelAgreementResponse);
1313

1414
/**
15-
* Report the progress of an _indexing agreement_.
15+
* Collect payment for an _indexing agreement_.
1616
*
1717
* This method allows the indexer to report the work completed to the DIPs gateway
1818
* and receive payment for the indexing work done.
1919
*/
20-
rpc ReportProgress(ReportProgressRequest) returns (ReportProgressResponse);
20+
rpc CollectPayment(CollectPaymentRequest) returns (CollectPaymentResponse);
2121
}
2222

2323

@@ -27,10 +27,8 @@ service DipsService {
2727
* See the `DipsService.CancelAgreement` method.
2828
*/
2929
message CancelAgreementRequest {
30-
bytes agreement_id = 1; /// The ID of the agreement to cancel.
31-
reserved 2 to 20; /// Reserved for future use.
32-
33-
bytes signature = 99; /// The signature of the message.
30+
uint64 version = 1;
31+
bytes signed_cancellation = 2; /// a signed ERC-712 message cancelling an agreement
3432
}
3533

3634
/**
@@ -39,28 +37,37 @@ message CancelAgreementRequest {
3937
* See the `DipsService.CancelAgreement` method.
4038
*/
4139
message CancelAgreementResponse {
42-
// Empty message
40+
/// Empty response, eventually we may add custom status codes
4341
}
4442

45-
4643
/**
47-
* A request to report the progress of an _indexing agreement_.
44+
* A request to collect payment _indexing agreement_.
4845
*
49-
* See the `DipsService.ReportProgress` method.
46+
* See the `DipsService.CollectPayment` method.
5047
*/
51-
message ReportProgressRequest {
52-
bytes agreement_id = 1; /// The ID of the agreement to report progress for.
53-
// TODO(LNSD): Add fields to the message
54-
55-
bytes signature = 99; /// The signature of the message.
48+
message CollectPaymentRequest {
49+
uint64 version = 1;
50+
bytes signed_collection = 2;
5651
}
5752

5853
/**
59-
* A response to a request to report the progress of an _indexing agreement_.
54+
* A response to a request to collect payment for an _indexing agreement_.
6055
*
61-
* See the `DipsService.ReportProgress` method.
56+
* See the `DipsService.CollectAgreement` method.
6257
*/
63-
message ReportProgressResponse {
64-
// TODO(LNSD): Add fields to the message
58+
message CollectPaymentResponse {
59+
uint64 version = 1;
60+
CollectPaymentStatus status = 2;
61+
bytes tap_receipt = 3;
6562
}
6663

64+
/**
65+
* The status on response to collect an _indexing agreement_.
66+
*/
67+
enum CollectPaymentStatus {
68+
ACCEPT = 0; /// The payment request was accepted.
69+
ERR_TOO_EARLY = 1; /// The payment request was done before min epochs passed
70+
ERR_TOO_LATE = 2; /// The payment request was done after max epochs passed
71+
ERR_AMOUNT_OUT_OF_BOUNDS = 3; /// The payment request is for too large an amount
72+
ERR_UNKNOWN = 99; /// Something else went terribly wrong
73+
}

crates/dips/proto/indexer.proto

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ service DipsService {
2222
* See the `DipsService.SubmitAgreementProposal` method.
2323
*/
2424
message SubmitAgreementProposalRequest {
25-
bytes agreementId = 1; /// The ID of the agreement to register.
26-
reserved 2 to 19; /// Reserved for future use.
27-
28-
bytes signed_voucher = 20; /// The voucher of the agreement.
25+
uint64 version = 1;
26+
bytes signed_voucher = 2; /// An ERC-712 signed indexing agreement voucher
2927
}
3028

3129
/**
@@ -46,15 +44,13 @@ enum ProposalResponse {
4644
}
4745

4846
/**
49-
* A request to cancel an existing _indexing agreement_.
47+
* A request to cancel an _indexing agreement_.
5048
*
5149
* See the `DipsService.CancelAgreement` method.
5250
*/
5351
message CancelAgreementRequest {
54-
bytes agreementId = 1; /// The ID of the agreement to cancel.
55-
reserved 2 to 20; /// Reserved for future use.
56-
57-
bytes signature = 99; /// The signature of the message.
52+
uint64 version = 1;
53+
bytes signed_cancellation = 2; /// a signed ERC-712 message cancelling an agreement
5854
}
5955

6056
/**
@@ -63,5 +59,5 @@ message CancelAgreementRequest {
6359
* See the `DipsService.CancelAgreement` method.
6460
*/
6561
message CancelAgreementResponse {
66-
// Empty message
62+
// Empty message, eventually we may add custom status codes
6763
}

crates/dips/src/lib.rs

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use std::{
1010
use alloy_rlp::Decodable;
1111
use thegraph_core::alloy::{
1212
core::primitives::Address,
13-
primitives::PrimitiveSignature as Signature,
13+
primitives::{b256, PrimitiveSignature as Signature, B256},
1414
rlp::{Encodable, RlpDecodable, RlpEncodable},
1515
signers::SignerSync,
1616
sol,
17-
sol_types::{Eip712Domain, SolStruct},
17+
sol_types::{eip712_domain, Eip712Domain, SolStruct},
1818
};
1919

2020
pub mod proto;
@@ -25,6 +25,41 @@ use store::AgreementStore;
2525
use thiserror::Error;
2626
use uuid::Uuid;
2727

28+
/// The Arbitrum One (mainnet) chain ID (eip155).
29+
const CHAIN_ID_ARBITRUM_ONE: ChainId = 0xa4b1; // 42161
30+
31+
/// DIPs EIP-712 domain salt
32+
const EIP712_DOMAIN_SALT: B256 =
33+
b256!("b4632c657c26dce5d4d7da1d65bda185b14ff8f905ddbb03ea0382ed06c5ef28");
34+
35+
/// Create an EIP-712 domain given a chain ID and dispute manager address.
36+
pub fn dips_agreement_eip712_domain() -> Eip712Domain {
37+
eip712_domain! {
38+
name: "Graph Protocol Indexing Agreement",
39+
version: "0",
40+
chain_id: CHAIN_ID_ARBITRUM_ONE,
41+
salt: EIP712_DOMAIN_SALT,
42+
}
43+
}
44+
45+
pub fn dips_cancellation_eip712_domain() -> Eip712Domain {
46+
eip712_domain! {
47+
name: "Graph Protocol Indexing Agreement Cancellation",
48+
version: "0",
49+
chain_id: CHAIN_ID_ARBITRUM_ONE,
50+
salt: EIP712_DOMAIN_SALT,
51+
}
52+
}
53+
54+
pub fn dips_collection_eip712_domain() -> Eip712Domain {
55+
eip712_domain! {
56+
name: "Graph Protocol Indexing Agreement Collection",
57+
version: "0",
58+
chain_id: CHAIN_ID_ARBITRUM_ONE,
59+
salt: EIP712_DOMAIN_SALT,
60+
}
61+
}
62+
2863
sol! {
2964
// EIP712 encoded bytes, ABI - ethers
3065
#[derive(Debug, RlpEncodable, RlpDecodable, PartialEq)]
@@ -35,31 +70,36 @@ sol! {
3570

3671
#[derive(Debug, RlpEncodable, RlpDecodable, PartialEq)]
3772
struct IndexingAgreementVoucher {
38-
// should coincide with signer
73+
// Randomly generated ID, must be unique for each indexer/gateway pair
74+
bytes32 agreement_id;
75+
// should coincide with signer of this voucher
3976
address payer;
4077
// should coincide with indexer
4178
address recipient;
42-
// data service that will initiate payment collection
79+
// data service that will initiate payment collection
4380
address service;
4481

4582
uint32 durationEpochs;
4683

4784
uint256 maxInitialAmount;
48-
uint256 minOngoingAmountPerEpoch;
85+
uint256 maxOngoingAmountPerEpoch;
4986

50-
uint32 maxEpochsPerCollection;
5187
uint32 minEpochsPerCollection;
88+
uint32 maxEpochsPerCollection;
89+
90+
// Deadline for the indexer to accept the agreement
91+
uint64 deadline;
5292
bytes metadata;
5393
}
5494

5595
// the vouchers are generic to each data service, in the case of subgraphs this is an ABI-encoded SubgraphIndexingVoucherMetadata
5696
#[derive(Debug, RlpEncodable, RlpDecodable, PartialEq)]
5797
struct SubgraphIndexingVoucherMetadata {
58-
uint256 pricePerBlock; // wei GRT
98+
uint256 basePricePerEpoch; // wei GRT
5999
uint256 pricePerEntity; // wei GRT
60100
string subgraphDeploymentId; // e.g. "Qmbg1qF4YgHjiVfsVt6a13ddrVcRtWyJQfD4LA3CwHM29f" - TODO consider using bytes32
61101
string protocolNetwork; // e.g. "eip155:42161"
62-
string chainId; // e.g. "eip155:1"
102+
string chainId; // indexed chain, e.g. "eip155:1"
63103
}
64104

65105
#[derive(Debug, RlpEncodable, RlpDecodable, PartialEq)]
@@ -70,18 +110,22 @@ sol! {
70110

71111
#[derive(Debug, RlpEncodable, RlpDecodable, PartialEq)]
72112
struct CancellationRequest {
73-
// should coincide with signer.
74-
address payer;
75-
// should coincide with indexer.
76-
address payee;
77-
// data service that will initiate payment collection.
78-
address service;
79-
// signer of the cancellation, can be signed by either party.
80-
address cancelledBy;
81-
// should only be usable within a limited period of time.
82-
uint64 timestamp;
83-
bytes metadata;
113+
uint256 agreement_id;
114+
}
115+
116+
#[derive(Debug, RlpEncodable, RlpDecodable, PartialEq)]
117+
struct SignedCollectionRequest {
118+
CollectionRequest request;
119+
bytes signature;
120+
}
121+
122+
#[derive(Debug, RlpEncodable, RlpDecodable, PartialEq)]
123+
struct CollectionRequest {
124+
uint256 agreement_id;
125+
address allocation_id;
126+
uint64 entity_count;
84127
}
128+
85129
}
86130

87131
#[derive(Error, Debug)]

crates/dips/src/proto/graphprotocol.gateway.dips.rs

Lines changed: 72 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,86 @@
55
/// See the `DipsService.CancelAgreement` method.
66
#[derive(Clone, PartialEq, ::prost::Message)]
77
pub struct CancelAgreementRequest {
8-
/// / The ID of the agreement to cancel.
9-
#[prost(bytes = "vec", tag = "1")]
10-
pub agreement_id: ::prost::alloc::vec::Vec<u8>,
11-
/// / The signature of the message.
12-
#[prost(bytes = "vec", tag = "99")]
13-
pub signature: ::prost::alloc::vec::Vec<u8>,
8+
#[prost(uint64, tag = "1")]
9+
pub version: u64,
10+
/// / a signed ERC-712 message cancelling an agreement
11+
#[prost(bytes = "vec", tag = "2")]
12+
pub signed_cancellation: ::prost::alloc::vec::Vec<u8>,
1413
}
1514
/// *
1615
/// A response to a request to cancel an _indexing agreement_.
1716
///
1817
/// See the `DipsService.CancelAgreement` method.
1918
///
20-
/// Empty message
19+
/// / Empty response, eventually we may add custom status codes
2120
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
2221
pub struct CancelAgreementResponse {}
2322
/// *
24-
/// A request to report the progress of an _indexing agreement_.
23+
/// A request to collect payment _indexing agreement_.
2524
///
26-
/// See the `DipsService.ReportProgress` method.
25+
/// See the `DipsService.CollectPayment` method.
2726
#[derive(Clone, PartialEq, ::prost::Message)]
28-
pub struct ReportProgressRequest {
29-
/// / The ID of the agreement to report progress for.
30-
#[prost(bytes = "vec", tag = "1")]
31-
pub agreement_id: ::prost::alloc::vec::Vec<u8>,
32-
/// / The signature of the message.
33-
#[prost(bytes = "vec", tag = "99")]
34-
pub signature: ::prost::alloc::vec::Vec<u8>,
27+
pub struct CollectPaymentRequest {
28+
#[prost(uint64, tag = "1")]
29+
pub version: u64,
30+
#[prost(bytes = "vec", tag = "2")]
31+
pub signed_collection: ::prost::alloc::vec::Vec<u8>,
3532
}
3633
/// *
37-
/// A response to a request to report the progress of an _indexing agreement_.
34+
/// A response to a request to collect payment for an _indexing agreement_.
3835
///
39-
/// See the `DipsService.ReportProgress` method.
40-
///
41-
/// TODO(LNSD): Add fields to the message
42-
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
43-
pub struct ReportProgressResponse {}
36+
/// See the `DipsService.CollectAgreement` method.
37+
#[derive(Clone, PartialEq, ::prost::Message)]
38+
pub struct CollectPaymentResponse {
39+
#[prost(uint64, tag = "1")]
40+
pub version: u64,
41+
#[prost(enumeration = "CollectPaymentStatus", tag = "2")]
42+
pub status: i32,
43+
#[prost(bytes = "vec", tag = "3")]
44+
pub tap_receipt: ::prost::alloc::vec::Vec<u8>,
45+
}
46+
/// *
47+
/// The status on response to collect an _indexing agreement_.
48+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
49+
#[repr(i32)]
50+
pub enum CollectPaymentStatus {
51+
/// / The payment request was accepted.
52+
Accept = 0,
53+
/// / The payment request was done before min epochs passed
54+
ErrTooEarly = 1,
55+
/// / The payment request was done after max epochs passed
56+
ErrTooLate = 2,
57+
/// / The payment request is for too large an amount
58+
ErrAmountOutOfBounds = 3,
59+
/// / Something else went terribly wrong
60+
ErrUnknown = 99,
61+
}
62+
impl CollectPaymentStatus {
63+
/// String value of the enum field names used in the ProtoBuf definition.
64+
///
65+
/// The values are not transformed in any way and thus are considered stable
66+
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
67+
pub fn as_str_name(&self) -> &'static str {
68+
match self {
69+
Self::Accept => "ACCEPT",
70+
Self::ErrTooEarly => "ERR_TOO_EARLY",
71+
Self::ErrTooLate => "ERR_TOO_LATE",
72+
Self::ErrAmountOutOfBounds => "ERR_AMOUNT_OUT_OF_BOUNDS",
73+
Self::ErrUnknown => "ERR_UNKNOWN",
74+
}
75+
}
76+
/// Creates an enum from field names used in the ProtoBuf definition.
77+
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
78+
match value {
79+
"ACCEPT" => Some(Self::Accept),
80+
"ERR_TOO_EARLY" => Some(Self::ErrTooEarly),
81+
"ERR_TOO_LATE" => Some(Self::ErrTooLate),
82+
"ERR_AMOUNT_OUT_OF_BOUNDS" => Some(Self::ErrAmountOutOfBounds),
83+
"ERR_UNKNOWN" => Some(Self::ErrUnknown),
84+
_ => None,
85+
}
86+
}
87+
}
4488
/// Generated client implementations.
4589
pub mod dips_service_client {
4690
#![allow(
@@ -167,15 +211,15 @@ pub mod dips_service_client {
167211
self.inner.unary(req, path, codec).await
168212
}
169213
/// *
170-
/// Report the progress of an _indexing agreement_.
214+
/// Collect payment for an _indexing agreement_.
171215
///
172216
/// This method allows the indexer to report the work completed to the DIPs gateway
173217
/// and receive payment for the indexing work done.
174-
pub async fn report_progress(
218+
pub async fn collect_payment(
175219
&mut self,
176-
request: impl tonic::IntoRequest<super::ReportProgressRequest>,
220+
request: impl tonic::IntoRequest<super::CollectPaymentRequest>,
177221
) -> std::result::Result<
178-
tonic::Response<super::ReportProgressResponse>,
222+
tonic::Response<super::CollectPaymentResponse>,
179223
tonic::Status,
180224
> {
181225
self.inner
@@ -188,14 +232,14 @@ pub mod dips_service_client {
188232
})?;
189233
let codec = tonic::codec::ProstCodec::default();
190234
let path = http::uri::PathAndQuery::from_static(
191-
"/graphprotocol.gateway.dips.DipsService/ReportProgress",
235+
"/graphprotocol.gateway.dips.DipsService/CollectPayment",
192236
);
193237
let mut req = request.into_request();
194238
req.extensions_mut()
195239
.insert(
196240
GrpcMethod::new(
197241
"graphprotocol.gateway.dips.DipsService",
198-
"ReportProgress",
242+
"CollectPayment",
199243
),
200244
);
201245
self.inner.unary(req, path, codec).await

0 commit comments

Comments
 (0)