Skip to content

Commit aa7be4d

Browse files
author
Stanisław Drozd
authored
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
1 parent 5c48dac commit aa7be4d

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

Dockerfile.client

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ COPY solana /usr/src/solana
1212
WORKDIR /usr/src/solana/pyth2wormhole
1313

1414
RUN --mount=type=cache,target=/root/.cache \
15-
cargo install --version =2.0.12 --locked spl-token-cli
15+
--mount=type=cache,target=target \
16+
cargo install --version =2.0.12 --locked spl-token-cli --target-dir target
1617

1718

1819
RUN solana config set --keypair "/usr/src/solana/keys/solana-devnet.json"
@@ -25,5 +26,5 @@ RUN --mount=type=cache,target=/root/.cache \
2526
--mount=type=cache,target=/usr/local/cargo/registry,id=cargo_registry \
2627
--mount=type=cache,target=target,id=cargo_registry \
2728
set -xe && \
28-
cargo install bridge_client --git https://github.com/wormhole-foundation/wormhole --tag $WORMHOLE_TAG --locked --root /usr/local && \
29-
cargo install token_bridge_client --git https://github.com/wormhole-foundation/wormhole --tag $WORMHOLE_TAG --locked --root /usr/local
29+
cargo install bridge_client --git https://github.com/wormhole-foundation/wormhole --tag $WORMHOLE_TAG --locked --root /usr/local --target-dir target && \
30+
cargo install token_bridge_client --git https://github.com/wormhole-foundation/wormhole --tag $WORMHOLE_TAG --locked --root /usr/local --target-dir target

solana/pyth2wormhole/client/src/main.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub const SEQNO_PREFIX: &'static str = "Program log: Sequence: ";
7070
#[tokio::main]
7171
async fn main() -> Result<(), ErrBox> {
7272
let cli = Cli::parse();
73-
init_logging(cli.log_level);
73+
init_logging();
7474

7575
// All other CLI actions make rpc requests, this one's meant to be
7676
// off-chain explicitly
@@ -295,7 +295,8 @@ async fn handle_attest(
295295
// join_all. We filter out errors and report them
296296
let errors: Vec<_> = results
297297
.iter()
298-
.filter_map(|r| r.as_ref().err().map(|e| e.to_string()))
298+
.enumerate()
299+
.filter_map(|(idx, r)| r.as_ref().err().map(|e| format!("Error {}: {:#?}\n", idx + 1, e)))
299300
.collect();
300301

301302
if !errors.is_empty() {
@@ -415,13 +416,13 @@ async fn attestation_sched_job(
415416
let group_name4err_msg = batch.group_name.clone();
416417

417418
// We never get to error reporting in daemon mode, attach a map_err
418-
let job_with_err_msg = job.map_err(move |e| async move {
419+
let job_with_err_msg = job.map_err(move |e| {
419420
warn!(
420-
"Batch {}/{}, group {:?} ERR: {}",
421+
"Batch {}/{}, group {:?} ERR: {:#?}",
421422
batch_no4err_msg,
422423
batch_count4err_msg,
423424
group_name4err_msg,
424-
e.to_string()
425+
e
425426
);
426427
e
427428
});
@@ -533,15 +534,11 @@ async fn attestation_job(
533534
Result::<(), ErrBoxSend>::Ok(())
534535
}
535536

536-
fn init_logging(verbosity: u32) {
537-
use LevelFilter::*;
538-
let filter = match verbosity {
539-
0..=1 => Error,
540-
2 => Warn,
541-
3 => Info,
542-
4 => Debug,
543-
_other => Trace,
544-
};
545-
546-
env_logger::builder().filter_level(filter).init();
537+
fn init_logging() {
538+
if std::env::var("RUST_LOG").is_ok() {
539+
env_logger::init()
540+
} else {
541+
// Default to info if RUST_LOG not set
542+
env_logger::builder().filter_level(LevelFilter::Info).init();
543+
}
547544
}

third_party/pyth/Dockerfile.p2w-attest

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
FROM bridge-client
1+
#syntax=docker/dockerfile:1.2@sha256:e2a8561e419ab1ba6b2fe6cbdf49fd92b95912df1cf7d313c3e2230a333fdbcc
2+
FROM ghcr.io/certusone/solana:1.10.31@sha256:d31e8db926a1d3fbaa9d9211d9979023692614b7b64912651aba0383e8c01bad AS solana
23

3-
RUN apt-get install -y python3
4+
RUN apt-get update && apt-get install -yq python3 libudev-dev ncat
5+
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs
46

57
ADD third_party/pyth/pyth_utils.py /usr/src/pyth/pyth_utils.py
68
ADD third_party/pyth/p2w_autoattest.py /usr/src/pyth/p2w_autoattest.py
79
ADD third_party/pyth/p2w-sdk/rust /usr/src/third_party/pyth/p2w-sdk/rust
810

11+
ADD solana /usr/src/solana
12+
13+
WORKDIR /usr/src/solana/pyth2wormhole
14+
15+
ENV EMITTER_ADDRESS="11111111111111111111111111111115"
16+
ENV BRIDGE_ADDRESS="Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o"
17+
918
RUN --mount=type=cache,target=/root/.cache \
1019
--mount=type=cache,target=target \
11-
--mount=type=cache,target=pyth2wormhole/target \
12-
cargo build --package pyth2wormhole-client && \
1320
cargo test --package pyth2wormhole-client && \
21+
cargo build --package pyth2wormhole-client && \
1422
mv target/debug/pyth2wormhole-client /usr/local/bin/pyth2wormhole-client && \
1523
chmod a+rx /usr/src/pyth/*.py
1624

0 commit comments

Comments
 (0)