Skip to content

smite-scenarios: log messages in name(type) format - #194

Open
ekzyis wants to merge 1 commit into
lnfuzz:masterfrom
ekzyis:log-messages-in-name-type-format
Open

smite-scenarios: log messages in name(type) format#194
ekzyis wants to merge 1 commit into
lnfuzz:masterfrom
ekzyis:log-messages-in-name-type-format

Conversation

@ekzyis

@ekzyis ekzyis commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

I found this quite useful. This changes the logs like this:

-SendMessage: Some(258), 138 bytes 
+SendMessage: channel_update(258), 138 bytes

and

-expected 33, got 17
+expected accept_channel(33), got error(17)

WDYT? Concept ACK?

@erickcestari erickcestari left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like the idea to make the logs more self-describing

Concept ACK 667aae8

Comment thread smite-scenarios/src/scenarios/ir.rs Outdated
Comment thread smite-scenarios/src/executor.rs
@morehouse

Copy link
Copy Markdown
Collaborator

Concept ACK. I think a much simpler way is to implement the Display trait for MessageType.

@ekzyis
ekzyis force-pushed the log-messages-in-name-type-format branch from 667aae8 to a56bfc7 Compare August 11, 2026 22:07
@ekzyis

ekzyis commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

addressed feedback in a56bfc7:

  • new MessageType struct with Display implementation
  • use existing Display implementation for UnexpectedMessage from #[error(message)]

@ekzyis
ekzyis force-pushed the log-messages-in-name-type-format branch from a56bfc7 to 33a0f32 Compare August 12, 2026 12:43
@ekzyis

ekzyis commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

a56bfc7..33a0f32:

  • renamed type_ to ty because I learned that ty is the Rust convention when your name conflicts with the reserved keyword type

Comment on lines +1830 to +1833
other => panic!(
"expected {}, got {other}",
msg_type::MessageType(msg_type::OPEN_CHANNEL)
),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: we could simplify all these panics

Suggested change
other => panic!(
"expected {}, got {other}",
msg_type::MessageType(msg_type::OPEN_CHANNEL)
),
other => panic!("expected open_channel, got {other}"),

Comment thread smite/src/bolt.rs
Comment on lines +1406 to +1409
for (msg, name, ty) in cases {
assert_eq!(msg.msg_type(), ty, "wrong type number for {name}");
assert_eq!(msg.msg_name(), name, "wrong type name for {ty}");
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
for (msg, name, ty) in cases {
assert_eq!(msg.msg_type(), ty, "wrong type number for {name}");
assert_eq!(msg.msg_name(), name, "wrong type name for {ty}");
}
for (msg, name, ty) in cases {
assert_eq!(msg.msg_type(), ty, "wrong type number for {name}");
assert_eq!(msg.msg_name(), name, "wrong type name for {ty}");
assert_eq!(msg.to_string(), format!("{name}({ty})"));
assert_eq!(msg_type::MessageType(ty).to_string(), format!("{name}({ty})"));
}

Comment thread smite/src/bolt.rs
impl std::fmt::Display for Message {
/// Formats as `name(type)`, e.g. `open_channel(32)`.
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}({})", self.msg_name(), self.msg_type())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
write!(f, "{}({})", self.msg_name(), self.msg_type())
write!(f, "{}", msg_type::MessageType(self.msg_type()))

Comment thread smite/src/bolt.rs
},
}

impl std::fmt::Display for Message {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: let's move this to just after the impl Message block below.

Comment thread smite/src/bolt.rs
Comment on lines +254 to +255
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MessageType(pub u16);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Now we're using MessageType in some places and u16 in others. I think it would be a bit cleaner if we refactored to use MessageType everywhere. For example, the msg_type::OPEN_CHANNEL and other constants could all be MessageTypes, UnexexpectedMessage errors can contain MessageTypes, and Message::msg_type can return a MessageType.

@morehouse

Copy link
Copy Markdown
Collaborator

We should also be able to get rid of the msg_type module and move the constants inside an impl MessageType block.

@erickcestari erickcestari left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably a follow-up PR, but another thing that might be useful for debugging is to log the warning and error data field as ASCII.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants