From e24d7fced41d132fbd5174eabb3d41b5f311f64b Mon Sep 17 00:00:00 2001 From: john xu Date: Fri, 24 May 2024 19:26:06 +0800 Subject: [PATCH] feat: disable inplace print in container env --- docker/entrypoint.sh | 12 +++++++----- lib/src/consts.rs | 5 ++++- lib/src/lib.rs | 10 ++++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index d97746429..8b2e44ca8 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -2,6 +2,8 @@ set -xeo pipefail +export IN_CONTAINER=1 + GRAMINE_PRIV_KEY="$HOME/.config/gramine/enclave-key.pem" RAIKO_DOCKER_VOLUME_PATH="/root/.config/raiko" RAIKO_DOCKER_VOLUME_CONFIG_PATH="$RAIKO_DOCKER_VOLUME_PATH/config" @@ -46,17 +48,17 @@ function update_docker_chain_specs() { fi if [ -n "${HOLESKY_RPC}" ]; then - jq --arg rpc "$HOLESKY_RPC" 'map(if .name == "holesky" then .rpc = $rpc else . end)' $CONFIG_FILE > /tmp/config_tmp.json && mv /tmp/config_tmp.json $CONFIG_FILE; + jq --arg rpc "$HOLESKY_RPC" 'map(if .name == "holesky" then .rpc = $rpc else . end)' $CONFIG_FILE >/tmp/config_tmp.json && mv /tmp/config_tmp.json $CONFIG_FILE echo "Updated config.json with .rpc=$HOLESKY_RPC" fi if [ -n "${HOLESKY_BEACON_RPC}" ]; then - jq --arg beacon_rpc "$HOLESKY_BEACON_RPC" 'map(if .name == "holesky" then .beacon_rpc = $beacon_rpc else . end)' $CONFIG_FILE > /tmp/config_tmp.json && mv /tmp/config_tmp.json $CONFIG_FILE; + jq --arg beacon_rpc "$HOLESKY_BEACON_RPC" 'map(if .name == "holesky" then .beacon_rpc = $beacon_rpc else . end)' $CONFIG_FILE >/tmp/config_tmp.json && mv /tmp/config_tmp.json $CONFIG_FILE echo "Updated config.json with .beacon_rpc=$HOLESKY_BEACON_RPC" fi if [ -n "${TAIKO_A7_RPC}" ]; then - jq --arg taiko_a7_rpc "$TAIKO_A7_RPC" 'map(if .name == "taiko_a7" then .rpc = $taiko_a7_rpc else . end)' $CONFIG_FILE > /tmp/config_tmp.json && mv /tmp/config_tmp.json $CONFIG_FILE; + jq --arg taiko_a7_rpc "$TAIKO_A7_RPC" 'map(if .name == "taiko_a7" then .rpc = $taiko_a7_rpc else . end)' $CONFIG_FILE >/tmp/config_tmp.json && mv /tmp/config_tmp.json $CONFIG_FILE echo "Updated config.json with .taiko_a7_rpc=$TAIKO_A7_RPC" fi } @@ -80,8 +82,8 @@ elif [[ $# -eq 1 && $1 == "--init-self-register" ]]; then else echo "start proving" if [[ ! -f "$RAIKO_DOCKER_VOLUME_PRIV_KEY_PATH" ]]; then - echo "Application was not bootstrapped. "\ - "$RAIKO_DOCKER_VOLUME_PRIV_KEY_PATH is missing. Bootstrap it first." >&2 + echo "Application was not bootstrapped. " \ + "$RAIKO_DOCKER_VOLUME_PRIV_KEY_PATH is missing. Bootstrap it first." >&2 exit 1 fi diff --git a/lib/src/consts.rs b/lib/src/consts.rs index 7ef7373ae..e8f1ccbec 100644 --- a/lib/src/consts.rs +++ b/lib/src/consts.rs @@ -27,8 +27,9 @@ use serde_json::Value; #[cfg(not(feature = "std"))] use crate::no_std::*; -use std::collections::HashMap; +use once_cell::sync::Lazy; use std::path::PathBuf; +use std::{collections::HashMap, env::var}; /// U256 representation of 0. pub const ZERO: U256 = U256::ZERO; @@ -46,6 +47,8 @@ pub const GWEI_TO_WEI: U256 = uint!(1_000_000_000_U256); const DEFAULT_CHAIN_SPECS: &str = include_str!("../../host/config/chain_spec_list_default.json"); +pub static IN_CONTAINER: Lazy> = Lazy::new(|| var("IN_CONTAINER").ok().map(|_| ())); + #[derive(Clone, Debug)] pub struct SupportedChainSpecs(HashMap); diff --git a/lib/src/lib.rs b/lib/src/lib.rs index ce9637c80..719114973 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -134,13 +134,19 @@ pub fn print_duration(title: &str, duration: time::Duration) { } pub fn inplace_print(title: &str) { - print!("\r{title}"); + if consts::IN_CONTAINER.is_some() { + return; + } + print!("\r\n{title}"); #[cfg(all(feature = "std", debug_assertions))] io::stdout().flush().unwrap(); } pub fn clear_line() { - print!("\r\x1B[2K"); + if consts::IN_CONTAINER.is_some() { + return; + } + print!("\r\n\x1B[2K"); } /// call forget only if running inside the guest