Skip to content

Commit 36b9ab9

Browse files
weiihannSavid
andauthored
refactor: storage calc and viz changes (#385)
* refactor(state): add key overhead * refactor(state): make current part of matrix * refactor(state): desc changes * refactor(state): graph aesthetic changes * feat(state): add new column on slots * feat(state): add sorting in columns * chore(state): text changes * lint * lint * revert vite * always deploy slots Co-authored-by: Andrew Davis <1709934+Savid@users.noreply.github.com> Signed-off-by: Ng Wei Han <47109095+weiihann@users.noreply.github.com> * add key overhead to contracts table * lint --------- Signed-off-by: Ng Wei Han <47109095+weiihann@users.noreply.github.com> Co-authored-by: Andrew Davis <1709934+Savid@users.noreply.github.com>
1 parent cb1a26b commit 36b9ab9

File tree

9 files changed

+621
-532
lines changed

9 files changed

+621
-532
lines changed

src/pages/ethereum/contracts/ContractPage.tsx

Lines changed: 127 additions & 230 deletions
Large diffs are not rendered by default.

src/pages/ethereum/contracts/hooks/useContractStorageData.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import type {
1515
export const EXPIRY_TYPES = ['slot', 'contract'] as const;
1616
export type ExpiryType = (typeof EXPIRY_TYPES)[number];
1717

18+
/**
19+
* Key overhead per storage slot in geth's snapshot structure.
20+
* Each slot key = 1 (prefix) + 32 (account hash) + 32 (storage hash) = 65 bytes
21+
*/
22+
const SLOT_KEY_OVERHEAD_BYTES = 65;
23+
1824
/** Available expiry policy options */
1925
export const EXPIRY_POLICIES = ['12m', '24m'] as const;
2026
export type ExpiryPolicy = (typeof EXPIRY_POLICIES)[number];
@@ -163,9 +169,11 @@ export function useContractStorageData(address: string): UseContractStorageDataR
163169
const contractCurrentMap = new Map<string, { slots: number; bytes: number }>();
164170
currentData.forEach(item => {
165171
if (item.day_start_date) {
172+
const slots = item.active_slots ?? 0;
173+
const valueBytes = item.effective_bytes ?? 0;
166174
contractCurrentMap.set(item.day_start_date, {
167-
slots: item.active_slots ?? 0,
168-
bytes: item.effective_bytes ?? 0,
175+
slots,
176+
bytes: slots * SLOT_KEY_OVERHEAD_BYTES + valueBytes,
169177
});
170178
}
171179
});
@@ -182,9 +190,11 @@ export function useContractStorageData(address: string): UseContractStorageDataR
182190
for (const policy of EXPIRY_POLICIES) {
183191
contractExpiryData[policy]?.forEach(item => {
184192
if (item.day_start_date) {
193+
const slots = item.active_slots ?? 0;
194+
const valueBytes = item.effective_bytes ?? 0;
185195
contractExpiryMaps[policy].set(item.day_start_date, {
186-
slots: item.active_slots ?? 0,
187-
bytes: item.effective_bytes ?? 0,
196+
slots,
197+
bytes: slots * SLOT_KEY_OVERHEAD_BYTES + valueBytes,
188198
});
189199
}
190200
});
@@ -194,9 +204,11 @@ export function useContractStorageData(address: string): UseContractStorageDataR
194204
const slotCurrentMap = new Map<string, { slots: number; bytes: number }>();
195205
slotCurrentData?.forEach(item => {
196206
if (item.day_start_date) {
207+
const slots = item.active_slots ?? 0;
208+
const valueBytes = item.effective_bytes ?? 0;
197209
slotCurrentMap.set(item.day_start_date, {
198-
slots: item.active_slots ?? 0,
199-
bytes: item.effective_bytes ?? 0,
210+
slots,
211+
bytes: slots * SLOT_KEY_OVERHEAD_BYTES + valueBytes,
200212
});
201213
}
202214
});
@@ -213,9 +225,11 @@ export function useContractStorageData(address: string): UseContractStorageDataR
213225
for (const policy of EXPIRY_POLICIES) {
214226
slotExpiryData[policy]?.forEach(item => {
215227
if (item.day_start_date) {
228+
const slots = item.active_slots ?? 0;
229+
const valueBytes = item.effective_bytes ?? 0;
216230
slotExpiryMaps[policy].set(item.day_start_date, {
217-
slots: item.active_slots ?? 0,
218-
bytes: item.effective_bytes ?? 0,
231+
slots,
232+
bytes: slots * SLOT_KEY_OVERHEAD_BYTES + valueBytes,
219233
});
220234
}
221235
});

0 commit comments

Comments
 (0)