@@ -312,14 +312,16 @@ func profileTransactionWithFVM(
312312 )... )
313313
314314 // Execute prior transactions to recreate state
315+ txIndex := 0
315316 if len (priorUserTxs ) > 0 {
316- if err := executeTransactions (vm , userCtx , execState , priorUserTxs , logger ); err != nil {
317+ if err := executeTransactions (vm , userCtx , execState , priorUserTxs , txIndex , logger ); err != nil {
317318 return nil , 0 , fmt .Errorf ("failed to execute prior user transactions: %w" , err )
318319 }
320+ txIndex += len (priorUserTxs )
319321 }
320322
321323 if len (priorSystemTxs ) > 0 {
322- if err := executeTransactions (vm , systemCtx , execState , priorSystemTxs , logger ); err != nil {
324+ if err := executeTransactions (vm , systemCtx , execState , priorSystemTxs , txIndex , logger ); err != nil {
323325 return nil , 0 , fmt .Errorf ("failed to execute prior system transactions: %w" , err )
324326 }
325327 }
@@ -339,8 +341,8 @@ func profileTransactionWithFVM(
339341 return nil , 0 , fmt .Errorf ("failed to create transaction context: %w" , err )
340342 }
341343
342- txIndex := uint32 (len (priorUserTxs ) + len (priorSystemTxs ))
343- txProc := fvm .Transaction (targetFlowTx , txIndex )
344+ targetTxIndex := uint32 (len (priorUserTxs ) + len (priorSystemTxs ))
345+ txProc := fvm .Transaction (targetFlowTx , targetTxIndex )
344346 _ , output , err := vm .Run (targetCtx , txProc , txn )
345347 if err != nil {
346348 return nil , 0 , fmt .Errorf ("failed to execute target transaction: %w" , err )
@@ -371,7 +373,7 @@ func isSystemTransaction(tx *flowsdk.Transaction) bool {
371373// separateTransactionsByType separates transactions into user and system transactions
372374func separateTransactionsByType (txs []* flowsdk.Transaction ) (user , system []* flowsdk.Transaction ) {
373375 user = make ([]* flowsdk.Transaction , 0 , len (txs ))
374- system = make ([]* flowsdk.Transaction , 0 )
376+ system = make ([]* flowsdk.Transaction , 0 , len ( txs ) )
375377
376378 for _ , tx := range txs {
377379 if isSystemTransaction (tx ) {
@@ -389,6 +391,7 @@ func executeTransactions(
389391 ctx fvm.Context ,
390392 execState * fvmState.ExecutionState ,
391393 txs []* flowsdk.Transaction ,
394+ startIndex int ,
392395 logger output.Logger ,
393396) error {
394397 for i , tx := range txs {
@@ -397,17 +400,17 @@ func executeTransactions(
397400 blockDB := fvmStorage .NewBlockDatabase (execState , 0 , nil )
398401 txn , err := blockDB .NewTransaction (0 , fvmState .DefaultParameters ())
399402 if err != nil {
400- return fmt .Errorf ("failed to create transaction context for tx %d: %w" , i , err )
403+ return fmt .Errorf ("failed to create transaction context for tx %d: %w" , startIndex + i , err )
401404 }
402405
403- txProc := fvm .Transaction (flowTx , uint32 (i ))
406+ txProc := fvm .Transaction (flowTx , uint32 (startIndex + i ))
404407 executionSnapshot , _ , err := vm .Run (ctx , txProc , txn )
405408 if err != nil {
406- return fmt .Errorf ("failed to execute transaction %d (%s): %w" , i , tx .ID ().String ()[:txIDDisplayLength ], err )
409+ return fmt .Errorf ("failed to execute transaction %d (%s): %w" , startIndex + i , tx .ID ().String ()[:txIDDisplayLength ], err )
407410 }
408411
409412 if err := execState .Merge (executionSnapshot ); err != nil {
410- return fmt .Errorf ("failed to merge execution snapshot for tx %d: %w" , i , err )
413+ return fmt .Errorf ("failed to merge execution snapshot for tx %d: %w" , startIndex + i , err )
411414 }
412415 }
413416
0 commit comments