Skip to content

Commit

Permalink
Drozdziak1/p2w client error logging and docker caching (#268)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Stanisław Drozd authored Sep 5, 2022
1 parent 5c48dac commit aa7be4d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
7 changes: 4 additions & 3 deletions Dockerfile.client
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
29 changes: 13 additions & 16 deletions solana/pyth2wormhole/client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
});
Expand Down Expand Up @@ -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();
}
}
16 changes: 12 additions & 4 deletions third_party/pyth/Dockerfile.p2w-attest
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit aa7be4d

Please sign in to comment.