11from typing import Any , Optional , List
22
3- from jam .log_setup import pvm_logger as logger , logger as jam_logger
3+ from jam .log_setup import logger as logger , logger as jam_logger
44from jam .execution .invocations .functions .protocol import (
55 InvocationFunctions as INVF ,
66)
@@ -80,7 +80,7 @@ def fetch(
8080 item_index : int ,
8181 import_segments : Optional [List ],
8282 extrinsics : Optional [Extrinsics ],
83- o : Optional [AccumulationInputs ]
83+ o : Optional [AccumulationInputs ] # bold i
8484 ):
8585 fetch_type = registers [10 ]
8686
@@ -132,21 +132,33 @@ def fetch(
132132 v = trace
133133 elif (
134134 w10 == 3
135- and item_index is not None
135+ and extrinsics is not None
136136 and w11 < len (extrinsics )
137137 and w12 < len (extrinsics [int (w11 )])
138138 ):
139139 v = extrinsics [w11 ][int (w12 )]
140- elif w10 == 4 and item_index is not None and w11 < len (extrinsics [item_index ]):
140+ elif (
141+ w10 == 4
142+ and extrinsics is not None
143+ and item_index is not None
144+ and item_index < len (extrinsics )
145+ and w11 < len (extrinsics [item_index ])
146+ ):
141147 v = extrinsics [item_index ][w11 ]
142148 elif (
143149 w10 == 5
144- and item_index is not None
150+ and import_segments is not None
145151 and w11 < len (import_segments )
146152 and w12 < len (import_segments [w11 ])
147153 ):
148154 v = import_segments [w11 ][w12 ]
149- elif w10 == 6 and item_index is not None and w11 < len (import_segments [item_index ]):
155+ elif (
156+ w10 == 6
157+ and import_segments is not None
158+ and item_index is not None
159+ and item_index < len (import_segments )
160+ and w11 < len (import_segments [item_index ])
161+ ):
150162 v = import_segments [item_index ][w11 ]
151163 elif package is not None :
152164
@@ -347,7 +359,7 @@ def write(
347359 service_data : AccountData ,
348360 service_index : ServiceId ,
349361 ):
350- # Get key,value start,end
362+ # Get key, value offset & size
351363 [ko , kz , vo , vz ] = registers [7 : 7 + 4 ]
352364
353365 logger .debug (
@@ -367,25 +379,21 @@ def write(
367379 )
368380 raise PvmError (PANIC )
369381
370-
371- # TODO: Handle out of balance using temp caches
372- # from jam.state.state import state
373- # state.store.save_n_clear_cache()
374-
375382 k = Bytes (memory .read (ko , kz ))
376383
377384 a = service_data .storage
378385
379386 curr_value = a .get (k )
380387 storage_len = len (curr_value ) if curr_value else HostStatus .NONE .value
388+
381389 if vz == 0 :
382390 a .__delitem__ (k )
383- elif memory .is_accessible (vo , vz , Accessibility . WRITE ):
391+ elif memory .is_accessible (vo , vz ):
384392 pre_data = a [k ]
385393 a [k ] = Bytes (memory .read (vo , vz ))
386394 if service_data .service .t > service_data .service .balance :
387- # state.store.clear()
388395 registers [7 ] = HostStatus .FULL .value
396+ # print("Storing FULL val on r[7]", registers[7])
389397 if pre_data is None :
390398 del a [k ]
391399 else :
@@ -400,6 +408,7 @@ def write(
400408 )
401409 raise PvmError (PANIC )
402410
411+ # print("Storing s_len val on r[7]", storage_len)
403412 registers [7 ] = storage_len
404413 return CONTINUE , gas , registers , memory , context
405414
@@ -426,15 +435,14 @@ def info(
426435 if target_service == 2 ** 64 - 1 :
427436 target_service = service_index
428437
429- if target_service > 2 ** 32 - 1 :
430- registers [7 ] = HostStatus .NONE .value
431- return CONTINUE , gas , registers , memory , context
432438
433- if target_service not in accounts :
439+ if target_service > 2 ** 32 - 1 or target_service not in accounts :
434440 registers [7 ] = HostStatus .NONE .value
435441 return CONTINUE , gas , registers , memory , context
436442
443+ # print("TYPE OF SERVICE", target_service, type(target_service))
437444 acc : AccountData = accounts [target_service ]
445+
438446 v = (
439447 bytes (acc .service .code_hash )
440448 + U64 (acc .service .balance ).encode ()
0 commit comments