Skip to content
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

better debugging for accountid32 in debug build #2990

Merged
merged 4 commits into from
Jan 19, 2024

Conversation

pgherveou
Copy link
Contributor

No description provided.

@pgherveou pgherveou added the R0-silent Changes should not be mentioned in any release notes label Jan 18, 2024
@pgherveou
Copy link
Contributor Author

I am also for using debug_assertions instead of a custom "force-debug" flag here to make verbose debug impl the default in debug build.

@bkchr thoughts?

#[cfg(any(feature = "std", feature = "force-debug"))]
mod implementation {
use super::*;
use proc_macro2::Span;
use syn::{token::SelfValue, Ident, Index};

@bkchr
Copy link
Member

bkchr commented Jan 18, 2024

We should really check the size impact of just having Debug everywhere. And then probably just enable it.

@pgherveou
Copy link
Contributor Author

pgherveou commented Jan 18, 2024

We should really check the size impact of just having Debug everywhere. And then probably just enable it.

that's a 8kb change for me when compiling node_template_runtime.compact.wasm size without debug-derive

@liamaharon
Copy link
Contributor

We should really check the size impact of just having Debug everywhere. And then probably just enable it.

that's a 8kb change for me when compiling node_template_runtime.compact.wasm size without debug-derive

what's the % increase on both node-template and rococo-runtime?

@pgherveou
Copy link
Contributor Author

pgherveou commented Jan 19, 2024

We should really check the size impact of just having Debug everywhere. And then probably just enable it.

that's a 8kb change for me when compiling node_template_runtime.compact.wasm size without debug-derive

what's the % increase on both node-template and rococo-runtime?

wasm patched master diff % increase
rococo_runtime.compact.compressed.wasm 1549204 1533452 15752 1.02
node_template_runtime.compact.compressed.wasm 246729 243338 3391 1.39
  • used the non compressed before, my bad
  • patch is
diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs
index 2da38d44be4..58d8616368e 100644
--- a/substrate/primitives/core/src/crypto.rs
+++ b/substrate/primitives/core/src/crypto.rs
@@ -593,14 +593,16 @@ impl std::fmt::Display for AccountId32 {
 }
 
 impl sp_std::fmt::Debug for AccountId32 {
-	#[cfg(feature = "std")]
 	fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
-		let s = self.to_ss58check();
-		write!(f, "{} ({}...)", crate::hexdisplay::HexDisplay::from(&self.0), &s[0..8])
-	}
+		#[cfg(feature = "serde")]
+		{
+			let s = self.to_ss58check();
+			write!(f, "{} ({}...)", crate::hexdisplay::HexDisplay::from(&self.0), &s[0..8])?;
+		}
+
+		#[cfg(not(feature = "serde"))]
+		write!(f, "{}", crate::hexdisplay::HexDisplay::from(&self.0))?;
 
-	#[cfg(not(feature = "std"))]
-	fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
 		Ok(())
 	}
 }
diff --git a/substrate/primitives/debug-derive/src/impls.rs b/substrate/primitives/debug-derive/src/impls.rs
index 76ef8367277..1b971e219ed 100644
--- a/substrate/primitives/debug-derive/src/impls.rs
+++ b/substrate/primitives/debug-derive/src/impls.rs
@@ -43,22 +43,6 @@ pub fn debug_derive(ast: DeriveInput) -> proc_macro::TokenStream {
 	gen.into()
 }
 
-#[cfg(all(not(feature = "std"), not(feature = "force-debug")))]
-mod implementation {
-	use super::*;
-
-	/// Derive the inner implementation of `Debug::fmt` function.
-	///
-	/// Non-std environment. We do nothing to prevent bloating the size of runtime.
-	/// Implement `Printable` if you need to print the details.
-	pub fn derive(_name_str: &str, _data: &Data) -> TokenStream {
-		quote! {
-			fmt.write_str("<wasm:stripped>")
-		}
-	}
-}
-
-#[cfg(any(feature = "std", feature = "force-debug"))]

@pgherveou pgherveou added this pull request to the merge queue Jan 19, 2024
@liamaharon liamaharon removed this pull request from the merge queue due to a manual request Jan 19, 2024
@liamaharon
Copy link
Contributor

We should really check the size impact of just having Debug everywhere. And then probably just enable it.

@pgherveou I removed from the merge queue because maybe we want to do this instead, since only very small increase to runtime size. @bkchr sound good?

@pgherveou
Copy link
Contributor Author

We should really check the size impact of just having Debug everywhere. And then probably just enable it.

@pgherveou I removed from the merge queue because maybe we want to do this instead, since only very small increase to runtime size. @bkchr sound good?

fine for me, this can be done in a follow up, but if we are fine with the size bump then we can use this patch instead, or maybe just get rid of debug-derive?

@liamaharon
Copy link
Contributor

Yeah that's what I meant just use your patch then we get it all done in this pr instead of needing to make another one, get reviews again, etc :)

@athei
Copy link
Member

athei commented Jan 19, 2024

We should really check the size impact of just having Debug everywhere. And then probably just enable it.

Agreed. The use of Debug vs RuntimeDebug seems really arbitrary. Do you suggest just getting rid of RuntimeDebug all together if the size impact is not too bad after compression?

@pgherveou
Copy link
Contributor Author

We should really check the size impact of just having Debug everywhere. And then probably just enable it.

Agreed. The use of Debug vs RuntimeDebug seems really arbitrary. Do you suggest just getting rid of RuntimeDebug all together if the size impact is not too bad after compression?

Happy to add that here if we have consensus.
The most important for us is to have the current patch merged as having AccountId stripped from logs make debugging contracts especially nested contract much harder

@athei
Copy link
Member

athei commented Jan 19, 2024

I am not really sure what is being discussed here. Your PR does derive Debug for the type unconditionally. We can only format ss58 if serde is available. So this is covered. We won't be changing the whole of substrate over to Debug in this PR. So I don't get why it was removed from the merge queue. Can you elaborate @liamaharon ?

@liamaharon
Copy link
Contributor

We won't be changing the whole of substrate over to Debug in this PR.

I must have misunderstood Basti's comment. Feel free to merge if this is ready.

@ggwpez
Copy link
Member

ggwpez commented Jan 19, 2024

We won't be changing the whole of substrate over to Debug in this PR.

Yea we would first have to re-check the size impact again as well.

@athei
Copy link
Member

athei commented Jan 19, 2024

We won't be changing the whole of substrate over to Debug in this PR.

I must have misunderstood Basti's comment. Feel free to merge if this is ready.

I understood it more as a general thing we should do. But not necessarily in this PR. Could be wrong though. Shouldn't stop us here. So let's go on and merge this. Eradication of RuntimeDebug should be a separate PR.

@athei athei added this pull request to the merge queue Jan 19, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 19, 2024
@bkchr
Copy link
Member

bkchr commented Jan 19, 2024

I understood it more as a general thing we should do

Yes, sorry for not being more specific 🙈

@bkchr bkchr added this pull request to the merge queue Jan 19, 2024
@bkchr
Copy link
Member

bkchr commented Jan 19, 2024

Created an issue: #3005

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 19, 2024
@ggwpez ggwpez added this pull request to the merge queue Jan 19, 2024
Merged via the queue into master with commit f2336d3 Jan 19, 2024
126 checks passed
@ggwpez ggwpez deleted the pg/better-debugging-for-accountid32-in-debug-build branch January 19, 2024 22:03
bgallois pushed a commit to duniter/duniter-polkadot-sdk that referenced this pull request Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants