From 80ddb7239a40e23fb174e021e7892fe62b267c36 Mon Sep 17 00:00:00 2001 From: Jeb Bearer Date: Thu, 2 May 2024 16:01:56 -0400 Subject: [PATCH] Expose synced merklized state height This is really useful to have for debugging --- api/state.toml | 13 ++++++++++--- src/merklized_state.rs | 6 +++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/api/state.toml b/api/state.toml index 8fb1fae3a..9528dcd41 100644 --- a/api/state.toml +++ b/api/state.toml @@ -14,7 +14,7 @@ FORMAT_VERSION = "0.1.0" NAME = "hotshot-state" DESCRIPTION = """ -Query snapshot of merklized state. +Query snapshot of merklized state. The state API provides an interface for serving queries against arbitrarily old snapshots of the state. This allows a full Merkle tree to be reconstructed from storage. However, if any parent state is missing then the partial snapshot can not be queried. """ @@ -27,7 +27,7 @@ PATH = ["/:height/:key", "commit/:commit/:key"] DOC = """ The endpoint offers two methods to query: by block height or by the tree's commitment. -GET /:height/:key +GET /:height/:key Retrieves the Merkle Path for the membership proof of a leaf based on the block height and entry index. Parameters: :height : The block height of the snapshot. @@ -41,4 +41,11 @@ Parameters: :key : The index of the entry in the Merkle tree. """ - \ No newline at end of file +[route.get_height] +PATH = ["/block-height"] +DOC = """ +The latest block height for which the merklized state is available. + +Note that this may be less than the block height indicated by other APIs, such as `status` or +`node`, since the merklized state storage is updated asynchronously. +""" diff --git a/src/merklized_state.rs b/src/merklized_state.rs index 5c6359fed..5e0df4961 100644 --- a/src/merklized_state.rs +++ b/src/merklized_state.rs @@ -89,7 +89,8 @@ pub fn define_api< ) -> Result, ApiError> where State: 'static + Send + Sync + ReadState, - ::State: Send + Sync + MerklizedStateDataSource, + ::State: + Send + Sync + MerklizedStateDataSource + MerklizedStateHeightPersistence, Types: NodeType, for<'a> >::Error: Display, { @@ -118,6 +119,9 @@ where state.get_path(snapshot, key).await.context(QuerySnafu) } .boxed() + })? + .get("get_height", move |_, state| { + async move { state.get_last_state_height().await.context(QuerySnafu) }.boxed() })?; Ok(api)