Skip to content

Commit

Permalink
shim/rollkit: downgrade go-da to 0.2.0
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pepyakin committed Mar 4, 2024
1 parent ff4b552 commit f6d7847
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 92 deletions.
33 changes: 5 additions & 28 deletions ikura/shim/proto/da.proto
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
// taken as is from:
// https://github.com/rollkit/go-da/blob/4538294d1704417d0b80273e6437ba1de5548e8a/da.go
// https://github.com/rollkit/go-da/blob/82f52969243cfa2bd7e4b1bd78bff48ed9cfffe6/proto/da/da.proto

syntax = "proto3";
package da;

// DAService is the protobuf service definition for interaction with Data Availability layers.
service DAService {
// MaxBlobSize returns the maximum blob size
rpc MaxBlobSize(MaxBlobSizeRequest) returns (MaxBlobSizeResponse) {}
// MaxBlobSize returns the maximum blob size
rpc MaxBlobSize(MaxBlobSizeRequest) returns (MaxBlobSizeResponse) {}

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

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

// GetProofs returns inclusion Proofs for all Blobs located in DA at given height.
rpc GetProofs(GetProofsRequest) returns (GetProofsResponse) {}

// Commit creates a Commitment for each given Blob.
rpc Commit(CommitRequest) returns (CommitResponse) {}

Expand All @@ -28,11 +25,6 @@ service DAService {
rpc Validate(ValidateRequest) returns (ValidateResponse) {}
}

// Namespace is the location for the blob to be submitted to, if supported by the DA layer.
message Namespace {
bytes value = 1;
}

// Blob is the data submitted/received from DA interface.
message Blob {
bytes value = 1;
Expand All @@ -59,13 +51,12 @@ message MaxBlobSizeRequest {

// MaxBlobSizeResponse is the response type for the MaxBlobSize rpc method.
message MaxBlobSizeResponse {
uint64 max_blob_size = 1;
uint64 max_blob_size = 1;
}

// GetRequest is the request type for the Get rpc method.
message GetRequest {
repeated ID ids = 1;
Namespace namespace = 2;
}

// GetResponse is the response type for the Get rpc method.
Expand All @@ -76,29 +67,16 @@ message GetResponse {
// GetIDsRequest is the request type for the GetIDs rpc method.
message GetIDsRequest {
uint64 height = 1;
Namespace namespace = 2;
}

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

// GetProofsRequest is the request type for the GetProofs rpc method.
message GetProofsRequest {
repeated ID ids = 1;
Namespace namespace = 2;
}

// GetProofsResponse is the response type for the GetProofs rpc method.
message GetProofsResponse {
repeated Proof proofs = 1;
}

// CommitRequest is the request type for the Commit rpc method.
message CommitRequest {
repeated Blob blobs = 1;
Namespace namespace = 2;
}

// CommitResponse is the response type for the Commit rpc method.
Expand All @@ -110,19 +88,18 @@ message CommitResponse {
message SubmitRequest {
repeated Blob blobs = 1;
double gas_price = 2;
Namespace namespace = 3;
}

// SubmitResponse is the response type for the Submit rpc method.
message SubmitResponse {
repeated ID ids = 1;
repeated Proof proofs = 2;
}

// ValidateRequest is the request type for the Validate rpc method.
message ValidateRequest {
repeated ID ids = 1;
repeated Proof proofs = 2;
Namespace namespace = 3;
}

// ValidateResponse is the response type for the Validate rpc method.
Expand Down
79 changes: 15 additions & 64 deletions ikura/shim/src/dock/rollkit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use tracing::info;

use self::pbda::{
da_service_server, Blob, CommitRequest, CommitResponse, GetIDsRequest, GetIDsResponse,
GetProofsRequest, GetProofsResponse, GetRequest, GetResponse, MaxBlobSizeRequest,
MaxBlobSizeResponse, SubmitRequest, SubmitResponse, ValidateRequest, ValidateResponse,
GetRequest, GetResponse, MaxBlobSizeRequest, MaxBlobSizeResponse, SubmitRequest,
SubmitResponse, ValidateRequest, ValidateResponse,
};

use crate::{ikura_rpc, key::Keypair};
Expand Down Expand Up @@ -87,9 +87,7 @@ impl da_service_server::DaService for RollkitDock {
}

async fn get(&self, request: Request<GetRequest>) -> Result<Response<GetResponse>, Status> {
let GetRequest { ids, namespace } = request.into_inner();
// Deliberately ignore the namespace since blob ids uniquely identify the blobs.
let _ = namespace;
let GetRequest { ids } = request.into_inner();
let mut cache = HashMap::new();
let mut response = GetResponse { blobs: vec![] };
for (index, id) in ids.into_iter().enumerate() {
Expand Down Expand Up @@ -130,12 +128,8 @@ impl da_service_server::DaService for RollkitDock {
&self,
request: Request<GetIDsRequest>,
) -> Result<Response<GetIDsResponse>, Status> {
let GetIDsRequest { namespace, height } = request.into_inner();
let namespace = self.obtain_namespace(namespace)?;
info!(
"retrieving IDs from namespace '{}' at {}",
&namespace, height
);
let GetIDsRequest { height } = request.into_inner();
info!("retrieving IDs at {}", height);
let block_hash = self.client.await_finalized_height(height).await;
let Ok(block) = self.client.await_block_at(Some(block_hash)).await else {
return Err(Status::internal("failed to retrieve block number {height}"));
Expand All @@ -144,7 +138,7 @@ impl da_service_server::DaService for RollkitDock {
// Collect all extrinsic indices for blobs in the given namespace.
let mut ids = Vec::with_capacity(block.blobs.len());
for blob in block.blobs {
if blob.namespace == namespace {
if self.namespace.map_or(true, |ns| ns == blob.namespace) {
let blob_id = BlobId {
block_number: height,
extrinsic_index: blob.extrinsic_index,
Expand All @@ -165,20 +159,24 @@ impl da_service_server::DaService for RollkitDock {
.as_ref()
.cloned()
.ok_or_else(|| Status::failed_precondition("no key for signing blobs"))?;
let namespace = self.namespace.ok_or_else(|| {
Status::failed_precondition("no namespace provided, and no default namespace set")
})?;
let SubmitRequest {
namespace,
blobs,
gas_price: _,
} = request.into_inner();
let namespace = self.obtain_namespace(namespace)?;
let mut response = SubmitResponse { ids: vec![] };
let mut response = SubmitResponse {
ids: vec![],
proofs: vec![],
};
let blob_n = blobs.len();
for (i, blob) in blobs.into_iter().enumerate() {
let data_hash = sha2_hash(&blob.value);
info!(
"submitting blob {i}/{blob_n} (0x{}) to namespace {}",
hex::encode(&data_hash),
namespace
namespace,
);
let (block_hash, extrinsic_index) = self
.client
Expand Down Expand Up @@ -208,26 +206,11 @@ impl da_service_server::DaService for RollkitDock {
};
info!("blob landed: {blob_id}");
response.ids.push(blob_id.into());
response.proofs.push(pbda::Proof { value: vec![] });
}
Ok(Response::new(response))
}

async fn get_proofs(
&self,
request: Request<GetProofsRequest>,
) -> Result<Response<GetProofsResponse>, Status> {
// TODO: implement
// https://github.com/thrumdev/blobs/issues/257
let GetProofsRequest { ids, .. } = request.into_inner();
let response = GetProofsResponse {
proofs: ids
.into_iter()
.map(|_| pbda::Proof { value: vec![] })
.collect(),
};
Ok(Response::new(response))
}

async fn validate(
&self,
request: Request<ValidateRequest>,
Expand Down Expand Up @@ -258,38 +241,6 @@ impl da_service_server::DaService for RollkitDock {
}
}

impl RollkitDock {
/// Returns the namespace to be used, either from the request or from the configuration.
///
/// If the namespace is not provided in the request, it will use the namespace from the
/// configuration.
fn obtain_namespace(
&self,
supplied_ns: Option<pbda::Namespace>,
) -> Result<ikura_nmt::Namespace, Status> {
Ok(match supplied_ns {
Some(pbda::Namespace {
value: raw_namespace_bytes,
}) => {
let raw_namespace_bytes = raw_namespace_bytes.as_slice();
if raw_namespace_bytes.len() != 16 {
return Err(Status::invalid_argument("namespace must be 16 bytes long"));
}
let mut namespace = [0u8; 16];
namespace.copy_from_slice(raw_namespace_bytes);
ikura_nmt::Namespace::from_raw_bytes(namespace)
}
None => {
if let Some(namespace) = &self.namespace {
namespace.clone()
} else {
return Err(Status::invalid_argument("namespace must be provided"));
}
}
})
}
}

fn sha2_hash(data: &[u8]) -> [u8; 32] {
use sha2::Digest;
sha2::Sha256::digest(data).into()
Expand Down

0 comments on commit f6d7847

Please sign in to comment.