Skip to content

chore: improve logging #189

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

Merged
merged 1 commit into from
Jan 12, 2024
Merged
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
10 changes: 9 additions & 1 deletion sugondat/nmt/src/ns.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use alloc::string::ToString;

use crate::NS_ID_SIZE;
use core::fmt;

Expand All @@ -13,7 +15,7 @@ use core::fmt;
/// # use sugondat_nmt::Namespace;
/// assert!(Namespace::from_u128_be(0x0100) > Namespace::from_u128_be(0x00FF));
/// ````
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
Expand Down Expand Up @@ -70,3 +72,9 @@ impl fmt::Display for Namespace {
Ok(())
}
}

impl fmt::Debug for Namespace {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("Namespace").field(&self.to_string()).finish()
}
}
8 changes: 7 additions & 1 deletion sugondat/shim/src/dock/rollkit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl RollkitRPCServer for RollkitDock {
self.client
.submit_blob(blob.data, namespace, submit_key.clone())
.await
.map_err(|_| err::submission_error())?;
.map_err(err::submission_error)?;
}
// TODO:
Ok(0)
Expand All @@ -70,6 +70,12 @@ impl RollkitRPCServer for RollkitDock {
fn parse_namespace(namespace: &str) -> anyhow::Result<sugondat_nmt::Namespace> {
use sugondat_nmt::NS_ID_SIZE;
let namespace_bytes = hex::decode(namespace)?;
if namespace_bytes.len() != NS_ID_SIZE {
debug!(
"The namespace '{}' is not {} bytes long. Resizing...",
namespace, NS_ID_SIZE
);
}
let namespace_bytes = match namespace_bytes.len() {
0 => anyhow::bail!("namespace must not be empty"),
1..=NS_ID_SIZE => {
Expand Down
4 changes: 2 additions & 2 deletions sugondat/shim/src/dock/rpc_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ pub fn no_signing_key() -> ErrorObjectOwned {
)
}

pub fn submission_error() -> ErrorObjectOwned {
pub fn submission_error(e: anyhow::Error) -> ErrorObjectOwned {
ErrorObjectOwned::owned(
jsonrpsee::types::error::INTERNAL_ERROR_CODE,
"Internal Error: failed to submit blob",
format!("Internal Error: failed to submit blob: {:?}", e),
None::<()>,
)
}
2 changes: 1 addition & 1 deletion sugondat/shim/src/dock/sovereign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl SovereignRPCServer for SovereignDock {
self.client
.submit_blob(blob, namespace, submit_key)
.await
.map_err(|_| err::submission_error())?;
.map_err(err::submission_error)?;
Ok(())
}
}
Expand Down
21 changes: 19 additions & 2 deletions sugondat/shim/src/sugondat_rpc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{fmt, sync::Arc};

use crate::key::Keypair;
use anyhow::Context;
Expand Down Expand Up @@ -343,7 +343,6 @@ pub struct Block {
}

/// Represents a blob in a sugondat block.
#[derive(Debug)]
pub struct Blob {
pub extrinsic_index: u32,
pub namespace: Namespace,
Expand All @@ -357,3 +356,21 @@ impl Blob {
sha2::Sha256::digest(&self.data).into()
}
}

impl fmt::Debug for Blob {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let abridged_data = if self.data.len() > 16 {
let mut s = hex::encode(&self.data[..16]);
s.push_str("...");
s
} else {
hex::encode(&self.data)
};
f.debug_struct("Blob")
.field("extrinsic_index", &self.extrinsic_index)
.field("namespace", &self.namespace)
.field("sender", &self.sender)
.field("data", &abridged_data)
.finish()
}
}