Skip to content

Experiment - rollkit adapter multiple blocks submission #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sugondat-shim/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ subxt = { version = "0.32.1" }
subxt-signer = {version = "0.32.1", features = ["subxt"] }
sha2 = "0.10.8"
hex = "0.4.3"
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }

[dev-dependencies]
temp-dir = "0.1.11"
35 changes: 24 additions & 11 deletions sugondat-shim/src/dock/rollkit.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use codec::{Decode, Encode};
use jsonrpsee::Methods;
use sugondat_shim_common_rollkit::{Blob, JsonRPCError, RollkitRPCServer};
use tracing::{debug, info};
Expand Down Expand Up @@ -25,6 +26,15 @@ impl RollkitDock {
}
}

#[derive(codec::Encode, codec::Decode)]
pub struct Batch(Vec<Vec<u8>>);

impl From<Vec<Blob>> for Batch {
fn from(value: Vec<Blob>) -> Self {
Self(value.into_iter().map(|blob| blob.data).collect())
}
}

#[async_trait::async_trait]
impl RollkitRPCServer for RollkitDock {
async fn retrieve(&self, namespace: String, height: u64) -> Result<Vec<Blob>, JsonRPCError> {
Expand All @@ -36,9 +46,12 @@ impl RollkitRPCServer for RollkitDock {
let block_hash = self.client.wait_finalized_height(height).await.unwrap();
let block = self.client.get_block_at(block_hash).await.unwrap();
let mut blobs = vec![];
for blob in block.blobs {
if blob.namespace == namespace {
blobs.push(Blob { data: blob.data });
// From the sugondat perspective in the block are contained blobs
// but each sugondat-blob is a rollkit-batch that could contain multiple rollkit-blobs
for batch in block.blobs {
if batch.namespace == namespace {
let batch_data: Batch = Decode::decode(&mut &batch.data[..]).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unwrap can be easily triggered by someone submitting another batch manually on the namespace. The assumption that all blobs with the namespace have been submitted through this API is fragile.

Panics should only happen on critical bugs. (IMO unwrap is a major code smell and expect("argument for impossibility") is a much better approach.

Copy link
Contributor Author

@gabriele-0201 gabriele-0201 Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree 100% with you! I put this unwrap just because that's a fast iteration to check a possible approach to solve that problem but it was never intended to be pushed on main 😅

blobs.extend(batch_data.0.into_iter().map(|blob| Blob { data: blob }));
}
}
Ok(blobs)
Expand All @@ -52,14 +65,14 @@ impl RollkitRPCServer for RollkitDock {
.as_ref()
.cloned()
.ok_or_else(err::no_signing_key)?;
for blob in blobs {
self.client
.submit_blob(blob.data, namespace, submit_key.clone())
.await
.map_err(|_| err::submission_error())?;
}
// TODO:
Ok(0)
let batch: Batch = blobs.into();
let block_hash = self
.client
.submit_blob(batch.encode(), namespace, submit_key.clone())
.await
.map_err(|_| err::submission_error())?;
let block = self.client.get_block_at(block_hash).await.unwrap();
Ok(block.number)
}
}

Expand Down