Skip to content

Commit c4dd651

Browse files
committed
chore: improve logging
This changeset is meant to improve the logging. Basically committing whatever logging changes that I did for debugging issues with the demo.
1 parent 3963d90 commit c4dd651

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

sugondat/nmt/src/ns.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use alloc::string::ToString;
2+
13
use crate::NS_ID_SIZE;
24
use core::fmt;
35

@@ -13,7 +15,7 @@ use core::fmt;
1315
/// # use sugondat_nmt::Namespace;
1416
/// assert!(Namespace::from_u128_be(0x0100) > Namespace::from_u128_be(0x00FF));
1517
/// ````
16-
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
18+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
1719
#[cfg_attr(
1820
feature = "serde",
1921
derive(serde::Serialize, serde::Deserialize),
@@ -70,3 +72,9 @@ impl fmt::Display for Namespace {
7072
Ok(())
7173
}
7274
}
75+
76+
impl fmt::Debug for Namespace {
77+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
78+
f.debug_tuple("Namespace").field(&self.to_string()).finish()
79+
}
80+
}

sugondat/shim/src/dock/rollkit.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl RollkitRPCServer for RollkitDock {
5656
self.client
5757
.submit_blob(blob.data, namespace, submit_key.clone())
5858
.await
59-
.map_err(|_| err::submission_error())?;
59+
.map_err(err::submission_error)?;
6060
}
6161
// TODO:
6262
Ok(0)
@@ -70,6 +70,12 @@ impl RollkitRPCServer for RollkitDock {
7070
fn parse_namespace(namespace: &str) -> anyhow::Result<sugondat_nmt::Namespace> {
7171
use sugondat_nmt::NS_ID_SIZE;
7272
let namespace_bytes = hex::decode(namespace)?;
73+
if namespace_bytes.len() != NS_ID_SIZE {
74+
debug!(
75+
"The namespace '{}' is not {} bytes long. Resizing...",
76+
namespace, NS_ID_SIZE
77+
);
78+
}
7379
let namespace_bytes = match namespace_bytes.len() {
7480
0 => anyhow::bail!("namespace must not be empty"),
7581
1..=NS_ID_SIZE => {

sugondat/shim/src/dock/rpc_error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ pub fn no_signing_key() -> ErrorObjectOwned {
1616
)
1717
}
1818

19-
pub fn submission_error() -> ErrorObjectOwned {
19+
pub fn submission_error(e: anyhow::Error) -> ErrorObjectOwned {
2020
ErrorObjectOwned::owned(
2121
jsonrpsee::types::error::INTERNAL_ERROR_CODE,
22-
"Internal Error: failed to submit blob",
22+
format!("Internal Error: failed to submit blob: {:?}", e),
2323
None::<()>,
2424
)
2525
}

sugondat/shim/src/dock/sovereign.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl SovereignRPCServer for SovereignDock {
6969
self.client
7070
.submit_blob(blob, namespace, submit_key)
7171
.await
72-
.map_err(|_| err::submission_error())?;
72+
.map_err(err::submission_error)?;
7373
Ok(())
7474
}
7575
}

sugondat/shim/src/sugondat_rpc/mod.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::sync::Arc;
1+
use std::{fmt, sync::Arc};
22

33
use crate::key::Keypair;
44
use anyhow::Context;
@@ -343,7 +343,6 @@ pub struct Block {
343343
}
344344

345345
/// Represents a blob in a sugondat block.
346-
#[derive(Debug)]
347346
pub struct Blob {
348347
pub extrinsic_index: u32,
349348
pub namespace: Namespace,
@@ -357,3 +356,21 @@ impl Blob {
357356
sha2::Sha256::digest(&self.data).into()
358357
}
359358
}
359+
360+
impl fmt::Debug for Blob {
361+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
362+
let abridged_data = if self.data.len() > 16 {
363+
let mut s = hex::encode(&self.data[..16]);
364+
s.push_str("...");
365+
s
366+
} else {
367+
hex::encode(&self.data)
368+
};
369+
f.debug_struct("Blob")
370+
.field("extrinsic_index", &self.extrinsic_index)
371+
.field("namespace", &self.namespace)
372+
.field("sender", &self.sender)
373+
.field("data", &abridged_data)
374+
.finish()
375+
}
376+
}

0 commit comments

Comments
 (0)