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

change(log): Log a cute message for blocks that were mined by Zebra (off by default) #6098

Merged
merged 12 commits into from
Feb 23, 2023
Merged
40 changes: 32 additions & 8 deletions zebra-state/src/service/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,37 @@ fn log_if_mined_by_zebra(tip_block: &ChainTipBlock) {
.starts_with(EXTRA_ZEBRA_COINBASE_DATA.as_bytes())
{
let text = String::from_utf8_lossy(coinbase_data.as_ref());
let data = hex::encode(coinbase_data.as_ref());
info!(
?text,
?data,
%height,
%hash,
"looks like this block was mined by Zebra!"
);

if coinbase_data.as_ref() == EXTRA_ZEBRA_COINBASE_DATA.as_bytes() {
info!(
%text,
%height,
%hash,
"looks like this block was mined by Zebra!"
);
} else {
// # Security
//
// Use the extra data as an allow-list, replacing unknown characters.
// This makes sure control characters and harmful messages don't get logged
// to the terminal.
let text = text.replace(
|c| {
!EXTRA_ZEBRA_COINBASE_DATA
.to_ascii_lowercase()
.contains(c.to_ascii_lowercase())
},
"?",
);
let data = hex::encode(coinbase_data.as_ref());

info!(
%text,
%data,
%height,
%hash,
"looks like this block was mined by Zebra!"
);
}
}
}