Skip to content

Commit ce9eee5

Browse files
committed
graph: ensure removal paths go through remove_entity
1 parent f0df23a commit ce9eee5

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

graph/src/components/store/write.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -498,31 +498,29 @@ impl RowGroup {
498498
}
499499

500500
pub fn track_metrics(&self, metrics: &mut BlockStateMetrics) {
501+
// Track entity count changes
501502
let changes: Vec<i32> = self
502503
.rows
503504
.iter()
504505
.map(|row| row.entity_count_change())
505506
.collect();
507+
metrics.track_entity_count_change_batch(&self.entity_type, &changes);
506508

507-
let (writes, removals): (Vec<_>, Vec<_>) = self
509+
// Track writes only
510+
let writes: Vec<Entity> = self
508511
.rows
509512
.iter()
510513
.filter_map(|row| match row {
511-
EntityModification::Insert { data, .. }
512-
| EntityModification::Overwrite { data, .. } => Some((data, false)),
514+
EntityModification::Insert { data, .. }
515+
| EntityModification::Overwrite { data, .. } => Some(data.as_ref().clone()),
513516
EntityModification::Remove { .. } => None,
514517
})
515-
.unzip();
516-
517-
metrics.track_entity_count_change_batch(&self.entity_type, &changes);
518+
.collect();
518519

519520
if !writes.is_empty() {
520521
metrics.track_entity_write_batch(&self.entity_type, &writes);
521522
metrics.track_storage_size_change_batch(&self.entity_type, &writes, false);
522523
}
523-
if !removals.is_empty() {
524-
metrics.track_storage_size_change_batch(&self.entity_type, &removals, true);
525-
}
526524
}
527525
}
528526

runtime/wasm/src/host_exports.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,24 @@ impl HostExports {
12491249
.map(|mut tokens| tokens.pop().unwrap())
12501250
.context("Failed to decode")
12511251
}
1252+
1253+
fn remove_entity(&mut self, key: &EntityKey) -> Result<(), HostExportError> {
1254+
let entity_type = key.entity_type.clone();
1255+
1256+
if let Some(entity) = state.entity_cache.get(&key, GetScope::Store)? {
1257+
// Track removal metrics while we still have the entity data
1258+
state
1259+
.metrics
1260+
.track_storage_size_change(&entity_type, &entity, true);
1261+
state.metrics.track_entity_count_change(&entity_type, -1);
1262+
}
1263+
1264+
state.modifications.push(EntityModification::remove(
1265+
key.clone(),
1266+
state.block.number,
1267+
));
1268+
Ok(())
1269+
}
12521270
}
12531271

12541272
fn string_to_h160(string: &str) -> Result<H160, DeterministicHostError> {

0 commit comments

Comments
 (0)