@@ -33,6 +33,8 @@ use crate::{error::DeterminismLevel, module::IntoTrap};
3333
3434use super :: module:: WasmInstanceData ;
3535
36+ use graph:: schema:: EntityKey ;
37+
3638fn write_poi_event (
3739 proof_of_indexing : & SharedProofOfIndexing ,
3840 poi_event : & ProofOfIndexingEvent ,
@@ -354,7 +356,7 @@ impl HostExports {
354356 . metrics
355357 . track_storage_size_change ( & entity_type, & entity, false ) ;
356358
357- if ! state. entity_cache . contains_key ( & key) {
359+ if state. entity_cache . get ( & key, GetScope :: Store ) ? . is_none ( ) {
358360 state. metrics . track_entity_count_change ( & entity_type, 1 ) ;
359361 }
360362
@@ -1250,21 +1252,27 @@ impl HostExports {
12501252 . context ( "Failed to decode" )
12511253 }
12521254
1253- fn remove_entity ( & mut self , key : & EntityKey ) -> Result < ( ) , HostExportError > {
1255+ fn remove_entity (
1256+ & mut self ,
1257+ key : & EntityKey ,
1258+ state : & mut BlockState ,
1259+ ) -> Result < ( ) , HostExportError > {
12541260 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
1261+
1262+ if let Some ( entity) = state. entity_cache . get ( key, GetScope :: Store ) ? {
12581263 state
12591264 . metrics
12601265 . track_storage_size_change ( & entity_type, & entity, true ) ;
12611266 state. metrics . track_entity_count_change ( & entity_type, -1 ) ;
12621267 }
12631268
1264- state. modifications . push ( EntityModification :: remove (
1265- key. clone ( ) ,
1266- state. block . number ,
1267- ) ) ;
1269+ state
1270+ . entity_cache
1271+ . modifications
1272+ . push ( EntityModification :: remove (
1273+ key. clone ( ) ,
1274+ state. entity_cache . block_number ,
1275+ ) ) ;
12681276 Ok ( ( ) )
12691277 }
12701278}
@@ -1395,3 +1403,9 @@ fn bytes_to_string_is_lossy() {
13951403 )
13961404 )
13971405}
1406+
1407+ impl From < StoreError > for HostExportError {
1408+ fn from ( err : StoreError ) -> Self {
1409+ HostExportError :: Deterministic ( anyhow:: Error :: from ( err) )
1410+ }
1411+ }
0 commit comments