-
Notifications
You must be signed in to change notification settings - Fork 87
feat: [2/4] integrate smtforest, avoid ser/de of full account/vault data in database #1394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: bernhard-db-schema-queries
Are you sure you want to change the base?
Changes from 13 commits
4ff0970
5ee1043
8eca359
e7f17ed
c8b43ab
19164be
8eb49af
6725461
ee65a88
741df6f
6a64077
9d5806e
2964a93
9416a63
ccc2d63
66ea831
1c4f8b1
80e0393
e7bf1aa
dad90e7
e441245
0a319d1
8897939
7d7fefc
0f53fa9
7400134
0e2d871
f78103e
ea05b01
3cd457a
c8f0eb1
ed7224e
6336f41
a1173f7
36470a5
928fdb4
5de3936
f5b4898
ca5ef9a
17fd95b
22f3ca9
3ee1884
eaf7242
72126e1
be9071b
a0f8fc9
88c058b
b84f25f
25b5550
31dacdd
55f4a46
bf67ce8
0c0e32b
ec4318e
4bfee30
b8d2e66
e453faa
f6d1ce1
b1f9cf6
d2d9e8c
2781db8
b0e537c
d6b31ef
9c859fc
b016495
579b9dc
3336edb
2aa8c8b
354d586
a96def0
e8cdad1
3009bf7
3110962
53cb5e8
0cc0c61
ac7b8f9
369db2f
6cd1033
7613624
e04ff10
9d8c220
5ed1a4f
3346d9f
dbbc1eb
c5a199a
c712ba4
d9a666f
29b840c
1b22a34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,6 +69,7 @@ impl From<AccountId> for proto::account::AccountId { | |
| // ACCOUNT UPDATE | ||
| // ================================================================================================ | ||
|
|
||
| // TODO should be called `AccountStateRef` or so | ||
| #[derive(Debug, PartialEq)] | ||
| pub struct AccountSummary { | ||
| pub account_id: AccountId, | ||
|
|
@@ -86,6 +87,7 @@ impl From<&AccountSummary> for proto::account::AccountSummary { | |
| } | ||
| } | ||
|
|
||
| // TODO #[deprecated(note = "avoid this type, details will be `None` always!")] | ||
| #[derive(Debug, PartialEq)] | ||
| pub struct AccountInfo { | ||
| pub summary: AccountSummary, | ||
|
|
@@ -375,6 +377,27 @@ impl AccountVaultDetails { | |
| } | ||
| } | ||
|
|
||
| /// Creates `AccountVaultDetails` from vault entries (key-value pairs). | ||
| /// | ||
| /// This is useful when entries have been fetched directly from the database | ||
| /// rather than extracted from an `AssetVault`. | ||
| /// | ||
| /// The entries are `(vault_key, asset)` pairs where `asset` is a Word representation. | ||
| pub fn from_entries(entries: Vec<(Word, Word)>) -> Result<Self, miden_objects::AssetError> { | ||
| let too_many_assets = entries.len() > Self::MAX_RETURN_ENTRIES; | ||
|
|
||
| if too_many_assets { | ||
| return Ok(Self::too_many()); | ||
| } | ||
|
||
|
|
||
| let assets = entries | ||
| .into_iter() | ||
| .map(|(_key, asset_word)| Asset::try_from(asset_word)) | ||
| .collect::<Result<Vec<_>, _>>()?; | ||
|
|
||
| Ok(Self { too_many_assets: false, assets }) | ||
| } | ||
|
|
||
| fn too_many() -> Self { | ||
| Self { | ||
| too_many_assets: true, | ||
|
|
@@ -418,16 +441,20 @@ impl From<AccountVaultDetails> for proto::rpc_store::AccountVaultDetails { | |
| pub struct AccountStorageMapDetails { | ||
| pub slot_index: u8, | ||
| pub too_many_entries: bool, | ||
| // TODO the following is only for the case when _all_ entries are included | ||
| // TODO for partials, we also need to provide merkle proofs / a partial SMT with inner nodes | ||
| // Reason: if all leaf values are included, one can reconstruct the entire SMT, if just one | ||
| // is missing one cannot | ||
| pub map_entries: Vec<(Word, Word)>, | ||
| } | ||
|
|
||
| impl AccountStorageMapDetails { | ||
| const MAX_RETURN_ENTRIES: usize = 1000; | ||
| pub const MAX_RETURN_ENTRIES: usize = 1000; | ||
|
|
||
| pub fn new(slot_index: u8, slot_data: SlotData, storage_map: &StorageMap) -> Self { | ||
| match slot_data { | ||
| SlotData::All => Self::from_all_entries(slot_index, storage_map), | ||
| SlotData::MapKeys(keys) => Self::from_specific_keys(slot_index, &keys[..], storage_map), | ||
| SlotData::MapKeys(_keys) => Self::from_all_entries(slot_index, storage_map), /* TODO use from_specific_keys */ | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -444,12 +471,27 @@ impl AccountStorageMapDetails { | |
| } | ||
| } | ||
|
|
||
| fn from_specific_keys(slot_index: u8, keys: &[Word], storage_map: &StorageMap) -> Self { | ||
| // TODO this is | ||
drahnr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #[allow(dead_code)] | ||
| fn from_specific_keys(slot_index: u8, keys: &[Word], _storage_map: &StorageMap) -> Self { | ||
| if keys.len() > Self::MAX_RETURN_ENTRIES { | ||
| Self::too_many_entries(slot_index) | ||
| } else { | ||
| // TODO For now, we return all entries instead of specific keys with proofs | ||
| Self::from_all_entries(slot_index, storage_map) | ||
| todo!("construct a partial SMT / set of key values") | ||
| } | ||
| } | ||
|
|
||
| /// Creates an `AccountStorageMapDetails` from already-queried entries (e.g., from database). | ||
| /// This is useful when entries have been fetched directly rather than extracted from a | ||
| /// `StorageMap`. | ||
| pub fn from_entries(slot_index: u8, map_entries: Vec<(Word, Word)>) -> Self { | ||
| let too_many_entries = map_entries.len() > Self::MAX_RETURN_ENTRIES; | ||
| let map_entries = if too_many_entries { Vec::new() } else { map_entries }; | ||
|
||
|
|
||
| Self { | ||
| slot_index, | ||
| too_many_entries, | ||
| map_entries, | ||
| } | ||
| } | ||
|
|
||
|
|
||
drahnr marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| -- Drop all tables in reverse order of creation (respecting foreign key dependencies) | ||
| DROP TABLE IF EXISTS transactions; | ||
| DROP TABLE IF EXISTS nullifiers; | ||
| DROP TABLE IF EXISTS account_vault_headers; | ||
| DROP TABLE IF EXISTS account_vault_assets; | ||
| DROP TABLE IF EXISTS account_storage_map_values; | ||
| DROP TABLE IF EXISTS note_scripts; | ||
| DROP TABLE IF EXISTS notes; | ||
| DROP TABLE IF EXISTS account_storage_headers; | ||
| DROP TABLE IF EXISTS accounts; | ||
| DROP TABLE IF EXISTS account_codes; | ||
| DROP TABLE IF EXISTS block_headers; |
Uh oh!
There was an error while loading. Please reload this page.