Skip to content

Commit

Permalink
provide trace information
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperFluffy committed Oct 24, 2024
1 parent f3c6c9f commit 998434f
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions crates/core/component/ibc/src/component/rpc/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(
storage: Storage,
request: &tonic::Request<T>,
) -> anyhow::Result<Snapshot> {
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
Expand Down

0 comments on commit 998434f

Please sign in to comment.