From 417ed72110dbd134a40ab1d862b3a9b391a039d5 Mon Sep 17 00:00:00 2001 From: Sergei Shulepov Date: Thu, 29 Feb 2024 23:52:04 +0700 Subject: [PATCH] shim/rollkit: downgrade go-da to 0.2.0 the version that was introduced in #260 (997046d926170d0bcf5e2824d5670c0a5fb85a2f) was using the latest version of go-da (0.4.0). 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. --- ikura/shim/proto/da.proto | 33 +++----------- ikura/shim/src/dock/rollkit.rs | 79 +++++++--------------------------- 2 files changed, 20 insertions(+), 92 deletions(-) diff --git a/ikura/shim/proto/da.proto b/ikura/shim/proto/da.proto index 4ce79b7..fc0f01d 100644 --- a/ikura/shim/proto/da.proto +++ b/ikura/shim/proto/da.proto @@ -1,13 +1,13 @@ // 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) {} @@ -15,9 +15,6 @@ service DAService { // 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) {} @@ -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; @@ -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. @@ -76,7 +67,6 @@ 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. @@ -84,21 +74,9 @@ 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. @@ -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. diff --git a/ikura/shim/src/dock/rollkit.rs b/ikura/shim/src/dock/rollkit.rs index 6952d75..a26db07 100644 --- a/ikura/shim/src/dock/rollkit.rs +++ b/ikura/shim/src/dock/rollkit.rs @@ -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}; @@ -87,9 +87,7 @@ impl da_service_server::DaService for RollkitDock { } async fn get(&self, request: Request) -> Result, 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() { @@ -130,12 +128,8 @@ impl da_service_server::DaService for RollkitDock { &self, request: Request, ) -> Result, 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}")); @@ -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, @@ -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 @@ -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, - ) -> Result, 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, @@ -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, - ) -> Result { - 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()