Skip to content

Commit

Permalink
Merge pull request #558 from EspressoSystems/jb/validated-state-height
Browse files Browse the repository at this point in the history
Expose synced merklized state height
  • Loading branch information
jbearer authored May 2, 2024
2 parents 13a0297 + 80ddb72 commit 046c60e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 10 additions & 3 deletions api/state.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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.
Expand All @@ -41,4 +41,11 @@ Parameters:
:key : The index of the entry in the Merkle tree.
"""


[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.
"""
6 changes: 5 additions & 1 deletion src/merklized_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ pub fn define_api<
) -> Result<Api<State, Error, Ver>, ApiError>
where
State: 'static + Send + Sync + ReadState,
<State as ReadState>::State: Send + Sync + MerklizedStateDataSource<Types, M, ARITY>,
<State as ReadState>::State:
Send + Sync + MerklizedStateDataSource<Types, M, ARITY> + MerklizedStateHeightPersistence,
Types: NodeType,
for<'a> <M::Commit as TryFrom<&'a TaggedBase64>>::Error: Display,
{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 046c60e

Please sign in to comment.