Skip to content

Commit

Permalink
[storage] short state key prefix
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 1a9bdca commit 1482bb8
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 96 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"type": "genesis_transaction",
"version": "0",
"hash": "0x48f7beb0c3c3c5378934981fc1a66ed7caffdd0a8e8b4e943aadc98e4ce3efbd",
"state_root_hash": "0xa90d31fb6a5df17fe7a8bb071b661ba00c360dc172657ac9013dbf563dbf32b3",
"state_root_hash": "0x9b0cec4915f003fe065032552a965e3f4709d71b19120c0e7384eed74eca7170",
"event_root_hash": "0xcbdbb1b830d1016d45a828bb3171ea81826e8315f14140acfbd7886f49fbcb40",
"gas_used": "0",
"success": true,
"vm_status": "Executed successfully",
"accumulator_root_hash": "0xb00d306484416ed404724ba7fcb70f23101ad23a8bce6deafc0f0dcda284b690",
"accumulator_root_hash": "0x640b122b4c24b12f3218d2d09bc6c797135f458b92a710bf296fe6a2f9ce5226",
"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": "0xa8fc186c28fc0f95b8233651438093e8e215a51dcd16475f5e68c0a421f6305c",
"state_root_hash": "0xd4c542cffa6151656cec70dad0e44206ec06a421afa7801ff6227d2aedc5c489",
"state_root_hash": "0xf344cd8dca9a3aa277baefb83a3e75a78bdeedf70a6aa2e04173b65a89ac29a3",
"event_root_hash": "0xd62c85b93234824cf825e9c028c3bcc59b06926039721bd7edd76b56ae9fcecf",
"gas_used": "0",
"success": true,
"vm_status": "Executed successfully",
"accumulator_root_hash": "0x7e372f1a7fda7081eed79ee1de3fb17eeee80e0e0c9e233df47882f38d2ff330",
"accumulator_root_hash": "0x3d521ad19e921a78ec21601eaba9ee7c4cdfacdf8982a4b3aa2e1da291dd0a1a",
"id": "0xf44b581f23222c10916b17a369b4da039d075952b58036f2a7b561446592403c",
"round": "1",
"previous_block_votes": [],
Expand All @@ -19,12 +19,12 @@
"type": "user_transaction",
"version": "2",
"hash": "0x7ecd26dfe2d314f8fc5b5e5ecd0fb64dfd341755f025759e8bb5226441068523",
"state_root_hash": "0xb8c8950f271aa6f0febc6921f7f15a4ea25b34e76509bfbd041a4d2292b22c88",
"state_root_hash": "0xb297a82744c07a2e253d791530dfe261f0a7f1952104bafad26ff5908efa4b3d",
"event_root_hash": "0x414343554d554c41544f525f504c414345484f4c4445525f4841534800000000",
"gas_used": "98",
"success": true,
"vm_status": "Executed successfully",
"accumulator_root_hash": "0xc6d160626df633dca7cd9540afd9db0cac53c9754890c0c4d65335a336c1410d",
"accumulator_root_hash": "0xaa70603b3e73ef00ab03cd295703aabcc2fd89df03caeee002106528920945ef",
"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": "0x94ea91ca86dabbe323c8d6ce9dccaa981e713dee84ef5b649a519a11f0688efb",
"state_root_hash": "0xd1bd5a17524d4108a9795366cd12e9ee96f7ce262f6a046f07864c1ebfa4bb3e",
"state_root_hash": "0x3df3563ad5dab05e0230bb110438326f466ae283583d93e83173d2efdf643326",
"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": "0xb09a7de2dc74d6cbb8b303f624ab779c04e07b960b5176cb0efc1a39827863c2",
"accumulator_root_hash": "0x21999f95a012e9d7e16ea89c38233e78b888da416ccac3dca5ee53ef782c39d1",
"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": "0xf041614384c1fa1041c41d09e03165de1894c9d0fd4a0bef27aa74d5c5e1edf7",
"state_root_hash": "0xd1bd5a17524d4108a9795366cd12e9ee96f7ce262f6a046f07864c1ebfa4bb3e",
"state_root_hash": "0x3df3563ad5dab05e0230bb110438326f466ae283583d93e83173d2efdf643326",
"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": "0x248aa1db30eee6384f56acdef89db9ddc91b5bf96198329df8ca8eb4c8404536",
"accumulator_root_hash": "0x800462f5d1d64c16cbd0892d98c975eddd5f71a40afe81e36b962812c09b8b0b",
"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": "0xcb16d12010be8372e54b392756d4b8f586a6817de83d6fe5b17cf04ee9e184ea",
"state_root_hash": "0xd1bd5a17524d4108a9795366cd12e9ee96f7ce262f6a046f07864c1ebfa4bb3e",
"state_root_hash": "0x3df3563ad5dab05e0230bb110438326f466ae283583d93e83173d2efdf643326",
"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": "0x270efbac79608c012dd62cfaedbb413edee5e526877a585f7341d73c41d533ad",
"accumulator_root_hash": "0xf9ef193c46f941a69ce5fffd5cade9365e8327c2c54c91bca573bd3112ef4262",
"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": "0x7e7cce0816c8893b387ee9df6639b76057b451fa2ee7fad79b150d1e5ab39972",
"state_root_hash": "0xd1bd5a17524d4108a9795366cd12e9ee96f7ce262f6a046f07864c1ebfa4bb3e",
"state_root_hash": "0x3df3563ad5dab05e0230bb110438326f466ae283583d93e83173d2efdf643326",
"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": "0x3f59b0d085b910ab47a01a66833f10339ebe49d78ad6ba3e80c8cf3dac635566",
"accumulator_root_hash": "0xa4cdcfa20e379370623edaa93f7cfc65b31c2244cabee8b4d45ffea160650f59",
"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": "0x2d05462ffbbe304c481df68b280819469adb3ccc88573121ce445c867a4a5e5a",
"state_root_hash": "0xd1bd5a17524d4108a9795366cd12e9ee96f7ce262f6a046f07864c1ebfa4bb3e",
"state_root_hash": "0x3df3563ad5dab05e0230bb110438326f466ae283583d93e83173d2efdf643326",
"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": "0x705e7cd7f0d22d6f1492b0ca828b4f78b5f3bbf45fc939edcd549ac2d1706b32",
"accumulator_root_hash": "0x461a739ff7b4b2287592ea989fc7b6f4b012a74e2965c5b843b139fc4c6f2a05",
"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": "0x1b45f833770dcd1bb69fb586b8367e459708e2cd4ba162110f8520b54794ab0f",
"state_root_hash": "0xd1bd5a17524d4108a9795366cd12e9ee96f7ce262f6a046f07864c1ebfa4bb3e",
"state_root_hash": "0x3df3563ad5dab05e0230bb110438326f466ae283583d93e83173d2efdf643326",
"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": "0xd2f4cd582f48b48412a9d62d070f177865c64bc97b91ff1ddae1b41efd407322",
"accumulator_root_hash": "0x90f490558b53984d847e54bdc67b3f004cc30174df7783ed5e965c45440220cf",
"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": "0x7d70c809eaed055de23cd99cc946954ebc3905e20dd1db0b6634dab13a3046f6",
"state_root_hash": "0xd1bd5a17524d4108a9795366cd12e9ee96f7ce262f6a046f07864c1ebfa4bb3e",
"state_root_hash": "0x3df3563ad5dab05e0230bb110438326f466ae283583d93e83173d2efdf643326",
"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": "0x695bb7a3368023e6da1f74638c602554fe38f20c7b873c74b4f3bee2dd5b771e",
"accumulator_root_hash": "0x1eff882afa35b67072cb26df8b28822ca7138d6d56c2202d34e93bf40ab108c3",
"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": "0x02dbb80ed580f1c272fb0e41d18e4c5367c03f4bfad5b711d297037beda71f97",
"state_root_hash": "0x4d11287d273f581a83bc63fdc025095cbe5b3a84ad2dc6a6ba1e8d542504f98a",
"state_root_hash": "0xc5fed9c28fe4ae51a6610e0225b06d2a59ccd574d0065e63976d3e746d5e81cf",
"event_root_hash": "0x414343554d554c41544f525f504c414345484f4c4445525f4841534800000000",
"gas_used": "26",
"success": false,
"vm_status": "Move abort by LIMIT_EXCEEDED - EINSUFFICIENT_BALANCE\n A limit on an amount, e.g. a currency, is exceeded. Example: withdrawal of money after account limits window\n is exhausted.\n Error codes",
"accumulator_root_hash": "0xeedc664947e476a8e1e23b10eb4e34a00d7b0c65df5e3dc0076d404becd78e64",
"accumulator_root_hash": "0x89c2d82a6113da1616c4c2762933ca8609339a38d2ea4fdf3610ba9fd6abf23c",
"sender": "0xe60912ecb0a8c365d163d258f3b9f1b62f8f9148c207643864d7ed4a2b23159",
"sequence_number": "0",
"max_gas_amount": "1000",
Expand Down
2 changes: 2 additions & 0 deletions types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ hex = "0.4.3"
itertools = { version = "0.10.0", default-features = false }
once_cell = "1.7.2"
mirai-annotations = "1.10.1"
num-derive = "0.3.3"
num-traits = "0.2.14"
proptest = { version = "1.0.0", optional = true }
proptest-derive = { version = "0.3.0", default-features = false, optional = true }
rand = "0.8.3"
Expand Down
53 changes: 29 additions & 24 deletions types/src/state_store/state_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ use aptos_crypto::{
};
use aptos_crypto_derive::CryptoHasher;
use move_core_types::account_address::AccountAddress;
use num_derive::ToPrimitive;
use num_traits::ToPrimitive;
use serde::{Deserialize, Serialize};

