Skip to content

Commit

Permalink
[Storage] Add functions to read proof by key and version. (aptos-labs…
Browse files Browse the repository at this point in the history
  • Loading branch information
grao1991 authored Jul 6, 2022
1 parent 7899dca commit 110bfde
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions storage/aptosdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,25 @@ impl DbReader for AptosDB {
})
}

/// Returns the proof of the given state key and version.
fn get_state_proof_by_version(
&self,
state_key: &StateKey,
version: Version,
) -> Result<SparseMerkleProof> {
gauged_api("get_proof_by_version", || {
error_if_version_is_pruned(
&self.pruner,
PrunerIndex::StateStorePrunerIndex,
"State",
version,
)?;

self.state_store
.get_state_proof_by_version(state_key, version)
})
}

fn get_startup_info(&self) -> Result<Option<StartupInfo>> {
gauged_api("get_startup_info", || {
self.ledger_store
Expand Down
10 changes: 10 additions & 0 deletions storage/aptosdb/src/state_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ impl DbReader for StateStore {
.transpose()
}

/// Returns the proof of the given state key and version.
fn get_state_proof_by_version(
&self,
state_key: &StateKey,
version: Version,
) -> Result<SparseMerkleProof> {
let (_, proof) = self.state_merkle_db.get_with_proof(state_key, version)?;
Ok(proof)
}

/// Get the state value with proof given the state key and version
fn get_state_value_with_proof_by_version(
&self,
Expand Down
9 changes: 9 additions & 0 deletions storage/storage-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,15 @@ pub trait DbReader: Send + Sync {
unimplemented!()
}

/// Returns the proof of the given state key and version.
fn get_state_proof_by_version(
&self,
state_key: &StateKey,
version: Version,
) -> Result<SparseMerkleProof> {
unimplemented!()
}

/// Gets a state value by state key along with the proof, out of the ledger state indicated by the state
/// Merkle tree root with a sparse merkle proof proving state tree root.
/// See [AptosDB::get_account_state_with_proof_by_version].
Expand Down

0 comments on commit 110bfde

Please sign in to comment.