0xMiden / 0xMiden/node

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

Abierto
#2,328 0 comentarios 0 reacciones 0 asignados Ver en GitHub
store
Lenguaje dominante
Rust
Estrellas
104
Forks
138
Merge medio
1 d 13 h
PR fusionados (30 d)
56

Descripción

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;
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.