@@ -182,7 +182,7 @@ mod v3 {
182
182
183
183
// fvm v2 implementation
184
184
mod v2 {
185
- use anyhow:: anyhow;
185
+ use anyhow:: { anyhow, Context } ;
186
186
use cid:: Cid ;
187
187
use num_traits:: FromPrimitive ;
188
188
use std:: sync:: Mutex ;
@@ -241,14 +241,14 @@ mod v2 {
241
241
let res = fvm2:: executor:: Executor :: execute_message (
242
242
self ,
243
243
Message2 {
244
- version : msg. version ,
244
+ version : msg. version . try_into ( ) . context ( "invalid message version" ) ? ,
245
245
from : Address2 :: from_bytes ( & msg. from . to_bytes ( ) ) . unwrap ( ) ,
246
246
to : Address2 :: from_bytes ( & msg. to . to_bytes ( ) ) . unwrap ( ) ,
247
247
sequence : msg. sequence ,
248
248
value : TokenAmount2 :: from_atto ( msg. value . atto ( ) . clone ( ) ) ,
249
249
method_num : msg. method_num ,
250
250
params : RawBytes2 :: new ( msg. params . into ( ) ) ,
251
- gas_limit : msg. gas_limit ,
251
+ gas_limit : msg. gas_limit . try_into ( ) . context ( "invalid gas limit" ) ? ,
252
252
gas_fee_cap : TokenAmount2 :: from_atto ( msg. gas_fee_cap . atto ( ) . clone ( ) ) ,
253
253
gas_premium : TokenAmount2 :: from_atto ( msg. gas_premium . atto ( ) . clone ( ) ) ,
254
254
} ,
@@ -263,7 +263,11 @@ mod v2 {
263
263
msg_receipt : Receipt {
264
264
exit_code : ExitCode :: new ( ret. msg_receipt . exit_code . value ( ) ) ,
265
265
return_data : RawBytes :: new ( ret. msg_receipt . return_data . into ( ) ) ,
266
- gas_used : ret. msg_receipt . gas_used ,
266
+ gas_used : ret
267
+ . msg_receipt
268
+ . gas_used
269
+ . try_into ( )
270
+ . context ( "negative gas used" ) ?,
267
271
events_root : None ,
268
272
} ,
269
273
penalty : TokenAmount :: from_atto ( ret. penalty . atto ( ) . clone ( ) ) ,
@@ -273,8 +277,8 @@ mod v2 {
273
277
ret. over_estimation_burn . atto ( ) . clone ( ) ,
274
278
) ,
275
279
refund : TokenAmount :: from_atto ( ret. refund . atto ( ) . clone ( ) ) ,
276
- gas_refund : ret. gas_refund ,
277
- gas_burned : ret. gas_burned ,
280
+ gas_refund : ret. gas_refund . try_into ( ) . context ( "negative gas refund" ) ? ,
281
+ gas_burned : ret. gas_burned . try_into ( ) . context ( "negative gas burned" ) ? ,
278
282
failure_info : ret. failure_info . map ( |failure| match failure {
279
283
ApplyFailure2 :: MessageBacktrace ( bt) => {
280
284
ApplyFailure :: MessageBacktrace ( Backtrace {
@@ -318,12 +322,26 @@ mod v2 {
318
322
. into_iter ( )
319
323
. filter_map ( |tr| match tr {
320
324
ExecutionEvent2 :: GasCharge ( charge) => {
325
+ // We set the gas for "negative" charges to 0. This isn't correct,
326
+ // but it won't matter in practice (the sum of the gas charges in
327
+ // the trace aren't guaranteed to equal the total gas charge
328
+ // anyways).
321
329
Some ( ExecutionEvent :: GasCharge ( GasCharge {
322
330
name : charge. name ,
323
331
compute_gas : Gas :: from_milligas (
324
- charge. compute_gas . as_milligas ( ) ,
332
+ charge
333
+ . compute_gas
334
+ . as_milligas ( )
335
+ . try_into ( )
336
+ . unwrap_or_default ( ) ,
337
+ ) ,
338
+ other_gas : Gas :: from_milligas (
339
+ charge
340
+ . storage_gas
341
+ . as_milligas ( )
342
+ . try_into ( )
343
+ . unwrap_or_default ( ) ,
325
344
) ,
326
- other_gas : Gas :: from_milligas ( charge. storage_gas . as_milligas ( ) ) ,
327
345
elapsed : Default :: default ( ) , // no timing information for v2.
328
346
} ) )
329
347
}
0 commit comments