Skip to content

Commit

Permalink
[Storage] Make generic state store key
Browse files Browse the repository at this point in the history
  • Loading branch information
sitalkedia authored and aptos-bot committed Mar 29, 2022
1 parent 498b750 commit 90646f5
Show file tree
Hide file tree
Showing 78 changed files with 942 additions and 705 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"type": "genesis_transaction",
"version": "0",
"hash": "0xf2ff7607724ce4c11b8c84c19db7db1d2cf1337409cabf15a55e0a88031596fc",
"state_root_hash": "0x526a17b0dbab0da1a2151242dbb2109a5bdd752ee68955d51559e5974a24976f",
"state_root_hash": "0xbded72ac28e7a9a6a8847793ca40a86dc6f821beac6556f3613fb9dea6d54fe2",
"event_root_hash": "0xdc52e4d65bc1d4bcc915eddd4afe5210466932431da4ca1e2f6076f24ff334c9",
"gas_used": "0",
"success": true,
"vm_status": "Executed successfully",
"accumulator_root_hash": "0x5c6d54910d44afb2675d2659c0fc3091207c097eb826f027218cf0770c4bb81d",
"accumulator_root_hash": "0xc879488b594f9dc6a4b1c3a6313df360926bd890b6e795b77d962200e39f152a",
"payload": {
"type": "write_set_payload",
"write_set": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"type": "block_metadata_transaction",
"version": "1",
"hash": "0x4713d577c835382e6b2ccb496595f7af6476f7277389e0c9ab290288cadf20a8",
"state_root_hash": "0x1fa939c38fefd8b582aa3a3a906d6a8e6a5dcbf93deae179de09eb8e15aed459",
"state_root_hash": "0x5fd7ca5c28e32ef0a87be656450302e5fdcb363de2af86882244bcb53e4b16a5",
"event_root_hash": "0xbf2bc789a83ba627b41caef795917152790ff6c97fe48606c23f7617e3b695c7",
"gas_used": "0",
"success": true,
"vm_status": "Executed successfully",
"accumulator_root_hash": "0x001907ebe6804388d5fcc00eb42db109ae56693575f79a723b85ddbbf2db9324",
"accumulator_root_hash": "0x20c312a26280d6ca9bf11e9f839ad222f295136642cf3304a71e4c1fff8b9527",
"id": "0xf44b581f23222c10916b17a369b4da039d075952b58036f2a7b561446592403c",
"round": "1",
"previous_block_votes": [],
Expand All @@ -19,12 +19,12 @@
"type": "user_transaction",
"version": "2",
"hash": "0xe5cfb5b362c05ff993d5104d157ae3108a5760d43eab7bbbb9dd0aa42d9945c6",
"state_root_hash": "0x198e58077611477b8ac68dc52c585c8d2c5f77e83cbc3a3a34ed4a5264459933",
"state_root_hash": "0x5da164a5c41b94c2821594174ad8dab4be229ede8b095b8befe761979394c372",
"event_root_hash": "0x414343554d554c41544f525f504c414345484f4c4445525f4841534800000000",
"gas_used": "412",
"success": true,
"vm_status": "Executed successfully",
"accumulator_root_hash": "0xaf04a1b40feb9fd14957d14ee10a41248f779ee41a07750ccb994c86cdca59a7",
"accumulator_root_hash": "0x5949b9b02b288e9d484aca33c2cbd37377a1ebcd68021ba9e0180a042c3ea7fc",
"sender": "0xa550c18",
"sequence_number": "0",
"max_gas_amount": "1000",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"type": "user_transaction",
"version": "2",
"hash": "0x4301a8ea114254a1694d265b0c66924bd97d04ed60a521bbbdfaa029ce277afb",
"state_root_hash": "0x7c5ec669fabe887e6a2a38fdbec6fe622e8a377d3020f99e2ae42519b7804c41",
"state_root_hash": "0x57bca4f1a7008c139699a2391570a289c4a0b317daf1639a67e08514953efc4a",
"event_root_hash": "0x414343554d554c41544f525f504c414345484f4c4445525f4841534800000000",
"gas_used": "1",
"success": false,
"vm_status": "Move bytecode deserialization / verification failed, including script function not found or invalid arguments",
"accumulator_root_hash": "0x114f6e6ca009af4bd5d0c9e98191195ca712c413889cd40c54aa7710fe83923d",
"accumulator_root_hash": "0xb4e338ba706af2dd1d171e14eddca4b64f1c4661d51ec270228e57d4bd9bbee4",
"sender": "0xa550c18",
"sequence_number": "0",
"max_gas_amount": "1000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"type": "user_transaction",
"version": "2",
"hash": "0xa76f6ca3c7bbb763e80dba0cb3f6d1d1ab5fe26502e185758bdd9df0f4831a60",
"state_root_hash": "0x7c5ec669fabe887e6a2a38fdbec6fe622e8a377d3020f99e2ae42519b7804c41",
"state_root_hash": "0x57bca4f1a7008c139699a2391570a289c4a0b317daf1639a67e08514953efc4a",
"event_root_hash": "0x414343554d554c41544f525f504c414345484f4c4445525f4841534800000000",
"gas_used": "1",
"success": false,
"vm_status": "Move bytecode deserialization / verification failed, including script function not found or invalid arguments",
"accumulator_root_hash": "0x0570271c3fb8d251afa6980ef7fe347cdab4a1c59a98ad4dacfa7f77a3ba21b8",
"accumulator_root_hash": "0xf88973af408a97ec09344f83919be544c9c298cfc548f6b187845e534b79f11d",
"sender": "0xa550c18",
"sequence_number": "0",
"max_gas_amount": "1000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"type": "user_transaction",
"version": "2",
"hash": "0xc83538832bd72205d12b9d3f727bb8023d233512d1f7f0a710fbdc59ae6e0d0c",
"state_root_hash": "0x7c5ec669fabe887e6a2a38fdbec6fe622e8a377d3020f99e2ae42519b7804c41",
"state_root_hash": "0x57bca4f1a7008c139699a2391570a289c4a0b317daf1639a67e08514953efc4a",
"event_root_hash": "0x414343554d554c41544f525f504c414345484f4c4445525f4841534800000000",
"gas_used": "1",
"success": false,
"vm_status": "Move bytecode deserialization / verification failed, including script function not found or invalid arguments",
"accumulator_root_hash": "0x77098e57f28f3af0131efbb1ab0bdca444ade5303489144172736341705feb6e",
"accumulator_root_hash": "0x72b9929b3c679708289a15fa70b052f01497b5d89a9fe65905df5a8961453b7d",
"sender": "0xa550c18",
"sequence_number": "0",
"max_gas_amount": "1000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"type": "user_transaction",
"version": "2",
"hash": "0x068b7171b72a144c0dda8460ab7c14b95308a33f6a1b71dff8076bbf63ede87c",
"state_root_hash": "0x7c5ec669fabe887e6a2a38fdbec6fe622e8a377d3020f99e2ae42519b7804c41",
"state_root_hash": "0x57bca4f1a7008c139699a2391570a289c4a0b317daf1639a67e08514953efc4a",
"event_root_hash": "0x414343554d554c41544f525f504c414345484f4c4445525f4841534800000000",
"gas_used": "1",
"success": false,
"vm_status": "Move bytecode deserialization / verification failed, including script function not found or invalid arguments",
"accumulator_root_hash": "0x1004a5c11780fa9df86daa1016638255b5b1b25daca9f8b434d083fb424a3e1b",
"accumulator_root_hash": "0x18e048381413700912f753e3c6fd68b409ef64ffc89138768c5c4665851ad79a",
"sender": "0xa550c18",
"sequence_number": "0",
"max_gas_amount": "1000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"type": "user_transaction",
"version": "2",
"hash": "0x859f7cb227645db8c149e77750216dc729de4185c4397803f522e8a6b3605253",
"state_root_hash": "0x7c5ec669fabe887e6a2a38fdbec6fe622e8a377d3020f99e2ae42519b7804c41",
"state_root_hash": "0x57bca4f1a7008c139699a2391570a289c4a0b317daf1639a67e08514953efc4a",
"event_root_hash": "0x414343554d554c41544f525f504c414345484f4c4445525f4841534800000000",
"gas_used": "1",
"success": false,
"vm_status": "Move bytecode deserialization / verification failed, including script function not found or invalid arguments",
"accumulator_root_hash": "0x4b14c4936148c0d7b7a12cca3d971e0c0789896bec99ad4cad8f8a2de5d4780a",
"accumulator_root_hash": "0x65a08f096ad8db74d77c90d312bc072b8d9ecef69213ee47a26b6cd2aadd71d0",
"sender": "0xa550c18",
"sequence_number": "0",
"max_gas_amount": "1000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"type": "user_transaction",
"version": "2",
"hash": "0xe58e229bc8dc107f9495127e81f8ea755ae1749651f6dd544a8ed3502f4376f3",
"state_root_hash": "0x7c5ec669fabe887e6a2a38fdbec6fe622e8a377d3020f99e2ae42519b7804c41",
"state_root_hash": "0x57bca4f1a7008c139699a2391570a289c4a0b317daf1639a67e08514953efc4a",
"event_root_hash": "0x414343554d554c41544f525f504c414345484f4c4445525f4841534800000000",
"gas_used": "1",
"success": false,
"vm_status": "Move bytecode deserialization / verification failed, including script function not found or invalid arguments",
"accumulator_root_hash": "0x1dcf937a7d637b49796100812c3d419ffe354a1d6291156fdfc3f13d269c7657",
"accumulator_root_hash": "0xc993e6b5a0de52d3f38c6328eba2d7d856e07ec1d95c1c231a448ab6701075d6",
"sender": "0xa550c18",
"sequence_number": "0",
"max_gas_amount": "1000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"type": "user_transaction",
"version": "2",
"hash": "0xacfde9314bb58673b2f15eae5cb6e4ad43a2e42cf4c62a2f9eba9dcce5eb96ad",
"state_root_hash": "0x7c5ec669fabe887e6a2a38fdbec6fe622e8a377d3020f99e2ae42519b7804c41",
"state_root_hash": "0x57bca4f1a7008c139699a2391570a289c4a0b317daf1639a67e08514953efc4a",
"event_root_hash": "0x414343554d554c41544f525f504c414345484f4c4445525f4841534800000000",
"gas_used": "1",
"success": false,
"vm_status": "Move bytecode deserialization / verification failed, including script function not found or invalid arguments",
"accumulator_root_hash": "0x871ed9e34f12e44a2fb7512cf72d4eaaa36aa1c5340c2757828ceedafc05ce63",
"accumulator_root_hash": "0x208de84945ff93eb4b08cb9565e5615cdfef1af293235425ac46cd3234f6471b",
"sender": "0xa550c18",
"sequence_number": "0",
"max_gas_amount": "1000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"type": "user_transaction",
"version": "4",
"hash": "0xbf88ed17fd51ff7bd53d652460a76cda92793874307f900cae38c4288fef1382",
"state_root_hash": "0x1525e6083330ea6add689aa0d4335ea87c314d4a7b29a106087373ffe79a0d21",
"state_root_hash": "0xb4c1121df381122c0f04f88b714a56b4beceb6023ef55d8a9d7145ecd1cef35d",
"event_root_hash": "0x414343554d554c41544f525f504c414345484f4c4445525f4841534800000000",
"gas_used": "21",
"success": false,
"vm_status": "Move abort: code 8 at 00000000000000000000000000000001::TestCoin",
"accumulator_root_hash": "0xf2d5f30ccce37b4ef32cb3c105d7ffd994cd942d2fb347c11b2e9b40a3cefc97",
"accumulator_root_hash": "0x8addedb6d0f64e3e53b08298702525989ed813fb731056b3e105fd1af5d678b5",
"sender": "0x62f8f9148c207643864d7ed4a2b23159",
"sequence_number": "0",
"max_gas_amount": "1000",
Expand Down
7 changes: 4 additions & 3 deletions api/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use aptos_types::{
use storage_interface::{MoveDbReader, Order};

use anyhow::{ensure, format_err, Result};
use aptos_types::state_store::state_key::StateKey;
use futures::{channel::oneshot, SinkExt};
use std::{
borrow::Borrow,
Expand Down Expand Up @@ -107,10 +108,10 @@ impl Context {
account: AccountAddress,
version: u64,
) -> Result<Option<AccountStateBlob>> {
let (account_state_blob, _) = self
let (state_value, _) = self
.db
.get_account_state_with_proof_by_version(account, version)?;
Ok(account_state_blob)
.get_state_value_with_proof_by_version(StateKey::AccountAddressKey(account), version)?;
Ok(state_value.map(AccountStateBlob::from))
}

pub fn get_block_timestamp(&self, version: u64) -> Result<u64> {
Expand Down
2 changes: 2 additions & 0 deletions aptos-move/aptos-validator-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use aptos_types::{
};
use move_binary_format::file_format::CompiledModule;

// TODO(skedia) Clean up this interfact to remove account specific logic and move to state store
// key-value interface with fine grained storage project
pub trait AptosValidatorInterface: Sync {
fn get_account_state_by_version(
&self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use aptos_types::{
account_state::AccountState,
contract_event::EventWithProof,
event::EventKey,
state_store::state_key::StateKey,
transaction::{Transaction, Version},
};
use aptosdb::AptosDB;
Expand All @@ -35,7 +36,7 @@ impl AptosValidatorInterface for DBDebuggerInterface {
version: Version,
) -> Result<Option<AccountState>> {
self.0
.get_account_state_with_proof_by_version(account, version)?
.get_state_value_with_proof_by_version(StateKey::AccountAddressKey(account), version)?
.0
.map(|s| AccountState::try_from(&s))
.transpose()
Expand Down
5 changes: 3 additions & 2 deletions aptos-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use aptos_types::{
chain_id::ChainId,
move_resource::MoveStorage,
on_chain_config::{VMPublishingOption, ON_CHAIN_CONFIG_REGISTRY},
state_store::state_key::StateKey,
waypoint::Waypoint,
};
use aptos_vm::AptosVM;
Expand Down Expand Up @@ -210,8 +211,8 @@ pub fn print_api_config(config: &NodeConfig, lazy: bool) {
fn fetch_chain_id(db: &DbReaderWriter) -> ChainId {
let blob = db
.reader
.get_account_state_with_proof_by_version(
aptos_root_address(),
.get_state_value_with_proof_by_version(
StateKey::AccountAddressKey(aptos_root_address()),
(&*db.reader)
.fetch_synced_version()
.expect("[aptos-node] failed fetching synced version."),
Expand Down
6 changes: 4 additions & 2 deletions config/management/genesis/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use aptos_temppath::TempPath;
use aptos_types::{
account_address::AccountAddress, account_config, account_state::AccountState,
network_address::NetworkAddress, on_chain_config::ValidatorSet,
validator_config::ValidatorConfig, waypoint::Waypoint,
state_store::state_key::StateKey, validator_config::ValidatorConfig, waypoint::Waypoint,
};
use aptos_vm::AptosVM;
use aptosdb::AptosDB;
Expand Down Expand Up @@ -240,7 +240,9 @@ fn validator_config(
reader: Arc<dyn DbReader>,
) -> Result<ValidatorConfig, Error> {
let blob = reader
.get_latest_account_state(account_config::validator_set_address())
.get_latest_state_value(StateKey::AccountAddressKey(
account_config::validator_set_address(),
))
.map_err(|e| {
Error::UnexpectedError(format!("ValidatorSet Account issue {}", e.to_string()))
})?
Expand Down
9 changes: 6 additions & 3 deletions execution/executor-benchmark/src/transaction_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use aptos_sdk::transaction_builder::TransactionFactory;
use aptos_types::{
account_address::AccountAddress,
account_config::{aptos_root_address, AccountResource},
account_state_blob::AccountStateBlob,
chain_id::ChainId,
state_store::state_key::StateKey,
transaction::{RawTransaction, SignedTransaction, Transaction, Version},
};
use chrono::Local;
Expand Down Expand Up @@ -338,11 +340,12 @@ impl TransactionGenerator {
let bar = get_progress_bar(self.accounts_cache.len());
for account in &self.accounts_cache {
let address = account.address;
let blob = db
.get_latest_account_state(address)
let state_store_value = db
.get_latest_state_value(StateKey::AccountAddressKey(address))
.expect("Failed to query storage.")
.expect("Account must exist.");
let account_resource = AccountResource::try_from(&blob).unwrap();
let account_resource =
AccountResource::try_from(&AccountStateBlob::from(state_store_value)).unwrap();
assert_eq!(account_resource.sequence_number(), account.sequence_number);
bar.inc(1);
}
Expand Down
47 changes: 34 additions & 13 deletions execution/executor-test-helpers/src/integration_test_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use aptos_types::{
xus_tag, XUS_NAME,
},
account_state::AccountState,
account_state_blob::AccountStateWithProof,
event::EventKey,
state_store::{state_key::StateKey, state_value::StateValueWithProof},
transaction::{
authenticator::AuthenticationKey, Transaction, TransactionListWithProof,
TransactionWithProof, WriteSetPayload,
Expand Down Expand Up @@ -298,19 +298,31 @@ pub fn test_execution_with_storage_impl() -> Arc<AptosDB> {

let account1_state_with_proof = db
.reader
.get_account_state_with_proof(account1, current_version, current_version)
.get_state_value_with_proof(
StateKey::AccountAddressKey(account1),
current_version,
current_version,
)
.unwrap();
verify_account_balance(&account1_state_with_proof, |x| x == 1_910_000).unwrap();

let account2_state_with_proof = db
.reader
.get_account_state_with_proof(account2, current_version, current_version)
.get_state_value_with_proof(
StateKey::AccountAddressKey(account2),
current_version,
current_version,
)
.unwrap();
verify_account_balance(&account2_state_with_proof, |x| x == 1_210_000).unwrap();

let account3_state_with_proof = db
.reader
.get_account_state_with_proof(account3, current_version, current_version)
.get_state_value_with_proof(
StateKey::AccountAddressKey(account3),
current_version,
current_version,
)
.unwrap();
verify_account_balance(&account3_state_with_proof, |x| x == 1_080_000).unwrap();

Expand Down Expand Up @@ -388,9 +400,13 @@ pub fn test_execution_with_storage_impl() -> Arc<AptosDB> {

let account4_state = db
.reader
.get_account_state_with_proof(account4, current_version, current_version)
.get_state_value_with_proof(
StateKey::AccountAddressKey(account4),
current_version,
current_version,
)
.unwrap();
assert!(account4_state.blob.is_none());
assert!(account4_state.value.is_none());

let account4_transaction = db
.reader
Expand Down Expand Up @@ -443,13 +459,21 @@ pub fn test_execution_with_storage_impl() -> Arc<AptosDB> {

let account1_state_with_proof = db
.reader
.get_account_state_with_proof(account1, current_version, current_version)
.get_state_value_with_proof(
StateKey::AccountAddressKey(account1),
current_version,
current_version,
)
.unwrap();
verify_account_balance(&account1_state_with_proof, |x| x == 1_770_000).unwrap();

let account3_state_with_proof = db
.reader
.get_account_state_with_proof(account3, current_version, current_version)
.get_state_value_with_proof(
StateKey::AccountAddressKey(account3),
current_version,
current_version,
)
.unwrap();
verify_account_balance(&account3_state_with_proof, |x| x == 1_220_000).unwrap();

Expand Down Expand Up @@ -524,14 +548,11 @@ pub fn create_db_and_executor<P: AsRef<std::path::Path>>(
(db, dbrw, executor, waypoint)
}

pub fn verify_account_balance<F>(
account_state_with_proof: &AccountStateWithProof,
f: F,
) -> Result<()>
pub fn verify_account_balance<F>(account_state_with_proof: &StateValueWithProof, f: F) -> Result<()>
where
F: Fn(u64) -> bool,
{
let balance = if let Some(blob) = &account_state_with_proof.blob {
let balance = if let Some(blob) = &account_state_with_proof.value {
AccountState::try_from(blob)?
.get_balance_resources()?
.get(&from_currency_code_string(XUS_NAME).unwrap())
Expand Down
2 changes: 1 addition & 1 deletion execution/executor-types/src/executed_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl ExecutedChunk {
Ok(TransactionToCommit::new(
txn.clone(),
txn_data.txn_info.clone(),
txn_data.account_blobs().clone(),
txn_data.state_updates().clone(),
Some(txn_data.jf_node_hashes().clone()),
txn_data.write_set().clone(),
txn_data.events().to_vec(),
Expand Down
Loading

0 comments on commit 90646f5

Please sign in to comment.