Skip to content

Commit

Permalink
feat: escape markdown chars for sim errors
Browse files Browse the repository at this point in the history
  • Loading branch information
blombern committed Sep 5, 2023
1 parent a474c4a commit 6cb72cc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/phoenix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod consensus_node;
mod demotion_monitor;
mod env;
mod inclusion_monitor;
mod markdown;
mod promotion_monitor;
mod validation_node;

Expand Down
6 changes: 3 additions & 3 deletions src/phoenix/demotion_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tracing::{error, info};

use crate::{
env::{ToBeaconExplorerUrl, ToNetwork},
phoenix::promotion_monitor::ELIGIBLE_ERRORS,
phoenix::{markdown, promotion_monitor::ELIGIBLE_ERRORS},
};

use super::{
Expand Down Expand Up @@ -94,12 +94,12 @@ pub async fn run_demotion_monitor(relay_pool: &PgPool, mev_pool: &PgPool) -> Res
.into_iter()
.map(|demotion| {
format!(
"*{name}* `{pubkey}` was demoted during slot [{slot}]({url}/slot/{slot}) with the following error:\n\n{error}",
"*{name}* `{pubkey}` was demoted during slot [{slot}]({url}/slot/{slot}) with the following error:\n\n```{error}```",
name = demotion.builder_id.clone().unwrap_or("unknown builder_id".to_string()),
pubkey = demotion.builder_pubkey,
slot = demotion.slot,
url = &APP_CONFIG.env.to_beacon_explorer_url(),
error = demotion.sim_error
error = markdown::escape_code_block(&demotion.sim_error)
)

}).join("\n\n");
Expand Down
15 changes: 15 additions & 0 deletions src/phoenix/markdown.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Used to escape characters inside markdown code blocks
// https://core.telegram.org/bots/api#markdownv2-style
pub fn escape_code_block(input: &str) -> String {
let mut output = String::new();
for c in input.chars() {
match c {
'`' | '\\' => {
output.push('\\');
}
_ => {}
}
output.push(c);
}
output
}

0 comments on commit 6cb72cc

Please sign in to comment.