diff --git a/src/phoenix.rs b/src/phoenix.rs index bdd40e3..d4f5190 100644 --- a/src/phoenix.rs +++ b/src/phoenix.rs @@ -5,6 +5,7 @@ mod consensus_node; mod demotion_monitor; mod env; mod inclusion_monitor; +mod markdown; mod promotion_monitor; mod validation_node; diff --git a/src/phoenix/demotion_monitor.rs b/src/phoenix/demotion_monitor.rs index 7e5d866..524ea11 100644 --- a/src/phoenix/demotion_monitor.rs +++ b/src/phoenix/demotion_monitor.rs @@ -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::{ @@ -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"); diff --git a/src/phoenix/markdown.rs b/src/phoenix/markdown.rs new file mode 100644 index 0000000..97710ab --- /dev/null +++ b/src/phoenix/markdown.rs @@ -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 +}