Skip to content

Commit f6d7847

Browse files
committed
shim/rollkit: downgrade go-da to 0.2.0
the version that was introduced in #260 (997046d) was using the latest version of go-da (0.4.0) gRPC service decl. However, the latest version of rollkit on which the gm demo was based off, was using 0.2.0. That was causing occasional problems. So I went ahead and downgraded it. Now, it seems to workfine (with exception of #259). Closes #258.
1 parent ff4b552 commit f6d7847

File tree

2 files changed

+20
-92
lines changed

2 files changed

+20
-92
lines changed

ikura/shim/proto/da.proto

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
// taken as is from:
2-
// https://github.com/rollkit/go-da/blob/4538294d1704417d0b80273e6437ba1de5548e8a/da.go
2+
// https://github.com/rollkit/go-da/blob/82f52969243cfa2bd7e4b1bd78bff48ed9cfffe6/proto/da/da.proto
33

44
syntax = "proto3";
55
package da;
66

77
// DAService is the protobuf service definition for interaction with Data Availability layers.
88
service DAService {
9-
// MaxBlobSize returns the maximum blob size
10-
rpc MaxBlobSize(MaxBlobSizeRequest) returns (MaxBlobSizeResponse) {}
9+
// MaxBlobSize returns the maximum blob size
10+
rpc MaxBlobSize(MaxBlobSizeRequest) returns (MaxBlobSizeResponse) {}
1111

1212
// Get returns Blob for each given ID, or an error.
1313
rpc Get(GetRequest) returns (GetResponse) {}
1414

1515
// GetIDs returns IDs of all Blobs located in DA at given height.
1616
rpc GetIDs(GetIDsRequest) returns (GetIDsResponse) {}
1717

18-
// GetProofs returns inclusion Proofs for all Blobs located in DA at given height.
19-
rpc GetProofs(GetProofsRequest) returns (GetProofsResponse) {}
20-
2118
// Commit creates a Commitment for each given Blob.
2219
rpc Commit(CommitRequest) returns (CommitResponse) {}
2320

@@ -28,11 +25,6 @@ service DAService {
2825
rpc Validate(ValidateRequest) returns (ValidateResponse) {}
2926
}
3027

31-
// Namespace is the location for the blob to be submitted to, if supported by the DA layer.
32-
message Namespace {
33-
bytes value = 1;
34-
}
35-
3628
// Blob is the data submitted/received from DA interface.
3729
message Blob {
3830
bytes value = 1;
@@ -59,13 +51,12 @@ message MaxBlobSizeRequest {
5951

6052
// MaxBlobSizeResponse is the response type for the MaxBlobSize rpc method.
6153
message MaxBlobSizeResponse {
62-
uint64 max_blob_size = 1;
54+
uint64 max_blob_size = 1;
6355
}
6456

6557
// GetRequest is the request type for the Get rpc method.
6658
message GetRequest {
6759
repeated ID ids = 1;
68-
Namespace namespace = 2;
6960
}
7061

7162
// GetResponse is the response type for the Get rpc method.
@@ -76,29 +67,16 @@ message GetResponse {
7667
// GetIDsRequest is the request type for the GetIDs rpc method.
7768
message GetIDsRequest {
7869
uint64 height = 1;
79-
Namespace namespace = 2;
8070
}
8171

8272
// GetIDsResponse is the response type for the GetIDs rpc method.
8373
message GetIDsResponse {
8474
repeated ID ids = 1;
8575
}
8676

87-
// GetProofsRequest is the request type for the GetProofs rpc method.
88-
message GetProofsRequest {
89-
repeated ID ids = 1;
90-
Namespace namespace = 2;
91-
}
92-
93-
// GetProofsResponse is the response type for the GetProofs rpc method.
94-
message GetProofsResponse {
95-
repeated Proof proofs = 1;
96-
}
97-
9877
// CommitRequest is the request type for the Commit rpc method.
9978
message CommitRequest {
10079
repeated Blob blobs = 1;
101-
Namespace namespace = 2;
10280
}
10381

10482
// CommitResponse is the response type for the Commit rpc method.
@@ -110,19 +88,18 @@ message CommitResponse {
11088
message SubmitRequest {
11189
repeated Blob blobs = 1;
11290
double gas_price = 2;
113-
Namespace namespace = 3;
11491
}
11592

11693
// SubmitResponse is the response type for the Submit rpc method.
11794
message SubmitResponse {
11895
repeated ID ids = 1;
96+
repeated Proof proofs = 2;
11997
}
12098

12199
// ValidateRequest is the request type for the Validate rpc method.
122100
message ValidateRequest {
123101
repeated ID ids = 1;
124102
repeated Proof proofs = 2;
125-
Namespace namespace = 3;
126103
}
127104

128105
// ValidateResponse is the response type for the Validate rpc method.

ikura/shim/src/dock/rollkit.rs

Lines changed: 15 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use tracing::info;
44

55
use self::pbda::{
66
da_service_server, Blob, CommitRequest, CommitResponse, GetIDsRequest, GetIDsResponse,
7-
GetProofsRequest, GetProofsResponse, GetRequest, GetResponse, MaxBlobSizeRequest,
8-
MaxBlobSizeResponse, SubmitRequest, SubmitResponse, ValidateRequest, ValidateResponse,
7+
GetRequest, GetResponse, MaxBlobSizeRequest, MaxBlobSizeResponse, SubmitRequest,
8+
SubmitResponse, ValidateRequest, ValidateResponse,
99
};
1010

1111
use crate::{ikura_rpc, key::Keypair};
@@ -87,9 +87,7 @@ impl da_service_server::DaService for RollkitDock {
8787
}
8888

8989
async fn get(&self, request: Request<GetRequest>) -> Result<Response<GetResponse>, Status> {
90-
let GetRequest { ids, namespace } = request.into_inner();
91-
// Deliberately ignore the namespace since blob ids uniquely identify the blobs.
92-
let _ = namespace;
90+
let GetRequest { ids } = request.into_inner();
9391
let mut cache = HashMap::new();
9492
let mut response = GetResponse { blobs: vec![] };
9593
for (index, id) in ids.into_iter().enumerate() {
@@ -130,12 +128,8 @@ impl da_service_server::DaService for RollkitDock {
130128
&self,
131129
request: Request<GetIDsRequest>,
132130
) -> Result<Response<GetIDsResponse>, Status> {
133-
let GetIDsRequest { namespace, height } = request.into_inner();
134-
let namespace = self.obtain_namespace(namespace)?;
135-
info!(
136-
"retrieving IDs from namespace '{}' at {}",
137-
&namespace, height
138-
);
131+
let GetIDsRequest { height } = request.into_inner();
132+
info!("retrieving IDs at {}", height);
139133
let block_hash = self.client.await_finalized_height(height).await;
140134
let Ok(block) = self.client.await_block_at(Some(block_hash)).await else {
141135
return Err(Status::internal("failed to retrieve block number {height}"));
@@ -144,7 +138,7 @@ impl da_service_server::DaService for RollkitDock {
144138
// Collect all extrinsic indices for blobs in the given namespace.
145139
let mut ids = Vec::with_capacity(block.blobs.len());
146140
for blob in block.blobs {
147-
if blob.namespace == namespace {
141+
if self.namespace.map_or(true, |ns| ns == blob.namespace) {
148142
let blob_id = BlobId {
149143
block_number: height,
150144
extrinsic_index: blob.extrinsic_index,
@@ -165,20 +159,24 @@ impl da_service_server::DaService for RollkitDock {
165159
.as_ref()
166160
.cloned()
167161
.ok_or_else(|| Status::failed_precondition("no key for signing blobs"))?;
162+
let namespace = self.namespace.ok_or_else(|| {
163+
Status::failed_precondition("no namespace provided, and no default namespace set")
164+
})?;
168165
let SubmitRequest {
169-
namespace,
170166
blobs,
171167
gas_price: _,
172168
} = request.into_inner();
173-
let namespace = self.obtain_namespace(namespace)?;
174-
let mut response = SubmitResponse { ids: vec![] };
169+
let mut response = SubmitResponse {
170+
ids: vec![],
171+
proofs: vec![],
172+
};
175173
let blob_n = blobs.len();
176174
for (i, blob) in blobs.into_iter().enumerate() {
177175
let data_hash = sha2_hash(&blob.value);
178176
info!(
179177
"submitting blob {i}/{blob_n} (0x{}) to namespace {}",
180178
hex::encode(&data_hash),
181-
namespace
179+
namespace,
182180
);
183181
let (block_hash, extrinsic_index) = self
184182
.client
@@ -208,26 +206,11 @@ impl da_service_server::DaService for RollkitDock {
208206
};
209207
info!("blob landed: {blob_id}");
210208
response.ids.push(blob_id.into());
209+
response.proofs.push(pbda::Proof { value: vec![] });
211210
}
212211
Ok(Response::new(response))
213212
}
214213

215-
async fn get_proofs(
216-
&self,
217-
request: Request<GetProofsRequest>,
218-
) -> Result<Response<GetProofsResponse>, Status> {
219-
// TODO: implement
220-
// https://github.com/thrumdev/blobs/issues/257
221-
let GetProofsRequest { ids, .. } = request.into_inner();
222-
let response = GetProofsResponse {
223-
proofs: ids
224-
.into_iter()
225-
.map(|_| pbda::Proof { value: vec![] })
226-
.collect(),
227-
};
228-
Ok(Response::new(response))
229-
}
230-
231214
async fn validate(
232215
&self,
233216
request: Request<ValidateRequest>,
@@ -258,38 +241,6 @@ impl da_service_server::DaService for RollkitDock {
258241
}
259242
}
260243

261-
impl RollkitDock {
262-
/// Returns the namespace to be used, either from the request or from the configuration.
263-
///
264-
/// If the namespace is not provided in the request, it will use the namespace from the
265-
/// configuration.
266-
fn obtain_namespace(
267-
&self,
268-
supplied_ns: Option<pbda::Namespace>,
269-
) -> Result<ikura_nmt::Namespace, Status> {
270-
Ok(match supplied_ns {
271-
Some(pbda::Namespace {
272-
value: raw_namespace_bytes,
273-
}) => {
274-
let raw_namespace_bytes = raw_namespace_bytes.as_slice();
275-
if raw_namespace_bytes.len() != 16 {
276-
return Err(Status::invalid_argument("namespace must be 16 bytes long"));
277-
}
278-
let mut namespace = [0u8; 16];
279-
namespace.copy_from_slice(raw_namespace_bytes);
280-
ikura_nmt::Namespace::from_raw_bytes(namespace)
281-
}
282-
None => {
283-
if let Some(namespace) = &self.namespace {
284-
namespace.clone()
285-
} else {
286-
return Err(Status::invalid_argument("namespace must be provided"));
287-
}
288-
}
289-
})
290-
}
291-
}
292-
293244
fn sha2_hash(data: &[u8]) -> [u8; 32] {
294245
use sha2::Digest;
295246
sha2::Sha256::digest(data).into()

0 commit comments

Comments
 (0)