From aa7be4d1bec8cbac16b75babd28c1a9656d49afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Drozd?= Date: Mon, 5 Sep 2022 17:00:24 +0200 Subject: [PATCH] Drozdziak1/p2w client error logging and docker caching (#268) * p2w-client: Fix silent logs, restore program log printing For some time now, p2w-client error reporting would fail to show daemon mode errors. The logs would only mention resends without ever showing failed attempts. with solana-program 1.10.31 came a newer, inferior program log reporting which only says "N program logs" instead of saying what they are. This changeset prints errors verbatim using formatted debug "{:#?}" syntax. * Docker: Improve p2w-attest/solana-devnet caching This commit speeds up caching in two ways: 1. By severing the dependency on bridge-client in Dockerfile.p2w-attest - mainly because of unnecessary `cargo install` builds which even with target dir caching can take ~1 minute. The bridge/token-bridge client binaries are not useful to p2w-client anyway. 2. By attaching cargo-install commands to a target dir cache via the --target-dir option in cargo --- Dockerfile.client | 7 +++--- solana/pyth2wormhole/client/src/main.rs | 29 +++++++++++-------------- third_party/pyth/Dockerfile.p2w-attest | 16 ++++++++++---- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/Dockerfile.client b/Dockerfile.client index 977d0a524d..838e26ad6a 100644 --- a/Dockerfile.client +++ b/Dockerfile.client @@ -12,7 +12,8 @@ COPY solana /usr/src/solana WORKDIR /usr/src/solana/pyth2wormhole RUN --mount=type=cache,target=/root/.cache \ - cargo install --version =2.0.12 --locked spl-token-cli + --mount=type=cache,target=target \ + cargo install --version =2.0.12 --locked spl-token-cli --target-dir target RUN solana config set --keypair "/usr/src/solana/keys/solana-devnet.json" @@ -25,5 +26,5 @@ RUN --mount=type=cache,target=/root/.cache \ --mount=type=cache,target=/usr/local/cargo/registry,id=cargo_registry \ --mount=type=cache,target=target,id=cargo_registry \ set -xe && \ - cargo install bridge_client --git https://github.com/wormhole-foundation/wormhole --tag $WORMHOLE_TAG --locked --root /usr/local && \ - cargo install token_bridge_client --git https://github.com/wormhole-foundation/wormhole --tag $WORMHOLE_TAG --locked --root /usr/local + cargo install bridge_client --git https://github.com/wormhole-foundation/wormhole --tag $WORMHOLE_TAG --locked --root /usr/local --target-dir target && \ + cargo install token_bridge_client --git https://github.com/wormhole-foundation/wormhole --tag $WORMHOLE_TAG --locked --root /usr/local --target-dir target diff --git a/solana/pyth2wormhole/client/src/main.rs b/solana/pyth2wormhole/client/src/main.rs index 59e66e96fb..857371b08b 100644 --- a/solana/pyth2wormhole/client/src/main.rs +++ b/solana/pyth2wormhole/client/src/main.rs @@ -70,7 +70,7 @@ pub const SEQNO_PREFIX: &'static str = "Program log: Sequence: "; #[tokio::main] async fn main() -> Result<(), ErrBox> { let cli = Cli::parse(); - init_logging(cli.log_level); + init_logging(); // All other CLI actions make rpc requests, this one's meant to be // off-chain explicitly @@ -295,7 +295,8 @@ async fn handle_attest( // join_all. We filter out errors and report them let errors: Vec<_> = results .iter() - .filter_map(|r| r.as_ref().err().map(|e| e.to_string())) + .enumerate() + .filter_map(|(idx, r)| r.as_ref().err().map(|e| format!("Error {}: {:#?}\n", idx + 1, e))) .collect(); if !errors.is_empty() { @@ -415,13 +416,13 @@ async fn attestation_sched_job( let group_name4err_msg = batch.group_name.clone(); // We never get to error reporting in daemon mode, attach a map_err - let job_with_err_msg = job.map_err(move |e| async move { + let job_with_err_msg = job.map_err(move |e| { warn!( - "Batch {}/{}, group {:?} ERR: {}", + "Batch {}/{}, group {:?} ERR: {:#?}", batch_no4err_msg, batch_count4err_msg, group_name4err_msg, - e.to_string() + e ); e }); @@ -533,15 +534,11 @@ async fn attestation_job( Result::<(), ErrBoxSend>::Ok(()) } -fn init_logging(verbosity: u32) { - use LevelFilter::*; - let filter = match verbosity { - 0..=1 => Error, - 2 => Warn, - 3 => Info, - 4 => Debug, - _other => Trace, - }; - - env_logger::builder().filter_level(filter).init(); +fn init_logging() { + if std::env::var("RUST_LOG").is_ok() { + env_logger::init() + } else { + // Default to info if RUST_LOG not set + env_logger::builder().filter_level(LevelFilter::Info).init(); + } } diff --git a/third_party/pyth/Dockerfile.p2w-attest b/third_party/pyth/Dockerfile.p2w-attest index 6fff7a4a99..14397469c9 100644 --- a/third_party/pyth/Dockerfile.p2w-attest +++ b/third_party/pyth/Dockerfile.p2w-attest @@ -1,16 +1,24 @@ -FROM bridge-client +#syntax=docker/dockerfile:1.2@sha256:e2a8561e419ab1ba6b2fe6cbdf49fd92b95912df1cf7d313c3e2230a333fdbcc +FROM ghcr.io/certusone/solana:1.10.31@sha256:d31e8db926a1d3fbaa9d9211d9979023692614b7b64912651aba0383e8c01bad AS solana -RUN apt-get install -y python3 +RUN apt-get update && apt-get install -yq python3 libudev-dev ncat +RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs ADD third_party/pyth/pyth_utils.py /usr/src/pyth/pyth_utils.py ADD third_party/pyth/p2w_autoattest.py /usr/src/pyth/p2w_autoattest.py ADD third_party/pyth/p2w-sdk/rust /usr/src/third_party/pyth/p2w-sdk/rust +ADD solana /usr/src/solana + +WORKDIR /usr/src/solana/pyth2wormhole + +ENV EMITTER_ADDRESS="11111111111111111111111111111115" +ENV BRIDGE_ADDRESS="Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o" + RUN --mount=type=cache,target=/root/.cache \ --mount=type=cache,target=target \ - --mount=type=cache,target=pyth2wormhole/target \ - cargo build --package pyth2wormhole-client && \ cargo test --package pyth2wormhole-client && \ + cargo build --package pyth2wormhole-client && \ mv target/debug/pyth2wormhole-client /usr/local/bin/pyth2wormhole-client && \ chmod a+rx /usr/src/pyth/*.py