const ACCOUNT_ADDRESS_KEY_PREFIX: &str = "acc_blb_|";
const ACCOUNT_ACCESS_PATH_KEY_PREFIX: &str = "access_path_|";
const RAW_KEY_PREFIX: &str = "raw_key_|";

#[derive(
Clone, Debug, CryptoHasher, Eq, PartialEq, Serialize, Deserialize, Ord, PartialOrd, Hash,
)]
Expand All @@ -26,36 +24,43 @@ pub enum StateKey {
Raw(Vec<u8>),
}

#[derive(ToPrimitive)]
enum StateKeyPrefix {
AccountAddress,
AccessPath,
Raw = 255,
}

impl StateKeyPrefix {
fn to_bytes(&self) -> Vec<u8> {
let byte = self
.to_u8()
.expect("Failed to convert StateKeyPrefix to u8");
vec![byte]
}
}

struct RawStateKey {
bytes: Vec<u8>,
}

impl From<&StateKey> for RawStateKey {
fn from(key: &StateKey) -> Self {
match key {
let (prefix, raw_key) = match key {
StateKey::AccountAddressKey(account_address) => {
let mut account_address_prefix = ACCOUNT_ADDRESS_KEY_PREFIX.as_bytes().to_vec();
account_address_prefix.extend(account_address.to_vec());
RawStateKey {
bytes: account_address_prefix,
}
(StateKeyPrefix::AccountAddress, account_address.to_vec())
}
StateKey::AccessPath(access_path) => {
let mut account_access_path_prefix =
ACCOUNT_ACCESS_PATH_KEY_PREFIX.as_bytes().to_vec();
account_access_path_prefix.extend(access_path.address.to_vec());
RawStateKey {
bytes: account_access_path_prefix,
}
let mut raw_key = access_path.address.to_vec();
raw_key.extend(access_path.path.clone());
(StateKeyPrefix::AccessPath, raw_key)
}
StateKey::Raw(raw_bytes) => {
let mut raw_path_prefix = RAW_KEY_PREFIX.as_bytes().to_vec();
raw_path_prefix.extend(raw_bytes);
RawStateKey {
bytes: raw_path_prefix,
}
}
}
StateKey::Raw(raw_bytes) => (StateKeyPrefix::Raw, raw_bytes.to_vec()),
};
let mut bytes = prefix.to_bytes();
bytes.extend(raw_key);

Self { bytes }
}
}

Expand Down

0 comments on commit 1482bb8

Please sign in to comment.