From 998434fce8c1d7ad36b1420bce195f0a62f70c1b Mon Sep 17 00:00:00 2001 From: Richard Janis Goldschmidt Date: Thu, 24 Oct 2024 14:59:17 +0200 Subject: [PATCH] provide trace information --- .../component/ibc/src/component/rpc/utils.rs | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/crates/core/component/ibc/src/component/rpc/utils.rs b/crates/core/component/ibc/src/component/rpc/utils.rs index 5bb78f0fad..e69aa39762 100644 --- a/crates/core/component/ibc/src/component/rpc/utils.rs +++ b/crates/core/component/ibc/src/component/rpc/utils.rs @@ -5,36 +5,32 @@ use anyhow::Context as _; use cnidarium::Snapshot; use cnidarium::Storage; use ibc_proto::ibc::core::client::v1::Height; +use tracing::debug; +use tracing::instrument; +#[instrument(skip_all, level = "debug")] pub(in crate::component::rpc) fn determine_snapshot_from_height_header( storage: Storage, request: &tonic::Request, ) -> anyhow::Result { - let height_entry = request - .metadata() - .get("height") - .context("no `height` header")? - .to_str() - .context("value of `height` header was not ASCII")?; - - 'state: { - let height = match parse_as_ibc_height(height_entry) - .context("failed to parse value as IBC height") - { - Err(err) => break 'state Err(err), - Ok(height) => height.revision_height, - }; - if height == 0 { - Ok(storage.latest_snapshot()) - } else { - storage - .snapshot(height) - .with_context(|| format!("could not open snapshot at revision height `{height}`")) + let height = match request.metadata().get("height") { + None => { + debug!("height header was missing; assuming a height of 0"); + TheHeight::zero().into_inner() } + Some(entry) => entry + .to_str() + .context("height header was present but its entry was not ASCII") + .and_then(parse_as_ibc_height) + .context("failed to height header as IBC height")?, + }; + if height.revision_height == 0 { + Ok(storage.latest_snapshot()) + } else { + storage + .snapshot(height.revision_height) + .context("failed to create state snapshot from IBC height in height header") } - .with_context(|| { - format!("failed determine snapshot from `\"height\": \"{height_entry}` header") - }) } /// Utility to implement