Skip to content

Commit 0a93d47

Browse files
authored
wormhole-attester: port the v1.3.0 healthcheck hotfix (#454)
* wormhole-attester: port the v1.3.0 healthcheck hotfix This PR fixes a missing assignment to HealthCheckState's enable flag. This would cause the attester to ignore all settings (including defaults) and keep the enable flag set to false because we would never bother setting it from attestation_cfg that came at runtime. The bug is fixed and the healthcheck behavior is hardened. Currently, the lazy_static block will explicitly initialize the global with default values from attestation_cfg (enable is true, window size is 100). This prevents a similar human error from disabling the healthcheck. Secondly, main.rs overwrites the default values using the HealthCheckState::new() constructor, instead of individual struct member assignments. This ensures that all necessary values or their defaults are passed as the desired healthcheck state. * p2w_autoattest.py: Get debug output from first attestation * wormhole-attester: fix ()-less function bug, harden usize convertion This change fixes a bug that would cause a gigantic allocation to happen, after the attestation_cfg::default_healthcheck_window_size function is taken without being called and converted to a very large usize value. This would result in a big allocation which would crash the attester. At the core it's a misunderstanding about "Fn() as usize" conversion which unfortunately is safe Rust. * Trigger build * wormhole-attester: Fix a misuse of a mutex guard This commit changes the `let hc = <lock the mutex>` into a direct assignment to the locked mutex guard. Rust mutices are typically scope-based which makes using them in variables more error prone. * Dockerfile.client: Remove unused ADD wormhole-attester. This speeds up the build of the container, and prevents useless triggers from the attester codebase * p2w_autoattest.py: simplify log filtering to just info
1 parent 01c4661 commit 0a93d47

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

third_party/pyth/p2w_autoattest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166

167167
# Set helpfully chatty logging default, filtering especially annoying
168168
# modules like async HTTP requests and tokio runtime logs
169-
os.environ["RUST_LOG"] = os.environ.get("RUST_LOG", "pyth_wormhole_attester_client,solana_client,main,pyth_sdk_solana=trace")
169+
os.environ["RUST_LOG"] = os.environ.get("RUST_LOG", "info")
170170

171171
# Send the first attestation in one-shot mode for testing
172172
first_attest_result = run_or_die(
@@ -187,6 +187,7 @@
187187
P2W_RPC_TIMEOUT_SECS,
188188
],
189189
capture_output=True,
190+
debug = True,
190191
)
191192

192193
logging.info("p2w_autoattest ready to roll!")

tilt-devnet/docker-images/Dockerfile.client

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ RUN apt-get update && apt-get install -yq libudev-dev ncat
99
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs
1010

1111
ADD rust-toolchain /rust-toolchain
12-
ADD wormhole-attester/ /usr/src/wormhole-attester
13-
WORKDIR /usr/src/wormhole-attester
12+
WORKDIR /usr/src/bridge-client
1413

1514
RUN --mount=type=cache,target=/root/.cache \
16-
--mount=type=cache,target=/usr/local/cargo/registry,id=cargo_registry \
17-
--mount=type=cache,target=/usr/src/solana/pyth2wormhole/target,id=p2w_cargo_build \
15+
--mount=type=cache,target=/usr/local/cargo/registry \
16+
--mount=type=cache,target=target \
1817
cargo install --version =2.0.12 --locked spl-token-cli --target-dir target
1918

2019

@@ -26,7 +25,7 @@ ENV BRIDGE_ADDRESS="Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o"
2625

2726
RUN --mount=type=cache,target=/root/.cache \
2827
--mount=type=cache,target=/usr/local/cargo/registry \
29-
--mount=type=cache,target=/usr/src/solana/pyth2wormhole/target \
28+
--mount=type=cache,target=target \
3029
set -xe && \
3130
cargo install bridge_client --git https://github.com/wormhole-foundation/wormhole --tag $WORMHOLE_TAG --locked --root /usr/local --target-dir target && \
3231
cargo install token_bridge_client --git https://github.com/wormhole-foundation/wormhole --tag $WORMHOLE_TAG --locked --root /usr/local --target-dir target

wormhole-attester/client/src/healthcheck.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
use {
2+
crate::attestation_cfg,
23
std::{
34
collections::VecDeque,
5+
convert::TryInto,
46
sync::Arc,
57
},
68
tokio::sync::Mutex,
79
};
810

911
lazy_static::lazy_static! {
10-
pub static ref HEALTHCHECK_STATE: Arc<Mutex<HealthCheckState>> = Arc::new(Mutex::new(HealthCheckState::new(1, false)));
12+
pub static ref HEALTHCHECK_STATE: Arc<Mutex<HealthCheckState>> = Arc::new(Mutex::new(HealthCheckState::new(attestation_cfg::default_healthcheck_window_size().try_into().expect("could not convert window size to usize"), attestation_cfg::default_enable_healthcheck())));
1113
}
1214

1315
/// Helper structure for deciding service health

wormhole-attester/client/src/main.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use {
4141
gen_set_config_tx,
4242
gen_set_is_active_tx,
4343
get_config_account,
44+
healthcheck::HealthCheckState,
4445
start_metrics_server,
4546
AttestationConfig,
4647
BatchState,
@@ -304,17 +305,20 @@ async fn handle_attest_daemon_mode(
304305
metrics_bind_addr: SocketAddr,
305306
) -> Result<(), ErrBox> {
306307
// Update healthcheck window size from config
307-
if attestation_cfg.enable_healthcheck {
308-
if attestation_cfg.healthcheck_window_size == 0 {
309-
return Err(format!(
310-
"{} must be above 0",
311-
stringify!(attestation_cfg.healthcheck_window_size)
312-
)
313-
.into());
314-
}
315-
let mut hc = HEALTHCHECK_STATE.lock().await;
316-
hc.max_window_size = attestation_cfg.healthcheck_window_size as usize;
317-
} else {
308+
if attestation_cfg.healthcheck_window_size == 0 {
309+
return Err(format!(
310+
"{} must be above 0",
311+
stringify!(attestation_cfg.healthcheck_window_size)
312+
)
313+
.into());
314+
}
315+
316+
*HEALTHCHECK_STATE.lock().await = HealthCheckState::new(
317+
attestation_cfg.healthcheck_window_size as usize,
318+
attestation_cfg.enable_healthcheck,
319+
);
320+
321+
if !attestation_cfg.enable_healthcheck {
318322
warn!("WARNING: Healthcheck is disabled");
319323
}
320324

0 commit comments

Comments
 (0)