0xMiden / 0xMiden/node

store: `apply_block` code does not correctly handle `StorageMapPatch::Remove` and `StorageMapPatch::Create` semantics

Aperta
#2,328 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
store
Lingua principale
Rust
Stelle
104
Fork
138
Merge medio
1g 13h
PR unite (30g)
56

Descrizione

After the recent upgrade to `miden-protocol` `next` there were some semantic changes introduced with `AccountPatch`: explicit create and remove operations were added for storage slots and storage maps.

`StorageValuePatch::Remove` and `StorageMapPatch::Remove` now needs to be handled explicitly in our storage code. In particular, `StorageMapPatch::Remove` is _not_ handled correctly right now.

The account state forest code skips removes (because `StorageMapPatch::entries` returns `None` for `Remove`: https://github.com/0xMiden/node/blob/914ff72faf7a8c7a4798bfc352e6e6a4167397c0/crates/store/src/account_state_forest/mod.rs#L743).

The code applying account state changes to SQLite also seems to just skip `Remove`: https://github.com/0xMiden/node/blob/914ff72faf7a8c7a4798bfc352e6e6a4167397c0/crates/store/src/db/models/queries/accounts.rs#L1146

Similarly, `StorageMapPatch::merge()` can merge a `Remove, Create` operation pair into a single `StorageMapPatch::Create` operation, so it's entirely possible that we're getting a `StorageMapPatch::Create` patch for an _existing_ storage map. In that case all current entries should be removed first and then the new entries added.

Note that we don't have a good way of representing map value removals in SQLite. The current schema for storage maps is this:

```sql
CREATE TABLE account_storage_map_values (
account_id BLOB NOT NULL,
block_num BIGINT NOT NULL,
slot_name TEXT NOT NULL,
key BLOB NOT NULL,
value BLOB NOT NULL,
is_latest BOOLEAN NOT NULL,

PRIMARY KEY (account_id, block_num, slot_name, key),
FOREIGN KEY (account_id, block_num) REFERENCES accounts(account_id, block_num) ON DELETE CASCADE
) WITHOUT ROWID;
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.