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

Simplify some logging #83

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 20 additions & 53 deletions core/src/commands/on_runtime_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ use std::{collections::BTreeMap, fmt::Debug, str::FromStr};

use bytesize::ByteSize;
use frame_try_runtime::UpgradeCheckSelect;
use paris::formatter::colorize_string;
use log::Level;
use parity_scale_codec::Encode;
use sc_executor::sp_wasm_interface::HostFunctions;
use sp_core::{hexdisplay::HexDisplay, Hasher};
use sp_runtime::traits::{Block as BlockT, HashingFor, NumberFor};
use sp_state_machine::{CompactProof, OverlayedChanges, StorageProof};

use crate::{
build_executor,
build_executor, misc,
state::{RuntimeChecks, State},
state_machine_call_with_proof, RefTimeInfo, SharedParams, LOG_TARGET,
};
Expand Down Expand Up @@ -106,24 +106,13 @@ where
}

// Run `TryRuntime_on_runtime_upgrade` with the given checks.
log::info!(
"{}",
colorize_string(
"<bold><blue>-------------------------------------------------------------------\n\n"
)
);
log::info!(
"{}",
colorize_string(format!(
"🔬 <bold><blue>Running TryRuntime_on_runtime_upgrade with checks: {:?}\n\n",
misc::basti_log(
Level::Info,
format!(
"🔬 Running TryRuntime_on_runtime_upgrade with checks: {:?}",
command.checks
))
);
log::info!(
"{}",
colorize_string(
"<bold><blue>-------------------------------------------------------------------"
)
.as_str(),
);
// Save the overlayed changes from the first run, so we can use them later for idempotency
// checks.
Expand All @@ -146,17 +135,9 @@ where
let (proof, ref_time_results) = match command.checks {
UpgradeCheckSelect::None => (proof, ref_time_results),
_ => {
log::info!(
"{}",
colorize_string("<bold><blue>-------------------------------------------------------------------\n\n")
);
log::info!(
"{}",
colorize_string("🔬 <bold><blue>TryRuntime_on_runtime_upgrade succeeded! Running it again without checks for weight measurements.\n\n"),
);
log::info!(
"{}",
colorize_string("<bold><blue>-------------------------------------------------------------------")
misc::basti_log(
Level::Info,
"🔬 TryRuntime_on_runtime_upgrade succeeded! Running it again without checks for weight measurements.",
);
let (proof, encoded_result) = state_machine_call_with_proof::<Block, HostFns>(
&ext,
Expand All @@ -179,17 +160,13 @@ where
true
}
false => {
log::info!(
"{}",
colorize_string("<bold><blue>-------------------------------------------------------------------\n\n")
);
log::info!(
"{}",
colorize_string(format!("🔬 <bold><blue>Running TryRuntime_on_runtime_upgrade again to check idempotency: {:?}\n\n", command.checks)),
);
log::info!(
"{}",
colorize_string("<bold><blue>-------------------------------------------------------------------")
misc::basti_log(
Level::Info,
format!(
"🔬 Running TryRuntime_on_runtime_upgrade again to check idempotency: {:?}",
command.checks
)
.as_str(),
);
let (oc_pre_root, _) = overlayed_changes.storage_root(&ext.backend, ext.state_version);
overlayed_changes.start_transaction();
Expand Down Expand Up @@ -267,19 +244,9 @@ where
};

if !weight_ok || !idempotency_ok {
log::error!(
"{}",
colorize_string("<bold><red>-------------------------------------------------------------------\n\n")
);
log::error!(
"{}",
colorize_string("❌ <bold><red>Issues detected, exiting non-zero. See logs.\n\n"),
);
log::error!(
"{}",
colorize_string(
"<bold><red>-------------------------------------------------------------------"
)
misc::basti_log(
Level::Error,
"❌ Issues detected, exiting non-zero. See logs.",
);
std::process::exit(1);
}
Expand Down
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use crate::shared_parameters::SharedParams;

pub mod commands;
pub mod inherent_provider;
mod misc;
mod parse;
pub mod shared_parameters;
pub mod state;
Expand Down
39 changes: 39 additions & 0 deletions core/src/misc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use log::{log, Level};
use paris::formatter::colorize_string;

fn level_to_color(level: Level) -> &'static str {
match level {
Level::Info => "blue",
Level::Warn => "yellow",
Level::Error => "red",
_ => "white",
}
}

/// A BIG log that's very difficult to miss.
pub fn basti_log(level: Level, message: &str) {
let color = level_to_color(level);
log!(
level,
"{}",
colorize_string(format!(
"<bold><{}>{}\n\n",
&color,
"-".repeat(message.len())
))
);
log!(
level,
"{}",
colorize_string(format!("<bold><{}>{}\n\n", &color, message))
);
log!(
level,
"{}",
colorize_string(format!(
"<bold><{}>{}\n\n",
&color,
"-".repeat(message.len())
))
);
}
Loading