Skip to content

Commit

Permalink
trivial: rename state_store_key -> state_key
Browse files Browse the repository at this point in the history
  • Loading branch information
msmouse authored and aptos-bot committed Apr 8, 2022
1 parent 636a2d8 commit 5b918ab
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 36 deletions.
4 changes: 2 additions & 2 deletions execution/executor-benchmark/src/transaction_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,12 @@ impl TransactionGenerator {
let bar = get_progress_bar(self.accounts_cache.len());
for account in &self.accounts_cache {
let address = account.address;
let state_store_value = db
let state_value = db
.get_latest_state_value(StateKey::AccountAddressKey(address))
.expect("Failed to query storage.")
.expect("Account must exist.");
let account_resource =
AccountResource::try_from(&AccountStateBlob::try_from(state_store_value).unwrap())
AccountResource::try_from(&AccountStateBlob::try_from(state_value).unwrap())
.unwrap();
assert_eq!(account_resource.sequence_number(), account.sequence_number);
bar.inc(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl StateSnapshotRestoreController {
ver_gauge.set(self.version as i64);
tgt_leaf_idx.set(manifest.chunks.last().map_or(0, |c| c.last_idx as i64));
for chunk in manifest.chunks {
let blobs = self.read_state_store_value(chunk.blobs).await?;
let blobs = self.read_state_value(chunk.blobs).await?;
let proof = self.storage.load_bcs_file(&chunk.proof).await?;

receiver.add_chunk(blobs, proof)?;
Expand All @@ -142,7 +142,7 @@ impl StateSnapshotRestoreController {
Ok(())
}

async fn read_state_store_value(
async fn read_state_value(
&self,
file_handle: FileHandle,
) -> Result<Vec<(HashValue, StateValue)>> {
Expand Down
17 changes: 7 additions & 10 deletions storage/storage-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ pub trait DbReader: Send + Sync {
///
/// [`AptosDB::get_latest_account_state`]:
/// ../aptosdb/struct.AptosDB.html#method.get_latest_account_state
fn get_latest_state_value(&self, state_store_key: StateKey) -> Result<Option<StateValue>> {
fn get_latest_state_value(&self, state_key: StateKey) -> Result<Option<StateValue>> {
unimplemented!()
}

Expand Down Expand Up @@ -407,7 +407,7 @@ pub trait DbReader: Send + Sync {
/// based on `ledger_version`
fn get_state_value_with_proof(
&self,
state_store_key: StateKey,
state_key: StateKey,
version: Version,
ledger_version: Version,
) -> Result<StateValueWithProof> {
Expand Down Expand Up @@ -523,12 +523,12 @@ impl MoveStorage for &dyn DbReader {
access_path: AccessPath,
version: Version,
) -> Result<Vec<u8>> {
let (state_store_value, _) = self.get_state_value_with_proof_by_version(
let (state_value, _) = self.get_state_value_with_proof_by_version(
&StateKey::AccountAddressKey(access_path.address),
version,
)?;
let account_state =
AccountState::try_from(&state_store_value.ok_or_else(|| {
AccountState::try_from(&state_value.ok_or_else(|| {
format_err!("missing blob in account state/account does not exist")
})?)?;

Expand Down Expand Up @@ -678,19 +678,16 @@ pub enum StorageRequest {
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
pub struct GetStateValueWithProofByVersionRequest {
/// The access key for the resource
pub state_store_key: StateKey,
pub state_key: StateKey,

/// The version the query is based on.
pub version: Version,
}

impl GetStateValueWithProofByVersionRequest {
/// Constructor.
pub fn new(state_store_key: StateKey, version: Version) -> Self {
Self {
state_store_key,
version,
}
pub fn new(state_key: StateKey, version: Version) -> Self {
Self { state_key, version }
}
}

Expand Down
18 changes: 9 additions & 9 deletions storage/storage-interface/src/verified_state_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ impl VerifiedStateView {
return Ok(contents.get(path).cloned());
}

let state_store_value_option =
let state_value_option =
self.get_state_value_internal(&StateKey::AccountAddressKey(address))?;

// Hack: Convert the state store value to account blob option as that is the
// only type of state value we support for now. This needs to change once we start
// supporting tables and other fine grained resources.
let new_account_blob = state_store_value_option
let new_account_blob = state_value_option
.map(AccountStateBlob::try_from)
.transpose()?
.as_ref()
Expand All @@ -164,13 +164,13 @@ impl VerifiedStateView {
fn get_state_value_internal(&self, state_key: &StateKey) -> Result<Option<StateValue>> {
// Do most of the work outside the write lock.
let key_hash = state_key.hash();
let state_store_value_option = match self.speculative_state.get(key_hash) {
let state_value_option = match self.speculative_state.get(key_hash) {
StateStoreStatus::ExistsInScratchPad(blob) => Some(blob),
StateStoreStatus::DoesNotExist => None,
// No matter it is in db or unknown, we have to query from db since even the
// former case, we don't have the blob data but only its hash.
StateStoreStatus::ExistsInDB | StateStoreStatus::Unknown => {
let (state_store_value, proof) = match self.latest_persistent_version {
let (state_value, proof) = match self.latest_persistent_version {
Some(version) => self
.reader
.get_state_value_with_proof_by_version(state_key, version)?,
Expand All @@ -180,7 +180,7 @@ impl VerifiedStateView {
.verify(
self.latest_persistent_state_root,
key_hash,
state_store_value.as_ref(),
state_value.as_ref(),
)
.map_err(|err| {
format_err!(
Expand All @@ -194,11 +194,11 @@ impl VerifiedStateView {
// multiple threads may enter this code, and another thread might add
// an address before this one. Thus the insertion might return a None here.
self.state_proof_cache.write().insert(key_hash, proof);
state_store_value
state_value
}
};

Ok(state_store_value_option)
Ok(state_value_option)
}

fn get_and_cache_state_value(&self, state_key: &StateKey) -> Result<Option<Vec<u8>>> {
Expand All @@ -207,12 +207,12 @@ impl VerifiedStateView {
// This can return None, which means the value has been deleted from the DB.
return Ok(contents.maybe_bytes.as_ref().cloned());
}
let state_store_value_option = self.get_state_value_internal(state_key)?;
let state_value_option = self.get_state_value_internal(state_key)?;
// Update the cache if still empty
let mut cache = self.state_cache.write();
let new_value = cache
.entry(state_key.clone())
.or_insert_with(|| state_store_value_option.unwrap_or_default());
.or_insert_with(|| state_value_option.unwrap_or_default());

Ok(new_value.maybe_bytes.as_ref().cloned())
}
Expand Down
2 changes: 1 addition & 1 deletion storage/storage-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl StorageService {
) -> Result<(Option<StateValue>, SparseMerkleProof<StateValue>), Error> {
Ok(self
.db
.get_state_value_with_proof_by_version(&req.state_store_key, req.version)?)
.get_state_value_with_proof_by_version(&req.state_key, req.version)?)
}

fn get_startup_info(&self) -> Result<Option<StartupInfo>, Error> {
Expand Down
4 changes: 2 additions & 2 deletions types/src/account_state_blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ impl TryFrom<&AccountState> for AccountStateBlob {
impl TryFrom<StateValue> for AccountStateBlob {
type Error = Error;

fn try_from(state_store_value: StateValue) -> Result<Self> {
let bytes = state_store_value
fn try_from(state_value: StateValue) -> Result<Self> {
let bytes = state_value
.maybe_bytes
.ok_or_else(|| format_err!("Empty state value passed"))?;
Ok(AccountStateBlob::from(bytes))
Expand Down
4 changes: 2 additions & 2 deletions types/src/proof/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,14 +750,14 @@ impl StateStoreValueProof {
ledger_info: &LedgerInfo,
state_version: Version,
value_hash: HashValue,
state_store_value: Option<&StateValue>,
state_value: Option<&StateValue>,
) -> Result<()> {
self.transaction_info_to_value_proof.verify(
self.transaction_info_with_proof
.transaction_info
.state_change_hash(),
value_hash,
state_store_value,
state_value,
)?;

self.transaction_info_with_proof
Expand Down
12 changes: 4 additions & 8 deletions types/src/state_store/state_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ impl StateValueWithProof {
///
/// Two things are ensured if no error is raised:
/// 1. This value exists in the ledger represented by `ledger_info`.
/// 2. It belongs to state_store_key and is seen at the time the transaction at version
/// 2. It belongs to state_key and is seen at the time the transaction at version
/// `state_version` is just committed. To make sure this is the latest state, pass in
/// `ledger_info.version()` as `state_version`.
pub fn verify(
&self,
ledger_info: &LedgerInfo,
version: Version,
state_store_key: StateKey,
state_key: StateKey,
) -> anyhow::Result<()> {
ensure!(
self.version == version,
Expand All @@ -143,12 +143,8 @@ impl StateValueWithProof {
version,
);

self.proof.verify(
ledger_info,
version,
state_store_key.hash(),
self.value.as_ref(),
)
self.proof
.verify(ledger_info, version, state_key.hash(), self.value.as_ref())
}
}

Expand Down

0 comments on commit 5b918ab

Please sign in to comment.