Skip to content

Commit

Permalink
feat: disable inplace print in container env
Browse files Browse the repository at this point in the history
  • Loading branch information
johntaiko committed May 24, 2024
1 parent 6b3b701 commit f13e527
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
12 changes: 7 additions & 5 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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

Expand Down
11 changes: 10 additions & 1 deletion lib/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,6 +47,14 @@ 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<Option<()>> = Lazy::new(|| {
if var("IN_CONTAINER").is_ok() {
Some(())
} else {
None
}
});

#[derive(Clone, Debug)]
pub struct SupportedChainSpecs(HashMap<String, ChainSpec>);

Expand Down
10 changes: 8 additions & 2 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f13e527

Please sign in to comment.